Changeset 250 in dev for trunk/abdev/BasicCompiler32
- Timestamp:
- Jul 29, 2007, 9:30:14 PM (17 years ago)
- Location:
- trunk/abdev/BasicCompiler32
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/abdev/BasicCompiler32/Compile_CallProc.cpp
r235 r250 329 329 //call dword ptr[edx+func_index] 330 330 if(i2*PTR_SIZE<=0x7F){ 331 OpBuffer[obp++]=(char)0xFF; 332 OpBuffer[obp++]=(char)0x52; 333 OpBuffer[obp++]=(char)(i2*PTR_SIZE); 331 compiler.codeGenerator.PutOld( 332 (char)0xFF, 333 (char)0x52, 334 (char)(i2*PTR_SIZE) 335 ); 334 336 } 335 337 else{ 336 OpBuffer[obp++]=(char)0xFF; 337 OpBuffer[obp++]=(char)0x92; 338 *((long *)(OpBuffer+obp))=i2*PTR_SIZE; 339 obp+=sizeof(long); 338 compiler.codeGenerator.PutOld( 339 (char)0xFF, 340 (char)0x92 341 ); 342 compiler.codeGenerator.PutOld( (long)(i2*PTR_SIZE), Schedule::None ); 340 343 } 341 344 } … … 361 364 } 362 365 363 bool Opcode_CallDllProc( const char *lpszParms, DllProc *pDllProc ){366 bool Opcode_CallDllProc( const char *lpszParms, const DllProc *pDllProc ){ 364 367 365 368 extern BOOL bDebugCompile; … … 397 400 398 401 //call dword ptr[LookupTable] 399 pDllProc->Using(); 400 OpBuffer[obp++]=(char)0xFF; 401 OpBuffer[obp++]=(char)0x15; 402 pobj_ImportAddrSchedule->add(pDllProc); 403 obp+=sizeof(long); 402 compiler.codeGenerator.op_call( pDllProc ); 404 403 405 404 if(pDllProc->IsCdecl()){ -
trunk/abdev/BasicCompiler32/Compile_Func.cpp
r235 r250 36 36 37 37 //fnstcw word ptr[esp] 38 OpBuffer[obp++]=(char)0xD9; 39 OpBuffer[obp++]=(char)0x3C; 40 OpBuffer[obp++]=(char)0x24; 38 compiler.codeGenerator.PutOld( 39 (char)0xD9, 40 (char)0x3C, 41 (char)0x24 42 ); 41 43 42 44 //mov ax,word ptr[esp] 43 OpBuffer[obp++]=(char)0x66; 44 OpBuffer[obp++]=(char)0x8B; 45 OpBuffer[obp++]=(char)0x04; 46 OpBuffer[obp++]=(char)0x24; 45 compiler.codeGenerator.op_mov_RM( sizeof(short), REG_EAX, REG_ESP, 0, MOD_BASE ); 47 46 48 47 //or ah,0Ch 49 OpBuffer[obp++]=(char)0x80; 50 OpBuffer[obp++]=(char)0xCC; 51 OpBuffer[obp++]=(char)0x0C; 48 compiler.codeGenerator.PutOld( 49 (char)0x80, 50 (char)0xCC, 51 (char)0x0C 52 ); 52 53 53 54 //mov word ptr[esp-2],ax 54 OpBuffer[obp++]=(char)0x66; 55 OpBuffer[obp++]=(char)0x89; 56 OpBuffer[obp++]=(char)0x44; 57 OpBuffer[obp++]=(char)0x24; 58 OpBuffer[obp++]=(char)0xFE; 55 compiler.codeGenerator.op_mov_MR( sizeof(short), REG_EAX, REG_ESP, -2, MOD_BASE_DISP8 ); 59 56 60 57 //fldcw word ptr[esp-2] 61 OpBuffer[obp++]=(char)0xD9; 62 OpBuffer[obp++]=(char)0x6C; 63 OpBuffer[obp++]=(char)0x24; 64 OpBuffer[obp++]=(char)0xFE; 58 compiler.codeGenerator.PutOld( 59 (char)0xD9, 60 (char)0x6C, 61 (char)0x24, 62 (char)0xFE 63 ); 65 64 66 65 //fistp dword ptr[esp+4] 67 OpBuffer[obp++]=(char)0xDB; 68 OpBuffer[obp++]=(char)0x5C; 69 OpBuffer[obp++]=(char)0x24; 70 OpBuffer[obp++]=(char)0x04; 66 compiler.codeGenerator.PutOld( 67 (char)0xDB, 68 (char)0x5C, 69 (char)0x24, 70 (char)0x04 71 ); 71 72 72 73 //fldcw word ptr[esp] 73 OpBuffer[obp++]=(char)0xD9; 74 OpBuffer[obp++]=(char)0x2C; 75 OpBuffer[obp++]=(char)0x24; 74 compiler.codeGenerator.PutOld( 75 (char)0xD9, 76 (char)0x2C, 77 (char)0x24 78 ); 76 79 77 80 //add esp,4 … … 86 89 87 90 //fnstcw word ptr[esp] 88 OpBuffer[obp++]=(char)0xD9; 89 OpBuffer[obp++]=(char)0x3C; 90 OpBuffer[obp++]=(char)0x24; 91 compiler.codeGenerator.PutOld( 92 (char)0xD9, 93 (char)0x3C, 94 (char)0x24 95 ); 91 96 92 97 //mov ax,word ptr[esp] 93 OpBuffer[obp++]=(char)0x66; 94 OpBuffer[obp++]=(char)0x8B; 95 OpBuffer[obp++]=(char)0x04; 96 OpBuffer[obp++]=(char)0x24; 98 compiler.codeGenerator.op_mov_RM( sizeof(short), REG_EAX, REG_ESP, 0, MOD_BASE ); 97 99 98 100 //or ah,0Ch 99 OpBuffer[obp++]=(char)0x80; 100 OpBuffer[obp++]=(char)0xCC; 101 OpBuffer[obp++]=(char)0x0C; 101 compiler.codeGenerator.PutOld( 102 (char)0x80, 103 (char)0xCC, 104 (char)0x0C 105 ); 102 106 103 107 //mov word ptr[esp-2],ax 104 OpBuffer[obp++]=(char)0x66; 105 OpBuffer[obp++]=(char)0x89; 106 OpBuffer[obp++]=(char)0x44; 107 OpBuffer[obp++]=(char)0x24; 108 OpBuffer[obp++]=(char)0xFE; 108 compiler.codeGenerator.op_mov_MR( sizeof(short), REG_EAX, REG_ESP, -2, MOD_BASE_DISP8 ); 109 109 110 110 //fldcw word ptr[esp-2] 111 OpBuffer[obp++]=(char)0xD9; 112 OpBuffer[obp++]=(char)0x6C; 113 OpBuffer[obp++]=(char)0x24; 114 OpBuffer[obp++]=(char)0xFE; 111 compiler.codeGenerator.PutOld( 112 (char)0xD9, 113 (char)0x6C, 114 (char)0x24, 115 (char)0xFE 116 ); 115 117 116 118 //fistp dword ptr[esp+4] 117 OpBuffer[obp++]=(char)0xDB; 118 OpBuffer[obp++]=(char)0x5C; 119 OpBuffer[obp++]=(char)0x24; 120 OpBuffer[obp++]=(char)0x04; 119 compiler.codeGenerator.PutOld( 120 (char)0xDB, 121 (char)0x5C, 122 (char)0x24, 123 (char)0x04 124 ); 121 125 122 126 //fldcw word ptr[esp] 123 OpBuffer[obp++]=(char)0xD9; 124 OpBuffer[obp++]=(char)0x2C; 125 OpBuffer[obp++]=(char)0x24; 127 compiler.codeGenerator.PutOld( 128 (char)0xD9, 129 (char)0x2C, 130 (char)0x24 131 ); 126 132 127 133 //add esp,4 … … 307 313 308 314 //mov eax,ProcAddr 309 OpBuffer[obp++]=(char)0xB8; 310 pobj_SubAddrSchedule->add(pUserProc,0); 311 obp+=sizeof(long); 315 compiler.codeGenerator.op_addressof( REG_EAX, pUserProc ); 312 316 } 313 317 -
trunk/abdev/BasicCompiler32/Compile_Object.cpp
r244 r250 89 89 compiler.codeGenerator.op_sub_RV8(REG_EBX,1); 90 90 91 //jnz ↑ 92 OpBuffer[obp++]=(char)0x0F; 93 OpBuffer[obp++]=(char)0x85; 94 *((long *)(OpBuffer+obp))=jnz_back-(obp+sizeof(long)); 95 obp+=sizeof(long); 91 //jne ↑ 92 compiler.codeGenerator.op_jne( jnz_back-obp, sizeof(long), false, true ); 96 93 } 97 94 } … … 293 290 compiler.codeGenerator.op_sub_RV8(REG_EBX,1); 294 291 295 //jnz ↑ 296 OpBuffer[obp++]=(char)0x0F; 297 OpBuffer[obp++]=(char)0x85; 298 *((long *)(OpBuffer+obp))=jnz_back-(obp+sizeof(long)); 299 obp+=sizeof(long); 292 //jne ↑ 293 compiler.codeGenerator.op_jne( jnz_back-obp, sizeof(long), false, true ); 300 294 301 295 -
trunk/abdev/BasicCompiler32/Compile_Statement.cpp
r248 r250 798 798 } 799 799 800 void AddCaseSchedule(void){ 801 extern DWORD *pCaseSchedule; 802 extern int CaseScheduleNum; 803 extern HANDLE hHeap; 804 805 pCaseSchedule=(DWORD *)HeapReAlloc(hHeap,0,pCaseSchedule,(CaseScheduleNum+1)*sizeof(DWORD)); 806 pCaseSchedule[CaseScheduleNum]=obp; 807 CaseScheduleNum++; 808 } 809 810 int CaseTypeSize; 800 //Caseスケジュール 801 class SelectSchedule 802 { 803 public: 804 SelectSchedule( int typeSize ) 805 : typeSize( typeSize ) 806 , nowCaseSchedule( 0 ) 807 { 808 } 809 810 PertialSchedules casePertialSchedules; 811 int typeSize; 812 int nowCaseSchedule; 813 }; 814 std::vector<SelectSchedule> selectSchedules; 815 811 816 void OpcodeSelect(const char *lpszParms){ 812 extern DWORD *pCaseSchedule;813 extern int CaseScheduleNum;814 extern int NowCaseSchedule;815 extern int CaseTypeSize;816 817 extern HANDLE hHeap; 817 818 extern char *basbuf; 818 819 int i,i2,i3,sw,NowCaseCp; 819 820 char temporary[VN_SIZE]; 820 821 DWORD *temp_pCaseSchedule; 822 int temp_CaseScheduleNum; 823 int temp_NowCaseSchedule; 824 int temp_CaseTypeSize; 825 826 temp_pCaseSchedule=pCaseSchedule; 827 temp_CaseScheduleNum=CaseScheduleNum; 828 temp_NowCaseSchedule=NowCaseSchedule; 829 temp_CaseTypeSize=CaseTypeSize; 830 pCaseSchedule=(DWORD *)HeapAlloc(hHeap,0,1); 831 CaseScheduleNum=0; 832 NowCaseSchedule=0; 833 821 834 822 Type type1; 835 823 if( !NumOpe(lpszParms,Type(), type1 ) ){ … … 837 825 } 838 826 839 CaseTypeSize = type1.GetSize(); 840 if( CaseTypeSize < sizeof(long) ){ 841 CaseTypeSize=sizeof(long); 827 selectSchedules.push_back( SelectSchedule( type1.GetSize() ) ); 828 829 if( selectSchedules.back().typeSize < sizeof(long) ){ 830 selectSchedules.back().typeSize = sizeof(long); 842 831 } 843 832 844 833 for(i=cp,sw=0;;i++){ 845 834 if(basbuf[i]=='\0'){ 846 HeapDefaultFree(pCaseSchedule); 847 pCaseSchedule=temp_pCaseSchedule; 848 CaseScheduleNum=temp_CaseScheduleNum; 849 NowCaseSchedule=temp_NowCaseSchedule; 850 CaseTypeSize=temp_CaseTypeSize; 835 selectSchedules.pop_back(); 851 836 SetError(22,"Select",cp); 852 837 return; … … 865 850 if(sw==0){ 866 851 //add esp,CaseTypeSize 867 compiler.codeGenerator.op_add_esp( CaseTypeSize);852 compiler.codeGenerator.op_add_esp( selectSchedules.back().typeSize ); 868 853 } 869 854 break; … … 957 942 958 943 //jne ... 959 OpBuffer[obp++]=(char)0x0F; 960 OpBuffer[obp++]=(char)0x85; 961 AddCaseSchedule(); 962 obp+=sizeof(long); 944 selectSchedules.back().casePertialSchedules.push_back( 945 compiler.codeGenerator.op_jne( 0, sizeof(long), true ) 946 ); 963 947 } 964 948 else if(type1.IsDouble()){ … … 969 953 970 954 //add esp,CaseTypeSize 971 compiler.codeGenerator.op_add_esp( CaseTypeSize);955 compiler.codeGenerator.op_add_esp(selectSchedules.back().typeSize); 972 956 973 957 //fld qword ptr[esp] … … 984 968 985 969 //jne ... 986 OpBuffer[obp++]=(char)0x0F; 987 OpBuffer[obp++]=(char)0x85; 988 AddCaseSchedule(); 989 obp+=sizeof(long); 970 selectSchedules.back().casePertialSchedules.push_back( 971 compiler.codeGenerator.op_jne( 0, sizeof(long), true ) 972 ); 990 973 } 991 974 else if(type1.IsSingle()){ … … 996 979 997 980 //add esp,CaseTypeSize 998 compiler.codeGenerator.op_add_esp( CaseTypeSize);981 compiler.codeGenerator.op_add_esp(selectSchedules.back().typeSize); 999 982 1000 983 //fld dword ptr[esp] … … 1011 994 1012 995 //jne ... 1013 OpBuffer[obp++]=(char)0x0F; 1014 OpBuffer[obp++]=(char)0x85; 1015 AddCaseSchedule(); 1016 obp+=sizeof(long); 996 selectSchedules.back().casePertialSchedules.push_back( 997 compiler.codeGenerator.op_jne( 0, sizeof(long), true ) 998 ); 1017 999 } 1018 1000 else{ … … 1029 1011 1030 1012 //je ... 1031 OpBuffer[obp++]=(char)0x0F; 1032 OpBuffer[obp++]=(char)0x84; 1033 AddCaseSchedule(); 1034 obp+=sizeof(long); 1013 selectSchedules.back().casePertialSchedules.push_back( 1014 compiler.codeGenerator.op_je( 0, sizeof(long), true ) 1015 ); 1035 1016 } 1036 1017 … … 1042 1023 1043 1024 //jmp ... 1044 OpBuffer[obp++]=(char)0xE9;1045 AddCaseSchedule();1046 obp+=sizeof(long);1025 selectSchedules.back().casePertialSchedules.push_back( 1026 compiler.codeGenerator.op_jmp( 0, sizeof(long), true ) 1027 ); 1047 1028 } 1048 1029 } … … 1055 1036 1056 1037 //jmp EndSelect 1057 OpBuffer[obp++]=(char)0xE9;1058 AddCaseSchedule();1059 obp+=sizeof(long);1038 selectSchedules.back().casePertialSchedules.push_back( 1039 compiler.codeGenerator.op_jmp( 0, sizeof(long), true ) 1040 ); 1060 1041 1061 1042 //最終スケジュール 1062 for(i=NowCaseSchedule;i<CaseScheduleNum;i++){ 1063 *(long *)(OpBuffer+pCaseSchedule[i])=obp-(pCaseSchedule[i]+sizeof(long)); 1064 } 1065 HeapDefaultFree(pCaseSchedule); 1043 for(i=selectSchedules.back().nowCaseSchedule;i<(int)selectSchedules.back().casePertialSchedules.size();i++){ 1044 compiler.codeGenerator.opfix_JmpPertialSchedule( selectSchedules.back().casePertialSchedules[i] ); 1045 } 1066 1046 1067 1047 //レキシカルスコープをレベルダウン 1068 1048 compiler.codeGenerator.lexicalScopes.End(); 1069 1049 1070 pCaseSchedule=temp_pCaseSchedule; 1071 CaseScheduleNum=temp_CaseScheduleNum; 1072 NowCaseSchedule=temp_NowCaseSchedule; 1073 CaseTypeSize=temp_CaseTypeSize; 1050 selectSchedules.pop_back(); 1074 1051 } 1075 1052 void OpcodeCase(char *Parameter){ 1076 extern DWORD *pCaseSchedule;1077 extern int NowCaseSchedule;1078 extern int CaseTypeSize;1079 1053 int i; 1080 1054 1081 if( !pCaseSchedule){1055 if(selectSchedules.back().typeSize==-1){ 1082 1056 SetError(30,"Case",cp); 1083 1057 return; … … 1085 1059 1086 1060 //jmp EndSelect 1087 OpBuffer[obp++]=(char)0xE9;1088 AddCaseSchedule();1089 obp+=sizeof(long);1061 selectSchedules.back().casePertialSchedules.push_back( 1062 compiler.codeGenerator.op_jmp( 0, sizeof(long), true ) 1063 ); 1090 1064 1091 1065 i=0; 1092 1066 while(1){ 1093 1067 //Caseスケジュール 1094 *(long *)(OpBuffer+pCaseSchedule[NowCaseSchedule])=obp-(pCaseSchedule[NowCaseSchedule]+sizeof(long));1095 NowCaseSchedule++;1068 compiler.codeGenerator.opfix_JmpPertialSchedule( selectSchedules.back().casePertialSchedules[selectSchedules.back().nowCaseSchedule] ); 1069 selectSchedules.back().nowCaseSchedule++; 1096 1070 1097 1071 i=JumpOneParameter(Parameter,i); … … 1100 1074 1101 1075 //add esp,CaseTypeSize 1102 compiler.codeGenerator.op_add_esp( CaseTypeSize);1076 compiler.codeGenerator.op_add_esp(selectSchedules.back().typeSize); 1103 1077 } 1104 1078 -
trunk/abdev/BasicCompiler32/Compile_Var.cpp
r248 r250 1136 1136 1137 1137 //call FillMemory 1138 OpBuffer[obp++]=(char)0xFF; 1139 OpBuffer[obp++]=(char)0x15; 1140 DllProc *pDllProc = GetDeclareHash("FillMemory"); 1141 pDllProc->Using(); 1142 pobj_ImportAddrSchedule->add(pDllProc); 1143 obp+=sizeof(long); 1138 compiler.codeGenerator.op_call( GetDeclareHash("FillMemory") ); 1144 1139 } 1145 1140 } -
trunk/abdev/BasicCompiler32/Opcode.h
r246 r250 219 219 bool Opcode_CallProcPtr( const char *variable, const char *lpszParms,ProcPointer *pProcPointer); 220 220 bool Opcode_CallProc(const char *Parameter,const UserProc *pUserProc,DWORD dwFlags,const char *ObjectName,int RefType); 221 bool Opcode_CallDllProc( const char *lpszParms, DllProc *pDllProc );221 bool Opcode_CallDllProc( const char *lpszParms, const DllProc *pDllProc ); 222 222 223 223 //Compile_ProcOp.cpp -
trunk/abdev/BasicCompiler32/x86CodeGenerator.cpp
r244 r250 1180 1180 } 1181 1181 void CodeGenerator::op_call(const UserProc *pUserProc){ 1182 pUserProc->Using();1183 1184 1182 pNativeCode->Put( (char)0xE8 ); 1185 1183 pNativeCode->PutUserProcSchedule( pUserProc, true ); 1186 1184 } 1185 void CodeGenerator::op_call( const DllProc *pDllProc ) 1186 { 1187 pNativeCode->Put( (char)0xFF ); 1188 pNativeCode->Put( (char)0x15 ); 1189 pNativeCode->PutDllProcSchedule( pDllProc ); 1190 } 1187 1191 void CodeGenerator::op_ret(){ 1188 1192 pNativeCode->Put( (char)0xC3 );
Note:
See TracChangeset
for help on using the changeset viewer.