source: dev/BasicCompiler32/Opcode.h@ 8

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

Constステートメントで定数変数を宣言できるように改良。

File size: 10.5 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);
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
179#define DIMFLAG_CONST 8
180void OpcodeDim(char *Parameter,DWORD dwFlag);
181void SetVarPtrToEax(RELATIVE_VAR *pRelativeVar);
182
183//CParameter.cpp
184#define OVERLOAD_LEVEL1 1
185#define OVERLOAD_LEVEL2 2
186#define OVERLOAD_LEVEL3 3
187class CParameter{
188 char *Parms[255];
189 TYPEINFO types[255];
190 int ParmsNum;
191
192 TYPEINFO ReturnTypeInfo;
193
194public:
195 CParameter(char *buffer);
196 CParameter(PARAMETER_INFO *pParamInfo,int ParmNum);
197 ~CParameter();
198 void SetReturnType(TYPEINFO *pTypeInfo);
199
200private:
201 BOOL _overload_check(PARAMETER_INFO *ppi,int pi_num,TYPEINFO *pReturnTypeInfo,int overload_level);
202 SUBINFO *OverloadSolutionWithReturnType(char *name,SUBINFO **ppsi,int num);
203public:
204 SUBINFO *OverloadSolution(char *name,SUBINFO **ppsi,int num);
205
206 BOOL ErrorCheck(char *FuncName,PARAMETER_INFO *ppi,int pi_num,int SecondParmNum);
207 void MacroParameterSupport(PARAMETER_INFO *ppi);
208 void SetObjectParameter(CClass *pobj_Class,LPSTR Parameter);
209 int SetParameter(char *FuncName,PARAMETER_INFO *ppi,int pi_num,int SecondParmNum);
210};
211
212//Compile_CallProc.cpp
213void AddLocalVarAddrSchedule();
214int CallProc(int idProc,void *pInfo,char *name,char *Parameter,LONG_PTR *plpRetIndex);
215BOOL CallPropertyMethod(char *variable,char *RightSide,TYPEINFO *pRetTypeInfo);
216#define PROCFLAG_NEW 1
217int Opcode_CallProcPtr(char *variable,char *Parameter,PROCPTRINFO *pi,LONG_PTR *plpIndex);
218int Opcode_CallProc(char *Parameter,SUBINFO *psi,LONG_PTR *plpIndex,DWORD dwFlags,char *ObjectName,int RefType);
219int Opcode_CallDllProc(char *Parameter,DECLAREINFO *pdi,LONG_PTR *plpIndex);
220
221//Compile_ProcOp.cpp
222void CompileLocal();
223
224//Compile_Func.cpp
225int GetFunctionType(int FuncNum);
226int GetFunctionFromName(char *FuncName);
227int Opcode_CallFunc(char *Parameter,int FuncNum);
228
229//OperatorProc.cpp
230void FreeTempObject(int reg,CClass *pobj_c);
231int CallOperatorProc(int idCalc,TYPEINFO *pBaseTypeInfo,int *type,LONG_PTR *index_stack,BOOL *bUseHeap,int &sp);
232void CallCastOperatorProc(int &CalcType,LONG_PTR &lpCalcIndex,BOOL bCalcUseHeap,int ToType,LONG_PTR lpToIndex);
233void CallArrayOperatorProc(CClass *pobj_Class,char *ObjectName,char *Parameter,TYPEINFO &RetTypeInfo);
234
235//Compile_Statement.cpp
236void OpcodeOthers(char *Command);
237void OpcodeIf(char *Parameter);
238void OpcodeGoto(char *Parameter);
239void OpcodeWhile(char *Parameter);
240void OpcodeExitWhile(void);
241void OpcodeFor(char *Parameter);
242void OpcodeExitFor(void);
243void OpcodeDo(char *Parameter);
244void OpcodeExitDo(void);
245void OpcodeContinue(void);
246void OpcodeExitSub(void);
247void OpcodeSelect(char *Parameter);
248void OpcodeCase(char *Parameter);
249void OpcodeGosub(char *Parameter);
250void OpcodeReturn(char *Parameter);
251void Opcode_Input(char *Parameter);
252void Opcode_Print(char *Parameter,BOOL bWrite);
253void OpcodeCallPtr(char *Parameter);
254void OpcodeSetPtrData(char *Parameter,int type);
255
256
257
258
259////////////////////////////////
260// IA-32機械語生成に利用する関数郡
261////////////////////////////////
262
263//Mod(モード)
264#define MOD_BASE (char)0x00
265#define MOD_DISP32 (char)0xFF
266#define MOD_BASE_DISP8 (char)0x40
267#define MOD_BASE_DISP32 (char)0x80
268#define MOD_REG (char)0xC0
269
270#define USE_OFFSET 1
271#define NON_OFFSET 0
272
273//op32_main.cpp
274BOOL IsSafeReg(int reg);
275void op_mov_RV (int reg,int offset);
276void op_mov_RV (int op_size,int reg,int offset);
277void op_mov_RR (int reg1,int reg2);
278void op_mov_RM (int op_size,int reg,int base_reg,int offset,char mod);
279void op_mov_RM_ex (int op_size,int reg,int base_reg1,int base_reg2,int offset,BOOL bUseOffset);
280void op_mov_MR (int op_size,int reg,int base_reg,int offset,char mod);
281void op_mov_MR_ex (int op_size,int reg,int base_reg1,int base_reg2,int offset,BOOL bUseOffset);
282void op_movsx_R32R16 (int reg32,int reg16);
283void op_movsx_R32R8 (int reg32,int reg8);
284void op_movsx_R16R8 (int reg16,int reg8);
285void op_inc (int reg);
286void op_dec (int reg);
287void op_add_RV8 (int reg,char cValue);
288void op_add_RM (int op_size,int reg,int base_reg,int offset,char mod);
289void op_adc_RV8 (int reg,char cValue);
290void op_sub_RV8 (int reg,char cValue);
291void op_sbb_RV8 (int reg,char cValue);
292void op_and_RV (int reg,int value);
293void op_cdq ();
294
295void op_rep_movs (int op_size);
296
297void op_push(int reg);
298void op_push_value(long data);
299void op_pop(int reg);
300void op_add_esp(int num);
301void op_sub_esp(int num);
302void op_test(int reg1,int reg2);
303void op_fld_ptr_esp(int type);
304void op_fld_basereg (int type,int base_reg);
305void op_fld_base_offset (int type,int base_reg,int offset);
306void op_fld_base_offset_ex (int type,int base_reg1,int base_reg2,int offset,BOOL bUseOffset);
307void op_fstp_basereg (int type,int base_reg);
308void op_fstp_base_offset (int type,int base_reg,int offset);
309void op_fstp_base_offset_ex (int type,int base_reg1,int base_reg2,int offset,BOOL bUseOffset);
310void op_zero_reg(int reg);
311void fpu_cast();
312void fpu_cast_end();
313
314void op_call(SUBINFO *psi);
Note: See TracBrowser for help on using the repository browser.