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

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

Superが機能しないバグを修正。
ソースコードが小さいとソース付加に失敗するバグを修正。

File size: 6.2 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 compiler.GetObjectModule().GetSources()[0]._ResetLength();
122
123 //重複エラー情報管理のメモリを解放
124 for(i3=0;i3<SynonymErrorNum;i3++) HeapDefaultFree(SynonymErrorWords[i3]);
125 HeapDefaultFree(SynonymErrorWords);
126 SynonymErrorWords=0;
127
128 if(bError||bStopCompile){
129 //定数に関する情報を解放
130 goto EndCompile;
131 }
132
133 StepCompileProgress();
134
135
136 /////////////////////////////////////////////////////////////////
137 // 静的リンクライブラリをロードする
138 /////////////////////////////////////////////////////////////////
139
140 if( !compiler.IsCore() )
141 {
142 // コアモジュールをロードする
143 extern BOOL bDebugCompile;
144 extern char szIncludeDir[MAX_PATH];
145
146 const char *coreFileName = "core.lib";
147 if( bDebugCompile )
148 {
149 coreFileName = "cored.lib";
150 }
151
152 char coreFilePath[MAX_PATH];
153 sprintf( coreFilePath, "..\\lib\\%s", coreFileName );
154 GetFullPath( coreFilePath, szIncludeDir );
155
156 compiler.staticLibraries.push_back( new ObjectModule() );
157 compiler.staticLibraries.back()->Read( coreFilePath );
158
159 Jenga::Common::Path path( coreFilePath );
160 CompileMessage( ((string)"\"" + path.GetFileName() + path.GetExt() + "\" を読み込みました。").c_str() );
161 }
162
163 BOOST_FOREACH( const std::string &filePath, compiler.staticLibraryFilePaths )
164 {
165 compiler.staticLibraries.push_back( new ObjectModule() );
166 compiler.staticLibraries.back()->Read( filePath );
167
168 Jenga::Common::Path path( filePath );
169 CompileMessage( ((string)"\"" + path.GetFileName() + path.GetExt() + "\" を読み込みました。").c_str() );
170 }
171
172
173 ///////////////////////
174 // コンパイル開始
175
176 //"コンパイル中..."
177 CompileMessage(STRING_COMPILE_COMPILING);
178
179 Compile();
180
181 //リソース情報を解放
182 extern RESOURCEDATAINFO *pCursorResourceInfo;
183 extern RESOURCEDATAINFO *pIconResourceInfo;
184 extern RESOURCEDATAINFO *pBitmapResourceInfo;
185 HeapDefaultFree(pCursorResourceInfo);
186 HeapDefaultFree(pBitmapResourceInfo);
187 HeapDefaultFree(pIconResourceInfo);
188
189 //コンパイルダイアログのプログレスバーを上げる
190 StepCompileProgress();
191
192
193 //////////////////////////
194 // 終了処理
195EndCompile:
196 if(bStopCompile){
197 PostMessage(GetDlgItem(hMainDlg,IDC_PROGRESS),PBM_SETPOS,0,0);
198
199 //"コンパイルはユーザーにより中断されました。"
200 CompileMessage(STRING_COMPILE_STOP);
201 }
202 else{
203 extern int CompileMsgNum;
204 extern int WarningNum;
205 if(bError==0){
206 //"コンパイルは正常に完了しました(エラー:%d、警告:%d)"
207 sprintf(temp2,
208 STRING_COMPILE_SUCCESS,
209 ErrorNum-CompileMsgNum-WarningNum,
210 WarningNum,
211 ((double)(GetTickCount() - beforeTickCount))/1000
212 );
213 }
214 else{
215 //"コンパイルは中断されました(エラー:%d、警告:%d)"
216 sprintf(temp2,STRING_COMPILE_ERROR,ErrorNum-CompileMsgNum-WarningNum,WarningNum);
217 }
218
219 CompileMessage("");
220 CompileMessage("-----------------------------------------------------");
221 CompileMessage(temp2);
222 }
223
224 //"閉じる"
225 SetDlgItemText(hMainDlg,IDOK,STRING_CLOSE);
226
227#ifdef _DEBUG
228 // デバッグモードのときはダイアログが隠れている
229 ShowWindow(hMainDlg,SW_SHOW);
230#endif
231}
232int MainThread(DWORD dummy){
233 extern BOOL bDebugCompile;
234 extern BOOL bDebugRun;
235 extern int bError;
236
237 if(bDebugRun){
238 if(bDebugCompile){
239 bDebugRun=0;
240
241 //デバッグコンパイル
242 OutputExe();
243
244 bDebugRun=1;
245 }
246
247 //デバッグ実行
248 if(bError==0) DebugProgram();
249 }
250 else{
251 //リリースコンパイル
252 OutputExe();
253 }
254
255 return 0;
256}
Note: See TracBrowser for help on using the repository browser.