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