source: dev/trunk/ab5.0/abdev/compiler_x64/Opcode.h@ 828

Last change on this file since 828 was 828, checked in by イグトランス (egtra), 13 years ago

egtraブランチの内容をマージ。

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