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