Changeset 255 in dev for trunk/abdev/BasicCompiler64
- Timestamp:
- Aug 1, 2007, 3:37:09 AM (17 years ago)
- Location:
- trunk/abdev/BasicCompiler64
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/abdev/BasicCompiler64/CodeGenerator.cpp
r254 r255 1599 1599 } 1600 1600 } 1601 void CodeGenerator::op_sub_rsp(long num){ 1601 const PertialSchedule *CodeGenerator::op_sub_rsp( long num, bool isPertialSchedule ) 1602 { 1602 1603 //スタックポインタの減算(push方向) 1604 const PertialSchedule *pPertialSchedule = NULL; 1603 1605 1604 1606 //sub rsp,num 1605 if( 0xFFFFFF80&num){1607 if( (0xFFFFFF80&num) != 0 || isPertialSchedule ){ 1606 1608 pNativeCode->Put( (char)0x48 ); 1607 1609 pNativeCode->Put( (char)0x81 ); 1608 1610 pNativeCode->Put( (char)0xEC ); 1611 1612 if( isPertialSchedule ) 1613 { 1614 pertialSchedules.push_back( new PertialSchedule( pNativeCode->GetSize(), sizeof(long) ) ); 1615 pPertialSchedule = pertialSchedules.back(); 1616 } 1609 1617 pNativeCode->Put( num ); 1610 1618 } … … 1616 1624 pNativeCode->Put( (char)num ); 1617 1625 } 1618 } 1619 1620 1621 void CodeGenerator::op_add_esp(long num){ 1622 //スタックポインタの加算(pop方向) 1623 1624 //add esp,num 1625 if(0xFFFFFF80&num){ 1626 pNativeCode->Put( (char)0x81 ); 1627 pNativeCode->Put( (char)0xC4 ); 1628 pNativeCode->Put( num ); 1629 } 1630 else{ 1631 //「-128 < num < 127」の場合 1632 pNativeCode->Put( (char)0x83 ); 1633 pNativeCode->Put( (char)0xC4 ); 1634 pNativeCode->Put( (char)num ); 1635 } 1636 } 1637 void CodeGenerator::op_sub_esp(long num){ 1638 //スタックポインタの減算(push方向) 1639 1640 //sub esp,num 1641 if(0xFFFFFF80&num){ 1642 pNativeCode->Put( (char)0x81 ); 1643 pNativeCode->Put( (char)0xEC ); 1644 pNativeCode->Put( num ); 1645 } 1646 else{ 1647 //「-128 < num < 127」の場合 1648 pNativeCode->Put( (char)0x83 ); 1649 pNativeCode->Put( (char)0xEC ); 1650 pNativeCode->Put( (char)num ); 1651 } 1626 1627 return pPertialSchedule; 1652 1628 } 1653 1629 -
trunk/abdev/BasicCompiler64/Compile_Object.cpp
r254 r255 86 86 87 87 //jnz ↑ 88 OpBuffer[obp++]=(char)0x0F; 89 OpBuffer[obp++]=(char)0x85; 90 *((long *)(OpBuffer+obp))=jnz_back-(obp+sizeof(long)); 91 obp+=sizeof(long); 88 compiler.codeGenerator.op_jne( jnz_back-obp, sizeof(long), false, true ); 92 89 } 93 90 } … … 286 283 287 284 //jnz ↑ 288 OpBuffer[obp++]=(char)0x0F; 289 OpBuffer[obp++]=(char)0x85; 290 *((long *)(OpBuffer+obp))=jnz_back-(obp+sizeof(long)); 291 obp+=sizeof(long); 285 compiler.codeGenerator.op_jne( jnz_back-obp, sizeof(long), false, true ); 292 286 293 287 -
trunk/abdev/BasicCompiler64/Compile_ProcOp.cpp
r254 r255 39 39 40 40 //sub rsp,スタックフレームサイズ 41 int StackFrameSchedule; 42 compiler.codeGenerator.op_sub_rsp(0xFFFFFFFF); 43 StackFrameSchedule=obp-sizeof(long); 41 const PertialSchedule *pStackFramePertialSchedule = compiler.codeGenerator.op_sub_rsp( 0, true ); 44 42 45 43 extern BOOL bDebugCompile; … … 65 63 66 64 //スタックフレームスケジュール(subコマンドに渡す値) 67 *((long *)(OpBuffer+StackFrameSchedule))=pobj_sf->GetFrameSize(0);65 compiler.codeGenerator.opfix( pStackFramePertialSchedule, pobj_sf->GetFrameSize(0) ); 68 66 69 67 UserProc::CompileStartForUserProc( pBackUserProc ); … … 77 75 78 76 //sub rsp,スタックフレームサイズ 79 int StackFrameSchedule; 80 compiler.codeGenerator.op_sub_rsp(0xFFFFFFFF); 81 StackFrameSchedule=obp-sizeof(long); 77 const PertialSchedule *pStackFramePertialSchedule = compiler.codeGenerator.op_sub_rsp( 0, true ); 82 78 83 79 BOOST_FOREACH( Variable *pVar, compiler.GetMeta().GetGlobalVars() ){ … … 102 98 103 99 //スタックフレームスケジュール(subコマンドに渡す値) 104 *((long *)(OpBuffer+StackFrameSchedule))=pobj_sf->GetFrameSize(0);100 compiler.codeGenerator.opfix( pStackFramePertialSchedule, pobj_sf->GetFrameSize(0) ); 105 101 106 102 //ret … … 135 131 //ret 136 132 compiler.codeGenerator.op_ret(); 137 }138 else if( userProc.GetName() == "_allrem" ){139 //乗除演算用の特殊関数(64ビット整数対応)140 BYTE Buffer_allrem[]={141 0x53,0x57,0x33,0xFF,0x8B,0x44,0x24,0x10,0x0B,0xC0,0x7D,0x14,0x47,0x8B,0x54,0x24,0x0C,0xF7,0xD8,0xF7,0xDA,0x83,0xD8,0x00,0x89,0x44,0x24,0x10,0x89,0x54,0x24,0x0C,0x8B,0x44,0x24,0x18,0x0B,0xC0,0x7D,0x13,0x8B,0x54,0x24,0x14,0xF7,0xD8,0xF7,0xDA,0x83,0xD8,0x00,0x89,0x44,0x24,0x18,0x89,0x54,0x24,0x14,0x0B,0xC0,0x75,0x1B,0x8B,0x4C,0x24,0x14,0x8B,0x44,0x24,0x10,0x33,0xD2,0xF7,0xF1,0x8B,0x44,0x24,0x0C,0xF7,0xF1,0x8B,0xC2,0x33,0xD2,0x4F,0x79,0x4E,0xEB,0x53,0x8B,0xD8,0x8B,0x4C,0x24,0x14,0x8B,0x54,0x24,0x10,0x8B,0x44,0x24,0x0C,0xD1,0xEB,0xD1,0xD9,0xD1,0xEA,0xD1,0xD8,0x0B,0xDB,0x75,0xF4,0xF7,0xF1,0x8B,0xC8,0xF7,0x64,0x24,0x18,0x91,0xF7,0x64,0x24,0x14,0x03,0xD1,0x72,0x0E,0x3B,0x54,0x24,0x10,0x77,0x08,0x72,0x0E,0x3B,0x44,0x24,0x0C,0x76,0x08,0x2B,0x44,0x24,0x14,0x1B,0x54,0x24,0x18,0x2B,0x44,0x24,0x0C,0x1B,0x54,0x24,0x10,0x4F,0x79,0x07,0xF7,0xDA,0xF7,0xD8,0x83,0xDA,0x00,0x5F,0x5B,0xC2,0x10,0x00142 };143 144 memcpy(OpBuffer+obp,Buffer_allrem,178);145 obp+=178;146 }147 else if( userProc.GetName() == "_allmul" ){148 //乗算用の特殊関数(64ビット整数対応)149 BYTE Buffer_allmul[]={150 0x8B,0x44,0x24,0x08,0x8B,0x4C,0x24,0x10,0x0B,0xC8,0x8B,0x4C,0x24,0x0C,0x75,0x09,0x8B,0x44,0x24,0x04,0xF7,0xE1,0xC2,0x10,0x00,0x53,0xF7,0xE1,0x8B,0xD8,0x8B,0x44,0x24,0x08,0xF7,0x64,0x24,0x14,0x03,0xD8,0x8B,0x44,0x24,0x08,0xF7,0xE1,0x03,0xD3,0x5B,0xC2,0x10,0x00151 };152 153 memcpy(OpBuffer+obp,Buffer_allmul,52);154 obp+=52;155 }156 else if( userProc.GetName() == "_alldiv" ){157 //除算用の特殊関数(64ビット整数対応)158 BYTE Buffer_alldiv[]={159 0x57,0x56,0x53,0x33,0xFF,0x8B,0x44,0x24,0x14,0x0B,0xC0,0x7D,0x14,0x47,0x8B,0x54,0x24,0x10,0xF7,0xD8,0xF7,0xDA,0x83,0xD8,0x00,0x89,0x44,0x24,0x14,0x89,0x54,0x24,0x10,0x8B,0x44,0x24,0x1C,0x0B,0xC0,0x7D,0x14,0x47,0x8B,0x54,0x24,0x18,0xF7,0xD8,0xF7,0xDA,0x83,0xD8,0x00,0x89,0x44,0x24,0x1C,0x89,0x54,0x24,0x18,0x0B,0xC0,0x75,0x18,0x8B,0x4C,0x24,0x18,0x8B,0x44,0x24,0x14,0x33,0xD2,0xF7,0xF1,0x8B,0xD8,0x8B,0x44,0x24,0x10,0xF7,0xF1,0x8B,0xD3,0xEB,0x41,0x8B,0xD8,0x8B,0x4C,0x24,0x18,0x8B,0x54,0x24,0x14,0x8B,0x44,0x24,0x10,0xD1,0xEB,0xD1,0xD9,0xD1,0xEA,0xD1,0xD8,0x0B,0xDB,0x75,0xF4,0xF7,0xF1,0x8B,0xF0,0xF7,0x64,0x24,0x1C,0x8B,0xC8,0x8B,0x44,0x24,0x18,0xF7,0xE6,0x03,0xD1,0x72,0x0E,0x3B,0x54,0x24,0x14,0x77,0x08,0x72,0x07,0x3B,0x44,0x24,0x10,0x76,0x01,0x4E,0x33,0xD2,0x8B,0xC6,0x4F,0x75,0x07,0xF7,0xDA,0xF7,0xD8,0x83,0xDA,0x00,0x5B,0x5E,0x5F,0xC2,0x10,0x00160 };161 162 memcpy(OpBuffer+obp,Buffer_alldiv,170);163 obp+=170;164 }165 else if( userProc.GetName() == "_allshl" ){166 //符号あり左ビットシフト用の特殊関数(64ビット整数対応)167 BYTE Buffer_allshl[]={168 0x80,0xF9,0x40,0x73,0x15,0x80,0xF9,0x20,0x73,0x06,0x0F,0xA5,0xC2,0xD3,0xE0,0xC3,0x8B,0xD0,0x33,0xC0,0x80,0xE1,0x1F,0xD3,0xE2,0xC3,0x33,0xC0,0x33,0xD2,0xC3169 };170 171 memcpy(OpBuffer+obp,Buffer_allshl,31);172 obp+=31;173 }174 else if( userProc.GetName() == "_allshr" ){175 //符号あり右ビットシフト用の特殊関数(64ビット整数対応)176 BYTE Buffer_allshr[]={177 0x80,0xF9,0x40,0x73,0x16,0x80,0xF9,0x20,0x73,0x06,0x0F,0xAD,0xD0,0xD3,0xFA,0xC3,0x8B,0xC2,0xC1,0xFA,0x1F,0x80,0xE1,0x1F,0xD3,0xF8,0xC3,0xC1,0xFA,0x1F,0x8B,0xC2,0xC3178 };179 180 memcpy(OpBuffer+obp,Buffer_allshr,33);181 obp+=33;182 }183 else if( userProc.GetName() == "_aullshr" ){184 //符号なし右ビットシフト用の特殊関数(64ビット整数対応)185 BYTE Buffer_aullshr[]={186 0x80,0xF9,0x40, //cmp cl,40h187 0x73,0x15, //jae RETZERO (0040d71a)188 0x80,0xF9,0x20, //cmp cl,20h189 0x73,0x06, //jae MORE32 (0040d710)190 0x0F,0xAD,0xD0, //shrd eax,edx,cl191 0xD3,0xEA, //shr edx,cl192 0xC3, //ret193 //MORE32:194 0x8B,0xC2, //mov eax,edx195 0x33,0xD2, //xor edx,edx196 0x80,0xE1,0x1F, //and cl,1Fh197 0xD3,0xE8, //shr eax,cl198 0xC3, //ret199 //RETZERO:200 0x33,0xC0, //xor eax,eax201 0x33,0xD2, //xor edx,edx202 0xC3 //ret203 };204 205 memcpy(OpBuffer+obp,Buffer_aullshr,31);206 obp+=31;207 133 } 208 134 else{ … … 441 367 442 368 //sub rsp,スタックフレームサイズ 443 int StackFrameSchedule; 444 compiler.codeGenerator.op_sub_rsp(0xFFFFFFFF); 445 StackFrameSchedule=obp-sizeof(long); 369 const PertialSchedule *pStackFramePertialSchedule = compiler.codeGenerator.op_sub_rsp( 0, true ); 446 370 447 371 //mov qword ptr[rsp+offset],reg ※スタックフレームを利用 … … 482 406 } 483 407 484 int RspOffsetSchedule=0;485 int RspOffsetSchedule2;408 const PertialSchedule *pRspOffsetPertialSchedule1 = NULL; 409 const PertialSchedule *pRspOffsetPertialSchedule2 = NULL; 486 410 if(bDebugCompile&&bDebugSupportProc==0){ 487 411 //mov rdx, qword ptr[rsp+スタックフレームサイズ] 488 compiler.codeGenerator.op_mov_RM(sizeof(_int64),REG_RDX,REG_RSP,0,MOD_BASE_DISP32); 489 RspOffsetSchedule=obp-sizeof(long); 412 pRspOffsetPertialSchedule1 = compiler.codeGenerator.op_mov_RM(sizeof(_int64),REG_RDX,REG_RSP,0,MOD_BASE_DISP32, Schedule::None, true ); 490 413 491 414 //mov rcx,rsp … … 493 416 494 417 //add rcx,スタックフレームサイズ+sizeof(_int64) ※ret用のサイズを考慮 495 compiler.codeGenerator.op_add_RV(REG_RCX,0); 496 RspOffsetSchedule2=obp-sizeof(long); 418 pRspOffsetPertialSchedule2 = compiler.codeGenerator.op_add_RV(REG_RCX,0, Schedule::None, true ); 497 419 498 420 //call _DebugSys_StartProc … … 713 635 BOOST_FOREACH( const PertialSchedule *pPertialSchedule, compiler.codeGenerator.localVarPertialSchedules ) 714 636 { 715 compiler.codeGenerator.opfix_offset( pPertialSchedule, AllLocalVarSize );637 compiler.codeGenerator.opfix_offset( pPertialSchedule, AllLocalVarSize + stackFrameSize ); 716 638 } 717 639 compiler.codeGenerator.localVarPertialSchedules.clear(); … … 742 664 743 665 //デバッグ用 744 if( RspOffsetSchedule){745 *((long *)(OpBuffer+RspOffsetSchedule))=stackFrameAndLocalParamSize;746 *((long *)(OpBuffer+RspOffsetSchedule2))=stackFrameAndLocalParamSize+sizeof(_int64);666 if( pRspOffsetPertialSchedule1 ){ 667 compiler.codeGenerator.opfix( pRspOffsetPertialSchedule1, stackFrameAndLocalParamSize ); 668 compiler.codeGenerator.opfix( pRspOffsetPertialSchedule2, stackFrameAndLocalParamSize + sizeof(_int64) ); 747 669 } 748 670 749 671 750 672 //スタックフレームスケジュール(subコマンド) 751 *((long *)(OpBuffer+StackFrameSchedule))=stackFrameAndLocalParamSize;673 compiler.codeGenerator.opfix( pStackFramePertialSchedule, stackFrameAndLocalParamSize ); 752 674 753 675 //スタックフレームスケジュールを実行 -
trunk/abdev/BasicCompiler64/MakePeHdr.cpp
r254 r255 393 393 394 394 //sub rsp,スタックフレームサイズ 395 int StackFrameSchedule; 396 compiler.codeGenerator.op_sub_rsp(0xFFFFFFFF); 397 StackFrameSchedule=obp-sizeof(long); 395 const PertialSchedule *pStackFramePertialSchedule = compiler.codeGenerator.op_sub_rsp( 0, true ); 398 396 399 397 if(bDebugCompile){ … … 457 455 458 456 //スタックフレームスケジュール(subコマンドに渡す値) 459 *((long *)(OpBuffer+StackFrameSchedule)) = stackFrameSize;457 compiler.codeGenerator.opfix( pStackFramePertialSchedule, stackFrameSize ); 460 458 461 459 //スタックフレームスケジュールを実行 -
trunk/abdev/BasicCompiler64/NumOpe.cpp
r254 r255 519 519 } 520 520 521 bool NumOpe( int *pReg,521 bool _numope( int *pReg, 522 522 const char *expression, 523 523 const Type &baseType, 524 524 Type &resultType, 525 BOOL *pbUseHeap ){ 525 BOOL *pbUseHeap ) 526 { 526 527 527 528 int i,i2,i3; … … 684 685 685 686 686 BOOL bInitRegSwitch=0;687 if(!pobj_reg){688 bInitRegSwitch=1;689 690 //作業用レジスタを取得691 pobj_reg=new CRegister(*pReg);692 }693 694 //エラー時の復旧用695 CRegister objReg_Backup;696 objReg_Backup=*pobj_reg;697 698 699 687 700 688 //////////////////////////////// … … 707 695 //リテラル値のみの計算かどうかを判別するためのフラグ 708 696 BOOL bLiteralCalculation=1; 709 710 //リテラル演算の場合を考慮した演算前のバッファ位置711 int BeforeObp;712 BeforeObp=obp;713 714 //リテラル演算の場合を考慮した演算前のプロシージャスケジュール位置715 //※64ビットの掛け算、除算などで特殊関数が呼ばれるため716 int Before_ProcAddrScheduleNum;717 Before_ProcAddrScheduleNum=pobj_SubAddrSchedule->num;718 719 //リテラル演算の場合を考慮した演算前のデータテーブルスケジュール位置720 int Before_DataTableScheduleNum;721 Before_DataTableScheduleNum=pobj_DataTableSchedule->num;722 723 //リテラル演算の場合を考慮した演算前の再配置スケジュール724 CReloc *pobj_BackReloc;725 pobj_BackReloc=new CReloc();726 pobj_BackReloc->copy(pobj_Reloc);727 728 //リテラル演算の場合を考慮した演算前のスタックフレームスケジュール位置729 int Before_StackFrameScheduleNum;730 Before_StackFrameScheduleNum=pobj_sf->num;731 697 732 698 double dbl; … … 1164 1130 1165 1131 if(bLiteralCalculation){ 1166 //右辺値が数値の定数式の場合 1167 Type resultType; 1168 StaticCalculation(true, expression,baseType.GetBasicType(),&i64data,resultType); 1169 1170 obp=BeforeObp; 1171 pobj_SubAddrSchedule->num=Before_ProcAddrScheduleNum; 1172 pobj_DataTableSchedule->num=Before_DataTableScheduleNum; 1173 pobj_Reloc->copy(pobj_BackReloc); 1174 pobj_sf->num=Before_StackFrameScheduleNum; 1175 *pobj_reg=objReg_Backup; 1176 1177 if(resultType.IsReal()){ 1178 if(baseType.IsReal()) resultType=baseType; 1179 1180 XmmReg=pobj_reg->LockXmmReg(); 1181 1182 if(resultType.IsDouble()){ 1183 i3 = compiler.GetDataTable().Add( i64data ); 1184 1185 //movlpd xmm_reg,qword ptr[data table offset] 1186 compiler.codeGenerator.op_movlpd_RM( XmmReg, 0, i3, MOD_DISP32, Schedule::DataTable ); 1187 } 1188 if(resultType.IsSingle()){ 1189 memcpy(&dbl,&i64data,sizeof(_int64)); 1190 1191 float flt; 1192 int i32data; 1193 flt=(float)dbl; 1194 memcpy(&i32data,&flt,sizeof(long)); 1195 1196 i3 = compiler.GetDataTable().Add( i32data ); 1197 1198 //movss xmm_reg,dword ptr[data table offset] 1199 compiler.codeGenerator.op_movss_RM( XmmReg, 0, i3, MOD_DISP32, Schedule::DataTable ); 1200 } 1201 } 1202 else{ 1203 if(!resultType.Is64()){ 1204 //整数(符号有り/無し) 1205 1206 i3=(long)i64data; 1207 1208 if(resultType.GetBasicSize()==sizeof(char)) i3=i3&0x000000FF; 1209 if(resultType.GetBasicSize()==sizeof(short)) i3=i3&0x0000FFFF; 1210 1211 i64data=(_int64)i3; 1212 } 1213 1214 UseReg=pobj_reg->LockReg(); 1215 1216 //mov reg,i64data 1217 compiler.codeGenerator.op_mov_RV64(UseReg,i64data); 1218 } 1219 1220 type_stack[0]=resultType.GetBasicType(); 1221 index_stack[0]=resultType.GetIndex(); 1132 SetError(); 1222 1133 } 1223 1134 else{ … … 1234 1145 1235 1146 1147 resultType.SetType( type_stack[0], index_stack[0] ); 1148 1149 bool isSuccessful = true; 1150 goto finish; 1151 1152 1153 1154 ////////////////// 1155 // エラー処理 1156 ////////////////// 1157 1158 error: 1159 1160 isSuccessful = false; 1161 goto finish; 1162 1163 1164 1165 1166 finish: 1167 1168 for(i=0;i<pnum;i++){ 1169 if(values[i]) HeapDefaultFree(values[i]); 1170 } 1171 1172 return isSuccessful; 1173 } 1174 1175 bool NumOpe( int *pReg, 1176 const char *expression, 1177 const Type &baseType, 1178 Type &resultType, 1179 BOOL *pbUseHeap ) 1180 { 1181 BOOL bInitRegSwitch=0; 1182 if(!pobj_reg){ 1183 bInitRegSwitch=1; 1184 1185 //作業用レジスタを取得 1186 pobj_reg=new CRegister(*pReg); 1187 } 1188 1189 //エラー時の復旧用 1190 CRegister objReg_Backup; 1191 objReg_Backup=*pobj_reg; 1192 1193 *pReg = pobj_reg->GetNextReg(); 1194 1195 1196 bool result = _numope( pReg, expression, baseType, resultType, pbUseHeap ); 1197 1198 1199 if( !result ) 1200 { 1201 *pobj_reg=objReg_Backup; 1202 } 1203 1236 1204 if(bInitRegSwitch){ 1237 1205 //整合性をチェック(バグ回避) 1238 pobj_reg->bug_check(); 1206 if( result ) 1207 { 1208 pobj_reg->bug_check(); 1209 } 1239 1210 1240 1211 //作業レジスタを解放 … … 1243 1214 } 1244 1215 1245 resultType.SetType( type_stack[0], index_stack[0] ); 1246 1247 bool isSuccessful = true; 1248 goto finish; 1249 1250 1251 1252 ////////////////// 1253 // エラー処理 1254 ////////////////// 1255 1256 error: 1257 1258 *pobj_reg=objReg_Backup; 1259 1260 if(bInitRegSwitch){ 1261 //作業レジスタを解放 1262 delete pobj_reg; 1263 pobj_reg=0; 1264 } 1265 1266 isSuccessful = false; 1267 goto finish; 1268 1269 1270 1271 1272 finish: 1273 1274 for(i=0;i<pnum;i++){ 1275 if(values[i]) HeapDefaultFree(values[i]); 1276 } 1277 1278 //再配置スケジュールバックアップ情報を解放 1279 delete pobj_BackReloc; 1280 1281 return isSuccessful; 1216 return result; 1282 1217 } -
trunk/abdev/BasicCompiler64/Opcode.h
r254 r255 19 19 extern char *OpBuffer; 20 20 21 #define breakpoint OpBuffer[obp++]=(char)0xCC;21 #define breakpoint compiler.codeGenerator.PutOld( (char)0xCC ); 22 22 23 23
Note:
See TracChangeset
for help on using the changeset viewer.