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

Last change on this file since 268 was 268, checked in by dai_9181, 17 years ago
File size: 5.1 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 extern int AllGlobalVarSize;
140 extern int AllInitGlobalVarSize;
141 compiler.GetObjectModule().meta.GetGlobalVars().clear();
142 AllGlobalVarSize=0;
143 AllInitGlobalVarSize=0;
144
145 Compile();
146
147 //リソース情報を解放
148 extern RESOURCEDATAINFO *pCursorResourceInfo;
149 extern RESOURCEDATAINFO *pIconResourceInfo;
150 extern RESOURCEDATAINFO *pBitmapResourceInfo;
151 HeapDefaultFree(pCursorResourceInfo);
152 HeapDefaultFree(pBitmapResourceInfo);
153 HeapDefaultFree(pIconResourceInfo);
154
155 //コンパイルダイアログのプログレスバーを上げる
156 StepCompileProgress();
157
158
159 //////////////////////////
160 // 終了処理
161EndCompile:
162 if(bStopCompile){
163 PostMessage(GetDlgItem(hMainDlg,IDC_PROGRESS),PBM_SETPOS,0,0);
164
165 //"コンパイルはユーザーにより中断されました。"
166 CompileMessage(STRING_COMPILE_STOP);
167 }
168 else{
169 extern int CompileMsgNum;
170 extern int WarningNum;
171 if(bError==0){
172 //"コンパイルは正常に完了しました(エラー:%d、警告:%d)"
173 sprintf(temp2,
174 STRING_COMPILE_SUCCESS,
175 ErrorNum-CompileMsgNum-WarningNum,
176 WarningNum,
177 ((double)(GetTickCount() - beforeTickCount))/1000
178 );
179 }
180 else{
181 //"コンパイルは中断されました(エラー:%d、警告:%d)"
182 sprintf(temp2,STRING_COMPILE_ERROR,ErrorNum-CompileMsgNum-WarningNum,WarningNum);
183 }
184
185 CompileMessage("");
186 CompileMessage("-----------------------------------------------------");
187 CompileMessage(temp2);
188 }
189
190 //"閉じる"
191 SetDlgItemText(hMainDlg,IDOK,STRING_CLOSE);
192
193#ifdef _DEBUG
194 // デバッグモードのときはダイアログが隠れている
195 ShowWindow(hMainDlg,SW_SHOW);
196#endif
197
198 //#include情報を解放
199 extern INCLUDEFILEINFO IncludeFileInfo;
200 for(i2=0;i2<IncludeFileInfo.FilesNum;i2++)
201 {
202 free(IncludeFileInfo.ppFileNames[i2]);
203 }
204 free(IncludeFileInfo.ppFileNames);
205}
206int MainThread(DWORD dummy){
207 extern BOOL bDebugCompile;
208 extern BOOL bDebugRun;
209 extern int bError;
210
211 if(bDebugRun){
212 if(bDebugCompile){
213 bDebugRun=0;
214
215 //デバッグコンパイル
216 OutputExe();
217
218 bDebugRun=1;
219 }
220
221 //デバッグ実行
222 if(bError==0) DebugProgram();
223 }
224 else{
225 //リリースコンパイル
226 OutputExe();
227 }
228
229 return 0;
230}
Note: See TracBrowser for help on using the repository browser.