source: dev/trunk/ab5.0/abdev/BasicCompiler_Common/include/NativeCode.h@ 520

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

Hashmapクラスをjengaプロジェクトに移動。

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