source: dev/trunk/abdev/BasicCompiler64/Opcode.h@ 262

Last change on this file since 262 was 262, checked in by dai_9181, 17 years ago
File size: 11.2 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;
18extern int obp;
19extern char *OpBuffer;
20
21#define breakpoint compiler.codeGenerator.PutOld( (char)0xCC );
22
23
24//プロシージャの種類
25#define PROC_DEFAULT 1 //ユーザー定義関数
26#define PROC_DLL 2 //DLL関数
27#define PROC_BUILTIN 3 //コンパイラ埋め込み型
28#define PROC_PTR 4 //関数ポインタ
29
30//プロシージャ
31struct PROCEDURE{
32 char name[255];
33 int address;
34 int types[MAX_PARMS];
35 _int8 ByVal[MAX_PARMS];
36 BOOL ReturnType;
37};
38
39//With情報
40struct WITHINFO{
41 char **ppName;
42 int *pWithCp;
43 int num;
44};
45
46
47class CStackFrame:public CSchedule{
48 ///////////////////////////
49 // スタックフレーム管理
50 ///////////////////////////
51
52 int lowest_sp; //スタックポインタの最下位位置
53 int now_sp; //スタックポインタ
54 int max_parm_size; //パラメータの最大サイズ
55
56public:
57 //コンストラクタ
58 CStackFrame();
59
60 //デストラクタ
61 ~CStackFrame();
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};
78extern CStackFrame *pobj_sf;
79
80
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
132 //レジスタが利用中かどうかを調べる
133 bool IsUsing( int reg );
134
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
176void ChangeOpcode(char *Command);
177void GetGlobalDataForDll(void);
178DWORD CompileBuffer(char Return_Sequence,WORD Return_Command);
179
180//Register.cpp
181BOOL IsGeneralReg(int reg);
182BOOL IsXmmReg(int reg);
183BOOL IsVolatileReg(int reg);
184void IfR14Push( int reg );
185
186//Compile_Calc.cpp
187void SetVariableFromRax(int VarType,int CalcType,RELATIVE_VAR *pRelativeVar);
188void OpcodeCalc(const char *Command);
189
190//NumOpe.cpp
191bool TermOpe(
192 const char *term,
193 const Type &baseType,
194 Type &resultType,
195 bool &isLiteral,
196 BOOL *pbUseHeap,
197 bool isWantObject = false,
198 bool *pIsClassName = NULL,
199 bool isProcedureCallOnly = false );
200bool NumOpe( int *pReg,
201 const char *Command,
202 const Type &baseType,
203 Type &resultType,
204 BOOL *pbUseHeap = NULL );
205
206//NumOpe_Arithmetic.cpp
207BOOL CalcTwoTerm_Arithmetic(int idCalc,int *type,LONG_PTR *index_stack,int *pStackPointer);
208BOOL Calc_Mod(int *type,LONG_PTR *index_stack,int *pStackPointer);
209BOOL Calc_Divide(int *type,int *pStackPointer,int BaseType);
210BOOL Calc_IntDivide(int *type,LONG_PTR *index_stack,int *pStackPointer);
211BOOL Calc_MinusMark(int *type,int sp);
212BOOL Calc_Power(int *type,int *pStackPointer);
213BOOL Calc_Shift(int idCalc,int *type,int *pStackPointer);
214
215//NumOpe_Logical.cpp
216BOOL CalcTwoTerm_Logical(int idCalc,int *type,LONG_PTR *index_stack,int *pStackPointer);
217BOOL Calc_Not(int *type,int sp);
218
219//NumOpe_Relation.cpp
220BOOL CalcTwoTerm_Relational(int idCalc,int *type,LONG_PTR *index_stack,int *pStackPointer);
221
222//NumOpe_TypeOperation.cpp
223void ExtendTypeTo64(int type,int reg);
224void ExtendTypeTo32(int type,int reg);
225void ExtendTypeTo16(int type,int reg);
226void ChangeTypeToXmm_Double(int type,int xmm_reg,int general_reg);
227void ChangeTypeToXmm_Single(int type,int xmm_reg,int general_reg);
228void ChangeTypeToWhole(int OldType,int NewType,int reg,int xmm_reg);
229void SetOneTermToReg_RealCalc(int TermType,int *pXmmReg);
230void SetOneTermToReg_Whole64Calc(int TermType,int *pReg);
231void SetOneTermToReg_Whole32Calc(int TermType,int *pReg);
232void SetTowTermToReg_RealCalc(int AnswerType,int *type,int sp,int *pXmmReg1,int *pXmmReg2);
233void SetTowTermToReg_Whole64Calc(int *type,int sp,int *pReg1,int *pReg2);
234void SetTowTermToReg_Whole32Calc(int *type,int sp,int *pReg1,int *pReg2);
235BOOL Calc_Cast(int *type,LONG_PTR *index_stack,int *pStackPointer);
236
237//Compile_Set_Var.cpp
238BOOL IsUse_r11(RELATIVE_VAR *pRelativeVar);
239void SetStructVariableFromRax( const Type &varType, const Type &calcType, RELATIVE_VAR *pRelativeVar,BOOL bUseHeap);
240void SetRealVariable(int VarType, int CalcType, RELATIVE_VAR *pRelativeVar);
241void SetBooleanVariable(int type,RELATIVE_VAR *pRelative);
242void SetWholeVariable(int varSize,int type,RELATIVE_VAR *pRelative);
243
244//increment.cpp
245void IncDec(int idCalc, const char *lpszLeft, const char *lpszRight);
246
247//Compile_Calc_PushVar.cpp
248void SetXmmReg_DoubleVariable(RELATIVE_VAR *pRelativeVar,int xmm_reg);
249void SetXmmReg_SingleVariable(RELATIVE_VAR *pRelativeVar,int xmm_reg);
250void SetReg_WholeVariable(int type,RELATIVE_VAR *pRelativeVar,int reg);
251
252//Compile_Interface.cpp
253bool CastToInterface( int reg, int vtblReg, const CClass &baseClass, const CClass &interfaceClass );
254
255//Compile_Object.cpp
256void Operator_New( const CClass &classObj, const char *objectSizeStr, const char *parameter,const Type &baseTypeInfo );
257void OpcodeDelete(const char *Parameter, bool isSweeping);
258
259//Compile_Var.cpp
260bool _member_offset(bool isErrorEnabled, bool isWriteAccess, const CClass &objClass, const char *member, RELATIVE_VAR *pRelativeVar, Type &resultType, BOOL bPrivateAccess);
261void SetThisPtrToReg(int reg);
262bool GetVarOffset(bool isErrorEnabled,bool isWriteAccess,const char *NameBuffer,RELATIVE_VAR *pRelativeVar,Type &resultType, Subscripts *pResultSubscripts = NULL );
263bool SetInitGlobalData(int offset,const Type &type,const Subscripts &subscripts,const char *InitBuf);
264#define DIMFLAG_INITDEBUGVAR 0x01
265#define DIMFLAG_NONCALL_CONSTRACTOR 0x02
266#define DIMFLAG_STATIC 0x04
267#define DIMFLAG_CONST 0x08
268void dim( char *VarName, const Subscripts &subscripts, Type &type, const char *InitBuf,const char *ConstractParameter,DWORD dwFlags);
269void SetVarPtrToReg(int reg,RELATIVE_VAR *pRelativeVar);
270bool Compile_AddGlobalRootsForGc();
271
272//ParamImpl.cpp
273class ParamImpl{
274 char *Parms[255];
275 vector<Type> types;
276 int ParmsNum;
277
278 Type returnType;
279
280 //一時オブジェクト管理用
281 bool useTempObject;
282 bool useTempParameters[255];
283 int StackOffsetOfTempObject[255];
284
285public:
286 ParamImpl(const char *buffer);
287 ParamImpl(const Parameters &params);
288 ~ParamImpl();
289 void SetReturnType( const Type &returnType );
290
291private:
292 bool EvaluateOverloadScore( int level, const Parameters &targetParms, const Type &targetResultType );
293
294public:
295 const UserProc *_OverloadSolution( const char *name, std::vector<const UserProc *> &subs, bool isEnabledReturnType = false );
296 const UserProc *OverloadSolution( const char *name, std::vector<const UserProc *> &subs, bool isEnabledReturnType = false );
297
298 void ApplyDefaultParameters( const Parameters &params );
299 bool ErrorCheck( const 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 string &procName, const Parameters &params, int SecondParmNum = -1 );
303
304 //一時オブジェクトパラメータの生成と破棄
305 int NewTempParameters( const 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,int RefType);
328bool Opcode_CallDllProc( const char *lpszParms,DllProc *pDllProc);
329
330//Compile_ProcOp.cpp
331void CompileLocal();
332
333//Compile_Func.cpp
334int GetFunctionFromName(char *FuncName);
335bool Opcode_CallFunc( const char *Parameter, const int FuncNum, Type &ReturnTypeInfo, bool isCallOn = true );
336
337//OperatorProc.cpp
338void FreeTempObject(int reg,const CClass *pobj_c);
339int CallOperatorProc(BYTE idCalc, const Type &baseType, int *type_stack,LONG_PTR *index_stack,BOOL *bUseHeap,int &sp);
340void CallCastOperatorProc(int reg,Type &calcType,BOOL bCalcUseHeap,const Type &toType);
341void CallIndexerGetterProc(int reg,const CClass *pobj_Class,char *ObjectName,char *Parameter,Type &resultType);
342
343//Compile_Statement.cpp
344void OpcodeOthers(const char *Command);
345void OpcodeIf(char *Parameter);
346void OpcodeGoto(char *Parameter);
347void OpcodeWhile(char *Parameter);
348void OpcodeFor(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.