source: dev/trunk/abdev/BasicCompiler32/Opcode.h@ 250

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

Selectステートメントのスケジュール機構をリファクタリング

File size: 11.2 KB
Line 
1#pragma once
2
3#include <Type.h>
4#include <Procedure.h>
5#include "MachineFixed.h"
6
7
8//変数の種類
9#define NON_VAR 0
10#define VAR_GLOBAL 1 // Global Variable
11#define VAR_REFGLOBAL 2 // Global Refference Variable
12#define VAR_LOCAL 3 // Local Variable
13#define VAR_REFLOCAL 4 // Local Refference Variable
14#define VAR_DIRECTMEM 5 // Direct memory
15
16
17extern int cp;
18extern int obp;
19extern char *OpBuffer;
20
21#define breakpoint OpBuffer[obp++]=(char)0xCC;
22
23
24//ラベルアドレス
25struct LABEL{
26 char *pName;
27 int line;
28 DWORD address;
29};
30
31//プロシージャの種類
32#define PROC_DEFAULT 1 //ユーザー定義関数
33#define PROC_DLL 2 //DLL関数
34#define PROC_BUILTIN 3 //コンパイラ埋め込み型
35#define PROC_PTR 4 //関数ポインタ
36
37//プロシージャ
38struct PROCEDURE{
39 char name[255];
40 int address;
41 int types[MAX_PARMS];
42 _int8 ByVal[MAX_PARMS];
43 BOOL ReturnType;
44};
45
46//With情報
47struct WITHINFO{
48 char **ppName;
49 int *pWithCp;
50 int num;
51};
52
53
54//RSrcSection.cpp
55char *GetRSrcSectionBuffer(int *pLen);
56
57//Compile.cpp
58void ChangeOpcode(char *Command);
59void GetGlobalDataForDll(void);
60DWORD CompileBuffer(char Return_Sequence,WORD Return_Command);
61
62//Compile_Calc.cpp
63void ChangeTypeToDouble_ToFpuReg(int OldType);
64void ChangeTypeToDouble(int OldType);
65void ChangeTypeToSingle(int OldType);
66void ChangeTypeToInt64(int OldType);
67void ChangeTypeToLong(int OldType);
68void ChangeTypeToInteger(int OldType);
69void ChangeTypeToByte(int OldType);
70void SetVariableFromEax(int VarType,int CalcType,RELATIVE_VAR *pRelativeVar);
71void OpcodeCalc( const char *Command );
72
73//NumOpe.cpp
74void PushReturnValue(int type);
75bool TermOpe(
76 const char *term,
77 const Type &baseType,
78 Type &resultType,
79 bool &isLiteral,
80 BOOL *pbUseHeap,
81 bool isWantObject = false,
82 bool *pIsClassName = NULL,
83 bool isProcedureCallOnly = false );
84bool NumOpe( int reg,
85 const char *expression,
86 const Type &baseType,
87 Type &resultType,
88 BOOL *pbUseHeap = NULL );
89bool NumOpe( const char *Command,
90 const Type &baseType,
91 Type &resultType,
92 BOOL *pbUseHeap = NULL );
93
94//NumOpe_Arithmetic.cpp
95void GetStackData_ToRegister(int *type,int sp);
96BOOL CalcTwoTerm_Arithmetic(int idCalc,int *type,LONG_PTR *index_stack,int *pStackPointer);
97BOOL Calc_Mod(int *type,int *pStackPointer);
98BOOL Calc_Divide(int *type,int *pStackPointer,int BaseType);
99BOOL Calc_IntDivide(int *type,LONG_PTR *index_stack,int *pStackPointer);
100BOOL Calc_MinusMark(int *type,int sp);
101BOOL Calc_Power(int *type,int *pStackPointer);
102BOOL Calc_Cast(int *type,LONG_PTR *index_stack,int *pStackPointer);
103BOOL Calc_SHL(int *type,int *pStackPointer);
104BOOL Calc_SHR(int *type,int *pStackPointer);
105
106//NumOpe_Logical.cpp
107BOOL Calc_Xor(int *type,LONG_PTR *index_stack,int *pStackPointer);
108BOOL Calc_Or(int *type,LONG_PTR *index_stack,int *pStackPointer);
109BOOL Calc_And(int *type,LONG_PTR *index_stack,int *pStackPointer);
110BOOL Calc_Not(int *type,int sp);
111
112//NumOpe_Relation.cpp
113BOOL Calc_Relation_PE(int *type_stack,LONG_PTR *index_stack,int *pStackPointer);
114BOOL Calc_Relation_QE(int *type_stack,LONG_PTR *index_stack,int *pStackPointer);
115BOOL Calc_Relation_P(int *type_stack,LONG_PTR *index_stack,int *pStackPointer);
116BOOL Calc_Relation_Q(int *type_stack,LONG_PTR *index_stack,int *pStackPointer);
117BOOL Calc_Relation_NotEqual(int *type,int *pStackPointer);
118BOOL Calc_Relation_Equal(int *type,int *pStackPointer);
119
120//NumOpe_TypeOperation.cpp
121void ExtendStackTo64(int type);
122void ChangeTypeToWhole(int OldType,int NewType);
123
124//Compile_Set_Var.cpp
125BOOL IsUse_ecx(RELATIVE_VAR *pRelativeVar);
126void SetStructVariable( const Type &varType, const Type &calcType, BOOL bUseHeap);
127void SetRealVariable(int VarType, int CalcType, RELATIVE_VAR *pRelativeVar);
128void SetWholeVariable( int varSize,int calcType, RELATIVE_VAR *pRelative );
129
130void SetDoubleVariable(int type,DWORD VarKind,DWORD offset,BOOL bOffsetOffset);
131void SetSingleVariable(int type,DWORD VarKind,DWORD offset,BOOL bOffsetOffset);
132void SetInt64Variable(int type,RELATIVE_VAR *pRelative);
133void SetDWordVariable(int type,DWORD VarKind,DWORD offset,BOOL bOffsetOffset);
134void SetLongVariable(int type,DWORD VarKind,DWORD offset,BOOL bOffsetOffset);
135void Set16Variable(int type,DWORD VarKind,DWORD offset,BOOL bOffsetOffset);
136void Set8Variable(int type,DWORD VarKind,DWORD offset,BOOL bOffsetOffset);
137void SetBooleanVariable(int type,RELATIVE_VAR *pRelative);
138void ExtendTypeTo64(int type);
139void ExtendTypeTo32(int type,int reg);
140void ExtendTypeTo16(int type,int reg);
141
142//increment.cpp
143void IncDec(int idCalc, const char *lpszLeft, const char *lpszRight);
144
145//calc2.cpp
146#define EXP_TYPE_NUMBER 1
147#define EXP_TYPE_EAX 2
148#define EXP_TYPE_FPU 3
149#define EXP_TYPE_VAR 4
150int NumOpEx(char *Command,double *pDbl,DWORD *pdwType,RELATIVE_VAR *pRelativeVar);
151
152//SetVar.cpp
153BOOL SetVariable(DWORD dwVarType,RELATIVE_VAR *pVarRelativeVar,
154 DWORD dwExpType,DWORD dwType,void *data);
155
156//Compile_Calc_PushVar.cpp
157void SetReg_RealVariable(int type,RELATIVE_VAR *pRelativeVar);
158void SetReg_WholeVariable(int type,RELATIVE_VAR *pRelativeVar,int reg, bool is64Head = false);
159void PushLongVariable(RELATIVE_VAR *pRelativeVar);
160
161//Compile_Object.cpp
162void Operator_New( const CClass &classObj, const char *objectSizeStr, const char *parameter, const Type &baseType );
163void OpcodeDelete(const char *Parameter, bool isSweeping);
164
165//Compile_Var.cpp
166void SetRelativeOffset( RELATIVE_VAR &relativeVar );
167bool _member_offset(bool isErrorEnabled, bool isWriteAccess, const CClass &objClass, const char *member, RELATIVE_VAR *pRelativeVar, Type &resultType, BOOL bPrivateAccess);
168void SetThisPtrToReg(int reg);
169bool GetVarOffset(bool isErrorEnabled,bool isWriteAccess,const char *NameBuffer,RELATIVE_VAR *pRelativeVar,Type &resultType, Subscripts *pResultSubscripts = NULL );
170bool SetInitGlobalData(int offset,const Type &type,const Subscripts &subscripts,const char *InitBuf);
171#define DIMFLAG_INITDEBUGVAR 1
172#define DIMFLAG_NONCALL_CONSTRACTOR 2
173#define DIMFLAG_STATIC 4
174#define DIMFLAG_CONST 8
175void dim( char *VarName, const Subscripts &subscripts, Type &type, const char *InitBuf,const char *ConstractParameter,DWORD dwFlags);
176void SetVarPtrToEax(RELATIVE_VAR *pRelativeVar);
177void SetVarPtrToReg(int reg,RELATIVE_VAR *pRelativeVar);
178bool Compile_AddGlobalRootsForGc();
179
180//ParamImpl.cpp
181class ParamImpl{
182 char *Parms[255];
183 vector<Type> types;
184 int ParmsNum;
185
186 Type returnType;
187
188 //一時オブジェクト管理用
189 bool useTempObject;
190 bool useTempParameters[255];
191 int nCountOfTempObjects;
192
193public:
194 ParamImpl(const char *buffer);
195 ParamImpl(const Parameters &params);
196 ~ParamImpl();
197 void SetReturnType( const Type &returnType );
198
199private:
200 bool EvaluateOverloadScore( int level, const Parameters &targetParms, const Type &targetResultType );
201public:
202 const UserProc *_OverloadSolution( const char *name, std::vector<const UserProc *> &subs, bool isEnabledReturnType = false );
203 const UserProc *OverloadSolution( const char *name, std::vector<const UserProc *> &subs, bool isEnabledReturnType = false );
204
205 void ApplyDefaultParameters( const Parameters &params );
206 bool ErrorCheck( const string &procName, const Parameters &params, int SecondParmNum = -1 );
207 void MacroParameterSupport( const Parameters &params );
208 void SetStructParameter( const Type &baseType, const char *expression );
209 int SetParameter( const string &procName, const Parameters &params, int SecondParmNum = -1 );
210
211 //一時オブジェクトパラメータの生成と破棄
212 int NewTempParameters( const string &procName, const Parameters &params, int SecondParmNum = -1 );
213 void DeleteTempParameters();
214};
215
216//Compile_CallProc.cpp
217void AddLocalVarAddrSchedule();
218#define PROCFLAG_NEW 1
219bool Opcode_CallProcPtr( const char *variable, const char *lpszParms,ProcPointer *pProcPointer);
220bool Opcode_CallProc(const char *Parameter,const UserProc *pUserProc,DWORD dwFlags,const char *ObjectName,int RefType);
221bool Opcode_CallDllProc( const char *lpszParms, const DllProc *pDllProc );
222
223//Compile_ProcOp.cpp
224void CompileLocal();
225
226//Compile_Func.cpp
227int GetFunctionFromName(char *FuncName);
228bool Opcode_CallFunc( const char *Parameter, const int FuncNum, Type &resultType, bool isCallOn = true );
229
230//OperatorProc.cpp
231void FreeTempObject(int reg,const CClass *pobj_c);
232int CallOperatorProc(int idCalc, const Type &baseType, int *type_stack,LONG_PTR *index_stack,BOOL *bUseHeap,int &sp);
233void CallCastOperatorProc(Type &calcType,BOOL bCalcUseHeap,const Type &toType);
234void CallIndexerGetterProc(const CClass *pobj_Class,char *ObjectName,char *Parameter,Type &resultType);
235
236//Compile_Statement.cpp
237void OpcodeOthers( const char *Command );
238void OpcodeIf(char *Parameter);
239void OpcodeGoto(char *Parameter);
240void OpcodeWhile(char *Parameter);
241void OpcodeFor(char *Parameter);
242void OpcodeDo(char *Parameter);
243void OpcodeContinue(void);
244void OpcodeExitSub(void);
245void OpcodeSelect(const char *lpszParms);
246void OpcodeCase(char *Parameter);
247void OpcodeGosub(char *Parameter);
248void OpcodeReturn(char *Parameter);
249void OpcodeSetPtrData(char *Parameter,int type);
250
251
252
253
254////////////////////////////////
255// IA-32機械語生成に利用する関数郡
256////////////////////////////////
257
258//op32_main.cpp
259BOOL IsSafeReg(int reg);
260/*
261void op_mov_RV (int reg,int offset);
262void op_mov_RV (int op_size,int reg,int offset);
263void op_mov_RR (int reg1,int reg2);
264void op_mov_RM (int op_size,int reg,int base_reg,int offset,char mod);
265void op_mov_RM_ex (int op_size,int reg,int base_reg1,int base_reg2,int offset,BOOL bUseOffset);
266void op_mov_MR (int op_size,int reg,int base_reg,int offset,char mod);
267void op_mov_MR_ex (int op_size,int reg,int base_reg1,int base_reg2,int offset,BOOL bUseOffset);
268void op_movsx_R32R16 (int reg32,int reg16);
269void op_movsx_R32R8 (int reg32,int reg8);
270void op_movsx_R16R8 (int reg16,int reg8);
271void op_inc (int reg);
272void op_dec (int reg);
273void op_add_RV8 (int reg,char cValue);
274void op_add_RM (int op_size,int reg,int base_reg,int offset,char mod);
275void op_adc_RV8 (int reg,char cValue);
276void op_sub_RV8 (int reg,char cValue);
277void op_sbb_RV8 (int reg,char cValue);
278void op_sbb_RR ( int reg1, int reg2 );
279void op_imul_RR (int reg1,int reg2);
280void op_imul_RV (int reg,int i32data);
281void op_and_RV (int reg,int value);
282void op_or_RR ( int op_size, int reg1, int reg2 );
283void op_neg ( int reg );
284void op_cdq ();
285
286void op_rep_movs (int op_size);
287
288void op_push(int reg);
289void op_push_V(long data);
290void op_pop(int reg = REG_NON);
291void op_add_esp(int num);
292void op_sub_esp(int num);
293void op_cmp_RR( int reg1, int reg2 );
294void op_cmp_value(int op_size,int reg,char byte_data);
295void op_setne( int reg );
296void op_test(int reg1,int reg2);
297void op_fld_ptr_esp(int type);
298void op_fld_basereg (int type,int base_reg);
299void op_fld_base_offset (int type,int base_reg,int offset);
300void op_fld_base_offset_ex (int type,int base_reg1,int base_reg2,int offset,BOOL bUseOffset);
301void op_fstp_basereg (int type,int base_reg);
302void op_fstp_base_offset (int type,int base_reg,int offset);
303void op_fstp_base_offset_ex (int type,int base_reg1,int base_reg2,int offset,BOOL bUseOffset);
304void op_fstp_push ( Type &type );
305void op_fistp_ptr_esp ( int typeSize );
306void op_zero_reg(int reg);
307void fpu_cast();
308void fpu_cast_end();
309
310void op_call(const UserProc *pUserProc);
311void op_ret();
312*/
Note: See TracBrowser for help on using the repository browser.