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

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