source: dev/trunk/abdev/BasicCompiler_Common/src/Linker.cpp@ 257

Last change on this file since 257 was 257, checked in by dai_9181, 17 years ago
File size: 3.3 KB
Line 
1#include "stdafx.h"
2
3#include <Compiler.h>
4
5
6// データテーブルスケジュール
7void Linker::ResolveDataTableSchedules( long dataSectionBaseOffset )
8{
9 BOOST_FOREACH( const Schedule &schedule, nativeCode.GetSchedules() )
10 {
11 if( schedule.GetType() == Schedule::DataTable )
12 {
13 nativeCode.Overwrite(
14 schedule.GetOffset(),
15 static_cast<long>( nativeCode.GetLong( schedule.GetOffset() ) + imageBase + dataSectionBaseOffset )
16 );
17 }
18 }
19}
20
21// DLL関数スケジュール
22void Linker::ResolveDllProcSchedules( long codeSectionBaseOffset, long importSectionBaseOffset )
23{
24 BOOST_FOREACH( const Schedule &schedule, nativeCode.GetSchedules() )
25 {
26 if( schedule.GetType() == Schedule::DllProc )
27 {
28#ifdef _AMD64
29 nativeCode.Overwrite(
30 schedule.GetOffset(),
31 static_cast<long>( importSectionBaseOffset + schedule.GetDllProc().GetLookupAddress()
32 - ( codeSectionBaseOffset + schedule.GetOffset() + sizeof(long) ) )
33 );
34#else
35 // TODO: 未完成
36 SetError();
37#endif
38 }
39 }
40}
41
42// ユーザ定義関数スケジュール
43void Linker::ResolveUserProcSchedules( long codeSectionBaseOffset )
44{
45 BOOST_FOREACH( const Schedule &schedule, nativeCode.GetSchedules() )
46 {
47 if( schedule.GetType() == Schedule::UserProc
48 || schedule.GetType() == Schedule::AddressOf )
49 {
50 if( schedule.GetUserProc().GetBeginOpAddress() == 0
51 && schedule.GetUserProc().GetEndOpAddress() == 0 )
52 {
53 SetError();
54 }
55
56 if( schedule.GetType() == Schedule::UserProc )
57 {
58 nativeCode.Overwrite(
59 schedule.GetOffset(),
60 static_cast<long>( schedule.GetUserProc().GetBeginOpAddress() - ( schedule.GetOffset() + sizeof(long) ) )
61 );
62 }
63 else if( schedule.GetType() == Schedule::AddressOf )
64 {
65 nativeCode.Overwrite(
66 schedule.GetOffset(),
67 static_cast<long>( schedule.GetUserProc().GetBeginOpAddress() + imageBase + codeSectionBaseOffset )
68 );
69 }
70 }
71 }
72}
73
74// グローバル変数スケジュール
75void Linker::ResolveGlobalVarSchedules( long rwSectionBaseOffset )
76{
77 BOOST_FOREACH( const Schedule &schedule, nativeCode.GetSchedules() )
78 {
79 if( schedule.GetType() == Schedule::GlobalVar )
80 {
81 if( nativeCode.GetLong( schedule.GetOffset() ) & 0x80000000 )
82 {
83 extern int AllInitGlobalVarSize;
84 nativeCode.Overwrite(
85 schedule.GetOffset(),
86 static_cast<long>( AllInitGlobalVarSize + (nativeCode.GetLong( schedule.GetOffset() ) & 0x7FFFFFFF) + imageBase + rwSectionBaseOffset )
87 );
88 }
89 else
90 {
91 nativeCode.Overwrite(
92 schedule.GetOffset(),
93 static_cast<long>( nativeCode.GetLong( schedule.GetOffset() ) + imageBase + rwSectionBaseOffset )
94 );
95 }
96 }
97 }
98}
99
100void Linker::Link( vector<ObjectModule *> &objectModules )
101{
102 /*
103 BOOST_FOREACH( ObjectModule *pObjectModule, objectModules )
104 {
105 }*/
106 ObjectModule &masterObjectModule = *objectModules[0];
107
108 nativeCode.Put( masterObjectModule.globalNativeCode );
109
110 masterObjectModule.meta.GetUserProcs().Iterator_Reset();
111 while( masterObjectModule.meta.GetUserProcs().Iterator_HasNext() )
112 {
113 const UserProc *pUserProc = masterObjectModule.meta.GetUserProcs().Iterator_GetNext();
114
115 if( pUserProc->IsUsing() )
116 {
117 pUserProc->SetBeginOpAddress( nativeCode.GetSize() );
118
119 nativeCode.Put( pUserProc->GetNativeCode() );
120
121 pUserProc->SetEndOpAddress( nativeCode.GetSize() );
122 }
123 }
124}
Note: See TracBrowser for help on using the repository browser.