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