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

Last change on this file since 682 was 603, checked in by dai_9181, 17 years ago

ObjectModuleに関連するクラス一式をab_commonプロジェクトに移動した。

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