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

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