source: dev/BasicCompiler64/Opcode.h@ 17

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

定数メンバ機能を有効にした。

File size: 16.0 KB
Line 
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//変数の種類
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 4 //Direct memory
59
60extern int cp;
61extern int obp;
62extern char *OpBuffer;
63
64//ラベルアドレス
65struct LABEL{
66 char *pName;
67 int line;
68 DWORD address;
69};
70
71//Goto未知ラベル
72struct GOTOLABELSCHEDULE{
73 char *pName;
74 int line;
75 DWORD pos;
76 DWORD now_cp;
77};
78
79
80//プロシージャの種類
81#define PROC_DEFAULT 1 //ユーザー定義関数
82#define PROC_DLL 2 //DLL関数
83#define PROC_BUILTIN 3 //コンパイラ埋め込み型
84#define PROC_PTR 4 //関数ポインタ
85
86//プロシージャ
87struct PROCEDURE{
88 char name[255];
89 int address;
90 int types[MAX_PARMS];
91 _int8 ByVal[MAX_PARMS];
92 BOOL ReturnType;
93};
94
95//With情報
96struct WITHINFO{
97 char **ppName;
98 int *pWithCp;
99 int num;
100};
101
102
103class CStackFrame:public CSchedule{
104 ///////////////////////////
105 // スタックフレーム管理
106 ///////////////////////////
107
108 int lowest_sp; //スタックポインタの最下位位置
109 int now_sp; //スタックポインタ
110 int max_parm_size; //パラメータの最大サイズ
111 int local_parm_size; //ローカル領域のパラメータサイズ
112
113public:
114 //コンストラクタ
115 CStackFrame();
116
117 //デストラクタ
118 ~CStackFrame();
119
120 void SetLocalParmSize(int size);
121 int GetFrameSize();
122 void push(int reg);
123 void push(int xmm_reg,int var_size);
124 void ref(int reg);
125 void ref(int xmm_reg,int var_size);
126 void pop(int reg);
127 void pop(int xmm_reg,int var_size);
128 void parameter_allocate(int size);
129 void RunningSchedule(void);
130
131 void error_check(void);
132};
133extern CStackFrame *pobj_sf;
134
135
136class CBlockReg{
137 int array_BlockReg[256];
138 int num;
139
140public:
141 CBlockReg();
142 void lock(int reg);
143 void unlock(int reg);
144 BOOL check(int reg);
145 void clear(void);
146
147 //レジスタのバックアップと復旧
148 void backup();
149 void restore();
150};
151extern CBlockReg *pobj_BlockReg;
152class CRegister{
153 ////////////////////
154 // レジスタ管理
155 ////////////////////
156
157 //利用可能なレジスタを列挙する関数
158 void EnumRegister(int *pRegList,int nMaxList,int *array_reg,int *sp,int AnswerReg);
159
160 int array_UseReg[16],sp_UseReg;
161
162 int array_XmmReg[16];
163 int sp_XmmReg;
164
165 int init_sp_reg,init_sp_xmm_reg;
166
167public:
168 CRegister(){};
169 CRegister(int AnswerReg);
170 ~CRegister(){};
171
172 //コンパイラにバグがないかをチェックする機構
173 void bug_check();
174
175 //汎用レジスタ
176 int GetNextReg();
177 int GetLockingReg();
178 int LockReg();
179 int UnlockReg();
180
181 //XMMレジスタ
182 int GetNextXmmReg();
183 int GetLockingXmmReg();
184 int LockXmmReg();
185 int UnlockXmmReg();
186
187 //レジスタのバックアップと復旧
188 void backup();
189 void restore();
190};
191extern CRegister *pobj_reg;
192
193
194#define BACKUP_REGISTER_RESOURCE \
195 /* レジスタをスタックフレームにバックアップ */ \
196 pobj_BlockReg->backup(); \
197 if(pobj_reg) pobj_reg->backup(); \
198 \
199 /* レジスタブロッキングオブジェクトを退避して再生成 */ \
200 CBlockReg *pobj_BlockReg_back; \
201 pobj_BlockReg_back=pobj_BlockReg; \
202 pobj_BlockReg=new CBlockReg; \
203 \
204 /* レジスタ管理オブジェクトポインタを退避して0をセット */ \
205 CRegister *pobj_reg_back; \
206 pobj_reg_back=pobj_reg; \
207 pobj_reg=0;
208
209#define RESTORE_REGISTER_RESOURCE \
210 /* レジスタブロッキングオブジェクトポインタを復元 */ \
211 delete pobj_BlockReg; \
212 pobj_BlockReg=pobj_BlockReg_back; \
213 \
214 /* レジスタ管理オブジェクトポインタを復元 */ \
215 delete pobj_reg; \
216 pobj_reg=pobj_reg_back; \
217 \
218 /* レジスタをスタックフレームから復元 */ \
219 if(pobj_reg) pobj_reg->restore(); \
220 pobj_BlockReg->restore();
221
222
223
224//MakePeHdr.cpp
225int AddDataTable(char *buffer,int length);
226
227//RSrcSection.cpp
228char *GetRSrcSectionBuffer(int *pLen);
229
230//Compile.cpp
231void ChangeOpcode(char *Command);
232void GetGlobalDataForDll(void);
233DWORD CompileBuffer(char Return_Sequence,WORD Return_Command);
234
235//Register.cpp
236BOOL IsGeneralReg(int reg);
237BOOL IsXmmReg(int reg);
238BOOL IsVolatileReg(int reg);
239
240//Compile_Calc.cpp
241void ChangeTypeToDouble_ToFpuReg(int OldType);
242void ChangeTypeToDouble(int OldType);
243void ChangeTypeToSingle(int OldType);
244void ChangeTypeToInt64(int OldType);
245void ChangeTypeToLong(int OldType);
246void ChangeTypeToInteger(int OldType);
247void ChangeTypeToByte(int OldType);
248void SetVariableFromRax(int VarType,int CalcType,RELATIVE_VAR *pRelativeVar);
249void OpcodeCalc(char *Command);
250
251//NumOpe.cpp
252int NumOpe(int *pReg,const char *Command,int BaseType,LONG_PTR lpBaseIndex,LONG_PTR *plpIndex,BOOL *pbUseHeap=0);
253
254//NumOpe_Arithmetic.cpp
255void GetStackData_ToRegister(int *type,int sp);
256BOOL CalcTwoTerm_Arithmetic(int idCalc,int *type,LONG_PTR *index_stack,int *pStackPointer);
257BOOL Calc_Mod(int *type,LONG_PTR *index_stack,int *pStackPointer);
258BOOL Calc_Divide(int *type,int *pStackPointer,int BaseType);
259BOOL Calc_IntDivide(int *type,LONG_PTR *index_stack,int *pStackPointer);
260BOOL Calc_MinusMark(int *type,int sp);
261BOOL Calc_Power(int *type,int *pStackPointer);
262BOOL Calc_Shift(int idCalc,int *type,int *pStackPointer);
263
264//NumOpe_Logical.cpp
265BOOL CalcTwoTerm_Logical(int idCalc,int *type,LONG_PTR *index_stack,int *pStackPointer);
266BOOL Calc_Not(int *type,int sp);
267
268//NumOpe_Relation.cpp
269BOOL CalcTwoTerm_Relational(int idCalc,int *type,LONG_PTR *index_stack,int *pStackPointer);
270
271//NumOpe_TypeOperation.cpp
272void ExtendTypeTo64(int type,int reg);
273void ExtendTypeTo32(int type,int reg);
274void ExtendTypeTo16(int type,int reg);
275void ChangeTypeToXmm_Double(int type,int xmm_reg,int general_reg);
276void ChangeTypeToXmm_Single(int type,int xmm_reg,int general_reg);
277void ChangeTypeToWhole(int OldType,int NewType,int reg,int xmm_reg);
278void SetOneTermToReg_RealCalc(int TermType,int *pXmmReg);
279void SetOneTermToReg_Whole64Calc(int TermType,int *pReg);
280void SetOneTermToReg_Whole32Calc(int TermType,int *pReg);
281void SetTowTermToReg_RealCalc(int AnswerType,int *type,int sp,int *pXmmReg1,int *pXmmReg2);
282void SetTowTermToReg_Whole64Calc(int *type,int sp,int *pReg1,int *pReg2);
283void SetTowTermToReg_Whole32Calc(int *type,int sp,int *pReg1,int *pReg2);
284BOOL Calc_Cast(int *type,LONG_PTR *index_stack,int *pStackPointer);
285
286//Compile_Set_Var.cpp
287BOOL IsUse_r11(RELATIVE_VAR *pRelativeVar);
288void SetObjectVariableFromRax(LONG_PTR lpVarIndex,int CalcType,LONG_PTR lpCalcIndex,RELATIVE_VAR *pRelativeVar,BOOL bUseHeap);
289void SetDoubleVariable(int type,RELATIVE_VAR *pRelative);
290void SetSingleVariable(int type,RELATIVE_VAR *pRelative);
291void SetWholeVariable(int var_size,int type,RELATIVE_VAR *pRelative);
292
293//increment.cpp
294void IncDec(int idCalc, char *lpszLeft, char *lpszRight);
295
296//calc2.cpp
297#define EXP_TYPE_NUMBER 1
298#define EXP_TYPE_EAX 2
299#define EXP_TYPE_FPU 3
300#define EXP_TYPE_VAR 4
301int NumOpEx(char *Command,double *pDbl,DWORD *pdwType,RELATIVE_VAR *pRelativeVar);
302
303//SetVar.cpp
304BOOL SetVariable(DWORD dwVarType,RELATIVE_VAR *pVarRelativeVar,
305 DWORD dwExpType,DWORD dwType,void *data);
306
307//Compile_Calc_PushVar.cpp
308void SetXmmReg_DoubleVariable(RELATIVE_VAR *pRelativeVar,int xmm_reg);
309void SetXmmReg_SingleVariable(RELATIVE_VAR *pRelativeVar,int xmm_reg);
310void SetReg_WholeVariable(int type,RELATIVE_VAR *pRelativeVar,int reg);
311
312//Compile_Object.cpp
313int Operator_New(const char *Parameter,LONG_PTR *plpIndex);
314void OpcodeDelete(const char *Parameter);
315
316//Compile_Var.cpp
317void GetWithName(char *buffer);
318void SetThisPtrToReg(int reg);
319BOOL GetVarOffset(bool isErrorEnabled,bool isWriteAccess,char *NameBuffer,int *pType,RELATIVE_VAR *pRelativeVar,LONG_PTR *plpIndex,int *pss=0);
320BOOL SetInitGlobalData(int offset,int type,LONG_PTR lpIndex,int *SubScripts,char *InitBuf);
321#define DIMFLAG_INITDEBUGVAR 1
322#define DIMFLAG_NONCALL_CONSTRACTOR 2
323#define DIMFLAG_STATIC 4
324#define DIMFLAG_CONST 8
325void OpcodeDim(char *Parameter,DWORD dwFlag);
326void SetVarPtrToReg(int reg,RELATIVE_VAR *pRelativeVar);
327
328//CParameter.cpp
329#define OVERLOAD_LEVEL1 1
330#define OVERLOAD_LEVEL2 2
331#define OVERLOAD_LEVEL3 3
332class CParameter{
333 char *Parms[255];
334 TYPEINFO types[255];
335 int ParmsNum;
336
337 TYPEINFO ReturnTypeInfo;
338
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);
347 SUBINFO *OverloadSolutionWithReturnType(char *name,SUBINFO **ppsi,int num);
348public:
349 SUBINFO *OverloadSolution(char *name,SUBINFO **ppsi,int num);
350
351 BOOL ErrorCheck(char *FuncName,PARAMETER_INFO *ppi,int pi_num,int SecondParmNum);
352 void MacroParameterSupport(PARAMETER_INFO *ppi);
353 void SetObjectParameter(int reg,CClass *pobj_Class,LPSTR Parameter);
354 void SetParameter(char *FuncName,PARAMETER_INFO *ppi,int pi_num,int SecondParmNum);
355 void BackupParameter(int pi_num);
356 void RestoreParameter(int pi_num);
357};
358
359//CLockParameter.cpp
360#define MAX_LOCKPARMS 255
361class CDBLockParms{
362public:
363 int array_LevelCount[MAX_LOCKPARMS];
364 CDBLockParms();
365 ~CDBLockParms();
366
367 void lock(int level);
368 void unlock(int level);
369};
370
371//Compile_CallProc.cpp
372void AddLocalVarAddrSchedule();
373int CallProc(int idProc,void *pInfo,char *name,char *Parameter,LONG_PTR *plpRetIndex);
374BOOL CallPropertyMethod(char *variable,char *RightSide,TYPEINFO *pRetTypeInfo);
375#define PROCFLAG_NEW 1
376int Opcode_CallProcPtr(char *variable,char *Parameter,PROCPTRINFO *pi,LONG_PTR *plpIndex);
377int Opcode_CallProc(char *Parameter,SUBINFO *psi,LONG_PTR *plpIndex,DWORD dwFlags,char *ObjectName,int RefType);
378int Opcode_CallDllProc(char *Parameter,DECLAREINFO *pdi,LONG_PTR *plpIndex);
379
380//Compile_ProcOp.cpp
381void CompileLocal();
382
383//Compile_Func.cpp
384int GetFunctionType(int FuncNum);
385int GetFunctionFromName(char *FuncName);
386int Opcode_CallFunc(char *Parameter,int FuncNum);
387
388//OperatorProc.cpp
389void FreeTempObject(int reg,CClass *pobj_c);
390int CallOperatorProc(int idCalc,TYPEINFO *pBaseTypeInfo,int *type,LONG_PTR *index_stack,BOOL *bUseHeap,int &sp);
391void CallCastOperatorProc(int reg,int &CalcType,LONG_PTR &lpCalcIndex,BOOL bCalcUseHeap,int ToType,LONG_PTR lpToIndex);
392void CallArrayOperatorProc(int reg,CClass *pobj_Class,char *ObjectName,char *Parameter,TYPEINFO &RetTypeInfo);
393
394//Compile_Statement.cpp
395void OpcodeOthers(char *Command);
396void OpcodeIf(char *Parameter);
397void OpcodeGoto(char *Parameter);
398void OpcodeWhile(char *Parameter);
399void OpcodeExitWhile(void);
400void OpcodeFor(char *Parameter);
401void OpcodeExitFor(void);
402void OpcodeDo(char *Parameter);
403void OpcodeExitDo(void);
404void OpcodeContinue(void);
405void OpcodeExitSub(void);
406void OpcodeSelect(char *Parameter);
407void OpcodeCase(char *Parameter);
408void OpcodeGosub(char *Parameter);
409void OpcodeReturn(char *Parameter);
410void Opcode_Input(char *Parameter);
411void Opcode_Print(char *Parameter,BOOL bWrite);
412void OpcodeCallPtr(char *Parameter);
413void OpcodeSetPtrData(char *Parameter,int type);
414
415
416//InsertOpcode.cpp
417void InsertDimStatement_ToProcHead(char *lpszCommand);
418
419
420
421////////////////////////////////
422// AMD64機械語生成に利用する関数郡
423////////////////////////////////
424
425//Mod(モード)
426#define MOD_BASE (char)0x00
427#define MOD_DISP32 (char)0xFF
428#define MOD_BASE_DISP8 (char)0x40
429#define MOD_BASE_DISP32 (char)0x80
430#define MOD_REG (char)0xC0
431
432#define USE_OFFSET 1
433#define NON_OFFSET 0
434
435//amd64_main.cpp
436BOOL IsSafeReg(int reg);
437void op_push(int reg);
438void op_push_value(long data);
439void op_pop(int reg);
440void op_mov_RV (int op_size,int reg,int i32data);
441void op_mov_RV64 (int reg,_int64 i64data);
442void op_mov_RM (int op_size,int reg,int base_reg,int offset,char mod);
443void op_mov_RM_ex (int op_size,int reg,int base_reg1,int base_reg2,int offset,BOOL bUseOffset);
444void op_mov_MR (int op_size,int reg,int base_reg,int offset,char mod);
445void op_mov_MR_ex (int op_size,int reg,int base_reg1,int base_reg2,int offset,BOOL bUseOffset);
446void op_mov_MV (int op_size,int base_reg,int offset,BOOL bUseOffset,int i32data);
447void op_mov_RR (int reg1,int reg2);
448void op_mov64_ToReg (int reg,_int64 i64data);
449void op_mov64_ToReg (int reg,int i32data);
450void op_mov64_ToReg_FromReg (int reg1,int reg2);
451void op_movsxd (int reg64,int reg32);
452void op_movsx64_FromReg16 (int reg64,int reg16);
453void op_movsx64_FromReg8 (int reg64,int reg8);
454void op_movsx32_FromReg16 (int reg32,int reg16);
455void op_movsx32_FromReg8 (int reg32,int reg8);
456void op_movsx16_FromReg8 (int reg32,int reg8);
457void op_inc (int reg);
458void op_dec (int reg);
459void op_add_RM (int op_size,int reg,int base_reg,int offset,char mod);
460void op_add64_value (int reg,int offset);
461void op_add64_reg (int reg1,int reg2);
462void op_add32_reg (int reg1,int reg2);
463void op_sub_RV (int op_size,int reg,int i32data);
464void op_sub64_reg (int reg1,int reg2);
465void op_sub32_reg (int reg1,int reg2);
466void op_imul_reg (int op_size,int reg1,int reg2);
467void op_imul_value (int op_size,int reg,int i32data);
468void op_div64_reg (int reg);
469void op_idiv64_reg (int reg);
470void op_shl_reg (int op_size,int reg);
471void op_sar_reg (int op_size,int reg);
472void op_shr_reg (int op_size,int reg);
473void op_and_reg (int op_size,int reg1,int reg2);
474void op_and64_value (int reg,int offset);
475void op_and32_value (int reg,int offset);
476void op_or_reg (int op_size,int reg1,int reg2);
477void op_xor_reg (int op_size,int reg1,int reg2);
478void op_not_reg (int op_size,int reg);
479void op_test (int reg1,int reg2);
480void op_cmp_reg (int op_size,int reg1,int reg2);
481void op_cmp_value (int op_size,int reg,char byte_data);
482void op_movlpd_MR (int xmm_reg,int base_reg,int offset,char mod);
483void op_movlpd_RM (int xmm_reg,int base_reg,int offset,char mod);
484void op_movsd_RR (int xmm_reg1,int xmm_reg2);
485void op_movsd_MR (int xmm_reg,int base_reg,int offset,char mod);
486void op_movss_RR (int xmm_reg1,int xmm_reg2);
487void op_movss_RM (int xmm_reg,int base_reg,int offset,char mod);
488void op_movss_MR (int xmm_reg,int base_reg,int offset,char mod);
489void op_movd_RX (int reg,int xmm_reg);
490void op_cvtsd2ss (int xmm_reg1,int xmm_reg2);
491void op_cvtss2sd (int xmm_reg1,int xmm_reg2);
492void op_cvttsd2si_xmm (int op_size,int reg,int xmm_reg);
493void op_cvttss2si_xmm (int op_size,int reg,int xmm_reg);
494void op_cvtsi2sd_reg (int op_size,int xmm_reg,int reg);
495void op_cvtsi2ss_reg (int op_size,int xmm_reg,int reg);
496void op_comisd (int xmm_reg1,int xmm_reg2);
497void op_comiss (int xmm_reg1,int xmm_reg2);
498void op_rep_movs (int op_size);
499void op_add_rsp(int num);
500void op_sub_rsp(int num);
501void op_add_esp(int num);
502void op_sub_esp(int num);
503void op_fld_ptr_esp(int type);
504void op_zero_reg(int reg);
505void op_call(SUBINFO *psi);
Note: See TracBrowser for help on using the repository browser.