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

Last change on this file since 351 was 350, 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//プロシージャ
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 ChangeOpcode(char *Command);
172void GetGlobalDataForDll(void);
173DWORD CompileBuffer(char Return_Sequence,WORD Return_Command);
174
175//Register.cpp
176BOOL IsGeneralReg(int reg);
177BOOL IsXmmReg(int reg);
178BOOL IsVolatileReg(int reg);
179void IfR14Push( int reg );
180
181//Compile_Calc.cpp
182void SetVariableFromRax( const Type &varType, int CalcType,RELATIVE_VAR *pRelativeVar);
183void OpcodeCalc(const char *Command);
184
185//NumOpe.cpp
186bool TermOpe(
187 const char *term,
188 const Type &baseType,
189 Type &resultType,
190 bool &isLiteral,
191 BOOL *pbUseHeap,
192 bool isWantObject = false,
193 bool *pIsClassName = NULL,
194 bool isProcedureCallOnly = false );
195bool NumOpe( int *pReg,
196 const char *Command,
197 const Type &baseType,
198 Type &resultType,
199 BOOL *pbUseHeap = 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 vector<Type> types;
268 int ParmsNum;
269
270 Type leftType;
271 Type returnType;
272
273 //一時オブジェクト管理用
274 bool useTempObject;
275 bool useTempParameters[255];
276 int StackOffsetOfTempObject[255];
277
278public:
279 ParamImpl(const char *buffer);
280 ParamImpl(const Parameters &params);
281 ~ParamImpl();
282 void SetLeftType( const Type &type )
283 {
284 this->leftType = type;
285 }
286 void SetReturnType( const Type &returnType );
287
288private:
289 bool EvaluateOverloadScore( int level, const Parameters &targetParms, const Type &targetResultType );
290
291public:
292 const UserProc *_OverloadSolution( const char *name, std::vector<const UserProc *> &subs, bool isEnabledReturnType = false );
293 const UserProc *OverloadSolution( const char *name, std::vector<const UserProc *> &subs, bool isEnabledReturnType = false );
294
295 void ApplyDefaultParameters( const Parameters &params );
296 bool ErrorCheck( const string &procName, const Parameters &params, int SecondParmNum = -1 );
297 void MacroParameterSupport( const Parameters &params );
298 void SetStructParameter( int reg, const Type &baseType, const char *expression );
299 void SetParameter( const string &procName, const Parameters &params, int SecondParmNum = -1, const UserProc *pUserProc = NULL );
300
301 //一時オブジェクトパラメータの生成と破棄
302 int NewTempParameters( const string &procName, const Parameters &params, int SecondParmNum = -1 );
303 void DeleteTempParameters();
304
305 void BackupParameter(int pi_num);
306 void RestoreParameter(int pi_num);
307};
308
309//CLockParameter.cpp
310#define MAX_LOCKPARMS 255
311class CDBLockParms{
312public:
313 int array_LevelCount[MAX_LOCKPARMS];
314 CDBLockParms();
315 ~CDBLockParms();
316
317 void lock(int level);
318 void unlock(int level);
319};
320
321//Compile_CallProc.cpp
322#define PROCFLAG_NEW 1
323bool Opcode_CallProcPtr(const char *variable, const char *lpszParms,ProcPointer *pProcPointer);
324bool Opcode_CallProc(const char *Parameter,const UserProc *pUserProc,DWORD dwFlags,const char *ObjectName);
325bool Opcode_CallDllProc( const char *lpszParms,DllProc *pDllProc);
326void Opcode_CallDelegate( const Delegate &dg, const char *methodPtrValueStr, const char *objPtrValueStr, const char *params );
327
328//Compile_ProcOp.cpp
329void _compile_proc(const UserProc *pUserProc);
330
331//Compile_Func.cpp
332int GetFunctionFromName(char *FuncName);
333bool Opcode_CallFunc( const char *Parameter, const int FuncNum, const Type &baseType, Type &resultType, bool isCallOn = true );
334
335//OperatorProc.cpp
336void FreeTempObject(int reg,const CClass *pobj_c);
337int CallOperatorProc(BYTE idCalc, const Type &baseType, int *type_stack,LONG_PTR *index_stack,BOOL *bUseHeap,int &sp);
338void CallCastOperatorProc(int reg,Type &calcType,BOOL bCalcUseHeap,const Type &toType);
339void CallIndexerGetterProc(int reg, const Type &classType, const char *ObjectName,char *Parameter,Type &resultType, DWORD dwProcFlags = 0 );
340
341//Compile_Statement.cpp
342void OpcodeOthers(const char *Command);
343void OpcodeIf(char *Parameter);
344void OpcodeGoto(char *Parameter);
345void OpcodeWhile(char *Parameter);
346void OpcodeFor(char *Parameter);
347void OpcodeDo(char *Parameter);
348void OpcodeContinue(void);
349void OpcodeExitSub(void);
350void OpcodeSelect( const char *Parameter );
351void OpcodeCase(char *Parameter);
352void OpcodeGosub(char *Parameter);
353void OpcodeReturn(char *Parameter);
354void OpcodeSetPtrData(char *Parameter,int type);
355
356
357//InsertOpcode.cpp
358void InsertDimStatement_ToProcHead(char *lpszCommand);
359
360
361BOOL IsSafeReg(int reg);
Note: See TracBrowser for help on using the repository browser.