source: dev/BasicCompiler32/Opcode.h@ 47

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

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

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