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