Changeset 250 in dev for trunk/abdev/BasicCompiler32/Compile_Statement.cpp
- Timestamp:
- Jul 29, 2007, 9:30:14 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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
Note:
See TracChangeset
for help on using the changeset viewer.