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

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

CollectTypeDefsメソッドをLexicalAnalyzerクラスに移動した。

File size: 7.3 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 //"コンパイル中..."
218 compiler.messenger.Output(STRING_COMPILE_COMPILING);
219
220 Compile();
221
222 //リソース情報を解放
223 extern RESOURCEDATAINFO *pCursorResourceInfo;
224 extern RESOURCEDATAINFO *pIconResourceInfo;
225 extern RESOURCEDATAINFO *pBitmapResourceInfo;
226 HeapDefaultFree(pCursorResourceInfo);
227 HeapDefaultFree(pBitmapResourceInfo);
228 HeapDefaultFree(pIconResourceInfo);
229
230 //コンパイルダイアログのプログレスバーを上げる
231 StepCompileProgress();
232
233
234 //////////////////////////
235 // 終了処理
236EndCompile:
237 if(bStopCompile){
238 PostMessage(GetDlgItem(hMainDlg,IDC_PROGRESS),PBM_SETPOS,0,0);
239
240 //"コンパイルはユーザーにより中断されました。"
241 compiler.messenger.Output(STRING_COMPILE_STOP);
242 }
243 else{
244 extern int WarningNum;
245 if( !compiler.errorMessenger.HasError() )
246 {
247 //"コンパイルは正常に完了しました(エラー:%d、警告:%d)"
248 sprintf(temp2,
249 STRING_COMPILE_SUCCESS,
250 compiler.errorMessenger.GetErrorCount(),
251 compiler.errorMessenger.GetWarningCount(),
252 ((double)(GetTickCount() - beforeTickCount))/1000
253 );
254 }
255 else
256 {
257 //"コンパイルは中断されました(エラー:%d、警告:%d)"
258 sprintf(temp2,STRING_COMPILE_ERROR,
259 compiler.errorMessenger.GetErrorCount(),
260 compiler.errorMessenger.GetWarningCount() );
261 }
262
263 compiler.messenger.Output( "" );
264 compiler.messenger.Output( "-----------------------------------------------------" );
265 compiler.messenger.Output( temp2 );
266 }
267
268 //"閉じる"
269 SetDlgItemText(hMainDlg,IDOK,STRING_CLOSE);
270
271 // エラーがない場合はビルド成功とする
272 if( !compiler.errorMessenger.HasError() )
273 {
274 // ビルド成功
275 compiler.BuildSuccessful();
276 }
277
278#ifdef _DEBUG
279 // デバッグモードのときはダイアログが隠れている
280 ShowWindow(hMainDlg,SW_SHOW);
281#endif
282}
283void MainThread(void *dummy)
284{
285 if( program.IsDebugRun() )
286 {
287 if( compiler.IsDebug() )
288 {
289 //デバッグコンパイル
290 OutputExe();
291 }
292
293 //デバッグ実行
294 if( !compiler.errorMessenger.HasError() )
295 {
296 DebugProgram();
297 }
298 }
299 else{
300 //リリースコンパイル
301 OutputExe();
302 }
303}
Note: See TracBrowser for help on using the repository browser.