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

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

OutputFatalErrorをやめて_ASSERTに変更。

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