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

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

ヘッダファイルを整理中

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