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