source: dev/trunk/ab5.0/abdev/BasicCompiler_Common/MakeExe.cpp@ 639

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

静的リンクリンカの依存関係解決モジュールを製作中

File size: 7.4 KB
Line 
1#include "stdafx.h"
2
3#include <Compiler.h>
4
5#include "common.h"
6#include <ver.h>
7
8void StepCompileProgress(void){
9 extern HWND hMainDlg;
10 PostMessage(GetDlgItem(hMainDlg,IDC_PROGRESS),PBM_STEPIT,0,0);
11}
12
13void MakeMiddleCode( char *buffer )
14{
15 // 改行コードをCRLFからLFにする
16 ChangeReturnCode( buffer );
17
18 // コメントを除去
19 DeleteComment( buffer );
20
21 //エスケープシーケンス設定
22 SetEscapeSequenceFormat( buffer );
23
24 //コマンド対応
25 ChangeCommandToCode( buffer );
26}
27
28void AddSourceCode(const char *buffer){
29 char *temp;
30 temp=(char *)HeapAlloc(hHeap,0,lstrlen(buffer)+8192);
31 lstrcpy(temp,buffer);
32
33 MakeMiddleCode( temp );
34
35 //最後尾に貼り付け
36 compiler.GetObjectModule().GetSource().Addition( temp );
37
38 HeapDefaultFree(temp);
39}
40
41void Build()
42{
43 extern HANDLE hHeap;
44 extern char *basbuf;
45 extern BOOL bStopCompile;
46 extern HWND hMainDlg;
47 char temp2[MAX_PATH];
48
49 // 開始時刻を記録
50 DWORD beforeTickCount = GetTickCount();
51
52 //プログレスバーの設定
53 PostMessage(GetDlgItem(hMainDlg,IDC_PROGRESS),PBM_SETRANGE,0,MAKELPARAM(0,6));
54 PostMessage(GetDlgItem(hMainDlg,IDC_PROGRESS),PBM_SETSTEP,1,0);
55
56 //"中断"
57 SetDlgItemText(hMainDlg,IDOK,STRING_STOP);
58
59 //中断フラグを初期化
60 bStopCompile=0;
61
62 //サブシステムのタイプ
63 extern unsigned short TypeOfSubSystem;
64 TypeOfSubSystem=IMAGE_SUBSYSTEM_WINDOWS_GUI;
65
66 // オブジェクトモジュール名をセットする
67 compiler.GetObjectModule().SetName( program.GetOutputFileName() );
68
69 //プログラムをファイルから読み込む
70 bool result = compiler.GetObjectModule().GetSource().ReadFile(
71 program.GetSourceFilePath(),
72 compiler.IsDebug(),
73 compiler.IsDll(),
74 compiler.IsUnicode(),
75 MAJOR_VER,
76 program.GetSourceFilePath(),
77 program.GetIncludeDir()
78 );
79 if( !result ){
80 compiler.errorMessenger.Output(201,program.GetSourceFilePath(),-1);
81 goto EndCompile;
82 }
83 if( !compiler.GetCurrentSource().cannotIncludePath.empty() )
84 {
85 compiler.errorMessenger.Output(
86 35,
87 compiler.GetCurrentSource().cannotIncludePath,
88 compiler.GetCurrentSource().cannotIncludeSourcePos
89 );
90 goto EndCompile;
91 }
92
93 //イメージベースの設定
94 extern DWORD ImageBase;
95 if(compiler.IsDll()) ImageBase=0x10000000;
96 else ImageBase=0x00400000;
97
98 if( compiler.errorMessenger.HasError() || bStopCompile ) goto EndCompile;
99
100
101 //////////////////////////
102 // 中間コードの生成を開始
103
104 //"最適化中..."
105 compiler.messenger.Output( STRING_COMPILE_OPTIMIZING );
106
107 //カッコを相互チェック(ダブルクォートチェックチェックを含む)
108 CheckParenthesis(basbuf);
109
110 if( compiler.errorMessenger.HasError() || bStopCompile )
111 {
112 goto EndCompile;
113 }
114
115 //コンパイルダイアログのプログレスバーを上げる
116 StepCompileProgress();
117
118 //ディレクティブ
119 DirectiveCheck();
120
121 //Next命令語を正規表現に変換
122 //NextCommandFormat(basbuf);
123
124 //エスケープシーケンス設定
125 SetEscapeSequenceFormat(basbuf);
126
127 //Def命令語をFunction命令語に変換
128 DefCommandFormat(basbuf);
129
130 //すべてのIf命令語をブロック形式に変換
131 IfCommandFormat(basbuf);
132
133 //対になる命令語を相互チェック
134 //CheckPareCommand();
135
136 if( compiler.errorMessenger.HasError() || bStopCompile )
137 {
138 goto EndCompile;
139 }
140
141 //コンパイルダイアログのプログレスバーを上げる
142 StepCompileProgress();
143
144 // 重複エラー情報をクリア
145 compiler.errorMessenger.ClearSynonymKeyWords();
146
147 ChangeCommandToCode(basbuf);
148 compiler.GetObjectModule().GetSource()._ResetLength();
149
150 if( compiler.errorMessenger.HasError() || bStopCompile )
151 {
152 //定数に関する情報を解放
153 goto EndCompile;
154 }
155
156 StepCompileProgress();
157
158
159 /////////////////////////////////////////////////////////////////
160 // 静的リンクライブラリをロードする
161 /////////////////////////////////////////////////////////////////
162 {
163 bool isSuccessfulLoadStaticLinkLibrary = true;
164 if( !compiler.IsCore() )
165 {
166 // コアモジュールをロードする
167 extern BOOL bDebugCompile;
168
169 const char *coreFileName = "core.lib";
170 if( compiler.IsDebug() )
171 {
172 coreFileName = "cored.lib";
173 }
174
175 char coreFilePath[MAX_PATH];
176#ifdef _AMD64_
177 sprintf( coreFilePath, "..\\lib\\x64\\%s", coreFileName );
178#else
179 sprintf( coreFilePath, "..\\lib\\%s", coreFileName );
180#endif
181 GetFullPath( coreFilePath, program.GetIncludeDir() );
182
183 Jenga::Common::Path path( coreFilePath );
184 if( path.IsExistFile() )
185 {
186 compiler.staticLibraries.push_back( new ObjectModule() );
187 if( compiler.staticLibraries.back()->Read( coreFilePath ) )
188 {
189 compiler.messenger.Output( ((std::string)"\"" + path.GetFullPath() + "\" を読み込みました。").c_str() );
190 }
191 else
192 {
193 compiler.errorMessenger.Output( 203, path.GetFullPath() );
194 isSuccessfulLoadStaticLinkLibrary = false;
195 }
196 }
197 else
198 {
199 compiler.errorMessenger.Output( 202, path.GetFullPath() );
200 isSuccessfulLoadStaticLinkLibrary = false;
201 }
202 }
203
204 ActiveBasic::Common::Environment::SetRemoveExternalMark( true );
205
206 BOOST_FOREACH( const std::string &filePath, compiler.staticLibraryFilePaths )
207 {
208 Jenga::Common::Path path( filePath );
209 if( path.IsExistFile() )
210 {
211 compiler.staticLibraries.push_back( new ObjectModule() );
212 if( compiler.staticLibraries.back()->Read( filePath ) )
213 {
214 compiler.messenger.Output( ((std::string)"\"" + path.GetFullPath() + "\" を読み込みました。").c_str() );
215 }
216 else
217 {
218 compiler.errorMessenger.Output( 203, path.GetFullPath() );
219 isSuccessfulLoadStaticLinkLibrary = false;
220 }
221 }
222 else
223 {
224 compiler.errorMessenger.Output( 202, path.GetFullPath() );
225 isSuccessfulLoadStaticLinkLibrary = false;
226 }
227 }
228
229 ActiveBasic::Common::Environment::SetRemoveExternalMark( false );
230
231 if( !isSuccessfulLoadStaticLinkLibrary )
232 {
233 // 静的リンクライブラリのロードに失敗したとき
234 goto EndCompile;
235 }
236 }
237
238
239 ///////////////////////
240 // コンパイル開始
241
242 MakeExe();
243
244 //コンパイルダイアログのプログレスバーを上げる
245 StepCompileProgress();
246
247
248 //////////////////////////
249 // 終了処理
250EndCompile:
251 if(bStopCompile){
252 PostMessage(GetDlgItem(hMainDlg,IDC_PROGRESS),PBM_SETPOS,0,0);
253
254 //"コンパイルはユーザーにより中断されました。"
255 compiler.messenger.Output(STRING_COMPILE_STOP);
256 }
257 else{
258 extern int WarningNum;
259 if( !compiler.errorMessenger.HasError() )
260 {
261 //"コンパイルは正常に完了しました(エラー:%d、警告:%d)"
262 sprintf(temp2,
263 STRING_COMPILE_SUCCESS,
264 compiler.errorMessenger.GetErrorCount(),
265 compiler.errorMessenger.GetWarningCount(),
266 ((double)(GetTickCount() - beforeTickCount))/1000
267 );
268 }
269 else
270 {
271 //"コンパイルは中断されました(エラー:%d、警告:%d)"
272 sprintf(temp2,STRING_COMPILE_ERROR,
273 compiler.errorMessenger.GetErrorCount(),
274 compiler.errorMessenger.GetWarningCount() );
275 }
276
277 compiler.messenger.Output( "" );
278 compiler.messenger.Output( "-----------------------------------------------------" );
279 compiler.messenger.Output( temp2 );
280 }
281
282 //"閉じる"
283 SetDlgItemText(hMainDlg,IDOK,STRING_CLOSE);
284
285 // エラーがない場合はビルド成功とする
286 if( !compiler.errorMessenger.HasError() )
287 {
288 // ビルド成功
289 compiler.BuildSuccessful();
290 }
291
292#ifdef _DEBUG
293 // デバッグモードのときはダイアログが隠れている
294 ShowWindow(hMainDlg,SW_SHOW);
295#endif
296}
297void MainThread(void *dummy)
298{
299 if( program.IsDebugRun() )
300 {
301 if( compiler.IsDebug() )
302 {
303 //デバッグコンパイル
304 Build();
305 }
306
307 //デバッグ実行
308 if( !compiler.errorMessenger.HasError() )
309 {
310 DebugProgram();
311 }
312 }
313 else{
314 //リリースコンパイル
315 Build();
316 }
317}
Note: See TracBrowser for help on using the repository browser.