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

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

smoothieプロジェクトが不要になったため、破棄。

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