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