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

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

ビルドメッセージを文言変更

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