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

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

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

File size: 4.4 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 if( type != Schedule::DllProc )
10 {
11 compiler.errorMessenger.OutputFatalError();
12 }
13 return *pDllProc;
14}
15const ::UserProc &Schedule::GetUserProc() const
16{
17 if( !( type == Schedule::UserProc || type == Schedule::AddressOf || type == Schedule::CatchAddress ) )
18 {
19 compiler.errorMessenger.OutputFatalError();
20 }
21 return *pUserProc;
22}
23const ::CClass &Schedule::GetClass() const
24{
25 if( !( type == Schedule::ComVtbl || type == Schedule::Vtbl || type == Schedule::TypeInfo ) )
26 {
27 compiler.errorMessenger.OutputFatalError();
28 }
29 return *pClass;
30}
31
32void Schedule::SpecifyAddressOf()
33{
34 if( type != Schedule::UserProc )
35 {
36 compiler.errorMessenger.OutputFatalError();
37 }
38 type = Schedule::AddressOf;
39}
40void Schedule::SpecifyCatchAddress()
41{
42 if( type != Schedule::UserProc )
43 {
44 compiler.errorMessenger.OutputFatalError();
45 }
46 type = Schedule::CatchAddress;
47}
48
49void NativeCode::PutEx( const NativeCode &nativeCode )
50{
51 long baseOffset = GetSize();
52
53 // コードバッファを追加
54 Put( nativeCode.GetBuffer(), nativeCode.GetSize() );
55
56 // スケジュールを追加
57 BOOST_FOREACH( const Schedule &schedule, nativeCode.schedules )
58 {
59 this->schedules.push_back(
60 Schedule(
61 schedule.GetType(),
62 baseOffset + schedule.GetOffset(),
63 schedule.GetLongPtrValue()
64 )
65 );
66 }
67
68 // ソースコード行番号とネイティブコード位置の対応情報を追加
69 BOOST_FOREACH( const SourceLine &sourceLine, nativeCode.sourceLines )
70 {
71 this->sourceLines.push_back(
72 SourceLine(
73 sourceLine.GetLineNum(),
74 baseOffset + sourceLine.GetNativeCodePos(),
75 sourceLine.GetSourceIndex(),
76 sourceLine.GetSourceCodePos(),
77 sourceLine.GetCodeType()
78 )
79 );
80 }
81}
82
83void NativeCode::PutEx( long l, Schedule::Type scheduleType )
84{
85 if( scheduleType == Schedule::CatchAddress )
86 {
87 const UserProc *pUserProc = &UserProc::CompilingUserProc();
88 if( UserProc::IsGlobalAreaCompiling() )
89 {
90 pUserProc = UserProc::pGlobalProc;
91 }
92 PutCatchAddressSchedule( pUserProc, l );
93 }
94 else
95 {
96 if( scheduleType != Schedule::None )
97 {
98 schedules.push_back( Schedule( scheduleType, GetSize() ) );
99 }
100
101 Put( l );
102 }
103}
104
105void NativeCode::PutUserProcSchedule( const UserProc *pUserProc, bool isCall )
106{
107 pUserProc->Using();
108
109 Schedule schedule( pUserProc, GetSize() );
110 if( isCall == false )
111 {
112 schedule.SpecifyAddressOf();
113 }
114 schedules.push_back( schedule );
115
116 Put( (long)0 );
117}
118
119void NativeCode::PutCatchAddressSchedule( const UserProc *pUserProc, long codePos )
120{
121 pUserProc->Using();
122
123 Schedule schedule( pUserProc, GetSize() );
124 schedule.SpecifyCatchAddress();
125 schedules.push_back( schedule );
126
127 Put( codePos );
128}
129
130void NativeCode::PutDllProcSchedule( const DllProc *pDllProc )
131{
132 pDllProc->Using();
133
134 schedules.push_back( Schedule( pDllProc, GetSize() ) );
135
136 Put( (long)0 );
137}
138
139void NativeCode::PutComVtblSchedule( const CClass *pClass )
140{
141 schedules.push_back( Schedule( Schedule::ComVtbl, pClass, GetSize() ) );
142
143 Put( (long)0 );
144}
145
146void NativeCode::PutVtblSchedule( const CClass *pClass )
147{
148 schedules.push_back( Schedule( Schedule::Vtbl, pClass, GetSize() ) );
149
150 Put( (long)0 );
151}
152
153void NativeCode::NextSourceLine()
154{
155 if( sourceLines.size() )
156 {
157 if( sourceLines.back().GetNativeCodePos() == GetSize() )
158 {
159 sourceLines.back().SetSourceCodePos( cp );
160 return;
161 }
162 }
163
164 extern BOOL bDebugSupportProc;
165 extern BOOL bSystemProc;
166 DWORD sourceLineType = 0;
167 if( bDebugSupportProc )
168 {
169 sourceLineType |= CODETYPE_DEBUGPROC;
170 }
171 if( bSystemProc )
172 {
173 sourceLineType |= CODETYPE_SYSTEMPROC;
174 }
175 sourceLines.push_back(
176 SourceLine(
177 (long)sourceLines.size(),
178 GetSize(),
179 compiler.GetObjectModule().GetCurrentSourceIndex(),
180 cp,
181 sourceLineType
182 )
183 );
184}
185
186void NativeCode::ResetDataSectionBaseOffset( long dataSectionBaseOffset )
187{
188 BOOST_FOREACH( const Schedule &schedule, schedules )
189 {
190 if( schedule.GetType() == Schedule::DataTable )
191 {
192 Overwrite(
193 schedule.GetOffset(),
194 GetLong( schedule.GetOffset() ) + dataSectionBaseOffset
195 );
196 }
197 }
198}
199void NativeCode::ResetSourceIndexes( long sourceIndexBase )
200{
201 BOOST_FOREACH( SourceLine &sourceLine, sourceLines )
202 {
203 sourceLine.SetSourceIndex( sourceLine.GetSourceIndex() + sourceIndexBase );
204 }
205}
Note: See TracBrowser for help on using the repository browser.