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
RevLine 
[224]1#pragma once
2
3#include <vector>
4
[228]5#include <jenga/include/common/Exception.h>
6
[225]7#include <BoostSerializationSupport.h>
8
[287]9#include <Binary.h>
10
[244]11class UserProc;
12
[224]13class Schedule
14{
15public:
16 enum Type
17 {
[237]18 None = 10000,
[225]19 GlobalVar, // グローバル変数スケジュール
[237]20 DataTable, // データテーブル スケジュール
[357]21 CatchAddress, // Catchアドレス スケジュール
[225]22 Relocation, // リロケーション情報スケジュール
[244]23 UserProc, // ユーザ定義関数呼び出し側スケジュール
24 AddressOf, // ユーザ定義関数位置スケジュール
[257]25 DllProc, // DLL関数位置スケジュール
[370]26 ComVtbl, // com_vtblスケジュール
[282]27 Vtbl, // vtblスケジュール
[355]28 TypeInfo, // TypeInfoスケジュール
[224]29 };
30
31private:
32 Type type;
[244]33 long offset;
[224]34
[244]35 union{
36 LONG_PTR lpValue;
37 const ::UserProc *pUserProc;
[250]38 const ::DllProc *pDllProc;
[282]39 const ::CClass *pClass;
[244]40 };
41
[224]42 // XMLシリアライズ用
43private:
44 friend class boost::serialization::access;
45 template<class Archive> void serialize(Archive& ar, const unsigned int version)
46 {
[256]47 trace_for_serialize( "serializing - Schedule" );
48
[224]49 ar & BOOST_SERIALIZATION_NVP( type );
50 ar & BOOST_SERIALIZATION_NVP( offset );
[272]51
52 switch( type )
53 {
54 case UserProc:
55 case AddressOf:
[357]56 case CatchAddress:
[278]57 ar & boost::serialization::make_nvp("pUserProc", const_cast<::UserProc *&>(pUserProc));
[272]58 break;
59 case DllProc:
[278]60 ar & boost::serialization::make_nvp("pDllProc", const_cast<::DllProc *&>(pDllProc));
[272]61 break;
[370]62 case ComVtbl:
[282]63 case Vtbl:
[355]64 case TypeInfo:
[282]65 ar & boost::serialization::make_nvp("pClass", const_cast<::CClass *&>(pClass));
66 break;
[272]67 default:
68 ar & BOOST_SERIALIZATION_NVP( lpValue );
69 break;
70 }
[224]71 }
72
73public:
74 Schedule()
75 {
76 }
[258]77 Schedule( Type type, long offset, LONG_PTR lpValue = 0 )
[224]78 : type( type )
79 , offset( offset )
[258]80 , lpValue( lpValue )
[224]81 {
82 }
[258]83 Schedule( const ::UserProc *pUserProc, long offset )
[244]84 : type( Schedule::UserProc )
85 , offset( offset )
86 , pUserProc( pUserProc )
87 {
88 }
[258]89 Schedule( const ::DllProc *pDllProc, long offset )
[257]90 : type( Schedule::DllProc )
[250]91 , offset( offset )
92 , pDllProc( pDllProc )
93 {
94 }
[355]95 Schedule( Type type, const ::CClass *pClass, long offset )
96 : type( type )
97 , pClass( pClass )
98 , offset( offset )
99 {
[370]100 if( !( type == Schedule::ComVtbl || type == Schedule::Vtbl || type == Schedule::TypeInfo ) )
101 {
102 DebugBreak();
103 }
[355]104 }
[224]105 ~Schedule()
106 {
107 }
[244]108
[257]109 Type GetType() const
110 {
111 return type;
112 }
113 long GetOffset() const
114 {
115 return offset;
116 }
[258]117 LONG_PTR GetLongPtrValue() const
118 {
119 return lpValue;
120 }
[257]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 {
[357]131 if( !( type == Schedule::UserProc || type == Schedule::AddressOf || type == Schedule::CatchAddress ) )
[257]132 {
133 SetError();
134 }
135 return *pUserProc;
136 }
[282]137 const ::CClass &GetClass() const
138 {
[370]139 if( !( type == Schedule::ComVtbl || type == Schedule::Vtbl || type == Schedule::TypeInfo ) )
[282]140 {
141 SetError();
142 }
143 return *pClass;
144 }
[257]145
[244]146 void SpecifyAddressOf()
147 {
148 if( type != Schedule::UserProc )
149 {
150 SetError();
151 }
152 type = Schedule::AddressOf;
153 }
[357]154 void SpecifyCatchAddress()
155 {
156 if( type != Schedule::UserProc )
157 {
158 SetError();
159 }
160 type = Schedule::CatchAddress;
161 }
[224]162};
163typedef std::vector<Schedule> Schedules;
164
[263]165#define CODETYPE_SYSTEMPROC 0x0001
166#define CODETYPE_DEBUGPROC 0x0002
167class SourceLine
168{
169 int lineNum;
170 long nativeCodePos;
[280]171 int sourceIndex;
[263]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 );
[280]184 ar & BOOST_SERIALIZATION_NVP( sourceIndex );
[263]185 ar & BOOST_SERIALIZATION_NVP( sourceCodePos );
186 ar & BOOST_SERIALIZATION_NVP( codeType );
187 }
188
189public:
[280]190 SourceLine( int lineNum, int nativeCodePos, int sourceIndex, int sourceCodePos, DWORD codeType )
[263]191 : lineNum( lineNum )
192 , nativeCodePos( nativeCodePos )
[280]193 , sourceIndex( sourceIndex )
[263]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 }
[280]210 int GetSourceIndex() const
211 {
212 return sourceIndex;
213 }
214 void SetSourceIndex( int sourceIndex )
215 {
216 this->sourceIndex = sourceIndex;
217 }
[263]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
[287]241class NativeCode : public Binary
[224]242{
[263]243 // リンカで解決しなければならないスケジュール
[224]244 Schedules schedules;
245
[263]246 // ソースコード行番号とネイティブコード位置の対応情報
247 SourceLines sourceLines;
248
[224]249 // XMLシリアライズ用
250private:
251 friend class boost::serialization::access;
[287]252 template<class Archive> void serialize(Archive& ar, const unsigned int version)
[224]253 {
[256]254 trace_for_serialize( "serializing(load) - NativeCode" );
255
[287]256 ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP( Binary );
[224]257 ar & BOOST_SERIALIZATION_NVP( schedules );
[263]258 ar & BOOST_SERIALIZATION_NVP( sourceLines );
[224]259 }
[256]260
[224]261public:
262 NativeCode()
[287]263 : Binary()
[224]264 {
265 }
[276]266 NativeCode( const NativeCode &nativeCode )
[287]267 : Binary()
[256]268 {
[287]269 PutEx( nativeCode );
[256]270 }
[276]271 NativeCode( const char *codeBuffer, int size )
[287]272 : Binary( codeBuffer, size )
[252]273 {
274 }
[224]275 ~NativeCode()
276 {
277 }
278
[256]279 void operator =( const NativeCode &nativeCode )
280 {
281 Clear();
[287]282 PutEx( nativeCode );
[256]283 }
284
[257]285 const Schedules &GetSchedules() const
286 {
287 return schedules;
288 }
[237]289
[287]290 void PutEx( const NativeCode &nativeCode );
[357]291 void PutEx( long l, Schedule::Type scheduleType );
[245]292 void PutUserProcSchedule( const UserProc *pUserProc, bool isCall );
[357]293 void PutCatchAddressSchedule( const UserProc *pUserProc, long codePos );
[250]294 void PutDllProcSchedule( const DllProc *pDllProc );
[370]295 void PutComVtblSchedule( const CClass *pClass );
[282]296 void PutVtblSchedule( const CClass *pClass );
[263]297
[265]298 const SourceLines &GetSourceLines() const
299 {
300 return sourceLines;
301 }
[263]302 void NextSourceLine();
[273]303
304 void ResetDataSectionBaseOffset( long dataSectionBaseOffset );
[280]305 void ResetSourceIndexes( long sourceIndexBase );
[224]306};
Note: See TracBrowser for help on using the repository browser.