source: dev/BasicCompiler32/Opcode.h@ 51

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

オーバーロード解決用の関数保持リストを "SUBINFO " ではなく、"vector<SUBINFO *>" に変更した。

File size: 11.0 KB
Line 
1//Opcode.h
2
3//未定義の定数情報
4#define IMAGE_FILE_MACHINE_AMD64 0x8664
5
6
7//レジスタを示す定数
8#define REG_EAX 0x00 //reg:000
9#define REG_ECX 0x01 //reg:001
10#define REG_EDX 0x02 //reg:010
11#define REG_EBX 0x03 //reg:011
12#define REG_ESP 0x04 //reg:100
13#define REG_EBP 0x05 //reg:101
14#define REG_ESI 0x06 //reg:110
15#define REG_EDI 0x07 //reg:111
16
17#define REG_RAX REG_EAX
18#define REG_RCX REG_ECX
19#define REG_RDX REG_EDX
20#define REG_RBX REG_EBX
21#define REG_RSP REG_ESP
22#define REG_RBP REG_EBP
23#define REG_RSI REG_ESI
24#define REG_RDI REG_EDI
25
26#define REGISTER_OPERAND(reg) (reg&0x07)
27
28//変数の種類
29#define NON_VAR 0
30#define VAR_GLOBAL 1 //Global Variable
31#define VAR_LOCAL 2 //Local Variable
32#define VAR_REFLOCAL 3 //Local Refference Variable
33#define VAR_DIRECTMEM 4 //Direct memory
34
35
36extern int cp;
37extern int obp;
38extern char *OpBuffer;
39
40#define breakpoint OpBuffer[obp++]=(char)0xCC;
41
42
43//ラベルアドレス
44struct LABEL{
45 char *pName;
46 int line;
47 DWORD address;
48};
49
50//Goto未知ラベル
51struct GOTOLABELSCHEDULE{
52 char *pName;
53 int line;
54 DWORD pos;
55 DWORD now_cp;
56};
57
58//プロシージャの種類
59#define PROC_DEFAULT 1 //ユーザー定義関数
60#define PROC_DLL 2 //DLL関数
61#define PROC_BUILTIN 3 //コンパイラ埋め込み型
62#define PROC_PTR 4 //関数ポインタ
63
64//プロシージャ
65struct PROCEDURE{
66 char name[255];
67 int address;
68 int types[MAX_PARMS];
69 _int8 ByVal[MAX_PARMS];
70 BOOL ReturnType;
71};
72
73//With情報
74struct WITHINFO{
75 char **ppName;
76 int *pWithCp;
77 int num;
78};
79
80
81//MakePeHdr.cpp
82int AddDataTable(char *buffer,int length);
83
84//RSrcSection.cpp
85char *GetRSrcSectionBuffer(int *pLen);
86
87//Compile.cpp
88void ChangeOpcode(char *Command);
89void GetGlobalDataForDll(void);
90DWORD CompileBuffer(char Return_Sequence,WORD Return_Command);
91
92//Compile_Calc.cpp
93void ChangeTypeToDouble_ToFpuReg(int OldType);
94void ChangeTypeToDouble(int OldType);
95void ChangeTypeToSingle(int OldType);
96void ChangeTypeToInt64(int OldType);
97void ChangeTypeToLong(int OldType);
98void ChangeTypeToInteger(int OldType);
99void ChangeTypeToByte(int OldType);
100void OpcodeCalc(char *Command);
101void SetRefVariable( const char *varname, const char *expression );
102
103//NumOpe.cpp
104void PushReturnValue(int type);
105int NumOpe(const char *Command,int BaseType,LONG_PTR lpBaseIndex,LONG_PTR *plpIndex,BOOL *pbUseHeap=0);
106
107//NumOpe_Arithmetic.cpp
108void GetStackData_ToRegister(int *type,int sp);
109BOOL CalcTwoTerm_Arithmetic(int idCalc,int *type,LONG_PTR *index_stack,int *pStackPointer);
110BOOL Calc_Mod(int *type,int *pStackPointer);
111BOOL Calc_Divide(int *type,int *pStackPointer,int BaseType);
112BOOL Calc_IntDivide(int *type,LONG_PTR *index_stack,int *pStackPointer);
113BOOL Calc_MinusMark(int *type,int sp);
114BOOL Calc_Power(int *type,int *pStackPointer);
115BOOL Calc_Cast(int *type,LONG_PTR *index_stack,int *pStackPointer);
116BOOL Calc_SHL(int *type,int *pStackPointer);
117BOOL Calc_SHR(int *type,int *pStackPointer);
118
119//NumOpe_Logical.cpp
120BOOL Calc_Xor(int *type,LONG_PTR *index_stack,int *pStackPointer);
121BOOL Calc_Or(int *type,LONG_PTR *index_stack,int *pStackPointer);
122BOOL Calc_And(int *type,LONG_PTR *index_stack,int *pStackPointer);
123BOOL Calc_Not(int *type,int sp);
124
125//NumOpe_Relation.cpp
126BOOL Calc_Relation_PE(int *type_stack,LONG_PTR *index_stack,int *pStackPointer);
127BOOL Calc_Relation_QE(int *type_stack,LONG_PTR *index_stack,int *pStackPointer);
128BOOL Calc_Relation_P(int *type_stack,LONG_PTR *index_stack,int *pStackPointer);
129BOOL Calc_Relation_Q(int *type_stack,LONG_PTR *index_stack,int *pStackPointer);
130BOOL Calc_Relation_NotEqual(int *type,int *pStackPointer);
131BOOL Calc_Relation_Equal(int *type,int *pStackPointer);
132
133//NumOpe_TypeOperation.cpp
134void ExtendStackTo64(int type);
135void ChangeTypeToWhole(int OldType,int NewType);
136
137//Compile_Set_Var.cpp
138BOOL IsUse_ecx(RELATIVE_VAR *pRelativeVar);
139void SetObjectVariable(LONG_PTR lpVarIndex,int CalcType,LONG_PTR lpCalcIndex,BOOL bUseHeap);
140void SetDoubleVariable(int type,DWORD VarKind,DWORD offset,BOOL bOffsetOffset);
141void SetSingleVariable(int type,DWORD VarKind,DWORD offset,BOOL bOffsetOffset);
142void SetInt64Variable(int type,RELATIVE_VAR *pRelative);
143void SetDWordVariable(int type,DWORD VarKind,DWORD offset,BOOL bOffsetOffset);
144void SetLongVariable(int type,DWORD VarKind,DWORD offset,BOOL bOffsetOffset);
145void Set16Variable(int type,DWORD VarKind,DWORD offset,BOOL bOffsetOffset);
146void Set8Variable(int type,DWORD VarKind,DWORD offset,BOOL bOffsetOffset);
147void SetBooleanVariable(int type,RELATIVE_VAR *pRelative);
148
149//increment.cpp
150void IncDec(int idCalc, char *lpszLeft, char *lpszRight);
151
152//calc2.cpp
153#define EXP_TYPE_NUMBER 1
154#define EXP_TYPE_EAX 2
155#define EXP_TYPE_FPU 3
156#define EXP_TYPE_VAR 4
157int NumOpEx(char *Command,double *pDbl,DWORD *pdwType,RELATIVE_VAR *pRelativeVar);
158
159//SetVar.cpp
160BOOL SetVariable(DWORD dwVarType,RELATIVE_VAR *pVarRelativeVar,
161 DWORD dwExpType,DWORD dwType,void *data);
162
163//Compile_Calc_PushVar.cpp
164void SetReg_RealVariable(int type,RELATIVE_VAR *pRelativeVar);
165void SetReg_WholeVariable(int type,RELATIVE_VAR *pRelativeVar,int reg);
166void PushDoubleVariable(RELATIVE_VAR *pRelativeVar);
167void PushLongVariable(RELATIVE_VAR *pRelativeVar);
168void PushIntegerVariable(RELATIVE_VAR *pRelativeVar);
169void PushWordVariable(RELATIVE_VAR *pRelativeVar);
170void PushCharVariable(RELATIVE_VAR *pRelativeVar);
171void PushByteVariable(RELATIVE_VAR *pRelativeVar);
172
173//Compile_Object.cpp
174int Operator_New(const char *Parameter,LONG_PTR *plpIndex);
175void OpcodeDelete(char *Parameter);
176
177//Compile_Var.cpp
178void GetWithName(char *buffer);
179void SetThisPtrToReg(int reg);
180BOOL GetVarOffset(bool isErrorEnabled,bool isWriteAccess,const char *NameBuffer,int *pType,RELATIVE_VAR *pRelativeVar,LONG_PTR *plpIndex,int *pss=0);
181BOOL SetInitGlobalData(int offset,int type,LONG_PTR lpIndex,int *SubScripts,char *InitBuf);
182#define DIMFLAG_INITDEBUGVAR 1
183#define DIMFLAG_NONCALL_CONSTRACTOR 2
184#define DIMFLAG_STATIC 4
185#define DIMFLAG_CONST 8
186void OpcodeDim(char *Parameter,DWORD dwFlag);
187void SetVarPtrToEax(RELATIVE_VAR *pRelativeVar);
188
189//CParameter.cpp
190#define OVERLOAD_LEVEL1 1
191#define OVERLOAD_LEVEL2 2
192#define OVERLOAD_LEVEL3 3
193class CParameter{
194 char *Parms[255];
195 TYPEINFO types[255];
196 int ParmsNum;
197
198 TYPEINFO ReturnTypeInfo;
199
200 //一時オブジェクト管理用
201 bool useTempObject;
202 bool useTempParameters[255];
203 int nCountOfTempObjects;
204
205public:
206 CParameter(const char *buffer);
207 CParameter(const PARAMETER_INFO *pParamInfo, const int ParmNum);
208 ~CParameter();
209 void SetReturnType(TYPEINFO *pTypeInfo);
210
211private:
212 BOOL _overload_check(PARAMETER_INFO *ppi,int pi_num,TYPEINFO *pReturnTypeInfo,int overload_level);
213 SUBINFO *OverloadSolutionWithReturnType( const char *name, std::vector<SUBINFO *> &subs );
214public:
215 SUBINFO *OverloadSolution( const char *name, std::vector<SUBINFO *> &subs );
216
217 BOOL ErrorCheck(const char *FuncName,PARAMETER_INFO *ppi,int pi_num,int SecondParmNum);
218 void MacroParameterSupport(PARAMETER_INFO *ppi);
219 void SetObjectParameter(CClass *pobj_Class,LPSTR Parameter);
220 int SetParameter(const char *FuncName,PARAMETER_INFO *ppi,int pi_num,int SecondParmNum);
221
222 //一時オブジェクトパラメータの生成と破棄
223 void NewTempParameters( const char *FuncName,PARAMETER_INFO *ppi,int pi_num,int SecondParmNum );
224 void DeleteTempParameters();
225};
226
227//Compile_CallProc.cpp
228void AddLocalVarAddrSchedule();
229#define PROCFLAG_NEW 1
230int Opcode_CallProcPtr(char *variable,char *Parameter,PROCPTRINFO *pi,LONG_PTR *plpIndex);
231void Opcode_CallProc(char *Parameter,SUBINFO *psi,DWORD dwFlags,char *ObjectName,int RefType);
232int Opcode_CallDllProc(char *Parameter,DECLAREINFO *pdi,LONG_PTR *plpIndex);
233
234//Compile_ProcOp.cpp
235void CompileLocal();
236
237//Compile_Func.cpp
238int GetFunctionType(int FuncNum);
239int GetFunctionFromName(char *FuncName);
240void Opcode_CallFunc( const char *Parameter, const int FuncNum, TYPEINFO &ReturnTypeInfo );
241
242//OperatorProc.cpp
243void FreeTempObject(int reg,CClass *pobj_c);
244int CallOperatorProc(int idCalc,TYPEINFO *pBaseTypeInfo,int *type,LONG_PTR *index_stack,BOOL *bUseHeap,int &sp);
245void CallCastOperatorProc(int &CalcType,LONG_PTR &lpCalcIndex,BOOL bCalcUseHeap,int ToType,LONG_PTR lpToIndex);
246void CallIndexerGetterProc(CClass *pobj_Class,char *ObjectName,char *Parameter,TYPEINFO &RetTypeInfo);
247
248//Compile_Statement.cpp
249void OpcodeOthers(char *Command);
250void OpcodeIf(char *Parameter);
251void OpcodeGoto(char *Parameter);
252void OpcodeWhile(char *Parameter);
253void OpcodeFor(char *Parameter);
254void OpcodeDo(char *Parameter);
255void OpcodeContinue(void);
256void OpcodeExitSub(void);
257void OpcodeSelect(char *Parameter);
258void OpcodeCase(char *Parameter);
259void OpcodeGosub(char *Parameter);
260void OpcodeReturn(char *Parameter);
261void Opcode_Input(char *Parameter);
262void Opcode_Print(char *Parameter,BOOL bWrite);
263void OpcodeCallPtr(char *Parameter);
264void OpcodeSetPtrData(char *Parameter,int type);
265
266
267
268
269////////////////////////////////
270// IA-32機械語生成に利用する関数郡
271////////////////////////////////
272
273//Mod(モード)
274#define MOD_BASE (char)0x00
275#define MOD_DISP32 (char)0xFF
276#define MOD_BASE_DISP8 (char)0x40
277#define MOD_BASE_DISP32 (char)0x80
278#define MOD_REG (char)0xC0
279
280#define USE_OFFSET 1
281#define NON_OFFSET 0
282
283//op32_main.cpp
284BOOL IsSafeReg(int reg);
285void op_mov_RV (int reg,int offset);
286void op_mov_RV (int op_size,int reg,int offset);
287void op_mov_RR (int reg1,int reg2);
288void op_mov_RM (int op_size,int reg,int base_reg,int offset,char mod);
289void op_mov_RM_ex (int op_size,int reg,int base_reg1,int base_reg2,int offset,BOOL bUseOffset);
290void op_mov_MR (int op_size,int reg,int base_reg,int offset,char mod);
291void op_mov_MR_ex (int op_size,int reg,int base_reg1,int base_reg2,int offset,BOOL bUseOffset);
292void op_movsx_R32R16 (int reg32,int reg16);
293void op_movsx_R32R8 (int reg32,int reg8);
294void op_movsx_R16R8 (int reg16,int reg8);
295void op_inc (int reg);
296void op_dec (int reg);
297void op_add_RV8 (int reg,char cValue);
298void op_add_RM (int op_size,int reg,int base_reg,int offset,char mod);
299void op_adc_RV8 (int reg,char cValue);
300void op_sub_RV8 (int reg,char cValue);
301void op_sbb_RV8 (int reg,char cValue);
302void op_sbb_RR ( int reg1, int reg2 );
303void op_and_RV (int reg,int value);
304void op_or_RR ( int op_size, int reg1, int reg2 );
305void op_neg ( int reg );
306void op_cdq ();
307
308void op_rep_movs (int op_size);
309
310void op_push(int reg);
311void op_push_value(long data);
312void op_pop(int reg);
313void op_add_esp(int num);
314void op_sub_esp(int num);
315void op_cmp_value(int op_size,int reg,char byte_data);
316void op_setne( int reg );
317void op_test(int reg1,int reg2);
318void op_fld_ptr_esp(int type);
319void op_fld_basereg (int type,int base_reg);
320void op_fld_base_offset (int type,int base_reg,int offset);
321void op_fld_base_offset_ex (int type,int base_reg1,int base_reg2,int offset,BOOL bUseOffset);
322void op_fstp_basereg (int type,int base_reg);
323void op_fstp_base_offset (int type,int base_reg,int offset);
324void op_fstp_base_offset_ex (int type,int base_reg1,int base_reg2,int offset,BOOL bUseOffset);
325void op_zero_reg(int reg);
326void fpu_cast();
327void fpu_cast_end();
328
329void op_call(SUBINFO *psi);
Note: See TracBrowser for help on using the repository browser.