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