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

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

Binaryクラスを追加

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