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

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

jenga.hを追加。

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