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

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

Messenger/ErrorMessengerクラスを導入。SetError関数によるエラー生成を廃止した。

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