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