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

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