source: dev/BasicCompiler32/Opcode.h@ 63

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

グローバル変数に対してByRefを指定できるようにした

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