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

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

ヘッダファイルを整理中

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