Changeset 241 in dev for trunk/abdev/BasicCompiler_Common/src/CommonCodeGenerator.cpp
- Timestamp:
- Jul 27, 2007, 12:06:11 AM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/abdev/BasicCompiler_Common/src/CommonCodeGenerator.cpp
r239 r241 23 23 if( (*it) == pPertialSchedule ) 24 24 { 25 long newValue = pNativeCode->GetSize() - (pPertialSchedule->GetCodePos()+pPertialSchedule->GetTypeSize()); 26 27 extern int obp; 28 long newValueOld = obp - (pPertialSchedule->GetObpOld()+pPertialSchedule->GetTypeSize()); 29 25 30 if( pPertialSchedule->GetTypeSize() == sizeof(char) ) 26 31 { 27 pNativeCode->Overwrite( pPertialSchedule->GetCodePos(), (char)( pNativeCode->GetSize() - (pPertialSchedule->GetCodePos()+1) ) ); 32 if( newValue < -128 || 127 < newValue ) 33 { 34 // 範囲外 35 SetError(); 36 } 37 38 pNativeCode->Overwrite( pPertialSchedule->GetCodePos(), (char)newValue ); 28 39 29 40 // TODO: 未完成(用が無くなったら消す) 30 extern int obp; 31 pNativeCode->OverwriteOld( pPertialSchedule->GetObpOld(), (char)( obp - (pPertialSchedule->GetObpOld()+1) ) ); 41 pNativeCode->OverwriteOld( pPertialSchedule->GetObpOld(), (char)newValueOld ); 42 } 43 else if( pPertialSchedule->GetTypeSize() == sizeof(long) ) 44 { 45 pNativeCode->Overwrite( pPertialSchedule->GetCodePos(), newValue ); 46 47 // TODO: 未完成(用が無くなったら消す) 48 pNativeCode->OverwriteOld( pPertialSchedule->GetObpOld(), newValueOld ); 32 49 } 33 50 else … … 52 69 } 53 70 } 54 CodeGenerator::PertialSchedule *CodeGenerator::__jmp_op_format( char opcode, long offset, int op_size, bool isPertialSchedule ) 55 { 56 pNativeCode->Put( opcode ); 71 CodeGenerator::PertialSchedule *CodeGenerator::__jmp_op_format( char opcode, long offset, int op_size, bool isPertialSchedule, bool isSelfOpcodeOffset ) 72 { 73 long beginCodePos = pNativeCode->GetSize(); 74 { 75 // TODO: 未完成 76 extern int obp; 77 beginCodePos = obp; 78 } 79 80 if( opcode == (char)0xEB ) 81 { 82 // jmp命令のとき 83 if( op_size == sizeof(char) ) 84 { 85 pNativeCode->Put( (char)opcode ); 86 } 87 else if( op_size == sizeof(long) ) 88 { 89 pNativeCode->Put( (char)0xE9 ); 90 } 91 else 92 { 93 SetError(); 94 } 95 } 96 else 97 { 98 if( op_size == sizeof(char) ) 99 { 100 pNativeCode->Put( (char)((char)0x70 | opcode) ); 101 } 102 else if( op_size == sizeof(long) ) 103 { 104 pNativeCode->Put( (char)0x0F ); 105 pNativeCode->Put( (char)((char)0x80 | opcode) ); 106 } 107 else 108 { 109 SetError(); 110 } 111 } 57 112 58 113 PertialSchedule *pPertialSchedule = NULL; … … 63 118 } 64 119 120 if( isSelfOpcodeOffset ) 121 { 122 // 自分自身の命令サイズを考慮する場合 123 //offset += ( pNativeCode->GetSize() - beginCodePos ) + op_size; 124 125 // TODO: 未完成 126 extern int obp; 127 offset -= ( obp - beginCodePos ) + op_size; 128 } 129 65 130 if( op_size == sizeof(char) ) 66 131 { … … 69 134 else if( op_size == sizeof(long) ) 70 135 { 136 pNativeCode->Put( offset ); 137 } 138 else 139 { 71 140 SetError(); 72 pNativeCode->Put( offset );73 }74 else75 {76 SetError();77 141 } 78 142 … … 81 145 CodeGenerator::PertialSchedule *CodeGenerator::op_jle( long offset, int op_size, bool isPertialSchedule ) 82 146 { 83 return __jmp_op_format( (char)0x 7E, offset, op_size, isPertialSchedule );147 return __jmp_op_format( (char)0x0E, offset, op_size, isPertialSchedule ); 84 148 } 85 149 CodeGenerator::PertialSchedule *CodeGenerator::op_jbe( long offset, int op_size, bool isPertialSchedule ) 86 150 { 87 return __jmp_op_format( (char)0x 76, offset, op_size, isPertialSchedule );151 return __jmp_op_format( (char)0x06, offset, op_size, isPertialSchedule ); 88 152 } 89 153 CodeGenerator::PertialSchedule *CodeGenerator::op_jge( long offset, int op_size, bool isPertialSchedule ) 90 154 { 91 return __jmp_op_format( (char)0x 7D, offset, op_size, isPertialSchedule );155 return __jmp_op_format( (char)0x0D, offset, op_size, isPertialSchedule ); 92 156 } 93 157 CodeGenerator::PertialSchedule *CodeGenerator::op_jae( long offset, int op_size, bool isPertialSchedule ) 94 158 { 95 return __jmp_op_format( (char)0x 73, offset, op_size, isPertialSchedule );159 return __jmp_op_format( (char)0x03, offset, op_size, isPertialSchedule ); 96 160 } 97 161 CodeGenerator::PertialSchedule *CodeGenerator::op_jl( long offset, int op_size, bool isPertialSchedule ) 98 162 { 99 return __jmp_op_format( (char)0x 7C, offset, op_size, isPertialSchedule );163 return __jmp_op_format( (char)0x0C, offset, op_size, isPertialSchedule ); 100 164 } 101 165 CodeGenerator::PertialSchedule *CodeGenerator::op_jb( long offset, int op_size, bool isPertialSchedule ) 102 166 { 103 return __jmp_op_format( (char)0x 72, offset, op_size, isPertialSchedule );167 return __jmp_op_format( (char)0x02, offset, op_size, isPertialSchedule ); 104 168 } 105 169 CodeGenerator::PertialSchedule *CodeGenerator::op_jg( long offset, int op_size, bool isPertialSchedule ) 106 170 { 107 return __jmp_op_format( (char)0x 7F, offset, op_size, isPertialSchedule );171 return __jmp_op_format( (char)0x0F, offset, op_size, isPertialSchedule ); 108 172 } 109 173 CodeGenerator::PertialSchedule *CodeGenerator::op_ja( long offset, int op_size, bool isPertialSchedule ) 110 174 { 111 return __jmp_op_format( (char)0x 77, offset, op_size, isPertialSchedule );175 return __jmp_op_format( (char)0x07, offset, op_size, isPertialSchedule ); 112 176 } 113 177 CodeGenerator::PertialSchedule *CodeGenerator::op_jne( long offset, int op_size, bool isPertialSchedule ) 114 178 { 115 return __jmp_op_format( (char)0x 75, offset, op_size, isPertialSchedule );179 return __jmp_op_format( (char)0x05, offset, op_size, isPertialSchedule ); 116 180 } 117 181 CodeGenerator::PertialSchedule *CodeGenerator::op_je( long offset, int op_size, bool isPertialSchedule ) 118 182 { 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 } 183 return __jmp_op_format( (char)0x04, offset, op_size, isPertialSchedule ); 184 } 185 CodeGenerator::PertialSchedule *CodeGenerator::op_jmp( long offset, int op_size, bool isPertialSchedule, bool isSelfOpcodeOffset ) 186 { 187 return __jmp_op_format( (char)0xEB, offset, op_size, isPertialSchedule, isSelfOpcodeOffset ); 188 } 189 void CodeGenerator::op_jmp_continue() 190 { 191 //op_jmp( GetContinueCodePos()-(pNativeCode->GetSize()+sizeof(long)), sizeof(long) ); 192 193 // TODO: 未完成(OpBuffer/obp廃止が整ったら上記のコードを有効にすべし) 194 195 if( GetContinueCodePosOld() == -1 ) 196 { 197 SetError(12,"Continue",cp); 198 return; 199 } 200 201 extern int obp; 202 op_jmp( GetContinueCodePosOld()-obp, sizeof(long), false, true ); 203 }
Note:
See TracChangeset
for help on using the changeset viewer.