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