Changeset 253 in dev for trunk/abdev/BasicCompiler_Common
- Timestamp:
- Jul 30, 2007, 4:12:54 PM (17 years ago)
- Location:
- trunk/abdev/BasicCompiler_Common
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/abdev/BasicCompiler_Common/Compile.cpp
r250 r253 88 88 extern LINEINFO *pLineInfo; 89 89 if(MaxLineInfoNum){ 90 extern int obp; 90 91 if(pLineInfo[MaxLineInfoNum-1].TopObp==obp){ 91 92 pLineInfo[MaxLineInfoNum-1].TopCp=cp; … … 95 96 pLineInfo=(LINEINFO *)HeapReAlloc(hHeap,0,pLineInfo,(MaxLineInfoNum+1)*sizeof(LINEINFO)); 96 97 pLineInfo[MaxLineInfoNum].TopCp=cp; 98 extern int obp; 97 99 pLineInfo[MaxLineInfoNum].TopObp=obp; 98 100 … … 123 125 pLabelNames[MaxLabelNum].pName=(char *)HeapAlloc(hHeap,0,lstrlen(Command+1)+1); 124 126 lstrcpy(pLabelNames[MaxLabelNum].pName,Command+1); 127 extern int obp; 125 128 pLabelNames[MaxLabelNum].address=obp; 126 129 MaxLabelNum++; 127 130 128 131 //書き込みスケジュール 129 std::vector<GotoLabelSchedule>::iterator it = compiler.codeGenerator.gotoLabelSchedules.begin();132 GotoLabelSchedules::iterator it = compiler.codeGenerator.gotoLabelSchedules.begin(); 130 133 while( it != compiler.codeGenerator.gotoLabelSchedules.end() ) 131 134 { 132 if( it->GetName() == Command+1 )135 if( (*it)->GetName() == Command+1 ) 133 136 { 134 *((long *)( OpBuffer + it->GetNativeCodePos() ))=obp-(it->GetNativeCodePos()+sizeof(long));137 compiler.codeGenerator.opfix_JmpPertialSchedule( (*it) ); 135 138 136 139 //詰める … … 335 338 extern BOOL bDebugCompile; 336 339 //int 3 337 if(bDebugCompile) OpBuffer[obp++]=(char)0xCC; 340 if(bDebugCompile) 341 { 342 breakpoint; 343 } 338 344 #if defined(_DEBUG) 339 else OpBuffer[obp++]=(char)0xCC; 345 else 346 { 347 breakpoint; 348 } 340 349 #endif 341 350 break; … … 532 541 pLabelNames[MaxLabelNum].pName=0; 533 542 pLabelNames[MaxLabelNum].line=i3; 543 extern int obp; 534 544 pLabelNames[MaxLabelNum].address=obp; 535 545 MaxLabelNum++; 536 546 537 547 //書き込みスケジュール 538 std::vector<GotoLabelSchedule>::iterator it = compiler.codeGenerator.gotoLabelSchedules.begin();548 GotoLabelSchedules::iterator it = compiler.codeGenerator.gotoLabelSchedules.begin(); 539 549 while( it != compiler.codeGenerator.gotoLabelSchedules.end() ) 540 550 { 541 if( it->GetName().size() == 0 && it->GetLineNum() == i3 )551 if( (*it)->GetName().size() == 0 && (*it)->GetLineNum() == i3 ) 542 552 { 543 *((long *)( OpBuffer + it->GetNativeCodePos() ))=obp-(it->GetNativeCodePos()+sizeof(long));544 553 compiler.codeGenerator.opfix_JmpPertialSchedule( (*it) ); 554 545 555 //詰める 546 556 it = compiler.codeGenerator.gotoLabelSchedules.erase( it ); -
trunk/abdev/BasicCompiler_Common/PESchedule.cpp
r242 r253 154 154 void CSchedule::add(){ 155 155 pObpValues=(int *)HeapReAlloc(hHeap,0,pObpValues,(num+1)*sizeof(int)); 156 extern int obp; 156 157 pObpValues[num]=obp; 157 158 num++; … … 227 228 if(!bCall){ 228 229 //リロケーション情報を追加する 230 extern int obp; 229 231 pobj_Reloc->AddSchedule_CodeSection(obp); 230 232 } -
trunk/abdev/BasicCompiler_Common/include/CodeGenerator.h
r252 r253 12 12 void ReallocNativeCodeBuffer(); 13 13 14 //Goto未知ラベル15 class GotoLabelSchedule16 {17 std::string name;18 int line;19 int nativeCodePos;20 int sourceCodePos;21 public:22 GotoLabelSchedule( const std::string &name, int nativeCodePos, int sourceCodePos )23 : name( name )24 , line( -1 )25 , nativeCodePos( nativeCodePos )26 , sourceCodePos( sourceCodePos )27 {28 }29 GotoLabelSchedule( int line, int nativeCodePos, int sourceCodePos )30 : line( line )31 , nativeCodePos( nativeCodePos )32 , sourceCodePos( sourceCodePos )33 {34 }35 const std::string &GetName() const36 {37 return name;38 }39 int GetLineNum() const40 {41 return line;42 }43 int GetNativeCodePos() const44 {45 return nativeCodePos;46 }47 int GetSourceCodePos() const48 {49 return sourceCodePos;50 }51 };52 53 14 // コード生成時の部分的なスケジューリング 54 15 class PertialSchedule … … 85 46 typedef std::vector<const PertialSchedule *> PertialSchedules; 86 47 48 //Goto未知ラベル 49 class GotoLabelSchedule : public PertialSchedule 50 { 51 std::string name; 52 int line; 53 int sourceCodePos; 54 public: 55 GotoLabelSchedule( const std::string &name, int nativeCodePos, int sourceCodePos ) 56 : PertialSchedule( nativeCodePos, sizeof(long) ) 57 , name( name ) 58 , line( -1 ) 59 , sourceCodePos( sourceCodePos ) 60 { 61 } 62 GotoLabelSchedule( int line, int nativeCodePos, int sourceCodePos ) 63 : PertialSchedule( nativeCodePos, sizeof(long) ) 64 , line( line ) 65 , sourceCodePos( sourceCodePos ) 66 { 67 } 68 const std::string &GetName() const 69 { 70 return name; 71 } 72 int GetLineNum() const 73 { 74 return line; 75 } 76 int GetSourceCodePos() const 77 { 78 return sourceCodePos; 79 } 80 }; 81 typedef std::vector<const GotoLabelSchedule *> GotoLabelSchedules; 82 87 83 class LexicalScope 88 84 { … … 186 182 public: 187 183 184 // ローカル変数用スケジュールの管理 185 PertialSchedules localVarPertialSchedules; 186 188 187 // Exit Subスケジュールの管理 189 188 std::vector<long> exitSubCodePositions; … … 191 190 192 191 // Gotoスケジュールの管理 193 std::vector<GotoLabelSchedule>gotoLabelSchedules;192 GotoLabelSchedules gotoLabelSchedules; 194 193 195 194 // レキシカルスコープの管理 … … 256 255 257 256 void opfix( const PertialSchedule *pPertialSchedule, long newValue ); 257 void opfix_offset( const PertialSchedule *pPertialSchedule, long offset ); 258 258 void opfix_JmpPertialSchedule( const PertialSchedule *pPertialSchedule ); 259 259 … … 279 279 void op_jmp_continue(); 280 280 void op_jmp_exitsub(); 281 void op_jmp_goto_schedule( const GotoLabelSchedule &gotoLabelSchedule);281 void op_jmp_goto_schedule( const std::string &name, int lineNum, int sourceCodePos ); 282 282 283 283 … … 370 370 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 ); 371 371 public: 372 void op_mov_MV ( int op_size, int base_reg, long offset, Schedule::Type offsetScheduleType, long value, Schedule::Type valueScheduleType = Schedule::None );373 void op_mov_RV (int reg,long offset, Schedule::Type scheduleType = Schedule::None );374 void op_mov_RR (int reg1,int reg2);375 void op_mov_RM (int op_size,int reg,int base_reg,int offset,char mod, Schedule::Type scheduleType = Schedule::None );376 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 );377 void op_mov_MR (int op_size,int reg,int base_reg,int offset,char mod, Schedule::Type scheduleType = Schedule::None );378 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 );379 void op_movsx_R32R16 (int reg32,int reg16 = REG_NON);380 void op_movsx_R32R8 (int reg32,int reg8 = REG_NON);381 void op_movsx_R16R8 (int reg16,int reg8 = REG_NON);382 void op_lea_RM ( int reg, int base_reg, long offset, char mod, Schedule::Type scheduleType = Schedule::None );383 void op_inc (int reg);384 void op_dec (int reg);385 void op_add_RV8 (int reg,char cValue);386 void op_add_RV ( int reg, long offset, Schedule::Type scheduleType = Schedule::None );387 void op_add_RR ( int reg1, int reg2 );388 void op_add_RM (int op_size,int reg,int base_reg,int offset,char mod, Schedule::Type scheduleType = Schedule::None );372 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 ); 373 void op_mov_RV ( int reg,long offset, Schedule::Type scheduleType = Schedule::None ); 374 void op_mov_RR ( int reg1,int reg2); 375 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 ); 376 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 ); 377 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 ); 378 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 ); 379 void op_movsx_R32R16 ( int reg32,int reg16 = REG_NON); 380 void op_movsx_R32R8 ( int reg32,int reg8 = REG_NON); 381 void op_movsx_R16R8 ( int reg16,int reg8 = REG_NON); 382 const PertialSchedule *op_lea_RM ( int reg, int base_reg, long offset, char mod, Schedule::Type scheduleType = Schedule::None, bool isPertialSchedule = false ); 383 void op_inc (int reg); 384 void op_dec (int reg); 385 void op_add_RV8 (int reg,char cValue); 386 const PertialSchedule *op_add_RV ( int reg, long offset, Schedule::Type scheduleType = Schedule::None, bool isPertialSchedule = false ); 387 void op_add_RR ( int reg1, int reg2 ); 388 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 ); 389 389 void op_adc_RV8 (int reg,char cValue); 390 390 void op_adc_RR ( int reg1, int reg2 ); … … 413 413 void op_pop(int reg = REG_NON); 414 414 void op_add_esp(long num); 415 void op_sub_esp(long num);415 const PertialSchedule *op_sub_esp( long num, bool isPertialSchedule = false ); 416 416 void op_cmp_RR( int reg1, int reg2 ); 417 417 void op_cmp_value(int op_size,int reg,char byte_data); … … 421 421 void op_fld_ptr_esp(int type); 422 422 void op_fld_basereg (int type,int base_reg); 423 void op_fld_base_offset (int type,int base_reg,long offset, Schedule::Type scheduleType = Schedule::None );424 void op_fld_base_offset_ex (int type,int base_reg1,int base_reg2,long offset,BOOL bUseOffset, Schedule::Type scheduleType = Schedule::None);423 const PertialSchedule *op_fld_base_offset (int type,int base_reg,long offset, Schedule::Type scheduleType = Schedule::None, bool isPertialSchedule = false ); 424 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 ); 425 425 void op_fstp_basereg (int type,int base_reg); 426 void op_fstp_base_offset (int type,int base_reg,long offset, Schedule::Type scheduleType = Schedule::None);427 void op_fstp_base_offset_ex (int type,int base_reg1,int base_reg2,long offset,BOOL bUseOffset, Schedule::Type scheduleType = Schedule::None);426 const PertialSchedule *op_fstp_base_offset (int type,int base_reg,long offset, Schedule::Type scheduleType = Schedule::None, bool isPertialSchedule = false ); 427 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 ); 428 428 void op_fistp_ptr_esp ( int typeSize ); 429 429 void op_fstp_push ( Type &type ); … … 452 452 pNativeCode->Put( nativeCode ); 453 453 } 454 void PutOld( char c ) 455 { 456 pNativeCode->Put( c ); 457 } 454 458 void PutOld( char c1, char c2 ) 455 459 { -
trunk/abdev/BasicCompiler_Common/include/NativeCode.h
r252 r253 7 7 #include <BoostSerializationSupport.h> 8 8 9 void AddLocalVarAddrSchedule();10 9 void ObpPlus( int step = 1 ); 11 10 … … 19 18 None = 10000, 20 19 GlobalVar, // グローバル変数スケジュール 21 LocalVar, // ローカル変数スケジュール22 20 DataTable, // データテーブル スケジュール 23 21 Relocation, // リロケーション情報スケジュール … … 172 170 } 173 171 172 long GetLong( int codePos ) const 173 { 174 return *(long *)(this->codeBuffer+codePos); 175 } 176 long _GetLong_ObpOld( int _obpOld ) const 177 { 178 extern char *OpBuffer; 179 return *(long *)(OpBuffer+_obpOld); 180 } 181 174 182 void Overwrite( int codePos, char c ) 175 183 { … … 236 244 pobj_GlobalVarSchedule->add(); 237 245 break; 238 case Schedule::LocalVar:239 AddLocalVarAddrSchedule();240 break;241 246 case Schedule::DataTable: 242 247 extern CSchedule *pobj_DataTableSchedule; -
trunk/abdev/BasicCompiler_Common/src/CommonCodeGenerator.cpp
r251 r253 65 65 66 66 isSuccessful = true; 67 break; 68 } 69 else 70 { 71 it++; 72 } 73 } 74 75 if( isSuccessful == false ) 76 { 77 SetError(); 78 } 79 } 80 81 void CodeGenerator::opfix_offset( const PertialSchedule *pPertialSchedule, long offset ) 82 { 83 bool isSuccessful = false; 84 85 PertialSchedules::iterator it = pertialSchedules.begin(); 86 while( it != pertialSchedules.end() ) 87 { 88 if( (*it) == pPertialSchedule ) 89 { 90 if( pPertialSchedule->GetTypeSize() == sizeof(long) ) 91 { 92 pNativeCode->Overwrite( 93 pPertialSchedule->GetCodePos(), 94 pNativeCode->GetLong(pPertialSchedule->GetCodePos()) + offset 95 ); 96 97 // TODO: 未完成(用が無くなったら消す) 98 pNativeCode->OverwriteOld( 99 pPertialSchedule->GetObpOld(), 100 pNativeCode->_GetLong_ObpOld(pPertialSchedule->GetObpOld()) + offset 101 ); 102 } 103 else 104 { 105 SetError(); 106 } 107 108 it = pertialSchedules.erase( it ); 109 delete pPertialSchedule; 110 111 isSuccessful = true; 112 break; 67 113 } 68 114 else … … 280 326 pNativeCode->Put( (long)0 ); 281 327 } 282 void CodeGenerator::op_jmp_goto_schedule( const GotoLabelSchedule &gotoLabelSchedule)328 void CodeGenerator::op_jmp_goto_schedule( const std::string &name, int lineNum, int sourceCodePos ) 283 329 { 284 330 // オペコード 285 331 pNativeCode->Put( (char)0xE9 ); 286 332 287 gotoLabelSchedules.push_back( gotoLabelSchedule ); 333 const GotoLabelSchedule *pGotoLabelSchedule = NULL; 334 if( name.size() == 0 ) 335 { 336 pGotoLabelSchedule = new GotoLabelSchedule( name, pNativeCode->GetSize(), sourceCodePos ); 337 } 338 else 339 { 340 pGotoLabelSchedule = new GotoLabelSchedule( name, pNativeCode->GetSize(), sourceCodePos ); 341 } 342 gotoLabelSchedules.push_back( pGotoLabelSchedule ); 343 344 pertialSchedules.push_back( pGotoLabelSchedule ); 288 345 289 346 pNativeCode->Put( (long)0 ); -
trunk/abdev/BasicCompiler_Common/src/LexicalScope.cpp
r248 r253 136 136 137 137 //mov ecx,dword ptr[ebp+offset] 138 compiler.codeGenerator.op_mov_RM(sizeof(long),REG_ECX,REG_EBP,-pVar->GetOffsetAddress(),MOD_BASE_DISP32, Schedule::LocalVar ); 138 compiler.codeGenerator.localVarPertialSchedules.push_back( 139 compiler.codeGenerator.op_mov_RM(sizeof(long),REG_ECX,REG_EBP,-pVar->GetOffsetAddress(),MOD_BASE_DISP32, Schedule::None, true ) 140 ); 139 141 140 142 //push ecx
Note:
See TracChangeset
for help on using the changeset viewer.