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

Last change on this file since 294 was 294, checked in by dai_9181, 17 years ago
File size: 6.0 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
159 BOOST_FOREACH( const std::string &filePath, compiler.staticLibraryFilePaths )
160 {
161 compiler.staticLibraries.push_back( new ObjectModule() );
162 compiler.staticLibraries.back()->Read( filePath );
163
164 Jenga::Common::Path path( filePath );
165 CompileMessage( ((string)"\"" + path.GetFileName() + path.GetExt() + "\" を読み込みました。").c_str() );
166 }
167
168
169 ///////////////////////
170 // コンパイル開始
171
172 //"コンパイル中..."
173 CompileMessage(STRING_COMPILE_COMPILING);
174
175 Compile();
176
177 //リソース情報を解放
178 extern RESOURCEDATAINFO *pCursorResourceInfo;
179 extern RESOURCEDATAINFO *pIconResourceInfo;
180 extern RESOURCEDATAINFO *pBitmapResourceInfo;
181 HeapDefaultFree(pCursorResourceInfo);
182 HeapDefaultFree(pBitmapResourceInfo);
183 HeapDefaultFree(pIconResourceInfo);
184
185 //コンパイルダイアログのプログレスバーを上げる
186 StepCompileProgress();
187
188
189 //////////////////////////
190 // 終了処理
191EndCompile:
192 if(bStopCompile){
193 PostMessage(GetDlgItem(hMainDlg,IDC_PROGRESS),PBM_SETPOS,0,0);
194
195 //"コンパイルはユーザーにより中断されました。"
196 CompileMessage(STRING_COMPILE_STOP);
197 }
198 else{
199 extern int CompileMsgNum;
200 extern int WarningNum;
201 if(bError==0){
202 //"コンパイルは正常に完了しました(エラー:%d、警告:%d)"
203 sprintf(temp2,
204 STRING_COMPILE_SUCCESS,
205 ErrorNum-CompileMsgNum-WarningNum,
206 WarningNum,
207 ((double)(GetTickCount() - beforeTickCount))/1000
208 );
209 }
210 else{
211 //"コンパイルは中断されました(エラー:%d、警告:%d)"
212 sprintf(temp2,STRING_COMPILE_ERROR,ErrorNum-CompileMsgNum-WarningNum,WarningNum);
213 }
214
215 CompileMessage("");
216 CompileMessage("-----------------------------------------------------");
217 CompileMessage(temp2);
218 }
219
220 //"閉じる"
221 SetDlgItemText(hMainDlg,IDOK,STRING_CLOSE);
222
223#ifdef _DEBUG
224 // デバッグモードのときはダイアログが隠れている
225 ShowWindow(hMainDlg,SW_SHOW);
226#endif
227}
228int MainThread(DWORD dummy){
229 extern BOOL bDebugCompile;
230 extern BOOL bDebugRun;
231 extern int bError;
232
233 if(bDebugRun){
234 if(bDebugCompile){
235 bDebugRun=0;
236
237 //デバッグコンパイル
238 OutputExe();
239
240 bDebugRun=1;
241 }
242
243 //デバッグ実行
244 if(bError==0) DebugProgram();
245 }
246 else{
247 //リリースコンパイル
248 OutputExe();
249 }
250
251 return 0;
252}
Note: See TracBrowser for help on using the repository browser.