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