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

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

[585][586]をリバース。NativeCodeクラスとMetaクラスは依存関係があるので分離しない方針とする。

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