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