source: dev/trunk/abdev/BasicCompiler_Common/include/CodeGenerator.h@ 233

Last change on this file since 233 was 232, checked in by dai_9181, 17 years ago
File size: 10.6 KB
Line 
1#pragma once
2
3#include <NativeCode.h>
4
5#ifdef _AMD64_
6#include "../../BasicCompiler64/MachineFixed.h"
7#else
8#include "../../BasicCompiler32/MachineFixed.h"
9#endif
10
11
12void ReallocNativeCodeBuffer();
13
14class CodeGenerator
15{
16 NativeCode *pNativeCode;
17
18 // XMLシリアライズ用
19private:
20 friend class boost::serialization::access;
21 template<class Archive> void serialize(Archive& ar, const unsigned int version)
22 {
23 ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP( NativeCode );
24 }
25
26public:
27
28 void Select( NativeCode &nativeCode )
29 {
30 pNativeCode = &nativeCode;
31 }
32
33#ifdef _AMD64_
34 /////////////////////////////////////////////////////////////////
35 // 64ビット
36 /////////////////////////////////////////////////////////////////
37private:
38 void set_rex(int op_size,int reg,int index_reg,int base_reg);
39 void set_mod_rm_sib_disp(char mod,int reg,int scale,int index_reg,int base_reg,long disp, Schedule::Type scheduleType = Schedule::None );
40 void __op_format(int op_size,char op_prefix,char opcode1,char opcode2,int reg,int base_reg,long offset,char mod, Schedule::Type scheduleType = Schedule::None );
41 void __jmp_op_format( char opcode, long offset, int op_size );
42public:
43 void op_mov_RV (int op_size,int reg,long i32data, Schedule::Type scheduleType = Schedule::None );
44 void op_mov_RV64 (int reg,_int64 i64data);
45 void op_mov_RM (int op_size,int reg,int base_reg,long offset,char mod, Schedule::Type scheduleType = Schedule::None );
46 void op_mov_RM_ex (int op_size,int reg,int base_reg1,int base_reg2,long offset,BOOL bUseOffset, Schedule::Type scheduleType = Schedule::None );
47 void op_mov_MR (int op_size,int reg,int base_reg,long offset,char mod, Schedule::Type scheduleType = Schedule::None );
48 void op_mov_MR_ex (int op_size,int reg,int base_reg1,int base_reg2,long offset,BOOL bUseOffset, Schedule::Type scheduleType = Schedule::None );
49 void op_mov_MV (int op_size,int base_reg,int offset,BOOL bUseOffset,long i32data);
50 void op_mov_RR (int reg1,int reg2);
51 void op_movsxd (int reg64,int reg32);
52 void op_movsx64_FromReg16 (int reg64,int reg16);
53 void op_movsx64_FromReg8 (int reg64,int reg8);
54 void op_movsx32_FromReg16 (int reg32,int reg16);
55 void op_movsx32_FromReg8 (int reg32,int reg8);
56 void op_movsx16_FromReg8 (int reg32,int reg8);
57 void op_cqo ();
58 void op_inc (int reg);
59 void op_dec (int reg);
60 void op_add_RM (int op_size,int reg,int base_reg,int offset,char mod, Schedule::Type scheduleType = Schedule::None );
61 void op_add_RV (int reg,long offset, Schedule::Type scheduleType = Schedule::None );
62 void op_add_RR (int reg1,int reg2);
63 void op_add32_reg (int reg1,int reg2);
64 void op_sub_RV (int op_size,int reg,long i32data);
65 void op_sub64_reg (int reg1,int reg2);
66 void op_sub32_reg (int reg1,int reg2);
67 void op_sbb_RR ( int op_size, int reg1, int reg2 );
68 void op_imul_RR (int op_size,int reg1,int reg2);
69 void op_imul_RV (int op_size,int reg,long i32data);
70 void op_div64_reg (int reg);
71 void op_idiv64_reg (int reg);
72 void op_shl_reg (int op_size,int reg);
73 void op_sar_reg (int op_size,int reg);
74 void op_shr_reg (int op_size,int reg);
75 void op_and_reg (int op_size,int reg1,int reg2);
76 void op_and64_value (int reg,long offset);
77 void op_and32_value (int reg,long offset);
78 void op_or_reg (int op_size,int reg1,int reg2);
79 void op_xor_reg (int op_size,int reg1,int reg2);
80 void op_not_reg (int op_size,int reg);
81 void op_neg ( int reg );
82 void op_test (int reg1,int reg2);
83 void op_cmp_reg (int op_size,int reg1,int reg2);
84 void op_cmp_value (int op_size,int reg,char byte_data);
85 void op_setne (int reg);
86 void op_movlpd_MR (int xmm_reg,int base_reg,int offset,char mod, Schedule::Type scheduleType = Schedule::None );
87 void op_movlpd_RM (int xmm_reg,int base_reg,int offset,char mod, Schedule::Type scheduleType = Schedule::None );
88 void op_movsd_RR (int xmm_reg1,int xmm_reg2);
89 void op_movsd_MR (int xmm_reg,int base_reg,int offset,char mod, Schedule::Type scheduleType = Schedule::None );
90 void op_movss_RR (int xmm_reg1,int xmm_reg2);
91 void op_movss_RM (int xmm_reg,int base_reg,int offset,char mod, Schedule::Type scheduleType = Schedule::None );
92 void op_movss_MR (int xmm_reg,int base_reg,int offset,char mod, Schedule::Type scheduleType = Schedule::None );
93 void op_movd_RX (int reg,int xmm_reg);
94 void op_cvtsd2ss (int xmm_reg1,int xmm_reg2);
95 void op_cvtss2sd (int xmm_reg1,int xmm_reg2);
96 void op_cvttsd2si_xmm (int op_size,int reg,int xmm_reg);
97 void op_cvttss2si_xmm (int op_size,int reg,int xmm_reg);
98 void op_cvtsi2sd_reg (int op_size,int xmm_reg,int reg);
99 void op_cvtsi2ss_reg (int op_size,int xmm_reg,int reg);
100 void op_comisd (int xmm_reg1,int xmm_reg2);
101 void op_comiss (int xmm_reg1,int xmm_reg2);
102 void op_rep_movs (int op_size);
103 void op_add_rsp(long num);
104 void op_sub_rsp(long num);
105 void op_add_esp(long num);
106 void op_sub_esp(long num);
107 void op_fld_ptr_esp(int type);
108 void op_zero_reg(int reg);
109 void op_jle( long offset, int op_size = sizeof(char) );
110 void op_jbe( long offset, int op_size = sizeof(char) );
111 void op_jge( long offset, int op_size = sizeof(char) );
112 void op_jae( long offset, int op_size = sizeof(char) );
113 void op_jl( long offset, int op_size = sizeof(char) );
114 void op_jb( long offset, int op_size = sizeof(char) );
115 void op_jg( long offset, int op_size = sizeof(char) );
116 void op_ja( long offset, int op_size = sizeof(char) );
117 void op_jne( long offset, int op_size = sizeof(char) );
118 void op_je( long offset, int op_size = sizeof(char) );
119 void op_jmp( long offset, int op_size = sizeof(char) );
120 void op_call( const UserProc *pUserProc );
121 void op_call( const DllProc *pDllProc );
122 void op_ret();
123
124#else
125 /////////////////////////////////////////////////////////////////
126 // 32ビット
127 /////////////////////////////////////////////////////////////////
128private:
129 void set_mod_rm_sib_disp(char mod,int reg,int scale,int index_reg,int base_reg,long disp, Schedule::Type scheduleType = Schedule::None );
130 void __op_format(char op_prefix,char opcode,int reg);
131 void __op_format(char op_prefix,char opcode1,char opcode2,int reg,int base_reg,int offset,char mod, Schedule::Type scheduleType = Schedule::None );
132public:
133 void op_mov_RV (int reg,long offset, Schedule::Type scheduleType = Schedule::None );
134 void op_mov_RR (int reg1,int reg2);
135 void op_mov_RM (int op_size,int reg,int base_reg,int offset,char mod, Schedule::Type scheduleType = Schedule::None );
136 void op_mov_RM_ex (int op_size,int reg,int base_reg1,int base_reg2,long offset,BOOL bUseOffset, Schedule::Type scheduleType = Schedule::None );
137 void op_mov_MR (int op_size,int reg,int base_reg,int offset,char mod, Schedule::Type scheduleType = Schedule::None );
138 void op_mov_MR_ex (int op_size,int reg,int base_reg1,int base_reg2,long offset,BOOL bUseOffset, Schedule::Type scheduleType = Schedule::None );
139 void op_movsx_R32R16 (int reg32,int reg16 = REG_NON);
140 void op_movsx_R32R8 (int reg32,int reg8 = REG_NON);
141 void op_movsx_R16R8 (int reg16,int reg8 = REG_NON);
142 void op_lea_RM ( int reg, int base_reg, long offset, char mod, Schedule::Type scheduleType = Schedule::None );
143 void op_inc (int reg);
144 void op_dec (int reg);
145 void op_add_RV8 (int reg,char cValue);
146 void op_add_RV ( int reg, long offset, Schedule::Type scheduleType = Schedule::None );
147 void op_add_RR ( int reg1, int reg2 );
148 void op_add_RM (int op_size,int reg,int base_reg,int offset,char mod, Schedule::Type scheduleType = Schedule::None );
149 void op_adc_RV8 (int reg,char cValue);
150 void op_adc_RR ( int reg1, int reg2 );
151 void op_sub_RV8 (int reg,char cValue);
152 void op_sub_RR ( int reg1, int reg2 );
153 void op_sbb_RV8 (int reg,char cValue);
154 void op_sbb_RR ( int reg1, int reg2 );
155 void op_imul_RR (int reg1,int reg2);
156 void op_imul_RV (int reg,long i32data);
157 void op_imul_RV8 (int reg,char cValue);
158 void op_div_R ( int reg );
159 void op_idiv_R ( int reg );
160 void op_and_RV (int reg,long value);
161 void op_and_RR ( int reg1, int reg2 );
162 void op_or_RR ( int op_size, int reg1, int reg2 );
163 void op_xor_RR ( int reg1, int reg2 = REG_NON );
164 void op_neg ( int reg );
165 void op_cdq ();
166
167 void op_rep_movs (int op_size);
168
169 void op_push(int reg);
170 void op_push_V(long data);
171 void op_push_M( int base_reg );
172 void op_push_M( int base_reg, long offset, Schedule::Type scheduleType = Schedule::None );
173 void op_pop(int reg = REG_NON);
174 void op_add_esp(long num);
175 void op_sub_esp(long num);
176 void op_cmp_RR( int reg1, int reg2 );
177 void op_cmp_value(int op_size,int reg,char byte_data);
178 void op_setne( int reg );
179 void op_test(int reg1,int reg2);
180 void op_test_ah( char cValue );
181 void op_fld_ptr_esp(int type);
182 void op_fld_basereg (int type,int base_reg);
183 void op_fld_base_offset (int type,int base_reg,long offset, Schedule::Type scheduleType = Schedule::None );
184 void op_fld_base_offset_ex (int type,int base_reg1,int base_reg2,long offset,BOOL bUseOffset, Schedule::Type scheduleType = Schedule::None);
185 void op_fstp_basereg (int type,int base_reg);
186 void op_fstp_base_offset (int type,int base_reg,long offset, Schedule::Type scheduleType = Schedule::None);
187 void op_fstp_base_offset_ex (int type,int base_reg1,int base_reg2,long offset,BOOL bUseOffset, Schedule::Type scheduleType = Schedule::None);
188 void op_fistp_ptr_esp ( int typeSize );
189 void op_fstp_push ( Type &type );
190 void op_fcompp();
191 void op_fnstsw_ax();
192 void op_zero_reg(int reg);
193 void fpu_cast();
194 void fpu_cast_end();
195
196 void op_call(const UserProc *pUserProc);
197 void op_ret();
198#endif
199
200
201
202
203 void PutOld( char c1, char c2 )
204 {
205 pNativeCode->Put( c1 );
206 pNativeCode->Put( c2 );
207 }
208 void PutOld( char c1, char c2, char c3 )
209 {
210 pNativeCode->Put( c1 );
211 pNativeCode->Put( c2 );
212 pNativeCode->Put( c3 );
213 }
214 void PutOld( char c1, char c2, char c3, char c4 )
215 {
216 pNativeCode->Put( c1 );
217 pNativeCode->Put( c2 );
218 pNativeCode->Put( c3 );
219 pNativeCode->Put( c4 );
220 }
221 void PutOld( char c1, char c2, char c3, long l )
222 {
223 pNativeCode->Put( c1 );
224 pNativeCode->Put( c2 );
225 pNativeCode->Put( c3 );
226 pNativeCode->Put( l );
227 }
228 void PutOld( char c1, char c2, char c3, char c4, char c5 )
229 {
230 pNativeCode->Put( c1 );
231 pNativeCode->Put( c2 );
232 pNativeCode->Put( c3 );
233 pNativeCode->Put( c4 );
234 pNativeCode->Put( c5 );
235 }
236 void PutOld( char c1, char c2, char c3, char c4, char c5, char c6 )
237 {
238 pNativeCode->Put( c1 );
239 pNativeCode->Put( c2 );
240 pNativeCode->Put( c3 );
241 pNativeCode->Put( c4 );
242 pNativeCode->Put( c5 );
243 pNativeCode->Put( c6 );
244 }
245};
Note: See TracBrowser for help on using the repository browser.