[232] | 1 | #include "stdafx.h"
|
---|
| 2 |
|
---|
[280] | 3 | #include <Compiler.h>
|
---|
[245] | 4 |
|
---|
[237] | 5 | #define BREAK_EIP(checkEip) (obp+0x00401000>=checkEip)
|
---|
[232] | 6 |
|
---|
[465] | 7 | const ::DllProc &Schedule::GetDllProc() const
|
---|
| 8 | {
|
---|
| 9 | if( type != Schedule::DllProc )
|
---|
| 10 | {
|
---|
| 11 | compiler.errorMessenger.OutputFatalError();
|
---|
| 12 | }
|
---|
| 13 | return *pDllProc;
|
---|
| 14 | }
|
---|
| 15 | const ::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 | }
|
---|
| 23 | const ::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 |
|
---|
| 32 | void Schedule::SpecifyAddressOf()
|
---|
| 33 | {
|
---|
| 34 | if( type != Schedule::UserProc )
|
---|
| 35 | {
|
---|
| 36 | compiler.errorMessenger.OutputFatalError();
|
---|
| 37 | }
|
---|
| 38 | type = Schedule::AddressOf;
|
---|
| 39 | }
|
---|
| 40 | void Schedule::SpecifyCatchAddress()
|
---|
| 41 | {
|
---|
| 42 | if( type != Schedule::UserProc )
|
---|
| 43 | {
|
---|
| 44 | compiler.errorMessenger.OutputFatalError();
|
---|
| 45 | }
|
---|
| 46 | type = Schedule::CatchAddress;
|
---|
| 47 | }
|
---|
| 48 |
|
---|
[287] | 49 | void NativeCode::PutEx( const NativeCode &nativeCode )
|
---|
[232] | 50 | {
|
---|
[287] | 51 | long baseOffset = GetSize();
|
---|
[257] | 52 |
|
---|
[263] | 53 | // コードバッファを追加
|
---|
[287] | 54 | Put( nativeCode.GetBuffer(), nativeCode.GetSize() );
|
---|
[257] | 55 |
|
---|
[263] | 56 | // スケジュールを追加
|
---|
[257] | 57 | BOOST_FOREACH( const Schedule &schedule, nativeCode.schedules )
|
---|
| 58 | {
|
---|
| 59 | this->schedules.push_back(
|
---|
| 60 | Schedule(
|
---|
| 61 | schedule.GetType(),
|
---|
[258] | 62 | baseOffset + schedule.GetOffset(),
|
---|
| 63 | schedule.GetLongPtrValue()
|
---|
[257] | 64 | )
|
---|
| 65 | );
|
---|
| 66 | }
|
---|
[263] | 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(),
|
---|
[280] | 75 | sourceLine.GetSourceIndex(),
|
---|
[263] | 76 | sourceLine.GetSourceCodePos(),
|
---|
| 77 | sourceLine.GetCodeType()
|
---|
| 78 | )
|
---|
| 79 | );
|
---|
| 80 | }
|
---|
[257] | 81 | }
|
---|
| 82 |
|
---|
[357] | 83 | void NativeCode::PutEx( long l, Schedule::Type scheduleType )
|
---|
| 84 | {
|
---|
| 85 | if( scheduleType == Schedule::CatchAddress )
|
---|
| 86 | {
|
---|
[364] | 87 | const UserProc *pUserProc = &UserProc::CompilingUserProc();
|
---|
| 88 | if( UserProc::IsGlobalAreaCompiling() )
|
---|
| 89 | {
|
---|
| 90 | pUserProc = UserProc::pGlobalProc;
|
---|
| 91 | }
|
---|
| 92 | PutCatchAddressSchedule( pUserProc, l );
|
---|
[357] | 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 |
|
---|
[245] | 105 | void NativeCode::PutUserProcSchedule( const UserProc *pUserProc, bool isCall )
|
---|
| 106 | {
|
---|
| 107 | pUserProc->Using();
|
---|
| 108 |
|
---|
[287] | 109 | Schedule schedule( pUserProc, GetSize() );
|
---|
[245] | 110 | if( isCall == false )
|
---|
| 111 | {
|
---|
| 112 | schedule.SpecifyAddressOf();
|
---|
| 113 | }
|
---|
| 114 | schedules.push_back( schedule );
|
---|
| 115 |
|
---|
[287] | 116 | Put( (long)0 );
|
---|
[245] | 117 | }
|
---|
[250] | 118 |
|
---|
[357] | 119 | void 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 |
|
---|
[250] | 130 | void NativeCode::PutDllProcSchedule( const DllProc *pDllProc )
|
---|
| 131 | {
|
---|
| 132 | pDllProc->Using();
|
---|
| 133 |
|
---|
[287] | 134 | schedules.push_back( Schedule( pDllProc, GetSize() ) );
|
---|
[250] | 135 |
|
---|
[287] | 136 | Put( (long)0 );
|
---|
[250] | 137 | }
|
---|
[263] | 138 |
|
---|
[370] | 139 | void NativeCode::PutComVtblSchedule( const CClass *pClass )
|
---|
| 140 | {
|
---|
| 141 | schedules.push_back( Schedule( Schedule::ComVtbl, pClass, GetSize() ) );
|
---|
| 142 |
|
---|
| 143 | Put( (long)0 );
|
---|
| 144 | }
|
---|
| 145 |
|
---|
[282] | 146 | void NativeCode::PutVtblSchedule( const CClass *pClass )
|
---|
| 147 | {
|
---|
[370] | 148 | schedules.push_back( Schedule( Schedule::Vtbl, pClass, GetSize() ) );
|
---|
[282] | 149 |
|
---|
[287] | 150 | Put( (long)0 );
|
---|
[282] | 151 | }
|
---|
| 152 |
|
---|
[263] | 153 | void NativeCode::NextSourceLine()
|
---|
| 154 | {
|
---|
| 155 | if( sourceLines.size() )
|
---|
| 156 | {
|
---|
[287] | 157 | if( sourceLines.back().GetNativeCodePos() == GetSize() )
|
---|
[263] | 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 | }
|
---|
[280] | 175 | sourceLines.push_back(
|
---|
| 176 | SourceLine(
|
---|
| 177 | (long)sourceLines.size(),
|
---|
[287] | 178 | GetSize(),
|
---|
[280] | 179 | compiler.GetObjectModule().GetCurrentSourceIndex(),
|
---|
| 180 | cp,
|
---|
| 181 | sourceLineType
|
---|
| 182 | )
|
---|
| 183 | );
|
---|
[263] | 184 | }
|
---|
[273] | 185 |
|
---|
| 186 | void 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 | }
|
---|
[280] | 199 | void NativeCode::ResetSourceIndexes( long sourceIndexBase )
|
---|
| 200 | {
|
---|
| 201 | BOOST_FOREACH( SourceLine &sourceLine, sourceLines )
|
---|
| 202 | {
|
---|
| 203 | sourceLine.SetSourceIndex( sourceLine.GetSourceIndex() + sourceIndexBase );
|
---|
| 204 | }
|
---|
| 205 | }
|
---|