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

Last change on this file since 376 was 372, checked in by dai_9181, 17 years ago

Foreachステートメントを実装中…

File size: 11.3 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 Compile( const char *source );
172void ChangeOpcode(char *Command);
173void GetGlobalDataForDll(void);
174DWORD CompileBuffer(char Return_Sequence,WORD Return_Command);
175
176//Register.cpp
177BOOL IsGeneralReg(int reg);
178BOOL IsXmmReg(int reg);
179BOOL IsVolatileReg(int reg);
180void IfR14Push( int reg );
181
182//Compile_Calc.cpp
183void SetVariableFromRax( const Type &varType, int CalcType,RELATIVE_VAR *pRelativeVar);
184void OpcodeCalc(const char *Command);
185
186//NumOpe.cpp
187bool TermOpe(
188 const char *term,
189 const Type &baseType,
190 Type &resultType,
191 bool &isLiteral,
192 BOOL *pbUseHeap,
193 bool isWantObject = false,
194 bool *pIsClassName = NULL,
195 bool isProcedureCallOnly = false );
196bool NumOpe( int *pReg,
197 const char *Command,
198 const Type &baseType,
199 Type &resultType,
200 BOOL *pbUseHeap = NULL );
201
202//NumOpe_Arithmetic.cpp
203BOOL CalcTwoTerm_Arithmetic(int idCalc,int *type,LONG_PTR *index_stack,int *pStackPointer);
204BOOL Calc_Mod(int *type,LONG_PTR *index_stack,int *pStackPointer);
205BOOL Calc_Divide(int *type,int *pStackPointer,int BaseType);
206BOOL Calc_IntDivide(int *type,LONG_PTR *index_stack,int *pStackPointer);
207BOOL Calc_MinusMark(int *type,int sp);
208BOOL Calc_Power(int *type,int *pStackPointer);
209BOOL Calc_Shift(int idCalc,int *type,int *pStackPointer);
210
211//NumOpe_Logical.cpp
212BOOL CalcTwoTerm_Logical(int idCalc,int *type,LONG_PTR *index_stack,int *pStackPointer);
213BOOL Calc_Not(int *type,int sp);
214
215//NumOpe_Relation.cpp
216BOOL CalcTwoTerm_Relational(int idCalc,int *type,LONG_PTR *index_stack,int *pStackPointer);
217
218//NumOpe_TypeOperation.cpp
219void ExtendTypeTo64( const Type &oldType, int reg );
220void ExtendTypeTo32( const Type &oldType, int reg );
221void ExtendTypeTo16( const Type &oldType, int reg );
222void ChangeTypeToXmm_Double(int type,int xmm_reg,int general_reg);
223void ChangeTypeToXmm_Single(int type,int xmm_reg,int general_reg);
224void ChangeTypeToWhole( const Type &oldType, const Type &newType, int reg, int xmm_reg );
225void SetOneTermToReg_RealCalc(int TermType,int *pXmmReg);
226void SetOneTermToReg_Whole64Calc(int TermType,int *pReg);
227void SetOneTermToReg_Whole32Calc(int TermType,int *pReg);
228void SetTowTermToReg_RealCalc(int AnswerType,int *type,int sp,int *pXmmReg1,int *pXmmReg2);
229void SetTowTermToReg_Whole64Calc(int *type,int sp,int *pReg1,int *pReg2);
230void SetTowTermToReg_Whole32Calc(int *type,int sp,int *pReg1,int *pReg2);
231BOOL Calc_Cast(int *type,LONG_PTR *index_stack,int *pStackPointer);
232
233//Compile_Set_Var.cpp
234BOOL IsUse_r11(RELATIVE_VAR *pRelativeVar);
235void SetStructVariableFromRax( const Type &varType, const Type &calcType, RELATIVE_VAR *pRelativeVar,BOOL bUseHeap);
236void SetRealVariable(int VarType, int CalcType, RELATIVE_VAR *pRelativeVar);
237void SetBooleanVariable(int type,RELATIVE_VAR *pRelative);
238void SetWholeVariable(int varSize,int type,RELATIVE_VAR *pRelative);
239
240//increment.cpp
241void IncDec(int idCalc, const char *lpszLeft, const char *lpszRight);
242
243//Compile_Calc_PushVar.cpp
244void SetXmmReg_DoubleVariable(RELATIVE_VAR *pRelativeVar,int xmm_reg);
245void SetXmmReg_SingleVariable(RELATIVE_VAR *pRelativeVar,int xmm_reg);
246void SetReg_WholeVariable( const Type &type, RELATIVE_VAR *pRelativeVar,int reg);
247
248//Compile_Object.cpp
249void Operator_New( const CClass &classObj, const char *objectSizeStr, const char *parameter,const Type &baseTypeInfo );
250void OpcodeDelete(const char *Parameter, bool isSweeping);
251
252//Compile_Var.cpp
253bool _member_offset(bool isErrorEnabled, bool isWriteAccess, const Type &classType, const char *member, RELATIVE_VAR *pRelativeVar, Type &resultType, BOOL bPrivateAccess);
254void SetThisPtrToReg(int reg);
255bool GetVarOffset(bool isErrorEnabled,bool isWriteAccess,const char *NameBuffer,RELATIVE_VAR *pRelativeVar,Type &resultType, Subscripts *pResultSubscripts = NULL );
256bool SetInitGlobalData(int offset,const Type &type,const Subscripts &subscripts,const char *InitBuf);
257#define DIMFLAG_INITDEBUGVAR 0x01
258#define DIMFLAG_NONCALL_CONSTRACTOR 0x02
259#define DIMFLAG_STATIC 0x04
260#define DIMFLAG_CONST 0x08
261void dim( char *VarName, const Subscripts &subscripts, const Type &type, const char *InitBuf,const char *ConstractParameter,DWORD dwFlags);
262void SetVarPtrToReg(int reg,RELATIVE_VAR *pRelativeVar);
263bool Compile_AddGlobalRootsForGc();
264
265//ParamImpl.cpp
266class ParamImpl{
267 char *Parms[255];
268 vector<Type> types;
269 int ParmsNum;
270
271 Type leftType;
272 Type returnType;
273
274 //一時オブジェクト管理用
275 bool useTempObject;
276 bool useTempParameters[255];
277 int StackOffsetOfTempObject[255];
278
279public:
280 ParamImpl(const char *buffer);
281 ParamImpl(const Parameters &params);
282 ~ParamImpl();
283 void SetLeftType( const Type &type )
284 {
285 this->leftType = type;
286 }
287 void SetReturnType( const Type &returnType );
288
289private:
290 bool EvaluateOverloadScore( int level, const Parameters &targetParms, const Type &targetResultType, bool &isErrored );
291
292public:
293 const UserProc *_OverloadSolution( const char *name, std::vector<const UserProc *> &subs, bool isEnabledReturnType = false );
294 const UserProc *OverloadSolution( const char *name, std::vector<const UserProc *> &subs, bool isEnabledReturnType = false );
295
296 void ApplyDefaultParameters( const Parameters &params );
297 bool ErrorCheck( const string &procName, const Parameters &params, int SecondParmNum = -1 );
298 void MacroParameterSupport( const Parameters &params );
299 void SetStructParameter( int reg, const Type &baseType, const char *expression );
300 void SetParameter( const string &procName, const Parameters &params, int SecondParmNum = -1, const UserProc *pUserProc = NULL );
301
302 //一時オブジェクトパラメータの生成と破棄
303 int NewTempParameters( const string &procName, const Parameters &params, int SecondParmNum = -1 );
304 void DeleteTempParameters();
305
306 void BackupParameter(int pi_num);
307 void RestoreParameter(int pi_num);
308};
309
310//CLockParameter.cpp
311#define MAX_LOCKPARMS 255
312class CDBLockParms{
313public:
314 int array_LevelCount[MAX_LOCKPARMS];
315 CDBLockParms();
316 ~CDBLockParms();
317
318 void lock(int level);
319 void unlock(int level);
320};
321
322//Compile_CallProc.cpp
323#define PROCFLAG_NEW 1
324bool Opcode_CallProcPtr(const char *variable, const char *lpszParms,ProcPointer *pProcPointer);
325bool Opcode_CallProc(const char *Parameter,const UserProc *pUserProc,DWORD dwFlags,const char *ObjectName);
326bool Opcode_CallDllProc( const char *lpszParms,DllProc *pDllProc);
327void Opcode_CallDelegate( const Delegate &dg, const char *methodPtrValueStr, const char *objPtrValueStr, const char *params );
328
329//Compile_ProcOp.cpp
330void _compile_proc(const UserProc *pUserProc);
331
332//Compile_Func.cpp
333int GetFunctionFromName(char *FuncName);
334bool Opcode_CallFunc( const char *Parameter, const int FuncNum, const Type &baseType, Type &resultType, bool isCallOn = true );
335
336//OperatorProc.cpp
337void FreeTempObject(int reg,const CClass *pobj_c);
338int CallOperatorProc(BYTE idCalc, const Type &baseType, int *type_stack,LONG_PTR *index_stack,BOOL *bUseHeap,int &sp);
339void CallCastOperatorProc(int reg,Type &calcType,BOOL bCalcUseHeap,const Type &toType);
340void CallIndexerGetterProc(int reg, const Type &classType, const char *ObjectName,char *Parameter,Type &resultType, DWORD dwProcFlags = 0 );
341
342//Compile_Statement.cpp
343void OpcodeOthers(const char *Command);
344void OpcodeIf(char *Parameter);
345void OpcodeGoto(char *Parameter);
346void OpcodeWhile(char *Parameter);
347void OpcodeFor(char *Parameter);
348void OpcodeForeach(const char *Parameter);
349void OpcodeDo(char *Parameter);
350void OpcodeContinue(void);
351void OpcodeExitSub(void);
352void OpcodeSelect( const char *Parameter );
353void OpcodeCase(char *Parameter);
354void OpcodeGosub(char *Parameter);
355void OpcodeReturn(char *Parameter);
356void OpcodeSetPtrData(char *Parameter,int type);
357
358
359//InsertOpcode.cpp
360void InsertDimStatement_ToProcHead(char *lpszCommand);
361
362
363BOOL IsSafeReg(int reg);
Note: See TracBrowser for help on using the repository browser.