Changeset 241 in dev for trunk/abdev/BasicCompiler_Common
- Timestamp:
- Jul 27, 2007, 12:06:11 AM (17 years ago)
- Location:
- trunk/abdev/BasicCompiler_Common
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/abdev/BasicCompiler_Common/Compile.cpp
r232 r241 23 23 LABEL *pLabelNames; 24 24 int MaxLabelNum; 25 26 //Continueアドレス27 DWORD dwContinueAddress;28 25 29 26 //Caseスケジュール -
trunk/abdev/BasicCompiler_Common/include/CodeGenerator.h
r240 r241 52 52 53 53 private: 54 55 // 部分スケジュールの管理 54 56 typedef std::vector<PertialSchedule *> PertialSchedules; 55 57 PertialSchedules pertialSchedules; 56 58 59 // Continue用のコード位置情報の管理 60 std::vector<long> continueCodePositions; 61 std::vector<long> _continueCodePositions_ObpOld; 62 57 63 public: 58 64 … … 78 84 } 79 85 86 long GetContinueCodePos() const 87 { 88 if( continueCodePositions.size() == 0 ) 89 { 90 return -1; 91 } 92 return continueCodePositions[continueCodePositions.size()-1]; 93 } 94 void ClearContinueArea() 95 { 96 continueCodePositions.clear(); 97 _continueCodePositions_ObpOld.clear(); 98 } 99 void ContinueAreaBegin() 100 { 101 continueCodePositions.push_back( pNativeCode->GetSize() ); 102 103 extern int obp; 104 _continueCodePositions_ObpOld.push_back( obp ); 105 } 106 void ContinueAreaEnd() 107 { 108 continueCodePositions.pop_back(); 109 _continueCodePositions_ObpOld.pop_back(); 110 } 111 long GetContinueCodePosOld() const 112 { 113 if( _continueCodePositions_ObpOld.size() == 0 ) 114 { 115 return -1; 116 } 117 return _continueCodePositions_ObpOld[_continueCodePositions_ObpOld.size()-1]; 118 } 119 80 120 void CheckUnresolveSchedule(); 81 121 … … 88 128 89 129 private: 90 PertialSchedule *__jmp_op_format( char opcode, long offset, int op_size, bool isPertialSchedule = false );130 PertialSchedule *__jmp_op_format( char opcode, long offset, int op_size, bool isPertialSchedule = false, bool isSelfOpcodeOffset = false ); 91 131 public: 92 132 PertialSchedule *op_jle( long offset, int op_size = sizeof(char), bool isPertialSchedule = false ); … … 100 140 PertialSchedule *op_jne( long offset, int op_size = sizeof(char), bool isPertialSchedule = false ); 101 141 PertialSchedule *op_je( long offset, int op_size = sizeof(char), bool isPertialSchedule = false ); 102 PertialSchedule *op_jmp( long offset, int op_size = sizeof(char), bool isPertialSchedule = false ); 142 PertialSchedule *op_jmp( long offset, int op_size = sizeof(char), bool isPertialSchedule = false, bool isSelfOpcodeOffset = false ); 143 void op_jmp_continue(); 103 144 104 145 -
trunk/abdev/BasicCompiler_Common/include/NativeCode.h
r237 r241 141 141 // 未完成 142 142 extern char *OpBuffer; 143 extern int obp;144 143 OpBuffer[_obpOld] = c; 144 } 145 void Overwrite( int codePos, long newLongValue ) 146 { 147 *(long *)(this->codeBuffer+codePos) = newLongValue; 148 } 149 void OverwriteOld( int _obpOld, long newLongValue ) 150 { 151 // 未完成 152 extern char *OpBuffer; 153 *(long *)(OpBuffer+_obpOld) = newLongValue; 145 154 } 146 155 -
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.