[206] | 1 | #include "stdafx.h"
|
---|
| 2 |
|
---|
[183] | 3 | #include <Program.h>
|
---|
[193] | 4 | #include <Compiler.h>
|
---|
[248] | 5 | #include <LexicalScope.h>
|
---|
[206] | 6 | #include <Class.h>
|
---|
| 7 | #include <Variable.h>
|
---|
[183] | 8 |
|
---|
[3] | 9 | #include "../BasicCompiler_Common/common.h"
|
---|
| 10 | #include "Opcode.h"
|
---|
| 11 |
|
---|
| 12 |
|
---|
[86] | 13 | void SystemProc( const UserProc &userProc ){
|
---|
| 14 | if( userProc.GetName() == "_System_GetEip" ){
|
---|
[3] | 15 | //mov eax,dword ptr[esp]
|
---|
[235] | 16 | compiler.codeGenerator.op_mov_RM( sizeof(long), REG_EAX, REG_ESP, 0, MOD_BASE );
|
---|
[3] | 17 |
|
---|
| 18 | //ret
|
---|
[225] | 19 | compiler.codeGenerator.op_ret();
|
---|
[3] | 20 | }
|
---|
[86] | 21 | else if( userProc.GetName() == "_System_InitDllGlobalVariables" ){
|
---|
[3] | 22 | ////////////////////////////////////////
|
---|
| 23 | // DLLのグローバル領域をコンパイル
|
---|
| 24 | ////////////////////////////////////////
|
---|
| 25 |
|
---|
[266] | 26 | if( !compiler.IsDll() ){
|
---|
[3] | 27 | //ret
|
---|
[225] | 28 | compiler.codeGenerator.op_ret();
|
---|
[3] | 29 |
|
---|
| 30 | return;
|
---|
| 31 | }
|
---|
| 32 |
|
---|
[206] | 33 | const UserProc *pBackUserProc;
|
---|
[537] | 34 | pBackUserProc = &compiler.GetCompilingUserProc();
|
---|
| 35 | compiler.StartGlobalAreaCompile();
|
---|
[3] | 36 |
|
---|
| 37 | int BackCp;
|
---|
| 38 | BackCp=cp;
|
---|
| 39 | cp=-1;
|
---|
| 40 |
|
---|
[459] | 41 | if( compiler.IsDebug() )
|
---|
| 42 | {
|
---|
[3] | 43 | //デバッグ用の変数を定義
|
---|
| 44 | DebugVariable();
|
---|
| 45 | }
|
---|
| 46 |
|
---|
| 47 | //GC用の変数を定義
|
---|
| 48 | InitGCVariables();
|
---|
| 49 |
|
---|
[129] | 50 | //_System_StartupProgramの呼び出し
|
---|
[206] | 51 | extern const UserProc *pSub_System_StartupProgram;
|
---|
[225] | 52 | compiler.codeGenerator.op_call(pSub_System_StartupProgram);
|
---|
[129] | 53 |
|
---|
[42] | 54 | //クラスに属する静的メンバを定義
|
---|
[265] | 55 | compiler.GetObjectModule().meta.GetClasses().InitStaticMember();
|
---|
[42] | 56 |
|
---|
[3] | 57 | GetGlobalDataForDll();
|
---|
| 58 |
|
---|
[537] | 59 | compiler.SetCompilingUserProc( pBackUserProc );
|
---|
[3] | 60 | cp=BackCp;
|
---|
| 61 |
|
---|
| 62 | //ret
|
---|
[225] | 63 | compiler.codeGenerator.op_ret();
|
---|
[3] | 64 | }
|
---|
[86] | 65 | else if( userProc.GetName() == "_System_InitStaticLocalVariables" ){
|
---|
[3] | 66 | //静的ローカルオブジェクトのコンストラクタ呼び出し
|
---|
| 67 |
|
---|
[265] | 68 | BOOST_FOREACH( Variable *pVar, compiler.GetObjectModule().meta.GetGlobalVars() ){
|
---|
[76] | 69 | if(memicmp(pVar->GetName().c_str(),"Static%",7)==0){
|
---|
[3] | 70 | //コンストラクタ呼び出し
|
---|
[206] | 71 | if( pVar->GetType().IsObject() ){
|
---|
[3] | 72 |
|
---|
| 73 | //エラー用
|
---|
[76] | 74 | cp=pVar->source_code_address;
|
---|
[3] | 75 |
|
---|
[50] | 76 | CallConstructor(
|
---|
[76] | 77 | pVar->GetName().c_str(),
|
---|
[206] | 78 | pVar->GetSubscripts(),
|
---|
| 79 | pVar->GetType(),
|
---|
| 80 | pVar->GetParamStrForConstructor().c_str());
|
---|
[3] | 81 | }
|
---|
| 82 | }
|
---|
| 83 | }
|
---|
| 84 |
|
---|
| 85 | //ret
|
---|
[225] | 86 | compiler.codeGenerator.op_ret();
|
---|
[3] | 87 | }
|
---|
[86] | 88 | else if( userProc.GetName() == "_System_Call_Destructor_of_GlobalObject" ){
|
---|
[3] | 89 |
|
---|
[206] | 90 | const UserProc *pBackUserProc;
|
---|
[537] | 91 | pBackUserProc = &compiler.GetCompilingUserProc();
|
---|
| 92 | compiler.StartGlobalAreaCompile();
|
---|
[3] | 93 |
|
---|
[248] | 94 | compiler.codeGenerator.lexicalScopes.CallDestructorsOfScopeEnd();
|
---|
[3] | 95 |
|
---|
[537] | 96 | compiler.SetCompilingUserProc( pBackUserProc );
|
---|
[3] | 97 |
|
---|
| 98 |
|
---|
| 99 | //ret
|
---|
[225] | 100 | compiler.codeGenerator.op_ret();
|
---|
[3] | 101 | }
|
---|
[86] | 102 | else if( userProc.GetName() == "_allrem" ){
|
---|
[3] | 103 | //乗除演算用の特殊関数(64ビット整数対応)
|
---|
| 104 | BYTE Buffer_allrem[]={
|
---|
| 105 | 0x53,0x57,0x33,0xFF,0x8B,0x44,0x24,0x10,0x0B,0xC0,0x7D,0x14,0x47,0x8B,0x54,0x24,0x0C,0xF7,0xD8,0xF7,0xDA,0x83,0xD8,0x00,0x89,0x44,0x24,0x10,0x89,0x54,0x24,0x0C,0x8B,0x44,0x24,0x18,0x0B,0xC0,0x7D,0x13,0x8B,0x54,0x24,0x14,0xF7,0xD8,0xF7,0xDA,0x83,0xD8,0x00,0x89,0x44,0x24,0x18,0x89,0x54,0x24,0x14,0x0B,0xC0,0x75,0x1B,0x8B,0x4C,0x24,0x14,0x8B,0x44,0x24,0x10,0x33,0xD2,0xF7,0xF1,0x8B,0x44,0x24,0x0C,0xF7,0xF1,0x8B,0xC2,0x33,0xD2,0x4F,0x79,0x4E,0xEB,0x53,0x8B,0xD8,0x8B,0x4C,0x24,0x14,0x8B,0x54,0x24,0x10,0x8B,0x44,0x24,0x0C,0xD1,0xEB,0xD1,0xD9,0xD1,0xEA,0xD1,0xD8,0x0B,0xDB,0x75,0xF4,0xF7,0xF1,0x8B,0xC8,0xF7,0x64,0x24,0x18,0x91,0xF7,0x64,0x24,0x14,0x03,0xD1,0x72,0x0E,0x3B,0x54,0x24,0x10,0x77,0x08,0x72,0x0E,0x3B,0x44,0x24,0x0C,0x76,0x08,0x2B,0x44,0x24,0x14,0x1B,0x54,0x24,0x18,0x2B,0x44,0x24,0x0C,0x1B,0x54,0x24,0x10,0x4F,0x79,0x07,0xF7,0xDA,0xF7,0xD8,0x83,0xDA,0x00,0x5F,0x5B,0xC2,0x10,0x00
|
---|
| 106 | };
|
---|
| 107 |
|
---|
[276] | 108 | compiler.codeGenerator.PutOld( NativeCode( (const char *)Buffer_allrem, 178 ) );
|
---|
[3] | 109 | }
|
---|
[86] | 110 | else if( userProc.GetName() == "_aullrem" ){
|
---|
[3] | 111 | //乗除演算用の特殊関数(64ビット整数対応)
|
---|
| 112 | BYTE Buffer_aullrem[]={
|
---|
| 113 | 0x53,0x8B,0x44,0x24,0x14,0x0B,0xC0,0x75,0x18,0x8B,0x4C,0x24,0x10,0x8B,
|
---|
| 114 | 0x44,0x24,0x0C,0x33,0xD2,0xF7,0xF1,0x8B,0x44,0x24,0x08,0xF7,0xF1,0x8B,
|
---|
| 115 | 0xC2,0x33,0xD2,0xEB,0x50,0x8B,0xC8,0x8B,0x5C,0x24,0x10,0x8B,0x54,0x24,
|
---|
| 116 | 0x0C,0x8B,0x44,0x24,0x08,0xD1,0xE9,0xD1,0xDB,0xD1,0xEA,0xD1,0xD8,0x0B,
|
---|
| 117 | 0xC9,0x75,0xF4,0xF7,0xF3,0x8B,0xC8,0xF7,0x64,0x24,0x14,0x91,0xF7,0x64,
|
---|
| 118 | 0x24,0x10,0x03,0xD1,0x72,0x0E,0x3B,0x54,0x24,0x0C,0x77,0x08,0x72,0x0E,
|
---|
| 119 | 0x3B,0x44,0x24,0x08,0x76,0x08,0x2B,0x44,0x24,0x10,0x1B,0x54,0x24,0x14,
|
---|
| 120 | 0x2B,0x44,0x24,0x08,0x1B,0x54,0x24,0x0C,0xF7,0xDA,0xF7,0xD8,0x83,0xDA,
|
---|
| 121 | 0x00,0x5B,0xC2,0x10,0x00
|
---|
| 122 | };
|
---|
| 123 |
|
---|
[276] | 124 | compiler.codeGenerator.PutOld( NativeCode( (const char *)Buffer_aullrem, 117 ) );
|
---|
[3] | 125 | }
|
---|
[86] | 126 | else if( userProc.GetName() == "_allmul" ){
|
---|
[3] | 127 | //乗算用の特殊関数(64ビット整数対応)
|
---|
| 128 | BYTE Buffer_allmul[]={
|
---|
| 129 | 0x8B,0x44,0x24,0x08,0x8B,0x4C,0x24,0x10,0x0B,0xC8,0x8B,0x4C,0x24,0x0C,0x75,0x09,0x8B,0x44,0x24,0x04,0xF7,0xE1,0xC2,0x10,0x00,0x53,0xF7,0xE1,0x8B,0xD8,0x8B,0x44,0x24,0x08,0xF7,0x64,0x24,0x14,0x03,0xD8,0x8B,0x44,0x24,0x08,0xF7,0xE1,0x03,0xD3,0x5B,0xC2,0x10,0x00
|
---|
| 130 | };
|
---|
| 131 |
|
---|
[276] | 132 | compiler.codeGenerator.PutOld( NativeCode( (const char *)Buffer_allmul, 52 ) );
|
---|
[3] | 133 | }
|
---|
[86] | 134 | else if( userProc.GetName() == "_alldiv" ){
|
---|
[3] | 135 | //除算用の特殊関数(64ビット整数対応)
|
---|
| 136 | BYTE Buffer_alldiv[]={
|
---|
| 137 | 0x57,0x56,0x53,0x33,0xFF,0x8B,0x44,0x24,0x14,0x0B,0xC0,0x7D,0x14,0x47,0x8B,0x54,0x24,0x10,0xF7,0xD8,0xF7,0xDA,0x83,0xD8,0x00,0x89,0x44,0x24,0x14,0x89,0x54,0x24,0x10,0x8B,0x44,0x24,0x1C,0x0B,0xC0,0x7D,0x14,0x47,0x8B,0x54,0x24,0x18,0xF7,0xD8,0xF7,0xDA,0x83,0xD8,0x00,0x89,0x44,0x24,0x1C,0x89,0x54,0x24,0x18,0x0B,0xC0,0x75,0x18,0x8B,0x4C,0x24,0x18,0x8B,0x44,0x24,0x14,0x33,0xD2,0xF7,0xF1,0x8B,0xD8,0x8B,0x44,0x24,0x10,0xF7,0xF1,0x8B,0xD3,0xEB,0x41,0x8B,0xD8,0x8B,0x4C,0x24,0x18,0x8B,0x54,0x24,0x14,0x8B,0x44,0x24,0x10,0xD1,0xEB,0xD1,0xD9,0xD1,0xEA,0xD1,0xD8,0x0B,0xDB,0x75,0xF4,0xF7,0xF1,0x8B,0xF0,0xF7,0x64,0x24,0x1C,0x8B,0xC8,0x8B,0x44,0x24,0x18,0xF7,0xE6,0x03,0xD1,0x72,0x0E,0x3B,0x54,0x24,0x14,0x77,0x08,0x72,0x07,0x3B,0x44,0x24,0x10,0x76,0x01,0x4E,0x33,0xD2,0x8B,0xC6,0x4F,0x75,0x07,0xF7,0xDA,0xF7,0xD8,0x83,0xDA,0x00,0x5B,0x5E,0x5F,0xC2,0x10,0x00
|
---|
| 138 | };
|
---|
| 139 |
|
---|
[276] | 140 | compiler.codeGenerator.PutOld( NativeCode( (const char *)Buffer_alldiv, 170 ) );
|
---|
[3] | 141 | }
|
---|
[86] | 142 | else if( userProc.GetName() == "_aulldiv" ){
|
---|
[3] | 143 | //整数除算用の特殊関数(64ビット整数対応)
|
---|
| 144 | BYTE Buffer_aulldiv[]={
|
---|
| 145 | 0x53,0x56,0x8B,0x44,0x24,0x18,0x0B,0xC0,0x75,0x18,0x8B,0x4C,0x24,0x14,
|
---|
| 146 | 0x8B,0x44,0x24,0x10,0x33,0xD2,0xF7,0xF1,0x8B,0xD8,0x8B,0x44,0x24,0x0C,
|
---|
| 147 | 0xF7,0xF1,0x8B,0xD3,0xEB,0x41,0x8B,0xC8,0x8B,0x5C,0x24,0x14,0x8B,0x54,
|
---|
| 148 | 0x24,0x10,0x8B,0x44,0x24,0x0C,0xD1,0xE9,0xD1,0xDB,0xD1,0xEA,0xD1,0xD8,
|
---|
| 149 | 0x0B,0xC9,0x75,0xF4,0xF7,0xF3,0x8B,0xF0,0xF7,0x64,0x24,0x18,0x8B,0xC8,
|
---|
| 150 | 0x8B,0x44,0x24,0x14,0xF7,0xE6,0x03,0xD1,0x72,0x0E,0x3B,0x54,0x24,0x10,
|
---|
| 151 | 0x77,0x08,0x72,0x07,0x3B,0x44,0x24,0x0C,0x76,0x01,0x4E,0x33,0xD2,0x8B,
|
---|
| 152 | 0xC6,0x5E,0x5B,0xC2,0x10,0x00
|
---|
| 153 | };
|
---|
| 154 |
|
---|
[276] | 155 | compiler.codeGenerator.PutOld( NativeCode( (const char *)Buffer_aulldiv, 104 ) );
|
---|
[3] | 156 | }
|
---|
[86] | 157 | else if( userProc.GetName() == "_allshl" ){
|
---|
[3] | 158 | //符号あり左ビットシフト用の特殊関数(64ビット整数対応)
|
---|
| 159 | BYTE Buffer_allshl[]={
|
---|
| 160 | 0x80,0xF9,0x40,0x73,0x15,0x80,0xF9,0x20,0x73,0x06,0x0F,0xA5,0xC2,0xD3,0xE0,0xC3,0x8B,0xD0,0x33,0xC0,0x80,0xE1,0x1F,0xD3,0xE2,0xC3,0x33,0xC0,0x33,0xD2,0xC3
|
---|
| 161 | };
|
---|
| 162 |
|
---|
[276] | 163 | compiler.codeGenerator.PutOld( NativeCode( (const char *)Buffer_allshl, 31 ) );
|
---|
[3] | 164 | }
|
---|
[86] | 165 | else if( userProc.GetName() == "_allshr" ){
|
---|
[3] | 166 | //符号あり右ビットシフト用の特殊関数(64ビット整数対応)
|
---|
| 167 | BYTE Buffer_allshr[]={
|
---|
| 168 | 0x80,0xF9,0x40,0x73,0x16,0x80,0xF9,0x20,0x73,0x06,0x0F,0xAD,0xD0,0xD3,0xFA,0xC3,0x8B,0xC2,0xC1,0xFA,0x1F,0x80,0xE1,0x1F,0xD3,0xF8,0xC3,0xC1,0xFA,0x1F,0x8B,0xC2,0xC3
|
---|
| 169 | };
|
---|
| 170 |
|
---|
[276] | 171 | compiler.codeGenerator.PutOld( NativeCode( (const char *)Buffer_allshr, 33 ) );
|
---|
[3] | 172 | }
|
---|
[86] | 173 | else if( userProc.GetName() == "_aullshr" ){
|
---|
[3] | 174 | //符号なし右ビットシフト用の特殊関数(64ビット整数対応)
|
---|
| 175 | BYTE Buffer_aullshr[]={
|
---|
| 176 | 0x80,0xF9,0x40, //cmp cl,40h
|
---|
| 177 | 0x73,0x15, //jae RETZERO (0040d71a)
|
---|
| 178 | 0x80,0xF9,0x20, //cmp cl,20h
|
---|
| 179 | 0x73,0x06, //jae MORE32 (0040d710)
|
---|
| 180 | 0x0F,0xAD,0xD0, //shrd eax,edx,cl
|
---|
| 181 | 0xD3,0xEA, //shr edx,cl
|
---|
| 182 | 0xC3, //ret
|
---|
| 183 | //MORE32:
|
---|
| 184 | 0x8B,0xC2, //mov eax,edx
|
---|
| 185 | 0x33,0xD2, //xor edx,edx
|
---|
| 186 | 0x80,0xE1,0x1F, //and cl,1Fh
|
---|
| 187 | 0xD3,0xE8, //shr eax,cl
|
---|
| 188 | 0xC3, //ret
|
---|
| 189 | //RETZERO:
|
---|
| 190 | 0x33,0xC0, //xor eax,eax
|
---|
| 191 | 0x33,0xD2, //xor edx,edx
|
---|
| 192 | 0xC3 //ret
|
---|
| 193 | };
|
---|
| 194 |
|
---|
[276] | 195 | compiler.codeGenerator.PutOld( NativeCode( (const char *)Buffer_aullshr, 31 ) );
|
---|
[3] | 196 | }
|
---|
[90] | 197 | else{
|
---|
[465] | 198 | compiler.errorMessenger.OutputFatalError();
|
---|
[90] | 199 | }
|
---|
| 200 | }
|
---|
[206] | 201 | void AutoGeneration( const UserProc &userProc){
|
---|
[90] | 202 | if( userProc.GetName() == "InitializeUserTypes"
|
---|
[89] | 203 | && userProc.HasParentClass()
|
---|
[131] | 204 | && userProc.GetParentClass().GetName() == "_System_TypeBase" ){
|
---|
[89] | 205 |
|
---|
[265] | 206 | compiler.GetObjectModule().meta.GetClasses().Compile_System_InitializeUserTypes();
|
---|
[86] | 207 | }
|
---|
[355] | 208 | else if( userProc.GetName() == "InitializeUserTypesForBaseType"
|
---|
| 209 | && userProc.HasParentClass()
|
---|
| 210 | && userProc.GetParentClass().GetName() == "_System_TypeBase" )
|
---|
| 211 | {
|
---|
| 212 | compiler.GetObjectModule().meta.GetClasses().Compile_System_InitializeUserTypesForBaseType();
|
---|
| 213 | }
|
---|
[95] | 214 | else if( userProc.GetName() == "RegisterGlobalRoots"
|
---|
| 215 | && userProc.HasParentClass()
|
---|
[131] | 216 | && userProc.GetParentClass().GetName() == "_System_CGarbageCollection" ){
|
---|
[95] | 217 |
|
---|
| 218 | Compile_AddGlobalRootsForGc();
|
---|
| 219 | }
|
---|
[308] | 220 | else if( userProc.GetName() == compiler.globalAreaProcName ){
|
---|
| 221 | ////////////////////////////////////////
|
---|
| 222 | // グローバル領域をコンパイル
|
---|
| 223 | ////////////////////////////////////////
|
---|
| 224 |
|
---|
[365] | 225 | UserProc::pGlobalProc = &userProc;
|
---|
| 226 |
|
---|
[537] | 227 | const UserProc *pBackUserProc = &compiler.GetCompilingUserProc();
|
---|
| 228 | compiler.StartGlobalAreaCompile();
|
---|
[308] | 229 |
|
---|
| 230 | int BackCp = cp;
|
---|
| 231 | cp=-1;
|
---|
| 232 |
|
---|
| 233 | //クラスに属する静的メンバを定義
|
---|
| 234 | compiler.GetObjectModule().meta.GetClasses().InitStaticMember();
|
---|
| 235 |
|
---|
| 236 | //グローバル実行領域をコンパイル開始
|
---|
| 237 | CompileBuffer(0,0);
|
---|
| 238 |
|
---|
| 239 | //Goto未知ラベルスケジュールが存在したらエラーにする
|
---|
| 240 | BOOST_FOREACH( const GotoLabelSchedule *pGotoLabelSchedule, compiler.codeGenerator.gotoLabelSchedules )
|
---|
| 241 | {
|
---|
| 242 | if(pGotoLabelSchedule->GetName().size()>0){
|
---|
[465] | 243 | compiler.errorMessenger.Output(6,pGotoLabelSchedule->GetName(),pGotoLabelSchedule->GetSourceCodePos());
|
---|
[308] | 244 | }
|
---|
| 245 | else{
|
---|
| 246 | char temporary[255];
|
---|
| 247 | sprintf(temporary,"%d",pGotoLabelSchedule->GetLineNum());
|
---|
[465] | 248 | compiler.errorMessenger.Output(6,temporary,pGotoLabelSchedule->GetSourceCodePos());
|
---|
[308] | 249 | }
|
---|
| 250 | }
|
---|
| 251 |
|
---|
[537] | 252 | compiler.SetCompilingUserProc( pBackUserProc );
|
---|
[308] | 253 | cp=BackCp;
|
---|
| 254 | }
|
---|
[350] | 255 | else if( userProc.HasParentClass()
|
---|
| 256 | && userProc.IsCastOperator()
|
---|
| 257 | && userProc.ReturnType().IsInterface() )
|
---|
| 258 | {
|
---|
| 259 | // インターフェイス型にキャストするためのメソッド
|
---|
| 260 |
|
---|
| 261 | int vtblMasterListIndex = userProc.GetParentClass().GetVtblMasterListIndex( &userProc.ReturnType().GetClass() );
|
---|
| 262 |
|
---|
| 263 | char temporary[1024];
|
---|
| 264 | sprintf( temporary,
|
---|
[370] | 265 | "Return New %s(ObjPtr( This ),Get_LONG_PTR( (Get_LONG_PTR( ObjPtr(This)+SizeOf(VoidPtr) ) + SizeOf(LONG_PTR)*%d) As VoidPtr ) As VoidPtr )",
|
---|
[350] | 266 | userProc.ReturnType().GetClass().GetName().c_str(),
|
---|
| 267 | vtblMasterListIndex
|
---|
| 268 | );
|
---|
| 269 | MakeMiddleCode( temporary );
|
---|
| 270 |
|
---|
| 271 | ChangeOpcode( temporary );
|
---|
| 272 | }
|
---|
[78] | 273 | else{
|
---|
[465] | 274 | compiler.errorMessenger.OutputFatalError();
|
---|
[78] | 275 | }
|
---|
[3] | 276 | }
|
---|
| 277 |
|
---|
[316] | 278 | void _compile_proc(const UserProc *pUserProc)
|
---|
| 279 | {
|
---|
[3] | 280 | extern char *basbuf;
|
---|
| 281 | extern HANDLE hHeap;
|
---|
[253] | 282 | int i3,i4,BaseOffset;
|
---|
[3] | 283 | char temporary[VN_SIZE];
|
---|
| 284 |
|
---|
[206] | 285 | if( pUserProc->GetLocalVars().size() ){
|
---|
[465] | 286 | compiler.errorMessenger.OutputFatalError();
|
---|
[76] | 287 | return;
|
---|
| 288 | }
|
---|
| 289 |
|
---|
[206] | 290 | trace_for_sourcecodestep( "★★★ " << pUserProc->GetFullName() << "のコンパイルを開始" );
|
---|
| 291 |
|
---|
[75] | 292 | pUserProc->CompleteCompile();
|
---|
[3] | 293 |
|
---|
| 294 | extern BOOL bSystemProc;
|
---|
[75] | 295 | if(memcmp(pUserProc->GetName().c_str(),"_System_",8)==0) bSystemProc=1;
|
---|
[3] | 296 | else bSystemProc=0;
|
---|
| 297 |
|
---|
| 298 | extern BOOL bDebugSupportProc;
|
---|
[459] | 299 | if(memcmp(pUserProc->GetName().c_str(),"_DebugSys_",10)==0)
|
---|
| 300 | {
|
---|
| 301 | if( !compiler.IsDebug() )
|
---|
| 302 | {
|
---|
[3] | 303 | return;
|
---|
| 304 | }
|
---|
| 305 | bDebugSupportProc=1;
|
---|
| 306 | }
|
---|
| 307 | else bDebugSupportProc=0;
|
---|
| 308 |
|
---|
[278] | 309 | if( pUserProc->GetCodeSize() != 0 || pUserProc->GetNativeCode().GetSize() != 0 )
|
---|
[276] | 310 | {
|
---|
| 311 | // 既にコード生成が行われている場合はエラー
|
---|
[465] | 312 | compiler.errorMessenger.OutputFatalError();
|
---|
[276] | 313 | }
|
---|
[3] | 314 |
|
---|
[533] | 315 | compiler.StartProcedureCompile( pUserProc );
|
---|
[89] | 316 |
|
---|
[75] | 317 | if(pUserProc->IsSystem()){
|
---|
[89] | 318 | ////////////////////
|
---|
| 319 | // 特殊関数
|
---|
| 320 | ////////////////////
|
---|
| 321 |
|
---|
[3] | 322 | extern int AllLocalVarSize;
|
---|
| 323 | AllLocalVarSize=0;
|
---|
| 324 |
|
---|
[86] | 325 | SystemProc(*pUserProc);
|
---|
[3] | 326 | return;
|
---|
| 327 | }
|
---|
| 328 |
|
---|
[285] | 329 | if( !pUserProc->IsAutoGeneration() )
|
---|
| 330 | {
|
---|
| 331 | cp=pUserProc->GetCodePos();
|
---|
| 332 | for(;;cp++){
|
---|
| 333 | if(IsCommandDelimitation(basbuf[cp])) break;
|
---|
| 334 | }
|
---|
| 335 | cp--;
|
---|
[3] | 336 | }
|
---|
| 337 |
|
---|
| 338 | //ローカル変数に関する情報
|
---|
| 339 | extern int AllLocalVarSize;
|
---|
| 340 | AllLocalVarSize=0;
|
---|
| 341 |
|
---|
| 342 | //パラメータ用の変数データを考慮
|
---|
[75] | 343 | for(i3=(int)pUserProc->RealParams().size()-1;i3>=0;i3--){
|
---|
| 344 | Parameter ¶m = *pUserProc->RealParams()[i3];
|
---|
[73] | 345 |
|
---|
[275] | 346 | Variable *pVar = new Variable( param.GetVarName(), param, false, param.IsRef(), "", false );
|
---|
[3] | 347 |
|
---|
[76] | 348 | if( param.IsArray() ){
|
---|
[206] | 349 | pVar->SetArray( param.GetSubscripts() );
|
---|
[3] | 350 | }
|
---|
| 351 |
|
---|
[76] | 352 | int varSize;
|
---|
[73] | 353 | if( param.IsRef() == false && param.IsStruct() ){
|
---|
[64] | 354 | //構造体のByValパラメータ
|
---|
[76] | 355 | pVar->ThisIsParameter();
|
---|
| 356 | varSize=PTR_SIZE;
|
---|
[3] | 357 | }
|
---|
| 358 | else{
|
---|
[76] | 359 | if( param.IsArray() == false ){
|
---|
| 360 | varSize = pVar->GetMemorySize();
|
---|
[3] | 361 | }
|
---|
| 362 | else{
|
---|
[76] | 363 | varSize=PTR_SIZE;
|
---|
[3] | 364 | }
|
---|
| 365 | }
|
---|
[76] | 366 | AllLocalVarSize+=varSize;
|
---|
[206] | 367 | pVar->SetOffsetAddress( AllLocalVarSize );
|
---|
[3] | 368 |
|
---|
| 369 | //レキシカルスコープ情報
|
---|
[248] | 370 | pVar->SetScopeLevel( compiler.codeGenerator.lexicalScopes.GetNowLevel() );
|
---|
| 371 | pVar->SetScopeStartAddress( compiler.codeGenerator.lexicalScopes.GetStartAddress() );
|
---|
[392] | 372 | pVar->isLiving = true;
|
---|
[3] | 373 |
|
---|
[206] | 374 | pUserProc->GetLocalVars().push_back( pVar );
|
---|
[3] | 375 | }
|
---|
| 376 |
|
---|
| 377 | //Thisポインタを示すローカルオフセット値をセット
|
---|
| 378 | extern int LocalVar_ThisPtrOffset;
|
---|
| 379 | LocalVar_ThisPtrOffset=AllLocalVarSize;
|
---|
| 380 |
|
---|
| 381 | BaseOffset=AllLocalVarSize;
|
---|
| 382 |
|
---|
| 383 | //ret用のアドレスを考慮
|
---|
| 384 | AllLocalVarSize+=sizeof(long);
|
---|
| 385 |
|
---|
| 386 |
|
---|
| 387 | ///////////////////////
|
---|
| 388 | // ここからコード生成
|
---|
| 389 |
|
---|
| 390 | //sub esp,AllLocalVarSize(スケジュール)
|
---|
[253] | 391 | const PertialSchedule *pAllLocalVarPertialSchedule = compiler.codeGenerator.op_sub_esp( 0, true );
|
---|
[3] | 392 |
|
---|
| 393 | //push ebp
|
---|
[225] | 394 | compiler.codeGenerator.op_push(REG_EBP);
|
---|
[3] | 395 |
|
---|
| 396 | //mov ebp,esp
|
---|
[235] | 397 | compiler.codeGenerator.op_mov_RR( REG_EBP, REG_ESP );
|
---|
[3] | 398 |
|
---|
| 399 | //push ebx
|
---|
[225] | 400 | compiler.codeGenerator.op_push(REG_EBX);
|
---|
[3] | 401 |
|
---|
| 402 | //push esi
|
---|
[235] | 403 | compiler.codeGenerator.op_push( REG_ESI );
|
---|
[3] | 404 |
|
---|
| 405 | //push edi
|
---|
[235] | 406 | compiler.codeGenerator.op_push( REG_EDI );
|
---|
[3] | 407 |
|
---|
[75] | 408 | if( !pUserProc->ReturnType().IsNull() ){
|
---|
[3] | 409 | //戻り値が存在するとき
|
---|
| 410 |
|
---|
[75] | 411 | const char *temp = pUserProc->GetName().c_str();
|
---|
| 412 | if( temp[0]==1&&temp[1]==ESC_OPERATOR ){
|
---|
| 413 | temp = "_System_ReturnValue";
|
---|
| 414 | }
|
---|
[3] | 415 |
|
---|
[75] | 416 | if( pUserProc->ReturnType().IsStruct() ){
|
---|
[64] | 417 | //戻り値用の構造体(値型)はパラメータで引き渡される
|
---|
[3] | 418 | }
|
---|
| 419 | else{
|
---|
[89] | 420 | if( pUserProc->ReturnType().IsObject() ){
|
---|
[299] | 421 | sprintf(temporary,"%s=Nothing%c%c%s",temp,1,ESC_AS, compiler.TypeToString( pUserProc->ReturnType() ).c_str() );
|
---|
[89] | 422 | }
|
---|
| 423 | else{
|
---|
| 424 | //戻り値用の変数の定義
|
---|
[299] | 425 | sprintf(temporary,"%s%c%c%s",temp,1,ESC_AS, compiler.TypeToString( pUserProc->ReturnType() ).c_str() );
|
---|
[89] | 426 | }
|
---|
[40] | 427 |
|
---|
[3] | 428 | OpcodeDim(temporary,0);
|
---|
| 429 | }
|
---|
| 430 | }
|
---|
| 431 |
|
---|
| 432 | //プロシージャ抜け出しスケジュール(Exit Sub/Function)
|
---|
[247] | 433 | compiler.codeGenerator.exitSubCodePositions.clear();
|
---|
[3] | 434 |
|
---|
[260] | 435 | //ラベル管理オブジェクトを初期化
|
---|
[261] | 436 | compiler.codeGenerator.gotoLabels.clear();
|
---|
[3] | 437 |
|
---|
| 438 | //Gotoラベルスケジュール
|
---|
[246] | 439 | compiler.codeGenerator.gotoLabelSchedules.clear();
|
---|
[3] | 440 |
|
---|
| 441 | //With情報のメモリを確保
|
---|
| 442 | extern WITHINFO WithInfo;
|
---|
| 443 | WithInfo.ppName=(char **)HeapAlloc(hHeap,0,1);
|
---|
| 444 | WithInfo.pWithCp=(int *)HeapAlloc(hHeap,0,1);
|
---|
| 445 | WithInfo.num=0;
|
---|
| 446 |
|
---|
[541] | 447 | // 重複エラー情報をクリア
|
---|
| 448 | compiler.errorMessenger.ClearSynonymKeyWords();
|
---|
[3] | 449 |
|
---|
| 450 | //Continueアドレスを初期化
|
---|
[241] | 451 | compiler.codeGenerator.ClearContinueArea();
|
---|
[3] | 452 |
|
---|
[308] | 453 | //レキシカルスコープ情報を初期化
|
---|
| 454 | compiler.codeGenerator.lexicalScopes.Init( compiler.codeGenerator.GetNativeCodeSize() );
|
---|
| 455 |
|
---|
[251] | 456 | const PertialSchedule *pEspOffsetPertialSchedule = NULL;
|
---|
[459] | 457 | if( compiler.IsDebug() && bDebugSupportProc == 0 )
|
---|
| 458 | {
|
---|
[3] | 459 | //push dword ptr[ebp+(AllLocalVarSize-BaseOffset)](スケジュール)
|
---|
[251] | 460 | pEspOffsetPertialSchedule = compiler.codeGenerator.op_push_M( REG_EBP, 0, Schedule::None, true );
|
---|
[3] | 461 |
|
---|
| 462 | //push dword ptr[ebp](以前のebp)
|
---|
[235] | 463 | compiler.codeGenerator.op_push_M( REG_EBP );
|
---|
[3] | 464 |
|
---|
| 465 | //call _DebugSys_StartProc
|
---|
[206] | 466 | extern const UserProc *pSub_DebugSys_StartProc;
|
---|
[225] | 467 | compiler.codeGenerator.op_call(pSub_DebugSys_StartProc);
|
---|
[3] | 468 | }
|
---|
| 469 |
|
---|
[536] | 470 | if( compiler.IsCompilingClass() ){
|
---|
| 471 | if( pUserProc->GetName() == compiler.GetCompilingClass().GetName() ){
|
---|
[3] | 472 | ////////////////////////////////////
|
---|
| 473 | // コンストラクタをコンパイルするとき
|
---|
| 474 | ////////////////////////////////////
|
---|
| 475 |
|
---|
[17] | 476 | //コンストラクタのコンパイル開始を通知
|
---|
[536] | 477 | compiler.GetCompilingClass().NotifyStartConstructorCompile();
|
---|
[17] | 478 |
|
---|
[27] | 479 | //基底クラスかどうかの識別
|
---|
| 480 | //(継承元がインターフェイスの場合も基底クラスと見なす)
|
---|
[3] | 481 | BOOL bThisIsSuperClass;
|
---|
[536] | 482 | if( !compiler.GetCompilingClass().HasSuperClass() ) bThisIsSuperClass=1;
|
---|
| 483 | else if( compiler.GetCompilingClass().GetSuperClass().GetConstructorMethod() == NULL ){
|
---|
[3] | 484 | //インターフェイスを継承したときはコンストラクタを持たない
|
---|
| 485 | bThisIsSuperClass=1;
|
---|
| 486 | }
|
---|
| 487 | else bThisIsSuperClass=0;
|
---|
| 488 |
|
---|
| 489 | if(!bThisIsSuperClass){
|
---|
| 490 | /* サブクラスコンストラクタをコンパイルしているときは、
|
---|
[27] | 491 | 基底クラスのコンストラクタを呼び出す */
|
---|
[3] | 492 |
|
---|
| 493 | i3=cp+1;
|
---|
| 494 | while(IsCommandDelimitation(basbuf[i3])) i3++;
|
---|
| 495 | for(i4=0;;i3++,i4++){
|
---|
| 496 | if(!IsVariableChar(basbuf[i3])){
|
---|
| 497 | temporary[i4]=0;
|
---|
| 498 | break;
|
---|
| 499 | }
|
---|
| 500 | temporary[i4]=basbuf[i3];
|
---|
| 501 | }
|
---|
[536] | 502 | if( compiler.GetCompilingClass().GetSuperClass().GetName() == temporary ){
|
---|
[27] | 503 | //基底クラスのコンストラクタを呼び出す
|
---|
[3] | 504 | cp=i3;
|
---|
| 505 | for(i4=0;;cp++,i4++){
|
---|
| 506 | if(IsCommandDelimitation(basbuf[cp])){
|
---|
| 507 | temporary[i4]=0;
|
---|
| 508 | break;
|
---|
| 509 | }
|
---|
| 510 | temporary[i4]=basbuf[cp];
|
---|
| 511 | }
|
---|
| 512 | if(!(temporary[0]=='('&&temporary[lstrlen(temporary)-1]==')')){
|
---|
[465] | 513 | compiler.errorMessenger.Output(1,NULL,cp);
|
---|
[3] | 514 | }
|
---|
| 515 | RemoveStringPare(temporary);
|
---|
| 516 |
|
---|
[89] | 517 | Type dummyType;
|
---|
| 518 | CallProc( PROC_DEFAULT
|
---|
[536] | 519 | , &compiler.GetCompilingClass().GetSuperClass().GetConstructorMethod()->GetUserProc()
|
---|
| 520 | , compiler.GetCompilingClass().GetSuperClass().GetConstructorMethod()->GetUserProc().GetName().c_str()
|
---|
[89] | 521 | , temporary
|
---|
[331] | 522 | , Type() // baseTypeはなし
|
---|
| 523 | , dummyType
|
---|
| 524 | );
|
---|
[3] | 525 | }
|
---|
| 526 | else{
|
---|
[27] | 527 | //基底クラスのコンストラクタを暗黙的に呼び出す
|
---|
[3] | 528 | Opcode_CallProc("",
|
---|
[536] | 529 | &compiler.GetCompilingClass().GetSuperClass().GetConstructorMethod()->GetUserProc(),
|
---|
[3] | 530 | 0,
|
---|
[290] | 531 | ""
|
---|
| 532 | );
|
---|
[3] | 533 | }
|
---|
| 534 | }
|
---|
| 535 | }
|
---|
[75] | 536 | else if( pUserProc->IsDestructor() ){
|
---|
[18] | 537 | //デストラクタをコンパイルしたとき
|
---|
| 538 |
|
---|
| 539 | //デストラクタのコンパイル開始を通知
|
---|
[536] | 540 | compiler.GetCompilingClass().NotifyStartDestructorCompile();
|
---|
[18] | 541 | }
|
---|
[3] | 542 | }
|
---|
| 543 |
|
---|
| 544 | //////////////////////////////////////////
|
---|
| 545 | //////////////////////////////////////////
|
---|
| 546 | ////// プロシージャ内をコンパイル ////////
|
---|
[90] | 547 | if( pUserProc->IsAutoGeneration() ){
|
---|
| 548 | AutoGeneration( *pUserProc );
|
---|
| 549 | }
|
---|
[75] | 550 | else{
|
---|
[90] | 551 | if(pUserProc->IsMacro()){
|
---|
| 552 | CompileBuffer(ESC_ENDMACRO,0);
|
---|
| 553 | }
|
---|
| 554 | else{
|
---|
| 555 | if(pUserProc->IsSub()){
|
---|
| 556 | CompileBuffer(ESC_ENDSUB,0);
|
---|
| 557 | }
|
---|
| 558 | else if(pUserProc->IsFunction()){
|
---|
| 559 | CompileBuffer(ESC_ENDFUNCTION,0);
|
---|
| 560 | }
|
---|
| 561 | }
|
---|
[75] | 562 | }
|
---|
[3] | 563 | //////////////////////////////////////////
|
---|
| 564 | //////////////////////////////////////////
|
---|
| 565 |
|
---|
[536] | 566 | if( compiler.IsCompilingClass() ){
|
---|
[17] | 567 |
|
---|
[536] | 568 | if( compiler.GetCompilingClass().IsCompilingConstructor() ){
|
---|
[17] | 569 | // コンストラクタをコンパイルしていたとき
|
---|
[18] | 570 |
|
---|
[17] | 571 | // コンストラクタのコンパイルが完了したことを通知
|
---|
[536] | 572 | compiler.GetCompilingClass().NotifyFinishConstructorCompile();
|
---|
[17] | 573 | }
|
---|
[75] | 574 | else if( pUserProc->IsDestructor() ){
|
---|
[3] | 575 | ////////////////////////////////////
|
---|
| 576 | //デストラクタをコンパイルしたとき
|
---|
| 577 | ////////////////////////////////////
|
---|
| 578 |
|
---|
[18] | 579 | // デストラクタのコンパイルが完了したことを通知
|
---|
[536] | 580 | compiler.GetCompilingClass().NotifyFinishDestructorCompile();
|
---|
[18] | 581 |
|
---|
[536] | 582 | if( compiler.GetCompilingClass().HasSuperClass() ){
|
---|
[3] | 583 | /* サブクラスのデストラクタをコンパイルしているときは、
|
---|
[27] | 584 | 基底クラスのデストラクタを呼び出す */
|
---|
[3] | 585 |
|
---|
[536] | 586 | const CMethod *method = compiler.GetCompilingClass().GetSuperClass().GetDestructorMethod();
|
---|
[51] | 587 | if( method ){
|
---|
[3] | 588 | Opcode_CallProc("",
|
---|
[206] | 589 | &method->GetUserProc(),
|
---|
[3] | 590 | 0,
|
---|
[290] | 591 | ""
|
---|
| 592 | );
|
---|
[3] | 593 | }
|
---|
| 594 | }
|
---|
| 595 | }
|
---|
| 596 | }
|
---|
| 597 |
|
---|
| 598 | //With情報のメモリを解放
|
---|
| 599 | for(i3=0;i3<WithInfo.num;i3++){
|
---|
[465] | 600 | compiler.errorMessenger.Output(22,"With",WithInfo.pWithCp[i3]);
|
---|
[3] | 601 | HeapDefaultFree(WithInfo.ppName[i3]);
|
---|
| 602 | }
|
---|
| 603 | HeapDefaultFree(WithInfo.ppName);
|
---|
| 604 | HeapDefaultFree(WithInfo.pWithCp);
|
---|
| 605 |
|
---|
| 606 | //push ebp
|
---|
| 607 | AllLocalVarSize+=sizeof(long);
|
---|
| 608 |
|
---|
| 609 | //ローカルオブジェクトの解放処理
|
---|
[248] | 610 | compiler.codeGenerator.lexicalScopes.CallDestructorsOfScopeEnd();
|
---|
[3] | 611 |
|
---|
[34] | 612 | //プロシージャ抜け出しスケジュール(Exit Sub/Function)
|
---|
[247] | 613 | compiler.codeGenerator.ResolveExitSubSchedule();
|
---|
[34] | 614 |
|
---|
[459] | 615 | if( compiler.IsDebug() && bDebugSupportProc == 0 )
|
---|
| 616 | {
|
---|
[251] | 617 | compiler.codeGenerator.opfix( pEspOffsetPertialSchedule, AllLocalVarSize-BaseOffset-sizeof(long) );
|
---|
[34] | 618 |
|
---|
| 619 | //call _DebugSys_EndProc
|
---|
[206] | 620 | extern const UserProc *pSub_DebugSys_EndProc;
|
---|
[225] | 621 | compiler.codeGenerator.op_call(pSub_DebugSys_EndProc);
|
---|
[34] | 622 | }
|
---|
| 623 |
|
---|
[75] | 624 | if( !pUserProc->ReturnType().IsNull() ){
|
---|
[3] | 625 | //戻り値をeax、edxに設定
|
---|
| 626 | RELATIVE_VAR RelativeVar;
|
---|
| 627 |
|
---|
[75] | 628 | const char *temp = pUserProc->GetName().c_str();
|
---|
| 629 | if( temp[0]==1 && temp[1]==ESC_OPERATOR ){
|
---|
[3] | 630 | temp="_System_ReturnValue";
|
---|
[75] | 631 | }
|
---|
[76] | 632 | GetVarOffsetReadWrite(temp,&RelativeVar,Type());
|
---|
[3] | 633 |
|
---|
[290] | 634 | const Type &returnType = pUserProc->ReturnType();
|
---|
| 635 | if( returnType.IsObject() || returnType.IsStruct() )
|
---|
| 636 | {
|
---|
[3] | 637 | SetVarPtrToEax(&RelativeVar);
|
---|
[290] | 638 | if( returnType.IsObject() )
|
---|
| 639 | {
|
---|
[64] | 640 | //mov eax,dword ptr[eax]
|
---|
[225] | 641 | compiler.codeGenerator.op_mov_RM( sizeof(long), REG_EAX, REG_EAX, 0, MOD_BASE );
|
---|
[64] | 642 | }
|
---|
[3] | 643 | }
|
---|
[290] | 644 | else if( returnType.IsReal() )
|
---|
[231] | 645 | {
|
---|
[3] | 646 | //fld qword ptr[ebp+offset]
|
---|
[253] | 647 | compiler.codeGenerator.localVarPertialSchedules.push_back(
|
---|
[290] | 648 | compiler.codeGenerator.op_fld_base_offset( returnType.GetBasicType(), REG_EBP, RelativeVar.offset, Schedule::None, true )
|
---|
[253] | 649 | );
|
---|
[3] | 650 | }
|
---|
[290] | 651 | else if( returnType.Is64() )
|
---|
| 652 | {
|
---|
[3] | 653 | //mov eax,dword ptr[ebp+offset]
|
---|
[253] | 654 | compiler.codeGenerator.localVarPertialSchedules.push_back(
|
---|
| 655 | compiler.codeGenerator.op_mov_RM( sizeof(long), REG_EAX, REG_EBP, RelativeVar.offset, MOD_BASE_DISP32, Schedule::None, true )
|
---|
| 656 | );
|
---|
[3] | 657 |
|
---|
| 658 | //mov edx,dword ptr[ebp+offset+sizeof(long)]
|
---|
[253] | 659 | compiler.codeGenerator.localVarPertialSchedules.push_back(
|
---|
| 660 | compiler.codeGenerator.op_mov_RM( sizeof(long), REG_EDX, REG_EBP, RelativeVar.offset+sizeof(long), MOD_BASE_DISP32, Schedule::None, true )
|
---|
| 661 | );
|
---|
[3] | 662 | }
|
---|
[290] | 663 | else if( returnType.GetSize() == sizeof(long) )
|
---|
[253] | 664 | {
|
---|
[3] | 665 | //mov eax,dword ptr[ebp+offset]
|
---|
[253] | 666 | compiler.codeGenerator.localVarPertialSchedules.push_back(
|
---|
| 667 | compiler.codeGenerator.op_mov_RM( sizeof(long), REG_EAX, REG_EBP, RelativeVar.offset, MOD_BASE_DISP32, Schedule::None, true )
|
---|
| 668 | );
|
---|
[3] | 669 | }
|
---|
[290] | 670 | else if( returnType.GetSize() == sizeof(short) )
|
---|
| 671 | {
|
---|
[3] | 672 | //xor eax,eax(eaxを0に初期化する)
|
---|
[225] | 673 | compiler.codeGenerator.op_zero_reg(REG_EAX);
|
---|
[3] | 674 |
|
---|
| 675 | //mov ax,word ptr[ebp+offset]
|
---|
[253] | 676 | compiler.codeGenerator.localVarPertialSchedules.push_back(
|
---|
| 677 | compiler.codeGenerator.op_mov_RM( sizeof(short), REG_EAX, REG_EBP, RelativeVar.offset, MOD_BASE_DISP32, Schedule::None, true )
|
---|
| 678 | );
|
---|
[3] | 679 | }
|
---|
[290] | 680 | else if( returnType.GetSize() == sizeof(char) )
|
---|
| 681 | {
|
---|
[3] | 682 | //xor eax,eax(eaxを0に初期化する)
|
---|
[225] | 683 | compiler.codeGenerator.op_zero_reg(REG_EAX);
|
---|
[3] | 684 |
|
---|
| 685 | //mov al,byte ptr[ebp+offset]
|
---|
[253] | 686 | compiler.codeGenerator.localVarPertialSchedules.push_back(
|
---|
| 687 | compiler.codeGenerator.op_mov_RM( sizeof(char), REG_EAX, REG_EBP, RelativeVar.offset, MOD_BASE_DISP32, Schedule::None, true )
|
---|
| 688 | );
|
---|
[3] | 689 | }
|
---|
[290] | 690 | else
|
---|
| 691 | {
|
---|
[465] | 692 | compiler.errorMessenger.OutputFatalError();
|
---|
[290] | 693 | }
|
---|
[3] | 694 | }
|
---|
| 695 |
|
---|
| 696 | //ローカル変数アドレススケジュール
|
---|
[253] | 697 | BOOST_FOREACH( const PertialSchedule *pPertialSchedule, compiler.codeGenerator.localVarPertialSchedules )
|
---|
| 698 | {
|
---|
| 699 | compiler.codeGenerator.opfix_offset( pPertialSchedule, AllLocalVarSize );
|
---|
[3] | 700 | }
|
---|
[253] | 701 | compiler.codeGenerator.localVarPertialSchedules.clear();
|
---|
[206] | 702 | BOOST_FOREACH( Variable *pVar, pUserProc->GetLocalVars() ){
|
---|
[76] | 703 | //後にデバッグで利用する
|
---|
[206] | 704 | pVar->SetOffsetAddress( AllLocalVarSize - pVar->GetOffsetAddress() );
|
---|
[3] | 705 | }
|
---|
| 706 |
|
---|
| 707 | //push ebp、ret用のアドレスを考慮
|
---|
| 708 | AllLocalVarSize-=sizeof(long)*2;
|
---|
| 709 |
|
---|
| 710 | //ローカル変数用メモリを確保するためのスケジュール(subコマンド)
|
---|
[253] | 711 | compiler.codeGenerator.opfix( pAllLocalVarPertialSchedule, AllLocalVarSize - BaseOffset );
|
---|
[3] | 712 |
|
---|
| 713 | //pop edi
|
---|
[235] | 714 | compiler.codeGenerator.op_pop( REG_EDI );
|
---|
[3] | 715 |
|
---|
| 716 | //pop esi
|
---|
[235] | 717 | compiler.codeGenerator.op_pop( REG_ESI );
|
---|
[3] | 718 |
|
---|
| 719 | //pop ebx
|
---|
[225] | 720 | compiler.codeGenerator.op_pop(REG_EBX);
|
---|
[3] | 721 |
|
---|
[459] | 722 | if( compiler.IsDebug() )
|
---|
| 723 | {
|
---|
[64] | 724 | //cmp esp,ebp
|
---|
[225] | 725 | compiler.codeGenerator.op_cmp_RR( REG_ESP, REG_EBP );
|
---|
[64] | 726 |
|
---|
[240] | 727 | //je 6(次のcallとbreakpointを飛び越す)
|
---|
| 728 | compiler.codeGenerator.op_je( 6 );
|
---|
[64] | 729 |
|
---|
| 730 | //call _esp_error
|
---|
[206] | 731 | extern const UserProc *pSub_esp_error;
|
---|
[225] | 732 | compiler.codeGenerator.op_call( pSub_esp_error );
|
---|
[64] | 733 |
|
---|
| 734 | breakpoint;
|
---|
| 735 | }
|
---|
| 736 |
|
---|
[3] | 737 | //mov esp,ebp
|
---|
[235] | 738 | compiler.codeGenerator.op_mov_RR( REG_ESP, REG_EBP );
|
---|
[3] | 739 |
|
---|
| 740 | //pop ebp
|
---|
[225] | 741 | compiler.codeGenerator.op_pop(REG_EBP);
|
---|
[3] | 742 |
|
---|
| 743 | //add esp AllLocalVarSize
|
---|
[225] | 744 | compiler.codeGenerator.op_add_esp(AllLocalVarSize-BaseOffset);
|
---|
[3] | 745 |
|
---|
[75] | 746 | if( BaseOffset==0 || pUserProc->IsCdecl() ){
|
---|
[142] | 747 | //ret
|
---|
[225] | 748 | compiler.codeGenerator.op_ret();
|
---|
[3] | 749 | }
|
---|
| 750 | else{
|
---|
| 751 | //ret BaseOffset(パラメータ分のスタック領域を解放)
|
---|
[240] | 752 | compiler.codeGenerator.op_ret( (_int16)BaseOffset );
|
---|
[3] | 753 | }
|
---|
| 754 |
|
---|
[533] | 755 | compiler.FinishProcedureCompile();
|
---|
[75] | 756 |
|
---|
[533] | 757 |
|
---|
[3] | 758 | //ローカル変数のネーム情報は後に解放する
|
---|
| 759 | }
|
---|