source: dev/trunk/abdev/BasicCompiler_Common/src/ObjectModule.cpp@ 371

Last change on this file since 371 was 355, checked in by dai_9181, 17 years ago

静的領域に初期オブジェクトを配置可能にした

File size: 2.6 KB
Line 
1#include "stdafx.h"
2
3#include <Compiler.h>
4
5enum ObjectModuleDataType
6{
7 ObjectModuleDataTypeXml,
8 ObjectModuleDataTypeText,
9 ObjectModuleDataTypeBinaly,
10};
11const ObjectModuleDataType objectModuleDataType = ObjectModuleDataTypeBinaly;
12
13
14void ObjectModule::StaticLink( ObjectModule &objectModule )
15{
16 long dataSectionBaseOffset = dataTable.GetSize();
17 int sourceIndexBase = (int)sources.size();
18
19 // メタ情報を結合
20 meta.StaticLink( objectModule.meta, dataSectionBaseOffset, sourceIndexBase );
21
22 // ネイティブコードを結合
23 objectModule.globalNativeCode.ResetDataSectionBaseOffset( dataSectionBaseOffset );
24 objectModule.globalNativeCode.ResetSourceIndexes( sourceIndexBase );
25 globalNativeCode.PutEx( objectModule.globalNativeCode );
26
27 // データテーブルを結合
28 objectModule.dataTable.ResetDataSectionBaseOffset( dataSectionBaseOffset );
29 dataTable.Add( objectModule.dataTable );
30
31 // ソースコードを結合
32 BOOST_FOREACH( const BasicSource &source, objectModule.sources )
33 {
34 this->sources.push_back( source );
35 }
36
37 // TODO: basbufがいらなくなったら消す
38 extern char *basbuf;
39 basbuf = this->sources[0].GetBuffer();
40}
41
42bool ObjectModule::Read( const std::string &filePath )
43{
44 switch( objectModuleDataType )
45 {
46 case ObjectModuleDataTypeXml:
47 return ReadXml( filePath );
48 case ObjectModuleDataTypeText:
49 return ReadText( filePath );
50 case ObjectModuleDataTypeBinaly:
51 return ReadBinaryFile( filePath );
52 default:
53 Jenga::Throw( "" );
54 break;
55 }
56 return false;
57}
58bool ObjectModule::Write( const std::string &filePath ) const
59{
60 switch( objectModuleDataType )
61 {
62 case ObjectModuleDataTypeXml:
63 return WriteXml( filePath );
64 case ObjectModuleDataTypeText:
65 return WriteText( filePath );
66 case ObjectModuleDataTypeBinaly:
67 return WriteBinaryFile( filePath );
68 default:
69 Jenga::Throw( "" );
70 break;
71 }
72 return false;
73}
74bool ObjectModule::ReadString( const std::string &str )
75{
76 switch( objectModuleDataType )
77 {
78 case ObjectModuleDataTypeXml:
79 return ReadXmlString( str );
80 case ObjectModuleDataTypeText:
81 return ReadTextString( str );
82 case ObjectModuleDataTypeBinaly:
83 return ReadBinaryString( str );
84 default:
85 Jenga::Throw( "" );
86 break;
87 }
88 return false;
89}
90bool ObjectModule::WriteString( std::string &str ) const
91{
92 switch( objectModuleDataType )
93 {
94 case ObjectModuleDataTypeXml:
95 return WriteXmlString( str );
96 case ObjectModuleDataTypeText:
97 return WriteTextString( str );
98 case ObjectModuleDataTypeBinaly:
99 return WriteBinaryString( str );
100 default:
101 Jenga::Throw( "" );
102 break;
103 }
104 return false;
105}
Note: See TracBrowser for help on using the repository browser.