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

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

OutputExe→Build
Compile()→MakeExe

File size: 7.7 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().GetCurrentSource().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().SetCurrentSourceIndex( (int)compiler.GetObjectModule().GetSources().size() );
68 compiler.GetObjectModule().GetSources().push_back( BasicSource() );
69 bool result = compiler.GetObjectModule().GetCurrentSource().ReadFile(
70 program.GetSourceFilePath(),
71 compiler.IsDebug(),
72 compiler.IsDll(),
73 compiler.IsUnicode(),
74 MAJOR_VER,
75 program.GetSourceFilePath(),
76 program.GetIncludeDir()
77 );
78 if( !result ){
79 compiler.errorMessenger.Output(201,program.GetSourceFilePath(),-1);
80 goto EndCompile;
81 }
82 if( !compiler.GetObjectModule().GetCurrentSource().cannotIncludePath.empty() )
83 {
84 compiler.errorMessenger.Output(
85 35,
86 compiler.GetObjectModule().GetCurrentSource().cannotIncludePath,
87 compiler.GetObjectModule().GetCurrentSource().cannotIncludeSourcePos
88 );
89 goto EndCompile;
90 }
91
92 //イメージベースの設定
93 extern DWORD ImageBase;
94 if(compiler.IsDll()) ImageBase=0x10000000;
95 else ImageBase=0x00400000;
96
97 if( compiler.errorMessenger.HasError() || bStopCompile ) goto EndCompile;
98
99
100 //////////////////////////
101 // 中間コードの生成を開始
102
103 //"最適化中..."
104 compiler.messenger.Output( STRING_COMPILE_OPTIMIZING );
105
106 //カッコを相互チェック(ダブルクォートチェックチェックを含む)
107 CheckParenthesis(basbuf);
108
109 if( compiler.errorMessenger.HasError() || bStopCompile )
110 {
111 goto EndCompile;
112 }
113
114 //コンパイルダイアログのプログレスバーを上げる
115 StepCompileProgress();
116
117 //ディレクティブ
118 DirectiveCheck();
119
120 //Next命令語を正規表現に変換
121 //NextCommandFormat(basbuf);
122
123 //エスケープシーケンス設定
124 SetEscapeSequenceFormat(basbuf);
125
126 //Def命令語をFunction命令語に変換
127 DefCommandFormat(basbuf);
128
129 //すべてのIf命令語をブロック形式に変換
130 IfCommandFormat(basbuf);
131
132 //対になる命令語を相互チェック
133 //CheckPareCommand();
134
135 if( compiler.errorMessenger.HasError() || bStopCompile )
136 {
137 goto EndCompile;
138 }
139
140 //コンパイルダイアログのプログレスバーを上げる
141 StepCompileProgress();
142
143 // 重複エラー情報をクリア
144 compiler.errorMessenger.ClearSynonymKeyWords();
145
146 ChangeCommandToCode(basbuf);
147 compiler.GetObjectModule().GetSources()[0]._ResetLength();
148
149 if( compiler.errorMessenger.HasError() || bStopCompile )
150 {
151 //定数に関する情報を解放
152 goto EndCompile;
153 }
154
155 StepCompileProgress();
156
157
158 /////////////////////////////////////////////////////////////////
159 // 静的リンクライブラリをロードする
160 /////////////////////////////////////////////////////////////////
161 {
162 bool isSuccessfulLoadStaticLinkLibrary = true;
163 if( !compiler.IsCore() )
164 {
165 // コアモジュールをロードする
166 extern BOOL bDebugCompile;
167
168 const char *coreFileName = "core.lib";
169 if( compiler.IsDebug() )
170 {
171 coreFileName = "cored.lib";
172 }
173
174 char coreFilePath[MAX_PATH];
175#ifdef _AMD64_
176 sprintf( coreFilePath, "..\\lib\\x64\\%s", coreFileName );
177#else
178 sprintf( coreFilePath, "..\\lib\\%s", coreFileName );
179#endif
180 GetFullPath( coreFilePath, program.GetIncludeDir() );
181
182 Jenga::Common::Path path( coreFilePath );
183 if( path.IsExistFile() )
184 {
185 compiler.staticLibraries.push_back( new ObjectModule() );
186 if( compiler.staticLibraries.back()->Read( coreFilePath ) )
187 {
188 compiler.messenger.Output( ((std::string)"\"" + path.GetFullPath() + "\" を読み込みました。").c_str() );
189 }
190 else
191 {
192 compiler.errorMessenger.Output( 203, path.GetFullPath() );
193 isSuccessfulLoadStaticLinkLibrary = false;
194 }
195 }
196 else
197 {
198 compiler.errorMessenger.Output( 202, path.GetFullPath() );
199 isSuccessfulLoadStaticLinkLibrary = false;
200 }
201 }
202
203 BOOST_FOREACH( const std::string &filePath, compiler.staticLibraryFilePaths )
204 {
205 Jenga::Common::Path path( filePath );
206 if( path.IsExistFile() )
207 {
208 compiler.staticLibraries.push_back( new ObjectModule() );
209 if( compiler.staticLibraries.back()->Read( filePath ) )
210 {
211 compiler.messenger.Output( ((std::string)"\"" + path.GetFullPath() + "\" を読み込みました。").c_str() );
212 }
213 else
214 {
215 compiler.errorMessenger.Output( 203, path.GetFullPath() );
216 isSuccessfulLoadStaticLinkLibrary = false;
217 }
218 }
219 else
220 {
221 compiler.errorMessenger.Output( 202, path.GetFullPath() );
222 isSuccessfulLoadStaticLinkLibrary = false;
223 }
224 }
225
226 if( !isSuccessfulLoadStaticLinkLibrary )
227 {
228 // 静的リンクライブラリのロードに失敗したとき
229 goto EndCompile;
230 }
231 }
232
233
234 ///////////////////////
235 // コンパイル開始
236
237 MakeExe();
238
239 //リソース情報を解放
240 extern RESOURCEDATAINFO *pCursorResourceInfo;
241 extern RESOURCEDATAINFO *pIconResourceInfo;
242 extern RESOURCEDATAINFO *pBitmapResourceInfo;
243 HeapDefaultFree(pCursorResourceInfo);
244 HeapDefaultFree(pBitmapResourceInfo);
245 HeapDefaultFree(pIconResourceInfo);
246
247 //コンパイルダイアログのプログレスバーを上げる
248 StepCompileProgress();
249
250
251 //////////////////////////
252 // 終了処理
253EndCompile:
254 if(bStopCompile){
255 PostMessage(GetDlgItem(hMainDlg,IDC_PROGRESS),PBM_SETPOS,0,0);
256
257 //"コンパイルはユーザーにより中断されました。"
258 compiler.messenger.Output(STRING_COMPILE_STOP);
259 }
260 else{
261 extern int WarningNum;
262 if( !compiler.errorMessenger.HasError() )
263 {
264 //"コンパイルは正常に完了しました(エラー:%d、警告:%d)"
265 sprintf(temp2,
266 STRING_COMPILE_SUCCESS,
267 compiler.errorMessenger.GetErrorCount(),
268 compiler.errorMessenger.GetWarningCount(),
269 ((double)(GetTickCount() - beforeTickCount))/1000
270 );
271 }
272 else
273 {
274 //"コンパイルは中断されました(エラー:%d、警告:%d)"
275 sprintf(temp2,STRING_COMPILE_ERROR,
276 compiler.errorMessenger.GetErrorCount(),
277 compiler.errorMessenger.GetWarningCount() );
278 }
279
280 compiler.messenger.Output( "" );
281 compiler.messenger.Output( "-----------------------------------------------------" );
282 compiler.messenger.Output( temp2 );
283 }
284
285 //"閉じる"
286 SetDlgItemText(hMainDlg,IDOK,STRING_CLOSE);
287
288 // エラーがない場合はビルド成功とする
289 if( !compiler.errorMessenger.HasError() )
290 {
291 // ビルド成功
292 compiler.BuildSuccessful();
293 }
294
295#ifdef _DEBUG
296 // デバッグモードのときはダイアログが隠れている
297 ShowWindow(hMainDlg,SW_SHOW);
298#endif
299}
300void MainThread(void *dummy)
301{
302 if( program.IsDebugRun() )
303 {
304 if( compiler.IsDebug() )
305 {
306 //デバッグコンパイル
307 Build();
308 }
309
310 //デバッグ実行
311 if( !compiler.errorMessenger.HasError() )
312 {
313 DebugProgram();
314 }
315 }
316 else{
317 //リリースコンパイル
318 Build();
319 }
320}
Note: See TracBrowser for help on using the repository browser.