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