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