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

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

COM修飾子に対応。COMインターフェイスを呼び出せるようにした

File size: 6.5 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 ComVtbl, // com_vtblスケジュール
27 Vtbl, // vtblスケジュール
28 TypeInfo, // TypeInfoスケジュール
29 };
30
31private:
32 Type type;
33 long offset;
34
35 union{
36 LONG_PTR lpValue;
37 const ::UserProc *pUserProc;
38 const ::DllProc *pDllProc;
39 const ::CClass *pClass;
40 };
41
42 // XMLシリアライズ用
43private:
44 friend class boost::serialization::access;
45 template<class Archive> void serialize(Archive& ar, const unsigned int version)
46 {
47 trace_for_serialize( "serializing - Schedule" );
48
49 ar & BOOST_SERIALIZATION_NVP( type );
50 ar & BOOST_SERIALIZATION_NVP( offset );
51
52 switch( type )
53 {
54 case UserProc:
55 case AddressOf:
56 case CatchAddress:
57 ar & boost::serialization::make_nvp("pUserProc", const_cast<::UserProc *&>(pUserProc));
58 break;
59 case DllProc:
60 ar & boost::serialization::make_nvp("pDllProc", const_cast<::DllProc *&>(pDllProc));
61 break;
62 case ComVtbl:
63 case Vtbl:
64 case TypeInfo:
65 ar & boost::serialization::make_nvp("pClass", const_cast<::CClass *&>(pClass));
66 break;
67 default:
68 ar & BOOST_SERIALIZATION_NVP( lpValue );
69 break;
70 }
71 }
72
73public:
74 Schedule()
75 {
76 }
77 Schedule( Type type, long offset, LONG_PTR lpValue = 0 )
78 : type( type )
79 , offset( offset )
80 , lpValue( lpValue )
81 {
82 }
83 Schedule( const ::UserProc *pUserProc, long offset )
84 : type( Schedule::UserProc )
85 , offset( offset )
86 , pUserProc( pUserProc )
87 {
88 }
89 Schedule( const ::DllProc *pDllProc, long offset )
90 : type( Schedule::DllProc )
91 , offset( offset )
92 , pDllProc( pDllProc )
93 {
94 }
95 Schedule( Type type, const ::CClass *pClass, long offset )
96 : type( type )
97 , pClass( pClass )
98 , offset( offset )
99 {
100 if( !( type == Schedule::ComVtbl || type == Schedule::Vtbl || type == Schedule::TypeInfo ) )
101 {
102 DebugBreak();
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::ComVtbl || 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 PutComVtblSchedule( const CClass *pClass );
296 void PutVtblSchedule( const CClass *pClass );
297
298 const SourceLines &GetSourceLines() const
299 {
300 return sourceLines;
301 }
302 void NextSourceLine();
303
304 void ResetDataSectionBaseOffset( long dataSectionBaseOffset );
305 void ResetSourceIndexes( long sourceIndexBase );
306};
Note: See TracBrowser for help on using the repository browser.