source: dev/BasicCompiler32/Opcode.h@ 77

Last change on this file since 77 was 77, checked in by dai_9181, 17 years ago

デフォルトパラメータに対応。

File size: 11.6 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 SetVariableFromEax(int VarType,int CalcType,RELATIVE_VAR *pRelativeVar);
100void OpcodeCalc(char *Command);
101
102//NumOpe.cpp
103void PushReturnValue(int type);
104bool NumOpe( const char *Command,
105 const Type &baseType,
106 Type &resultType,
107 BOOL *pbUseHeap = NULL );
108
109//NumOpe_Arithmetic.cpp
110void GetStackData_ToRegister(int *type,int sp);
111BOOL CalcTwoTerm_Arithmetic(int idCalc,int *type,LONG_PTR *index_stack,int *pStackPointer);
112BOOL Calc_Mod(int *type,int *pStackPointer);
113BOOL Calc_Divide(int *type,int *pStackPointer,int BaseType);
114BOOL Calc_IntDivide(int *type,LONG_PTR *index_stack,int *pStackPointer);
115BOOL Calc_MinusMark(int *type,int sp);
116BOOL Calc_Power(int *type,int *pStackPointer);
117BOOL Calc_Cast(int *type,LONG_PTR *index_stack,int *pStackPointer);
118BOOL Calc_SHL(int *type,int *pStackPointer);
119BOOL Calc_SHR(int *type,int *pStackPointer);
120
121//NumOpe_Logical.cpp
122BOOL Calc_Xor(int *type,LONG_PTR *index_stack,int *pStackPointer);
123BOOL Calc_Or(int *type,LONG_PTR *index_stack,int *pStackPointer);
124BOOL Calc_And(int *type,LONG_PTR *index_stack,int *pStackPointer);
125BOOL Calc_Not(int *type,int sp);
126
127//NumOpe_Relation.cpp
128BOOL Calc_Relation_PE(int *type_stack,LONG_PTR *index_stack,int *pStackPointer);
129BOOL Calc_Relation_QE(int *type_stack,LONG_PTR *index_stack,int *pStackPointer);
130BOOL Calc_Relation_P(int *type_stack,LONG_PTR *index_stack,int *pStackPointer);
131BOOL Calc_Relation_Q(int *type_stack,LONG_PTR *index_stack,int *pStackPointer);
132BOOL Calc_Relation_NotEqual(int *type,int *pStackPointer);
133BOOL Calc_Relation_Equal(int *type,int *pStackPointer);
134
135//NumOpe_TypeOperation.cpp
136void ExtendStackTo64(int type);
137void ChangeTypeToWhole(int OldType,int NewType);
138
139//Compile_Set_Var.cpp
140BOOL IsUse_ecx(RELATIVE_VAR *pRelativeVar);
141void SetStructVariable( const Type &varType, const Type &calcType, BOOL bUseHeap);
142void SetRealVariable(int VarType, int CalcType, RELATIVE_VAR *pRelativeVar);
143void SetWholeVariable( int varSize,int calcType, RELATIVE_VAR *pRelative );
144
145void SetDoubleVariable(int type,DWORD VarKind,DWORD offset,BOOL bOffsetOffset);
146void SetSingleVariable(int type,DWORD VarKind,DWORD offset,BOOL bOffsetOffset);
147void SetInt64Variable(int type,RELATIVE_VAR *pRelative);
148void SetDWordVariable(int type,DWORD VarKind,DWORD offset,BOOL bOffsetOffset);
149void SetLongVariable(int type,DWORD VarKind,DWORD offset,BOOL bOffsetOffset);
150void Set16Variable(int type,DWORD VarKind,DWORD offset,BOOL bOffsetOffset);
151void Set8Variable(int type,DWORD VarKind,DWORD offset,BOOL bOffsetOffset);
152void SetBooleanVariable(int type,RELATIVE_VAR *pRelative);
153
154//increment.cpp
155void IncDec(int idCalc, char *lpszLeft, char *lpszRight);
156
157//calc2.cpp
158#define EXP_TYPE_NUMBER 1
159#define EXP_TYPE_EAX 2
160#define EXP_TYPE_FPU 3
161#define EXP_TYPE_VAR 4
162int NumOpEx(char *Command,double *pDbl,DWORD *pdwType,RELATIVE_VAR *pRelativeVar);
163
164//SetVar.cpp
165BOOL SetVariable(DWORD dwVarType,RELATIVE_VAR *pVarRelativeVar,
166 DWORD dwExpType,DWORD dwType,void *data);
167
168//Compile_Calc_PushVar.cpp
169void SetReg_RealVariable(int type,RELATIVE_VAR *pRelativeVar);
170void SetReg_WholeVariable(int type,RELATIVE_VAR *pRelativeVar,int reg);
171void PushDoubleVariable(RELATIVE_VAR *pRelativeVar);
172void PushLongVariable(RELATIVE_VAR *pRelativeVar);
173void PushIntegerVariable(RELATIVE_VAR *pRelativeVar);
174void PushWordVariable(RELATIVE_VAR *pRelativeVar);
175void PushCharVariable(RELATIVE_VAR *pRelativeVar);
176void PushByteVariable(RELATIVE_VAR *pRelativeVar);
177
178//Compile_Object.cpp
179void Operator_New( const CClass &classObj, const char *objectSizeStr, const char *parameter, const Type &baseType );
180void OpcodeDelete(const char *Parameter, bool isSweeping);
181
182//Compile_Var.cpp
183void SetRelativeOffset( RELATIVE_VAR &relativeVar );
184void GetWithName(char *buffer);
185void SetThisPtrToReg(int reg);
186bool GetVarOffset(bool isErrorEnabled,bool isWriteAccess,const char *NameBuffer,RELATIVE_VAR *pRelativeVar,Type &resultType,int *pss = 0);
187bool SetInitGlobalData(int offset,const Type &type,const int *SubScripts,char *InitBuf);
188#define DIMFLAG_INITDEBUGVAR 1
189#define DIMFLAG_NONCALL_CONSTRACTOR 2
190#define DIMFLAG_STATIC 4
191#define DIMFLAG_CONST 8
192void dim(bool isRef, char *VarName,int *SubScripts,Type &type,char *InitBuf,char *ConstractParameter,DWORD dwFlags);
193void SetVarPtrToEax(RELATIVE_VAR *pRelativeVar);
194
195//ParamImpl.cpp
196#define OVERLOAD_MIN_LEVEL 0
197#define OVERLOAD_MAX_LEVEL 3
198#define OVERLOAD_LEVEL0 0
199#define OVERLOAD_LEVEL1 1
200#define OVERLOAD_LEVEL2 2
201#define OVERLOAD_LEVEL3 3
202class ParamImpl{
203 char *Parms[255];
204 vector<Type> types;
205 int ParmsNum;
206
207 Type returnType;
208
209 //一時オブジェクト管理用
210 bool useTempObject;
211 bool useTempParameters[255];
212 int nCountOfTempObjects;
213
214public:
215 ParamImpl(const char *buffer);
216 ParamImpl(const Parameters &params);
217 ~ParamImpl();
218 void SetReturnType( const Type &returnType );
219
220private:
221 bool _overload_check( int level, const Parameters &targetParms, const Type &targetResultType );
222 UserProc *OverloadSolutionWithReturnType( const char *name, std::vector<UserProc *> &subs );
223public:
224 UserProc *OverloadSolution( const char *name, std::vector<UserProc *> &subs );
225
226 void ApplyDefaultParameters( const Parameters &params );
227 bool ErrorCheck( const string &procName, const Parameters &params, int SecondParmNum = -1 );
228 void MacroParameterSupport( const Parameters &params );
229 void SetStructParameter( const Type &baseType, const char *expression );
230 int SetParameter( const string &procName, const Parameters &params, int SecondParmNum = -1 );
231
232 //一時オブジェクトパラメータの生成と破棄
233 int NewTempParameters( const string &procName, const Parameters &params, int SecondParmNum = -1 );
234 void DeleteTempParameters();
235};
236
237//Compile_CallProc.cpp
238void AddLocalVarAddrSchedule();
239#define PROCFLAG_NEW 1
240bool Opcode_CallProcPtr( const char *variable, const char *lpszParms,ProcPointer *pProcPointer);
241bool Opcode_CallProc(const char *Parameter,UserProc *pUserProc,DWORD dwFlags,const char *ObjectName,int RefType);
242bool Opcode_CallDllProc( const char *lpszParms, DllProc *pDllProc );
243
244//Compile_ProcOp.cpp
245void CompileLocal();
246
247//Compile_Func.cpp
248int GetFunctionType(int FuncNum);
249int GetFunctionFromName(char *FuncName);
250bool Opcode_CallFunc( const char *Parameter, const int FuncNum, Type &resultType, bool isCallOn = true );
251
252//OperatorProc.cpp
253void FreeTempObject(int reg,const CClass *pobj_c);
254int CallOperatorProc(int idCalc, const Type &baseType, int *type_stack,LONG_PTR *index_stack,BOOL *bUseHeap,int &sp);
255void CallCastOperatorProc(Type &calcType,BOOL bCalcUseHeap,const Type &toType);
256void CallIndexerGetterProc(const CClass *pobj_Class,char *ObjectName,char *Parameter,Type &resultType);
257
258//Compile_Statement.cpp
259void OpcodeOthers(char *Command);
260void OpcodeIf(char *Parameter);
261void OpcodeGoto(char *Parameter);
262void OpcodeWhile(char *Parameter);
263void OpcodeFor(char *Parameter);
264void OpcodeDo(char *Parameter);
265void OpcodeContinue(void);
266void OpcodeExitSub(void);
267void OpcodeSelect(const char *lpszParms);
268void OpcodeCase(char *Parameter);
269void OpcodeGosub(char *Parameter);
270void OpcodeReturn(char *Parameter);
271void OpcodeSetPtrData(char *Parameter,int type);
272
273
274
275
276////////////////////////////////
277// IA-32機械語生成に利用する関数郡
278////////////////////////////////
279
280//Mod(モード)
281#define MOD_BASE (char)0x00
282#define MOD_DISP32 (char)0xFF
283#define MOD_BASE_DISP8 (char)0x40
284#define MOD_BASE_DISP32 (char)0x80
285#define MOD_REG (char)0xC0
286
287#define USE_OFFSET 1
288#define NON_OFFSET 0
289
290//op32_main.cpp
291BOOL IsSafeReg(int reg);
292void op_mov_RV (int reg,int offset);
293void op_mov_RV (int op_size,int reg,int offset);
294void op_mov_RR (int reg1,int reg2);
295void op_mov_RM (int op_size,int reg,int base_reg,int offset,char mod);
296void op_mov_RM_ex (int op_size,int reg,int base_reg1,int base_reg2,int offset,BOOL bUseOffset);
297void op_mov_MR (int op_size,int reg,int base_reg,int offset,char mod);
298void op_mov_MR_ex (int op_size,int reg,int base_reg1,int base_reg2,int offset,BOOL bUseOffset);
299void op_movsx_R32R16 (int reg32,int reg16);
300void op_movsx_R32R8 (int reg32,int reg8);
301void op_movsx_R16R8 (int reg16,int reg8);
302void op_inc (int reg);
303void op_dec (int reg);
304void op_add_RV8 (int reg,char cValue);
305void op_add_RM (int op_size,int reg,int base_reg,int offset,char mod);
306void op_adc_RV8 (int reg,char cValue);
307void op_sub_RV8 (int reg,char cValue);
308void op_sbb_RV8 (int reg,char cValue);
309void op_sbb_RR ( int reg1, int reg2 );
310void op_imul_RR (int reg1,int reg2);
311void op_imul_RV (int reg,int i32data);
312void op_and_RV (int reg,int value);
313void op_or_RR ( int op_size, int reg1, int reg2 );
314void op_neg ( int reg );
315void op_cdq ();
316
317void op_rep_movs (int op_size);
318
319void op_push(int reg);
320void op_push_V(long data);
321void op_pop(int reg);
322void op_add_esp(int num);
323void op_sub_esp(int num);
324void op_cmp_RR( int reg1, int reg2 );
325void op_cmp_value(int op_size,int reg,char byte_data);
326void op_setne( int reg );
327void op_test(int reg1,int reg2);
328void op_fld_ptr_esp(int type);
329void op_fld_basereg (int type,int base_reg);
330void op_fld_base_offset (int type,int base_reg,int offset);
331void op_fld_base_offset_ex (int type,int base_reg1,int base_reg2,int offset,BOOL bUseOffset);
332void op_fstp_basereg (int type,int base_reg);
333void op_fstp_base_offset (int type,int base_reg,int offset);
334void op_fstp_base_offset_ex (int type,int base_reg1,int base_reg2,int offset,BOOL bUseOffset);
335void op_fistp_ptr_esp ( int typeSize );
336void op_zero_reg(int reg);
337void fpu_cast();
338void fpu_cast_end();
339
340void op_call(UserProc *pUserProc);
Note: See TracBrowser for help on using the repository browser.