Changeset 241 in dev for trunk/abdev/BasicCompiler32
- Timestamp:
- Jul 27, 2007, 12:06:11 AM (17 years ago)
- Location:
- trunk/abdev/BasicCompiler32
- Files:
-
- 4 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 // コード生成対象を選択
Note:
See TracChangeset
for help on using the changeset viewer.