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