source: dev/BasicCompiler32/Opcode.h@ 6

Last change on this file since 6 was 3, checked in by dai_9181, 18 years ago
File size: 10.4 KB
RevLine 
[3]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);
97
98//NumOpe.cpp
99void PushReturnValue(int type);
100int NumOpe(char *Command,int BaseType,LONG_PTR lpBaseIndex,LONG_PTR *plpIndex,BOOL *pbUseHeap=0);
101
102//NumOpe_Arithmetic.cpp
103void GetStackData_ToRegister(int *type,int sp);
104BOOL CalcTwoTerm_Arithmetic(int idCalc,int *type,LONG_PTR *index_stack,int *pStackPointer);
105BOOL Calc_Mod(int *type,int *pStackPointer);
106BOOL Calc_Divide(int *type,int *pStackPointer,int BaseType);
107BOOL Calc_IntDivide(int *type,LONG_PTR *index_stack,int *pStackPointer);
108BOOL Calc_MinusMark(int *type,int sp);
109BOOL Calc_Power(int *type,int *pStackPointer);
110BOOL Calc_Cast(int *type,LONG_PTR *index_stack,int *pStackPointer);
111BOOL Calc_SHL(int *type,int *pStackPointer);
112BOOL Calc_SHR(int *type,int *pStackPointer);
113
114//NumOpe_Logical.cpp
115BOOL Calc_Xor(int *type,LONG_PTR *index_stack,int *pStackPointer);
116BOOL Calc_Or(int *type,LONG_PTR *index_stack,int *pStackPointer);
117BOOL Calc_And(int *type,LONG_PTR *index_stack,int *pStackPointer);
118BOOL Calc_Not(int *type,int sp);
119
120//NumOpe_Relation.cpp
121BOOL Calc_Relation_PE(int *type_stack,LONG_PTR *index_stack,int *pStackPointer);
122BOOL Calc_Relation_QE(int *type_stack,LONG_PTR *index_stack,int *pStackPointer);
123BOOL Calc_Relation_P(int *type_stack,LONG_PTR *index_stack,int *pStackPointer);
124BOOL Calc_Relation_Q(int *type_stack,LONG_PTR *index_stack,int *pStackPointer);
125BOOL Calc_Relation_NotEqual(int *type,int *pStackPointer);
126BOOL Calc_Relation_Equal(int *type,int *pStackPointer);
127
128//NumOpe_TypeOperation.cpp
129void ExtendStackTo64(int type);
130void ChangeTypeToWhole(int OldType,int NewType);
131
132//Compile_Set_Var.cpp
133BOOL IsUse_ecx(RELATIVE_VAR *pRelativeVar);
134void SetObjectVariable(LONG_PTR lpVarIndex,int CalcType,LONG_PTR lpCalcIndex,BOOL bUseHeap);
135void SetDoubleVariable(int type,DWORD VarKind,DWORD offset,BOOL bOffsetOffset);
136void SetSingleVariable(int type,DWORD VarKind,DWORD offset,BOOL bOffsetOffset);
137void SetInt64Variable(int type,RELATIVE_VAR *pRelative);
138void SetDWordVariable(int type,DWORD VarKind,DWORD offset,BOOL bOffsetOffset);
139void SetLongVariable(int type,DWORD VarKind,DWORD offset,BOOL bOffsetOffset);
140void Set16Variable(int type,DWORD VarKind,DWORD offset,BOOL bOffsetOffset);
141void Set8Variable(int type,DWORD VarKind,DWORD offset,BOOL bOffsetOffset);
142
143//increment.cpp
144void IncDec(int idCalc, char *lpszLeft, char *lpszRight);
145
146//calc2.cpp
147#define EXP_TYPE_NUMBER 1
148#define EXP_TYPE_EAX 2
149#define EXP_TYPE_FPU 3
150#define EXP_TYPE_VAR 4
151int NumOpEx(char *Command,double *pDbl,DWORD *pdwType,RELATIVE_VAR *pRelativeVar);
152
153//SetVar.cpp
154BOOL SetVariable(DWORD dwVarType,RELATIVE_VAR *pVarRelativeVar,
155 DWORD dwExpType,DWORD dwType,void *data);
156
157//Compile_Calc_PushVar.cpp
158void SetReg_RealVariable(int type,RELATIVE_VAR *pRelativeVar);
159void SetReg_WholeVariable(int type,RELATIVE_VAR *pRelativeVar,int reg);
160void PushDoubleVariable(RELATIVE_VAR *pRelativeVar);
161void PushLongVariable(RELATIVE_VAR *pRelativeVar);
162void PushIntegerVariable(RELATIVE_VAR *pRelativeVar);
163void PushWordVariable(RELATIVE_VAR *pRelativeVar);
164void PushCharVariable(RELATIVE_VAR *pRelativeVar);
165void PushByteVariable(RELATIVE_VAR *pRelativeVar);
166
167//Compile_Object.cpp
168int Operator_New(char *Parameter,LONG_PTR *plpIndex);
169void OpcodeDelete(char *Parameter);
170
171//Compile_Var.cpp
172void GetWithName(char *buffer);
173void SetThisPtrToReg(int reg);
174BOOL GetVarOffset(BOOL bError,char *NameBuffer,int *pType,RELATIVE_VAR *pRelativeVar,LONG_PTR *plpIndex,int *pss=0);
175BOOL SetInitGlobalData(int offset,int type,LONG_PTR lpIndex,int *SubScripts,char *InitBuf);
176#define DIMFLAG_INITDEBUGVAR 1
177#define DIMFLAG_NONCALL_CONSTRACTOR 2
178#define DIMFLAG_STATIC 4
179void OpcodeDim(char *Parameter,DWORD dwFlag);
180void SetVarPtrToEax(RELATIVE_VAR *pRelativeVar);
181
182//CParameter.cpp
183#define OVERLOAD_LEVEL1 1
184#define OVERLOAD_LEVEL2 2
185#define OVERLOAD_LEVEL3 3
186class CParameter{
187 char *Parms[255];
188 TYPEINFO types[255];
189 int ParmsNum;
190
191 TYPEINFO ReturnTypeInfo;
192
193public:
194 CParameter(char *buffer);
195 CParameter(PARAMETER_INFO *pParamInfo,int ParmNum);
196 ~CParameter();
197 void SetReturnType(TYPEINFO *pTypeInfo);
198
199private:
200 BOOL _overload_check(PARAMETER_INFO *ppi,int pi_num,TYPEINFO *pReturnTypeInfo,int overload_level);
201 SUBINFO *OverloadSolutionWithReturnType(char *name,SUBINFO **ppsi,int num);
202public:
203 SUBINFO *OverloadSolution(char *name,SUBINFO **ppsi,int num);
204
205 BOOL ErrorCheck(char *FuncName,PARAMETER_INFO *ppi,int pi_num,int SecondParmNum);
206 void MacroParameterSupport(PARAMETER_INFO *ppi);
207 void SetObjectParameter(CClass *pobj_Class,LPSTR Parameter);
208 int SetParameter(char *FuncName,PARAMETER_INFO *ppi,int pi_num,int SecondParmNum);
209};
210
211//Compile_CallProc.cpp
212void AddLocalVarAddrSchedule();
213int CallProc(int idProc,void *pInfo,char *name,char *Parameter,LONG_PTR *plpRetIndex);
214BOOL CallPropertyMethod(char *variable,char *RightSide,TYPEINFO *pRetTypeInfo);
215#define PROCFLAG_NEW 1
216int Opcode_CallProcPtr(char *variable,char *Parameter,PROCPTRINFO *pi,LONG_PTR *plpIndex);
217int Opcode_CallProc(char *Parameter,SUBINFO *psi,LONG_PTR *plpIndex,DWORD dwFlags,char *ObjectName,int RefType);
218int Opcode_CallDllProc(char *Parameter,DECLAREINFO *pdi,LONG_PTR *plpIndex);
219
220//Compile_ProcOp.cpp
221void CompileLocal();
222
223//Compile_Func.cpp
224int GetFunctionType(int FuncNum);
225int GetFunctionFromName(char *FuncName);
226int Opcode_CallFunc(char *Parameter,int FuncNum);
227
228//OperatorProc.cpp
229void FreeTempObject(int reg,CClass *pobj_c);
230int CallOperatorProc(int idCalc,TYPEINFO *pBaseTypeInfo,int *type,LONG_PTR *index_stack,BOOL *bUseHeap,int &sp);
231void CallCastOperatorProc(int &CalcType,LONG_PTR &lpCalcIndex,BOOL bCalcUseHeap,int ToType,LONG_PTR lpToIndex);
232void CallArrayOperatorProc(CClass *pobj_Class,char *ObjectName,char *Parameter,TYPEINFO &RetTypeInfo);
233
234//Compile_Statement.cpp
235void OpcodeOthers(char *Command);
236void OpcodeIf(char *Parameter);
237void OpcodeGoto(char *Parameter);
238void OpcodeWhile(char *Parameter);
239void OpcodeExitWhile(void);
240void OpcodeFor(char *Parameter);
241void OpcodeExitFor(void);
242void OpcodeDo(char *Parameter);
243void OpcodeExitDo(void);
244void OpcodeContinue(void);
245void OpcodeExitSub(void);
246void OpcodeSelect(char *Parameter);
247void OpcodeCase(char *Parameter);
248void OpcodeGosub(char *Parameter);
249void OpcodeReturn(char *Parameter);
250void Opcode_Input(char *Parameter);
251void Opcode_Print(char *Parameter,BOOL bWrite);
252void OpcodeCallPtr(char *Parameter);
253void OpcodeSetPtrData(char *Parameter,int type);
254
255
256
257
258////////////////////////////////
259// IA-32機械語生成に利用する関数郡
260////////////////////////////////
261
262//Mod(モード)
263#define MOD_BASE (char)0x00
264#define MOD_DISP32 (char)0xFF
265#define MOD_BASE_DISP8 (char)0x40
266#define MOD_BASE_DISP32 (char)0x80
267#define MOD_REG (char)0xC0
268
269#define USE_OFFSET 1
270#define NON_OFFSET 0
271
272//op32_main.cpp
273BOOL IsSafeReg(int reg);
274void op_mov_RV (int reg,int offset);
275void op_mov_RV (int op_size,int reg,int offset);
276void op_mov_RR (int reg1,int reg2);
277void op_mov_RM (int op_size,int reg,int base_reg,int offset,char mod);
278void op_mov_RM_ex (int op_size,int reg,int base_reg1,int base_reg2,int offset,BOOL bUseOffset);
279void op_mov_MR (int op_size,int reg,int base_reg,int offset,char mod);
280void op_mov_MR_ex (int op_size,int reg,int base_reg1,int base_reg2,int offset,BOOL bUseOffset);
281void op_movsx_R32R16 (int reg32,int reg16);
282void op_movsx_R32R8 (int reg32,int reg8);
283void op_movsx_R16R8 (int reg16,int reg8);
284void op_inc (int reg);
285void op_dec (int reg);
286void op_add_RV8 (int reg,char cValue);
287void op_add_RM (int op_size,int reg,int base_reg,int offset,char mod);
288void op_adc_RV8 (int reg,char cValue);
289void op_sub_RV8 (int reg,char cValue);
290void op_sbb_RV8 (int reg,char cValue);
291void op_and_RV (int reg,int value);
292void op_cdq ();
293
294void op_rep_movs (int op_size);
295
296void op_push(int reg);
297void op_push_value(long data);
298void op_pop(int reg);
299void op_add_esp(int num);
300void op_sub_esp(int num);
301void op_test(int reg1,int reg2);
302void op_fld_ptr_esp(int type);
303void op_fld_basereg (int type,int base_reg);
304void op_fld_base_offset (int type,int base_reg,int offset);
305void op_fld_base_offset_ex (int type,int base_reg1,int base_reg2,int offset,BOOL bUseOffset);
306void op_fstp_basereg (int type,int base_reg);
307void op_fstp_base_offset (int type,int base_reg,int offset);
308void op_fstp_base_offset_ex (int type,int base_reg1,int base_reg2,int offset,BOOL bUseOffset);
309void op_zero_reg(int reg);
310void fpu_cast();
311void fpu_cast_end();
312
313void op_call(SUBINFO *psi);
Note: See TracBrowser for help on using the repository browser.