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
RevLine 
[224]1#pragma once
2
3#include <vector>
4
[225]5#include <BoostSerializationSupport.h>
6
[287]7#include <Binary.h>
8
[244]9class UserProc;
10
[224]11class Schedule
12{
13public:
14 enum Type
15 {
[237]16 None = 10000,
[225]17 GlobalVar, // グローバル変数スケジュール
[237]18 DataTable, // データテーブル スケジュール
[357]19 CatchAddress, // Catchアドレス スケジュール
[225]20 Relocation, // リロケーション情報スケジュール
[244]21 UserProc, // ユーザ定義関数呼び出し側スケジュール
22 AddressOf, // ユーザ定義関数位置スケジュール
[257]23 DllProc, // DLL関数位置スケジュール
[370]24 ComVtbl, // com_vtblスケジュール
[282]25 Vtbl, // vtblスケジュール
[355]26 TypeInfo, // TypeInfoスケジュール
[224]27 };
28
29private:
30 Type type;
[244]31 long offset;
[224]32
[244]33 union{
34 LONG_PTR lpValue;
35 const ::UserProc *pUserProc;
[250]36 const ::DllProc *pDllProc;
[282]37 const ::CClass *pClass;
[244]38 };
39
[224]40 // XMLシリアライズ用
41private:
42 friend class boost::serialization::access;
43 template<class Archive> void serialize(Archive& ar, const unsigned int version)
44 {
[256]45 trace_for_serialize( "serializing - Schedule" );
46
[224]47 ar & BOOST_SERIALIZATION_NVP( type );
48 ar & BOOST_SERIALIZATION_NVP( offset );
[272]49
50 switch( type )
51 {
52 case UserProc:
53 case AddressOf:
[357]54 case CatchAddress:
[278]55 ar & boost::serialization::make_nvp("pUserProc", const_cast<::UserProc *&>(pUserProc));
[272]56 break;
57 case DllProc:
[278]58 ar & boost::serialization::make_nvp("pDllProc", const_cast<::DllProc *&>(pDllProc));
[272]59 break;
[370]60 case ComVtbl:
[282]61 case Vtbl:
[355]62 case TypeInfo:
[282]63 ar & boost::serialization::make_nvp("pClass", const_cast<::CClass *&>(pClass));
64 break;
[272]65 default:
66 ar & BOOST_SERIALIZATION_NVP( lpValue );
67 break;
68 }
[224]69 }
70
71public:
72 Schedule()
73 {
74 }
[258]75 Schedule( Type type, long offset, LONG_PTR lpValue = 0 )
[224]76 : type( type )
77 , offset( offset )
[258]78 , lpValue( lpValue )
[224]79 {
80 }
[258]81 Schedule( const ::UserProc *pUserProc, long offset )
[244]82 : type( Schedule::UserProc )
83 , offset( offset )
84 , pUserProc( pUserProc )
85 {
86 }
[258]87 Schedule( const ::DllProc *pDllProc, long offset )
[257]88 : type( Schedule::DllProc )
[250]89 , offset( offset )
90 , pDllProc( pDllProc )
91 {
92 }
[355]93 Schedule( Type type, const ::CClass *pClass, long offset )
94 : type( type )
95 , pClass( pClass )
96 , offset( offset )
97 {
[370]98 if( !( type == Schedule::ComVtbl || type == Schedule::Vtbl || type == Schedule::TypeInfo ) )
99 {
100 DebugBreak();
101 }
[355]102 }
[224]103 ~Schedule()
104 {
105 }
[244]106
[257]107 Type GetType() const
108 {
109 return type;
110 }
111 long GetOffset() const
112 {
113 return offset;
114 }
[258]115 LONG_PTR GetLongPtrValue() const
116 {
117 return lpValue;
118 }
[465]119 const ::DllProc &GetDllProc() const;
120 const ::UserProc &GetUserProc() const;
121 const ::CClass &GetClass() const;
[257]122
[465]123 void SpecifyAddressOf();
124 void SpecifyCatchAddress();
[224]125};
126typedef std::vector<Schedule> Schedules;
127
[263]128#define CODETYPE_SYSTEMPROC 0x0001
129#define CODETYPE_DEBUGPROC 0x0002
130class SourceLine
131{
132 int lineNum;
133 long nativeCodePos;
[280]134 int sourceIndex;
[263]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 );
[280]147 ar & BOOST_SERIALIZATION_NVP( sourceIndex );
[263]148 ar & BOOST_SERIALIZATION_NVP( sourceCodePos );
149 ar & BOOST_SERIALIZATION_NVP( codeType );
150 }
151
152public:
[280]153 SourceLine( int lineNum, int nativeCodePos, int sourceIndex, int sourceCodePos, DWORD codeType )
[263]154 : lineNum( lineNum )
155 , nativeCodePos( nativeCodePos )
[280]156 , sourceIndex( sourceIndex )
[263]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 }
[280]173 int GetSourceIndex() const
174 {
175 return sourceIndex;
176 }
177 void SetSourceIndex( int sourceIndex )
178 {
179 this->sourceIndex = sourceIndex;
180 }
[263]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
[287]204class NativeCode : public Binary
[224]205{
[263]206 // リンカで解決しなければならないスケジュール
[224]207 Schedules schedules;
208
[263]209 // ソースコード行番号とネイティブコード位置の対応情報
210 SourceLines sourceLines;
211
[224]212 // XMLシリアライズ用
213private:
214 friend class boost::serialization::access;
[287]215 template<class Archive> void serialize(Archive& ar, const unsigned int version)
[224]216 {
[256]217 trace_for_serialize( "serializing(load) - NativeCode" );
218
[287]219 ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP( Binary );
[224]220 ar & BOOST_SERIALIZATION_NVP( schedules );
[263]221 ar & BOOST_SERIALIZATION_NVP( sourceLines );
[224]222 }
[256]223
[224]224public:
225 NativeCode()
[287]226 : Binary()
[224]227 {
228 }
[276]229 NativeCode( const NativeCode &nativeCode )
[287]230 : Binary()
[256]231 {
[287]232 PutEx( nativeCode );
[256]233 }
[276]234 NativeCode( const char *codeBuffer, int size )
[287]235 : Binary( codeBuffer, size )
[252]236 {
237 }
[224]238 ~NativeCode()
239 {
240 }
241
[256]242 void operator =( const NativeCode &nativeCode )
243 {
244 Clear();
[287]245 PutEx( nativeCode );
[256]246 }
247
[257]248 const Schedules &GetSchedules() const
249 {
250 return schedules;
251 }
[237]252
[287]253 void PutEx( const NativeCode &nativeCode );
[357]254 void PutEx( long l, Schedule::Type scheduleType );
[245]255 void PutUserProcSchedule( const UserProc *pUserProc, bool isCall );
[357]256 void PutCatchAddressSchedule( const UserProc *pUserProc, long codePos );
[250]257 void PutDllProcSchedule( const DllProc *pDllProc );
[370]258 void PutComVtblSchedule( const CClass *pClass );
[282]259 void PutVtblSchedule( const CClass *pClass );
[263]260
[265]261 const SourceLines &GetSourceLines() const
262 {
263 return sourceLines;
264 }
[263]265 void NextSourceLine();
[273]266
267 void ResetDataSectionBaseOffset( long dataSectionBaseOffset );
[280]268 void ResetSourceIndexes( long sourceIndexBase );
[224]269};
Note: See TracBrowser for help on using the repository browser.