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

Last change on this file since 563 was 551, checked in by dai_9181, 17 years ago

・PutWithScheduleメソッドを追加。
・NativeCodeクラスが持つCompilerクラスへの依存度を除去した。

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( Schedule::Type type, const ::UserProc *pUserProc, long offset )
76 : type( type )
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};
117typedef std::vector<Schedule> Schedules;
118
119#define CODETYPE_SYSTEMPROC 0x0001
120#define CODETYPE_DEBUGPROC 0x0002
121class SourceLine
122{
123 int lineNum;
124 long nativeCodePos;
125 int sourceIndex;
126 long sourceCodePos;
127 DWORD codeType;
128
129 // XMLシリアライズ用
130private:
131 friend class boost::serialization::access;
132 template<class Archive> void serialize(Archive& ar, const unsigned int version)
133 {
134 trace_for_serialize( "serializing - SourceLine" );
135
136 ar & BOOST_SERIALIZATION_NVP( lineNum );
137 ar & BOOST_SERIALIZATION_NVP( nativeCodePos );
138 ar & BOOST_SERIALIZATION_NVP( sourceIndex );
139 ar & BOOST_SERIALIZATION_NVP( sourceCodePos );
140 ar & BOOST_SERIALIZATION_NVP( codeType );
141 }
142
143public:
144 SourceLine( int lineNum, int nativeCodePos, int sourceIndex, int sourceCodePos, DWORD codeType )
145 : lineNum( lineNum )
146 , nativeCodePos( nativeCodePos )
147 , sourceIndex( sourceIndex )
148 , sourceCodePos( sourceCodePos )
149 , codeType( codeType )
150 {
151 }
152 SourceLine()
153 {
154 }
155
156 int GetLineNum() const
157 {
158 return lineNum;
159 }
160 long GetNativeCodePos() const
161 {
162 return nativeCodePos;
163 }
164 int GetSourceIndex() const
165 {
166 return sourceIndex;
167 }
168 void SetSourceIndex( int sourceIndex )
169 {
170 this->sourceIndex = sourceIndex;
171 }
172 long GetSourceCodePos() const
173 {
174 return sourceCodePos;
175 }
176 void SetSourceCodePos( int sourceCodePos )
177 {
178 this->sourceCodePos = sourceCodePos;
179 }
180 DWORD GetCodeType() const
181 {
182 return codeType;
183 }
184 bool IsInSystemProc() const
185 {
186 return ( (codeType&CODETYPE_SYSTEMPROC) != 0 );
187 }
188 bool IsInDebugProc() const
189 {
190 return ( (codeType&CODETYPE_DEBUGPROC) != 0 );
191 }
192};
193typedef std::vector<SourceLine> SourceLines;
194
195class NativeCode : public Jenga::Common::Binary
196{
197 // リンカで解決しなければならないスケジュール
198 Schedules schedules;
199
200 // ソースコード行番号とネイティブコード位置の対応情報
201 SourceLines sourceLines;
202
203 // XMLシリアライズ用
204private:
205 friend class boost::serialization::access;
206 template<class Archive> void serialize(Archive& ar, const unsigned int version)
207 {
208 trace_for_serialize( "serializing(load) - NativeCode" );
209
210 ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP( Jenga::Common::Binary );
211 ar & BOOST_SERIALIZATION_NVP( schedules );
212 ar & BOOST_SERIALIZATION_NVP( sourceLines );
213 }
214
215public:
216 NativeCode()
217 : Jenga::Common::Binary()
218 {
219 }
220 NativeCode( const NativeCode &nativeCode )
221 : Jenga::Common::Binary()
222 {
223 PutEx( nativeCode );
224 }
225 NativeCode( const char *codeBuffer, int size )
226 : Jenga::Common::Binary( codeBuffer, size )
227 {
228 }
229 ~NativeCode()
230 {
231 }
232
233 void operator =( const NativeCode &nativeCode )
234 {
235 Clear();
236 PutEx( nativeCode );
237 }
238
239 const Schedules &GetSchedules() const
240 {
241 return schedules;
242 }
243
244 void PutEx( const NativeCode &nativeCode );
245 void PutEx( long l, Schedule::Type scheduleType );
246 void PutUserProcSchedule( const UserProc *pUserProc, bool isCall );
247 void PutCatchAddressSchedule( const UserProc *pUserProc, long codePos );
248 void PutDllProcSchedule( const DllProc *pDllProc );
249 void PutComVtblSchedule( const CClass *pClass );
250 void PutVtblSchedule( const CClass *pClass );
251
252 const SourceLines &GetSourceLines() const
253 {
254 return sourceLines;
255 }
256 void NextSourceLine( int currentSourceIndex );
257
258 void ResetDataSectionBaseOffset( long dataSectionBaseOffset );
259 void ResetSourceIndexes( long sourceIndexBase );
260};
Note: See TracBrowser for help on using the repository browser.