[829] | 1 | #pragma once
|
---|
| 2 |
|
---|
| 3 | #include <LexicalScope.h>
|
---|
| 4 |
|
---|
| 5 | #ifdef _AMD64_
|
---|
| 6 | #include "../../compiler_x64/MachineFixed.h"
|
---|
| 7 | #else
|
---|
| 8 | #include "../../compiler_x86/MachineFixed.h"
|
---|
| 9 | #endif
|
---|
| 10 |
|
---|
| 11 | // コード生成時の部分的なスケジューリング
|
---|
| 12 | class PertialSchedule
|
---|
| 13 | {
|
---|
| 14 | int codePos; // バッファ位置
|
---|
| 15 | int typeSize; // 対象サイズ(一般的には8bit/32bit)
|
---|
| 16 |
|
---|
| 17 | public:
|
---|
| 18 | PertialSchedule( int codePos, int typeSize )
|
---|
| 19 | : codePos( codePos )
|
---|
| 20 | , typeSize( typeSize )
|
---|
| 21 | {
|
---|
| 22 | }
|
---|
| 23 | ~PertialSchedule()
|
---|
| 24 | {
|
---|
| 25 | }
|
---|
| 26 |
|
---|
| 27 | int GetCodePos() const
|
---|
| 28 | {
|
---|
| 29 | return codePos;
|
---|
| 30 | }
|
---|
| 31 | int GetTypeSize() const
|
---|
| 32 | {
|
---|
| 33 | return typeSize;
|
---|
| 34 | }
|
---|
| 35 |
|
---|
| 36 | private:
|
---|
| 37 | PertialSchedule(PertialSchedule const&);
|
---|
| 38 | PertialSchedule& operator =(PertialSchedule const&);
|
---|
| 39 | };
|
---|
| 40 | typedef std::vector<const PertialSchedule *> PertialSchedules;
|
---|
| 41 |
|
---|
| 42 | //Goto未知ラベル
|
---|
| 43 | class GotoLabelSchedule : public PertialSchedule
|
---|
| 44 | {
|
---|
| 45 | std::string name;
|
---|
| 46 | int line;
|
---|
| 47 | int sourceCodePos;
|
---|
| 48 | public:
|
---|
| 49 | GotoLabelSchedule( const std::string &name, int nativeCodePos, int sourceCodePos )
|
---|
| 50 | : PertialSchedule( nativeCodePos, sizeof(long) )
|
---|
| 51 | , name( name )
|
---|
| 52 | , line( -1 )
|
---|
| 53 | , sourceCodePos( sourceCodePos )
|
---|
| 54 | {
|
---|
| 55 | }
|
---|
| 56 | GotoLabelSchedule( int line, int nativeCodePos, int sourceCodePos )
|
---|
| 57 | : PertialSchedule( nativeCodePos, sizeof(long) )
|
---|
| 58 | , line( line )
|
---|
| 59 | , sourceCodePos( sourceCodePos )
|
---|
| 60 | {
|
---|
| 61 | }
|
---|
| 62 | const std::string &GetName() const
|
---|
| 63 | {
|
---|
| 64 | return name;
|
---|
| 65 | }
|
---|
| 66 | int GetLineNum() const
|
---|
| 67 | {
|
---|
| 68 | return line;
|
---|
| 69 | }
|
---|
| 70 | int GetSourceCodePos() const
|
---|
| 71 | {
|
---|
| 72 | return sourceCodePos;
|
---|
| 73 | }
|
---|
| 74 |
|
---|
| 75 | private:
|
---|
| 76 | GotoLabelSchedule(GotoLabelSchedule const&);
|
---|
| 77 | GotoLabelSchedule& operator =(GotoLabelSchedule const&);
|
---|
| 78 | };
|
---|
| 79 | typedef std::vector<const GotoLabelSchedule *> GotoLabelSchedules;
|
---|
| 80 |
|
---|
| 81 | //ラベルアドレス
|
---|
| 82 | class GotoLabel
|
---|
| 83 | {
|
---|
| 84 | public:
|
---|
| 85 | std::string name;
|
---|
| 86 | int line;
|
---|
| 87 | DWORD address;
|
---|
| 88 |
|
---|
| 89 | GotoLabel( const std::string &name, long nativeCodePos )
|
---|
| 90 | : name( name )
|
---|
| 91 | , line( -1 )
|
---|
| 92 | , address( nativeCodePos )
|
---|
| 93 | {
|
---|
| 94 | }
|
---|
| 95 | GotoLabel( int line, long nativeCodePos )
|
---|
| 96 | : name( "" )
|
---|
| 97 | , line( line )
|
---|
| 98 | , address( nativeCodePos )
|
---|
| 99 | {
|
---|
| 100 | }
|
---|
| 101 |
|
---|
| 102 | GotoLabel(GotoLabel&& y)
|
---|
| 103 | : name(std::move(y.name))
|
---|
| 104 | , line(std::move(y.line))
|
---|
| 105 | , address(std::move(y.address))
|
---|
| 106 | {
|
---|
| 107 | }
|
---|
| 108 |
|
---|
| 109 | GotoLabel(GotoLabel const& y)
|
---|
| 110 | : name(y.name)
|
---|
| 111 | , line(y.line)
|
---|
| 112 | , address(y.address)
|
---|
| 113 | {
|
---|
| 114 | }
|
---|
| 115 |
|
---|
| 116 | GotoLabel& operator =(GotoLabel&& y)
|
---|
| 117 | {
|
---|
| 118 | name = std::move(y.name);
|
---|
| 119 | line = std::move(y.line);
|
---|
| 120 | address = std::move(y.address);
|
---|
| 121 | return *this;
|
---|
| 122 | }
|
---|
| 123 |
|
---|
| 124 | GotoLabel& operator =(GotoLabel const& y)
|
---|
| 125 | {
|
---|
| 126 | return *this = std::move(GotoLabel(y));
|
---|
| 127 | }
|
---|
| 128 | };
|
---|
| 129 | typedef std::vector<GotoLabel> GotoLabels;
|
---|
| 130 |
|
---|
| 131 | class LexicalScope
|
---|
| 132 | {
|
---|
| 133 | public:
|
---|
| 134 | enum SCOPE_TYPE{
|
---|
| 135 | // ベース
|
---|
| 136 | SCOPE_TYPE_BASE,
|
---|
| 137 |
|
---|
| 138 | // 分岐
|
---|
| 139 | SCOPE_TYPE_IF,
|
---|
| 140 |
|
---|
| 141 | // ループ
|
---|
| 142 | SCOPE_TYPE_DO,
|
---|
| 143 | SCOPE_TYPE_FOR,
|
---|
| 144 | SCOPE_TYPE_WHILE,
|
---|
| 145 |
|
---|
| 146 | // ケース分け
|
---|
| 147 | SCOPE_TYPE_SELECT,
|
---|
| 148 |
|
---|
| 149 | // 例外処理
|
---|
| 150 | SCOPE_TRY,
|
---|
| 151 | SCOPE_CATCH,
|
---|
| 152 | SCOPE_FINALLY,
|
---|
| 153 | };
|
---|
| 154 |
|
---|
| 155 | private:
|
---|
| 156 | int level;
|
---|
| 157 | int StartAddress;
|
---|
| 158 | SCOPE_TYPE TypeOfStatement;
|
---|
| 159 |
|
---|
| 160 | PertialSchedules breakPertialSchedules;
|
---|
| 161 |
|
---|
| 162 | public:
|
---|
| 163 | LexicalScope( int level, int addr, SCOPE_TYPE TypeOfStatement )
|
---|
| 164 | : level( level )
|
---|
| 165 | , StartAddress( addr )
|
---|
| 166 | , TypeOfStatement( TypeOfStatement )
|
---|
| 167 | {
|
---|
| 168 | }
|
---|
| 169 | ~LexicalScope()
|
---|
| 170 | {
|
---|
| 171 | }
|
---|
| 172 |
|
---|
| 173 | int GetStartAddress()
|
---|
| 174 | {
|
---|
| 175 | return StartAddress;
|
---|
| 176 | }
|
---|
| 177 | SCOPE_TYPE GetTypeOfStatement()
|
---|
| 178 | {
|
---|
| 179 | return TypeOfStatement;
|
---|
| 180 | }
|
---|
| 181 |
|
---|
| 182 | void Break();
|
---|
| 183 | void RunScheduleOfBreak();
|
---|
| 184 |
|
---|
| 185 | private:
|
---|
| 186 | LexicalScope(LexicalScope const&);
|
---|
| 187 | LexicalScope& operator =(LexicalScope const&);
|
---|
| 188 | };
|
---|
| 189 |
|
---|
| 190 | class LexicalScopes
|
---|
| 191 | {
|
---|
| 192 | LexicalScope **ppScopes;
|
---|
| 193 | int level;
|
---|
| 194 |
|
---|
| 195 | public:
|
---|
| 196 |
|
---|
| 197 | LexicalScopes(){
|
---|
| 198 | ppScopes = (LexicalScope **)malloc( 1 );
|
---|
| 199 | level=0;
|
---|
| 200 | }
|
---|
| 201 | ~LexicalScopes(){
|
---|
| 202 | free( ppScopes );
|
---|
| 203 | }
|
---|
| 204 |
|
---|
| 205 | //初期化(関数コンパイルの開始時に呼び出される)
|
---|
| 206 | void Init(int addr);
|
---|
| 207 |
|
---|
| 208 | // スコープを開始
|
---|
| 209 | void Start( int addr, LexicalScope::SCOPE_TYPE TypeOfStatement );
|
---|
| 210 |
|
---|
| 211 | // スコープを検索
|
---|
| 212 | LexicalScope *SearchScope( LexicalScope::SCOPE_TYPE TypeOfStatement );
|
---|
| 213 |
|
---|
| 214 | int GetNowLevel(void);
|
---|
| 215 | void SetNowLevel( int level );
|
---|
| 216 | int GetStartAddress(void);
|
---|
| 217 |
|
---|
| 218 | void End();
|
---|
| 219 |
|
---|
| 220 | //スコープ終了時のデストラクタ呼び出し
|
---|
| 221 | void CallDestructorsOfScopeEnd();
|
---|
| 222 |
|
---|
| 223 | //Returnステートメント用のデストラクタ呼び出し
|
---|
| 224 | void CallDestructorsOfReturn( int BaseLevel = 0 );
|
---|
| 225 |
|
---|
| 226 | private:
|
---|
| 227 | LexicalScopes(LexicalScopes const&);
|
---|
| 228 | LexicalScopes& operator =(LexicalScopes const&);
|
---|
| 229 | };
|
---|
| 230 |
|
---|
| 231 | class CodeGenerator
|
---|
| 232 | {
|
---|
| 233 | NativeCode *pNativeCode;
|
---|
| 234 |
|
---|
| 235 | private:
|
---|
| 236 | // 部分スケジュールの管理
|
---|
| 237 | PertialSchedules pertialSchedules;
|
---|
| 238 |
|
---|
| 239 | // Continue用のコード位置情報の管理
|
---|
| 240 | std::vector<long> continueCodePositions;
|
---|
| 241 |
|
---|
| 242 | // コンパイル中のステップにおいて、構造体の一時オブジェクトの解放が必要かどうか
|
---|
| 243 | bool isNeedFreeTempStructureInCurrentStep;
|
---|
| 244 |
|
---|
| 245 | public:
|
---|
| 246 |
|
---|
| 247 | // ローカル変数用スケジュールの管理
|
---|
| 248 | PertialSchedules localVarPertialSchedules;
|
---|
| 249 |
|
---|
| 250 | // Exit Subスケジュールの管理
|
---|
| 251 | std::vector<long> exitSubCodePositions;
|
---|
| 252 |
|
---|
| 253 | // Gotoスケジュールの管理
|
---|
| 254 | GotoLabels gotoLabels;
|
---|
| 255 | GotoLabelSchedules gotoLabelSchedules;
|
---|
| 256 |
|
---|
| 257 | // レキシカルスコープの管理
|
---|
| 258 | LexicalScopes lexicalScopes;
|
---|
| 259 |
|
---|
| 260 | CodeGenerator()
|
---|
| 261 | : pNativeCode( 0 )
|
---|
| 262 | , isNeedFreeTempStructureInCurrentStep( false )
|
---|
| 263 | {
|
---|
| 264 | }
|
---|
| 265 | ~CodeGenerator()
|
---|
| 266 | {
|
---|
| 267 | if( pNativeCode )
|
---|
| 268 | {
|
---|
| 269 | CheckUnresolveSchedule();
|
---|
| 270 | }
|
---|
| 271 | }
|
---|
| 272 |
|
---|
| 273 | void Select( NativeCode &nativeCode )
|
---|
| 274 | {
|
---|
| 275 | if( pNativeCode )
|
---|
| 276 | {
|
---|
| 277 | CheckUnresolveSchedule();
|
---|
| 278 | }
|
---|
| 279 | pNativeCode = &nativeCode;
|
---|
| 280 | }
|
---|
| 281 | long GetNativeCodeSize() const
|
---|
| 282 | {
|
---|
| 283 | return pNativeCode->GetSize();
|
---|
| 284 | }
|
---|
| 285 |
|
---|
| 286 | void NextSourceLine( const SourceCodePosition &sourceCodePosition, bool isInSystemProc )
|
---|
| 287 | {
|
---|
| 288 | pNativeCode->NextSourceLine( sourceCodePosition, isInSystemProc );
|
---|
| 289 | }
|
---|
| 290 |
|
---|
| 291 | long GetContinueCodePos() const
|
---|
| 292 | {
|
---|
| 293 | if( continueCodePositions.size() == 0 )
|
---|
| 294 | {
|
---|
| 295 | return -1;
|
---|
| 296 | }
|
---|
| 297 | return continueCodePositions[continueCodePositions.size()-1];
|
---|
| 298 | }
|
---|
| 299 | void ClearContinueArea()
|
---|
| 300 | {
|
---|
| 301 | continueCodePositions.clear();
|
---|
| 302 | }
|
---|
| 303 | void ContinueAreaBegin()
|
---|
| 304 | {
|
---|
| 305 | continueCodePositions.push_back( pNativeCode->GetSize() );
|
---|
| 306 | }
|
---|
| 307 | void ContinueAreaEnd()
|
---|
| 308 | {
|
---|
| 309 | continueCodePositions.pop_back();
|
---|
| 310 | }
|
---|
| 311 |
|
---|
| 312 | void PutWithSchedule( long l, Schedule::Type scheduleType );
|
---|
| 313 |
|
---|
| 314 | void ResolveExitSubSchedule();
|
---|
| 315 |
|
---|
| 316 | void CheckUnresolveSchedule();
|
---|
| 317 |
|
---|
| 318 | void opfix( const PertialSchedule *pPertialSchedule, _int64 newValue );
|
---|
| 319 | void opfix_offset( const PertialSchedule *pPertialSchedule, long offset );
|
---|
| 320 | void opfix_JmpPertialSchedule( const PertialSchedule *pPertialSchedule );
|
---|
| 321 |
|
---|
| 322 |
|
---|
| 323 | /////////////////////////////////////////////////////////////////
|
---|
| 324 | // 32bit/64bit共通 機械語生成
|
---|
| 325 | /////////////////////////////////////////////////////////////////
|
---|
| 326 |
|
---|
| 327 | private:
|
---|
| 328 | const PertialSchedule *__jmp_op_format( char opcode, long offset, int op_size, bool isPertialSchedule = false, bool isSelfOpcodeOffset = false );
|
---|
| 329 | public:
|
---|
| 330 | const PertialSchedule *op_jle( long offset, int op_size = sizeof(char), bool isPertialSchedule = false, bool isSelfOpcodeOffset = false );
|
---|
| 331 | const PertialSchedule *op_jbe( long offset, int op_size = sizeof(char), bool isPertialSchedule = false, bool isSelfOpcodeOffset = false );
|
---|
| 332 | const PertialSchedule *op_jge( long offset, int op_size = sizeof(char), bool isPertialSchedule = false, bool isSelfOpcodeOffset = false );
|
---|
| 333 | const PertialSchedule *op_jae( long offset, int op_size = sizeof(char), bool isPertialSchedule = false, bool isSelfOpcodeOffset = false );
|
---|
| 334 | const PertialSchedule *op_jl( long offset, int op_size = sizeof(char), bool isPertialSchedule = false, bool isSelfOpcodeOffset = false );
|
---|
| 335 | const PertialSchedule *op_jb( long offset, int op_size = sizeof(char), bool isPertialSchedule = false, bool isSelfOpcodeOffset = false );
|
---|
| 336 | const PertialSchedule *op_jg( long offset, int op_size = sizeof(char), bool isPertialSchedule = false, bool isSelfOpcodeOffset = false );
|
---|
| 337 | const PertialSchedule *op_ja( long offset, int op_size = sizeof(char), bool isPertialSchedule = false, bool isSelfOpcodeOffset = false );
|
---|
| 338 | const PertialSchedule *op_jne( long offset, int op_size = sizeof(char), bool isPertialSchedule = false, bool isSelfOpcodeOffset = false );
|
---|
| 339 | const PertialSchedule *op_je( long offset, int op_size = sizeof(char), bool isPertialSchedule = false, bool isSelfOpcodeOffset = false );
|
---|
| 340 | const PertialSchedule *op_jmp( long offset, int op_size = sizeof(char), bool isPertialSchedule = false, bool isSelfOpcodeOffset = false );
|
---|
| 341 | void op_jmp_continue();
|
---|
| 342 | void op_jmp_exitsub();
|
---|
| 343 | void op_jmp_goto_schedule( const std::string &name, int lineNum, int sourceCodePos );
|
---|
| 344 | void op_AddNeedFreeTempStructure( int reg );
|
---|
| 345 | void op_FreeTempStructure();
|
---|
| 346 |
|
---|
| 347 |
|
---|
| 348 | #ifdef _AMD64_
|
---|
| 349 | /////////////////////////////////////////////////////////////////
|
---|
| 350 | // 64ビット機械語生成
|
---|
| 351 | /////////////////////////////////////////////////////////////////
|
---|
| 352 | private:
|
---|
| 353 | void set_rex(int op_size,int reg,int index_reg,int base_reg);
|
---|
| 354 | const PertialSchedule *set_mod_rm_sib_disp(char mod,int reg,int scale,int index_reg,int base_reg,long disp, Schedule::Type scheduleType = Schedule::None, bool isPertialSchedule = false );
|
---|
| 355 | const PertialSchedule *__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, bool isPertialSchedule = false );
|
---|
| 356 | public:
|
---|
| 357 | const PertialSchedule *op_mov_RV (int op_size,int reg,long i32data, Schedule::Type scheduleType = Schedule::None, bool isPertialSchedule = false );
|
---|
| 358 | const PertialSchedule *op_mov_RV64 ( int reg, _int64 i64data, bool isPertialSchedule = false );
|
---|
| 359 | const PertialSchedule *op_mov_RM (int op_size,int reg,int base_reg,long offset,char mod, Schedule::Type scheduleType = Schedule::None, bool isPertialSchedule = false );
|
---|
| 360 | const PertialSchedule *op_mov_RM_ex (int op_size,int reg,int base_reg1,int base_reg2,long offset,BOOL bUseOffset, Schedule::Type scheduleType = Schedule::None, bool isPertialSchedule = false );
|
---|
| 361 | const PertialSchedule *op_mov_MR (int op_size,int reg,int base_reg,long offset,char mod, Schedule::Type scheduleType = Schedule::None, bool isPertialSchedule = false );
|
---|
| 362 | const PertialSchedule *op_mov_MR_ex (int op_size,int reg,int base_reg1,int base_reg2,long offset,BOOL bUseOffset, Schedule::Type scheduleType = Schedule::None, bool isPertialSchedule = false );
|
---|
| 363 | const PertialSchedule *op_mov_MV (int op_size,int base_reg,int offset, Schedule::Type offsetScheduleType, bool isPertialSchedule, BOOL bUseOffset,long i32data);
|
---|
| 364 | void op_mov_RR (int reg1,int reg2);
|
---|
| 365 | void op_movsxd (int reg64,int reg32);
|
---|
| 366 | void op_movsx64_FromReg16 (int reg64,int reg16);
|
---|
| 367 | void op_movsx64_FromReg8 (int reg64,int reg8);
|
---|
| 368 | void op_movsx32_FromReg16 (int reg32,int reg16);
|
---|
| 369 | void op_movsx32_FromReg8 (int reg32,int reg8);
|
---|
| 370 | void op_movsx16_FromReg8 (int reg32,int reg8);
|
---|
| 371 | void op_cqo ();
|
---|
| 372 | void op_inc (int reg);
|
---|
| 373 | void op_dec (int reg);
|
---|
| 374 | const PertialSchedule *op_add_RM (int op_size,int reg,int base_reg,int offset,char mod, Schedule::Type scheduleType = Schedule::None, bool isPertialSchedule = false );
|
---|
| 375 | const PertialSchedule *op_add_RV (int reg,long offset, Schedule::Type scheduleType = Schedule::None, bool isPertialSchedule = false );
|
---|
| 376 | void op_add_RR (int reg1,int reg2);
|
---|
| 377 | void op_add32_reg (int reg1,int reg2);
|
---|
| 378 | void op_sub_RV (int op_size,int reg,long i32data);
|
---|
| 379 | void op_sub64_reg (int reg1,int reg2);
|
---|
| 380 | void op_sub32_reg (int reg1,int reg2);
|
---|
| 381 | void op_sbb_RR ( int op_size, int reg1, int reg2 );
|
---|
| 382 | void op_imul_RR (int op_size,int reg1,int reg2);
|
---|
| 383 | void op_imul_RV (int op_size,int reg,long i32data);
|
---|
| 384 | void op_div64_reg (int reg);
|
---|
| 385 | void op_idiv64_reg (int reg);
|
---|
| 386 | void op_shl_reg (int op_size,int reg);
|
---|
| 387 | void op_sar_reg (int op_size,int reg);
|
---|
| 388 | void op_shr_reg (int op_size,int reg);
|
---|
| 389 | void op_and_reg (int op_size,int reg1,int reg2);
|
---|
| 390 | void op_and64_value (int reg,long offset);
|
---|
| 391 | void op_and32_value (int reg,long offset);
|
---|
| 392 | void op_or_reg (int op_size,int reg1,int reg2);
|
---|
| 393 | void op_xor_reg (int op_size,int reg1,int reg2);
|
---|
| 394 | void op_not_reg (int op_size,int reg);
|
---|
| 395 | void op_neg ( int reg );
|
---|
| 396 | void op_test (int reg1,int reg2);
|
---|
| 397 | void op_cmp_reg (int op_size,int reg1,int reg2);
|
---|
| 398 | void op_cmp_value (int op_size,int reg,char byte_data);
|
---|
| 399 | void op_setne (int reg);
|
---|
| 400 | const PertialSchedule *op_movlpd_MR (int xmm_reg,int base_reg,int offset,char mod, Schedule::Type scheduleType = Schedule::None, bool isPertialSchedule = false );
|
---|
| 401 | const PertialSchedule *op_movlpd_RM (int xmm_reg,int base_reg,int offset,char mod, Schedule::Type scheduleType = Schedule::None, bool isPertialSchedule = false );
|
---|
| 402 | void op_movsd_RR (int xmm_reg1,int xmm_reg2);
|
---|
| 403 | const PertialSchedule *op_movsd_MR (int xmm_reg,int base_reg,int offset,char mod, Schedule::Type scheduleType = Schedule::None, bool isPertialSchedule = false );
|
---|
| 404 | void op_movss_RR (int xmm_reg1,int xmm_reg2);
|
---|
| 405 | const PertialSchedule *op_movss_RM (int xmm_reg,int base_reg,int offset,char mod, Schedule::Type scheduleType = Schedule::None, bool isPertialSchedule = false );
|
---|
| 406 | const PertialSchedule *op_movss_MR (int xmm_reg,int base_reg,int offset,char mod, Schedule::Type scheduleType = Schedule::None, bool isPertialSchedule = false );
|
---|
| 407 | void op_movd_RX (int reg,int xmm_reg);
|
---|
| 408 | void op_cvtsd2ss (int xmm_reg1,int xmm_reg2);
|
---|
| 409 | void op_cvtss2sd (int xmm_reg1,int xmm_reg2);
|
---|
| 410 | void op_cvttsd2si_xmm (int op_size,int reg,int xmm_reg);
|
---|
| 411 | void op_cvttss2si_xmm (int op_size,int reg,int xmm_reg);
|
---|
| 412 | void op_cvtsi2sd_reg (int op_size,int xmm_reg,int reg);
|
---|
| 413 | void op_cvtsi2ss_reg (int op_size,int xmm_reg,int reg);
|
---|
| 414 | void op_comisd (int xmm_reg1,int xmm_reg2);
|
---|
| 415 | void op_comiss (int xmm_reg1,int xmm_reg2);
|
---|
| 416 | void op_rep_movs (int op_size);
|
---|
| 417 | void op_add_rsp(long num);
|
---|
| 418 | const PertialSchedule *op_sub_rsp( long num, bool isPertialSchedule = false );
|
---|
| 419 | void op_fld_ptr_esp(int type);
|
---|
| 420 | void op_zero_reg(int reg);
|
---|
| 421 |
|
---|
| 422 | void op_call( const UserProc *pUserProc );
|
---|
| 423 | void op_call( const DllProc *pDllProc );
|
---|
| 424 | void op_ret();
|
---|
| 425 | void op_addressof( int reg, const UserProc *pUserProc );
|
---|
| 426 | void op_mov_RV_com_vtbl( int reg, const CClass *pClass );
|
---|
| 427 | void op_mov_RV_vtbl( int reg, const CClass *pClass );
|
---|
| 428 |
|
---|
| 429 | #else
|
---|
| 430 | /////////////////////////////////////////////////////////////////
|
---|
| 431 | // 32ビット機械語生成
|
---|
| 432 | /////////////////////////////////////////////////////////////////
|
---|
| 433 | private:
|
---|
| 434 | const PertialSchedule *set_mod_rm_sib_disp(char mod,int reg,int scale,int index_reg,int base_reg,long disp, Schedule::Type scheduleType, bool isPertialSchedule );
|
---|
| 435 | void __op_format(char op_prefix,char opcode,int reg);
|
---|
| 436 | const PertialSchedule *__op_format(char op_prefix,char opcode1,char opcode2,int reg,int base_reg,int offset,char mod, Schedule::Type scheduleType = Schedule::None, bool isPertialSchedule = false );
|
---|
| 437 | public:
|
---|
| 438 | const PertialSchedule *op_mov_MV ( int op_size, int base_reg, long offset, Schedule::Type offsetScheduleType, bool isPertialSchedule, long value, Schedule::Type valueScheduleType = Schedule::None );
|
---|
| 439 | const PertialSchedule *op_mov_RV ( int reg, long offset, Schedule::Type scheduleType = Schedule::None, bool isPertialSchedule = false );
|
---|
| 440 | void op_mov_RR ( int reg1,int reg2);
|
---|
| 441 | const PertialSchedule *op_mov_RM ( int op_size,int reg,int base_reg,int offset,char mod, Schedule::Type scheduleType = Schedule::None, bool isPertialSchedule = false );
|
---|
| 442 | const PertialSchedule *op_mov_RM_ex ( int op_size,int reg,int base_reg1,int base_reg2,long offset,BOOL bUseOffset, Schedule::Type scheduleType = Schedule::None, bool isPertialSchedule = false );
|
---|
| 443 | const PertialSchedule *op_mov_MR ( int op_size,int reg,int base_reg,int offset,char mod, Schedule::Type scheduleType = Schedule::None, bool isPertialSchedule = false );
|
---|
| 444 | const PertialSchedule *op_mov_MR_ex ( int op_size,int reg,int base_reg1,int base_reg2,long offset,BOOL bUseOffset, Schedule::Type scheduleType = Schedule::None, bool isPertialSchedule = false );
|
---|
| 445 | void op_movsx_R32R16 ( int reg32,int reg16 = REG_NON);
|
---|
| 446 | void op_movsx_R32R8 ( int reg32,int reg8 = REG_NON);
|
---|
| 447 | void op_movsx_R16R8 ( int reg16,int reg8 = REG_NON);
|
---|
| 448 | const PertialSchedule *op_lea_RM ( int reg, int base_reg, long offset, char mod, Schedule::Type scheduleType = Schedule::None, bool isPertialSchedule = false );
|
---|
| 449 | void op_inc (int reg);
|
---|
| 450 | void op_dec (int reg);
|
---|
| 451 | void op_add_RV8 (int reg,char cValue);
|
---|
| 452 | const PertialSchedule *op_add_RV ( int reg, long offset, Schedule::Type scheduleType = Schedule::None, bool isPertialSchedule = false );
|
---|
| 453 | void op_add_RR ( int reg1, int reg2 );
|
---|
| 454 | const PertialSchedule *op_add_RM (int op_size,int reg,int base_reg,int offset,char mod, Schedule::Type scheduleType = Schedule::None, bool isPertialSchedule = false );
|
---|
| 455 | void op_adc_RV8 (int reg,char cValue);
|
---|
| 456 | void op_adc_RR ( int reg1, int reg2 );
|
---|
| 457 | void op_sub_RV8 (int reg,char cValue);
|
---|
| 458 | void op_sub_RR ( int reg1, int reg2 );
|
---|
| 459 | void op_sbb_RV8 (int reg,char cValue);
|
---|
| 460 | void op_sbb_RR ( int reg1, int reg2 );
|
---|
| 461 | void op_imul_RR (int reg1,int reg2);
|
---|
| 462 | void op_imul_RV (int reg,long i32data);
|
---|
| 463 | void op_imul_RV8 (int reg,char cValue);
|
---|
| 464 | void op_div_R ( int reg );
|
---|
| 465 | void op_idiv_R ( int reg );
|
---|
| 466 | void op_and_RV (int reg,long value);
|
---|
| 467 | void op_and_RR ( int reg1, int reg2 );
|
---|
| 468 | void op_or_RR ( int op_size, int reg1, int reg2 );
|
---|
| 469 | void op_xor_RR ( int reg1, int reg2 = REG_NON );
|
---|
| 470 | void op_neg ( int reg );
|
---|
| 471 | void op_cdq ();
|
---|
| 472 |
|
---|
| 473 | void op_rep_movs (int op_size);
|
---|
| 474 |
|
---|
| 475 | void op_push(int reg);
|
---|
| 476 | void op_push_V( long data, Schedule::Type scheduleType = Schedule::None );
|
---|
| 477 | void op_push_M( int base_reg );
|
---|
| 478 | const PertialSchedule *op_push_M( int base_reg, long offset, Schedule::Type scheduleType = Schedule::None, bool isPertialSchedule = false );
|
---|
| 479 | void op_pop(int reg = REG_NON);
|
---|
| 480 | void op_add_esp(long num);
|
---|
| 481 | const PertialSchedule *op_sub_esp( long num, bool isPertialSchedule = false );
|
---|
| 482 | void op_cmp_RR( int reg1, int reg2 );
|
---|
| 483 | void op_cmp_value(int op_size,int reg,char byte_data);
|
---|
| 484 | void op_setne( int reg );
|
---|
| 485 | void op_test(int reg1,int reg2);
|
---|
| 486 | void op_test_ah( char cValue );
|
---|
| 487 | void op_fld_ptr_esp(int type);
|
---|
| 488 | void op_fld_basereg (int type,int base_reg);
|
---|
| 489 | const PertialSchedule *op_fld_base_offset (int type,int base_reg,long offset, Schedule::Type scheduleType = Schedule::None, bool isPertialSchedule = false );
|
---|
| 490 | const PertialSchedule *op_fld_base_offset_ex (int type,int base_reg1,int base_reg2,long offset,BOOL bUseOffset, Schedule::Type scheduleType = Schedule::None, bool isPertialSchedule = false );
|
---|
| 491 | void op_fstp_basereg (int type,int base_reg);
|
---|
| 492 | const PertialSchedule *op_fstp_base_offset (int type,int base_reg,long offset, Schedule::Type scheduleType = Schedule::None, bool isPertialSchedule = false );
|
---|
| 493 | const PertialSchedule *op_fstp_base_offset_ex (int type,int base_reg1,int base_reg2,long offset,BOOL bUseOffset, Schedule::Type scheduleType = Schedule::None, bool isPertialSchedule = false );
|
---|
| 494 | void op_fistp_ptr_esp ( int typeSize );
|
---|
| 495 | void op_fstp_push ( Type &type );
|
---|
| 496 | void op_fcompp();
|
---|
| 497 | void op_fnstsw_ax();
|
---|
| 498 | void op_zero_reg(int reg);
|
---|
| 499 | void fpu_cast();
|
---|
| 500 | void fpu_cast_end();
|
---|
| 501 |
|
---|
| 502 | void op_call_R( int reg );
|
---|
| 503 | void op_call(const UserProc *pUserProc);
|
---|
| 504 | void op_call(const DllProc *pDllProc);
|
---|
| 505 | void op_ret();
|
---|
| 506 | void op_ret( short stackFrameSize );
|
---|
| 507 | void op_addressof( int reg, const UserProc *pUserProc );
|
---|
| 508 | void op_mov_RV_com_vtbl( int reg, const CClass *pClass );
|
---|
| 509 | void op_mov_RV_vtbl( int reg, const CClass *pClass );
|
---|
| 510 | #endif
|
---|
| 511 |
|
---|
| 512 |
|
---|
| 513 |
|
---|
| 514 | void PutOld( long l, Schedule::Type scheduleType )
|
---|
| 515 | {
|
---|
| 516 | this->PutWithSchedule( l, scheduleType );
|
---|
| 517 | }
|
---|
| 518 | const PertialSchedule *PutOld( long l, bool isPertialSchedule )
|
---|
| 519 | {
|
---|
| 520 | const PertialSchedule *pPertialSchedule;
|
---|
| 521 | if( isPertialSchedule )
|
---|
| 522 | {
|
---|
| 523 | pertialSchedules.push_back( new PertialSchedule( pNativeCode->GetSize(), sizeof(long) ) );
|
---|
| 524 | pPertialSchedule = pertialSchedules.back();
|
---|
| 525 | }
|
---|
| 526 | pNativeCode->Put( l );
|
---|
| 527 | return pPertialSchedule;
|
---|
| 528 | }
|
---|
| 529 | void PutOld( const NativeCode &nativeCode )
|
---|
| 530 | {
|
---|
| 531 | pNativeCode->PutEx( nativeCode );
|
---|
| 532 | }
|
---|
| 533 | void PutOld( char c )
|
---|
| 534 | {
|
---|
| 535 | pNativeCode->Put( c );
|
---|
| 536 | }
|
---|
| 537 | void PutOld( char c1, char c2 )
|
---|
| 538 | {
|
---|
| 539 | pNativeCode->Put( c1 );
|
---|
| 540 | pNativeCode->Put( c2 );
|
---|
| 541 | }
|
---|
| 542 | void PutOld( char c1, char c2, char c3 )
|
---|
| 543 | {
|
---|
| 544 | pNativeCode->Put( c1 );
|
---|
| 545 | pNativeCode->Put( c2 );
|
---|
| 546 | pNativeCode->Put( c3 );
|
---|
| 547 | }
|
---|
| 548 | void PutOld( char c1, char c2, char c3, char c4 )
|
---|
| 549 | {
|
---|
| 550 | pNativeCode->Put( c1 );
|
---|
| 551 | pNativeCode->Put( c2 );
|
---|
| 552 | pNativeCode->Put( c3 );
|
---|
| 553 | pNativeCode->Put( c4 );
|
---|
| 554 | }
|
---|
| 555 | void PutOld( char c1, char c2, char c3, long l )
|
---|
| 556 | {
|
---|
| 557 | pNativeCode->Put( c1 );
|
---|
| 558 | pNativeCode->Put( c2 );
|
---|
| 559 | pNativeCode->Put( c3 );
|
---|
| 560 | pNativeCode->Put( l );
|
---|
| 561 | }
|
---|
| 562 | void PutOld( char c1, char c2, char c3, char c4, char c5 )
|
---|
| 563 | {
|
---|
| 564 | pNativeCode->Put( c1 );
|
---|
| 565 | pNativeCode->Put( c2 );
|
---|
| 566 | pNativeCode->Put( c3 );
|
---|
| 567 | pNativeCode->Put( c4 );
|
---|
| 568 | pNativeCode->Put( c5 );
|
---|
| 569 | }
|
---|
| 570 | void PutOld( char c1, char c2, char c3, char c4, char c5, char c6 )
|
---|
| 571 | {
|
---|
| 572 | pNativeCode->Put( c1 );
|
---|
| 573 | pNativeCode->Put( c2 );
|
---|
| 574 | pNativeCode->Put( c3 );
|
---|
| 575 | pNativeCode->Put( c4 );
|
---|
| 576 | pNativeCode->Put( c5 );
|
---|
| 577 | pNativeCode->Put( c6 );
|
---|
| 578 | }
|
---|
| 579 |
|
---|
| 580 | private:
|
---|
| 581 | CodeGenerator(CodeGenerator const&);
|
---|
| 582 | CodeGenerator& operator =(CodeGenerator const&);
|
---|
| 583 | };
|
---|