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

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

・Compiler::IsDebugメソッドを導入した(bDebugCompileグローバル変数は廃止)。
・bStrictグローバル変数は意味を成さないので廃止した。

File size: 7.5 KB
RevLine 
[206]1#include "stdafx.h"
2
[182]3#include <jenga/include/smoothie/Smoothie.h>
[294]4#include <jenga/include/common/Path.h>
[182]5
[206]6#include <Compiler.h>
7
[4]8#include "common.h"
9
10void StepCompileProgress(void){
11 extern HWND hMainDlg;
12 PostMessage(GetDlgItem(hMainDlg,IDC_PROGRESS),PBM_STEPIT,0,0);
13}
14
[350]15void MakeMiddleCode( char *buffer )
16{
[322]17 // 改行コードをCRLFからLFにする
[350]18 ChangeReturnCode( buffer );
[322]19
20 // コメントを除去
[350]21 DeleteComment( buffer );
[322]22
[15]23 //エスケープシーケンス設定
[350]24 SetEscapeSequenceFormat( buffer );
[15]25
26 //コマンド対応
[350]27 ChangeCommandToCode( buffer );
28}
[15]29
[350]30void AddSourceCode(const char *buffer){
31 char *temp;
32 temp=(char *)HeapAlloc(hHeap,0,lstrlen(buffer)+8192);
33 lstrcpy(temp,buffer);
34
35 MakeMiddleCode( temp );
36
[15]37 //最後尾に貼り付け
[280]38 compiler.GetObjectModule().GetCurrentSource().Addition( temp );
[15]39
40 HeapDefaultFree(temp);
41}
42
[4]43void OutputExe(void){
44 extern HANDLE hHeap;
45 extern char *basbuf;
46 extern int ErrorNum;
47 extern BOOL bStopCompile;
48 extern HWND hMainDlg;
[279]49 int i3;
[4]50 char temp2[MAX_PATH];
51
[266]52 // 開始時刻を記録
53 DWORD beforeTickCount = GetTickCount();
54
[4]55 //プログレスバーの設定
56 PostMessage(GetDlgItem(hMainDlg,IDC_PROGRESS),PBM_SETRANGE,0,MAKELPARAM(0,6));
57 PostMessage(GetDlgItem(hMainDlg,IDC_PROGRESS),PBM_SETSTEP,1,0);
58
59 //"中断"
60 SetDlgItemText(hMainDlg,IDOK,STRING_STOP);
61
62 //中断フラグを初期化
63 bStopCompile=0;
64
65 //サブシステムのタイプ
66 extern unsigned short TypeOfSubSystem;
67 TypeOfSubSystem=IMAGE_SUBSYSTEM_WINDOWS_GUI;
68
69 //プログラムをファイルから読み込む
70 extern char SourceFileName[MAX_PATH];
[308]71 compiler.GetObjectModule().SetCurrentSourceIndex( (int)compiler.GetObjectModule().GetSources().size() );
[280]72 compiler.GetObjectModule().GetSources().push_back( BasicSource() );
73 if( !compiler.GetObjectModule().GetCurrentSource().ReadFile( SourceFileName ) ){
[15]74 SetError(201,SourceFileName,-1);
75 goto EndCompile;
76 }
[4]77
78 //イメージベースの設定
79 extern DWORD ImageBase;
[266]80 if(compiler.IsDll()) ImageBase=0x10000000;
[4]81 else ImageBase=0x00400000;
82
83 extern BOOL bError;
84 if(bError||bStopCompile) goto EndCompile;
85
86
87 //////////////////////////
88 // 中間コードの生成を開始
89 extern BOOL bClipCompileView;
90
91 //"最適化中..."
92 CompileMessage(STRING_COMPILE_OPTIMIZING);
93
94 //カッコを相互チェック(ダブルクォートチェックチェックを含む)
95 CheckParenthesis(basbuf);
96
97 if(bError||bStopCompile) goto EndCompile;
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(bError||bStopCompile) goto EndCompile;
121
122 //コンパイルダイアログのプログレスバーを上げる
123 StepCompileProgress();
124
125 //重複エラー情報管理のメモリを確保
126 extern char **SynonymErrorWords;
127 extern int SynonymErrorNum;
128 SynonymErrorNum=0;
129 SynonymErrorWords=(char **)HeapAlloc(hHeap,0,1);
130
131 ChangeCommandToCode(basbuf);
[304]132 compiler.GetObjectModule().GetSources()[0]._ResetLength();
[4]133
134 //重複エラー情報管理のメモリを解放
135 for(i3=0;i3<SynonymErrorNum;i3++) HeapDefaultFree(SynonymErrorWords[i3]);
136 HeapDefaultFree(SynonymErrorWords);
[75]137 SynonymErrorWords=0;
[4]138
139 if(bError||bStopCompile){
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;
156 extern char szIncludeDir[MAX_PATH];
[294]157
[315]158 const char *coreFileName = "core.lib";
[459]159 if( compiler.IsDebug() )
[315]160 {
161 coreFileName = "cored.lib";
162 }
163
164 char coreFilePath[MAX_PATH];
[308]165#ifdef _AMD64_
[315]166 sprintf( coreFilePath, "..\\lib\\x64\\%s", coreFileName );
[308]167#else
[315]168 sprintf( coreFilePath, "..\\lib\\%s", coreFileName );
[308]169#endif
[315]170 GetFullPath( coreFilePath, szIncludeDir );
[294]171
[315]172 Jenga::Common::Path path( coreFilePath );
173 if( path.IsExistFile() )
174 {
175 compiler.staticLibraries.push_back( new ObjectModule() );
176 if( compiler.staticLibraries.back()->Read( coreFilePath ) )
177 {
178 CompileMessage( ((string)"\"" + path.GetFileName() + path.GetExt() + "\" を読み込みました。").c_str() );
179 }
180 else
181 {
182 CompileMessage( ((string)"\"" + path.GetFileName() + path.GetExt() + "\" ファイルが壊れています。").c_str() );
183 isSuccessfulLoadStaticLinkLibrary = false;
184 }
185 }
186 else
187 {
188 CompileMessage( ((string)"\"" + path.GetFileName() + path.GetExt() + "\" ファイルが存在しません。").c_str() );
189 isSuccessfulLoadStaticLinkLibrary = false;
190 }
191 }
[299]192
[315]193 BOOST_FOREACH( const std::string &filePath, compiler.staticLibraryFilePaths )
194 {
195 Jenga::Common::Path path( filePath );
196 if( path.IsExistFile() )
197 {
198 compiler.staticLibraries.push_back( new ObjectModule() );
199 if( compiler.staticLibraries.back()->Read( filePath ) )
200 {
201 CompileMessage( ((string)"\"" + path.GetFileName() + path.GetExt() + "\" を読み込みました。").c_str() );
202 }
203 else
204 {
205 CompileMessage( ((string)"\"" + path.GetFileName() + path.GetExt() + "\" ファイルが壊れています。").c_str() );
206 isSuccessfulLoadStaticLinkLibrary = false;
207 }
208 }
209 else
210 {
211 CompileMessage( ((string)"\"" + path.GetFileName() + path.GetExt() + "\" ファイルが存在しません。").c_str() );
212 isSuccessfulLoadStaticLinkLibrary = false;
213 }
214 }
[294]215
[315]216 if( !isSuccessfulLoadStaticLinkLibrary )
217 {
218 // 静的リンクライブラリのロードに失敗したとき
219 goto EndCompile;
220 }
[294]221 }
222
223
[4]224 ///////////////////////
225 // コンパイル開始
226
227 //"コンパイル中..."
228 CompileMessage(STRING_COMPILE_COMPILING);
229
230 Compile();
231
232 //リソース情報を解放
233 extern RESOURCEDATAINFO *pCursorResourceInfo;
234 extern RESOURCEDATAINFO *pIconResourceInfo;
235 extern RESOURCEDATAINFO *pBitmapResourceInfo;
236 HeapDefaultFree(pCursorResourceInfo);
237 HeapDefaultFree(pBitmapResourceInfo);
238 HeapDefaultFree(pIconResourceInfo);
239
240 //コンパイルダイアログのプログレスバーを上げる
241 StepCompileProgress();
242
243
244 //////////////////////////
245 // 終了処理
246EndCompile:
247 if(bStopCompile){
248 PostMessage(GetDlgItem(hMainDlg,IDC_PROGRESS),PBM_SETPOS,0,0);
249
250 //"コンパイルはユーザーにより中断されました。"
251 CompileMessage(STRING_COMPILE_STOP);
252 }
253 else{
254 extern int CompileMsgNum;
255 extern int WarningNum;
256 if(bError==0){
257 //"コンパイルは正常に完了しました(エラー:%d、警告:%d)"
[266]258 sprintf(temp2,
259 STRING_COMPILE_SUCCESS,
260 ErrorNum-CompileMsgNum-WarningNum,
261 WarningNum,
262 ((double)(GetTickCount() - beforeTickCount))/1000
263 );
[4]264 }
265 else{
266 //"コンパイルは中断されました(エラー:%d、警告:%d)"
267 sprintf(temp2,STRING_COMPILE_ERROR,ErrorNum-CompileMsgNum-WarningNum,WarningNum);
268 }
269
270 CompileMessage("");
271 CompileMessage("-----------------------------------------------------");
272 CompileMessage(temp2);
273 }
274
275 //"閉じる"
276 SetDlgItemText(hMainDlg,IDOK,STRING_CLOSE);
277
[92]278#ifdef _DEBUG
279 // デバッグモードのときはダイアログが隠れている
280 ShowWindow(hMainDlg,SW_SHOW);
281#endif
[4]282}
283int MainThread(DWORD dummy){
284 extern BOOL bDebugRun;
285 extern int bError;
286
287 if(bDebugRun){
[459]288 if( compiler.IsDebug() )
289 {
[4]290 bDebugRun=0;
291
292 //デバッグコンパイル
293 OutputExe();
294
295 bDebugRun=1;
296 }
297
298 //デバッグ実行
299 if(bError==0) DebugProgram();
300 }
301 else{
302 //リリースコンパイル
303 OutputExe();
304 }
305
306 return 0;
307}
Note: See TracBrowser for help on using the repository browser.