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

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

CDefine::Initメソッドで使用するCompilerクラス依存のフラグを外部から引き渡すようにした。

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