source: dev/BasicCompiler32/Opcode.h@ 60

Last change on this file since 60 was 56, checked in by dai_9181, 18 years ago

・[Unicode]リテラル文字列のスイッチング
・[Unicode]Char型を文字型として扱うようにする
・[Unicode]SByte型を追加する
に対応。

/unicodeコマンドオプションに対応。

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