Changeset 241 in dev
- Timestamp:
- Jul 27, 2007, 12:06:11 AM (17 years ago)
- Location:
- trunk/abdev
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/abdev/BasicCompiler32/Compile_ProcOp.cpp
r240 r241 443 443 444 444 //Continueアドレスを初期化 445 extern DWORD dwContinueAddress; 446 dwContinueAddress=-1; 445 compiler.codeGenerator.ClearContinueArea(); 447 446 448 447 if(bDebugCompile&&bDebugSupportProc==0){ -
trunk/abdev/BasicCompiler32/Compile_Statement.cpp
r236 r241 126 126 127 127 void OpcodeIf(char *Parameter){ 128 int i,i2 ,i3,i4;128 int i,i2; 129 129 Type tempType; 130 130 … … 140 140 } 141 141 142 CodeGenerator::PertialSchedule *pIfPertialSchedule = NULL; 142 143 if( !NumOpe(Parameter,Type(),tempType) ){ 143 144 //NumOpe内でエラー 144 i3=-1; //ダミー145 145 } 146 146 else if( tempType.IsDouble() ){ … … 167 167 168 168 //jne (endif、または else まで) 169 OpBuffer[obp++]=(char)0x0F; 170 OpBuffer[obp++]=(char)0x85; 171 obp+=sizeof(long); 172 173 //jneの番地 174 i3=obp; 169 pIfPertialSchedule = compiler.codeGenerator.op_jne( 0, sizeof(long), true ); 175 170 } 176 171 else if( tempType.IsSingle() ){ … … 197 192 198 193 //jne (endif、または else まで) 199 OpBuffer[obp++]=(char)0x0F; 200 OpBuffer[obp++]=(char)0x85; 201 obp+=sizeof(long); 202 203 //jneの番地 204 i3=obp; 194 pIfPertialSchedule = compiler.codeGenerator.op_jne( 0, sizeof(long), true ); 205 195 } 206 196 else if( tempType.Is64() ){ … … 217 207 218 208 //jne 219 OpBuffer[obp++]=(char)0x0F; 220 OpBuffer[obp++]=(char)0x85; 221 obp+=sizeof(long); 222 i3=obp; 223 209 CodeGenerator::PertialSchedule *pTempPertialSchedule1 = compiler.codeGenerator.op_jne( 0, sizeof(char), true ); 224 210 225 211 //cmp ebx,0 … … 227 213 228 214 //jne 229 OpBuffer[obp++]=(char)0x0F; 230 OpBuffer[obp++]=(char)0x85; 231 obp+=sizeof(long); 232 i4=obp; 233 234 215 CodeGenerator::PertialSchedule *pTempPertialSchedule2 = compiler.codeGenerator.op_jne( 0, sizeof(char), true ); 235 216 236 217 //jmp (endif、または else までジャンプ) 237 OpBuffer[obp++]=(char)0xE9; 238 obp+=sizeof(long); 239 240 *((long *)(OpBuffer+i3-sizeof(long)))=obp-i3; 241 *((long *)(OpBuffer+i4-sizeof(long)))=obp-i4; 242 243 //jmpの番地 244 i3=obp; 218 pIfPertialSchedule = compiler.codeGenerator.op_jmp( 0, sizeof(long), true ); 219 220 compiler.codeGenerator.opfix_JmpPertialSchedule( pTempPertialSchedule1 ); 221 compiler.codeGenerator.opfix_JmpPertialSchedule( pTempPertialSchedule2 ); 245 222 } 246 223 else{ … … 254 231 255 232 //je (endif、または else まで条件ジャンプ) 256 OpBuffer[obp++]=(char)0x0F; 257 OpBuffer[obp++]=(char)0x84; 258 obp+=sizeof(long); 259 260 //jeの番地 261 i3=obp; 233 pIfPertialSchedule = compiler.codeGenerator.op_je( 0, sizeof(long), true ); 262 234 } 263 235 … … 276 248 277 249 278 if( i3==-1) return;250 if( pIfPertialSchedule == NULL ) return; 279 251 280 252 if(i2==ESC_ELSE){ 281 253 //jmp (endifまで) 282 OpBuffer[obp++]=(char)0xE9; 283 obp+=sizeof(long); 284 285 *((long *)(OpBuffer+i3-sizeof(long)))=obp-i3; //ifからelseへのジャンプ先のオフセット値 286 287 i3=obp; 254 CodeGenerator::PertialSchedule *pTempPertialSchedule = compiler.codeGenerator.op_jmp( 0, sizeof(long), true ); 255 256 compiler.codeGenerator.opfix_JmpPertialSchedule( pIfPertialSchedule ); 288 257 289 258 … … 301 270 302 271 303 *((long *)(OpBuffer+i3-sizeof(long)))=obp-i3; //jmpジャンプ先のオフセット値272 compiler.codeGenerator.opfix_JmpPertialSchedule( pTempPertialSchedule ); 304 273 } 305 274 else{ 306 *((long *)(OpBuffer+i3-sizeof(long)))=obp-i3; //jeジャンプ先のオフセット値275 compiler.codeGenerator.opfix_JmpPertialSchedule( pIfPertialSchedule ); 307 276 } 308 277 } … … 371 340 void OpcodeWhile(char *Parameter){ 372 341 extern HANDLE hHeap; 373 int i2,i3 = 0;374 342 375 343 //Continueアドレスのバックアップとセット 376 extern DWORD dwContinueAddress; 377 DWORD dwTempContinue; 378 dwTempContinue=dwContinueAddress; 379 dwContinueAddress=obp; 344 compiler.codeGenerator.ContinueAreaBegin(); 380 345 381 346 if(!Parameter[0]) SetError(10,"While",cp); 382 347 383 int je_schedule;348 CodeGenerator::PertialSchedule *pWhilePertialSchedule = NULL; 384 349 Type tempType; 385 350 if( !NumOpe(Parameter,Type(),tempType) ){ 386 351 //ダミー 387 i3=-1;388 352 } 389 353 else if( tempType.IsDouble() ){ … … 410 374 411 375 //jne (Wend まで) 412 OpBuffer[obp++]=(char)0x0F; 413 OpBuffer[obp++]=(char)0x85; 414 obp+=sizeof(long); 415 416 //jeの番地 417 je_schedule=obp; 376 pWhilePertialSchedule = compiler.codeGenerator.op_jne( 0, sizeof(long), true ); 418 377 } 419 378 else if( tempType.IsSingle() ){ … … 436 395 compiler.codeGenerator.op_fnstsw_ax(); 437 396 438 //test ah,40 397 //test ah,40h 439 398 compiler.codeGenerator.op_test_ah( (char)0x40 ); 440 399 441 400 //jne (Wend まで) 442 OpBuffer[obp++]=(char)0x0F; 443 OpBuffer[obp++]=(char)0x85; 444 obp+=sizeof(long); 445 446 //jeの番地 447 je_schedule=obp; 401 pWhilePertialSchedule = compiler.codeGenerator.op_jne( 0, sizeof(long), true ); 448 402 } 449 403 else if( tempType.Is64() ){ … … 460 414 461 415 //jne 462 OpBuffer[obp++]=(char)0x0F; 463 OpBuffer[obp++]=(char)0x85; 464 obp+=sizeof(long); 465 i2=obp; 466 416 CodeGenerator::PertialSchedule *pTempPertialSchedule1 = compiler.codeGenerator.op_jne( 0, sizeof(char), true ); 467 417 468 418 //cmp ebx,0 … … 470 420 471 421 //jne 472 OpBuffer[obp++]=(char)0x0F; 473 OpBuffer[obp++]=(char)0x85; 474 obp+=sizeof(long); 475 i3=obp; 476 477 478 //jmp (endif、または else までジャンプ) 479 OpBuffer[obp++]=(char)0xE9; 480 obp+=sizeof(long); 481 482 *((long *)(OpBuffer+i2-sizeof(long)))=obp-i2; 483 *((long *)(OpBuffer+i3-sizeof(long)))=obp-i3; 484 485 //jmpの番地 486 je_schedule=obp; 422 CodeGenerator::PertialSchedule *pTempPertialSchedule2 = compiler.codeGenerator.op_jne( 0, sizeof(char), true ); 423 424 //jmp (Wendまでジャンプ) 425 pWhilePertialSchedule = compiler.codeGenerator.op_jmp( 0, sizeof(long), true ); 426 427 compiler.codeGenerator.opfix_JmpPertialSchedule( pTempPertialSchedule1 ); 428 compiler.codeGenerator.opfix_JmpPertialSchedule( pTempPertialSchedule2 ); 487 429 } 488 430 else{ … … 496 438 497 439 //je (Wend まで) 498 OpBuffer[obp++]=(char)0x0F; 499 OpBuffer[obp++]=(char)0x84; 500 obp+=sizeof(long); 501 502 //実行中の番地 503 je_schedule=obp; 440 pWhilePertialSchedule = compiler.codeGenerator.op_je( 0, sizeof(long), true ); 504 441 } 505 442 … … 512 449 GetLexicalScopes().CallDestructorsOfScopeEnd(); 513 450 514 if( i3 == -1 ){515 return;516 }517 518 451 //jmp ... 519 OpBuffer[obp++]=(char)0xE9; 520 *((long *)(OpBuffer+obp))=dwContinueAddress-(obp+sizeof(long)); 521 obp+=sizeof(long); 452 compiler.codeGenerator.op_jmp_continue(); 522 453 523 454 //レキシカルスコープをレベルダウン 524 455 GetLexicalScopes().End(); 525 456 526 *((long *)(OpBuffer+je_schedule-sizeof(long)))=obp-je_schedule; //jeジャンプ先のオフセット値 527 528 //Continueアドレスを復元 529 dwContinueAddress=dwTempContinue; 457 if( pWhilePertialSchedule ) 458 { 459 compiler.codeGenerator.opfix_JmpPertialSchedule( pWhilePertialSchedule ); 460 } 461 462 compiler.codeGenerator.ContinueAreaEnd(); 530 463 } 531 464 … … 533 466 void OpcodeFor(char *Parameter){ 534 467 extern HANDLE hHeap; 535 int i,i2 ,i3;468 int i,i2; 536 469 char temporary[VN_SIZE],variable[VN_SIZE],JudgeNum[VN_SIZE],StepNum[VN_SIZE]; 537 470 … … 559 492 560 493 //jmp ... 561 OpBuffer[obp++]=(char)0xE9; 562 i2=obp; 563 obp+=sizeof(long); 494 CodeGenerator::PertialSchedule *pTempPertialSchedule = compiler.codeGenerator.op_jmp( 0, sizeof(long), true ); 564 495 565 496 //Continueアドレスのバックアップとセット 566 extern DWORD dwContinueAddress; 567 DWORD dwTempContinue; 568 dwTempContinue=dwContinueAddress; 569 dwContinueAddress=obp; 497 compiler.codeGenerator.ContinueAreaBegin(); 570 498 571 499 //第2パラメータを取得(to~) … … 583 511 OpcodeCalc(temporary); 584 512 585 *((long *)(OpBuffer+i2))=obp-(i2+sizeof(long));513 compiler.codeGenerator.opfix_JmpPertialSchedule( pTempPertialSchedule ); 586 514 587 515 //増加か減少かを区別する … … 596 524 597 525 //je [カウンタ減少の場合の判定] 598 OpBuffer[obp++]=(char)0x0F; 599 OpBuffer[obp++]=(char)0x84; 600 i2=obp; 601 obp+=sizeof(long); 526 pTempPertialSchedule = compiler.codeGenerator.op_je( 0, sizeof(long), true ); 602 527 603 528 //判定(カウンタ増加の場合) … … 609 534 610 535 //jmp [カウンタ減少の場合の判定を飛び越す] 611 OpBuffer[obp++]=(char)0xE9; 612 i3=obp; 613 obp+=sizeof(long); 614 615 *((long *)(OpBuffer+i2))=obp-(i2+sizeof(long)); //jeジャンプ先のオフセット値 536 CodeGenerator::PertialSchedule *pTempPertialSchedule2 = compiler.codeGenerator.op_jmp( 0, sizeof(long), true ); 537 538 //jeジャンプ先のオフセット値 539 compiler.codeGenerator.opfix_JmpPertialSchedule( pTempPertialSchedule ); 616 540 617 541 //判定(カウンタ減少の場合) … … 622 546 compiler.codeGenerator.op_pop(REG_EAX); 623 547 624 *((long *)(OpBuffer+i3))=obp-(i3+sizeof(long)); //jmpジャンプ先のオフセット値 548 //jmpジャンプ先のオフセット値 549 compiler.codeGenerator.opfix_JmpPertialSchedule( pTempPertialSchedule2 ); 625 550 626 551 //cmp eax,0 … … 630 555 631 556 //je ... 632 OpBuffer[obp++]=(char)0x0F; 633 OpBuffer[obp++]=(char)0x84; 634 int je_schedule=obp; 635 obp+=sizeof(long); 557 pTempPertialSchedule = compiler.codeGenerator.op_je( 0, sizeof(long), true ); 636 558 637 559 //レキシカルスコープをレベルアップ … … 650 572 651 573 //jmp ... 652 OpBuffer[obp++]=(char)0xE9; 653 *((long *)(OpBuffer+obp))=dwContinueAddress-(obp+sizeof(long)); 654 obp+=sizeof(long); 574 compiler.codeGenerator.op_jmp_continue(); 655 575 656 576 //レキシカルスコープをレベルダウン 657 577 GetLexicalScopes().End(); 658 578 659 *((long *)(OpBuffer+je_schedule))=obp-(je_schedule+sizeof(long)); //jeジャンプ先のオフセット値 579 //jeジャンプ先のオフセット値 580 compiler.codeGenerator.opfix_JmpPertialSchedule( pTempPertialSchedule ); 660 581 661 582 //Continueアドレスを復元 662 dwContinueAddress=dwTempContinue;583 compiler.codeGenerator.ContinueAreaEnd(); 663 584 } 664 585 … … 670 591 671 592 //Continueアドレスのバックアップとセット 672 extern DWORD dwContinueAddress; 673 DWORD dwTempContinue; 674 dwTempContinue=dwContinueAddress; 675 dwContinueAddress=obp; 593 compiler.codeGenerator.ContinueAreaBegin(); 676 594 677 595 //レキシカルスコープをレベルアップ … … 682 600 683 601 GetLexicalScopes().CallDestructorsOfScopeEnd(); 602 603 CodeGenerator::PertialSchedule *pDoPertialSchedule = NULL; 684 604 685 605 extern char *basbuf; … … 731 651 732 652 //jne 5(ループ終了) 733 OpBuffer[obp++]=(char)0x75; 734 OpBuffer[obp++]=(char)0x05; 653 pDoPertialSchedule = compiler.codeGenerator.op_jne( 0, sizeof(char), true ); 735 654 } 736 655 else if(basbuf[i3]=='1'){ … … 738 657 739 658 //je 5(ループ終了) 740 OpBuffer[obp++]=(char)0x74; 741 OpBuffer[obp++]=(char)0x05; 659 pDoPertialSchedule = compiler.codeGenerator.op_je( 0, sizeof(char), true ); 742 660 } 743 661 } … … 768 686 769 687 //jne 5(ループ終了) 770 OpBuffer[obp++]=(char)0x75; 771 OpBuffer[obp++]=(char)0x05; 688 pDoPertialSchedule = compiler.codeGenerator.op_jne( 0, sizeof(char), true ); 772 689 } 773 690 else if(basbuf[i3]=='1'){ … … 775 692 776 693 //je 5(ループ終了) 777 OpBuffer[obp++]=(char)0x74; 778 OpBuffer[obp++]=(char)0x05; 694 pDoPertialSchedule = compiler.codeGenerator.op_je( 0, sizeof(char), true ); 779 695 } 780 696 } … … 812 728 813 729 //jmp 5(ループ終了) 814 OpBuffer[obp++]=(char)0xEB; 815 OpBuffer[obp++]=(char)0x05; 730 pDoPertialSchedule = compiler.codeGenerator.op_jmp( 0, sizeof(char), true ); 816 731 817 732 *((long *)(OpBuffer+i2-sizeof(long)))=obp-i2; … … 829 744 830 745 //jmp 5(ループ終了) 831 OpBuffer[obp++]=(char)0xEB; 832 OpBuffer[obp++]=(char)0x05; 746 pDoPertialSchedule = compiler.codeGenerator.op_jmp( 0, sizeof(char), true ); 833 747 } 834 748 } … … 844 758 845 759 //je 5(ループ終了) 846 OpBuffer[obp++]=(char)0x74; 847 OpBuffer[obp++]=(char)0x05; 760 pDoPertialSchedule = compiler.codeGenerator.op_je( 0, sizeof(char), true ); 848 761 } 849 762 else if(basbuf[i3]=='1'){ … … 851 764 852 765 //jne 5(ループ終了) 853 OpBuffer[obp++]=(char)0x75; 854 OpBuffer[obp++]=(char)0x05; 766 pDoPertialSchedule = compiler.codeGenerator.op_jne( 0, sizeof(char), true ); 855 767 } 856 768 } … … 860 772 861 773 //jmp ... 862 OpBuffer[obp++]=(char)0xE9; 863 *((long *)(OpBuffer+obp))=dwContinueAddress-(obp+sizeof(long)); 864 obp+=sizeof(long); 774 compiler.codeGenerator.op_jmp_continue(); 775 776 if( pDoPertialSchedule ) 777 { 778 compiler.codeGenerator.opfix_JmpPertialSchedule( pDoPertialSchedule ); 779 } 865 780 866 781 //jmp ... … … 876 791 877 792 //Continueアドレスを復元 878 dwContinueAddress=dwTempContinue;793 compiler.codeGenerator.ContinueAreaEnd(); 879 794 } 880 795 void OpcodeContinue(void){ 881 extern DWORD dwContinueAddress;882 883 if(dwContinueAddress==-1){884 SetError(12,"Continue",cp);885 return;886 }887 888 796 //jmp ...(Continue addr) 889 OpBuffer[obp++]=(char)0xE9; 890 891 *((long *)(OpBuffer+obp))=dwContinueAddress-(obp+sizeof(long)); 892 obp+=sizeof(long); 797 compiler.codeGenerator.op_jmp_continue(); 893 798 } 894 799 -
trunk/abdev/BasicCompiler32/Compile_Var.cpp
r237 r241 140 140 141 141 //add dword ptr[esp],eax 142 OpBuffer[obp++]=(char)0x01; 143 OpBuffer[obp++]=(char)0x04; 144 OpBuffer[obp++]=(char)0x24; 142 compiler.codeGenerator.PutOld( 143 (char)0x01, 144 (char)0x04, 145 (char)0x24 146 ); 145 147 146 148 HeapDefaultFree(pParm[i]); … … 238 240 if(offset){ 239 241 //add ecx,offset 240 OpBuffer[obp++]=(char)0x81; 241 OpBuffer[obp++]=(char)0xC1; 242 *((long *)(OpBuffer+obp))=offset; 243 obp+=sizeof(long); 242 compiler.codeGenerator.op_add_RV( REG_ECX, offset ); 244 243 } 245 244 … … 314 313 315 314 //mov ecx,dword ptr[ecx] 316 OpBuffer[obp++]=(char)0x8B; 317 OpBuffer[obp++]=(char)0x09; 315 compiler.codeGenerator.op_mov_RM( sizeof(long), REG_ECX, REG_ECX, 0, MOD_BASE ); 318 316 } 319 317 else{ … … 669 667 670 668 //mov ecx,dword ptr[eax] 671 OpBuffer[obp++]=(char)0x8B; 672 OpBuffer[obp++]=(char)0x08; 669 compiler.codeGenerator.op_mov_RM( sizeof(long), REG_ECX, REG_EAX, 0, MOD_BASE ); 673 670 } 674 671 } … … 690 687 691 688 //mov ecx,dword ptr[eax] 692 OpBuffer[obp++]=(char)0x8B; 693 OpBuffer[obp++]=(char)0x08; 689 compiler.codeGenerator.op_mov_RM( sizeof(long), REG_ECX, REG_EAX, 0, MOD_BASE ); 694 690 } 695 691 else{ … … 964 960 if( type.IsDouble() ){ 965 961 //mov eax,HILONG(dbl) 966 OpBuffer[obp++]=(char)0xB8; 967 *((long *)(OpBuffer+obp))=(long)*(long *)(((char *)(&dbl))+4); 968 obp+=sizeof(long); 962 compiler.codeGenerator.op_mov_RV( REG_EAX, *(long *)(((char *)(&dbl))+4) ); 969 963 970 964 //mov dword ptr[ebp+offset+sizeof(long)],eax … … 1133 1127 1134 1128 //mov eax,ebp 1135 OpBuffer[obp++]=(char)0x8B; 1136 OpBuffer[obp++]=(char)0xC5; 1129 compiler.codeGenerator.op_mov_RR( REG_EAX, REG_EBP ); 1137 1130 1138 1131 //add eax,offset … … 1192 1185 if(pRelativeVar->bOffsetOffset){ 1193 1186 //mov eax,ecx 1194 OpBuffer[obp++]=(char)0x8B; 1195 OpBuffer[obp++]=(char)0xC1; 1187 compiler.codeGenerator.op_mov_RR( REG_EAX, REG_ECX ); 1196 1188 1197 1189 //add eax,dword ptr[offset] … … 1209 1201 1210 1202 //lea eax,dword ptr[ebp+ecx] 1211 OpBuffer[obp++]=(char)0x8D; 1212 OpBuffer[obp++]=(char)0x44; 1213 OpBuffer[obp++]=(char)0x0D; 1214 OpBuffer[obp++]=(char)0x00; 1203 compiler.codeGenerator.PutOld( 1204 (char)0x8D, 1205 (char)0x44, 1206 (char)0x0D, 1207 (char)0x00 1208 ); 1215 1209 } 1216 1210 else{ -
trunk/abdev/BasicCompiler32/MakePeHdr.cpp
r234 r241 434 434 435 435 //Continueアドレスを初期化 436 extern DWORD dwContinueAddress; 437 dwContinueAddress=-1; 436 compiler.codeGenerator.ClearContinueArea(); 438 437 439 438 // コード生成対象を選択 -
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.