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

Last change on this file since 272 was 272, checked in by dai_9181, 17 years ago
File size: 5.2 KB
Line 
1#include "stdafx.h"
2
3#include <jenga/include/smoothie/Smoothie.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 AddSourceCode(char *buffer){
15 char *temp;
16 temp=(char *)HeapAlloc(hHeap,0,lstrlen(buffer)+8192);
17 lstrcpy(temp,buffer);
18
19 //エスケープシーケンス設定
20 SetEscapeSequenceFormat(temp);
21
22 //コマンド対応
23 ChangeCommandToCode(temp);
24
25 //最後尾に貼り付け
26 compiler.source.Addition( temp );
27
28 HeapDefaultFree(temp);
29}
30
31void OutputExe(void){
32 extern HANDLE hHeap;
33 extern char *basbuf;
34 extern int ErrorNum;
35 extern BOOL bStopCompile;
36 extern HWND hMainDlg;
37 int i2,i3;
38 char temp2[MAX_PATH];
39
40 // 開始時刻を記録
41 DWORD beforeTickCount = GetTickCount();
42
43 //プログレスバーの設定
44 PostMessage(GetDlgItem(hMainDlg,IDC_PROGRESS),PBM_SETRANGE,0,MAKELPARAM(0,6));
45 PostMessage(GetDlgItem(hMainDlg,IDC_PROGRESS),PBM_SETSTEP,1,0);
46
47 //"中断"
48 SetDlgItemText(hMainDlg,IDOK,STRING_STOP);
49
50 //中断フラグを初期化
51 bStopCompile=0;
52
53 //サブシステムのタイプ
54 extern unsigned short TypeOfSubSystem;
55 TypeOfSubSystem=IMAGE_SUBSYSTEM_WINDOWS_GUI;
56
57 //プログラムをファイルから読み込む
58 extern char SourceFileName[MAX_PATH];
59 if( !compiler.source.ReadFile( SourceFileName ) ){
60 SetError(201,SourceFileName,-1);
61 goto EndCompile;
62 }
63
64 //イメージベースの設定
65 extern DWORD ImageBase;
66 if(compiler.IsDll()) ImageBase=0x10000000;
67 else ImageBase=0x00400000;
68
69 extern BOOL bError;
70 if(bError||bStopCompile) goto EndCompile;
71
72
73 //////////////////////////
74 // 中間コードの生成を開始
75 extern BOOL bClipCompileView;
76
77 //"最適化中..."
78 CompileMessage(STRING_COMPILE_OPTIMIZING);
79
80 //カッコを相互チェック(ダブルクォートチェックチェックを含む)
81 CheckParenthesis(basbuf);
82
83 if(bError||bStopCompile) goto EndCompile;
84
85 //コンパイルダイアログのプログレスバーを上げる
86 StepCompileProgress();
87
88 //ディレクティブ
89 DirectiveCheck();
90
91 //Next命令語を正規表現に変換
92 //NextCommandFormat(basbuf);
93
94 //エスケープシーケンス設定
95 SetEscapeSequenceFormat(basbuf);
96
97 //Def命令語をFunction命令語に変換
98 DefCommandFormat(basbuf);
99
100 //すべてのIf命令語をブロック形式に変換
101 IfCommandFormat(basbuf);
102
103 //対になる命令語を相互チェック
104 //CheckPareCommand();
105
106 if(bError||bStopCompile) goto EndCompile;
107
108 //コンパイルダイアログのプログレスバーを上げる
109 StepCompileProgress();
110
111 //重複エラー情報管理のメモリを確保
112 extern char **SynonymErrorWords;
113 extern int SynonymErrorNum;
114 SynonymErrorNum=0;
115 SynonymErrorWords=(char **)HeapAlloc(hHeap,0,1);
116
117 ChangeCommandToCode(basbuf);
118
119 //重複エラー情報管理のメモリを解放
120 for(i3=0;i3<SynonymErrorNum;i3++) HeapDefaultFree(SynonymErrorWords[i3]);
121 HeapDefaultFree(SynonymErrorWords);
122 SynonymErrorWords=0;
123
124 if(bError||bStopCompile){
125 //定数に関する情報を解放
126 goto EndCompile;
127 }
128
129 StepCompileProgress();
130
131
132 ///////////////////////
133 // コンパイル開始
134
135 //"コンパイル中..."
136 CompileMessage(STRING_COMPILE_COMPILING);
137
138 //グローバル変数に関する情報
139 // TODO: AllGlobalVarSize、AllInitGlobalVarSizeをVariablesクラスに入れる
140 extern int AllGlobalVarSize;
141 extern int AllInitGlobalVarSize;
142 compiler.GetObjectModule().meta.GetGlobalVars().clear();
143 AllGlobalVarSize=0;
144 AllInitGlobalVarSize=0;
145
146 Compile();
147
148 //リソース情報を解放
149 extern RESOURCEDATAINFO *pCursorResourceInfo;
150 extern RESOURCEDATAINFO *pIconResourceInfo;
151 extern RESOURCEDATAINFO *pBitmapResourceInfo;
152 HeapDefaultFree(pCursorResourceInfo);
153 HeapDefaultFree(pBitmapResourceInfo);
154 HeapDefaultFree(pIconResourceInfo);
155
156 //コンパイルダイアログのプログレスバーを上げる
157 StepCompileProgress();
158
159
160 //////////////////////////
161 // 終了処理
162EndCompile:
163 if(bStopCompile){
164 PostMessage(GetDlgItem(hMainDlg,IDC_PROGRESS),PBM_SETPOS,0,0);
165
166 //"コンパイルはユーザーにより中断されました。"
167 CompileMessage(STRING_COMPILE_STOP);
168 }
169 else{
170 extern int CompileMsgNum;
171 extern int WarningNum;
172 if(bError==0){
173 //"コンパイルは正常に完了しました(エラー:%d、警告:%d)"
174 sprintf(temp2,
175 STRING_COMPILE_SUCCESS,
176 ErrorNum-CompileMsgNum-WarningNum,
177 WarningNum,
178 ((double)(GetTickCount() - beforeTickCount))/1000
179 );
180 }
181 else{
182 //"コンパイルは中断されました(エラー:%d、警告:%d)"
183 sprintf(temp2,STRING_COMPILE_ERROR,ErrorNum-CompileMsgNum-WarningNum,WarningNum);
184 }
185
186 CompileMessage("");
187 CompileMessage("-----------------------------------------------------");
188 CompileMessage(temp2);
189 }
190
191 //"閉じる"
192 SetDlgItemText(hMainDlg,IDOK,STRING_CLOSE);
193
194#ifdef _DEBUG
195 // デバッグモードのときはダイアログが隠れている
196 ShowWindow(hMainDlg,SW_SHOW);
197#endif
198
199 //#include情報を解放
200 extern INCLUDEFILEINFO IncludeFileInfo;
201 for(i2=0;i2<IncludeFileInfo.FilesNum;i2++)
202 {
203 free(IncludeFileInfo.ppFileNames[i2]);
204 }
205 free(IncludeFileInfo.ppFileNames);
206}
207int MainThread(DWORD dummy){
208 extern BOOL bDebugCompile;
209 extern BOOL bDebugRun;
210 extern int bError;
211
212 if(bDebugRun){
213 if(bDebugCompile){
214 bDebugRun=0;
215
216 //デバッグコンパイル
217 OutputExe();
218
219 bDebugRun=1;
220 }
221
222 //デバッグ実行
223 if(bError==0) DebugProgram();
224 }
225 else{
226 //リリースコンパイル
227 OutputExe();
228 }
229
230 return 0;
231}
Note: See TracBrowser for help on using the repository browser.