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

Last change on this file since 322 was 322, checked in by dai_9181, 17 years ago

コンパイラ組み込みテンプレートエンジンを実装。
静的リンクライブラリ、デバッグ情報の内部形式をテキストからバイナリに変更した。

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