Changeset 282 in dev for trunk/abdev/BasicCompiler_Common
- Timestamp:
- Aug 14, 2007, 11:57:32 PM (17 years ago)
- Location:
- trunk/abdev/BasicCompiler_Common
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/abdev/BasicCompiler_Common/include/Class.h
r272 r282 360 360 int GetFuncNumInVtbl( const UserProc *pUserProc ) const; 361 361 LONG_PTR GetVtblGlobalOffset(void) const; 362 void GenerateVTables(); 362 363 void ActionVtblSchedule(LONG_PTR ImageBase, LONG_PTR MemPos_CodeSection); 363 364 bool IsAbstract() const; … … 387 388 virtual void CollectClassesForNameOnly( const BasicSource &source ); 388 389 390 void GenerateVTables(); 389 391 void ActionVtblSchedule(LONG_PTR ImageBase, LONG_PTR MemPos_CodeSection); 390 392 -
trunk/abdev/BasicCompiler_Common/include/CodeGenerator.h
r276 r282 448 448 void op_ret( short stackFrameSize ); 449 449 void op_addressof( int reg, const UserProc *pUserProc ); 450 void op_mov_RV_vtbl( int reg, const CClass *pClass ); 450 451 #endif 451 452 -
trunk/abdev/BasicCompiler_Common/include/Linker.h
r273 r282 34 34 void ResolveGlobalVarSchedules( long rwSectionBaseOffset ); 35 35 36 // vtblスケジュール 37 void ResolveVtblSchedule( long dataSectionBaseOffset ); 38 36 39 // リンク 37 40 void Link( ObjectModule &masterObjectModule ); -
trunk/abdev/BasicCompiler_Common/include/NativeCode.h
r280 r282 21 21 AddressOf, // ユーザ定義関数位置スケジュール 22 22 DllProc, // DLL関数位置スケジュール 23 Vtbl, // vtblスケジュール 23 24 }; 24 25 … … 31 32 const ::UserProc *pUserProc; 32 33 const ::DllProc *pDllProc; 34 const ::CClass *pClass; 33 35 }; 34 36 … … 52 54 ar & boost::serialization::make_nvp("pDllProc", const_cast<::DllProc *&>(pDllProc)); 53 55 break; 56 case Vtbl: 57 ar & boost::serialization::make_nvp("pClass", const_cast<::CClass *&>(pClass)); 58 break; 54 59 default: 55 60 ar & BOOST_SERIALIZATION_NVP( lpValue ); … … 80 85 { 81 86 } 87 Schedule( const ::CClass *pClass, long offset ) 88 : type( Schedule::Vtbl ) 89 , offset( offset ) 90 , pClass( pClass ) 91 { 92 } 82 93 ~Schedule() 83 94 { … … 111 122 } 112 123 return *pUserProc; 124 } 125 const ::CClass &GetClass() const 126 { 127 if( type != Schedule::Vtbl ) 128 { 129 SetError(); 130 } 131 return *pClass; 113 132 } 114 133 … … 360 379 void PutUserProcSchedule( const UserProc *pUserProc, bool isCall ); 361 380 void PutDllProcSchedule( const DllProc *pDllProc ); 381 void PutVtblSchedule( const CClass *pClass ); 362 382 void Put( short s ) 363 383 { -
trunk/abdev/BasicCompiler_Common/include/Source.h
r281 r282 176 176 bool isEqualBasbuf = false; 177 177 extern char *basbuf; 178 if( basbuf == buffer )178 if( basbuf == buffer + 2 ) 179 179 { 180 180 isEqualBasbuf = true; -
trunk/abdev/BasicCompiler_Common/src/Class.cpp
r276 r282 720 720 return vtbl_offset; 721 721 } 722 void CClass::GenerateVTables() 723 { 724 if( IsAbstract() ) 725 { 726 // 抽象クラスは無視 727 return; 728 } 729 if( !IsUsing() ) 730 { 731 // 使われていないクラスは無視 732 return; 733 } 734 735 const UserProc **ppsi; 736 ppsi=(const UserProc **)malloc(GetVtblNum()*sizeof(UserProc *)); 737 738 //関数テーブルに値をセット 739 int i2 = 0; 740 BOOST_FOREACH( const CMethod *pMethod, methods ){ 741 if(pMethod->IsVirtual()){ 742 if( !pMethod->GetUserProc().IsUsing() ) 743 { 744 ts((char *)pMethod->GetUserProc().GetFullName().c_str()); 745 } 746 pMethod->GetUserProc().Using(); 747 748 if(pMethod->IsAbstract()){ 749 extern int cp; 750 SmoothieException::Throw(300,NULL,cp); 751 752 ppsi[i2]=0; 753 } 754 else{ 755 ppsi[i2]=&pMethod->GetUserProc(); 756 } 757 i2++; 758 } 759 } 760 761 vtbl_offset=compiler.GetObjectModule().dataTable.AddBinary((void *)ppsi,GetVtblNum()*sizeof(LONG_PTR)); 762 763 for( int i=0; i < GetVtblNum(); i++ ){ 764 pobj_Reloc->AddSchedule_DataSection(vtbl_offset+i*sizeof(LONG_PTR)); 765 } 766 767 free(ppsi); 768 } 722 769 void CClass::ActionVtblSchedule(LONG_PTR ImageBase, LONG_PTR MemPos_CodeSection){ 770 if( IsAbstract() ) 771 { 772 // 抽象クラスは無視 773 return; 774 } 775 if( !IsUsing() ) 776 { 777 // 使われていないクラスは無視 778 return; 779 } 723 780 if(vtbl_offset==-1) return; 724 781 … … 731 788 pUserProc=(UserProc *)pVtbl[i]; 732 789 if(!pUserProc) continue; 790 791 if( pUserProc->GetBeginOpAddress() == 0 792 && pUserProc->GetEndOpAddress() == 0 ) 793 { 794 Jenga::Throw( "未解決の仮想関数が存在する" ); 795 } 733 796 734 797 pVtbl[i]=pUserProc->GetBeginOpAddress()+ImageBase+MemPos_CodeSection; … … 908 971 } 909 972 } 973 } 974 } 975 976 void Classes::GenerateVTables() 977 { 978 Iterator_Reset(); 979 while( Iterator_HasNext() ) 980 { 981 CClass *pClass = Iterator_GetNext(); 982 pClass->GenerateVTables(); 910 983 } 911 984 } … … 1615 1688 pParentClass->Using(); 1616 1689 1690 // 仮想関数になるメソッドに使用チェックをつける 1691 BOOST_FOREACH( const CMethod *pMethod, pParentClass->GetMethods() ) 1692 { 1693 if( pMethod->IsVirtual() ) 1694 { 1695 pMethod->GetUserProc().Using(); 1696 } 1697 } 1698 1617 1699 pCompilingMethod = pParentClass->GetMethods().GetMethodPtr( pUserProc ); 1618 1700 if( !pCompilingMethod ){ -
trunk/abdev/BasicCompiler_Common/src/Linker.cpp
r276 r282 102 102 } 103 103 104 void Linker::ResolveVtblSchedule( long dataSectionBaseOffset ) 105 { 106 BOOST_FOREACH( const Schedule &schedule, nativeCode.GetSchedules() ) 107 { 108 if( schedule.GetType() == Schedule::Vtbl ) 109 { 110 LONG_PTR vtblAddress = schedule.GetClass().GetVtblGlobalOffset(); 111 112 nativeCode.Overwrite( 113 schedule.GetOffset(), 114 static_cast<long>( vtblAddress + imageBase + dataSectionBaseOffset ) 115 ); 116 } 117 } 118 } 119 104 120 void Linker::Link( ObjectModule &masterObjectModule ) 105 121 { -
trunk/abdev/BasicCompiler_Common/src/NativeCode.cpp
r280 r282 64 64 } 65 65 66 void NativeCode::PutVtblSchedule( const CClass *pClass ) 67 { 68 schedules.push_back( Schedule( pClass, size ) ); 69 70 *((long *)(codeBuffer+size))=0; 71 size += sizeof(long); 72 } 73 66 74 void NativeCode::NextSourceLine() 67 75 { -
trunk/abdev/BasicCompiler_Common/src/ObjectModule.cpp
r280 r282 33 33 this->sources.push_back( source ); 34 34 } 35 36 // TODO: basbufがいらなくなったら消す 37 extern char *basbuf; 38 basbuf = this->sources[0].GetBuffer(); 35 39 } 36 40
Note:
See TracChangeset
for help on using the changeset viewer.