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