source: dev/BasicCompiler64/Opcode.h@ 48

Last change on this file since 48 was 46, checked in by dai_9181, 18 years ago

VarPtrの戻り値の型をVoidPtrではなく、ポインタレベルを増加した型にした。
関連関数のパラメータにconstを適用。

File size: 16.3 KB
RevLine 
[3]1//Opcode.h
2
3
4//レジスタを示す定数
5#define REG_EAX 1
6#define REG_EBX 2
7#define REG_ECX 3
8#define REG_EDX 4
9#define REG_ESP 5
10#define REG_EBP 6
11
12#define REGISTER_OPERAND(reg) (reg&0x07)
13
14#define REG_NON -1
15#define REG_RAX 0x00 //reg:000
16#define REG_RCX 0x01 //reg:001
17#define REG_RDX 0x02 //reg:010
18#define REG_RBX 0x03 //reg:011
19#define REG_RSP 0x04 //reg:100
20#define REG_RBP 0x05 //reg:101
21#define REG_RSI 0x06 //reg:110
22#define REG_RDI 0x07 //reg:111
23#define REG_R8 0x08 //reg:000(REXプリフィックス)
24#define REG_R9 0x09 //reg:001(REXプリフィックス)
25#define REG_R10 0x0A //reg:010(REXプリフィックス)
26#define REG_R11 0x0B //reg:011(REXプリフィックス)
27#define REG_R12 0x0C //reg:100(REXプリフィックス)
28#define REG_R13 0x0D //reg:101(REXプリフィックス)
29#define REG_R14 0x0E //reg:110(REXプリフィックス)
30#define REG_R15 0x0F //reg:111(REXプリフィックス)
31
32#define REG_XMM0 0x10 //reg:000
33#define REG_XMM1 0x11 //reg:001
34#define REG_XMM2 0x12 //reg:010
35#define REG_XMM3 0x13 //reg:011
36#define REG_XMM4 0x14 //reg:100
37#define REG_XMM5 0x15 //reg:101
38#define REG_XMM6 0x16 //reg:110
39#define REG_XMM7 0x17 //reg:111
40#define REG_XMM8 0x18 //reg:000
41#define REG_XMM9 0x19 //reg:001
42#define REG_XMM10 0x1A //reg:010
43#define REG_XMM11 0x1B //reg:011
44#define REG_XMM12 0x1C //reg:100
45#define REG_XMM13 0x1D //reg:101
46#define REG_XMM14 0x1E //reg:110
47#define REG_XMM15 0x1F //reg:111
48
49#define IS_XMM_REG(reg) (reg&0x10)
50
51
52
53//変数の種類
[40]54#define NON_VAR 0
55#define VAR_GLOBAL 1 //Global Variable
56#define VAR_LOCAL 2 //Local Variable
57#define VAR_REFLOCAL 3 //Local Refference Variable
58#define VAR_DIRECTMEM 5 //Direct memory
[3]59
[40]60
[3]61extern int cp;
62extern int obp;
63extern char *OpBuffer;
64
65//ラベルアドレス
66struct LABEL{
67 char *pName;
68 int line;
69 DWORD address;
70};
71
72//Goto未知ラベル
73struct GOTOLABELSCHEDULE{
74 char *pName;
75 int line;
76 DWORD pos;
77 DWORD now_cp;
78};
79
80
81//プロシージャの種類
82#define PROC_DEFAULT 1 //ユーザー定義関数
83#define PROC_DLL 2 //DLL関数
84#define PROC_BUILTIN 3 //コンパイラ埋め込み型
85#define PROC_PTR 4 //関数ポインタ
86
87//プロシージャ
88struct PROCEDURE{
89 char name[255];
90 int address;
91 int types[MAX_PARMS];
92 _int8 ByVal[MAX_PARMS];
93 BOOL ReturnType;
94};
95
96//With情報
97struct WITHINFO{
98 char **ppName;
99 int *pWithCp;
100 int num;
101};
102
103
104class CStackFrame:public CSchedule{
105 ///////////////////////////
106 // スタックフレーム管理
107 ///////////////////////////
108
109 int lowest_sp; //スタックポインタの最下位位置
110 int now_sp; //スタックポインタ
111 int max_parm_size; //パラメータの最大サイズ
112 int local_parm_size; //ローカル領域のパラメータサイズ
113
114public:
115 //コンストラクタ
116 CStackFrame();
117
118 //デストラクタ
119 ~CStackFrame();
120
121 void SetLocalParmSize(int size);
122 int GetFrameSize();
[20]123 int push(int reg);
[3]124 void push(int xmm_reg,int var_size);
[20]125 void ref_offset_data( int reg, int sp_offset );
[3]126 void ref(int reg);
127 void ref(int xmm_reg,int var_size);
128 void pop(int reg);
129 void pop(int xmm_reg,int var_size);
130 void parameter_allocate(int size);
131 void RunningSchedule(void);
132
133 void error_check(void);
134};
135extern CStackFrame *pobj_sf;
136
137
138class CBlockReg{
139 int array_BlockReg[256];
140 int num;
141
142public:
143 CBlockReg();
144 void lock(int reg);
145 void unlock(int reg);
146 BOOL check(int reg);
147 void clear(void);
148
149 //レジスタのバックアップと復旧
150 void backup();
151 void restore();
152};
153extern CBlockReg *pobj_BlockReg;
154class CRegister{
155 ////////////////////
156 // レジスタ管理
157 ////////////////////
158
159 //利用可能なレジスタを列挙する関数
160 void EnumRegister(int *pRegList,int nMaxList,int *array_reg,int *sp,int AnswerReg);
161
162 int array_UseReg[16],sp_UseReg;
163
164 int array_XmmReg[16];
165 int sp_XmmReg;
166
167 int init_sp_reg,init_sp_xmm_reg;
168
169public:
170 CRegister(){};
171 CRegister(int AnswerReg);
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
[19]189 //レジスタが利用中かどうかを調べる
190 bool IsUsing( int reg );
191
[3]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//MakePeHdr.cpp
230int AddDataTable(char *buffer,int length);
231
232//RSrcSection.cpp
233char *GetRSrcSectionBuffer(int *pLen);
234
235//Compile.cpp
236void ChangeOpcode(char *Command);
237void GetGlobalDataForDll(void);
238DWORD CompileBuffer(char Return_Sequence,WORD Return_Command);
239
240//Register.cpp
241BOOL IsGeneralReg(int reg);
242BOOL IsXmmReg(int reg);
243BOOL IsVolatileReg(int reg);
244
245//Compile_Calc.cpp
246void SetVariableFromRax(int VarType,int CalcType,RELATIVE_VAR *pRelativeVar);
247void OpcodeCalc(char *Command);
[40]248void SetRefVariable( const char *varname, const char *expression );
[3]249
250//NumOpe.cpp
[15]251int NumOpe(int *pReg,const char *Command,int BaseType,LONG_PTR lpBaseIndex,LONG_PTR *plpIndex,BOOL *pbUseHeap=0);
[3]252
253//NumOpe_Arithmetic.cpp
254BOOL CalcTwoTerm_Arithmetic(int idCalc,int *type,LONG_PTR *index_stack,int *pStackPointer);
255BOOL Calc_Mod(int *type,LONG_PTR *index_stack,int *pStackPointer);
256BOOL Calc_Divide(int *type,int *pStackPointer,int BaseType);
257BOOL Calc_IntDivide(int *type,LONG_PTR *index_stack,int *pStackPointer);
258BOOL Calc_MinusMark(int *type,int sp);
259BOOL Calc_Power(int *type,int *pStackPointer);
260BOOL Calc_Shift(int idCalc,int *type,int *pStackPointer);
261
262//NumOpe_Logical.cpp
263BOOL CalcTwoTerm_Logical(int idCalc,int *type,LONG_PTR *index_stack,int *pStackPointer);
264BOOL Calc_Not(int *type,int sp);
265
266//NumOpe_Relation.cpp
267BOOL CalcTwoTerm_Relational(int idCalc,int *type,LONG_PTR *index_stack,int *pStackPointer);
268
269//NumOpe_TypeOperation.cpp
270void ExtendTypeTo64(int type,int reg);
271void ExtendTypeTo32(int type,int reg);
272void ExtendTypeTo16(int type,int reg);
273void ChangeTypeToXmm_Double(int type,int xmm_reg,int general_reg);
274void ChangeTypeToXmm_Single(int type,int xmm_reg,int general_reg);
275void ChangeTypeToWhole(int OldType,int NewType,int reg,int xmm_reg);
276void SetOneTermToReg_RealCalc(int TermType,int *pXmmReg);
277void SetOneTermToReg_Whole64Calc(int TermType,int *pReg);
278void SetOneTermToReg_Whole32Calc(int TermType,int *pReg);
279void SetTowTermToReg_RealCalc(int AnswerType,int *type,int sp,int *pXmmReg1,int *pXmmReg2);
280void SetTowTermToReg_Whole64Calc(int *type,int sp,int *pReg1,int *pReg2);
281void SetTowTermToReg_Whole32Calc(int *type,int sp,int *pReg1,int *pReg2);
282BOOL Calc_Cast(int *type,LONG_PTR *index_stack,int *pStackPointer);
283
284//Compile_Set_Var.cpp
285BOOL IsUse_r11(RELATIVE_VAR *pRelativeVar);
286void SetObjectVariableFromRax(LONG_PTR lpVarIndex,int CalcType,LONG_PTR lpCalcIndex,RELATIVE_VAR *pRelativeVar,BOOL bUseHeap);
287void SetDoubleVariable(int type,RELATIVE_VAR *pRelative);
288void SetSingleVariable(int type,RELATIVE_VAR *pRelative);
[36]289void SetBooleanVariable(int type,RELATIVE_VAR *pRelative);
[3]290void SetWholeVariable(int var_size,int type,RELATIVE_VAR *pRelative);
291
292//increment.cpp
293void IncDec(int idCalc, char *lpszLeft, char *lpszRight);
294
295//calc2.cpp
296#define EXP_TYPE_NUMBER 1
297#define EXP_TYPE_EAX 2
298#define EXP_TYPE_FPU 3
299#define EXP_TYPE_VAR 4
300int NumOpEx(char *Command,double *pDbl,DWORD *pdwType,RELATIVE_VAR *pRelativeVar);
301
302//Compile_Calc_PushVar.cpp
303void SetXmmReg_DoubleVariable(RELATIVE_VAR *pRelativeVar,int xmm_reg);
304void SetXmmReg_SingleVariable(RELATIVE_VAR *pRelativeVar,int xmm_reg);
305void SetReg_WholeVariable(int type,RELATIVE_VAR *pRelativeVar,int reg);
306
307//Compile_Object.cpp
[15]308int Operator_New(const char *Parameter,LONG_PTR *plpIndex);
309void OpcodeDelete(const char *Parameter);
[3]310
311//Compile_Var.cpp
312void GetWithName(char *buffer);
313void SetThisPtrToReg(int reg);
[40]314BOOL GetVarOffset(bool isErrorEnabled,bool isWriteAccess,const char *NameBuffer,int *pType,RELATIVE_VAR *pRelativeVar,LONG_PTR *plpIndex,int *pss=0);
[3]315BOOL SetInitGlobalData(int offset,int type,LONG_PTR lpIndex,int *SubScripts,char *InitBuf);
[40]316#define DIMFLAG_INITDEBUGVAR 0x01
317#define DIMFLAG_NONCALL_CONSTRACTOR 0x02
318#define DIMFLAG_STATIC 0x04
319#define DIMFLAG_CONST 0x08
[3]320void OpcodeDim(char *Parameter,DWORD dwFlag);
321void SetVarPtrToReg(int reg,RELATIVE_VAR *pRelativeVar);
322
323//CParameter.cpp
324#define OVERLOAD_LEVEL1 1
325#define OVERLOAD_LEVEL2 2
326#define OVERLOAD_LEVEL3 3
327class CParameter{
328 char *Parms[255];
329 TYPEINFO types[255];
330 int ParmsNum;
331
332 TYPEINFO ReturnTypeInfo;
333
[20]334 //一時オブジェクト管理用
335 bool useTempObject;
336 bool useTempParameters[255];
337 int StackOffsetOfTempObject[255];
338
[3]339public:
340 CParameter(char *buffer);
341 CParameter(PARAMETER_INFO *pParamInfo,int ParmNum);
342 ~CParameter();
343 void SetReturnType(TYPEINFO *pTypeInfo);
344
345private:
346 BOOL _overload_check(PARAMETER_INFO *ppi,int pi_num,TYPEINFO *pReturnTypeInfo,int overload_level);
[46]347 SUBINFO *OverloadSolutionWithReturnType(const char *name,SUBINFO **ppsi,int num);
[3]348public:
[46]349 SUBINFO *OverloadSolution(const char *name,SUBINFO **ppsi,int num);
[3]350
[46]351 BOOL ErrorCheck(const char *FuncName,PARAMETER_INFO *ppi,int pi_num,int SecondParmNum);
[3]352 void MacroParameterSupport(PARAMETER_INFO *ppi);
353 void SetObjectParameter(int reg,CClass *pobj_Class,LPSTR Parameter);
[20]354
355 //一時オブジェクトパラメータの生成と破棄
[46]356 void NewTempParameters( const char *FuncName,PARAMETER_INFO *ppi,int pi_num,int SecondParmNum );
[20]357 void DeleteTempParameters();
358
[46]359 void SetParameter(const char *FuncName,PARAMETER_INFO *ppi,int pi_num,int SecondParmNum);
[20]360
[3]361 void BackupParameter(int pi_num);
362 void RestoreParameter(int pi_num);
363};
364
365//CLockParameter.cpp
366#define MAX_LOCKPARMS 255
367class CDBLockParms{
368public:
369 int array_LevelCount[MAX_LOCKPARMS];
370 CDBLockParms();
371 ~CDBLockParms();
372
373 void lock(int level);
374 void unlock(int level);
375};
376
377//Compile_CallProc.cpp
378void AddLocalVarAddrSchedule();
379int CallProc(int idProc,void *pInfo,char *name,char *Parameter,LONG_PTR *plpRetIndex);
380BOOL CallPropertyMethod(char *variable,char *RightSide,TYPEINFO *pRetTypeInfo);
381#define PROCFLAG_NEW 1
382int Opcode_CallProcPtr(char *variable,char *Parameter,PROCPTRINFO *pi,LONG_PTR *plpIndex);
[31]383void Opcode_CallProc(char *Parameter,SUBINFO *psi,DWORD dwFlags,char *ObjectName,int RefType);
[3]384int Opcode_CallDllProc(char *Parameter,DECLAREINFO *pdi,LONG_PTR *plpIndex);
385
386//Compile_ProcOp.cpp
387void CompileLocal();
388
389//Compile_Func.cpp
390int GetFunctionType(int FuncNum);
391int GetFunctionFromName(char *FuncName);
[46]392void Opcode_CallFunc( const char *Parameter, const int FuncNum, TYPEINFO &ReturnTypeInfo );
[3]393
394//OperatorProc.cpp
395void FreeTempObject(int reg,CClass *pobj_c);
396int CallOperatorProc(int idCalc,TYPEINFO *pBaseTypeInfo,int *type,LONG_PTR *index_stack,BOOL *bUseHeap,int &sp);
397void CallCastOperatorProc(int reg,int &CalcType,LONG_PTR &lpCalcIndex,BOOL bCalcUseHeap,int ToType,LONG_PTR lpToIndex);
[38]398void CallIndexerGetterProc(int reg,CClass *pobj_Class,char *ObjectName,char *Parameter,TYPEINFO &RetTypeInfo);
[3]399
400//Compile_Statement.cpp
401void OpcodeOthers(char *Command);
402void OpcodeIf(char *Parameter);
403void OpcodeGoto(char *Parameter);
404void OpcodeWhile(char *Parameter);
405void OpcodeFor(char *Parameter);
406void OpcodeDo(char *Parameter);
407void OpcodeContinue(void);
408void OpcodeExitSub(void);
409void OpcodeSelect(char *Parameter);
410void OpcodeCase(char *Parameter);
411void OpcodeGosub(char *Parameter);
412void OpcodeReturn(char *Parameter);
413void Opcode_Input(char *Parameter);
414void Opcode_Print(char *Parameter,BOOL bWrite);
415void OpcodeCallPtr(char *Parameter);
416void OpcodeSetPtrData(char *Parameter,int type);
417
418
419//InsertOpcode.cpp
420void InsertDimStatement_ToProcHead(char *lpszCommand);
421
422
423
424////////////////////////////////
425// AMD64機械語生成に利用する関数郡
426////////////////////////////////
427
428//Mod(モード)
429#define MOD_BASE (char)0x00
430#define MOD_DISP32 (char)0xFF
431#define MOD_BASE_DISP8 (char)0x40
432#define MOD_BASE_DISP32 (char)0x80
433#define MOD_REG (char)0xC0
434
435#define USE_OFFSET 1
436#define NON_OFFSET 0
437
438//amd64_main.cpp
439BOOL IsSafeReg(int reg);
440void op_push(int reg);
441void op_push_value(long data);
442void op_pop(int reg);
443void op_mov_RV (int op_size,int reg,int i32data);
444void op_mov_RV64 (int reg,_int64 i64data);
445void op_mov_RM (int op_size,int reg,int base_reg,int offset,char mod);
446void op_mov_RM_ex (int op_size,int reg,int base_reg1,int base_reg2,int offset,BOOL bUseOffset);
447void op_mov_MR (int op_size,int reg,int base_reg,int offset,char mod);
448void op_mov_MR_ex (int op_size,int reg,int base_reg1,int base_reg2,int offset,BOOL bUseOffset);
449void op_mov_MV (int op_size,int base_reg,int offset,BOOL bUseOffset,int i32data);
450void op_mov_RR (int reg1,int reg2);
451void op_mov64_ToReg (int reg,_int64 i64data);
452void op_mov64_ToReg (int reg,int i32data);
453void op_mov64_ToReg_FromReg (int reg1,int reg2);
454void op_movsxd (int reg64,int reg32);
455void op_movsx64_FromReg16 (int reg64,int reg16);
456void op_movsx64_FromReg8 (int reg64,int reg8);
457void op_movsx32_FromReg16 (int reg32,int reg16);
458void op_movsx32_FromReg8 (int reg32,int reg8);
459void op_movsx16_FromReg8 (int reg32,int reg8);
460void op_inc (int reg);
461void op_dec (int reg);
462void op_add_RM (int op_size,int reg,int base_reg,int offset,char mod);
463void op_add64_value (int reg,int offset);
464void op_add64_reg (int reg1,int reg2);
465void op_add32_reg (int reg1,int reg2);
466void op_sub_RV (int op_size,int reg,int i32data);
467void op_sub64_reg (int reg1,int reg2);
468void op_sub32_reg (int reg1,int reg2);
[36]469void op_sbb_RR ( int op_size, int reg1, int reg2 );
[3]470void op_imul_reg (int op_size,int reg1,int reg2);
471void op_imul_value (int op_size,int reg,int i32data);
472void op_div64_reg (int reg);
473void op_idiv64_reg (int reg);
474void op_shl_reg (int op_size,int reg);
475void op_sar_reg (int op_size,int reg);
476void op_shr_reg (int op_size,int reg);
477void op_and_reg (int op_size,int reg1,int reg2);
478void op_and64_value (int reg,int offset);
479void op_and32_value (int reg,int offset);
480void op_or_reg (int op_size,int reg1,int reg2);
481void op_xor_reg (int op_size,int reg1,int reg2);
482void op_not_reg (int op_size,int reg);
[36]483void op_neg ( int reg );
[3]484void op_test (int reg1,int reg2);
485void op_cmp_reg (int op_size,int reg1,int reg2);
486void op_cmp_value (int op_size,int reg,char byte_data);
[36]487void op_setne (int reg);
[3]488void op_movlpd_MR (int xmm_reg,int base_reg,int offset,char mod);
489void op_movlpd_RM (int xmm_reg,int base_reg,int offset,char mod);
490void op_movsd_RR (int xmm_reg1,int xmm_reg2);
491void op_movsd_MR (int xmm_reg,int base_reg,int offset,char mod);
492void op_movss_RR (int xmm_reg1,int xmm_reg2);
493void op_movss_RM (int xmm_reg,int base_reg,int offset,char mod);
494void op_movss_MR (int xmm_reg,int base_reg,int offset,char mod);
495void op_movd_RX (int reg,int xmm_reg);
496void op_cvtsd2ss (int xmm_reg1,int xmm_reg2);
497void op_cvtss2sd (int xmm_reg1,int xmm_reg2);
498void op_cvttsd2si_xmm (int op_size,int reg,int xmm_reg);
499void op_cvttss2si_xmm (int op_size,int reg,int xmm_reg);
500void op_cvtsi2sd_reg (int op_size,int xmm_reg,int reg);
501void op_cvtsi2ss_reg (int op_size,int xmm_reg,int reg);
502void op_comisd (int xmm_reg1,int xmm_reg2);
503void op_comiss (int xmm_reg1,int xmm_reg2);
504void op_rep_movs (int op_size);
505void op_add_rsp(int num);
506void op_sub_rsp(int num);
507void op_add_esp(int num);
508void op_sub_esp(int num);
509void op_fld_ptr_esp(int type);
510void op_zero_reg(int reg);
[19]511void op_call( SUBINFO *psi );
512void op_call( DECLAREINFO *pdi );
Note: See TracBrowser for help on using the repository browser.