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

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

libファイルを跨ったテンプレート展開に対応。

File size: 7.3 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 BOOST_FOREACH( const std::string &filePath, compiler.staticLibraryFilePaths )
205 {
206 Jenga::Common::Path path( filePath );
207 if( path.IsExistFile() )
208 {
209 compiler.staticLibraries.push_back( new ObjectModule() );
210 if( compiler.staticLibraries.back()->Read( filePath ) )
211 {
212 compiler.messenger.Output( ((std::string)"\"" + path.GetFullPath() + "\" を読み込みました。").c_str() );
213 }
214 else
215 {
216 compiler.errorMessenger.Output( 203, path.GetFullPath() );
217 isSuccessfulLoadStaticLinkLibrary = false;
218 }
219 }
220 else
221 {
222 compiler.errorMessenger.Output( 202, path.GetFullPath() );
223 isSuccessfulLoadStaticLinkLibrary = false;
224 }
225 }
226
227 if( !isSuccessfulLoadStaticLinkLibrary )
228 {
229 // 静的リンクライブラリのロードに失敗したとき
230 goto EndCompile;
231 }
232 }
233
234
235 ///////////////////////
236 // コンパイル開始
237
238 MakeExe();
239
240 //コンパイルダイアログのプログレスバーを上げる
241 StepCompileProgress();
242
243
244 //////////////////////////
245 // 終了処理
246EndCompile:
247 if(bStopCompile){
248 PostMessage(GetDlgItem(hMainDlg,IDC_PROGRESS),PBM_SETPOS,0,0);
249
250 //"コンパイルはユーザーにより中断されました。"
251 compiler.messenger.Output(STRING_COMPILE_STOP);
252 }
253 else{
254 extern int WarningNum;
255 if( !compiler.errorMessenger.HasError() )
256 {
257 //"コンパイルは正常に完了しました(エラー:%d、警告:%d)"
258 sprintf(temp2,
259 STRING_COMPILE_SUCCESS,
260 compiler.errorMessenger.GetErrorCount(),
261 compiler.errorMessenger.GetWarningCount(),
262 ((double)(GetTickCount() - beforeTickCount))/1000
263 );
264 }
265 else
266 {
267 //"コンパイルは中断されました(エラー:%d、警告:%d)"
268 sprintf(temp2,STRING_COMPILE_ERROR,
269 compiler.errorMessenger.GetErrorCount(),
270 compiler.errorMessenger.GetWarningCount() );
271 }
272
273 compiler.messenger.Output( "" );
274 compiler.messenger.Output( "-----------------------------------------------------" );
275 compiler.messenger.Output( temp2 );
276 }
277
278 //"閉じる"
279 SetDlgItemText(hMainDlg,IDOK,STRING_CLOSE);
280
281 // エラーがない場合はビルド成功とする
282 if( !compiler.errorMessenger.HasError() )
283 {
284 // ビルド成功
285 compiler.BuildSuccessful();
286 }
287
288#ifdef _DEBUG
289 // デバッグモードのときはダイアログが隠れている
290 ShowWindow(hMainDlg,SW_SHOW);
291#endif
292}
293void MainThread(void *dummy)
294{
295 if( program.IsDebugRun() )
296 {
297 if( compiler.IsDebug() )
298 {
299 //デバッグコンパイル
300 Build();
301 }
302
303 //デバッグ実行
304 if( !compiler.errorMessenger.HasError() )
305 {
306 DebugProgram();
307 }
308 }
309 else{
310 //リリースコンパイル
311 Build();
312 }
313}
Note: See TracBrowser for help on using the repository browser.