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

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

CodeGeneratorクラスのベースを実装

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