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