source: dev/trunk/abdev/BasicCompiler_Common/MakeExe.cpp@ 299

Last change on this file since 299 was 299, checked in by dai_9181, 17 years ago
File size: 6.1 KB
Line 
1#include "stdafx.h"
2
3#include <jenga/include/smoothie/Smoothie.h>
4#include <jenga/include/common/Path.h>
5
6#include <Compiler.h>
7
8#include "common.h"
9
10void StepCompileProgress(void){
11 extern HWND hMainDlg;
12 PostMessage(GetDlgItem(hMainDlg,IDC_PROGRESS),PBM_STEPIT,0,0);
13}
14
15void AddSourceCode(char *buffer){
16 char *temp;
17 temp=(char *)HeapAlloc(hHeap,0,lstrlen(buffer)+8192);
18 lstrcpy(temp,buffer);
19
20 //エスケープシーケンス設定
21 SetEscapeSequenceFormat(temp);
22
23 //コマンド対応
24 ChangeCommandToCode(temp);
25
26 //最後尾に貼り付け
27 compiler.GetObjectModule().GetCurrentSource().Addition( temp );
28
29 HeapDefaultFree(temp);
30}
31
32void OutputExe(void){
33 extern HANDLE hHeap;
34 extern char *basbuf;
35 extern int ErrorNum;
36 extern BOOL bStopCompile;
37 extern HWND hMainDlg;
38 int i3;
39 char temp2[MAX_PATH];
40
41 // 開始時刻を記録
42 DWORD beforeTickCount = GetTickCount();
43
44 //プログレスバーの設定
45 PostMessage(GetDlgItem(hMainDlg,IDC_PROGRESS),PBM_SETRANGE,0,MAKELPARAM(0,6));
46 PostMessage(GetDlgItem(hMainDlg,IDC_PROGRESS),PBM_SETSTEP,1,0);
47
48 //"中断"
49 SetDlgItemText(hMainDlg,IDOK,STRING_STOP);
50
51 //中断フラグを初期化
52 bStopCompile=0;
53
54 //サブシステムのタイプ
55 extern unsigned short TypeOfSubSystem;
56 TypeOfSubSystem=IMAGE_SUBSYSTEM_WINDOWS_GUI;
57
58 //プログラムをファイルから読み込む
59 extern char SourceFileName[MAX_PATH];
60 compiler.GetObjectModule().SetCurrentSourceIndex( compiler.GetObjectModule().GetSources().size() );
61 compiler.GetObjectModule().GetSources().push_back( BasicSource() );
62 if( !compiler.GetObjectModule().GetCurrentSource().ReadFile( SourceFileName ) ){
63 SetError(201,SourceFileName,-1);
64 goto EndCompile;
65 }
66
67 //イメージベースの設定
68 extern DWORD ImageBase;
69 if(compiler.IsDll()) ImageBase=0x10000000;
70 else ImageBase=0x00400000;
71
72 extern BOOL bError;
73 if(bError||bStopCompile) goto EndCompile;
74
75
76 //////////////////////////
77 // 中間コードの生成を開始
78 extern BOOL bClipCompileView;
79
80 //"最適化中..."
81 CompileMessage(STRING_COMPILE_OPTIMIZING);
82
83 //カッコを相互チェック(ダブルクォートチェックチェックを含む)
84 CheckParenthesis(basbuf);
85
86 if(bError||bStopCompile) goto EndCompile;
87
88 //コンパイルダイアログのプログレスバーを上げる
89 StepCompileProgress();
90
91 //ディレクティブ
92 DirectiveCheck();
93
94 //Next命令語を正規表現に変換
95 //NextCommandFormat(basbuf);
96
97 //エスケープシーケンス設定
98 SetEscapeSequenceFormat(basbuf);
99
100 //Def命令語をFunction命令語に変換
101 DefCommandFormat(basbuf);
102
103 //すべてのIf命令語をブロック形式に変換
104 IfCommandFormat(basbuf);
105
106 //対になる命令語を相互チェック
107 //CheckPareCommand();
108
109 if(bError||bStopCompile) goto EndCompile;
110
111 //コンパイルダイアログのプログレスバーを上げる
112 StepCompileProgress();
113
114 //重複エラー情報管理のメモリを確保
115 extern char **SynonymErrorWords;
116 extern int SynonymErrorNum;
117 SynonymErrorNum=0;
118 SynonymErrorWords=(char **)HeapAlloc(hHeap,0,1);
119
120 ChangeCommandToCode(basbuf);
121
122 //重複エラー情報管理のメモリを解放
123 for(i3=0;i3<SynonymErrorNum;i3++) HeapDefaultFree(SynonymErrorWords[i3]);
124 HeapDefaultFree(SynonymErrorWords);
125 SynonymErrorWords=0;
126
127 if(bError||bStopCompile){
128 //定数に関する情報を解放
129 goto EndCompile;
130 }
131
132 StepCompileProgress();
133
134
135 /////////////////////////////////////////////////////////////////
136 // 静的リンクライブラリをロードする
137 /////////////////////////////////////////////////////////////////
138
139 if( !compiler.IsCore() )
140 {
141 // コアモジュールをロードする
142 extern BOOL bDebugCompile;
143 extern char szIncludeDir[MAX_PATH];
144
145 const char *coreFileName = "core.lib";
146 if( bDebugCompile )
147 {
148 coreFileName = "cored.lib";
149 }
150
151 char coreFilePath[MAX_PATH];
152 sprintf( coreFilePath, "..\\lib\\%s", coreFileName );
153 GetFullPath( coreFilePath, szIncludeDir );
154
155 compiler.staticLibraries.push_back( new ObjectModule() );
156 compiler.staticLibraries.back()->Read( coreFilePath );
157
158 Jenga::Common::Path path( coreFilePath );
159 CompileMessage( ((string)"\"" + path.GetFileName() + path.GetExt() + "\" を読み込みました。").c_str() );
160 }
161
162 BOOST_FOREACH( const std::string &filePath, compiler.staticLibraryFilePaths )
163 {
164 compiler.staticLibraries.push_back( new ObjectModule() );
165 compiler.staticLibraries.back()->Read( filePath );
166
167 Jenga::Common::Path path( filePath );
168 CompileMessage( ((string)"\"" + path.GetFileName() + path.GetExt() + "\" を読み込みました。").c_str() );
169 }
170
171
172 ///////////////////////
173 // コンパイル開始
174
175 //"コンパイル中..."
176 CompileMessage(STRING_COMPILE_COMPILING);
177
178 Compile();
179
180 //リソース情報を解放
181 extern RESOURCEDATAINFO *pCursorResourceInfo;
182 extern RESOURCEDATAINFO *pIconResourceInfo;
183 extern RESOURCEDATAINFO *pBitmapResourceInfo;
184 HeapDefaultFree(pCursorResourceInfo);
185 HeapDefaultFree(pBitmapResourceInfo);
186 HeapDefaultFree(pIconResourceInfo);
187
188 //コンパイルダイアログのプログレスバーを上げる
189 StepCompileProgress();
190
191
192 //////////////////////////
193 // 終了処理
194EndCompile:
195 if(bStopCompile){
196 PostMessage(GetDlgItem(hMainDlg,IDC_PROGRESS),PBM_SETPOS,0,0);
197
198 //"コンパイルはユーザーにより中断されました。"
199 CompileMessage(STRING_COMPILE_STOP);
200 }
201 else{
202 extern int CompileMsgNum;
203 extern int WarningNum;
204 if(bError==0){
205 //"コンパイルは正常に完了しました(エラー:%d、警告:%d)"
206 sprintf(temp2,
207 STRING_COMPILE_SUCCESS,
208 ErrorNum-CompileMsgNum-WarningNum,
209 WarningNum,
210 ((double)(GetTickCount() - beforeTickCount))/1000
211 );
212 }
213 else{
214 //"コンパイルは中断されました(エラー:%d、警告:%d)"
215 sprintf(temp2,STRING_COMPILE_ERROR,ErrorNum-CompileMsgNum-WarningNum,WarningNum);
216 }
217
218 CompileMessage("");
219 CompileMessage("-----------------------------------------------------");
220 CompileMessage(temp2);
221 }
222
223 //"閉じる"
224 SetDlgItemText(hMainDlg,IDOK,STRING_CLOSE);
225
226#ifdef _DEBUG
227 // デバッグモードのときはダイアログが隠れている
228 ShowWindow(hMainDlg,SW_SHOW);
229#endif
230}
231int MainThread(DWORD dummy){
232 extern BOOL bDebugCompile;
233 extern BOOL bDebugRun;
234 extern int bError;
235
236 if(bDebugRun){
237 if(bDebugCompile){
238 bDebugRun=0;
239
240 //デバッグコンパイル
241 OutputExe();
242
243 bDebugRun=1;
244 }
245
246 //デバッグ実行
247 if(bError==0) DebugProgram();
248 }
249 else{
250 //リリースコンパイル
251 OutputExe();
252 }
253
254 return 0;
255}
Note: See TracBrowser for help on using the repository browser.