source: dev/trunk/abdev/BasicCompiler_Common/include/NativeCode.h@ 302

Last change on this file since 302 was 287, checked in by dai_9181, 17 years ago

Binaryクラスを追加

File size: 6.0 KB
RevLine 
[224]1#pragma once
2
3#include <vector>
4
[228]5#include <jenga/include/common/Exception.h>
6
[225]7#include <BoostSerializationSupport.h>
8
[287]9#include <Binary.h>
10
[244]11class UserProc;
12
[224]13class Schedule
14{
15public:
16 enum Type
17 {
[237]18 None = 10000,
[225]19 GlobalVar, // グローバル変数スケジュール
[237]20 DataTable, // データテーブル スケジュール
[225]21 Relocation, // リロケーション情報スケジュール
[244]22 UserProc, // ユーザ定義関数呼び出し側スケジュール
23 AddressOf, // ユーザ定義関数位置スケジュール
[257]24 DllProc, // DLL関数位置スケジュール
[282]25 Vtbl, // vtblスケジュール
[224]26 };
27
28private:
29 Type type;
[244]30 long offset;
[224]31
[244]32 union{
33 LONG_PTR lpValue;
34 const ::UserProc *pUserProc;
[250]35 const ::DllProc *pDllProc;
[282]36 const ::CClass *pClass;
[244]37 };
38
[224]39 // XMLシリアライズ用
40private:
41 friend class boost::serialization::access;
42 template<class Archive> void serialize(Archive& ar, const unsigned int version)
43 {
[256]44 trace_for_serialize( "serializing - Schedule" );
45
[224]46 ar & BOOST_SERIALIZATION_NVP( type );
47 ar & BOOST_SERIALIZATION_NVP( offset );
[272]48
49 switch( type )
50 {
51 case UserProc:
52 case AddressOf:
[278]53 ar & boost::serialization::make_nvp("pUserProc", const_cast<::UserProc *&>(pUserProc));
[272]54 break;
55 case DllProc:
[278]56 ar & boost::serialization::make_nvp("pDllProc", const_cast<::DllProc *&>(pDllProc));
[272]57 break;
[282]58 case Vtbl:
59 ar & boost::serialization::make_nvp("pClass", const_cast<::CClass *&>(pClass));
60 break;
[272]61 default:
62 ar & BOOST_SERIALIZATION_NVP( lpValue );
63 break;
64 }
[224]65 }
66
67public:
68 Schedule()
69 {
70 }
[258]71 Schedule( Type type, long offset, LONG_PTR lpValue = 0 )
[224]72 : type( type )
73 , offset( offset )
[258]74 , lpValue( lpValue )
[224]75 {
76 }
[258]77 Schedule( const ::UserProc *pUserProc, long offset )
[244]78 : type( Schedule::UserProc )
79 , offset( offset )
80 , pUserProc( pUserProc )
81 {
82 }
[258]83 Schedule( const ::DllProc *pDllProc, long offset )
[257]84 : type( Schedule::DllProc )
[250]85 , offset( offset )
86 , pDllProc( pDllProc )
87 {
88 }
[282]89 Schedule( const ::CClass *pClass, long offset )
90 : type( Schedule::Vtbl )
91 , offset( offset )
92 , pClass( pClass )
93 {
94 }
[224]95 ~Schedule()
96 {
97 }
[244]98
[257]99 Type GetType() const
100 {
101 return type;
102 }
103 long GetOffset() const
104 {
105 return offset;
106 }
[258]107 LONG_PTR GetLongPtrValue() const
108 {
109 return lpValue;
110 }
[257]111 const ::DllProc &GetDllProc() const
112 {
113 if( type != Schedule::DllProc )
114 {
115 SetError();
116 }
117 return *pDllProc;
118 }
119 const ::UserProc &GetUserProc() const
120 {
[258]121 if( !( type == Schedule::UserProc || type == Schedule::AddressOf ) )
[257]122 {
123 SetError();
124 }
125 return *pUserProc;
126 }
[282]127 const ::CClass &GetClass() const
128 {
129 if( type != Schedule::Vtbl )
130 {
131 SetError();
132 }
133 return *pClass;
134 }
[257]135
[244]136 void SpecifyAddressOf()
137 {
138 if( type != Schedule::UserProc )
139 {
140 SetError();
141 }
142 type = Schedule::AddressOf;
143 }
[224]144};
145typedef std::vector<Schedule> Schedules;
146
[263]147#define CODETYPE_SYSTEMPROC 0x0001
148#define CODETYPE_DEBUGPROC 0x0002
149class SourceLine
150{
151 int lineNum;
152 long nativeCodePos;
[280]153 int sourceIndex;
[263]154 long sourceCodePos;
155 DWORD codeType;
156
157 // XMLシリアライズ用
158private:
159 friend class boost::serialization::access;
160 template<class Archive> void serialize(Archive& ar, const unsigned int version)
161 {
162 trace_for_serialize( "serializing - SourceLine" );
163
164 ar & BOOST_SERIALIZATION_NVP( lineNum );
165 ar & BOOST_SERIALIZATION_NVP( nativeCodePos );
[280]166 ar & BOOST_SERIALIZATION_NVP( sourceIndex );
[263]167 ar & BOOST_SERIALIZATION_NVP( sourceCodePos );
168 ar & BOOST_SERIALIZATION_NVP( codeType );
169 }
170
171public:
[280]172 SourceLine( int lineNum, int nativeCodePos, int sourceIndex, int sourceCodePos, DWORD codeType )
[263]173 : lineNum( lineNum )
174 , nativeCodePos( nativeCodePos )
[280]175 , sourceIndex( sourceIndex )
[263]176 , sourceCodePos( sourceCodePos )
177 , codeType( codeType )
178 {
179 }
180 SourceLine()
181 {
182 }
183
184 int GetLineNum() const
185 {
186 return lineNum;
187 }
188 long GetNativeCodePos() const
189 {
190 return nativeCodePos;
191 }
[280]192 int GetSourceIndex() const
193 {
194 return sourceIndex;
195 }
196 void SetSourceIndex( int sourceIndex )
197 {
198 this->sourceIndex = sourceIndex;
199 }
[263]200 long GetSourceCodePos() const
201 {
202 return sourceCodePos;
203 }
204 void SetSourceCodePos( int sourceCodePos )
205 {
206 this->sourceCodePos = sourceCodePos;
207 }
208 DWORD GetCodeType() const
209 {
210 return codeType;
211 }
212 bool IsInSystemProc() const
213 {
214 return ( (codeType&CODETYPE_SYSTEMPROC) != 0 );
215 }
216 bool IsInDebugProc() const
217 {
218 return ( (codeType&CODETYPE_DEBUGPROC) != 0 );
219 }
220};
221typedef std::vector<SourceLine> SourceLines;
222
[287]223class NativeCode : public Binary
[224]224{
[263]225 // リンカで解決しなければならないスケジュール
[224]226 Schedules schedules;
227
[263]228 // ソースコード行番号とネイティブコード位置の対応情報
229 SourceLines sourceLines;
230
[224]231 // XMLシリアライズ用
232private:
233 friend class boost::serialization::access;
[287]234 template<class Archive> void serialize(Archive& ar, const unsigned int version)
[224]235 {
[256]236 trace_for_serialize( "serializing(load) - NativeCode" );
237
[287]238 ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP( Binary );
[224]239 ar & BOOST_SERIALIZATION_NVP( schedules );
[263]240 ar & BOOST_SERIALIZATION_NVP( sourceLines );
[224]241 }
[256]242
[224]243public:
244 NativeCode()
[287]245 : Binary()
[224]246 {
247 }
[276]248 NativeCode( const NativeCode &nativeCode )
[287]249 : Binary()
[256]250 {
[287]251 PutEx( nativeCode );
[256]252 }
[276]253 NativeCode( const char *codeBuffer, int size )
[287]254 : Binary( codeBuffer, size )
[252]255 {
256 }
[224]257 ~NativeCode()
258 {
259 }
260
[256]261 void operator =( const NativeCode &nativeCode )
262 {
263 Clear();
[287]264 PutEx( nativeCode );
[256]265 }
266
[257]267 const Schedules &GetSchedules() const
268 {
269 return schedules;
270 }
[237]271
[287]272 void PutEx( const NativeCode &nativeCode );
273 void PutEx( long l, Schedule::Type scheduleType )
[253]274 {
[224]275 if( scheduleType != Schedule::None )
276 {
[287]277 schedules.push_back( Schedule( scheduleType, GetSize() ) );
[224]278 }
279
[287]280 Put( l );
[224]281 }
[245]282 void PutUserProcSchedule( const UserProc *pUserProc, bool isCall );
[250]283 void PutDllProcSchedule( const DllProc *pDllProc );
[282]284 void PutVtblSchedule( const CClass *pClass );
[263]285
[265]286 const SourceLines &GetSourceLines() const
287 {
288 return sourceLines;
289 }
[263]290 void NextSourceLine();
[273]291
292 void ResetDataSectionBaseOffset( long dataSectionBaseOffset );
[280]293 void ResetSourceIndexes( long sourceIndexBase );
[224]294};
Note: See TracBrowser for help on using the repository browser.