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

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