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

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

依存関係を整理中

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