Changeset 273 in dev for trunk/abdev
- Timestamp:
- Aug 11, 2007, 4:03:49 PM (17 years ago)
- Location:
- trunk/abdev
- Files:
-
- 17 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/abdev/BasicCompiler32/BasicCompiler.vcproj
r270 r273 1317 1317 </File> 1318 1318 <File 1319 RelativePath="..\BasicCompiler_Common\src\ObjectModule.cpp" 1320 > 1321 </File> 1322 <File 1319 1323 RelativePath="..\BasicCompiler_Common\src\Procedure.cpp" 1320 1324 > -
trunk/abdev/BasicCompiler32/Compile_Var.cpp
r265 r273 14 14 //変数 15 15 // TODO: xml未完成 16 int AllGlobalVarSize;17 int AllInitGlobalVarSize;18 19 16 int AllLocalVarSize; 20 17 -
trunk/abdev/BasicCompiler32/MakePeHdr.cpp
r272 r273 149 149 ////////////////// 150 150 // データテーブル 151 compiler.GetObjectModule().dataTable.Clear();152 151 if(bDebugCompile){ 153 152 compiler.GetObjectModule().dataTable.Add( (long)0x00000002 ); … … 493 492 494 493 //グローバル実行領域のコードサイズ 495 GlobalOpBufferSize =obp;494 GlobalOpBufferSize = compiler.linker.GetNativeCode().GetSize(); 496 495 497 496 //With情報のメモリを解放 … … 541 540 trace( "コード生成が終了しました。" ); 542 541 543 vector<ObjectModule *> masterObjectModules; 544 masterObjectModules.push_back( &compiler.GetObjectModule() ); 545 compiler.linker.Link( masterObjectModules ); 542 compiler.linker.Link( compiler.GetObjectModule() ); 546 543 547 544 oldSourceLines = compiler.linker.GetNativeCode().GetSourceLines(); … … 884 881 //グローバル変数情報を扱う構造体も初期バッファの有無による配置を行う 885 882 //(デバッグ情報で利用される) 886 extern int AllInitGlobalVarSize;887 883 BOOST_FOREACH( Variable *pVar, compiler.GetObjectModule().meta.GetGlobalVars() ){ 888 884 if(pVar->GetOffsetAddress()&0x80000000){ 889 pVar->SetOffsetAddress( (pVar->GetOffsetAddress()&0x7FFFFFFF)+AllInitGlobalVarSize ); 885 pVar->SetOffsetAddress( 886 (pVar->GetOffsetAddress()&0x7FFFFFFF) 887 + compiler.GetObjectModule().meta.GetGlobalVars().GetAllInitSize() 888 ); 890 889 } 891 890 } … … 913 912 914 913 //コードセッションのファイル上のサイズ 915 if(obp%FILE_ALIGNMENT) FileSize_CodeSection=obp+(FILE_ALIGNMENT-obp%FILE_ALIGNMENT); 916 else FileSize_CodeSection=obp; 914 if(compiler.linker.GetNativeCode().GetSize()%FILE_ALIGNMENT) 915 { 916 FileSize_CodeSection = 917 compiler.linker.GetNativeCode().GetSize() 918 + (FILE_ALIGNMENT-compiler.linker.GetNativeCode().GetSize()%FILE_ALIGNMENT); 919 } 920 else 921 { 922 FileSize_CodeSection = compiler.linker.GetNativeCode().GetSize(); 923 } 917 924 if(FileSize_CodeSection) bUse_CodeSection=1; 918 925 else bUse_CodeSection=0; … … 947 954 948 955 //リライタブルセクションのファイル上のサイズ(グローバル変数の初期情報のみを格納) 949 if(AllInitGlobalVarSize%FILE_ALIGNMENT) FileSize_RWSection=AllInitGlobalVarSize+(FILE_ALIGNMENT-AllInitGlobalVarSize%FILE_ALIGNMENT); 956 if( compiler.GetObjectModule().meta.GetGlobalVars().GetAllInitSize() % FILE_ALIGNMENT ) 957 { 958 FileSize_RWSection = 959 compiler.GetObjectModule().meta.GetGlobalVars().GetAllInitSize() 960 + (FILE_ALIGNMENT-compiler.GetObjectModule().meta.GetGlobalVars().GetAllInitSize()%FILE_ALIGNMENT); 961 } 950 962 else{ 951 if(AllInitGlobalVarSize) FileSize_RWSection=AllInitGlobalVarSize; 963 if( compiler.GetObjectModule().meta.GetGlobalVars().GetAllInitSize() ) 964 { 965 FileSize_RWSection = compiler.GetObjectModule().meta.GetGlobalVars().GetAllInitSize(); 966 } 952 967 else FileSize_RWSection=FILE_ALIGNMENT; 953 968 } … … 1011 1026 1012 1027 //リライタブルセクションのメモリ上のサイズ 1013 extern int AllGlobalVarSize;1014 i=AllInitGlobalVarSize+AllGlobalVarSize;1028 i = compiler.GetObjectModule().meta.GetGlobalVars().GetAllInitSize() 1029 + compiler.GetObjectModule().meta.GetGlobalVars().GetAllSize(); 1015 1030 if(i%MEM_ALIGNMENT) MemSize_RWSection=i+(MEM_ALIGNMENT-i%MEM_ALIGNMENT); 1016 1031 else MemSize_RWSection=i; … … 1189 1204 //初期バッファなし 1190 1205 *((long *)(OpBuffer+pobj_GlobalVarSchedule->pObpValues[i]))= 1191 AllInitGlobalVarSize+1206 compiler.GetObjectModule().meta.GetGlobalVars().GetAllInitSize() + 1192 1207 (*((long *)(OpBuffer+pobj_GlobalVarSchedule->pObpValues[i])) & 0x7FFFFFFF)+ 1193 1208 ImageBase+MemPos_RWSection; … … 1207 1222 compiler.linker.ResolveUserProcSchedules( MemPos_CodeSection ); 1208 1223 compiler.linker.ResolveGlobalVarSchedules( MemPos_RWSection ); 1209 1210 if( obp == compiler.linker.GetNativeCode().GetSize() )1211 {1212 memcpy( OpBuffer, compiler.linker.GetNativeCode().GetCodeBuffer(), compiler.linker.GetNativeCode().GetSize() );1213 }1214 else1215 {1216 SetError();1217 }1218 1224 1219 1225 … … 1475 1481 memset((char *)RWSectionHeader.Name,0,IMAGE_SIZEOF_SHORT_NAME); 1476 1482 lstrcpy((char *)RWSectionHeader.Name,".data"); 1477 RWSectionHeader.Misc.VirtualSize= AllInitGlobalVarSize+AllGlobalVarSize; 1483 RWSectionHeader.Misc.VirtualSize= compiler.GetObjectModule().meta.GetGlobalVars().GetAllInitSize() 1484 + compiler.GetObjectModule().meta.GetGlobalVars().GetAllSize(); 1478 1485 RWSectionHeader.VirtualAddress= MemPos_RWSection; 1479 1486 RWSectionHeader.SizeOfRawData= FileSize_RWSection; … … 1605 1612 1606 1613 //コード 1607 WriteFile(hFile,OpBuffer,obp,(DWORD *)&i2,NULL); 1614 WriteFile( 1615 hFile, 1616 compiler.linker.GetNativeCode().GetCodeBuffer(), 1617 compiler.linker.GetNativeCode().GetSize(), 1618 (DWORD *)&i2, 1619 NULL 1620 ); 1608 1621 i+=i2; 1609 1622 -
trunk/abdev/BasicCompiler_Common/MakeExe.cpp
r272 r273 135 135 //"コンパイル中..." 136 136 CompileMessage(STRING_COMPILE_COMPILING); 137 138 //グローバル変数に関する情報139 // TODO: AllGlobalVarSize、AllInitGlobalVarSizeをVariablesクラスに入れる140 extern int AllGlobalVarSize;141 extern int AllInitGlobalVarSize;142 compiler.GetObjectModule().meta.GetGlobalVars().clear();143 AllGlobalVarSize=0;144 AllInitGlobalVarSize=0;145 137 146 138 Compile(); -
trunk/abdev/BasicCompiler_Common/VariableOpe.cpp
r265 r273 970 970 // グローバル変数を追加 971 971 ///////////////////////// 972 extern int AllInitGlobalVarSize;973 extern int AllGlobalVarSize;974 972 975 973 if( compiler.GetObjectModule().meta.GetGlobalVars().DuplicateCheck( Symbol( name ) ) ){ … … 997 995 998 996 // 変数を追加 999 compiler.GetObjectModule().meta.GetGlobalVars().push_back( pVar ); 1000 1001 //アラインメントを考慮 1002 int alignment = 0; 1003 if( pVar->GetType().IsStruct() ){ 1004 alignment = pVar->GetType().GetClass().GetFixedAlignment(); 1005 } 1006 1007 if(InitBuf[0]||dwFlag==DIMFLAG_INITDEBUGVAR){ 1008 //初期バッファがあるとき 1009 1010 if( alignment ){ 1011 if( AllInitGlobalVarSize % alignment ){ 1012 AllInitGlobalVarSize += alignment - (AllInitGlobalVarSize % alignment); 1013 } 1014 } 1015 1016 pVar->SetOffsetAddress( AllInitGlobalVarSize ); 1017 AllInitGlobalVarSize += pVar->GetMemorySize(); 1018 } 1019 else{ 1020 //初期バッファがないとき 1021 1022 if( alignment ){ 1023 if( AllGlobalVarSize % alignment ){ 1024 AllGlobalVarSize += alignment - (AllGlobalVarSize % alignment); 1025 } 1026 } 1027 1028 pVar->SetOffsetAddress( AllGlobalVarSize | 0x80000000 ); 1029 AllGlobalVarSize += pVar->GetMemorySize(); 1030 } 997 compiler.GetObjectModule().meta.GetGlobalVars().Add( 998 pVar, 999 ( InitBuf[0] != 0 || dwFlag == DIMFLAG_INITDEBUGVAR ) 1000 ); 1031 1001 1032 1002 if(InitBuf[0]){ … … 1035 1005 //初期バッファにデータをセット 1036 1006 extern BYTE *initGlobalBuf; 1037 initGlobalBuf=(BYTE *)HeapReAlloc(hHeap, 1007 initGlobalBuf = (BYTE *)HeapReAlloc( 1008 hHeap, 1038 1009 HEAP_ZERO_MEMORY, 1039 1010 initGlobalBuf, 1040 AllInitGlobalVarSize); 1011 compiler.GetObjectModule().meta.GetGlobalVars().GetAllInitSize() 1012 ); 1041 1013 1042 1014 result = SetInitGlobalData(pVar->GetOffsetAddress(), -
trunk/abdev/BasicCompiler_Common/include/DataTable.h
r256 r273 7 7 char *buffer; 8 8 int size; 9 10 void Realloc( int size ) 11 { 12 this->buffer = (char *)realloc( this->buffer, size + 100 ); 13 this->size = size; 14 } 9 15 10 16 // XMLシリアライズ用 … … 75 81 } 76 82 77 void operator = ( const DataTable &dataTable )83 void operator = ( const DataTable &dataTable ) 78 84 { 79 85 Clear(); … … 81 87 } 82 88 83 void Realloc( int size );84 89 int AddBinary( const void *buffer, int size ); 85 90 int Add( _int64 i64data ); … … 89 94 int AddString( const char *str, int length ); 90 95 int AddString( const char *str ); 96 void Add( const DataTable &dataTable ) 97 { 98 AddBinary( dataTable.GetPtr(), dataTable.GetSize() ); 99 } 91 100 92 101 const void *GetPtr() const; -
trunk/abdev/BasicCompiler_Common/include/Linker.h
r270 r273 35 35 36 36 // リンク 37 void Link( vector<ObjectModule *> &objectModules);37 void Link( ObjectModule &masterObjectModule ); 38 38 }; -
trunk/abdev/BasicCompiler_Common/include/Meta.h
r272 r273 75 75 76 76 // 静的リンク 77 void StaticLink( Meta &meta );77 void StaticLink( Meta &meta, long dataSectionBaseOffset ); 78 78 79 79 const NamespaceScopesCollection &GetNamespaces() const -
trunk/abdev/BasicCompiler_Common/include/NativeCode.h
r272 r273 427 427 } 428 428 void NextSourceLine(); 429 430 void ResetDataSectionBaseOffset( long dataSectionBaseOffset ); 429 431 }; -
trunk/abdev/BasicCompiler_Common/include/ObjectModule.h
r270 r273 28 28 ar & BOOST_SERIALIZATION_NVP( dataTable ); 29 29 } 30 31 public: 32 void StaticLink( ObjectModule &objectModule ); 30 33 }; 31 34 typedef std::vector<ObjectModule *> ObjectModules; -
trunk/abdev/BasicCompiler_Common/include/Variable.h
r271 r273 214 214 class Variables : public vector<Variable *> 215 215 { 216 int allSize; 217 int allInitSize; 216 218 public: 217 Variables(){} 219 Variables() 220 : allSize( 0 ) 221 , allInitSize( 0 ) 222 { 223 } 218 224 ~Variables(){ 219 225 Clear(); … … 225 231 } 226 232 233 allSize = 0; 234 allInitSize = 0; 227 235 clear(); 228 236 } … … 235 243 236 244 const Variable *BackSearch( const Symbol &symbol ) const; 237 238 245 const Variable *Find( const Symbol &symbol )const; 246 247 void Add( Variable *pVar, bool isInitArea ); 248 249 int GetAllSize() const 250 { 251 return allSize; 252 } 253 int GetAllInitSize() const 254 { 255 return allInitSize; 256 } 239 257 240 258 -
trunk/abdev/BasicCompiler_Common/src/Compiler.cpp
r270 r273 13 13 { 14 14 // メタ情報 15 pNowObjectModule-> meta.StaticLink( pStaticLibrary->meta);15 pNowObjectModule->StaticLink( *pStaticLibrary ); 16 16 } 17 17 } -
trunk/abdev/BasicCompiler_Common/src/DataTable.cpp
r256 r273 7 7 #include <memory.h> 8 8 #include <stdlib.h> 9 10 void DataTable::Realloc( int size )11 {12 this->buffer = (char *)realloc( this->buffer, size + 100 );13 this->size = size;14 }15 9 16 10 int DataTable::AddBinary( const void *buffer, int size ){ -
trunk/abdev/BasicCompiler_Common/src/Linker.cpp
r263 r273 78 78 void Linker::ResolveGlobalVarSchedules( long rwSectionBaseOffset ) 79 79 { 80 int allInitVarSize = compiler.GetObjectModule().meta.GetGlobalVars().GetAllInitSize(); 81 80 82 BOOST_FOREACH( const Schedule &schedule, nativeCode.GetSchedules() ) 81 83 { … … 84 86 if( nativeCode.GetLong( schedule.GetOffset() ) & 0x80000000 ) 85 87 { 86 extern int AllInitGlobalVarSize;87 88 nativeCode.Overwrite( 88 89 schedule.GetOffset(), 89 static_cast<long>( AllInitGlobalVarSize + (nativeCode.GetLong( schedule.GetOffset() ) & 0x7FFFFFFF) + imageBase + rwSectionBaseOffset )90 static_cast<long>( allInitVarSize + (nativeCode.GetLong( schedule.GetOffset() ) & 0x7FFFFFFF) + imageBase + rwSectionBaseOffset ) 90 91 ); 91 92 } … … 101 102 } 102 103 103 void Linker::Link( vector<ObjectModule *> &objectModules)104 void Linker::Link( ObjectModule &masterObjectModule ) 104 105 { 105 106 // nativeCodeは初期状態でなければならない … … 108 109 SetError(); 109 110 } 110 111 /*112 BOOST_FOREACH( ObjectModule *pObjectModule, objectModules )113 {114 }*/115 ObjectModule &masterObjectModule = *objectModules[0];116 111 117 112 nativeCode.Put( masterObjectModule.globalNativeCode, false ); -
trunk/abdev/BasicCompiler_Common/src/Meta.cpp
r272 r273 36 36 } 37 37 38 void Meta::StaticLink( Meta &meta )38 void Meta::StaticLink( Meta &meta, long dataSectionBaseOffset ) 39 39 { 40 40 // 名前空間 … … 53 53 UserProc *pUserProc = meta.GetUserProcs().Iterator_GetNext(); 54 54 pUserProc->isTargetObjectModule = false; 55 56 pUserProc->GetNativeCode().ResetDataSectionBaseOffset( dataSectionBaseOffset ); 57 55 58 this->userProcs.Put( pUserProc ); 56 59 } -
trunk/abdev/BasicCompiler_Common/src/NativeCode.cpp
r263 r273 125 125 sourceLines.push_back( SourceLine( (long)sourceLines.size(), size, cp, sourceLineType ) ); 126 126 } 127 128 void NativeCode::ResetDataSectionBaseOffset( long dataSectionBaseOffset ) 129 { 130 BOOST_FOREACH( const Schedule &schedule, schedules ) 131 { 132 if( schedule.GetType() == Schedule::DataTable ) 133 { 134 Overwrite( 135 schedule.GetOffset(), 136 GetLong( schedule.GetOffset() ) + dataSectionBaseOffset 137 ); 138 } 139 } 140 } -
trunk/abdev/BasicCompiler_Common/src/Variable.cpp
r248 r273 73 73 return NULL; 74 74 } 75 76 void Variables::Add( Variable *pVar, bool isInitArea ) 77 { 78 int alignment = 0; 79 if( pVar->GetType().IsStruct() ){ 80 alignment = pVar->GetType().GetClass().GetFixedAlignment(); 81 } 82 83 if( isInitArea ){ 84 //初期バッファがあるとき 85 86 if( alignment ){ 87 if( allInitSize % alignment ){ 88 allInitSize += alignment - (allInitSize % alignment); 89 } 90 } 91 92 pVar->SetOffsetAddress( allInitSize ); 93 allInitSize += pVar->GetMemorySize(); 94 } 95 else{ 96 //初期バッファがないとき 97 98 if( alignment ){ 99 if( allSize % alignment ){ 100 allSize += alignment - (allSize % alignment); 101 } 102 } 103 104 pVar->SetOffsetAddress( allSize | 0x80000000 ); 105 allSize += pVar->GetMemorySize(); 106 } 107 108 push_back( pVar ); 109 }
Note:
See TracChangeset
for help on using the changeset viewer.