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

Last change on this file since 580 was 528, checked in by dai_9181, 17 years ago

[522][527]を64bit版にマージ。

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