Changeset 254 in dev for trunk/abdev/BasicCompiler64
- Timestamp:
- Jul 31, 2007, 4:30:31 AM (17 years ago)
- Location:
- trunk/abdev/BasicCompiler64
- Files:
-
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/abdev/BasicCompiler64/BasicCompiler.vcproj
r242 r254 317 317 </File> 318 318 <File 319 RelativePath="..\BasicCompiler_Common\include\LexicalScop ingImpl.h"319 RelativePath="..\BasicCompiler_Common\include\LexicalScope.h" 320 320 > 321 321 </File> … … 1124 1124 </File> 1125 1125 <File 1126 RelativePath="..\BasicCompiler_Common\src\LexicalScop ingImpl.cpp"1126 RelativePath="..\BasicCompiler_Common\src\LexicalScope.cpp" 1127 1127 > 1128 1128 </File> -
trunk/abdev/BasicCompiler64/CodeGenerator.cpp
r243 r254 79 79 #define INDEX_NON 0x04 80 80 81 void CodeGenerator::set_mod_rm_sib_disp(char mod,int reg,int scale,int index_reg,int base_reg,long disp, Schedule::Type scheduleType ){ 81 const PertialSchedule *CodeGenerator::set_mod_rm_sib_disp(char mod,int reg,int scale,int index_reg,int base_reg,long disp, Schedule::Type scheduleType, bool isPertialSchedule ) 82 { 83 const PertialSchedule *pPertialSchedule = NULL; 84 82 85 if(mod==MOD_DISP32){ 83 86 //ModR/Mバイト … … 94 97 95 98 //レジスタモードの場合は、ここで終了 96 if(mod==MOD_REG) return ;99 if(mod==MOD_REG) return pPertialSchedule; 97 100 98 101 … … 106 109 107 110 //ディスプレースメントを必要としない場合は、ここで終了 108 if(mod==MOD_BASE) return ;111 if(mod==MOD_BASE) return pPertialSchedule; 109 112 110 113 … … 113 116 ////////////////////////// 114 117 115 if(mod==MOD_BASE_DISP8) pNativeCode->Put( (char)disp ); 116 else{ 118 if(mod==MOD_BASE_DISP8) 119 { 120 pNativeCode->Put( (char)disp ); 121 } 122 else 123 { 124 if( isPertialSchedule ) 125 { 126 pertialSchedules.push_back( new PertialSchedule( pNativeCode->GetSize(), sizeof(long) ) ); 127 pPertialSchedule = pertialSchedules.back(); 128 } 129 117 130 pNativeCode->Put( disp, scheduleType ); 118 131 } 119 } 120 121 122 123 void CodeGenerator::__op_format(int op_size,char op_prefix,char opcode1,char opcode2,int reg,int base_reg,long offset,char mod, Schedule::Type scheduleType ){ 132 133 return pPertialSchedule; 134 } 135 136 137 138 const PertialSchedule *CodeGenerator::__op_format(int op_size,char op_prefix,char opcode1,char opcode2,int reg,int base_reg,long offset,char mod, Schedule::Type scheduleType, bool isPertialSchedule ){ 124 139 //命令プリフィックス 125 140 if(op_prefix) pNativeCode->Put( op_prefix ); … … 133 148 134 149 //ModR/M, SIB, disp 135 set_mod_rm_sib_disp(mod,reg,SCALE_NON,INDEX_NON,base_reg,offset, scheduleType );150 return set_mod_rm_sib_disp(mod,reg,SCALE_NON,INDEX_NON,base_reg,offset, scheduleType, isPertialSchedule ); 136 151 } 137 152 … … 175 190 pNativeCode->Put( i64data ); 176 191 } 177 void CodeGenerator::op_mov_RM(int op_size,int reg,int base_reg,long offset,char mod, Schedule::Type scheduleType ){192 const PertialSchedule *CodeGenerator::op_mov_RM(int op_size,int reg,int base_reg,long offset,char mod, Schedule::Type scheduleType, bool isPertialSchedule ){ 178 193 //mov reg64,qword ptr[base_reg+offset] 179 194 //mov reg32,dword ptr[base_reg+offset] … … 190 205 else opcode=(char)0x8B; 191 206 192 __op_format(op_size,op_prefix,opcode,0,reg,base_reg,offset,mod, scheduleType);193 } 194 void CodeGenerator::op_mov_RM_ex(int op_size,int reg,int base_reg1,int base_reg2,long offset,BOOL bUseOffset, Schedule::Type scheduleType ){207 return __op_format(op_size,op_prefix,opcode,0,reg,base_reg,offset,mod, scheduleType, isPertialSchedule ); 208 } 209 const PertialSchedule *CodeGenerator::op_mov_RM_ex(int op_size,int reg,int base_reg1,int base_reg2,long offset,BOOL bUseOffset, Schedule::Type scheduleType, bool isPertialSchedule ){ 195 210 //mov reg64,qword ptr[base_reg1+base_reg2+offset] 196 211 //mov reg32,dword ptr[base_reg1+base_reg2+offset] 197 212 //mov reg16,word ptr[base_reg1+base_reg2+offset] 198 213 //mov reg8,byte ptr[base_reg1+base_reg2+offset] 214 const PertialSchedule *pPertialSchedule = NULL; 199 215 200 216 if(base_reg1==REG_RSP){ … … 226 242 227 243 //オフセット値 244 if( isPertialSchedule ) 245 { 246 pertialSchedules.push_back( new PertialSchedule( pNativeCode->GetSize(), sizeof(long) ) ); 247 pPertialSchedule = pertialSchedules.back(); 248 } 228 249 pNativeCode->Put( offset, scheduleType ); 229 250 } … … 239 260 pNativeCode->Put( (char)(REGISTER_OPERAND(base_reg1)<<3 | REGISTER_OPERAND(base_reg2)) ); 240 261 } 241 } 242 void CodeGenerator::op_mov_MR(int op_size,int reg,int base_reg,long offset,char mod, Schedule::Type scheduleType ){ 262 263 return pPertialSchedule; 264 } 265 const PertialSchedule *CodeGenerator::op_mov_MR(int op_size,int reg,int base_reg,long offset,char mod, Schedule::Type scheduleType, bool isPertialSchedule ){ 243 266 //mov qword ptr[base_reg+offset],reg64 244 267 //mov dword ptr[base_reg+offset],reg32 … … 255 278 else opcode=(char)0x89; 256 279 257 __op_format(op_size,op_prefix,opcode,0,reg,base_reg,offset,mod, scheduleType );258 } 259 void CodeGenerator::op_mov_MR_ex(int op_size,int reg,int base_reg1,int base_reg2,long offset,BOOL bUseOffset, Schedule::Type scheduleType ){280 return __op_format(op_size,op_prefix,opcode,0,reg,base_reg,offset,mod, scheduleType, isPertialSchedule ); 281 } 282 const PertialSchedule *CodeGenerator::op_mov_MR_ex(int op_size,int reg,int base_reg1,int base_reg2,long offset,BOOL bUseOffset, Schedule::Type scheduleType, bool isPertialSchedule ){ 260 283 //mov qword ptr[base_reg1+base_reg2+offset],reg64 261 284 //mov dword ptr[base_reg1+base_reg2+offset],reg32 262 285 //mov word ptr[base_reg1+base_reg2+offset],reg16 263 286 //mov byte ptr[base_reg1+base_reg2+offset],reg8 287 const PertialSchedule *pPertialSchedule = NULL; 264 288 265 289 if(base_reg1==REG_RSP){ … … 291 315 292 316 //オフセット値 317 if( isPertialSchedule ) 318 { 319 pertialSchedules.push_back( new PertialSchedule( pNativeCode->GetSize(), sizeof(long) ) ); 320 pPertialSchedule = pertialSchedules.back(); 321 } 293 322 pNativeCode->Put( offset, scheduleType ); 294 323 } … … 304 333 pNativeCode->Put( (char)(REGISTER_OPERAND(base_reg1)<<3 | REGISTER_OPERAND(base_reg2)) ); 305 334 } 306 } 307 308 void CodeGenerator::op_mov_MV(int op_size,int base_reg,int offset, Schedule::Type offsetScheduleType, BOOL bUseOffset,long i32data){ 335 336 return pPertialSchedule; 337 } 338 339 const PertialSchedule *CodeGenerator::op_mov_MV(int op_size,int base_reg,int offset, Schedule::Type offsetScheduleType, bool isPertialSchedule, BOOL bUseOffset,long i32data){ 309 340 //mov ptr[base_reg+offset],i32data 310 341 //mov ptr[base_reg ],i32data 342 const PertialSchedule *pPertialSchedule = NULL; 311 343 312 344 //16ビット演算のプリフィックス … … 326 358 327 359 //ModR/M, SIB, disp 328 set_mod_rm_sib_disp(MOD_BASE_DISP32,0,SCALE_NON,INDEX_NON,base_reg,offset, offsetScheduleType );360 pPertialSchedule = set_mod_rm_sib_disp(MOD_BASE_DISP32,0,SCALE_NON,INDEX_NON,base_reg,offset, offsetScheduleType, isPertialSchedule ); 329 361 } 330 362 else{ … … 346 378 pNativeCode->Put( (char)i32data ); 347 379 } 380 381 return pPertialSchedule; 348 382 } 349 383 … … 561 595 ///////////////////// 562 596 563 void CodeGenerator::op_add_RM(int op_size,int reg,int base_reg,int offset,char mod, Schedule::Type scheduleType ){597 const PertialSchedule *CodeGenerator::op_add_RM(int op_size,int reg,int base_reg,int offset,char mod, Schedule::Type scheduleType, bool isPertialSchedule ){ 564 598 //add reg64,qword ptr[base_reg+offset] 565 599 //add reg32,dword ptr[base_reg+offset] … … 576 610 else opcode=(char)0x03; 577 611 578 __op_format(op_size,op_prefix,opcode,0,reg,base_reg,offset,mod, scheduleType );579 } 580 581 void CodeGenerator::op_add_RV(int reg,long offset, Schedule::Type scheduleType ){612 return __op_format(op_size,op_prefix,opcode,0,reg,base_reg,offset,mod, scheduleType, isPertialSchedule ); 613 } 614 615 const PertialSchedule *CodeGenerator::op_add_RV(int reg,long offset, Schedule::Type scheduleType, bool isPertialSchedule ){ 582 616 //add reg,offset 617 const PertialSchedule *pPertialSchedule = NULL; 618 583 619 char RexByte=-1; 584 620 … … 594 630 pNativeCode->Put( (char)RexByte ); 595 631 pNativeCode->Put( (char)0x05 ); 596 pNativeCode->Put( offset, scheduleType );597 632 } 598 633 else{ … … 603 638 pNativeCode->Put( (char)0x81 ); 604 639 pNativeCode->Put( (char)(0xC0| REGISTER_OPERAND(reg)) ); 605 pNativeCode->Put( offset, scheduleType ); 606 } 640 } 641 642 if( isPertialSchedule ) 643 { 644 pertialSchedules.push_back( new PertialSchedule( pNativeCode->GetSize(), sizeof(long) ) ); 645 pPertialSchedule = pertialSchedules.back(); 646 } 647 pNativeCode->Put( offset, scheduleType ); 648 649 return pPertialSchedule; 607 650 } 608 651 void CodeGenerator::op_add_RR(int reg1,int reg2){ … … 1303 1346 //////////////////// 1304 1347 1305 void CodeGenerator::op_movlpd_MR(int xmm_reg,int base_reg,int offset,char mod, Schedule::Type scheduleType ){1348 const PertialSchedule *CodeGenerator::op_movlpd_MR(int xmm_reg,int base_reg,int offset,char mod, Schedule::Type scheduleType, bool isPertialSchedule ){ 1306 1349 //movlpd qword ptr[base_reg+offset],xmm_reg 1307 __op_format(0,(char)0x66,(char)0x0F,(char)0x13,xmm_reg,base_reg,offset,mod, scheduleType );1308 } 1309 void CodeGenerator::op_movlpd_RM(int xmm_reg,int base_reg,int offset,char mod, Schedule::Type scheduleType ){1350 return __op_format(0,(char)0x66,(char)0x0F,(char)0x13,xmm_reg,base_reg,offset,mod, scheduleType, isPertialSchedule ); 1351 } 1352 const PertialSchedule *CodeGenerator::op_movlpd_RM(int xmm_reg,int base_reg,int offset,char mod, Schedule::Type scheduleType, bool isPertialSchedule ){ 1310 1353 //movlpd xmm_reg,qword ptr[base_reg+offset] 1311 __op_format(0,(char)0x66,(char)0x0F,(char)0x12,xmm_reg,base_reg,offset,mod, scheduleType );1354 return __op_format(0,(char)0x66,(char)0x0F,(char)0x12,xmm_reg,base_reg,offset,mod, scheduleType, isPertialSchedule ); 1312 1355 } 1313 1356 void CodeGenerator::op_movsd_RR(int xmm_reg1,int xmm_reg2){ … … 1317 1360 __op_format(0,(char)0xF2,(char)0x0F,(char)0x10,xmm_reg1,xmm_reg2,0,MOD_REG); 1318 1361 } 1319 void CodeGenerator::op_movsd_MR(int xmm_reg,int base_reg,int offset,char mod, Schedule::Type scheduleType ){1362 const PertialSchedule *CodeGenerator::op_movsd_MR(int xmm_reg,int base_reg,int offset,char mod, Schedule::Type scheduleType, bool isPertialSchedule ){ 1320 1363 //movsd qword ptr[reg+offset],xmm_reg 1321 1364 //movsd qword ptr[reg],xmm_reg 1322 __op_format(0,(char)0xF2,(char)0x0F,(char)0x11,xmm_reg,base_reg,offset,mod, scheduleType );1365 return __op_format(0,(char)0xF2,(char)0x0F,(char)0x11,xmm_reg,base_reg,offset,mod, scheduleType, isPertialSchedule ); 1323 1366 } 1324 1367 void CodeGenerator::op_movss_RR(int xmm_reg1,int xmm_reg2){ … … 1328 1371 __op_format(0,(char)0xF3,(char)0x0F,(char)0x10,xmm_reg1,xmm_reg2,0,MOD_REG); 1329 1372 } 1330 void CodeGenerator::op_movss_RM(int xmm_reg,int base_reg,int offset,char mod, Schedule::Type scheduleType ){1373 const PertialSchedule *CodeGenerator::op_movss_RM(int xmm_reg,int base_reg,int offset,char mod, Schedule::Type scheduleType, bool isPertialSchedule ){ 1331 1374 //movss xmm_reg,dword ptr[base_reg+offset] 1332 __op_format(0,(char)0xF3,(char)0x0F,(char)0x10,xmm_reg,base_reg,offset,mod, scheduleType );1333 } 1334 void CodeGenerator::op_movss_MR(int xmm_reg,int base_reg,int offset,char mod, Schedule::Type scheduleType ){1375 return __op_format(0,(char)0xF3,(char)0x0F,(char)0x10,xmm_reg,base_reg,offset,mod, scheduleType, isPertialSchedule ); 1376 } 1377 const PertialSchedule *CodeGenerator::op_movss_MR(int xmm_reg,int base_reg,int offset,char mod, Schedule::Type scheduleType, bool isPertialSchedule ){ 1335 1378 //movss dword ptr[reg+offset],xmm_reg 1336 1379 //movss dword ptr[reg],xmm_reg 1337 __op_format(0,(char)0xF3,(char)0x0F,(char)0x11,xmm_reg,base_reg,offset,mod, scheduleType );1380 return __op_format(0,(char)0xF3,(char)0x0F,(char)0x11,xmm_reg,base_reg,offset,mod, scheduleType, isPertialSchedule ); 1338 1381 } 1339 1382 -
trunk/abdev/BasicCompiler64/Compile_Calc_PushVar.cpp
r242 r254 32 32 (char)0x1C 33 33 ); 34 compiler.codeGenerator.PutOld( 35 (long)pRelativeVar->offset, 36 Schedule::LocalVar 34 compiler.codeGenerator.localVarPertialSchedules.push_back( 35 compiler.codeGenerator.PutOld( (long)pRelativeVar->offset, true ) 37 36 ); 38 37 } 39 38 else{ 40 39 //movlpd xmm_reg,qword ptr[rsp+offset] 41 compiler.codeGenerator.op_movlpd_RM( xmm_reg, REG_RSP, (long)pRelativeVar->offset, MOD_BASE_DISP32, Schedule::LocalVar ); 40 compiler.codeGenerator.localVarPertialSchedules.push_back( 41 compiler.codeGenerator.op_movlpd_RM( xmm_reg, REG_RSP, (long)pRelativeVar->offset, MOD_BASE_DISP32, Schedule::None, true ) 42 ); 42 43 } 43 44 } … … 45 46 if(pRelativeVar->bOffsetOffset){ 46 47 //add r11,qword ptr[rsp+offset] 47 compiler.codeGenerator.op_add_RM(sizeof(_int64),REG_R11,REG_RSP,(int)pRelativeVar->offset,MOD_BASE_DISP32, Schedule::LocalVar ); 48 compiler.codeGenerator.localVarPertialSchedules.push_back( 49 compiler.codeGenerator.op_add_RM(sizeof(_int64),REG_R11,REG_RSP,(int)pRelativeVar->offset,MOD_BASE_DISP32, Schedule::None, true ) 50 ); 48 51 } 49 52 else{ 50 53 //mov r11,qword ptr[rsp+offset] 51 compiler.codeGenerator.op_mov_RM(sizeof(_int64),REG_R11,REG_RSP,(int)pRelativeVar->offset,MOD_BASE_DISP32, Schedule::LocalVar ); 54 compiler.codeGenerator.localVarPertialSchedules.push_back( 55 compiler.codeGenerator.op_mov_RM(sizeof(_int64),REG_R11,REG_RSP,(int)pRelativeVar->offset,MOD_BASE_DISP32, Schedule::None, true ) 56 ); 52 57 } 53 58 … … 85 90 (char)0x1C 86 91 ); 87 compiler.codeGenerator.PutOld( 88 (long)pRelativeVar->offset, 89 Schedule::LocalVar 92 compiler.codeGenerator.localVarPertialSchedules.push_back( 93 compiler.codeGenerator.PutOld( (long)pRelativeVar->offset, true ) 90 94 ); 91 95 } 92 96 else{ 93 97 //movss xmm_reg,dword ptr[rsp+offset] 94 compiler.codeGenerator.op_movss_RM( xmm_reg, REG_RSP, (long)pRelativeVar->offset, MOD_BASE_DISP32, Schedule::LocalVar ); 98 compiler.codeGenerator.localVarPertialSchedules.push_back( 99 compiler.codeGenerator.op_movss_RM( xmm_reg, REG_RSP, (long)pRelativeVar->offset, MOD_BASE_DISP32, Schedule::None, true ) 100 ); 95 101 } 96 102 } … … 98 104 if(pRelativeVar->bOffsetOffset){ 99 105 //add r11,qword ptr[rsp+offset] 100 compiler.codeGenerator.op_add_RM(sizeof(_int64),REG_R11,REG_RSP,(int)pRelativeVar->offset,MOD_BASE_DISP32, Schedule::LocalVar ); 106 compiler.codeGenerator.localVarPertialSchedules.push_back( 107 compiler.codeGenerator.op_add_RM(sizeof(_int64),REG_R11,REG_RSP,(int)pRelativeVar->offset,MOD_BASE_DISP32, Schedule::None, true ) 108 ); 101 109 } 102 110 else{ 103 111 //mov r11,qword ptr[rsp+offset] 104 compiler.codeGenerator.op_mov_RM(sizeof(_int64),REG_R11,REG_RSP,(int)pRelativeVar->offset,MOD_BASE_DISP32, Schedule::LocalVar ); 112 compiler.codeGenerator.localVarPertialSchedules.push_back( 113 compiler.codeGenerator.op_mov_RM(sizeof(_int64),REG_R11,REG_RSP,(int)pRelativeVar->offset,MOD_BASE_DISP32, Schedule::None, true ) 114 ); 105 115 } 106 116 … … 145 155 if(pRelativeVar->bOffsetOffset){ 146 156 //mov reg, ptr[rsp+r11+offset] 147 compiler.codeGenerator.op_mov_RM_ex(varSize,reg,REG_RSP,REG_R11,(int)pRelativeVar->offset,USE_OFFSET, Schedule::LocalVar ); 157 compiler.codeGenerator.localVarPertialSchedules.push_back( 158 compiler.codeGenerator.op_mov_RM_ex(varSize,reg,REG_RSP,REG_R11,(int)pRelativeVar->offset,USE_OFFSET, Schedule::None, true ) 159 ); 148 160 } 149 161 else{ 150 162 //mov reg, ptr[rsp+offset] 151 compiler.codeGenerator.op_mov_RM(varSize,reg,REG_RSP,(int)pRelativeVar->offset,MOD_BASE_DISP32, Schedule::LocalVar ); 163 compiler.codeGenerator.localVarPertialSchedules.push_back( 164 compiler.codeGenerator.op_mov_RM(varSize,reg,REG_RSP,(int)pRelativeVar->offset,MOD_BASE_DISP32, Schedule::None, true ) 165 ); 152 166 } 153 167 } … … 155 169 if(pRelativeVar->bOffsetOffset){ 156 170 //add r11,qword ptr[rsp+offset] 157 compiler.codeGenerator.op_add_RM(sizeof(_int64),REG_R11,REG_RSP,(int)pRelativeVar->offset,MOD_BASE_DISP32, Schedule::LocalVar ); 171 compiler.codeGenerator.localVarPertialSchedules.push_back( 172 compiler.codeGenerator.op_add_RM(sizeof(_int64),REG_R11,REG_RSP,(int)pRelativeVar->offset,MOD_BASE_DISP32, Schedule::None, true ) 173 ); 158 174 } 159 175 else{ 160 176 //mov r11,qword ptr[rsp+offset] 161 compiler.codeGenerator.op_mov_RM(sizeof(_int64),REG_R11,REG_RSP,(int)pRelativeVar->offset,MOD_BASE_DISP32, Schedule::LocalVar ); 177 compiler.codeGenerator.localVarPertialSchedules.push_back( 178 compiler.codeGenerator.op_mov_RM(sizeof(_int64),REG_R11,REG_RSP,(int)pRelativeVar->offset,MOD_BASE_DISP32, Schedule::None, true ) 179 ); 162 180 } 163 181 -
trunk/abdev/BasicCompiler64/Compile_CallProc.cpp
r228 r254 7 7 #include "../BasicCompiler_Common/common.h" 8 8 #include "Opcode.h" 9 10 //ローカル変数アドレススケジュール11 DWORD *pLocalVarAddrSchedule;12 int LocalVarAddrScheduleNum;13 9 14 10 void Call_DebugSys_SaveContext(){ … … 27 23 compiler.codeGenerator.op_call(pSub_DebugSys_SaveContext); 28 24 } 29 30 void AddLocalVarAddrSchedule(){31 extern HANDLE hHeap;32 33 //ローカル変数アドレススケジュールに追加する34 pLocalVarAddrSchedule=(DWORD *)HeapReAlloc(hHeap,0,pLocalVarAddrSchedule,(LocalVarAddrScheduleNum+1)*sizeof(DWORD));35 pLocalVarAddrSchedule[LocalVarAddrScheduleNum]=obp;36 LocalVarAddrScheduleNum++;37 }38 39 25 40 26 bool Opcode_CallProcPtr( const char *variable, const char *lpszParms,ProcPointer *pProcPointer){ -
trunk/abdev/BasicCompiler64/Compile_Object.cpp
r243 r254 173 173 174 174 //mov qword ptr[rax],typeSize(オブジェクトのサイズ) 175 compiler.codeGenerator.op_mov_MV(sizeof(_int64),REG_RAX,0, Schedule::None, NON_OFFSET,typeSize);175 compiler.codeGenerator.op_mov_MV(sizeof(_int64),REG_RAX,0, Schedule::None, false, NON_OFFSET,typeSize); 176 176 177 177 //add rax,PTR_SIZE -
trunk/abdev/BasicCompiler64/Compile_ProcOp.cpp
r242 r254 6 6 #include <Program.h> 7 7 #include <Compiler.h> 8 #include <LexicalScopingImpl.h>9 8 #include <Class.h> 10 9 … … 116 115 UserProc::CompileStartForGlobalArea(); 117 116 118 GetLexicalScopes().CallDestructorsOfScopeEnd();117 compiler.codeGenerator.lexicalScopes.CallDestructorsOfScopeEnd(); 119 118 120 119 UserProc::CompileStartForUserProc( pBackUserProc ); … … 308 307 309 308 //プロシージャ抜け出しスケジュール(Exit Sub/Function) 310 extern DWORD *pExitSubSchedule; 311 extern int ExitSubScheduleNum; 312 pExitSubSchedule=(DWORD *)HeapAlloc(hHeap,0,1); 313 ExitSubScheduleNum=0; 309 compiler.codeGenerator.exitSubCodePositions.clear(); 310 compiler.codeGenerator._exitSubCodePositions_ObpOld.clear(); 314 311 315 312 //ラベル用のメモリを確保 … … 320 317 321 318 //Gotoラベルスケジュール 322 extern GOTOLABELSCHEDULE *pGotoLabelSchedule; 323 extern int GotoLabelScheduleNum; 324 pGotoLabelSchedule=(GOTOLABELSCHEDULE *)HeapAlloc(hHeap,0,1); 325 GotoLabelScheduleNum=0; 319 compiler.codeGenerator.gotoLabelSchedules.clear(); 326 320 327 321 //With情報のメモリを確保 … … 344 338 AllLocalVarSize=0; 345 339 346 //ローカル変数アドレススケジュール347 extern DWORD *pLocalVarAddrSchedule;348 extern int LocalVarAddrScheduleNum;349 pLocalVarAddrSchedule=(DWORD *)HeapAlloc(hHeap,0,1);350 LocalVarAddrScheduleNum=0;351 352 340 //レキシカルスコープ情報を初期化 353 GetLexicalScopes().Init(obp);341 compiler.codeGenerator.lexicalScopes.Init(obp); 354 342 355 343 … … 386 374 387 375 //レキシカルスコープ情報 388 pVar->SetScopeLevel( GetLexicalScopes().GetNowLevel() );389 pVar->SetScopeStartAddress( GetLexicalScopes().GetStartAddress() );376 pVar->SetScopeLevel( compiler.codeGenerator.lexicalScopes.GetNowLevel() ); 377 pVar->SetScopeStartAddress( compiler.codeGenerator.lexicalScopes.GetStartAddress() ); 390 378 pVar->bLiving=TRUE; 391 379 … … 661 649 HeapDefaultFree(pLabelNames); 662 650 663 //Goto未知ラベルスケジュールを解放664 for(i3=0;i3<GotoLabelScheduleNum;i3++){665 if(pGotoLabelSchedule[i3].pName){666 SetError(6,pGotoLabelSchedule[i3].pName,pGotoLabelSchedule[i3].now_cp);667 HeapDefaultFree(pGotoLabelSchedule[i3].pName);668 }669 else{670 sprintf(temporary,"%d",pGotoLabelSchedule[i3].line);671 SetError(6,temporary,pGotoLabelSchedule[i3].now_cp);672 }673 }674 HeapDefaultFree(pGotoLabelSchedule);675 676 651 //With情報のメモリを解放 677 652 for(i3=0;i3<WithInfo.num;i3++){ … … 683 658 684 659 //ローカルオブジェクト(レキシカルスコープレベル=0)の解放処理 685 GetLexicalScopes().CallDestructorsOfScopeEnd();660 compiler.codeGenerator.lexicalScopes.CallDestructorsOfScopeEnd(); 686 661 687 662 //プロシージャ抜け出しスケジュール(Exit Sub/Function) 688 for(i3=0;i3<ExitSubScheduleNum;i3++){ 689 *((long *)(OpBuffer+pExitSubSchedule[i3]))=obp-(pExitSubSchedule[i3]+sizeof(long)); 690 } 691 HeapDefaultFree(pExitSubSchedule); 663 compiler.codeGenerator.ResolveExitSubSchedule(); 692 664 693 665 if(bDebugCompile&&bDebugSupportProc==0){ … … 739 711 740 712 //ローカル変数アドレススケジュール 741 for(i3=0;i3<LocalVarAddrScheduleNum;i3++){ 742 *((long *)(OpBuffer+pLocalVarAddrSchedule[i3])) += AllLocalVarSize + stackFrameSize; 743 } 744 HeapDefaultFree(pLocalVarAddrSchedule); 713 BOOST_FOREACH( const PertialSchedule *pPertialSchedule, compiler.codeGenerator.localVarPertialSchedules ) 714 { 715 compiler.codeGenerator.opfix_offset( pPertialSchedule, AllLocalVarSize ); 716 } 717 compiler.codeGenerator.localVarPertialSchedules.clear(); 745 718 BOOST_FOREACH( Variable *pVar, pUserProc->GetLocalVars() ){ 746 719 //後にデバッグで利用する -
trunk/abdev/BasicCompiler64/Compile_Set_Var.cpp
r242 r254 126 126 (char)0x1C 127 127 ); 128 compiler.codeGenerator.PutOld( 129 (long)pRelative->offset, 130 Schedule::LocalVar 128 compiler.codeGenerator.localVarPertialSchedules.push_back( 129 compiler.codeGenerator.PutOld( (long)pRelative->offset, true ) 131 130 ); 132 131 } 133 132 else{ 134 133 //movsd qword ptr[rsp+offset],xmm0 135 compiler.codeGenerator.op_movsd_MR( REG_XMM0, REG_RSP, (long)pRelative->offset, MOD_BASE_DISP32, Schedule::LocalVar ); 134 compiler.codeGenerator.localVarPertialSchedules.push_back( 135 compiler.codeGenerator.op_movsd_MR( REG_XMM0, REG_RSP, (long)pRelative->offset, MOD_BASE_DISP32, Schedule::None, true ) 136 ); 136 137 } 137 138 } … … 139 140 if(pRelative->bOffsetOffset){ 140 141 //add r11,qword ptr[rsp+offset] 141 compiler.codeGenerator.op_add_RM(sizeof(_int64),REG_R11,REG_RSP,(int)pRelative->offset,MOD_BASE_DISP32, Schedule::LocalVar ); 142 compiler.codeGenerator.localVarPertialSchedules.push_back( 143 compiler.codeGenerator.op_add_RM(sizeof(_int64),REG_R11,REG_RSP,(int)pRelative->offset,MOD_BASE_DISP32, Schedule::None, true ) 144 ); 142 145 } 143 146 else{ 144 147 //mov r11,qword ptr[rsp+offset] 145 compiler.codeGenerator.op_mov_RM(sizeof(_int64),REG_R11,REG_RSP,(int)pRelative->offset,MOD_BASE_DISP32, Schedule::LocalVar ); 148 compiler.codeGenerator.localVarPertialSchedules.push_back( 149 compiler.codeGenerator.op_mov_RM(sizeof(_int64),REG_R11,REG_RSP,(int)pRelative->offset,MOD_BASE_DISP32, Schedule::None, true ) 150 ); 146 151 } 147 152 … … 186 191 (char)0x1C 187 192 ); 188 compiler.codeGenerator.PutOld( 189 (long)pRelative->offset, 190 Schedule::LocalVar 193 compiler.codeGenerator.localVarPertialSchedules.push_back( 194 compiler.codeGenerator.PutOld( (long)pRelative->offset, true ) 191 195 ); 192 196 } 193 197 else{ 194 198 //movss dword ptr[rsp+offset],xmm0 195 compiler.codeGenerator.op_movss_MR( REG_XMM0, REG_RSP, (long)pRelative->offset, MOD_BASE_DISP32, Schedule::LocalVar ); 199 compiler.codeGenerator.localVarPertialSchedules.push_back( 200 compiler.codeGenerator.op_movss_MR( REG_XMM0, REG_RSP, (long)pRelative->offset, MOD_BASE_DISP32, Schedule::None, true ) 201 ); 196 202 } 197 203 } … … 199 205 if(pRelative->bOffsetOffset){ 200 206 //add r11,qword ptr[rsp+offset] 201 compiler.codeGenerator.op_add_RM(sizeof(_int64),REG_R11,REG_RSP,(int)pRelative->offset,MOD_BASE_DISP32, Schedule::LocalVar ); 207 compiler.codeGenerator.localVarPertialSchedules.push_back( 208 compiler.codeGenerator.op_add_RM(sizeof(_int64),REG_R11,REG_RSP,(int)pRelative->offset,MOD_BASE_DISP32, Schedule::None, true ) 209 ); 202 210 } 203 211 else{ 204 212 //mov r11,qword ptr[rsp+offset] 205 compiler.codeGenerator.op_mov_RM(sizeof(_int64),REG_R11,REG_RSP,(int)pRelative->offset,MOD_BASE_DISP32, Schedule::LocalVar ); 213 compiler.codeGenerator.localVarPertialSchedules.push_back( 214 compiler.codeGenerator.op_mov_RM(sizeof(_int64),REG_R11,REG_RSP,(int)pRelative->offset,MOD_BASE_DISP32, Schedule::None, true ) 215 ); 206 216 } 207 217 … … 302 312 if(pRelative->bOffsetOffset){ 303 313 //mov ptr[rsp+r11+offset],rax/eax/ax/al 304 compiler.codeGenerator.op_mov_MR_ex(varSize,REG_RAX,REG_RSP,REG_R11,(int)pRelative->offset,USE_OFFSET, Schedule::LocalVar ); 314 compiler.codeGenerator.localVarPertialSchedules.push_back( 315 compiler.codeGenerator.op_mov_MR_ex(varSize,REG_RAX,REG_RSP,REG_R11,(int)pRelative->offset,USE_OFFSET, Schedule::None, true ) 316 ); 305 317 } 306 318 else{ 307 319 //mov ptr[rsp+offset],rax/eax/ax/al 308 compiler.codeGenerator.op_mov_MR(varSize,REG_RAX,REG_RSP,(int)pRelative->offset,MOD_BASE_DISP32, Schedule::LocalVar ); 320 compiler.codeGenerator.localVarPertialSchedules.push_back( 321 compiler.codeGenerator.op_mov_MR(varSize,REG_RAX,REG_RSP,(int)pRelative->offset,MOD_BASE_DISP32, Schedule::None, true ) 322 ); 309 323 } 310 324 } … … 312 326 if(pRelative->bOffsetOffset){ 313 327 //add r11,qword ptr[rsp+offset] 314 compiler.codeGenerator.op_add_RM( sizeof(_int64), REG_R11, REG_RSP, (int)pRelative->offset, MOD_BASE_DISP32, Schedule::LocalVar ); 328 compiler.codeGenerator.localVarPertialSchedules.push_back( 329 compiler.codeGenerator.op_add_RM( sizeof(_int64), REG_R11, REG_RSP, (int)pRelative->offset, MOD_BASE_DISP32, Schedule::None, true ) 330 ); 315 331 } 316 332 else{ 317 333 //mov r11,qword ptr[rsp+offset] 318 compiler.codeGenerator.op_mov_RM(sizeof(_int64),REG_R11,REG_RSP,(int)pRelative->offset,MOD_BASE_DISP32, Schedule::LocalVar ); 334 compiler.codeGenerator.localVarPertialSchedules.push_back( 335 compiler.codeGenerator.op_mov_RM(sizeof(_int64),REG_R11,REG_RSP,(int)pRelative->offset,MOD_BASE_DISP32, Schedule::None, true ) 336 ); 319 337 } 320 338 -
trunk/abdev/BasicCompiler64/Compile_Statement.cpp
r243 r254 3 3 #include <jenga/include/smoothie/LexicalAnalysis.h> 4 4 5 #include <LexicalScopingImpl.h>6 5 #include <Compiler.h> 7 6 … … 192 191 193 192 //je (endif、または else まで条件ジャンプ) 194 CodeGenerator::PertialSchedule *pIfPertialSchedule = compiler.codeGenerator.op_je( 0, sizeof(long), true );193 const PertialSchedule *pIfPertialSchedule = compiler.codeGenerator.op_je( 0, sizeof(long), true ); 195 194 196 195 … … 200 199 201 200 //レキシカルスコープをレベルアップ 202 GetLexicalScopes().Start( obp,SCOPE_TYPE_IF );201 compiler.codeGenerator.lexicalScopes.Start( obp, LexicalScope::SCOPE_TYPE_IF ); 203 202 204 203 int i2=CompileBuffer(ESC_ENDIF,0); 205 204 206 205 //レキシカルスコープをレベルダウン 207 GetLexicalScopes().End();206 compiler.codeGenerator.lexicalScopes.End(); 208 207 209 208 210 209 if(i2==ESC_ELSE){ 211 210 //jmp (endifまで) 212 CodeGenerator::PertialSchedule *pTempPertialSchedule = compiler.codeGenerator.op_jmp( 0, sizeof(long), true );211 const PertialSchedule *pTempPertialSchedule = compiler.codeGenerator.op_jmp( 0, sizeof(long), true ); 213 212 214 213 compiler.codeGenerator.opfix_JmpPertialSchedule( pIfPertialSchedule ); … … 221 220 222 221 //レキシカルスコープをレベルアップ 223 GetLexicalScopes().Start( obp,SCOPE_TYPE_IF );222 compiler.codeGenerator.lexicalScopes.Start( obp, LexicalScope::SCOPE_TYPE_IF ); 224 223 225 224 CompileBuffer(ESC_ENDIF,0); 226 225 227 226 //レキシカルスコープをレベルダウン 228 GetLexicalScopes().End();227 compiler.codeGenerator.lexicalScopes.End(); 229 228 230 229 … … 259 258 void OpcodeGoto(char *Parameter){ 260 259 extern HANDLE hHeap; 261 extern GOTOLABELSCHEDULE *pGotoLabelSchedule;262 extern int GotoLabelScheduleNum;263 260 int i,LineNum; 264 261 … … 266 263 i=GetLabelAddress(Parameter+1,0); 267 264 268 //jmp ...269 OpBuffer[obp++]=(char)0xE9;270 if(i==-1){271 pGotoLabelSchedule=(GOTOLABELSCHEDULE *)HeapReAlloc(hHeap,0,pGotoLabelSchedule,(GotoLabelScheduleNum+1)*sizeof(GOTOLABELSCHEDULE));272 pGotoLabelSchedule[GotoLabelScheduleNum].pName=(char *)HeapAlloc(hHeap,0,lstrlen(Parameter+1)+1);273 lstrcpy(pGotoLabelSchedule[GotoLabelScheduleNum].pName,Parameter+1);274 pGotoLabelSchedule[GotoLabelScheduleNum].pos=obp;275 pGotoLabelSchedule[GotoLabelScheduleNum].now_cp=cp;276 GotoLabelScheduleNum++;277 }278 *((long *)(OpBuffer+obp))=i-(obp+sizeof(long));279 obp+=sizeof(long);265 if( i == -1 ) 266 { 267 //jmp ...(schedule) 268 extern int obp; 269 compiler.codeGenerator.op_jmp_goto_schedule( (const std::string)(Parameter + 1), 0, cp ); 270 } 271 else 272 { 273 //jmp ... 274 extern int obp; 275 compiler.codeGenerator.op_jmp( i-obp, sizeof(long), false, true ); 276 } 280 277 } 281 278 else{ … … 283 280 i=GetLabelAddress(0,LineNum); 284 281 285 //jmp ...286 OpBuffer[obp++]=(char)0xE9;287 if(i==-1){288 pGotoLabelSchedule=(GOTOLABELSCHEDULE *)HeapReAlloc(hHeap,0,pGotoLabelSchedule,(GotoLabelScheduleNum+1)*sizeof(GOTOLABELSCHEDULE));289 pGotoLabelSchedule[GotoLabelScheduleNum].pName=0;290 pGotoLabelSchedule[GotoLabelScheduleNum].line=LineNum;291 pGotoLabelSchedule[GotoLabelScheduleNum].pos=obp;292 pGotoLabelSchedule[GotoLabelScheduleNum].now_cp=cp;293 GotoLabelScheduleNum++;294 }295 *((long *)(OpBuffer+obp))=i-(obp+sizeof(long));296 obp+=sizeof(long);282 if( i == -1 ) 283 { 284 //jmp ...(schedule) 285 extern int obp; 286 compiler.codeGenerator.op_jmp_goto_schedule( "", LineNum, cp ); 287 } 288 else 289 { 290 //jmp ... 291 extern int obp; 292 compiler.codeGenerator.op_jmp( i-obp, sizeof(long), false, true ); 293 } 297 294 } 298 295 } … … 309 306 310 307 //je (Wend まで) 311 CodeGenerator::PertialSchedule *pWhilePertialSchedule = compiler.codeGenerator.op_je( 0, sizeof(long), true );308 const PertialSchedule *pWhilePertialSchedule = compiler.codeGenerator.op_je( 0, sizeof(long), true ); 312 309 313 310 //レキシカルスコープをレベルアップ 314 GetLexicalScopes().Start( obp,SCOPE_TYPE_WHILE );311 compiler.codeGenerator.lexicalScopes.Start( obp, LexicalScope::SCOPE_TYPE_WHILE ); 315 312 316 313 //While内をコンパイル 317 314 CompileBuffer(0,COM_WEND); 318 315 319 GetLexicalScopes().CallDestructorsOfScopeEnd();316 compiler.codeGenerator.lexicalScopes.CallDestructorsOfScopeEnd(); 320 317 321 318 //jmp ... … … 323 320 324 321 //レキシカルスコープをレベルダウン 325 GetLexicalScopes().End();322 compiler.codeGenerator.lexicalScopes.End(); 326 323 327 324 compiler.codeGenerator.opfix_JmpPertialSchedule( pWhilePertialSchedule ); … … 364 361 365 362 //jmp ... 366 CodeGenerator::PertialSchedule *pTempPertialSchedule = compiler.codeGenerator.op_jmp( 0, sizeof(long), true );363 const PertialSchedule *pTempPertialSchedule = compiler.codeGenerator.op_jmp( 0, sizeof(long), true ); 367 364 368 365 //Continueアドレスのバックアップとセット … … 407 404 408 405 //jmp [カウンタ減少の場合の判定を飛び越す] 409 CodeGenerator::PertialSchedule *pTempPertialSchedule2 = compiler.codeGenerator.op_jmp( 0, sizeof(long), true );406 const PertialSchedule *pTempPertialSchedule2 = compiler.codeGenerator.op_jmp( 0, sizeof(long), true ); 410 407 411 408 //jeジャンプ先のオフセット値 … … 430 427 431 428 //レキシカルスコープをレベルアップ 432 GetLexicalScopes().Start( obp,SCOPE_TYPE_FOR );429 compiler.codeGenerator.lexicalScopes.Start( obp, LexicalScope::SCOPE_TYPE_FOR ); 433 430 434 431 //For内をコンパイル 435 432 CompileBuffer(0,COM_NEXT); 436 433 437 GetLexicalScopes().CallDestructorsOfScopeEnd();434 compiler.codeGenerator.lexicalScopes.CallDestructorsOfScopeEnd(); 438 435 439 436 if(szNextVariable[0]){ … … 447 444 448 445 //レキシカルスコープをレベルダウン 449 GetLexicalScopes().End();446 compiler.codeGenerator.lexicalScopes.End(); 450 447 451 448 //jeジャンプ先のオフセット値 … … 466 463 467 464 //レキシカルスコープをレベルアップ 468 GetLexicalScopes().Start( obp,SCOPE_TYPE_DO );465 compiler.codeGenerator.lexicalScopes.Start( obp, LexicalScope::SCOPE_TYPE_DO ); 469 466 470 467 //Do内をコンパイル 471 468 CompileBuffer(0,COM_LOOP); 472 469 473 GetLexicalScopes().CallDestructorsOfScopeEnd();474 475 CodeGenerator::PertialSchedule *pDoPertialSchedule = NULL;470 compiler.codeGenerator.lexicalScopes.CallDestructorsOfScopeEnd(); 471 472 const PertialSchedule *pDoPertialSchedule = NULL; 476 473 477 474 extern char *basbuf; … … 522 519 523 520 //jmp ... 524 CodeGenerator::PertialSchedule *pTempPertialSchedule = compiler.codeGenerator.op_jmp( 0, sizeof(long), true );521 const PertialSchedule *pTempPertialSchedule = compiler.codeGenerator.op_jmp( 0, sizeof(long), true ); 525 522 526 523 //レキシカルスコープをレベルダウン 527 GetLexicalScopes().End();524 compiler.codeGenerator.lexicalScopes.End(); 528 525 529 526 //jmpジャンプ先のオフセット値 … … 539 536 540 537 void OpcodeExitSub(void){ 541 extern DWORD *pExitSubSchedule;542 extern int ExitSubScheduleNum;543 extern HANDLE hHeap;544 545 538 if( UserProc::IsGlobalAreaCompiling() ){ 546 539 SetError(12,"Exit Sub/Function",cp); … … 549 542 550 543 //未解放のローカルオブジェクトのデストラクタを呼び出す 551 GetLexicalScopes().CallDestructorsOfReturn();544 compiler.codeGenerator.lexicalScopes.CallDestructorsOfReturn(); 552 545 553 546 //jmp ...(End Sub/Function) 554 OpBuffer[obp++]=(char)0xE9; 555 556 pExitSubSchedule=(DWORD *)HeapReAlloc(hHeap,0,pExitSubSchedule,(ExitSubScheduleNum+1)*sizeof(DWORD)); 557 pExitSubSchedule[ExitSubScheduleNum]=obp; 558 ExitSubScheduleNum++; 559 560 obp+=sizeof(long); 561 } 562 563 void AddCaseSchedule(void){ 564 extern DWORD *pCaseSchedule; 565 extern int CaseScheduleNum; 566 extern HANDLE hHeap; 567 568 pCaseSchedule=(DWORD *)HeapReAlloc(hHeap,0,pCaseSchedule,(CaseScheduleNum+1)*sizeof(DWORD)); 569 pCaseSchedule[CaseScheduleNum]=obp; 570 CaseScheduleNum++; 571 } 547 compiler.codeGenerator.op_jmp_exitsub(); 548 } 549 550 //Caseスケジュール 551 class SelectSchedule 552 { 553 public: 554 SelectSchedule( int typeSize ) 555 : typeSize( typeSize ) 556 , nowCaseSchedule( 0 ) 557 { 558 } 559 560 PertialSchedules casePertialSchedules; 561 int typeSize; 562 int nowCaseSchedule; 563 }; 564 std::vector<SelectSchedule> selectSchedules; 565 572 566 void OpcodeSelect( const char *lpszParms ){ 573 extern DWORD *pCaseSchedule;574 extern int CaseScheduleNum;575 extern int NowCaseSchedule;576 567 extern HANDLE hHeap; 577 568 extern char *basbuf; 578 569 int i,i2,i3,NowCaseCp; 579 570 char temporary[VN_SIZE]; 580 581 DWORD *temp_pCaseSchedule; 582 int temp_CaseScheduleNum; 583 int temp_NowCaseSchedule; 584 585 temp_pCaseSchedule=pCaseSchedule; 586 temp_CaseScheduleNum=CaseScheduleNum; 587 temp_NowCaseSchedule=NowCaseSchedule; 588 pCaseSchedule=(DWORD *)HeapAlloc(hHeap,0,1); 589 CaseScheduleNum=0; 590 NowCaseSchedule=0; 591 571 592 572 int reg1=REG_RAX; 593 573 Type type1; … … 596 576 } 597 577 578 selectSchedules.push_back( SelectSchedule( type1.GetSize() ) ); 579 580 if( selectSchedules.back().typeSize < sizeof(long) ){ 581 selectSchedules.back().typeSize = sizeof(long); 582 } 583 598 584 if(type1.IsDouble()){ 599 585 //movsd qword ptr[rsp+offset],xmm_reg ※スタックフレームを利用 … … 613 599 for(i=cp;;i++){ 614 600 if(basbuf[i]=='\0'){ 615 HeapDefaultFree(pCaseSchedule); 616 pCaseSchedule=temp_pCaseSchedule; 617 CaseScheduleNum=temp_CaseScheduleNum; 618 NowCaseSchedule=temp_NowCaseSchedule; 601 selectSchedules.pop_back(); 619 602 SetError(22,"Select",cp); 620 603 return; … … 718 701 719 702 //jne ... 720 OpBuffer[obp++]=(char)0x0F; 721 OpBuffer[obp++]=(char)0x85; 703 selectSchedules.back().casePertialSchedules.push_back( 704 compiler.codeGenerator.op_jne( 0, sizeof(long), true ) 705 ); 722 706 } 723 707 else{ … … 759 743 760 744 //je ... 761 OpBuffer[obp++]=(char)0x0F; 762 OpBuffer[obp++]=(char)0x84; 745 selectSchedules.back().casePertialSchedules.push_back( 746 compiler.codeGenerator.op_je( 0, sizeof(long), true ) 747 ); 763 748 } 764 AddCaseSchedule();765 obp+=sizeof(long);766 749 767 750 if(basbuf[i]!=',') break; … … 770 753 if(basbuf[i]==1&&basbuf[i+1]==ESC_CASEELSE){ 771 754 //jmp ... 772 OpBuffer[obp++]=(char)0xE9;773 AddCaseSchedule();774 obp+=sizeof(long);755 selectSchedules.back().casePertialSchedules.push_back( 756 compiler.codeGenerator.op_jmp( 0, sizeof(long), true ) 757 ); 775 758 } 776 759 } … … 780 763 781 764 //レキシカルスコープをレベルアップ 782 GetLexicalScopes().Start( obp,SCOPE_TYPE_SELECT );765 compiler.codeGenerator.lexicalScopes.Start( obp, LexicalScope::SCOPE_TYPE_SELECT ); 783 766 784 767 //Select Case内をコンパイル … … 786 769 787 770 //jmp EndSelect 788 OpBuffer[obp++]=(char)0xE9;789 AddCaseSchedule();790 obp+=sizeof(long);771 selectSchedules.back().casePertialSchedules.push_back( 772 compiler.codeGenerator.op_jmp( 0, sizeof(long), true ) 773 ); 791 774 792 775 //最終スケジュール 793 for(i=NowCaseSchedule;i<CaseScheduleNum;i++){ 794 *(long *)(OpBuffer+pCaseSchedule[i])=obp-(pCaseSchedule[i]+sizeof(long)); 795 } 796 HeapDefaultFree(pCaseSchedule); 776 for(i=selectSchedules.back().nowCaseSchedule;i<(int)selectSchedules.back().casePertialSchedules.size();i++){ 777 compiler.codeGenerator.opfix_JmpPertialSchedule( selectSchedules.back().casePertialSchedules[i] ); 778 } 797 779 798 780 //レキシカルスコープをレベルダウン 799 GetLexicalScopes().End(); 800 801 pCaseSchedule=temp_pCaseSchedule; 802 CaseScheduleNum=temp_CaseScheduleNum; 803 NowCaseSchedule=temp_NowCaseSchedule; 781 compiler.codeGenerator.lexicalScopes.End(); 782 783 selectSchedules.pop_back(); 804 784 } 805 785 void OpcodeCase(char *Parameter){ 806 extern DWORD *pCaseSchedule;807 extern int NowCaseSchedule;808 786 int i; 809 787 810 if( !pCaseSchedule){788 if(selectSchedules.back().typeSize==-1){ 811 789 SetError(30,"Case",cp); 812 790 return; … … 814 792 815 793 //jmp EndSelect 816 OpBuffer[obp++]=(char)0xE9;817 AddCaseSchedule();818 obp+=sizeof(long);794 selectSchedules.back().casePertialSchedules.push_back( 795 compiler.codeGenerator.op_jmp( 0, sizeof(long), true ) 796 ); 819 797 820 798 i=0; 821 799 while(1){ 822 800 //Caseスケジュール 823 *(long *)(OpBuffer+pCaseSchedule[NowCaseSchedule])=obp-(pCaseSchedule[NowCaseSchedule]+sizeof(long));824 NowCaseSchedule++;801 compiler.codeGenerator.opfix_JmpPertialSchedule( selectSchedules.back().casePertialSchedules[selectSchedules.back().nowCaseSchedule] ); 802 selectSchedules.back().nowCaseSchedule++; 825 803 826 804 i=JumpOneParameter(Parameter,i); … … 830 808 831 809 void OpcodeGosub(char *Parameter){ 832 extern HANDLE hHeap;833 extern GOTOLABELSCHEDULE *pGotoLabelSchedule;834 extern int GotoLabelScheduleNum;835 int i,LineNum;836 837 //call _System_GetEip838 extern const UserProc *pSub_System_GetEip;839 compiler.codeGenerator.op_call(pSub_System_GetEip);840 841 //add rax,offset(Gosubステートメントの最終ポイント)842 int schedule=obp,schedule2;843 compiler.codeGenerator.op_add_RV(REG_RAX,0);844 schedule2=obp-sizeof(long);845 846 //※戻り先用のrip847 //mov qword ptr[rsp+offset],rax ※スタックフレームを利用848 pobj_sf->push(REG_RAX);849 850 851 if(Parameter[0]=='*'){852 i=GetLabelAddress(Parameter+1,0);853 854 //jmp ...855 OpBuffer[obp++]=(char)0xE9;856 if(i==-1){857 pGotoLabelSchedule=(GOTOLABELSCHEDULE *)HeapReAlloc(hHeap,0,pGotoLabelSchedule,(GotoLabelScheduleNum+1)*sizeof(GOTOLABELSCHEDULE));858 pGotoLabelSchedule[GotoLabelScheduleNum].pName=(char *)HeapAlloc(hHeap,0,lstrlen(Parameter+1)+1);859 lstrcpy(pGotoLabelSchedule[GotoLabelScheduleNum].pName,Parameter+1);860 pGotoLabelSchedule[GotoLabelScheduleNum].pos=obp;861 pGotoLabelSchedule[GotoLabelScheduleNum].now_cp=cp;862 GotoLabelScheduleNum++;863 }864 *((long *)(OpBuffer+obp))=i-(obp+sizeof(long));865 obp+=sizeof(long);866 }867 else{868 LineNum=atoi(Parameter);869 i=GetLabelAddress(0,LineNum);870 871 //jmp ...872 OpBuffer[obp++]=(char)0xE9;873 if(i==-1){874 pGotoLabelSchedule=(GOTOLABELSCHEDULE *)HeapReAlloc(hHeap,0,pGotoLabelSchedule,(GotoLabelScheduleNum+1)*sizeof(GOTOLABELSCHEDULE));875 pGotoLabelSchedule[GotoLabelScheduleNum].pName=0;876 pGotoLabelSchedule[GotoLabelScheduleNum].line=LineNum;877 pGotoLabelSchedule[GotoLabelScheduleNum].pos=obp;878 pGotoLabelSchedule[GotoLabelScheduleNum].now_cp=cp;879 GotoLabelScheduleNum++;880 }881 *((long *)(OpBuffer+obp))=i-(obp+sizeof(long));882 obp+=sizeof(long);883 }884 885 *((long *)(OpBuffer+schedule2))=obp-schedule;886 887 //※スタックフレームを元に戻す888 pobj_sf->pop(REG_NON);889 890 810 SetError(-1,"Gosub ~ Returnステートメントは64ビットコンパイラで利用することはできません。",cp); 891 811 } -
trunk/abdev/BasicCompiler64/Compile_Var.cpp
r243 r254 4 4 #include <jenga/include/smoothie/LexicalAnalysis.h> 5 5 6 #include <LexicalScopingImpl.h>7 6 #include <CodeGenerator.h> 8 7 #include <Compiler.h> … … 989 988 990 989 //mov qword ptr[rsp+offset],rax 991 compiler.codeGenerator.op_mov_MR(sizeof(_int64),REG_RAX,REG_RSP,offset,MOD_BASE_DISP32); 992 obp-=sizeof(long); 993 AddLocalVarAddrSchedule(); 994 obp+=sizeof(long); 990 compiler.codeGenerator.localVarPertialSchedules.push_back( 991 compiler.codeGenerator.op_mov_MR(sizeof(_int64),REG_RAX,REG_RSP,offset,MOD_BASE_DISP32, Schedule::None, true ) 992 ); 995 993 } 996 994 else if( type.IsSingle() ){ … … 999 997 1000 998 //mov dword ptr[rsp+offset],value 1001 compiler.codeGenerator.op_mov_MV(sizeof(long),REG_RSP,offset, Schedule::LocalVar, USE_OFFSET,*(int *)&flt); 999 compiler.codeGenerator.localVarPertialSchedules.push_back( 1000 compiler.codeGenerator.op_mov_MV(sizeof(long),REG_RSP,offset, Schedule::None, true, USE_OFFSET,*(int *)&flt) 1001 ); 1002 1002 } 1003 1003 else if( type.Is64() || type.IsPointer() ){ … … 1014 1014 1015 1015 //mov qword ptr[rsp+offset],rax 1016 compiler.codeGenerator.op_mov_MR(sizeof(_int64),REG_RAX,REG_RSP,offset,MOD_BASE_DISP32, Schedule::LocalVar ); 1016 compiler.codeGenerator.localVarPertialSchedules.push_back( 1017 compiler.codeGenerator.op_mov_MR(sizeof(_int64),REG_RAX,REG_RSP,offset,MOD_BASE_DISP32, Schedule::None, true ) 1018 ); 1017 1019 } 1018 1020 else{ … … 1022 1024 1023 1025 //mov qword ptr[rsp+offset],rax 1024 compiler.codeGenerator.op_mov_MR(sizeof(_int64),REG_RAX,REG_RSP,offset,MOD_BASE_DISP32, Schedule::LocalVar ); 1026 compiler.codeGenerator.localVarPertialSchedules.push_back( 1027 compiler.codeGenerator.op_mov_MR(sizeof(_int64),REG_RAX,REG_RSP,offset,MOD_BASE_DISP32, Schedule::None, true ) 1028 ); 1025 1029 } 1026 1030 else{ 1027 1031 //mov qword ptr[rsp+offset],value 1028 compiler.codeGenerator.op_mov_MV(sizeof(_int64),REG_RSP,offset, Schedule::LocalVar, USE_OFFSET,(int)i64data); 1032 compiler.codeGenerator.localVarPertialSchedules.push_back( 1033 compiler.codeGenerator.op_mov_MV(sizeof(_int64),REG_RSP,offset, Schedule::None, true, USE_OFFSET,(int)i64data) 1034 ); 1029 1035 } 1030 1036 } … … 1032 1038 else if( type.IsDWord() || type.IsLong() ){ 1033 1039 //mov dword ptr[rsp+offset],value 1034 compiler.codeGenerator.op_mov_MV(sizeof(long),REG_RSP,offset, Schedule::LocalVar,USE_OFFSET,(int)i64data); 1040 compiler.codeGenerator.localVarPertialSchedules.push_back( 1041 compiler.codeGenerator.op_mov_MV(sizeof(long),REG_RSP,offset, Schedule::None, true, USE_OFFSET,(int)i64data) 1042 ); 1035 1043 } 1036 1044 else if( type.IsWord() || type.IsInteger() ){ 1037 1045 //mov word ptr[rsp+offset],value 1038 compiler.codeGenerator.op_mov_MV(sizeof(short),REG_RSP,offset, Schedule::LocalVar,USE_OFFSET,(int)i64data); 1046 compiler.codeGenerator.localVarPertialSchedules.push_back( 1047 compiler.codeGenerator.op_mov_MV(sizeof(short),REG_RSP,offset, Schedule::None, true, USE_OFFSET,(int)i64data) 1048 ); 1039 1049 } 1040 1050 else if( type.IsSByte() || type.IsByte() || type.IsBoolean() ){ 1041 1051 //mov byte ptr[rsp+offset],value 1042 compiler.codeGenerator.op_mov_MV(sizeof(char),REG_RSP,offset, Schedule::LocalVar,USE_OFFSET,(int)i64data); 1052 compiler.codeGenerator.localVarPertialSchedules.push_back( 1053 compiler.codeGenerator.op_mov_MV(sizeof(char),REG_RSP,offset, Schedule::None, true, USE_OFFSET,(int)i64data) 1054 ); 1043 1055 } 1044 1056 return true; … … 1074 1086 1075 1087 //レキシカルスコープ 1076 pVar->SetScopeLevel( GetLexicalScopes().GetNowLevel() );1077 pVar->SetScopeStartAddress( GetLexicalScopes().GetStartAddress() );1088 pVar->SetScopeLevel( compiler.codeGenerator.lexicalScopes.GetNowLevel() ); 1089 pVar->SetScopeStartAddress( compiler.codeGenerator.lexicalScopes.GetStartAddress() ); 1078 1090 pVar->bLiving=TRUE; 1079 1091 … … 1109 1121 1110 1122 //レキシカルスコープ 1111 pVar->SetScopeLevel( GetLexicalScopes().GetNowLevel() );1112 pVar->SetScopeStartAddress( GetLexicalScopes().GetStartAddress() );1123 pVar->SetScopeLevel( compiler.codeGenerator.lexicalScopes.GetNowLevel() ); 1124 pVar->SetScopeStartAddress( compiler.codeGenerator.lexicalScopes.GetStartAddress() ); 1113 1125 pVar->bLiving=TRUE; 1114 1126 … … 1151 1163 1152 1164 //add rcx, offset 1153 compiler.codeGenerator.op_add_RV( REG_RCX, -pVar->GetOffsetAddress() ); 1154 obp-=sizeof(long); 1155 AddLocalVarAddrSchedule(); 1156 obp+=sizeof(long); 1165 compiler.codeGenerator.localVarPertialSchedules.push_back( 1166 compiler.codeGenerator.op_add_RV( REG_RCX, -pVar->GetOffsetAddress(), Schedule::None, true ) 1167 ); 1157 1168 1158 1169 //call FillMemory … … 1217 1228 if(pRelativeVar->bOffsetOffset){ 1218 1229 //add r11,offset 1219 compiler.codeGenerator.op_add_RV( REG_R11, (long)pRelativeVar->offset, Schedule::LocalVar ); 1230 compiler.codeGenerator.localVarPertialSchedules.push_back( 1231 compiler.codeGenerator.op_add_RV( REG_R11, (long)pRelativeVar->offset, Schedule::None, true ) 1232 ); 1220 1233 1221 1234 //add r11,rsp … … 1230 1243 1231 1244 //add reg,offset 1232 compiler.codeGenerator.op_add_RV(reg,(long)pRelativeVar->offset, Schedule::LocalVar ); 1245 compiler.codeGenerator.localVarPertialSchedules.push_back( 1246 compiler.codeGenerator.op_add_RV(reg,(long)pRelativeVar->offset, Schedule::None, true ) 1247 ); 1233 1248 } 1234 1249 } … … 1236 1251 if(pRelativeVar->bOffsetOffset){ 1237 1252 //add r11,qword ptr[rsp+offset] 1238 compiler.codeGenerator.op_add_RM( sizeof(_int64), REG_R11, REG_RSP, (long)pRelativeVar->offset, MOD_BASE_DISP32, Schedule::LocalVar ); 1253 compiler.codeGenerator.localVarPertialSchedules.push_back( 1254 compiler.codeGenerator.op_add_RM( sizeof(_int64), REG_R11, REG_RSP, (long)pRelativeVar->offset, MOD_BASE_DISP32, Schedule::None, true ) 1255 ); 1239 1256 } 1240 1257 else{ 1241 1258 //mov r11,qword ptr[rsp+offset] 1242 compiler.codeGenerator.op_mov_RM(sizeof(_int64),REG_R11,REG_RSP,(int)pRelativeVar->offset,MOD_BASE_DISP32, Schedule::LocalVar ); 1259 compiler.codeGenerator.localVarPertialSchedules.push_back( 1260 compiler.codeGenerator.op_mov_RM(sizeof(_int64),REG_R11,REG_RSP,(int)pRelativeVar->offset,MOD_BASE_DISP32, Schedule::None, true ) 1261 ); 1243 1262 } 1244 1263 -
trunk/abdev/BasicCompiler64/MakePeHdr.cpp
r242 r254 5 5 #include <jenga/include/smoothie/Smoothie.h> 6 6 7 #include <LexicalScopingImpl.h>8 7 #include <Class.h> 9 8 #include <Compiler.h> … … 334 333 335 334 //レキシカルスコープ情報を初期化 336 GetLexicalScopes().Init(obp);335 compiler.codeGenerator.lexicalScopes.Init(obp); 337 336 338 337 … … 369 368 370 369 //Gotoラベルスケジュール 371 extern GOTOLABELSCHEDULE *pGotoLabelSchedule; 372 extern int GotoLabelScheduleNum; 373 pGotoLabelSchedule=(GOTOLABELSCHEDULE *)HeapAlloc(hHeap,0,1); 374 GotoLabelScheduleNum=0; 370 compiler.codeGenerator.gotoLabelSchedules.clear(); 375 371 376 372 //With情報のメモリを確保 … … 424 420 HeapDefaultFree(pLabelNames); 425 421 426 //Goto未知ラベルスケジュール を解放427 for(i=0;i<GotoLabelScheduleNum;i++){428 if(pGotoLabelSchedule[i].pName){429 SetError(6,pGotoLabelSchedule[i].pName,pGotoLabelSchedule[i].now_cp);430 HeapDefaultFree(pGotoLabelSchedule[i].pName);422 //Goto未知ラベルスケジュールが存在したらエラーにする 423 BOOST_FOREACH( const GotoLabelSchedule *pGotoLabelSchedule, compiler.codeGenerator.gotoLabelSchedules ) 424 { 425 if(pGotoLabelSchedule->GetName().size()>0){ 426 SetError(6,pGotoLabelSchedule->GetName(),pGotoLabelSchedule->GetSourceCodePos()); 431 427 } 432 428 else{ 433 sprintf(temporary,"%d",pGotoLabelSchedule [i].line);434 SetError(6,temporary,pGotoLabelSchedule [i].now_cp);429 sprintf(temporary,"%d",pGotoLabelSchedule->GetLineNum()); 430 SetError(6,temporary,pGotoLabelSchedule->GetSourceCodePos()); 435 431 } 436 432 } 437 HeapDefaultFree(pGotoLabelSchedule);438 433 439 434 -
trunk/abdev/BasicCompiler64/NumOpe.cpp
r242 r254 533 533 } 534 534 535 if(expression[0]==1&& expression[1]==ESC_NEW ){536 //New演算子(オブジェクト生成)537 538 if( pobj_BlockReg->check(REG_RAX) ){539 SetError();540 }541 542 //////////////////////////////////////////////////////543 ///// レジスタ資源のバックアップ544 { BACKUP_REGISTER_RESOURCE545 //////////////////////////////////////////////////////546 547 if( !Operator_New( expression+2, baseType, resultType ) ){548 return false;549 }550 551 /////////////////////////////////////////////552 ////// レジスタ資源を復元553 RESTORE_REGISTER_RESOURCE554 }////////////////////////////////////////////555 556 //mov reg,rax557 compiler.codeGenerator.op_mov_RR( *pReg, REG_RAX );558 559 return true;560 }561 562 535 if( !baseType.IsNull() && expression[0] == '[' ){ 563 536 // リテラル配列の場合 … … 608 581 609 582 resultType = baseType; 583 584 return true; 585 } 586 587 bool isLiteralCalculation; 588 if( !NumOpe_GetType( expression, baseType, resultType, &isLiteralCalculation ) ) 589 { 590 return false; 591 } 592 if( isLiteralCalculation ) 593 { 594 //右辺値が数値の定数式の場合 595 _int64 i64data; 596 StaticCalculation(true, expression,baseType.GetBasicType(),&i64data,resultType); 597 598 if(resultType.IsReal()){ 599 if(baseType.IsReal()) resultType=baseType; 600 601 int xmmReg = REG_XMM0; 602 603 if(resultType.IsDouble()){ 604 i3 = compiler.GetDataTable().Add( i64data ); 605 606 //movlpd xmm_reg,qword ptr[data table offset] 607 compiler.codeGenerator.op_movlpd_RM( xmmReg, 0, i3, MOD_DISP32, Schedule::DataTable ); 608 } 609 if(resultType.IsSingle()){ 610 double dbl; 611 memcpy(&dbl,&i64data,sizeof(_int64)); 612 613 float flt; 614 int i32data; 615 flt=(float)dbl; 616 memcpy(&i32data,&flt,sizeof(long)); 617 618 i3 = compiler.GetDataTable().Add( i32data ); 619 620 //movss xmm_reg,dword ptr[data table offset] 621 compiler.codeGenerator.op_movss_RM( xmmReg, 0, i3, MOD_DISP32, Schedule::DataTable ); 622 } 623 } 624 else{ 625 if(!resultType.Is64()){ 626 //整数(符号有り/無し) 627 628 i3=(long)i64data; 629 630 if(resultType.GetBasicSize()==sizeof(char)) i3=i3&0x000000FF; 631 if(resultType.GetBasicSize()==sizeof(short)) i3=i3&0x0000FFFF; 632 633 i64data=(_int64)i3; 634 } 635 636 //mov reg,i64data 637 compiler.codeGenerator.op_mov_RV64(*pReg,i64data); 638 } 639 return true; 640 } 641 642 if(expression[0]==1&& expression[1]==ESC_NEW ){ 643 //New演算子(オブジェクト生成) 644 645 if( pobj_BlockReg->check(REG_RAX) ){ 646 SetError(); 647 } 648 649 ////////////////////////////////////////////////////// 650 ///// レジスタ資源のバックアップ 651 { BACKUP_REGISTER_RESOURCE 652 ////////////////////////////////////////////////////// 653 654 if( !Operator_New( expression+2, baseType, resultType ) ){ 655 return false; 656 } 657 658 ///////////////////////////////////////////// 659 ////// レジスタ資源を復元 660 RESTORE_REGISTER_RESOURCE 661 }//////////////////////////////////////////// 662 663 //mov reg,rax 664 compiler.codeGenerator.op_mov_RR( *pReg, REG_RAX ); 610 665 611 666 return true; -
trunk/abdev/BasicCompiler64/Opcode.h
r226 r254 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 … … 339 331 340 332 //Compile_CallProc.cpp 341 void AddLocalVarAddrSchedule();342 333 #define PROCFLAG_NEW 1 343 334 bool Opcode_CallProcPtr(const char *variable, const char *lpszParms,ProcPointer *pProcPointer);
Note:
See TracChangeset
for help on using the changeset viewer.