[3] | 1 | //Opcode.h
|
---|
| 2 |
|
---|
| 3 | //未定義の定数情報
|
---|
| 4 | #define IMAGE_FILE_MACHINE_AMD64 0x8664
|
---|
| 5 |
|
---|
| 6 |
|
---|
| 7 | //レジスタを示す定数
|
---|
| 8 | #define REG_EAX 0x00 //reg:000
|
---|
| 9 | #define REG_ECX 0x01 //reg:001
|
---|
| 10 | #define REG_EDX 0x02 //reg:010
|
---|
| 11 | #define REG_EBX 0x03 //reg:011
|
---|
| 12 | #define REG_ESP 0x04 //reg:100
|
---|
| 13 | #define REG_EBP 0x05 //reg:101
|
---|
| 14 | #define REG_ESI 0x06 //reg:110
|
---|
| 15 | #define REG_EDI 0x07 //reg:111
|
---|
| 16 |
|
---|
| 17 | #define REG_RAX REG_EAX
|
---|
| 18 | #define REG_RCX REG_ECX
|
---|
| 19 | #define REG_RDX REG_EDX
|
---|
| 20 | #define REG_RBX REG_EBX
|
---|
| 21 | #define REG_RSP REG_ESP
|
---|
| 22 | #define REG_RBP REG_EBP
|
---|
| 23 | #define REG_RSI REG_ESI
|
---|
| 24 | #define REG_RDI REG_EDI
|
---|
| 25 |
|
---|
| 26 | #define REGISTER_OPERAND(reg) (reg&0x07)
|
---|
| 27 |
|
---|
| 28 | //変数の種類
|
---|
| 29 | #define NON_VAR 0
|
---|
| 30 | #define VAR_GLOBAL 1 //Global Variable
|
---|
| 31 | #define VAR_LOCAL 2 //Local Variable
|
---|
| 32 | #define VAR_REFLOCAL 3 //Local Refference Variable
|
---|
| 33 | #define VAR_DIRECTMEM 4 //Direct memory
|
---|
| 34 |
|
---|
[49] | 35 |
|
---|
[3] | 36 | extern int cp;
|
---|
| 37 | extern int obp;
|
---|
| 38 | extern char *OpBuffer;
|
---|
| 39 |
|
---|
[49] | 40 | #define breakpoint OpBuffer[obp++]=(char)0xCC;
|
---|
| 41 |
|
---|
| 42 |
|
---|
[3] | 43 | //ラベルアドレス
|
---|
| 44 | struct LABEL{
|
---|
| 45 | char *pName;
|
---|
| 46 | int line;
|
---|
| 47 | DWORD address;
|
---|
| 48 | };
|
---|
| 49 |
|
---|
| 50 | //Goto未知ラベル
|
---|
| 51 | struct GOTOLABELSCHEDULE{
|
---|
| 52 | char *pName;
|
---|
| 53 | int line;
|
---|
| 54 | DWORD pos;
|
---|
| 55 | DWORD now_cp;
|
---|
| 56 | };
|
---|
| 57 |
|
---|
| 58 | //プロシージャの種類
|
---|
| 59 | #define PROC_DEFAULT 1 //ユーザー定義関数
|
---|
| 60 | #define PROC_DLL 2 //DLL関数
|
---|
| 61 | #define PROC_BUILTIN 3 //コンパイラ埋め込み型
|
---|
| 62 | #define PROC_PTR 4 //関数ポインタ
|
---|
| 63 |
|
---|
| 64 | //プロシージャ
|
---|
| 65 | struct PROCEDURE{
|
---|
| 66 | char name[255];
|
---|
| 67 | int address;
|
---|
| 68 | int types[MAX_PARMS];
|
---|
| 69 | _int8 ByVal[MAX_PARMS];
|
---|
| 70 | BOOL ReturnType;
|
---|
| 71 | };
|
---|
| 72 |
|
---|
| 73 | //With情報
|
---|
| 74 | struct WITHINFO{
|
---|
| 75 | char **ppName;
|
---|
| 76 | int *pWithCp;
|
---|
| 77 | int num;
|
---|
| 78 | };
|
---|
| 79 |
|
---|
| 80 |
|
---|
| 81 | //MakePeHdr.cpp
|
---|
| 82 | int AddDataTable(char *buffer,int length);
|
---|
| 83 |
|
---|
| 84 | //RSrcSection.cpp
|
---|
| 85 | char *GetRSrcSectionBuffer(int *pLen);
|
---|
| 86 |
|
---|
| 87 | //Compile.cpp
|
---|
| 88 | void ChangeOpcode(char *Command);
|
---|
| 89 | void GetGlobalDataForDll(void);
|
---|
| 90 | DWORD CompileBuffer(char Return_Sequence,WORD Return_Command);
|
---|
| 91 |
|
---|
| 92 | //Compile_Calc.cpp
|
---|
| 93 | void ChangeTypeToDouble_ToFpuReg(int OldType);
|
---|
| 94 | void ChangeTypeToDouble(int OldType);
|
---|
| 95 | void ChangeTypeToSingle(int OldType);
|
---|
| 96 | void ChangeTypeToInt64(int OldType);
|
---|
| 97 | void ChangeTypeToLong(int OldType);
|
---|
| 98 | void ChangeTypeToInteger(int OldType);
|
---|
| 99 | void ChangeTypeToByte(int OldType);
|
---|
| 100 | void OpcodeCalc(char *Command);
|
---|
[40] | 101 | void SetRefVariable( const char *varname, const char *expression );
|
---|
[3] | 102 |
|
---|
| 103 | //NumOpe.cpp
|
---|
| 104 | void PushReturnValue(int type);
|
---|
[40] | 105 | int NumOpe(const char *Command,int BaseType,LONG_PTR lpBaseIndex,LONG_PTR *plpIndex,BOOL *pbUseHeap=0);
|
---|
[3] | 106 |
|
---|
| 107 | //NumOpe_Arithmetic.cpp
|
---|
| 108 | void GetStackData_ToRegister(int *type,int sp);
|
---|
| 109 | BOOL CalcTwoTerm_Arithmetic(int idCalc,int *type,LONG_PTR *index_stack,int *pStackPointer);
|
---|
| 110 | BOOL Calc_Mod(int *type,int *pStackPointer);
|
---|
| 111 | BOOL Calc_Divide(int *type,int *pStackPointer,int BaseType);
|
---|
| 112 | BOOL Calc_IntDivide(int *type,LONG_PTR *index_stack,int *pStackPointer);
|
---|
| 113 | BOOL Calc_MinusMark(int *type,int sp);
|
---|
| 114 | BOOL Calc_Power(int *type,int *pStackPointer);
|
---|
| 115 | BOOL Calc_Cast(int *type,LONG_PTR *index_stack,int *pStackPointer);
|
---|
| 116 | BOOL Calc_SHL(int *type,int *pStackPointer);
|
---|
| 117 | BOOL Calc_SHR(int *type,int *pStackPointer);
|
---|
| 118 |
|
---|
| 119 | //NumOpe_Logical.cpp
|
---|
| 120 | BOOL Calc_Xor(int *type,LONG_PTR *index_stack,int *pStackPointer);
|
---|
| 121 | BOOL Calc_Or(int *type,LONG_PTR *index_stack,int *pStackPointer);
|
---|
| 122 | BOOL Calc_And(int *type,LONG_PTR *index_stack,int *pStackPointer);
|
---|
| 123 | BOOL Calc_Not(int *type,int sp);
|
---|
| 124 |
|
---|
| 125 | //NumOpe_Relation.cpp
|
---|
| 126 | BOOL Calc_Relation_PE(int *type_stack,LONG_PTR *index_stack,int *pStackPointer);
|
---|
| 127 | BOOL Calc_Relation_QE(int *type_stack,LONG_PTR *index_stack,int *pStackPointer);
|
---|
| 128 | BOOL Calc_Relation_P(int *type_stack,LONG_PTR *index_stack,int *pStackPointer);
|
---|
| 129 | BOOL Calc_Relation_Q(int *type_stack,LONG_PTR *index_stack,int *pStackPointer);
|
---|
| 130 | BOOL Calc_Relation_NotEqual(int *type,int *pStackPointer);
|
---|
| 131 | BOOL Calc_Relation_Equal(int *type,int *pStackPointer);
|
---|
| 132 |
|
---|
| 133 | //NumOpe_TypeOperation.cpp
|
---|
| 134 | void ExtendStackTo64(int type);
|
---|
| 135 | void ChangeTypeToWhole(int OldType,int NewType);
|
---|
| 136 |
|
---|
| 137 | //Compile_Set_Var.cpp
|
---|
| 138 | BOOL IsUse_ecx(RELATIVE_VAR *pRelativeVar);
|
---|
| 139 | void SetObjectVariable(LONG_PTR lpVarIndex,int CalcType,LONG_PTR lpCalcIndex,BOOL bUseHeap);
|
---|
| 140 | void SetDoubleVariable(int type,DWORD VarKind,DWORD offset,BOOL bOffsetOffset);
|
---|
| 141 | void SetSingleVariable(int type,DWORD VarKind,DWORD offset,BOOL bOffsetOffset);
|
---|
| 142 | void SetInt64Variable(int type,RELATIVE_VAR *pRelative);
|
---|
| 143 | void SetDWordVariable(int type,DWORD VarKind,DWORD offset,BOOL bOffsetOffset);
|
---|
| 144 | void SetLongVariable(int type,DWORD VarKind,DWORD offset,BOOL bOffsetOffset);
|
---|
| 145 | void Set16Variable(int type,DWORD VarKind,DWORD offset,BOOL bOffsetOffset);
|
---|
| 146 | void Set8Variable(int type,DWORD VarKind,DWORD offset,BOOL bOffsetOffset);
|
---|
[36] | 147 | void SetBooleanVariable(int type,RELATIVE_VAR *pRelative);
|
---|
[3] | 148 |
|
---|
| 149 | //increment.cpp
|
---|
| 150 | void IncDec(int idCalc, char *lpszLeft, char *lpszRight);
|
---|
| 151 |
|
---|
| 152 | //calc2.cpp
|
---|
| 153 | #define EXP_TYPE_NUMBER 1
|
---|
| 154 | #define EXP_TYPE_EAX 2
|
---|
| 155 | #define EXP_TYPE_FPU 3
|
---|
| 156 | #define EXP_TYPE_VAR 4
|
---|
| 157 | int NumOpEx(char *Command,double *pDbl,DWORD *pdwType,RELATIVE_VAR *pRelativeVar);
|
---|
| 158 |
|
---|
| 159 | //SetVar.cpp
|
---|
| 160 | BOOL SetVariable(DWORD dwVarType,RELATIVE_VAR *pVarRelativeVar,
|
---|
| 161 | DWORD dwExpType,DWORD dwType,void *data);
|
---|
| 162 |
|
---|
| 163 | //Compile_Calc_PushVar.cpp
|
---|
| 164 | void SetReg_RealVariable(int type,RELATIVE_VAR *pRelativeVar);
|
---|
| 165 | void SetReg_WholeVariable(int type,RELATIVE_VAR *pRelativeVar,int reg);
|
---|
| 166 | void PushDoubleVariable(RELATIVE_VAR *pRelativeVar);
|
---|
| 167 | void PushLongVariable(RELATIVE_VAR *pRelativeVar);
|
---|
| 168 | void PushIntegerVariable(RELATIVE_VAR *pRelativeVar);
|
---|
| 169 | void PushWordVariable(RELATIVE_VAR *pRelativeVar);
|
---|
| 170 | void PushCharVariable(RELATIVE_VAR *pRelativeVar);
|
---|
| 171 | void PushByteVariable(RELATIVE_VAR *pRelativeVar);
|
---|
| 172 |
|
---|
| 173 | //Compile_Object.cpp
|
---|
[40] | 174 | int Operator_New(const char *Parameter,LONG_PTR *plpIndex);
|
---|
[3] | 175 | void OpcodeDelete(char *Parameter);
|
---|
| 176 |
|
---|
| 177 | //Compile_Var.cpp
|
---|
| 178 | void GetWithName(char *buffer);
|
---|
| 179 | void SetThisPtrToReg(int reg);
|
---|
[40] | 180 | BOOL GetVarOffset(bool isErrorEnabled,bool isWriteAccess,const char *NameBuffer,int *pType,RELATIVE_VAR *pRelativeVar,LONG_PTR *plpIndex,int *pss=0);
|
---|
[3] | 181 | BOOL SetInitGlobalData(int offset,int type,LONG_PTR lpIndex,int *SubScripts,char *InitBuf);
|
---|
[8] | 182 | #define DIMFLAG_INITDEBUGVAR 1
|
---|
| 183 | #define DIMFLAG_NONCALL_CONSTRACTOR 2
|
---|
| 184 | #define DIMFLAG_STATIC 4
|
---|
| 185 | #define DIMFLAG_CONST 8
|
---|
[3] | 186 | void OpcodeDim(char *Parameter,DWORD dwFlag);
|
---|
| 187 | void SetVarPtrToEax(RELATIVE_VAR *pRelativeVar);
|
---|
| 188 |
|
---|
| 189 | //CParameter.cpp
|
---|
| 190 | #define OVERLOAD_LEVEL1 1
|
---|
| 191 | #define OVERLOAD_LEVEL2 2
|
---|
| 192 | #define OVERLOAD_LEVEL3 3
|
---|
| 193 | class CParameter{
|
---|
| 194 | char *Parms[255];
|
---|
| 195 | TYPEINFO types[255];
|
---|
| 196 | int ParmsNum;
|
---|
| 197 |
|
---|
| 198 | TYPEINFO ReturnTypeInfo;
|
---|
| 199 |
|
---|
[20] | 200 | //一時オブジェクト管理用
|
---|
| 201 | bool useTempObject;
|
---|
| 202 | bool useTempParameters[255];
|
---|
| 203 | int nCountOfTempObjects;
|
---|
| 204 |
|
---|
[3] | 205 | public:
|
---|
| 206 | CParameter(char *buffer);
|
---|
| 207 | CParameter(PARAMETER_INFO *pParamInfo,int ParmNum);
|
---|
| 208 | ~CParameter();
|
---|
| 209 | void SetReturnType(TYPEINFO *pTypeInfo);
|
---|
| 210 |
|
---|
| 211 | private:
|
---|
| 212 | BOOL _overload_check(PARAMETER_INFO *ppi,int pi_num,TYPEINFO *pReturnTypeInfo,int overload_level);
|
---|
[46] | 213 | SUBINFO *OverloadSolutionWithReturnType(const char *name,SUBINFO **ppsi,int num);
|
---|
[3] | 214 | public:
|
---|
[46] | 215 | SUBINFO *OverloadSolution(const char *name,SUBINFO **ppsi,int num);
|
---|
[3] | 216 |
|
---|
[46] | 217 | BOOL ErrorCheck(const char *FuncName,PARAMETER_INFO *ppi,int pi_num,int SecondParmNum);
|
---|
[3] | 218 | void MacroParameterSupport(PARAMETER_INFO *ppi);
|
---|
| 219 | void SetObjectParameter(CClass *pobj_Class,LPSTR Parameter);
|
---|
[46] | 220 | int SetParameter(const char *FuncName,PARAMETER_INFO *ppi,int pi_num,int SecondParmNum);
|
---|
[20] | 221 |
|
---|
| 222 | //一時オブジェクトパラメータの生成と破棄
|
---|
[46] | 223 | void NewTempParameters( const char *FuncName,PARAMETER_INFO *ppi,int pi_num,int SecondParmNum );
|
---|
[20] | 224 | void DeleteTempParameters();
|
---|
[3] | 225 | };
|
---|
| 226 |
|
---|
| 227 | //Compile_CallProc.cpp
|
---|
| 228 | void AddLocalVarAddrSchedule();
|
---|
| 229 | int CallProc(int idProc,void *pInfo,char *name,char *Parameter,LONG_PTR *plpRetIndex);
|
---|
| 230 | BOOL CallPropertyMethod(char *variable,char *RightSide,TYPEINFO *pRetTypeInfo);
|
---|
| 231 | #define PROCFLAG_NEW 1
|
---|
| 232 | int Opcode_CallProcPtr(char *variable,char *Parameter,PROCPTRINFO *pi,LONG_PTR *plpIndex);
|
---|
[31] | 233 | void Opcode_CallProc(char *Parameter,SUBINFO *psi,DWORD dwFlags,char *ObjectName,int RefType);
|
---|
[3] | 234 | int Opcode_CallDllProc(char *Parameter,DECLAREINFO *pdi,LONG_PTR *plpIndex);
|
---|
| 235 |
|
---|
| 236 | //Compile_ProcOp.cpp
|
---|
| 237 | void CompileLocal();
|
---|
| 238 |
|
---|
| 239 | //Compile_Func.cpp
|
---|
| 240 | int GetFunctionType(int FuncNum);
|
---|
| 241 | int GetFunctionFromName(char *FuncName);
|
---|
[46] | 242 | void Opcode_CallFunc( const char *Parameter, const int FuncNum, TYPEINFO &ReturnTypeInfo );
|
---|
[3] | 243 |
|
---|
| 244 | //OperatorProc.cpp
|
---|
| 245 | void FreeTempObject(int reg,CClass *pobj_c);
|
---|
| 246 | int CallOperatorProc(int idCalc,TYPEINFO *pBaseTypeInfo,int *type,LONG_PTR *index_stack,BOOL *bUseHeap,int &sp);
|
---|
| 247 | void CallCastOperatorProc(int &CalcType,LONG_PTR &lpCalcIndex,BOOL bCalcUseHeap,int ToType,LONG_PTR lpToIndex);
|
---|
[38] | 248 | void CallIndexerGetterProc(CClass *pobj_Class,char *ObjectName,char *Parameter,TYPEINFO &RetTypeInfo);
|
---|
[3] | 249 |
|
---|
| 250 | //Compile_Statement.cpp
|
---|
| 251 | void OpcodeOthers(char *Command);
|
---|
| 252 | void OpcodeIf(char *Parameter);
|
---|
| 253 | void OpcodeGoto(char *Parameter);
|
---|
| 254 | void OpcodeWhile(char *Parameter);
|
---|
| 255 | void OpcodeFor(char *Parameter);
|
---|
| 256 | void OpcodeDo(char *Parameter);
|
---|
| 257 | void OpcodeContinue(void);
|
---|
| 258 | void OpcodeExitSub(void);
|
---|
| 259 | void OpcodeSelect(char *Parameter);
|
---|
| 260 | void OpcodeCase(char *Parameter);
|
---|
| 261 | void OpcodeGosub(char *Parameter);
|
---|
| 262 | void OpcodeReturn(char *Parameter);
|
---|
| 263 | void Opcode_Input(char *Parameter);
|
---|
| 264 | void Opcode_Print(char *Parameter,BOOL bWrite);
|
---|
| 265 | void OpcodeCallPtr(char *Parameter);
|
---|
| 266 | void OpcodeSetPtrData(char *Parameter,int type);
|
---|
| 267 |
|
---|
| 268 |
|
---|
| 269 |
|
---|
| 270 |
|
---|
| 271 | ////////////////////////////////
|
---|
| 272 | // IA-32機械語生成に利用する関数郡
|
---|
| 273 | ////////////////////////////////
|
---|
| 274 |
|
---|
| 275 | //Mod(モード)
|
---|
| 276 | #define MOD_BASE (char)0x00
|
---|
| 277 | #define MOD_DISP32 (char)0xFF
|
---|
| 278 | #define MOD_BASE_DISP8 (char)0x40
|
---|
| 279 | #define MOD_BASE_DISP32 (char)0x80
|
---|
| 280 | #define MOD_REG (char)0xC0
|
---|
| 281 |
|
---|
| 282 | #define USE_OFFSET 1
|
---|
| 283 | #define NON_OFFSET 0
|
---|
| 284 |
|
---|
| 285 | //op32_main.cpp
|
---|
| 286 | BOOL IsSafeReg(int reg);
|
---|
| 287 | void op_mov_RV (int reg,int offset);
|
---|
| 288 | void op_mov_RV (int op_size,int reg,int offset);
|
---|
| 289 | void op_mov_RR (int reg1,int reg2);
|
---|
| 290 | void op_mov_RM (int op_size,int reg,int base_reg,int offset,char mod);
|
---|
| 291 | void op_mov_RM_ex (int op_size,int reg,int base_reg1,int base_reg2,int offset,BOOL bUseOffset);
|
---|
| 292 | void op_mov_MR (int op_size,int reg,int base_reg,int offset,char mod);
|
---|
| 293 | void op_mov_MR_ex (int op_size,int reg,int base_reg1,int base_reg2,int offset,BOOL bUseOffset);
|
---|
| 294 | void op_movsx_R32R16 (int reg32,int reg16);
|
---|
| 295 | void op_movsx_R32R8 (int reg32,int reg8);
|
---|
| 296 | void op_movsx_R16R8 (int reg16,int reg8);
|
---|
| 297 | void op_inc (int reg);
|
---|
| 298 | void op_dec (int reg);
|
---|
| 299 | void op_add_RV8 (int reg,char cValue);
|
---|
| 300 | void op_add_RM (int op_size,int reg,int base_reg,int offset,char mod);
|
---|
| 301 | void op_adc_RV8 (int reg,char cValue);
|
---|
| 302 | void op_sub_RV8 (int reg,char cValue);
|
---|
| 303 | void op_sbb_RV8 (int reg,char cValue);
|
---|
[36] | 304 | void op_sbb_RR ( int reg1, int reg2 );
|
---|
[3] | 305 | void op_and_RV (int reg,int value);
|
---|
[36] | 306 | void op_or_RR ( int op_size, int reg1, int reg2 );
|
---|
| 307 | void op_neg ( int reg );
|
---|
[3] | 308 | void op_cdq ();
|
---|
| 309 |
|
---|
| 310 | void op_rep_movs (int op_size);
|
---|
| 311 |
|
---|
| 312 | void op_push(int reg);
|
---|
| 313 | void op_push_value(long data);
|
---|
| 314 | void op_pop(int reg);
|
---|
| 315 | void op_add_esp(int num);
|
---|
| 316 | void op_sub_esp(int num);
|
---|
[36] | 317 | void op_cmp_value(int op_size,int reg,char byte_data);
|
---|
| 318 | void op_setne( int reg );
|
---|
[3] | 319 | void op_test(int reg1,int reg2);
|
---|
| 320 | void op_fld_ptr_esp(int type);
|
---|
| 321 | void op_fld_basereg (int type,int base_reg);
|
---|
| 322 | void op_fld_base_offset (int type,int base_reg,int offset);
|
---|
| 323 | void op_fld_base_offset_ex (int type,int base_reg1,int base_reg2,int offset,BOOL bUseOffset);
|
---|
| 324 | void op_fstp_basereg (int type,int base_reg);
|
---|
| 325 | void op_fstp_base_offset (int type,int base_reg,int offset);
|
---|
| 326 | void op_fstp_base_offset_ex (int type,int base_reg1,int base_reg2,int offset,BOOL bUseOffset);
|
---|
| 327 | void op_zero_reg(int reg);
|
---|
| 328 | void fpu_cast();
|
---|
| 329 | void fpu_cast_end();
|
---|
| 330 |
|
---|
| 331 | void op_call(SUBINFO *psi);
|
---|