source: dev/BasicCompiler32/Opcode.h@ 122

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

(呼び出し単体コードも対応→)関数の戻り値オブジェクトのメンバ・メソッドを一時オブジェクトを介さずに参照できるようにした。

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