source: dev/trunk/ab5.0/abdev/ab_common/include/Lexical/NativeCode.h@ 603

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

ObjectModuleに関連するクラス一式をab_commonプロジェクトに移動した。

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