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