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

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

いくつかのグローバル変数をProgram/Debuggerクラスにまとめた。

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