[206] | 1 | #pragma once
|
---|
[3] | 2 |
|
---|
[206] | 3 | #include <Type.h>
|
---|
| 4 | #include <Procedure.h>
|
---|
[226] | 5 | #include "MachineFixed.h"
|
---|
[3] | 6 |
|
---|
[206] | 7 |
|
---|
[3] | 8 | //変数の種類
|
---|
[40] | 9 | #define NON_VAR 0
|
---|
[62] | 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 |
|
---|
[40] | 16 |
|
---|
[3] | 17 | extern int cp;
|
---|
| 18 | extern int obp;
|
---|
| 19 | extern char *OpBuffer;
|
---|
| 20 |
|
---|
[255] | 21 | #define breakpoint compiler.codeGenerator.PutOld( (char)0xCC );
|
---|
[49] | 22 |
|
---|
| 23 |
|
---|
[3] | 24 | //ラベルアドレス
|
---|
| 25 | struct LABEL{
|
---|
| 26 | char *pName;
|
---|
| 27 | int line;
|
---|
| 28 | DWORD address;
|
---|
| 29 | };
|
---|
| 30 |
|
---|
| 31 |
|
---|
| 32 | //プロシージャの種類
|
---|
| 33 | #define PROC_DEFAULT 1 //ユーザー定義関数
|
---|
| 34 | #define PROC_DLL 2 //DLL関数
|
---|
| 35 | #define PROC_BUILTIN 3 //コンパイラ埋め込み型
|
---|
| 36 | #define PROC_PTR 4 //関数ポインタ
|
---|
| 37 |
|
---|
| 38 | //プロシージャ
|
---|
| 39 | struct PROCEDURE{
|
---|
| 40 | char name[255];
|
---|
| 41 | int address;
|
---|
| 42 | int types[MAX_PARMS];
|
---|
| 43 | _int8 ByVal[MAX_PARMS];
|
---|
| 44 | BOOL ReturnType;
|
---|
| 45 | };
|
---|
| 46 |
|
---|
| 47 | //With情報
|
---|
| 48 | struct WITHINFO{
|
---|
| 49 | char **ppName;
|
---|
| 50 | int *pWithCp;
|
---|
| 51 | int num;
|
---|
| 52 | };
|
---|
| 53 |
|
---|
| 54 |
|
---|
| 55 | class CStackFrame:public CSchedule{
|
---|
| 56 | ///////////////////////////
|
---|
| 57 | // スタックフレーム管理
|
---|
| 58 | ///////////////////////////
|
---|
| 59 |
|
---|
| 60 | int lowest_sp; //スタックポインタの最下位位置
|
---|
| 61 | int now_sp; //スタックポインタ
|
---|
| 62 | int max_parm_size; //パラメータの最大サイズ
|
---|
| 63 |
|
---|
| 64 | public:
|
---|
| 65 | //コンストラクタ
|
---|
| 66 | CStackFrame();
|
---|
| 67 |
|
---|
| 68 | //デストラクタ
|
---|
| 69 | ~CStackFrame();
|
---|
| 70 |
|
---|
[220] | 71 | int GetFrameSize( int localParamSize );
|
---|
[64] | 72 | int GetNowSp();
|
---|
| 73 | void mov_sp( int reg );
|
---|
[20] | 74 | int push(int reg);
|
---|
[66] | 75 | void push(int xmm_reg,int varSize);
|
---|
[20] | 76 | void ref_offset_data( int reg, int sp_offset );
|
---|
[3] | 77 | void ref(int reg);
|
---|
[66] | 78 | void ref(int xmm_reg,int varSize);
|
---|
[64] | 79 | void pop(int reg = REG_NON);
|
---|
[66] | 80 | void pop(int xmm_reg,int varSize);
|
---|
[3] | 81 | void parameter_allocate(int size);
|
---|
[220] | 82 | void RunningSchedule( int stackFrameSize );
|
---|
[3] | 83 |
|
---|
| 84 | void error_check(void);
|
---|
| 85 | };
|
---|
| 86 | extern CStackFrame *pobj_sf;
|
---|
| 87 |
|
---|
| 88 |
|
---|
| 89 | class CBlockReg{
|
---|
| 90 | int array_BlockReg[256];
|
---|
| 91 | int num;
|
---|
| 92 |
|
---|
| 93 | public:
|
---|
| 94 | CBlockReg();
|
---|
| 95 | void lock(int reg);
|
---|
| 96 | void unlock(int reg);
|
---|
| 97 | BOOL check(int reg);
|
---|
| 98 | void clear(void);
|
---|
| 99 |
|
---|
| 100 | //レジスタのバックアップと復旧
|
---|
| 101 | void backup();
|
---|
| 102 | void restore();
|
---|
| 103 | };
|
---|
| 104 | extern CBlockReg *pobj_BlockReg;
|
---|
| 105 | class CRegister{
|
---|
| 106 | ////////////////////
|
---|
| 107 | // レジスタ管理
|
---|
| 108 | ////////////////////
|
---|
| 109 |
|
---|
| 110 | //利用可能なレジスタを列挙する関数
|
---|
| 111 | void EnumRegister(int *pRegList,int nMaxList,int *array_reg,int *sp,int AnswerReg);
|
---|
| 112 |
|
---|
| 113 | int array_UseReg[16],sp_UseReg;
|
---|
| 114 |
|
---|
| 115 | int array_XmmReg[16];
|
---|
| 116 | int sp_XmmReg;
|
---|
| 117 |
|
---|
| 118 | int init_sp_reg,init_sp_xmm_reg;
|
---|
| 119 |
|
---|
| 120 | public:
|
---|
| 121 | CRegister(){};
|
---|
| 122 | CRegister(int AnswerReg);
|
---|
| 123 | ~CRegister(){};
|
---|
| 124 |
|
---|
| 125 | //コンパイラにバグがないかをチェックする機構
|
---|
| 126 | void bug_check();
|
---|
| 127 |
|
---|
| 128 | //汎用レジスタ
|
---|
| 129 | int GetNextReg();
|
---|
| 130 | int GetLockingReg();
|
---|
| 131 | int LockReg();
|
---|
| 132 | int UnlockReg();
|
---|
| 133 |
|
---|
| 134 | //XMMレジスタ
|
---|
| 135 | int GetNextXmmReg();
|
---|
| 136 | int GetLockingXmmReg();
|
---|
| 137 | int LockXmmReg();
|
---|
| 138 | int UnlockXmmReg();
|
---|
| 139 |
|
---|
[19] | 140 | //レジスタが利用中かどうかを調べる
|
---|
| 141 | bool IsUsing( int reg );
|
---|
| 142 |
|
---|
[3] | 143 | //レジスタのバックアップと復旧
|
---|
| 144 | void backup();
|
---|
| 145 | void restore();
|
---|
| 146 | };
|
---|
| 147 | extern CRegister *pobj_reg;
|
---|
| 148 |
|
---|
| 149 |
|
---|
| 150 | #define BACKUP_REGISTER_RESOURCE \
|
---|
| 151 | /* レジスタをスタックフレームにバックアップ */ \
|
---|
| 152 | pobj_BlockReg->backup(); \
|
---|
| 153 | if(pobj_reg) pobj_reg->backup(); \
|
---|
| 154 | \
|
---|
| 155 | /* レジスタブロッキングオブジェクトを退避して再生成 */ \
|
---|
| 156 | CBlockReg *pobj_BlockReg_back; \
|
---|
| 157 | pobj_BlockReg_back=pobj_BlockReg; \
|
---|
| 158 | pobj_BlockReg=new CBlockReg; \
|
---|
| 159 | \
|
---|
| 160 | /* レジスタ管理オブジェクトポインタを退避して0をセット */ \
|
---|
| 161 | CRegister *pobj_reg_back; \
|
---|
| 162 | pobj_reg_back=pobj_reg; \
|
---|
| 163 | pobj_reg=0;
|
---|
| 164 |
|
---|
| 165 | #define RESTORE_REGISTER_RESOURCE \
|
---|
| 166 | /* レジスタブロッキングオブジェクトポインタを復元 */ \
|
---|
| 167 | delete pobj_BlockReg; \
|
---|
| 168 | pobj_BlockReg=pobj_BlockReg_back; \
|
---|
| 169 | \
|
---|
| 170 | /* レジスタ管理オブジェクトポインタを復元 */ \
|
---|
| 171 | delete pobj_reg; \
|
---|
| 172 | pobj_reg=pobj_reg_back; \
|
---|
| 173 | \
|
---|
| 174 | /* レジスタをスタックフレームから復元 */ \
|
---|
| 175 | if(pobj_reg) pobj_reg->restore(); \
|
---|
| 176 | pobj_BlockReg->restore();
|
---|
| 177 |
|
---|
| 178 |
|
---|
| 179 |
|
---|
| 180 | //RSrcSection.cpp
|
---|
| 181 | char *GetRSrcSectionBuffer(int *pLen);
|
---|
| 182 |
|
---|
| 183 | //Compile.cpp
|
---|
| 184 | void ChangeOpcode(char *Command);
|
---|
| 185 | void GetGlobalDataForDll(void);
|
---|
| 186 | DWORD CompileBuffer(char Return_Sequence,WORD Return_Command);
|
---|
| 187 |
|
---|
| 188 | //Register.cpp
|
---|
| 189 | BOOL IsGeneralReg(int reg);
|
---|
| 190 | BOOL IsXmmReg(int reg);
|
---|
| 191 | BOOL IsVolatileReg(int reg);
|
---|
[131] | 192 | void IfR14Push( int reg );
|
---|
[3] | 193 |
|
---|
| 194 | //Compile_Calc.cpp
|
---|
| 195 | void SetVariableFromRax(int VarType,int CalcType,RELATIVE_VAR *pRelativeVar);
|
---|
[129] | 196 | void OpcodeCalc(const char *Command);
|
---|
[3] | 197 |
|
---|
| 198 | //NumOpe.cpp
|
---|
[128] | 199 | bool TermOpe(
|
---|
| 200 | const char *term,
|
---|
| 201 | const Type &baseType,
|
---|
| 202 | Type &resultType,
|
---|
| 203 | bool &isLiteral,
|
---|
| 204 | BOOL *pbUseHeap,
|
---|
| 205 | bool isWantObject = false,
|
---|
| 206 | bool *pIsClassName = NULL,
|
---|
| 207 | bool isProcedureCallOnly = false );
|
---|
[75] | 208 | bool NumOpe( int *pReg,
|
---|
| 209 | const char *Command,
|
---|
| 210 | const Type &baseType,
|
---|
| 211 | Type &resultType,
|
---|
| 212 | BOOL *pbUseHeap = NULL );
|
---|
[3] | 213 |
|
---|
| 214 | //NumOpe_Arithmetic.cpp
|
---|
| 215 | BOOL CalcTwoTerm_Arithmetic(int idCalc,int *type,LONG_PTR *index_stack,int *pStackPointer);
|
---|
| 216 | BOOL Calc_Mod(int *type,LONG_PTR *index_stack,int *pStackPointer);
|
---|
| 217 | BOOL Calc_Divide(int *type,int *pStackPointer,int BaseType);
|
---|
| 218 | BOOL Calc_IntDivide(int *type,LONG_PTR *index_stack,int *pStackPointer);
|
---|
| 219 | BOOL Calc_MinusMark(int *type,int sp);
|
---|
| 220 | BOOL Calc_Power(int *type,int *pStackPointer);
|
---|
| 221 | BOOL Calc_Shift(int idCalc,int *type,int *pStackPointer);
|
---|
| 222 |
|
---|
| 223 | //NumOpe_Logical.cpp
|
---|
| 224 | BOOL CalcTwoTerm_Logical(int idCalc,int *type,LONG_PTR *index_stack,int *pStackPointer);
|
---|
| 225 | BOOL Calc_Not(int *type,int sp);
|
---|
| 226 |
|
---|
| 227 | //NumOpe_Relation.cpp
|
---|
| 228 | BOOL CalcTwoTerm_Relational(int idCalc,int *type,LONG_PTR *index_stack,int *pStackPointer);
|
---|
| 229 |
|
---|
| 230 | //NumOpe_TypeOperation.cpp
|
---|
| 231 | void ExtendTypeTo64(int type,int reg);
|
---|
| 232 | void ExtendTypeTo32(int type,int reg);
|
---|
| 233 | void ExtendTypeTo16(int type,int reg);
|
---|
| 234 | void ChangeTypeToXmm_Double(int type,int xmm_reg,int general_reg);
|
---|
| 235 | void ChangeTypeToXmm_Single(int type,int xmm_reg,int general_reg);
|
---|
| 236 | void ChangeTypeToWhole(int OldType,int NewType,int reg,int xmm_reg);
|
---|
| 237 | void SetOneTermToReg_RealCalc(int TermType,int *pXmmReg);
|
---|
| 238 | void SetOneTermToReg_Whole64Calc(int TermType,int *pReg);
|
---|
| 239 | void SetOneTermToReg_Whole32Calc(int TermType,int *pReg);
|
---|
| 240 | void SetTowTermToReg_RealCalc(int AnswerType,int *type,int sp,int *pXmmReg1,int *pXmmReg2);
|
---|
| 241 | void SetTowTermToReg_Whole64Calc(int *type,int sp,int *pReg1,int *pReg2);
|
---|
| 242 | void SetTowTermToReg_Whole32Calc(int *type,int sp,int *pReg1,int *pReg2);
|
---|
| 243 | BOOL Calc_Cast(int *type,LONG_PTR *index_stack,int *pStackPointer);
|
---|
| 244 |
|
---|
| 245 | //Compile_Set_Var.cpp
|
---|
| 246 | BOOL IsUse_r11(RELATIVE_VAR *pRelativeVar);
|
---|
[75] | 247 | void SetStructVariableFromRax( const Type &varType, const Type &calcType, RELATIVE_VAR *pRelativeVar,BOOL bUseHeap);
|
---|
[64] | 248 | void SetRealVariable(int VarType, int CalcType, RELATIVE_VAR *pRelativeVar);
|
---|
[36] | 249 | void SetBooleanVariable(int type,RELATIVE_VAR *pRelative);
|
---|
[66] | 250 | void SetWholeVariable(int varSize,int type,RELATIVE_VAR *pRelative);
|
---|
[3] | 251 |
|
---|
| 252 | //increment.cpp
|
---|
[129] | 253 | void IncDec(int idCalc, const char *lpszLeft, const char *lpszRight);
|
---|
[3] | 254 |
|
---|
| 255 | //Compile_Calc_PushVar.cpp
|
---|
| 256 | void SetXmmReg_DoubleVariable(RELATIVE_VAR *pRelativeVar,int xmm_reg);
|
---|
| 257 | void SetXmmReg_SingleVariable(RELATIVE_VAR *pRelativeVar,int xmm_reg);
|
---|
| 258 | void SetReg_WholeVariable(int type,RELATIVE_VAR *pRelativeVar,int reg);
|
---|
| 259 |
|
---|
[131] | 260 | //Compile_Interface.cpp
|
---|
| 261 | bool CastToInterface( int reg, int vtblReg, const CClass &baseClass, const CClass &interfaceClass );
|
---|
| 262 |
|
---|
[3] | 263 | //Compile_Object.cpp
|
---|
[75] | 264 | void Operator_New( const CClass &classObj, const char *objectSizeStr, const char *parameter,const Type &baseTypeInfo );
|
---|
[64] | 265 | void OpcodeDelete(const char *Parameter, bool isSweeping);
|
---|
[3] | 266 |
|
---|
| 267 | //Compile_Var.cpp
|
---|
[97] | 268 | bool _member_offset(bool isErrorEnabled, bool isWriteAccess, const CClass &objClass, const char *member, RELATIVE_VAR *pRelativeVar, Type &resultType, BOOL bPrivateAccess);
|
---|
[3] | 269 | void SetThisPtrToReg(int reg);
|
---|
[206] | 270 | bool GetVarOffset(bool isErrorEnabled,bool isWriteAccess,const char *NameBuffer,RELATIVE_VAR *pRelativeVar,Type &resultType, Subscripts *pResultSubscripts = NULL );
|
---|
| 271 | bool SetInitGlobalData(int offset,const Type &type,const Subscripts &subscripts,const char *InitBuf);
|
---|
[40] | 272 | #define DIMFLAG_INITDEBUGVAR 0x01
|
---|
| 273 | #define DIMFLAG_NONCALL_CONSTRACTOR 0x02
|
---|
| 274 | #define DIMFLAG_STATIC 0x04
|
---|
| 275 | #define DIMFLAG_CONST 0x08
|
---|
[206] | 276 | void dim( char *VarName, const Subscripts &subscripts, Type &type, const char *InitBuf,const char *ConstractParameter,DWORD dwFlags);
|
---|
[3] | 277 | void SetVarPtrToReg(int reg,RELATIVE_VAR *pRelativeVar);
|
---|
[95] | 278 | bool Compile_AddGlobalRootsForGc();
|
---|
[3] | 279 |
|
---|
[71] | 280 | //ParamImpl.cpp
|
---|
| 281 | class ParamImpl{
|
---|
[3] | 282 | char *Parms[255];
|
---|
[75] | 283 | vector<Type> types;
|
---|
[3] | 284 | int ParmsNum;
|
---|
| 285 |
|
---|
[75] | 286 | Type returnType;
|
---|
[3] | 287 |
|
---|
[20] | 288 | //一時オブジェクト管理用
|
---|
| 289 | bool useTempObject;
|
---|
| 290 | bool useTempParameters[255];
|
---|
| 291 | int StackOffsetOfTempObject[255];
|
---|
| 292 |
|
---|
[3] | 293 | public:
|
---|
[71] | 294 | ParamImpl(const char *buffer);
|
---|
[75] | 295 | ParamImpl(const Parameters ¶ms);
|
---|
[71] | 296 | ~ParamImpl();
|
---|
[75] | 297 | void SetReturnType( const Type &returnType );
|
---|
[3] | 298 |
|
---|
| 299 | private:
|
---|
[140] | 300 | bool EvaluateOverloadScore( int level, const Parameters &targetParms, const Type &targetResultType );
|
---|
| 301 |
|
---|
[3] | 302 | public:
|
---|
[206] | 303 | const UserProc *_OverloadSolution( const char *name, std::vector<const UserProc *> &subs, bool isEnabledReturnType = false );
|
---|
| 304 | const UserProc *OverloadSolution( const char *name, std::vector<const UserProc *> &subs, bool isEnabledReturnType = false );
|
---|
[3] | 305 |
|
---|
[77] | 306 | void ApplyDefaultParameters( const Parameters ¶ms );
|
---|
[75] | 307 | bool ErrorCheck( const string &procName, const Parameters ¶ms, int SecondParmNum = -1 );
|
---|
| 308 | void MacroParameterSupport( const Parameters ¶ms );
|
---|
| 309 | void SetStructParameter( int reg, const Type &baseType, const char *expression );
|
---|
| 310 | void SetParameter( const string &procName, const Parameters ¶ms, int SecondParmNum = -1 );
|
---|
[20] | 311 |
|
---|
| 312 | //一時オブジェクトパラメータの生成と破棄
|
---|
[75] | 313 | int NewTempParameters( const string &procName, const Parameters ¶ms, int SecondParmNum = -1 );
|
---|
[20] | 314 | void DeleteTempParameters();
|
---|
| 315 |
|
---|
[3] | 316 | void BackupParameter(int pi_num);
|
---|
| 317 | void RestoreParameter(int pi_num);
|
---|
| 318 | };
|
---|
| 319 |
|
---|
| 320 | //CLockParameter.cpp
|
---|
| 321 | #define MAX_LOCKPARMS 255
|
---|
| 322 | class CDBLockParms{
|
---|
| 323 | public:
|
---|
| 324 | int array_LevelCount[MAX_LOCKPARMS];
|
---|
| 325 | CDBLockParms();
|
---|
| 326 | ~CDBLockParms();
|
---|
| 327 |
|
---|
| 328 | void lock(int level);
|
---|
| 329 | void unlock(int level);
|
---|
| 330 | };
|
---|
| 331 |
|
---|
| 332 | //Compile_CallProc.cpp
|
---|
| 333 | #define PROCFLAG_NEW 1
|
---|
[75] | 334 | bool Opcode_CallProcPtr(const char *variable, const char *lpszParms,ProcPointer *pProcPointer);
|
---|
[206] | 335 | bool Opcode_CallProc(const char *Parameter,const UserProc *pUserProc,DWORD dwFlags,const char *ObjectName,int RefType);
|
---|
[75] | 336 | bool Opcode_CallDllProc( const char *lpszParms,DllProc *pDllProc);
|
---|
[3] | 337 |
|
---|
| 338 | //Compile_ProcOp.cpp
|
---|
| 339 | void CompileLocal();
|
---|
| 340 |
|
---|
| 341 | //Compile_Func.cpp
|
---|
| 342 | int GetFunctionFromName(char *FuncName);
|
---|
[75] | 343 | bool Opcode_CallFunc( const char *Parameter, const int FuncNum, Type &ReturnTypeInfo, bool isCallOn = true );
|
---|
[3] | 344 |
|
---|
| 345 | //OperatorProc.cpp
|
---|
[75] | 346 | void FreeTempObject(int reg,const CClass *pobj_c);
|
---|
[206] | 347 | int CallOperatorProc(BYTE idCalc, const Type &baseType, int *type_stack,LONG_PTR *index_stack,BOOL *bUseHeap,int &sp);
|
---|
[75] | 348 | void CallCastOperatorProc(int reg,Type &calcType,BOOL bCalcUseHeap,const Type &toType);
|
---|
| 349 | void CallIndexerGetterProc(int reg,const CClass *pobj_Class,char *ObjectName,char *Parameter,Type &resultType);
|
---|
[3] | 350 |
|
---|
| 351 | //Compile_Statement.cpp
|
---|
[129] | 352 | void OpcodeOthers(const char *Command);
|
---|
[3] | 353 | void OpcodeIf(char *Parameter);
|
---|
| 354 | void OpcodeGoto(char *Parameter);
|
---|
| 355 | void OpcodeWhile(char *Parameter);
|
---|
| 356 | void OpcodeFor(char *Parameter);
|
---|
| 357 | void OpcodeDo(char *Parameter);
|
---|
| 358 | void OpcodeContinue(void);
|
---|
| 359 | void OpcodeExitSub(void);
|
---|
[75] | 360 | void OpcodeSelect( const char *Parameter );
|
---|
[3] | 361 | void OpcodeCase(char *Parameter);
|
---|
| 362 | void OpcodeGosub(char *Parameter);
|
---|
| 363 | void OpcodeReturn(char *Parameter);
|
---|
| 364 | void OpcodeSetPtrData(char *Parameter,int type);
|
---|
| 365 |
|
---|
| 366 |
|
---|
| 367 | //InsertOpcode.cpp
|
---|
| 368 | void InsertDimStatement_ToProcHead(char *lpszCommand);
|
---|
| 369 |
|
---|
| 370 |
|
---|
| 371 | BOOL IsSafeReg(int reg);
|
---|