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