source: dev/trunk/ab5.0/abdev/compiler_x64/Opcode.h@ 797

Last change on this file since 797 was 704, checked in by dai_9181, 16 years ago

[702]を64bit版にマージ。

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