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

Last change on this file since 828 was 828, checked in by イグトランス (egtra), 12 years ago

egtraブランチの内容をマージ。

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