source: dev/trunk/ab5.0/abdev/BasicCompiler_Common/src/NativeCode.cpp@ 551

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

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

File size: 3.6 KB
Line 
1#include "stdafx.h"
2
3#include <Compiler.h>
4
5#define BREAK_EIP(checkEip) (obp+0x00401000>=checkEip)
6
7const ::DllProc &Schedule::GetDllProc() const
8{
9 _ASSERT( type == Schedule::DllProc );
10 return *pDllProc;
11}
12const ::UserProc &Schedule::GetUserProc() const
13{
14 _ASSERT( type == Schedule::UserProc || type == Schedule::AddressOf || type == Schedule::CatchAddress );
15 return *pUserProc;
16}
17const ::CClass &Schedule::GetClass() const
18{
19 _ASSERT( type == Schedule::ComVtbl || type == Schedule::Vtbl || type == Schedule::TypeInfo );
20 return *pClass;
21}
22
23void NativeCode::PutEx( const NativeCode &nativeCode )
24{
25 long baseOffset = GetSize();
26
27 // コードバッファを追加
28 Put( nativeCode.GetBuffer(), nativeCode.GetSize() );
29
30 // スケジュールを追加
31 BOOST_FOREACH( const Schedule &schedule, nativeCode.schedules )
32 {
33 this->schedules.push_back(
34 Schedule(
35 schedule.GetType(),
36 baseOffset + schedule.GetOffset(),
37 schedule.GetLongPtrValue()
38 )
39 );
40 }
41
42 // ソースコード行番号とネイティブコード位置の対応情報を追加
43 BOOST_FOREACH( const SourceLine &sourceLine, nativeCode.sourceLines )
44 {
45 this->sourceLines.push_back(
46 SourceLine(
47 sourceLine.GetLineNum(),
48 baseOffset + sourceLine.GetNativeCodePos(),
49 sourceLine.GetSourceIndex(),
50 sourceLine.GetSourceCodePos(),
51 sourceLine.GetCodeType()
52 )
53 );
54 }
55}
56
57void NativeCode::PutEx( long l, Schedule::Type scheduleType )
58{
59 if( scheduleType != Schedule::None )
60 {
61 schedules.push_back( Schedule( scheduleType, GetSize() ) );
62 }
63
64 Put( l );
65}
66
67void NativeCode::PutUserProcSchedule( const UserProc *pUserProc, bool isCall )
68{
69 pUserProc->Using();
70
71 Schedule::Type type = isCall ? Schedule::UserProc : Schedule::AddressOf;
72
73 schedules.push_back( Schedule( type, pUserProc, GetSize() ) );
74
75 Put( (long)0 );
76}
77
78void NativeCode::PutCatchAddressSchedule( const UserProc *pUserProc, long codePos )
79{
80 pUserProc->Using();
81
82 schedules.push_back( Schedule( Schedule::CatchAddress, pUserProc, GetSize() ) );
83
84 Put( codePos );
85}
86
87void NativeCode::PutDllProcSchedule( const DllProc *pDllProc )
88{
89 pDllProc->Using();
90
91 schedules.push_back( Schedule( pDllProc, GetSize() ) );
92
93 Put( (long)0 );
94}
95
96void NativeCode::PutComVtblSchedule( const CClass *pClass )
97{
98 schedules.push_back( Schedule( Schedule::ComVtbl, pClass, GetSize() ) );
99
100 Put( (long)0 );
101}
102
103void NativeCode::PutVtblSchedule( const CClass *pClass )
104{
105 schedules.push_back( Schedule( Schedule::Vtbl, pClass, GetSize() ) );
106
107 Put( (long)0 );
108}
109
110void NativeCode::NextSourceLine( int currentSourceIndex )
111{
112 if( sourceLines.size() )
113 {
114 if( sourceLines.back().GetNativeCodePos() == GetSize() )
115 {
116 sourceLines.back().SetSourceCodePos( cp );
117 return;
118 }
119 }
120
121 extern BOOL bDebugSupportProc;
122 extern BOOL bSystemProc;
123 DWORD sourceLineType = 0;
124 if( bDebugSupportProc )
125 {
126 sourceLineType |= CODETYPE_DEBUGPROC;
127 }
128 if( bSystemProc )
129 {
130 sourceLineType |= CODETYPE_SYSTEMPROC;
131 }
132 sourceLines.push_back(
133 SourceLine(
134 (long)sourceLines.size(),
135 GetSize(),
136 currentSourceIndex,
137 cp,
138 sourceLineType
139 )
140 );
141}
142
143void NativeCode::ResetDataSectionBaseOffset( long dataSectionBaseOffset )
144{
145 BOOST_FOREACH( const Schedule &schedule, schedules )
146 {
147 if( schedule.GetType() == Schedule::DataTable )
148 {
149 Overwrite(
150 schedule.GetOffset(),
151 GetLong( schedule.GetOffset() ) + dataSectionBaseOffset
152 );
153 }
154 }
155}
156void NativeCode::ResetSourceIndexes( long sourceIndexBase )
157{
158 BOOST_FOREACH( SourceLine &sourceLine, sourceLines )
159 {
160 sourceLine.SetSourceIndex( sourceLine.GetSourceIndex() + sourceIndexBase );
161 }
162}
Note: See TracBrowser for help on using the repository browser.