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

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

デプロイ時にcore.lib/cored.libのビルドもできるようにした。

File size: 7.6 KB
RevLine 
[206]1#include "stdafx.h"
2
[294]3#include <jenga/include/common/Path.h>
[182]4
[206]5#include <Compiler.h>
6
[4]7#include "common.h"
8
9void StepCompileProgress(void){
10 extern HWND hMainDlg;
11 PostMessage(GetDlgItem(hMainDlg,IDC_PROGRESS),PBM_STEPIT,0,0);
12}
13
[350]14void MakeMiddleCode( char *buffer )
15{
[322]16 // 改行コードをCRLFからLFにする
[350]17 ChangeReturnCode( buffer );
[322]18
19 // コメントを除去
[350]20 DeleteComment( buffer );
[322]21
[15]22 //エスケープシーケンス設定
[350]23 SetEscapeSequenceFormat( buffer );
[15]24
25 //コマンド対応
[350]26 ChangeCommandToCode( buffer );
27}
[15]28
[350]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
[15]36 //最後尾に貼り付け
[280]37 compiler.GetObjectModule().GetCurrentSource().Addition( temp );
[15]38
39 HeapDefaultFree(temp);
40}
41
[4]42void OutputExe(void){
43 extern HANDLE hHeap;
44 extern char *basbuf;
45 extern BOOL bStopCompile;
46 extern HWND hMainDlg;
[279]47 int i3;
[4]48 char temp2[MAX_PATH];
49
[266]50 // 開始時刻を記録
51 DWORD beforeTickCount = GetTickCount();
52
[4]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 //プログラムをファイルから読み込む
[308]68 compiler.GetObjectModule().SetCurrentSourceIndex( (int)compiler.GetObjectModule().GetSources().size() );
[280]69 compiler.GetObjectModule().GetSources().push_back( BasicSource() );
[467]70 if( !compiler.GetObjectModule().GetCurrentSource().ReadFile( program.GetSourceFilePath() ) ){
71 compiler.errorMessenger.Output(201,program.GetSourceFilePath(),-1);
[15]72 goto EndCompile;
73 }
[4]74
75 //イメージベースの設定
76 extern DWORD ImageBase;
[266]77 if(compiler.IsDll()) ImageBase=0x10000000;
[4]78 else ImageBase=0x00400000;
79
[465]80 if( compiler.errorMessenger.HasError() || bStopCompile ) goto EndCompile;
[4]81
82
83 //////////////////////////
84 // 中間コードの生成を開始
85
86 //"最適化中..."
[465]87 compiler.messenger.Output( STRING_COMPILE_OPTIMIZING );
[4]88
89 //カッコを相互チェック(ダブルクォートチェックチェックを含む)
90 CheckParenthesis(basbuf);
91
[465]92 if( compiler.errorMessenger.HasError() || bStopCompile )
93 {
94 goto EndCompile;
95 }
[4]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
[465]118 if( compiler.errorMessenger.HasError() || bStopCompile )
119 {
120 goto EndCompile;
121 }
[4]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);
[304]133 compiler.GetObjectModule().GetSources()[0]._ResetLength();
[4]134
135 //重複エラー情報管理のメモリを解放
136 for(i3=0;i3<SynonymErrorNum;i3++) HeapDefaultFree(SynonymErrorWords[i3]);
137 HeapDefaultFree(SynonymErrorWords);
[75]138 SynonymErrorWords=0;
[4]139
[465]140 if( compiler.errorMessenger.HasError() || bStopCompile )
141 {
[4]142 //定数に関する情報を解放
143 goto EndCompile;
144 }
145
146 StepCompileProgress();
147
148
[294]149 /////////////////////////////////////////////////////////////////
150 // 静的リンクライブラリをロードする
151 /////////////////////////////////////////////////////////////////
152 {
[315]153 bool isSuccessfulLoadStaticLinkLibrary = true;
154 if( !compiler.IsCore() )
[294]155 {
[315]156 // コアモジュールをロードする
157 extern BOOL bDebugCompile;
[294]158
[315]159 const char *coreFileName = "core.lib";
[459]160 if( compiler.IsDebug() )
[315]161 {
162 coreFileName = "cored.lib";
163 }
164
165 char coreFilePath[MAX_PATH];
[308]166#ifdef _AMD64_
[315]167 sprintf( coreFilePath, "..\\lib\\x64\\%s", coreFileName );
[308]168#else
[315]169 sprintf( coreFilePath, "..\\lib\\%s", coreFileName );
[308]170#endif
[467]171 GetFullPath( coreFilePath, program.GetIncludeDir() );
[294]172
[315]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 {
[466]179 compiler.messenger.Output( ((string)"\"" + path.GetFullPath() + "\" を読み込みました。").c_str() );
[315]180 }
181 else
182 {
[472]183 compiler.errorMessenger.Output( 203, path.GetFullPath() );
[315]184 isSuccessfulLoadStaticLinkLibrary = false;
185 }
186 }
187 else
188 {
[472]189 compiler.errorMessenger.Output( 202, path.GetFullPath() );
[315]190 isSuccessfulLoadStaticLinkLibrary = false;
191 }
192 }
[299]193
[315]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 {
[466]202 compiler.messenger.Output( ((string)"\"" + path.GetFullPath() + "\" を読み込みました。").c_str() );
[315]203 }
204 else
205 {
[472]206 compiler.errorMessenger.Output( 203, path.GetFullPath() );
[315]207 isSuccessfulLoadStaticLinkLibrary = false;
208 }
209 }
210 else
211 {
[472]212 compiler.errorMessenger.Output( 202, path.GetFullPath() );
[315]213 isSuccessfulLoadStaticLinkLibrary = false;
214 }
215 }
[294]216
[315]217 if( !isSuccessfulLoadStaticLinkLibrary )
218 {
219 // 静的リンクライブラリのロードに失敗したとき
220 goto EndCompile;
221 }
[294]222 }
223
224
[4]225 ///////////////////////
226 // コンパイル開始
227
228 //"コンパイル中..."
[465]229 compiler.messenger.Output(STRING_COMPILE_COMPILING);
[4]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 //"コンパイルはユーザーにより中断されました。"
[465]252 compiler.messenger.Output(STRING_COMPILE_STOP);
[4]253 }
254 else{
255 extern int WarningNum;
[465]256 if( !compiler.errorMessenger.HasError() )
257 {
[4]258 //"コンパイルは正常に完了しました(エラー:%d、警告:%d)"
[266]259 sprintf(temp2,
260 STRING_COMPILE_SUCCESS,
[465]261 compiler.errorMessenger.GetErrorCount(),
262 compiler.errorMessenger.GetWarningCount(),
[266]263 ((double)(GetTickCount() - beforeTickCount))/1000
264 );
[4]265 }
[465]266 else
267 {
[4]268 //"コンパイルは中断されました(エラー:%d、警告:%d)"
[465]269 sprintf(temp2,STRING_COMPILE_ERROR,
270 compiler.errorMessenger.GetErrorCount(),
271 compiler.errorMessenger.GetWarningCount() );
[4]272 }
273
[465]274 compiler.messenger.Output( "" );
275 compiler.messenger.Output( "-----------------------------------------------------" );
276 compiler.messenger.Output( temp2 );
[4]277 }
278
279 //"閉じる"
280 SetDlgItemText(hMainDlg,IDOK,STRING_CLOSE);
281
[472]282 // エラーがない場合はビルド成功とする
283 if( !compiler.errorMessenger.HasError() )
284 {
285 // ビルド成功
286 compiler.BuildSuccessful();
287 }
288
[92]289#ifdef _DEBUG
290 // デバッグモードのときはダイアログが隠れている
291 ShowWindow(hMainDlg,SW_SHOW);
292#endif
[4]293}
[467]294void MainThread(void *dummy)
295{
296 if( program.IsDebugRun() )
297 {
[459]298 if( compiler.IsDebug() )
299 {
[4]300 //デバッグコンパイル
301 OutputExe();
302 }
303
304 //デバッグ実行
[465]305 if( !compiler.errorMessenger.HasError() )
306 {
307 DebugProgram();
308 }
[4]309 }
310 else{
311 //リリースコンパイル
312 OutputExe();
313 }
314}
Note: See TracBrowser for help on using the repository browser.