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

Last change on this file since 357 was 357, checked in by dai_9181, 16 years ago

例外処理機構実装中...

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