📄 cometvm.h
字号:
// CometVM.h: interface for the CCometVM class.
///////////////////////////////////////////////////////////////////////
//文件功能: Comet虚拟机类
//开发人员:杨军
//开发日期:2004-4-18
//修改人员:
//修改日期:
///////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
#if !defined(COMET_VM_INCLUDED)
#define COMET_VM_INCLUDED
#include "CaslUtil.h"
#include "OperateStatus.h"
#include "PlatformIndependentDataType.h"
#include "ForStlUse.h"
#include "CaslCompiler.h"
#include "XmlErrorHandler.h"
#include "ConsoleManage.h"
#define VM_MEMORY_LIMIT 65535
class CDebugCmd;
class CUIDemoApp;
class CCaslEditCtrl;
class CMainFrame;
class CCometVM
{
//-------------声明友元类 begins---------------------------------
friend class CDebugCmd;
friend class CUIDemoApp;
friend class CCaslEditCtrl;
friend class CMainFrame;
friend class CRegisterBar;
//-------------声明友元类 ends ---------------------------------
public:
CCometVM();
virtual ~CCometVM();
//---------------------初始化虚拟机的运行环境----------------------
int InitVM();
//---------------------结束虚拟机的运行----------------------------
int ExitVM();
//---------------------装入一个可执行文件--------------------------
int LoadExeFile(const char * argExeFile);
//---------------------开始运行装入的可执行文件--------------------
int Run();
//---------------------开始基于命令行调试装入的可执行文件----------
int ConsoleDebug();
public:
//-------------COMET虚拟机的内存上界-------------------------------
const int m_icVMMemoryLimit;
private:
//--------------检查指定内存地址是否超过了COMET虚拟机的内存范围-----
bool IsAddressValid(U2 argAddress);
//---------------------从当前PC处读出一条指令-----------------------
int ReadInstruction();
//--------------------执行当前指令----------------------------------
int ExecuteInstruction();
//---------------------ST指令的执行函数----------------------------
int Instruction_LD();
//---------------------LEA指令的执行函数----------------------------
int Instruction_LEA();
//---------------------ST指令的执行函数----------------------------
int Instruction_ST();
//---------------------ADD指令的执行函数----------------------------
int Instruction_ADD();
//---------------------SUB指令的执行函数----------------------------
int Instruction_Sub();
//---------------------AND指令的执行函数----------------------------
int Instruction_AND();
//---------------------OR指令的执行函数----------------------------
int Instruction_OR();
//---------------------EOR指令的执行函数----------------------------
int Instruction_EOR();
//---------------------CPA指令的执行函数----------------------------
int Instruction_CPA();
//---------------------CPAL指令的执行函数----------------------------
int Instruction_CPL();
//---------------------SLA指令的执行函数----------------------------
int Instruction_SLA();
//---------------------SRA指令的执行函数----------------------------
int Instruction_SRA();
//---------------------SLL指令的执行函数----------------------------
int Instruction_SLL();
//---------------------SRL指令的执行函数----------------------------
int Instruction_SRL();
//---------------------JMP指令的执行函数----------------------------
int Instruction_JMP();
//---------------------JPZ指令的执行函数----------------------------
int Instruction_JPZ();
//---------------------JMI指令的执行函数----------------------------
int Instruction_JMI();
//---------------------JNZ指令的执行函数----------------------------
int Instruction_JNZ();
//---------------------JZE指令的执行函数----------------------------
int Instruction_JZE();
//---------------------PUSH指令的执行函数----------------------------
int Instruction_Push();
//---------------------POP指令的执行函数----------------------------
int Instruction_Pop();
//---------------------CALL指令的执行函数----------------------------
int Instruction_Call();
//---------------------RET指令的执行函数----------------------------
int Instruction_Ret();
//---------------------用于转化宏的内部指令begins------------------
//---------------------Set_NLabel指令的执行函数---------------------
int Instruction_Set_NLabel();
//---------------------Set_ALabel指令的执行函数---------------------
int Instruction_Set_ALabel();
//---------------------Func_In指令的执行函数---------------------
int Instruction_Func_In();
//---------------------Func_Outl指令的执行函数---------------------
int Instruction_Func_Out();
//---------------------用于转化宏的内部指令ends------------------
//---------------------In 宏的执行函数------------------------------
int Macro_In();
//---------------------Out 宏的执行函数------------------------------
int Macro_Out();
//---------------------Exit 宏的执行函数------------------------------
int Macro_Exit();
//---------------------检验指令是否正确------------------------------
bool VerifyInstruction();
//---------------------依据指定的寄存器的数据更新标志寄存器的数据----
int AdjustFR(int argRegNumber);
//---------------------获得数据输入----------------------------------
int InputData();
//---------------------进行数据输出----------------------------------
int OutputData();
//---------解析地址字符串,获得要Dump的内存区域的起止地址-----------------
int ParseAddressForDump(string& argAddress, U2& argStartAddr, U2& argEndAddr);
//---------解析地址字符串,获得要Go的指令内存区域的起止地址------------------
int ParseAddressForGo(string argAddress, U2& argStartAddr, U2& argEndAddr);
//---------解析地址字符串,获得要Go的指令内存区域的起始地址和要执行的指令的条数----
int ParseAddressForProceed(string argAddress, U2& argStartAddr, U2& argInstNumber);
//---------解析地址字符串,获得要Assemble的内存区域的起止地址-----------------
int ParseAddressForUnassemble(string argAddress, U2& argStartAddr, U2& argEndAddr);
//---------顺序增加PC的指针-----------------------------------------
inline void IncrementPC()
{
m_PC += 2;
}
private:
//-----------------------变量定义begins---------------------------------
//---------可执行文件装入内存后的组织格式如下:---------------------
//1.变量区
//2.常量区
//3.指令区
//--------------------字节指针,指向虚拟机的内存基址----------------
S1 * m_pVMMemoryBase;
//--------------------字节指针,指向变量区的内存基址----------------
S1 * m_pVarMemoryBase;
//--------------------字节指针,指向常量区的内存基址
S1 * m_pConstMemoryBase;
//--------------------指令指针,指向指令区的内存基址
S1 * m_pInstructionMemoryBase;
//--------------------五个16bit的通用寄存器(GR0----------GR4)------
S2 m_GR[5];
//--------------------16bit的指令计数器(PC)------------------------
U2 m_PC;
//--------------------可执行程序在虚拟机内存中的起始位置(相对于虚拟机内存起点计算)---
U2 m_ExecCodeStart;
//--------------------2bit的标志寄存器(FR)(为方便起见,为其分配一个Byte)--
S1 m_FR;
//--------------------栈底地址--------------------------------------
int m_iStackBottom;
//--------------------存放IN, OUT要用到的ALabel的偏移地址-----------------
S2 m_ALabel;
//--------------------存放IN, OUT要用到的NLabel的偏移地址
S2 m_NLabel;
//--------------------当前PC指向的目标指令--------------------------
ObjectCode m_objInstruction;
//--------------------错误处理类------------------------------------
CXmlErrorHandler m_errorHandler;
//--------------------可视化调试信息vector---------------------------
vector<InstructionDebugInfo> m_vecVisualDebugInfo;
//-----------------------变量定义ends ---------------------------------
#ifdef WINDOW_MODE
//---------如果是工作在Windows模式下,需要利用控制台操作类完成虚拟机的输入,输出操作--------------
CConsoleManage m_console;
#endif
};
#endif // !defined(COMET_VM_INCLUDED)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -