[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);
|
---|
[3] | 100 | void OpcodeCalc(char *Command);
|
---|
| 101 |
|
---|
| 102 | //NumOpe.cpp
|
---|
| 103 | void PushReturnValue(int type);
|
---|
[40] | 104 | int NumOpe(const char *Command,int BaseType,LONG_PTR lpBaseIndex,LONG_PTR *plpIndex,BOOL *pbUseHeap=0);
|
---|
[3] | 105 |
|
---|
| 106 | //NumOpe_Arithmetic.cpp
|
---|
| 107 | void GetStackData_ToRegister(int *type,int sp);
|
---|
| 108 | BOOL CalcTwoTerm_Arithmetic(int idCalc,int *type,LONG_PTR *index_stack,int *pStackPointer);
|
---|
| 109 | BOOL Calc_Mod(int *type,int *pStackPointer);
|
---|
| 110 | BOOL Calc_Divide(int *type,int *pStackPointer,int BaseType);
|
---|
| 111 | BOOL Calc_IntDivide(int *type,LONG_PTR *index_stack,int *pStackPointer);
|
---|
| 112 | BOOL Calc_MinusMark(int *type,int sp);
|
---|
| 113 | BOOL Calc_Power(int *type,int *pStackPointer);
|
---|
| 114 | BOOL Calc_Cast(int *type,LONG_PTR *index_stack,int *pStackPointer);
|
---|
| 115 | BOOL Calc_SHL(int *type,int *pStackPointer);
|
---|
| 116 | BOOL Calc_SHR(int *type,int *pStackPointer);
|
---|
| 117 |
|
---|
| 118 | //NumOpe_Logical.cpp
|
---|
| 119 | BOOL Calc_Xor(int *type,LONG_PTR *index_stack,int *pStackPointer);
|
---|
| 120 | BOOL Calc_Or(int *type,LONG_PTR *index_stack,int *pStackPointer);
|
---|
| 121 | BOOL Calc_And(int *type,LONG_PTR *index_stack,int *pStackPointer);
|
---|
| 122 | BOOL Calc_Not(int *type,int sp);
|
---|
| 123 |
|
---|
| 124 | //NumOpe_Relation.cpp
|
---|
| 125 | BOOL Calc_Relation_PE(int *type_stack,LONG_PTR *index_stack,int *pStackPointer);
|
---|
| 126 | BOOL Calc_Relation_QE(int *type_stack,LONG_PTR *index_stack,int *pStackPointer);
|
---|
| 127 | BOOL Calc_Relation_P(int *type_stack,LONG_PTR *index_stack,int *pStackPointer);
|
---|
| 128 | BOOL Calc_Relation_Q(int *type_stack,LONG_PTR *index_stack,int *pStackPointer);
|
---|
| 129 | BOOL Calc_Relation_NotEqual(int *type,int *pStackPointer);
|
---|
| 130 | BOOL Calc_Relation_Equal(int *type,int *pStackPointer);
|
---|
| 131 |
|
---|
| 132 | //NumOpe_TypeOperation.cpp
|
---|
| 133 | void ExtendStackTo64(int type);
|
---|
| 134 | void ChangeTypeToWhole(int OldType,int NewType);
|
---|
| 135 |
|
---|
| 136 | //Compile_Set_Var.cpp
|
---|
| 137 | BOOL IsUse_ecx(RELATIVE_VAR *pRelativeVar);
|
---|
[64] | 138 | void SetStructVariable(LONG_PTR lpVarIndex,int CalcType,LONG_PTR lpCalcIndex,BOOL bUseHeap);
|
---|
| 139 | void SetRealVariable(int VarType, int CalcType, RELATIVE_VAR *pRelativeVar);
|
---|
[66] | 140 | void SetWholeVariable( int varSize,int calcType, RELATIVE_VAR *pRelative );
|
---|
[64] | 141 |
|
---|
[3] | 142 | void SetDoubleVariable(int type,DWORD VarKind,DWORD offset,BOOL bOffsetOffset);
|
---|
| 143 | void SetSingleVariable(int type,DWORD VarKind,DWORD offset,BOOL bOffsetOffset);
|
---|
| 144 | void SetInt64Variable(int type,RELATIVE_VAR *pRelative);
|
---|
| 145 | void SetDWordVariable(int type,DWORD VarKind,DWORD offset,BOOL bOffsetOffset);
|
---|
| 146 | void SetLongVariable(int type,DWORD VarKind,DWORD offset,BOOL bOffsetOffset);
|
---|
| 147 | void Set16Variable(int type,DWORD VarKind,DWORD offset,BOOL bOffsetOffset);
|
---|
| 148 | void Set8Variable(int type,DWORD VarKind,DWORD offset,BOOL bOffsetOffset);
|
---|
[36] | 149 | void SetBooleanVariable(int type,RELATIVE_VAR *pRelative);
|
---|
[3] | 150 |
|
---|
| 151 | //increment.cpp
|
---|
| 152 | void IncDec(int idCalc, char *lpszLeft, char *lpszRight);
|
---|
| 153 |
|
---|
| 154 | //calc2.cpp
|
---|
| 155 | #define EXP_TYPE_NUMBER 1
|
---|
| 156 | #define EXP_TYPE_EAX 2
|
---|
| 157 | #define EXP_TYPE_FPU 3
|
---|
| 158 | #define EXP_TYPE_VAR 4
|
---|
| 159 | int NumOpEx(char *Command,double *pDbl,DWORD *pdwType,RELATIVE_VAR *pRelativeVar);
|
---|
| 160 |
|
---|
| 161 | //SetVar.cpp
|
---|
| 162 | BOOL SetVariable(DWORD dwVarType,RELATIVE_VAR *pVarRelativeVar,
|
---|
| 163 | DWORD dwExpType,DWORD dwType,void *data);
|
---|
| 164 |
|
---|
| 165 | //Compile_Calc_PushVar.cpp
|
---|
| 166 | void SetReg_RealVariable(int type,RELATIVE_VAR *pRelativeVar);
|
---|
| 167 | void SetReg_WholeVariable(int type,RELATIVE_VAR *pRelativeVar,int reg);
|
---|
| 168 | void PushDoubleVariable(RELATIVE_VAR *pRelativeVar);
|
---|
| 169 | void PushLongVariable(RELATIVE_VAR *pRelativeVar);
|
---|
| 170 | void PushIntegerVariable(RELATIVE_VAR *pRelativeVar);
|
---|
| 171 | void PushWordVariable(RELATIVE_VAR *pRelativeVar);
|
---|
| 172 | void PushCharVariable(RELATIVE_VAR *pRelativeVar);
|
---|
| 173 | void PushByteVariable(RELATIVE_VAR *pRelativeVar);
|
---|
| 174 |
|
---|
| 175 | //Compile_Object.cpp
|
---|
[64] | 176 | void Operator_New( CClass &classObj, const char *objectSizeStr, const char *parameter, const TYPEINFO &baseTypeInfo );
|
---|
| 177 | int Operator_New(const char *Parameter,LONG_PTR *plpIndex,const TYPEINFO &baseTypeInfo );
|
---|
| 178 | void OpcodeDelete(const char *Parameter, bool isSweeping);
|
---|
[3] | 179 |
|
---|
| 180 | //Compile_Var.cpp
|
---|
[66] | 181 | void SetRelativeOffset( RELATIVE_VAR &relativeVar );
|
---|
[3] | 182 | void GetWithName(char *buffer);
|
---|
| 183 | void SetThisPtrToReg(int reg);
|
---|
[40] | 184 | BOOL GetVarOffset(bool isErrorEnabled,bool isWriteAccess,const char *NameBuffer,int *pType,RELATIVE_VAR *pRelativeVar,LONG_PTR *plpIndex,int *pss=0);
|
---|
[3] | 185 | BOOL SetInitGlobalData(int offset,int type,LONG_PTR lpIndex,int *SubScripts,char *InitBuf);
|
---|
[8] | 186 | #define DIMFLAG_INITDEBUGVAR 1
|
---|
| 187 | #define DIMFLAG_NONCALL_CONSTRACTOR 2
|
---|
| 188 | #define DIMFLAG_STATIC 4
|
---|
| 189 | #define DIMFLAG_CONST 8
|
---|
[64] | 190 | void dim(bool isRef, char *VarName,int *SubScripts,TYPEINFO &TypeInfo,int TypeSize,char *InitBuf,char *ConstractParameter,DWORD dwFlags);
|
---|
[3] | 191 | void OpcodeDim(char *Parameter,DWORD dwFlag);
|
---|
| 192 | void SetVarPtrToEax(RELATIVE_VAR *pRelativeVar);
|
---|
| 193 |
|
---|
[71] | 194 | //ParamImpl.cpp
|
---|
[64] | 195 | #define OVERLOAD_MIN_LEVEL 0
|
---|
| 196 | #define OVERLOAD_MAX_LEVEL 3
|
---|
| 197 | #define OVERLOAD_LEVEL0 0
|
---|
[3] | 198 | #define OVERLOAD_LEVEL1 1
|
---|
| 199 | #define OVERLOAD_LEVEL2 2
|
---|
| 200 | #define OVERLOAD_LEVEL3 3
|
---|
[71] | 201 | class ParamImpl{
|
---|
[3] | 202 | char *Parms[255];
|
---|
| 203 | TYPEINFO types[255];
|
---|
| 204 | int ParmsNum;
|
---|
| 205 |
|
---|
| 206 | TYPEINFO ReturnTypeInfo;
|
---|
| 207 |
|
---|
[20] | 208 | //一時オブジェクト管理用
|
---|
| 209 | bool useTempObject;
|
---|
| 210 | bool useTempParameters[255];
|
---|
| 211 | int nCountOfTempObjects;
|
---|
| 212 |
|
---|
[3] | 213 | public:
|
---|
[71] | 214 | ParamImpl(const char *buffer);
|
---|
| 215 | ParamImpl(const PARAMETER_INFO *pParamInfo, const int ParmNum);
|
---|
| 216 | ~ParamImpl();
|
---|
[3] | 217 | void SetReturnType(TYPEINFO *pTypeInfo);
|
---|
| 218 |
|
---|
| 219 | private:
|
---|
| 220 | BOOL _overload_check(PARAMETER_INFO *ppi,int pi_num,TYPEINFO *pReturnTypeInfo,int overload_level);
|
---|
[50] | 221 | SUBINFO *OverloadSolutionWithReturnType( const char *name, std::vector<SUBINFO *> &subs );
|
---|
[3] | 222 | public:
|
---|
[50] | 223 | SUBINFO *OverloadSolution( const char *name, std::vector<SUBINFO *> &subs );
|
---|
[3] | 224 |
|
---|
[46] | 225 | BOOL ErrorCheck(const char *FuncName,PARAMETER_INFO *ppi,int pi_num,int SecondParmNum);
|
---|
[3] | 226 | void MacroParameterSupport(PARAMETER_INFO *ppi);
|
---|
[64] | 227 | void SetStructParameter(CClass *pobj_Class,LPSTR Parameter);
|
---|
[46] | 228 | int SetParameter(const char *FuncName,PARAMETER_INFO *ppi,int pi_num,int SecondParmNum);
|
---|
[20] | 229 |
|
---|
| 230 | //一時オブジェクトパラメータの生成と破棄
|
---|
[64] | 231 | int NewTempParameters( const char *FuncName,PARAMETER_INFO *ppi,int pi_num,int SecondParmNum );
|
---|
[20] | 232 | void DeleteTempParameters();
|
---|
[3] | 233 | };
|
---|
| 234 |
|
---|
| 235 | //Compile_CallProc.cpp
|
---|
| 236 | void AddLocalVarAddrSchedule();
|
---|
| 237 | #define PROCFLAG_NEW 1
|
---|
| 238 | int Opcode_CallProcPtr(char *variable,char *Parameter,PROCPTRINFO *pi,LONG_PTR *plpIndex);
|
---|
[64] | 239 | void Opcode_CallProc(const char *Parameter,SUBINFO *psi,DWORD dwFlags,char *ObjectName,int RefType);
|
---|
[3] | 240 | int Opcode_CallDllProc(char *Parameter,DECLAREINFO *pdi,LONG_PTR *plpIndex);
|
---|
| 241 |
|
---|
| 242 | //Compile_ProcOp.cpp
|
---|
| 243 | void CompileLocal();
|
---|
| 244 |
|
---|
| 245 | //Compile_Func.cpp
|
---|
| 246 | int GetFunctionType(int FuncNum);
|
---|
| 247 | int GetFunctionFromName(char *FuncName);
|
---|
[46] | 248 | void Opcode_CallFunc( const char *Parameter, const int FuncNum, TYPEINFO &ReturnTypeInfo );
|
---|
[3] | 249 |
|
---|
| 250 | //OperatorProc.cpp
|
---|
| 251 | void FreeTempObject(int reg,CClass *pobj_c);
|
---|
| 252 | int CallOperatorProc(int idCalc,TYPEINFO *pBaseTypeInfo,int *type,LONG_PTR *index_stack,BOOL *bUseHeap,int &sp);
|
---|
| 253 | void CallCastOperatorProc(int &CalcType,LONG_PTR &lpCalcIndex,BOOL bCalcUseHeap,int ToType,LONG_PTR lpToIndex);
|
---|
[38] | 254 | void CallIndexerGetterProc(CClass *pobj_Class,char *ObjectName,char *Parameter,TYPEINFO &RetTypeInfo);
|
---|
[3] | 255 |
|
---|
| 256 | //Compile_Statement.cpp
|
---|
| 257 | void OpcodeOthers(char *Command);
|
---|
| 258 | void OpcodeIf(char *Parameter);
|
---|
| 259 | void OpcodeGoto(char *Parameter);
|
---|
| 260 | void OpcodeWhile(char *Parameter);
|
---|
| 261 | void OpcodeFor(char *Parameter);
|
---|
| 262 | void OpcodeDo(char *Parameter);
|
---|
| 263 | void OpcodeContinue(void);
|
---|
| 264 | void OpcodeExitSub(void);
|
---|
| 265 | void OpcodeSelect(char *Parameter);
|
---|
| 266 | void OpcodeCase(char *Parameter);
|
---|
| 267 | void OpcodeGosub(char *Parameter);
|
---|
| 268 | void OpcodeReturn(char *Parameter);
|
---|
[64] | 269 | void Opcode_Input(const char *Parameter);
|
---|
| 270 | void Opcode_Print(const char *Parameter,BOOL bWrite);
|
---|
[3] | 271 | void OpcodeCallPtr(char *Parameter);
|
---|
| 272 | void OpcodeSetPtrData(char *Parameter,int type);
|
---|
| 273 |
|
---|
| 274 |
|
---|
| 275 |
|
---|
| 276 |
|
---|
| 277 | ////////////////////////////////
|
---|
| 278 | // IA-32機械語生成に利用する関数郡
|
---|
| 279 | ////////////////////////////////
|
---|
| 280 |
|
---|
| 281 | //Mod(モード)
|
---|
| 282 | #define MOD_BASE (char)0x00
|
---|
| 283 | #define MOD_DISP32 (char)0xFF
|
---|
| 284 | #define MOD_BASE_DISP8 (char)0x40
|
---|
| 285 | #define MOD_BASE_DISP32 (char)0x80
|
---|
| 286 | #define MOD_REG (char)0xC0
|
---|
| 287 |
|
---|
| 288 | #define USE_OFFSET 1
|
---|
| 289 | #define NON_OFFSET 0
|
---|
| 290 |
|
---|
| 291 | //op32_main.cpp
|
---|
| 292 | BOOL IsSafeReg(int reg);
|
---|
| 293 | void op_mov_RV (int reg,int offset);
|
---|
| 294 | void op_mov_RV (int op_size,int reg,int offset);
|
---|
| 295 | void op_mov_RR (int reg1,int reg2);
|
---|
| 296 | void op_mov_RM (int op_size,int reg,int base_reg,int offset,char mod);
|
---|
| 297 | void op_mov_RM_ex (int op_size,int reg,int base_reg1,int base_reg2,int offset,BOOL bUseOffset);
|
---|
| 298 | void op_mov_MR (int op_size,int reg,int base_reg,int offset,char mod);
|
---|
| 299 | void op_mov_MR_ex (int op_size,int reg,int base_reg1,int base_reg2,int offset,BOOL bUseOffset);
|
---|
| 300 | void op_movsx_R32R16 (int reg32,int reg16);
|
---|
| 301 | void op_movsx_R32R8 (int reg32,int reg8);
|
---|
| 302 | void op_movsx_R16R8 (int reg16,int reg8);
|
---|
| 303 | void op_inc (int reg);
|
---|
| 304 | void op_dec (int reg);
|
---|
| 305 | void op_add_RV8 (int reg,char cValue);
|
---|
| 306 | void op_add_RM (int op_size,int reg,int base_reg,int offset,char mod);
|
---|
| 307 | void op_adc_RV8 (int reg,char cValue);
|
---|
| 308 | void op_sub_RV8 (int reg,char cValue);
|
---|
| 309 | void op_sbb_RV8 (int reg,char cValue);
|
---|
[36] | 310 | void op_sbb_RR ( int reg1, int reg2 );
|
---|
[64] | 311 | void op_imul_RR (int reg1,int reg2);
|
---|
| 312 | void op_imul_RV (int reg,int i32data);
|
---|
[3] | 313 | void op_and_RV (int reg,int value);
|
---|
[36] | 314 | void op_or_RR ( int op_size, int reg1, int reg2 );
|
---|
| 315 | void op_neg ( int reg );
|
---|
[3] | 316 | void op_cdq ();
|
---|
| 317 |
|
---|
| 318 | void op_rep_movs (int op_size);
|
---|
| 319 |
|
---|
| 320 | void op_push(int reg);
|
---|
[67] | 321 | void op_push_V(long data);
|
---|
[3] | 322 | void op_pop(int reg);
|
---|
| 323 | void op_add_esp(int num);
|
---|
| 324 | void op_sub_esp(int num);
|
---|
[64] | 325 | void op_cmp_RR( int reg1, int reg2 );
|
---|
[36] | 326 | void op_cmp_value(int op_size,int reg,char byte_data);
|
---|
| 327 | void op_setne( int reg );
|
---|
[3] | 328 | void op_test(int reg1,int reg2);
|
---|
| 329 | void op_fld_ptr_esp(int type);
|
---|
| 330 | void op_fld_basereg (int type,int base_reg);
|
---|
| 331 | void op_fld_base_offset (int type,int base_reg,int offset);
|
---|
| 332 | void op_fld_base_offset_ex (int type,int base_reg1,int base_reg2,int offset,BOOL bUseOffset);
|
---|
| 333 | void op_fstp_basereg (int type,int base_reg);
|
---|
| 334 | void op_fstp_base_offset (int type,int base_reg,int offset);
|
---|
| 335 | void op_fstp_base_offset_ex (int type,int base_reg1,int base_reg2,int offset,BOOL bUseOffset);
|
---|
[66] | 336 | void op_fistp_ptr_esp ( int typeSize );
|
---|
[3] | 337 | void op_zero_reg(int reg);
|
---|
| 338 | void fpu_cast();
|
---|
| 339 | void fpu_cast_end();
|
---|
| 340 |
|
---|
| 341 | void op_call(SUBINFO *psi);
|
---|