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

Last change on this file since 309 was 309, 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;
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 CClass &objClass, 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 returnType;
280
281 //一時オブジェクト管理用
282 bool useTempObject;
283 bool useTempParameters[255];
284 int StackOffsetOfTempObject[255];
285
286public:
287 ParamImpl(const char *buffer);
288 ParamImpl(const Parameters &params);
289 ~ParamImpl();
290 void SetReturnType( const Type &returnType );
291
292private:
293 bool EvaluateOverloadScore( int level, const Parameters &targetParms, const Type &targetResultType );
294
295public:
296 const UserProc *_OverloadSolution( const char *name, std::vector<const UserProc *> &subs, bool isEnabledReturnType = false );
297 const UserProc *OverloadSolution( const char *name, std::vector<const UserProc *> &subs, bool isEnabledReturnType = false );
298
299 void ApplyDefaultParameters( const Parameters &params );
300 bool ErrorCheck( const string &procName, const Parameters &params, int SecondParmNum = -1 );
301 void MacroParameterSupport( const Parameters &params );
302 void SetStructParameter( int reg, const Type &baseType, const char *expression );
303 void SetParameter( const string &procName, const Parameters &params, int SecondParmNum = -1 );
304
305 //一時オブジェクトパラメータの生成と破棄
306 int NewTempParameters( const string &procName, const Parameters &params, int SecondParmNum = -1 );
307 void DeleteTempParameters();
308
309 void BackupParameter(int pi_num);
310 void RestoreParameter(int pi_num);
311};
312
313//CLockParameter.cpp
314#define MAX_LOCKPARMS 255
315class CDBLockParms{
316public:
317 int array_LevelCount[MAX_LOCKPARMS];
318 CDBLockParms();
319 ~CDBLockParms();
320
321 void lock(int level);
322 void unlock(int level);
323};
324
325//Compile_CallProc.cpp
326#define PROCFLAG_NEW 1
327bool Opcode_CallProcPtr(const char *variable, const char *lpszParms,ProcPointer *pProcPointer);
328bool Opcode_CallProc(const char *Parameter,const UserProc *pUserProc,DWORD dwFlags,const char *ObjectName);
329bool Opcode_CallDllProc( const char *lpszParms,DllProc *pDllProc);
330
331//Compile_ProcOp.cpp
332void CompileLocal();
333
334//Compile_Func.cpp
335int GetFunctionFromName(char *FuncName);
336bool Opcode_CallFunc( const char *Parameter, const int FuncNum, Type &ReturnTypeInfo, 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 *bUseHeap,int &sp);
341void CallCastOperatorProc(int reg,Type &calcType,BOOL bCalcUseHeap,const Type &toType);
342void CallIndexerGetterProc(int reg,const CClass *pobj_Class,char *ObjectName,char *Parameter,Type &resultType);
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 OpcodeDo(char *Parameter);
351void OpcodeContinue(void);
352void OpcodeExitSub(void);
353void OpcodeSelect( const char *Parameter );
354void OpcodeCase(char *Parameter);
355void OpcodeGosub(char *Parameter);
356void OpcodeReturn(char *Parameter);
357void OpcodeSetPtrData(char *Parameter,int type);
358
359
360//InsertOpcode.cpp
361void InsertDimStatement_ToProcHead(char *lpszCommand);
362
363
364BOOL IsSafeReg(int reg);
Note: See TracBrowser for help on using the repository browser.