- Timestamp:
- Jul 28, 2007, 1:30:22 PM (17 years ago)
- Location:
- trunk/abdev
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/abdev/BasicCompiler32/Compile_ProcOp.cpp
r241 r246 425 425 426 426 //Gotoラベルスケジュール 427 extern GOTOLABELSCHEDULE *pGotoLabelSchedule; 428 extern int GotoLabelScheduleNum; 429 pGotoLabelSchedule=(GOTOLABELSCHEDULE *)HeapAlloc(hHeap,0,1); 430 GotoLabelScheduleNum=0; 427 compiler.codeGenerator.gotoLabelSchedules.clear(); 431 428 432 429 //With情報のメモリを確保 … … 608 605 HeapDefaultFree(pLabelNames); 609 606 610 //Goto未知ラベルスケジュールを解放611 for(i3=0;i3<GotoLabelScheduleNum;i3++){612 if(pGotoLabelSchedule[i3].pName){613 SetError(6,pGotoLabelSchedule[i3].pName,pGotoLabelSchedule[i3].now_cp);614 HeapDefaultFree(pGotoLabelSchedule[i3].pName);615 }616 else{617 sprintf(temporary,"%d",pGotoLabelSchedule[i3].line);618 SetError(6,temporary,pGotoLabelSchedule[i3].now_cp);619 }620 }621 HeapDefaultFree(pGotoLabelSchedule);622 623 607 //With情報のメモリを解放 624 608 for(i3=0;i3<WithInfo.num;i3++){ -
trunk/abdev/BasicCompiler32/Compile_Statement.cpp
r245 r246 300 300 void OpcodeGoto(char *Parameter){ 301 301 extern HANDLE hHeap; 302 extern GOTOLABELSCHEDULE *pGotoLabelSchedule;303 extern int GotoLabelScheduleNum;304 302 int i,LineNum; 305 303 … … 307 305 i=GetLabelAddress(Parameter+1,0); 308 306 309 //jmp ... 310 OpBuffer[obp++]=(char)0xE9; 311 if(i==-1){ 312 pGotoLabelSchedule=(GOTOLABELSCHEDULE *)HeapReAlloc(hHeap,0,pGotoLabelSchedule,(GotoLabelScheduleNum+1)*sizeof(GOTOLABELSCHEDULE)); 313 pGotoLabelSchedule[GotoLabelScheduleNum].pName=(char *)HeapAlloc(hHeap,0,lstrlen(Parameter+1)+1); 314 lstrcpy(pGotoLabelSchedule[GotoLabelScheduleNum].pName,Parameter+1); 315 pGotoLabelSchedule[GotoLabelScheduleNum].pos=obp; 316 pGotoLabelSchedule[GotoLabelScheduleNum].now_cp=cp; 317 GotoLabelScheduleNum++; 318 } 319 *((long *)(OpBuffer+obp))=i-(obp+sizeof(long)); 320 obp+=sizeof(long); 307 if( i == -1 ) 308 { 309 //jmp ...(schedule) 310 compiler.codeGenerator.op_jmp_goto_schedule( GotoLabelSchedule( (const std::string)(Parameter + 1), obp, cp ) ); 311 } 312 else 313 { 314 //jmp ... 315 compiler.codeGenerator.op_jmp( i-obp, sizeof(long), false, true ); 316 } 321 317 } 322 318 else{ … … 324 320 i=GetLabelAddress(0,LineNum); 325 321 326 //jmp ... 327 OpBuffer[obp++]=(char)0xE9; 328 if(i==-1){ 329 pGotoLabelSchedule=(GOTOLABELSCHEDULE *)HeapReAlloc(hHeap,0,pGotoLabelSchedule,(GotoLabelScheduleNum+1)*sizeof(GOTOLABELSCHEDULE)); 330 pGotoLabelSchedule[GotoLabelScheduleNum].pName=0; 331 pGotoLabelSchedule[GotoLabelScheduleNum].line=LineNum; 332 pGotoLabelSchedule[GotoLabelScheduleNum].pos=obp; 333 pGotoLabelSchedule[GotoLabelScheduleNum].now_cp=cp; 334 GotoLabelScheduleNum++; 335 } 336 *((long *)(OpBuffer+obp))=i-(obp+sizeof(long)); 337 obp+=sizeof(long); 322 if( i == -1 ) 323 { 324 //jmp ...(schedule) 325 compiler.codeGenerator.op_jmp_goto_schedule( GotoLabelSchedule( LineNum, obp, cp ) ); 326 } 327 else 328 { 329 //jmp ... 330 compiler.codeGenerator.op_jmp( i-obp, sizeof(long), false, true ); 331 } 338 332 } 339 333 } … … 1126 1120 void OpcodeGosub(char *Parameter){ 1127 1121 extern HANDLE hHeap; 1128 extern GOTOLABELSCHEDULE *pGotoLabelSchedule;1129 extern int GotoLabelScheduleNum;1130 1122 int i,LineNum; 1131 1123 … … 1133 1125 i=GetLabelAddress(Parameter+1,0); 1134 1126 1135 //call ... 1136 OpBuffer[obp++]=(char)0xE8; 1137 if(i==-1){ 1138 pGotoLabelSchedule=(GOTOLABELSCHEDULE *)HeapReAlloc(hHeap,0,pGotoLabelSchedule,(GotoLabelScheduleNum+1)*sizeof(GOTOLABELSCHEDULE)); 1139 pGotoLabelSchedule[GotoLabelScheduleNum].pName=(char *)HeapAlloc(hHeap,0,lstrlen(Parameter+1)+1); 1140 lstrcpy(pGotoLabelSchedule[GotoLabelScheduleNum].pName,Parameter+1); 1141 pGotoLabelSchedule[GotoLabelScheduleNum].pos=obp; 1142 pGotoLabelSchedule[GotoLabelScheduleNum].now_cp=cp; 1143 GotoLabelScheduleNum++; 1144 } 1145 *((long *)(OpBuffer+obp))=i-(obp+sizeof(long)); 1146 obp+=sizeof(long); 1127 if( i == -1 ) 1128 { 1129 //jmp ...(schedule) 1130 compiler.codeGenerator.op_jmp_goto_schedule( GotoLabelSchedule( (const std::string)(Parameter + 1), obp, cp ) ); 1131 } 1132 else 1133 { 1134 //jmp ... 1135 compiler.codeGenerator.op_jmp( i-obp, sizeof(long), false, true ); 1136 } 1147 1137 } 1148 1138 else{ … … 1150 1140 i=GetLabelAddress(0,LineNum); 1151 1141 1152 //call ... 1153 OpBuffer[obp++]=(char)0xE8; 1154 if(i==-1){ 1155 pGotoLabelSchedule=(GOTOLABELSCHEDULE *)HeapReAlloc(hHeap,0,pGotoLabelSchedule,(GotoLabelScheduleNum+1)*sizeof(GOTOLABELSCHEDULE)); 1156 pGotoLabelSchedule[GotoLabelScheduleNum].pName=0; 1157 pGotoLabelSchedule[GotoLabelScheduleNum].line=LineNum; 1158 pGotoLabelSchedule[GotoLabelScheduleNum].pos=obp; 1159 pGotoLabelSchedule[GotoLabelScheduleNum].now_cp=cp; 1160 GotoLabelScheduleNum++; 1161 } 1162 *((long *)(OpBuffer+obp))=i-(obp+sizeof(long)); 1163 obp+=sizeof(long); 1142 if( i == -1 ) 1143 { 1144 //jmp ...(schedule) 1145 compiler.codeGenerator.op_jmp_goto_schedule( GotoLabelSchedule( LineNum, obp, cp ) ); 1146 } 1147 else 1148 { 1149 //jmp ... 1150 compiler.codeGenerator.op_jmp( i-obp, sizeof(long), false, true ); 1151 } 1164 1152 } 1165 1153 } -
trunk/abdev/BasicCompiler32/MakePeHdr.cpp
r244 r246 422 422 423 423 //Gotoラベルスケジュール 424 extern GOTOLABELSCHEDULE *pGotoLabelSchedule; 425 extern int GotoLabelScheduleNum; 426 pGotoLabelSchedule=(GOTOLABELSCHEDULE *)HeapAlloc(hHeap,0,1); 427 GotoLabelScheduleNum=0; 424 compiler.codeGenerator.gotoLabelSchedules.clear(); 428 425 429 426 //With情報のメモリを確保 … … 473 470 HeapDefaultFree(pLabelNames); 474 471 475 //Goto未知ラベルスケジュール を解放476 for(i=0;i<GotoLabelScheduleNum;i++){477 if(pGotoLabelSchedule[i].pName){478 SetError(6,pGotoLabelSchedule[i].pName,pGotoLabelSchedule[i].now_cp);479 HeapDefaultFree(pGotoLabelSchedule[i].pName);472 //Goto未知ラベルスケジュールが存在したらエラーにする 473 BOOST_FOREACH( const GotoLabelSchedule &gotoLabelSchedule, compiler.codeGenerator.gotoLabelSchedules ) 474 { 475 if(gotoLabelSchedule.GetName().size()>0){ 476 SetError(6,gotoLabelSchedule.GetName(),gotoLabelSchedule.GetSourceCodePos()); 480 477 } 481 478 else{ 482 sprintf(temporary,"%d", pGotoLabelSchedule[i].line);483 SetError(6,temporary, pGotoLabelSchedule[i].now_cp);479 sprintf(temporary,"%d",gotoLabelSchedule.GetLineNum()); 480 SetError(6,temporary,gotoLabelSchedule.GetSourceCodePos()); 484 481 } 485 482 } 486 HeapDefaultFree(pGotoLabelSchedule);487 483 488 484 -
trunk/abdev/BasicCompiler32/Opcode.h
r225 r246 27 27 int line; 28 28 DWORD address; 29 };30 31 //Goto未知ラベル32 struct GOTOLABELSCHEDULE{33 char *pName;34 int line;35 DWORD pos;36 DWORD now_cp;37 29 }; 38 30 -
trunk/abdev/BasicCompiler_Common/Compile.cpp
r241 r246 32 32 DWORD *pExitSubSchedule; 33 33 int ExitSubScheduleNum; 34 35 //Goto未知ラベル スケジュール36 GOTOLABELSCHEDULE *pGotoLabelSchedule;37 int GotoLabelScheduleNum;38 34 39 35 //グローバル変数初期バッファ … … 123 119 void ChangeOpcode(char *Command){ 124 120 extern HANDLE hHeap; 125 int i,i2;126 121 127 122 if(Command[0]=='\0') … … 141 136 142 137 //書き込みスケジュール 143 for(i=0;i<GotoLabelScheduleNum;i++){ 144 if(lstrcmp(pGotoLabelSchedule[i].pName,Command+1)==0){ 145 *((long *)(OpBuffer+pGotoLabelSchedule[i].pos))=obp-(pGotoLabelSchedule[i].pos+sizeof(long)); 146 147 HeapDefaultFree(pGotoLabelSchedule[i].pName); 148 138 std::vector<GotoLabelSchedule>::iterator it = compiler.codeGenerator.gotoLabelSchedules.begin(); 139 while( it != compiler.codeGenerator.gotoLabelSchedules.end() ) 140 { 141 if( it->GetName() == Command+1 ) 142 { 143 *((long *)( OpBuffer + it->GetNativeCodePos() ))=obp-(it->GetNativeCodePos()+sizeof(long)); 144 149 145 //詰める 150 GotoLabelScheduleNum--; 151 for(i2=i;i2<GotoLabelScheduleNum;i2++){ 152 pGotoLabelSchedule[i2].pName=pGotoLabelSchedule[i2+1].pName; 153 pGotoLabelSchedule[i2].line=pGotoLabelSchedule[i2+1].line; 154 pGotoLabelSchedule[i2].pos=pGotoLabelSchedule[i2+1].pos; 155 } 156 i--; 157 continue; 146 it = compiler.codeGenerator.gotoLabelSchedules.erase( it ); 147 } 148 else 149 { 150 it++; 158 151 } 159 152 } … … 552 545 553 546 //書き込みスケジュール 554 for(i=0;i<GotoLabelScheduleNum;i++){ 555 if(pGotoLabelSchedule[i].pName==0&& 556 pGotoLabelSchedule[i].line==i3){ 557 *((long *)(OpBuffer+pGotoLabelSchedule[i].pos))=obp-(pGotoLabelSchedule[i].pos+sizeof(long)); 558 547 std::vector<GotoLabelSchedule>::iterator it = compiler.codeGenerator.gotoLabelSchedules.begin(); 548 while( it != compiler.codeGenerator.gotoLabelSchedules.end() ) 549 { 550 if( it->GetName().size() == 0 && it->GetLineNum() == i3 ) 551 { 552 *((long *)( OpBuffer + it->GetNativeCodePos() ))=obp-(it->GetNativeCodePos()+sizeof(long)); 553 559 554 //詰める 560 GotoLabelScheduleNum--; 561 for(i2=i;i2<GotoLabelScheduleNum;i2++){ 562 pGotoLabelSchedule[i2].pName=pGotoLabelSchedule[i2+1].pName; 563 pGotoLabelSchedule[i2].line=pGotoLabelSchedule[i2+1].line; 564 pGotoLabelSchedule[i2].pos=pGotoLabelSchedule[i2+1].pos; 565 } 566 i--; 555 it = compiler.codeGenerator.gotoLabelSchedules.erase( it ); 556 } 557 else 558 { 559 it++; 567 560 } 568 561 } -
trunk/abdev/BasicCompiler_Common/include/CodeGenerator.h
r245 r246 12 12 void ReallocNativeCodeBuffer(); 13 13 14 //Goto未知ラベル 15 class GotoLabelSchedule 16 { 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() const 36 { 37 return name; 38 } 39 int GetLineNum() const 40 { 41 return line; 42 } 43 int GetNativeCodePos() const 44 { 45 return nativeCodePos; 46 } 47 int GetSourceCodePos() const 48 { 49 return sourceCodePos; 50 } 51 }; 52 14 53 class CodeGenerator 15 54 { … … 61 100 62 101 public: 102 103 // Gotoスケジュールの管理 104 std::vector<GotoLabelSchedule> gotoLabelSchedules; 63 105 64 106 CodeGenerator() … … 141 183 const PertialSchedule *op_jmp( long offset, int op_size = sizeof(char), bool isPertialSchedule = false, bool isSelfOpcodeOffset = false ); 142 184 void op_jmp_continue(); 185 void op_jmp_goto_schedule( const GotoLabelSchedule &gotoLabelSchedule ); 143 186 144 187 -
trunk/abdev/BasicCompiler_Common/src/CommonCodeGenerator.cpp
r245 r246 202 202 op_jmp( GetContinueCodePosOld()-obp, sizeof(long), false, true ); 203 203 } 204 void CodeGenerator::op_jmp_goto_schedule( const GotoLabelSchedule &gotoLabelSchedule ) 205 { 206 // オペコード 207 pNativeCode->Put( (char)0xE9 ); 208 209 gotoLabelSchedules.push_back( gotoLabelSchedule ); 210 211 pNativeCode->Put( (long)0 ); 212 }
Note:
See TracChangeset
for help on using the changeset viewer.