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