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