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

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

ファイルバージョンを更新(5.0.6.0にあげた)。
libファイルに関するメッセージを出力する際、ファイル名ではなく絶対パスを表示するようにした。

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