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

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