[239] | 1 | #include "stdafx.h"
|
---|
| 2 |
|
---|
| 3 | #include <CodeGenerator.h>
|
---|
| 4 |
|
---|
| 5 |
|
---|
| 6 | void CodeGenerator::CheckUnresolveSchedule()
|
---|
| 7 | {
|
---|
| 8 | if( pertialSchedules.size() > 0 )
|
---|
| 9 | {
|
---|
| 10 | SetError();
|
---|
| 11 | }
|
---|
| 12 | }
|
---|
| 13 |
|
---|
| 14 |
|
---|
| 15 | // 分岐関連
|
---|
| 16 | void CodeGenerator::opfix_JmpPertialSchedule( const PertialSchedule *pPertialSchedule )
|
---|
| 17 | {
|
---|
| 18 | bool isSuccessful = false;
|
---|
| 19 |
|
---|
| 20 | CodeGenerator::PertialSchedules::iterator it = pertialSchedules.begin();
|
---|
| 21 | while( it != pertialSchedules.end() )
|
---|
| 22 | {
|
---|
| 23 | if( (*it) == pPertialSchedule )
|
---|
| 24 | {
|
---|
| 25 | if( pPertialSchedule->GetTypeSize() == sizeof(char) )
|
---|
| 26 | {
|
---|
| 27 | pNativeCode->Overwrite( pPertialSchedule->GetCodePos(), (char)( pNativeCode->GetSize() - (pPertialSchedule->GetCodePos()+1) ) );
|
---|
| 28 |
|
---|
| 29 | // TODO: 未完成(用が無くなったら消す)
|
---|
| 30 | extern int obp;
|
---|
| 31 | pNativeCode->OverwriteOld( pPertialSchedule->GetObpOld(), (char)( obp - (pPertialSchedule->GetObpOld()+1) ) );
|
---|
| 32 | }
|
---|
| 33 | else
|
---|
| 34 | {
|
---|
| 35 | SetError();
|
---|
| 36 | }
|
---|
| 37 |
|
---|
| 38 | pertialSchedules.erase( it );
|
---|
| 39 | delete pPertialSchedule;
|
---|
| 40 |
|
---|
| 41 | isSuccessful = true;
|
---|
| 42 | }
|
---|
| 43 | else
|
---|
| 44 | {
|
---|
| 45 | it++;
|
---|
| 46 | }
|
---|
| 47 | }
|
---|
| 48 |
|
---|
| 49 | if( isSuccessful == false )
|
---|
| 50 | {
|
---|
| 51 | SetError();
|
---|
| 52 | }
|
---|
| 53 | }
|
---|
| 54 | CodeGenerator::PertialSchedule *CodeGenerator::__jmp_op_format( char opcode, long offset, int op_size, bool isPertialSchedule )
|
---|
| 55 | {
|
---|
| 56 | pNativeCode->Put( opcode );
|
---|
| 57 |
|
---|
| 58 | PertialSchedule *pPertialSchedule = NULL;
|
---|
| 59 | if( isPertialSchedule )
|
---|
| 60 | {
|
---|
| 61 | pertialSchedules.push_back( new PertialSchedule( pNativeCode->GetSize(), op_size ) );
|
---|
| 62 | pPertialSchedule = pertialSchedules[pertialSchedules.size()-1];
|
---|
| 63 | }
|
---|
| 64 |
|
---|
| 65 | if( op_size == sizeof(char) )
|
---|
| 66 | {
|
---|
| 67 | pNativeCode->Put( (char)offset );
|
---|
| 68 | }
|
---|
| 69 | else if( op_size == sizeof(long) )
|
---|
| 70 | {
|
---|
| 71 | SetError();
|
---|
| 72 | pNativeCode->Put( offset );
|
---|
| 73 | }
|
---|
| 74 | else
|
---|
| 75 | {
|
---|
| 76 | SetError();
|
---|
| 77 | }
|
---|
| 78 |
|
---|
| 79 | return pPertialSchedule;
|
---|
| 80 | }
|
---|
| 81 | CodeGenerator::PertialSchedule *CodeGenerator::op_jle( long offset, int op_size, bool isPertialSchedule )
|
---|
| 82 | {
|
---|
| 83 | return __jmp_op_format( (char)0x7E, offset, op_size, isPertialSchedule );
|
---|
| 84 | }
|
---|
| 85 | CodeGenerator::PertialSchedule *CodeGenerator::op_jbe( long offset, int op_size, bool isPertialSchedule )
|
---|
| 86 | {
|
---|
| 87 | return __jmp_op_format( (char)0x76, offset, op_size, isPertialSchedule );
|
---|
| 88 | }
|
---|
| 89 | CodeGenerator::PertialSchedule *CodeGenerator::op_jge( long offset, int op_size, bool isPertialSchedule )
|
---|
| 90 | {
|
---|
| 91 | return __jmp_op_format( (char)0x7D, offset, op_size, isPertialSchedule );
|
---|
| 92 | }
|
---|
| 93 | CodeGenerator::PertialSchedule *CodeGenerator::op_jae( long offset, int op_size, bool isPertialSchedule )
|
---|
| 94 | {
|
---|
| 95 | return __jmp_op_format( (char)0x73, offset, op_size, isPertialSchedule );
|
---|
| 96 | }
|
---|
| 97 | CodeGenerator::PertialSchedule *CodeGenerator::op_jl( long offset, int op_size, bool isPertialSchedule )
|
---|
| 98 | {
|
---|
| 99 | return __jmp_op_format( (char)0x7C, offset, op_size, isPertialSchedule );
|
---|
| 100 | }
|
---|
| 101 | CodeGenerator::PertialSchedule *CodeGenerator::op_jb( long offset, int op_size, bool isPertialSchedule )
|
---|
| 102 | {
|
---|
| 103 | return __jmp_op_format( (char)0x72, offset, op_size, isPertialSchedule );
|
---|
| 104 | }
|
---|
| 105 | CodeGenerator::PertialSchedule *CodeGenerator::op_jg( long offset, int op_size, bool isPertialSchedule )
|
---|
| 106 | {
|
---|
| 107 | return __jmp_op_format( (char)0x7F, offset, op_size, isPertialSchedule );
|
---|
| 108 | }
|
---|
| 109 | CodeGenerator::PertialSchedule *CodeGenerator::op_ja( long offset, int op_size, bool isPertialSchedule )
|
---|
| 110 | {
|
---|
| 111 | return __jmp_op_format( (char)0x77, offset, op_size, isPertialSchedule );
|
---|
| 112 | }
|
---|
| 113 | CodeGenerator::PertialSchedule *CodeGenerator::op_jne( long offset, int op_size, bool isPertialSchedule )
|
---|
| 114 | {
|
---|
| 115 | return __jmp_op_format( (char)0x75, offset, op_size, isPertialSchedule );
|
---|
| 116 | }
|
---|
| 117 | CodeGenerator::PertialSchedule *CodeGenerator::op_je( long offset, int op_size, bool isPertialSchedule )
|
---|
| 118 | {
|
---|
| 119 | return __jmp_op_format( (char)0x74, offset, op_size, isPertialSchedule );
|
---|
| 120 | }
|
---|
| 121 | CodeGenerator::PertialSchedule *CodeGenerator::op_jmp( long offset, int op_size, bool isPertialSchedule )
|
---|
| 122 | {
|
---|
| 123 | return __jmp_op_format( (char)0xEB, offset, op_size, isPertialSchedule );
|
---|
| 124 | }
|
---|