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