[3] | 1 | #include "../BasicCompiler_Common/common.h"
|
---|
| 2 | #include "Opcode.h"
|
---|
| 3 |
|
---|
| 4 |
|
---|
| 5 | void SystemProc(char *name){
|
---|
| 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 |
|
---|
| 28 | extern BOOL bCompilingGlobal;
|
---|
| 29 | BOOL bBackCompilingGlobal;
|
---|
| 30 | bBackCompilingGlobal=bCompilingGlobal;
|
---|
| 31 | bCompilingGlobal=1;
|
---|
| 32 |
|
---|
| 33 | int BackCp;
|
---|
| 34 | BackCp=cp;
|
---|
| 35 | cp=-1;
|
---|
| 36 |
|
---|
| 37 | extern BOOL bDebugCompile;
|
---|
| 38 | if(bDebugCompile){
|
---|
| 39 | //デバッグ用の変数を定義
|
---|
| 40 | DebugVariable();
|
---|
| 41 | }
|
---|
| 42 |
|
---|
| 43 | //GC用の変数を定義
|
---|
| 44 | InitGCVariables();
|
---|
| 45 |
|
---|
| 46 | GetGlobalDataForDll();
|
---|
| 47 |
|
---|
| 48 | bCompilingGlobal=bBackCompilingGlobal;
|
---|
| 49 | cp=BackCp;
|
---|
| 50 |
|
---|
| 51 | //ret
|
---|
| 52 | OpBuffer[obp++]=(char)0xC3;
|
---|
| 53 | }
|
---|
| 54 | else if(lstrcmp(name,"_System_InitStaticLocalVariables")==0){
|
---|
| 55 | //静的ローカルオブジェクトのコンストラクタ呼び出し
|
---|
| 56 |
|
---|
| 57 | extern int MaxGlobalVarNum;
|
---|
| 58 | extern VARIABLE *GlobalVar;
|
---|
| 59 | int i;
|
---|
| 60 | for(i=0;i<MaxGlobalVarNum;i++){
|
---|
| 61 | if(_memicmp(GlobalVar[i].name,"Static%",7)==0){
|
---|
| 62 | //コンストラクタ呼び出し
|
---|
| 63 | if(GlobalVar[i].type==DEF_OBJECT){
|
---|
| 64 |
|
---|
| 65 | //エラー用
|
---|
| 66 | cp=GlobalVar[i].source_code_address;
|
---|
| 67 |
|
---|
| 68 | TYPEINFO TypeInfo;
|
---|
| 69 | TypeInfo.type=GlobalVar[i].type;
|
---|
| 70 | TypeInfo.u.lpIndex=GlobalVar[i].u.index;
|
---|
| 71 | CallConstractor(
|
---|
| 72 | GlobalVar[i].name,
|
---|
| 73 | GlobalVar[i].SubScripts,
|
---|
| 74 | TypeInfo,
|
---|
| 75 | GlobalVar[i].ConstractParameter);
|
---|
| 76 | }
|
---|
| 77 | }
|
---|
| 78 | }
|
---|
| 79 |
|
---|
| 80 | //ret
|
---|
| 81 | OpBuffer[obp++]=(char)0xC3;
|
---|
| 82 | }
|
---|
| 83 | else if(lstrcmp(name,"_System_Call_Destructor_of_GlobalObject")==0){
|
---|
| 84 |
|
---|
| 85 | extern BOOL bCompilingGlobal;
|
---|
| 86 | BOOL bBackCompilingGlobal;
|
---|
| 87 | bBackCompilingGlobal=bCompilingGlobal;
|
---|
| 88 | bCompilingGlobal=1;
|
---|
| 89 |
|
---|
| 90 | CallDestrouctorsOfScope();
|
---|
| 91 |
|
---|
| 92 | bCompilingGlobal=bBackCompilingGlobal;
|
---|
| 93 |
|
---|
| 94 |
|
---|
| 95 | //ret
|
---|
| 96 | OpBuffer[obp++]=(char)0xC3;
|
---|
| 97 | }
|
---|
| 98 | else if(lstrcmp(name,"_System_GetSp")==0){
|
---|
| 99 | //mov eax,esp
|
---|
| 100 | op_mov_RR(REG_EAX,REG_ESP);
|
---|
| 101 |
|
---|
| 102 | //add eax,PTR_SIZE
|
---|
| 103 | op_add_RV8(REG_EAX,PTR_SIZE);
|
---|
| 104 |
|
---|
| 105 | //ret
|
---|
| 106 | OpBuffer[obp++]=(char)0xC3;
|
---|
| 107 | }
|
---|
| 108 | else if(lstrcmp(name,"_allrem")==0){
|
---|
| 109 | //乗除演算用の特殊関数(64ビット整数対応)
|
---|
| 110 | BYTE Buffer_allrem[]={
|
---|
| 111 | 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
|
---|
| 112 | };
|
---|
| 113 |
|
---|
| 114 | memcpy(OpBuffer+obp,Buffer_allrem,178);
|
---|
| 115 | obp+=178;
|
---|
| 116 | }
|
---|
| 117 | else if(lstrcmp(name,"_aullrem")==0){
|
---|
| 118 | //乗除演算用の特殊関数(64ビット整数対応)
|
---|
| 119 | BYTE Buffer_aullrem[]={
|
---|
| 120 | 0x53,0x8B,0x44,0x24,0x14,0x0B,0xC0,0x75,0x18,0x8B,0x4C,0x24,0x10,0x8B,
|
---|
| 121 | 0x44,0x24,0x0C,0x33,0xD2,0xF7,0xF1,0x8B,0x44,0x24,0x08,0xF7,0xF1,0x8B,
|
---|
| 122 | 0xC2,0x33,0xD2,0xEB,0x50,0x8B,0xC8,0x8B,0x5C,0x24,0x10,0x8B,0x54,0x24,
|
---|
| 123 | 0x0C,0x8B,0x44,0x24,0x08,0xD1,0xE9,0xD1,0xDB,0xD1,0xEA,0xD1,0xD8,0x0B,
|
---|
| 124 | 0xC9,0x75,0xF4,0xF7,0xF3,0x8B,0xC8,0xF7,0x64,0x24,0x14,0x91,0xF7,0x64,
|
---|
| 125 | 0x24,0x10,0x03,0xD1,0x72,0x0E,0x3B,0x54,0x24,0x0C,0x77,0x08,0x72,0x0E,
|
---|
| 126 | 0x3B,0x44,0x24,0x08,0x76,0x08,0x2B,0x44,0x24,0x10,0x1B,0x54,0x24,0x14,
|
---|
| 127 | 0x2B,0x44,0x24,0x08,0x1B,0x54,0x24,0x0C,0xF7,0xDA,0xF7,0xD8,0x83,0xDA,
|
---|
| 128 | 0x00,0x5B,0xC2,0x10,0x00
|
---|
| 129 | };
|
---|
| 130 |
|
---|
| 131 | memcpy(OpBuffer+obp,Buffer_aullrem,117);
|
---|
| 132 | obp+=117;
|
---|
| 133 | }
|
---|
| 134 | else if(lstrcmp(name,"_allmul")==0){
|
---|
| 135 | //乗算用の特殊関数(64ビット整数対応)
|
---|
| 136 | BYTE Buffer_allmul[]={
|
---|
| 137 | 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
|
---|
| 138 | };
|
---|
| 139 |
|
---|
| 140 | memcpy(OpBuffer+obp,Buffer_allmul,52);
|
---|
| 141 | obp+=52;
|
---|
| 142 | }
|
---|
| 143 | else if(lstrcmp(name,"_alldiv")==0){
|
---|
| 144 | //除算用の特殊関数(64ビット整数対応)
|
---|
| 145 | BYTE Buffer_alldiv[]={
|
---|
| 146 | 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
|
---|
| 147 | };
|
---|
| 148 |
|
---|
| 149 | memcpy(OpBuffer+obp,Buffer_alldiv,170);
|
---|
| 150 | obp+=170;
|
---|
| 151 | }
|
---|
| 152 | else if(lstrcmp(name,"_aulldiv")==0){
|
---|
| 153 | //整数除算用の特殊関数(64ビット整数対応)
|
---|
| 154 | BYTE Buffer_aulldiv[]={
|
---|
| 155 | 0x53,0x56,0x8B,0x44,0x24,0x18,0x0B,0xC0,0x75,0x18,0x8B,0x4C,0x24,0x14,
|
---|
| 156 | 0x8B,0x44,0x24,0x10,0x33,0xD2,0xF7,0xF1,0x8B,0xD8,0x8B,0x44,0x24,0x0C,
|
---|
| 157 | 0xF7,0xF1,0x8B,0xD3,0xEB,0x41,0x8B,0xC8,0x8B,0x5C,0x24,0x14,0x8B,0x54,
|
---|
| 158 | 0x24,0x10,0x8B,0x44,0x24,0x0C,0xD1,0xE9,0xD1,0xDB,0xD1,0xEA,0xD1,0xD8,
|
---|
| 159 | 0x0B,0xC9,0x75,0xF4,0xF7,0xF3,0x8B,0xF0,0xF7,0x64,0x24,0x18,0x8B,0xC8,
|
---|
| 160 | 0x8B,0x44,0x24,0x14,0xF7,0xE6,0x03,0xD1,0x72,0x0E,0x3B,0x54,0x24,0x10,
|
---|
| 161 | 0x77,0x08,0x72,0x07,0x3B,0x44,0x24,0x0C,0x76,0x01,0x4E,0x33,0xD2,0x8B,
|
---|
| 162 | 0xC6,0x5E,0x5B,0xC2,0x10,0x00
|
---|
| 163 | };
|
---|
| 164 |
|
---|
| 165 | memcpy(OpBuffer+obp,Buffer_aulldiv,104);
|
---|
| 166 | obp+=104;
|
---|
| 167 | }
|
---|
| 168 | else if(lstrcmp(name,"_allshl")==0){
|
---|
| 169 | //符号あり左ビットシフト用の特殊関数(64ビット整数対応)
|
---|
| 170 | BYTE Buffer_allshl[]={
|
---|
| 171 | 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
|
---|
| 172 | };
|
---|
| 173 |
|
---|
| 174 | memcpy(OpBuffer+obp,Buffer_allshl,31);
|
---|
| 175 | obp+=31;
|
---|
| 176 | }
|
---|
| 177 | else if(lstrcmp(name,"_allshr")==0){
|
---|
| 178 | //符号あり右ビットシフト用の特殊関数(64ビット整数対応)
|
---|
| 179 | BYTE Buffer_allshr[]={
|
---|
| 180 | 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
|
---|
| 181 | };
|
---|
| 182 |
|
---|
| 183 | memcpy(OpBuffer+obp,Buffer_allshr,33);
|
---|
| 184 | obp+=33;
|
---|
| 185 | }
|
---|
| 186 | else if(lstrcmp(name,"_aullshr")==0){
|
---|
| 187 | //符号なし右ビットシフト用の特殊関数(64ビット整数対応)
|
---|
| 188 | BYTE Buffer_aullshr[]={
|
---|
| 189 | 0x80,0xF9,0x40, //cmp cl,40h
|
---|
| 190 | 0x73,0x15, //jae RETZERO (0040d71a)
|
---|
| 191 | 0x80,0xF9,0x20, //cmp cl,20h
|
---|
| 192 | 0x73,0x06, //jae MORE32 (0040d710)
|
---|
| 193 | 0x0F,0xAD,0xD0, //shrd eax,edx,cl
|
---|
| 194 | 0xD3,0xEA, //shr edx,cl
|
---|
| 195 | 0xC3, //ret
|
---|
| 196 | //MORE32:
|
---|
| 197 | 0x8B,0xC2, //mov eax,edx
|
---|
| 198 | 0x33,0xD2, //xor edx,edx
|
---|
| 199 | 0x80,0xE1,0x1F, //and cl,1Fh
|
---|
| 200 | 0xD3,0xE8, //shr eax,cl
|
---|
| 201 | 0xC3, //ret
|
---|
| 202 | //RETZERO:
|
---|
| 203 | 0x33,0xC0, //xor eax,eax
|
---|
| 204 | 0x33,0xD2, //xor edx,edx
|
---|
| 205 | 0xC3 //ret
|
---|
| 206 | };
|
---|
| 207 |
|
---|
| 208 | memcpy(OpBuffer+obp,Buffer_aullshr,31);
|
---|
| 209 | obp+=31;
|
---|
| 210 | }
|
---|
| 211 | }
|
---|
| 212 |
|
---|
| 213 | void CompileBufferInProcedure(SUBINFO *psi){
|
---|
| 214 | extern char *basbuf;
|
---|
| 215 | extern HANDLE hHeap;
|
---|
| 216 | extern SUBINFO **ppSubHash;
|
---|
| 217 | extern BOOL bDebugCompile;
|
---|
| 218 | int i3,i4,i5,VarSize,LocalVarSchedule,EspOffsetSchedule,BufferSize,BaseOffset;
|
---|
| 219 | char temporary[VN_SIZE];
|
---|
| 220 |
|
---|
| 221 | BufferSize=128;
|
---|
| 222 |
|
---|
| 223 | if(psi->bUse==0||psi->bCompile) return;
|
---|
| 224 |
|
---|
| 225 | psi->bCompile=1;
|
---|
| 226 |
|
---|
| 227 | extern BOOL bSystemProc;
|
---|
| 228 | if(memcmp(psi->name,"_System_",8)==0) bSystemProc=1;
|
---|
| 229 | else bSystemProc=0;
|
---|
| 230 |
|
---|
| 231 | extern BOOL bDebugSupportProc;
|
---|
| 232 | if(memcmp(psi->name,"_DebugSys_",10)==0){
|
---|
| 233 | if(!bDebugCompile){
|
---|
| 234 | psi->pVar=(VARIABLE *)HeapAlloc(hHeap,0,1);
|
---|
| 235 | psi->VarNum=0;
|
---|
| 236 | return;
|
---|
| 237 | }
|
---|
| 238 | bDebugSupportProc=1;
|
---|
| 239 | }
|
---|
| 240 | else bDebugSupportProc=0;
|
---|
| 241 |
|
---|
| 242 | psi->CompileAddress=obp;
|
---|
| 243 |
|
---|
| 244 | if(psi->bSystem){
|
---|
| 245 | extern int MaxLocalVarNum;
|
---|
| 246 | extern int AllLocalVarSize;
|
---|
| 247 | MaxLocalVarNum=0;
|
---|
| 248 | AllLocalVarSize=0;
|
---|
| 249 |
|
---|
| 250 | SystemProc(psi->name);
|
---|
| 251 |
|
---|
| 252 | psi->EndOpAddr=obp;
|
---|
| 253 | psi->pVar=(VARIABLE *)HeapAlloc(hHeap,0,1);
|
---|
| 254 | psi->VarNum=0;
|
---|
| 255 | return;
|
---|
| 256 | }
|
---|
| 257 |
|
---|
| 258 | cp=psi->address;
|
---|
| 259 | for(;;cp++){
|
---|
| 260 | if(IsCommandDelimitation(basbuf[cp])) break;
|
---|
| 261 | }
|
---|
| 262 | cp--;
|
---|
| 263 |
|
---|
| 264 | //ローカル変数に関する情報
|
---|
| 265 | extern VARIABLE *LocalVar;
|
---|
| 266 | extern int MaxLocalVarNum;
|
---|
| 267 | extern int AllLocalVarSize;
|
---|
| 268 | LocalVar=(VARIABLE *)HeapAlloc(hHeap,0,1);
|
---|
| 269 | MaxLocalVarNum=0;
|
---|
| 270 | AllLocalVarSize=0;
|
---|
| 271 |
|
---|
| 272 | //ローカル変数アドレススケジュール
|
---|
| 273 | extern DWORD *pLocalVarAddrSchedule;
|
---|
| 274 | extern int LocalVarAddrScheduleNum;
|
---|
| 275 | pLocalVarAddrSchedule=(DWORD *)HeapAlloc(hHeap,0,1);
|
---|
| 276 | LocalVarAddrScheduleNum=0;
|
---|
| 277 |
|
---|
| 278 | //パラメータ用の変数データを考慮
|
---|
| 279 | for(i3=psi->RealParmNum-1;i3>=0;i3--){
|
---|
| 280 | //変数データを追加
|
---|
| 281 | LocalVar=(VARIABLE *)HeapReAlloc(hHeap,0,LocalVar,(MaxLocalVarNum+1)*sizeof(VARIABLE));
|
---|
| 282 |
|
---|
| 283 | lstrcpy(LocalVar[MaxLocalVarNum].name,psi->pRealParmInfo[i3].name);
|
---|
| 284 |
|
---|
| 285 | LocalVar[MaxLocalVarNum].bArray=psi->pRealParmInfo[i3].bArray;
|
---|
| 286 | memcpy(LocalVar[MaxLocalVarNum].SubScripts,psi->pRealParmInfo[i3].SubScripts,MAX_ARRAYDIM*sizeof(int));
|
---|
| 287 |
|
---|
| 288 | LocalVar[MaxLocalVarNum].type=psi->pRealParmInfo[i3].type;
|
---|
| 289 | if(LocalVar[MaxLocalVarNum].type==DEF_OBJECT){
|
---|
| 290 | if(psi->bExport)
|
---|
| 291 | SetError(24,NULL,cp);
|
---|
| 292 | }
|
---|
| 293 |
|
---|
| 294 | LocalVar[MaxLocalVarNum].u.index=psi->pRealParmInfo[i3].u.index;
|
---|
| 295 |
|
---|
| 296 | if(psi->pRealParmInfo[i3].bByVal&&psi->pRealParmInfo[i3].type==DEF_OBJECT){
|
---|
| 297 | //実態オブジェクトのByValパラメータ
|
---|
| 298 | LocalVar[MaxLocalVarNum].fRef=REF_PARAMETER | OBJECT_PARAMETER;
|
---|
| 299 | VarSize=PTR_SIZE;
|
---|
| 300 | }
|
---|
| 301 | else{
|
---|
| 302 | if(psi->pRealParmInfo[i3].bByVal&&psi->pRealParmInfo[i3].bArray==0){
|
---|
| 303 | LocalVar[MaxLocalVarNum].fRef=0;
|
---|
| 304 | VarSize=GetTypeSize(LocalVar[MaxLocalVarNum].type,LocalVar[MaxLocalVarNum].u.index);
|
---|
| 305 | if(VarSize%PTR_SIZE) VarSize+=PTR_SIZE-(VarSize%PTR_SIZE);
|
---|
| 306 | }
|
---|
| 307 | else{
|
---|
| 308 | LocalVar[MaxLocalVarNum].fRef=REF_PARAMETER;
|
---|
| 309 | VarSize=PTR_SIZE;
|
---|
| 310 | }
|
---|
| 311 | }
|
---|
| 312 | AllLocalVarSize+=VarSize;
|
---|
| 313 | LocalVar[MaxLocalVarNum].offset=AllLocalVarSize;
|
---|
| 314 |
|
---|
| 315 | //レキシカルスコープ情報
|
---|
| 316 | LocalVar[MaxLocalVarNum].ScopeLevel=obj_LexScopes.GetNowLevel();
|
---|
| 317 | LocalVar[MaxLocalVarNum].ScopeStartAddress=obj_LexScopes.GetStartAddress();
|
---|
| 318 | LocalVar[MaxLocalVarNum].bLiving=TRUE;
|
---|
| 319 |
|
---|
| 320 | MaxLocalVarNum++;
|
---|
| 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 | pobj_CompilingClass=psi->pobj_ParentClass;
|
---|
| 334 |
|
---|
| 335 | //コンパイル中の関数
|
---|
| 336 | extern SUBINFO *pCompilingSubInfo;
|
---|
| 337 | pCompilingSubInfo=psi;
|
---|
| 338 |
|
---|
| 339 |
|
---|
| 340 | ///////////////////////
|
---|
| 341 | // ここからコード生成
|
---|
| 342 |
|
---|
| 343 | //sub esp,AllLocalVarSize(スケジュール)
|
---|
| 344 | op_sub_esp(0xFFFFFFFF);
|
---|
| 345 | LocalVarSchedule=obp-sizeof(long);
|
---|
| 346 |
|
---|
| 347 | //push ebp
|
---|
| 348 | op_push(REG_EBP);
|
---|
| 349 |
|
---|
| 350 | //mov ebp,esp
|
---|
| 351 | OpBuffer[obp++]=(char)0x8B;
|
---|
| 352 | OpBuffer[obp++]=(char)0xEC;
|
---|
| 353 |
|
---|
| 354 | //push ebx
|
---|
| 355 | op_push(REG_EBX);
|
---|
| 356 |
|
---|
| 357 | //push esi
|
---|
| 358 | OpBuffer[obp++]=(char)0x56;
|
---|
| 359 |
|
---|
| 360 | //push edi
|
---|
| 361 | OpBuffer[obp++]=(char)0x57;
|
---|
| 362 |
|
---|
| 363 | if(psi->ReturnType!=-1){
|
---|
| 364 | //戻り値が存在するとき
|
---|
| 365 |
|
---|
| 366 | char *temp;
|
---|
| 367 | if(psi->name[0]==1&&psi->name[1]==ESC_OPERATOR) temp="_System_ReturnValue";
|
---|
| 368 | else temp=psi->name;
|
---|
| 369 |
|
---|
| 370 | if(psi->ReturnType==DEF_OBJECT){
|
---|
| 371 | //戻り値用オブジェクトのコンストラクタを呼び出す
|
---|
| 372 | if(psi->u.Return_pobj_c->ConstructorMemberSubIndex!=-1){
|
---|
| 373 | sprintf(temporary,"%s.%s()",temp,psi->u.Return_pobj_c->name);
|
---|
| 374 | OpcodeOthers(temporary);
|
---|
| 375 | }
|
---|
| 376 | }
|
---|
| 377 | else{
|
---|
| 378 | //戻り値用の変数の定義
|
---|
| 379 | sprintf(temporary,"%s%c%c",temp,1,ESC_AS);
|
---|
| 380 | GetTypeName(psi->ReturnType,psi->u.ReturnIndex,temporary+lstrlen(temporary));
|
---|
| 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
|
---|
| 432 | extern SUBINFO *pSub_DebugSys_StartProc;
|
---|
| 433 | op_call(pSub_DebugSys_StartProc);
|
---|
| 434 | }
|
---|
| 435 |
|
---|
| 436 | if(pobj_CompilingClass){
|
---|
| 437 | if(lstrcmp(psi->name,pobj_CompilingClass->name)==0){
|
---|
| 438 | ////////////////////////////////////
|
---|
| 439 | // コンストラクタをコンパイルするとき
|
---|
| 440 | ////////////////////////////////////
|
---|
| 441 |
|
---|
| 442 | //スーパークラスかどうかの識別
|
---|
| 443 | //(継承元がインターフェイスの場合もスーパークラスと見なす)
|
---|
| 444 | BOOL bThisIsSuperClass;
|
---|
| 445 | if(pobj_CompilingClass->pobj_InheritsClass==0) bThisIsSuperClass=1;
|
---|
| 446 | else if(pobj_CompilingClass->pobj_InheritsClass->ConstructorMemberSubIndex==-1){
|
---|
| 447 | //インターフェイスを継承したときはコンストラクタを持たない
|
---|
| 448 | bThisIsSuperClass=1;
|
---|
| 449 | }
|
---|
| 450 | else bThisIsSuperClass=0;
|
---|
| 451 |
|
---|
| 452 | if(!bThisIsSuperClass){
|
---|
| 453 | /* サブクラスコンストラクタをコンパイルしているときは、
|
---|
| 454 | スーパークラスのコンストラクタを呼び出す */
|
---|
| 455 |
|
---|
| 456 | i3=cp+1;
|
---|
| 457 | while(IsCommandDelimitation(basbuf[i3])) i3++;
|
---|
| 458 | for(i4=0;;i3++,i4++){
|
---|
| 459 | if(!IsVariableChar(basbuf[i3])){
|
---|
| 460 | temporary[i4]=0;
|
---|
| 461 | break;
|
---|
| 462 | }
|
---|
| 463 | temporary[i4]=basbuf[i3];
|
---|
| 464 | }
|
---|
| 465 | if(lstrcmp(temporary,
|
---|
| 466 | pobj_CompilingClass->pobj_InheritsClass->name)==0){
|
---|
| 467 | //スーパークラスのコンストラクタを呼び出す
|
---|
| 468 | cp=i3;
|
---|
| 469 | for(i4=0;;cp++,i4++){
|
---|
| 470 | if(IsCommandDelimitation(basbuf[cp])){
|
---|
| 471 | temporary[i4]=0;
|
---|
| 472 | break;
|
---|
| 473 | }
|
---|
| 474 | temporary[i4]=basbuf[cp];
|
---|
| 475 | }
|
---|
| 476 | if(!(temporary[0]=='('&&temporary[lstrlen(temporary)-1]==')')){
|
---|
| 477 | SetError(1,NULL,cp);
|
---|
| 478 | }
|
---|
| 479 | RemoveStringPare(temporary);
|
---|
| 480 |
|
---|
| 481 | i3=pobj_CompilingClass->pobj_InheritsClass->ConstructorMemberSubIndex;
|
---|
| 482 | Opcode_CallProc(temporary,
|
---|
| 483 | pobj_CompilingClass->ppobj_Method[i3]->psi,
|
---|
| 484 | 0,
|
---|
| 485 | 0,
|
---|
| 486 | "",
|
---|
| 487 | 0);
|
---|
| 488 | }
|
---|
| 489 | else{
|
---|
| 490 | //スーパークラスのコンストラクタを暗黙的に呼び出す
|
---|
| 491 | i3=pobj_CompilingClass->pobj_InheritsClass->ConstructorMemberSubIndex;
|
---|
| 492 | Opcode_CallProc("",
|
---|
| 493 | pobj_CompilingClass->ppobj_Method[i3]->psi,
|
---|
| 494 | 0,
|
---|
| 495 | 0,
|
---|
| 496 | "",
|
---|
| 497 | 0);
|
---|
| 498 | }
|
---|
| 499 | }
|
---|
| 500 |
|
---|
| 501 |
|
---|
| 502 | //実体クラスを持つメンバのコンストラクタ(引数有りを除く)を呼び出す
|
---|
| 503 | int offset;
|
---|
| 504 | int MemberTypeSize;
|
---|
| 505 | int MemberObjectNum;
|
---|
| 506 | if(pobj_CompilingClass->vtbl_num) offset=PTR_SIZE;
|
---|
| 507 | else offset=0;
|
---|
| 508 | for(i3=0;i3<pobj_CompilingClass->iMemberNum;i3++){
|
---|
| 509 | offset=GetSizeOfClassMember(pobj_CompilingClass,pobj_CompilingClass->ppobj_Member[i3]->name,NULL);
|
---|
| 510 |
|
---|
| 511 | if(pobj_CompilingClass->ppobj_Member[i3]->TypeInfo.type==DEF_OBJECT){
|
---|
| 512 | if(pobj_CompilingClass->ppobj_Member[i3]->TypeInfo.u.pobj_Class->ConstructorMemberSubIndex!=-1){
|
---|
| 513 | i5=pobj_CompilingClass->ppobj_Member[i3]->TypeInfo.u.pobj_Class->ConstructorMemberSubIndex;
|
---|
| 514 | if(pobj_CompilingClass->ppobj_Member[i3]->TypeInfo.u.pobj_Class->ppobj_Method[i5]->psi->RealParmNum==1){ //Thisポインタを第一引数に持ち合わせるため、引数なしの場合はこの値が1になる
|
---|
| 515 |
|
---|
| 516 | MemberTypeSize=
|
---|
| 517 | GetTypeSize(pobj_CompilingClass->ppobj_Member[i3]->TypeInfo.type,
|
---|
| 518 | pobj_CompilingClass->ppobj_Member[i3]->TypeInfo.u.lpIndex);
|
---|
| 519 |
|
---|
| 520 | MemberObjectNum=
|
---|
| 521 | JumpSubScripts(pobj_CompilingClass->ppobj_Member[i3]->SubScripts);
|
---|
| 522 |
|
---|
| 523 | for(i4=0;i4<MemberObjectNum;i4++){
|
---|
| 524 | //Thisポインタをecxにコピー
|
---|
| 525 | SetThisPtrToReg(REG_ECX);
|
---|
| 526 |
|
---|
| 527 | //add ecx,offset
|
---|
| 528 | OpBuffer[obp++]=(char)0x81;
|
---|
| 529 | OpBuffer[obp++]=(char)0xC1;
|
---|
| 530 | *((long *)(OpBuffer+obp))=offset+i4*MemberTypeSize;
|
---|
| 531 | obp+=sizeof(long);
|
---|
| 532 |
|
---|
| 533 | //push ecx
|
---|
| 534 | op_push(REG_ECX);
|
---|
| 535 |
|
---|
| 536 | //call constructor
|
---|
| 537 | op_call(pobj_CompilingClass->ppobj_Member[i3]->TypeInfo.u.pobj_Class->ppobj_Method[i5]->psi);
|
---|
| 538 | }
|
---|
| 539 | }
|
---|
| 540 | }
|
---|
| 541 | }
|
---|
| 542 | }
|
---|
| 543 |
|
---|
| 544 |
|
---|
| 545 | //仮想関数テーブルを初期化
|
---|
| 546 | if(pobj_CompilingClass->vtbl_num&&
|
---|
| 547 | pobj_CompilingClass->IsHoldAbstractFunction()==0){
|
---|
| 548 | //関数テーブルに値をセット
|
---|
| 549 | offset=pobj_CompilingClass->GetVtblGlobalOffset();
|
---|
| 550 |
|
---|
| 551 | //mov eax,offset
|
---|
| 552 | OpBuffer[obp++]=(char)0xB8;
|
---|
| 553 | *((long *)(OpBuffer+obp))=offset;
|
---|
| 554 | pobj_DataTableSchedule->add();
|
---|
| 555 | obp+=sizeof(long);
|
---|
| 556 |
|
---|
| 557 | //Thisポインタをecxにコピー
|
---|
| 558 | SetThisPtrToReg(REG_ECX);
|
---|
| 559 |
|
---|
| 560 | //mov dword ptr[ecx],eax
|
---|
| 561 | OpBuffer[obp++]=(char)0x89;
|
---|
| 562 | OpBuffer[obp++]=(char)0x01;
|
---|
| 563 | }
|
---|
| 564 | }
|
---|
| 565 | }
|
---|
| 566 |
|
---|
| 567 | //////////////////////////////////////////
|
---|
| 568 | //////////////////////////////////////////
|
---|
| 569 | ////// プロシージャ内をコンパイル ////////
|
---|
| 570 | if(psi->dwType==SUBTYPE_SUB) CompileBuffer(ESC_ENDSUB,0);
|
---|
| 571 | else if(psi->dwType==SUBTYPE_FUNCTION) CompileBuffer(ESC_ENDFUNCTION,0);
|
---|
| 572 | else if(psi->dwType==SUBTYPE_MACRO) CompileBuffer(ESC_ENDMACRO,0);
|
---|
| 573 | //////////////////////////////////////////
|
---|
| 574 | //////////////////////////////////////////
|
---|
| 575 |
|
---|
| 576 | if(pobj_CompilingClass){
|
---|
| 577 | if(psi->name[0]=='~'){
|
---|
| 578 | ////////////////////////////////////
|
---|
| 579 | //デストラクタをコンパイルしたとき
|
---|
| 580 | ////////////////////////////////////
|
---|
| 581 |
|
---|
| 582 | if(pobj_CompilingClass->pobj_InheritsClass){
|
---|
| 583 | /* サブクラスのデストラクタをコンパイルしているときは、
|
---|
| 584 | スーパークラスのデストラクタを呼び出す */
|
---|
| 585 |
|
---|
| 586 | i3=pobj_CompilingClass->pobj_InheritsClass->DestructorMemberSubIndex;
|
---|
| 587 | if(i3!=-1){
|
---|
| 588 | Opcode_CallProc("",
|
---|
| 589 | pobj_CompilingClass->ppobj_Method[i3]->psi,
|
---|
| 590 | 0,
|
---|
| 591 | 0,
|
---|
| 592 | "",
|
---|
| 593 | 0);
|
---|
| 594 | }
|
---|
| 595 | }
|
---|
| 596 |
|
---|
| 597 | //実体クラスを持つメンバのデストラクタを呼び出す
|
---|
| 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--){
|
---|
| 604 | MemberTypeSize=
|
---|
| 605 | GetTypeSize(pobj_CompilingClass->ppobj_Member[i3]->TypeInfo.type,
|
---|
| 606 | pobj_CompilingClass->ppobj_Member[i3]->TypeInfo.u.lpIndex);
|
---|
| 607 |
|
---|
| 608 | MemberObjectNum=
|
---|
| 609 | JumpSubScripts(pobj_CompilingClass->ppobj_Member[i3]->SubScripts);
|
---|
| 610 |
|
---|
| 611 | offset-=MemberTypeSize*MemberObjectNum;
|
---|
| 612 |
|
---|
| 613 | if(pobj_CompilingClass->ppobj_Member[i3]->TypeInfo.type==DEF_OBJECT){
|
---|
| 614 | if(pobj_CompilingClass->ppobj_Member[i3]->TypeInfo.u.pobj_Class->DestructorMemberSubIndex!=-1){
|
---|
| 615 | for(i4=MemberObjectNum-1;i4>=0;i4--){
|
---|
| 616 | //Thisポインタをecxにコピー
|
---|
| 617 | SetThisPtrToReg(REG_ECX);
|
---|
| 618 |
|
---|
| 619 | //add ecx,offset
|
---|
| 620 | OpBuffer[obp++]=(char)0x81;
|
---|
| 621 | OpBuffer[obp++]=(char)0xC1;
|
---|
| 622 | *((long *)(OpBuffer+obp))=offset+i4*MemberTypeSize;
|
---|
| 623 | obp+=sizeof(long);
|
---|
| 624 |
|
---|
| 625 | //push ecx
|
---|
| 626 | op_push(REG_ECX);
|
---|
| 627 |
|
---|
| 628 | //call destructor
|
---|
| 629 | i5=pobj_CompilingClass->ppobj_Member[i3]->TypeInfo.u.pobj_Class->DestructorMemberSubIndex;
|
---|
| 630 | op_call(pobj_CompilingClass->ppobj_Member[i3]->TypeInfo.u.pobj_Class->ppobj_Method[i5]->psi);
|
---|
| 631 | }
|
---|
| 632 | }
|
---|
| 633 | }
|
---|
| 634 | }
|
---|
| 635 | }
|
---|
| 636 | }
|
---|
| 637 |
|
---|
| 638 | //プロシージャ抜け出しスケジュール(Exit Sub/Function)
|
---|
| 639 | for(i3=0;i3<ExitSubScheduleNum;i3++){
|
---|
| 640 | *((long *)(OpBuffer+pExitSubSchedule[i3]))=obp-(pExitSubSchedule[i3]+sizeof(long));
|
---|
| 641 | }
|
---|
| 642 | HeapDefaultFree(pExitSubSchedule);
|
---|
| 643 |
|
---|
| 644 | if(bDebugCompile&&bDebugSupportProc==0){
|
---|
| 645 | *((long *)(OpBuffer+EspOffsetSchedule))=AllLocalVarSize-BaseOffset;
|
---|
| 646 |
|
---|
| 647 | //call _DebugSys_EndProc
|
---|
| 648 | extern SUBINFO *pSub_DebugSys_EndProc;
|
---|
| 649 | op_call(pSub_DebugSys_EndProc);
|
---|
| 650 | }
|
---|
| 651 |
|
---|
| 652 | //ラベル用のメモリを解放
|
---|
| 653 | for(i3=0;i3<MaxLabelNum;i3++){
|
---|
| 654 | if(pLabelNames[i3].pName) HeapDefaultFree(pLabelNames[i3].pName);
|
---|
| 655 | }
|
---|
| 656 | HeapDefaultFree(pLabelNames);
|
---|
| 657 |
|
---|
| 658 | //Goto未知ラベルスケジュールを解放
|
---|
| 659 | for(i3=0;i3<GotoLabelScheduleNum;i3++){
|
---|
| 660 | if(pGotoLabelSchedule[i3].pName){
|
---|
| 661 | SetError(6,pGotoLabelSchedule[i3].pName,pGotoLabelSchedule[i3].now_cp);
|
---|
| 662 | HeapDefaultFree(pGotoLabelSchedule[i3].pName);
|
---|
| 663 | }
|
---|
| 664 | else{
|
---|
| 665 | sprintf(temporary,"%d",pGotoLabelSchedule[i3].line);
|
---|
| 666 | SetError(6,temporary,pGotoLabelSchedule[i3].now_cp);
|
---|
| 667 | }
|
---|
| 668 | }
|
---|
| 669 | HeapDefaultFree(pGotoLabelSchedule);
|
---|
| 670 |
|
---|
| 671 | //With情報のメモリを解放
|
---|
| 672 | for(i3=0;i3<WithInfo.num;i3++){
|
---|
| 673 | SetError(22,"With",WithInfo.pWithCp[i3]);
|
---|
| 674 | HeapDefaultFree(WithInfo.ppName[i3]);
|
---|
| 675 | }
|
---|
| 676 | HeapDefaultFree(WithInfo.ppName);
|
---|
| 677 | HeapDefaultFree(WithInfo.pWithCp);
|
---|
| 678 |
|
---|
| 679 | //重複エラー情報管理のメモリを解放
|
---|
| 680 | for(i3=0;i3<SynonymErrorNum;i3++) HeapDefaultFree(SynonymErrorWords[i3]);
|
---|
| 681 | HeapDefaultFree(SynonymErrorWords);
|
---|
| 682 |
|
---|
| 683 | //push ebp
|
---|
| 684 | AllLocalVarSize+=sizeof(long);
|
---|
| 685 |
|
---|
| 686 | //ローカルオブジェクトの解放処理
|
---|
| 687 | CallDestrouctorsOfScope();
|
---|
| 688 |
|
---|
| 689 | if(psi->ReturnType!=-1){
|
---|
| 690 | //戻り値をeax、edxに設定
|
---|
| 691 | RELATIVE_VAR RelativeVar;
|
---|
| 692 | LONG_PTR lpIndex;
|
---|
| 693 |
|
---|
| 694 | char *temp;
|
---|
| 695 | if(psi->name[0]==1&&psi->name[1]==ESC_OPERATOR)
|
---|
| 696 | temp="_System_ReturnValue";
|
---|
| 697 | else temp=psi->name;
|
---|
| 698 | GetVarOffset(1,temp,&i3,&RelativeVar,&lpIndex);
|
---|
| 699 |
|
---|
| 700 | i3=psi->ReturnType;
|
---|
| 701 |
|
---|
| 702 | if(i3==DEF_OBJECT){
|
---|
| 703 | SetVarPtrToEax(&RelativeVar);
|
---|
| 704 | }
|
---|
| 705 | else if(i3==DEF_DOUBLE){
|
---|
| 706 | //fld qword ptr[ebp+offset]
|
---|
| 707 | OpBuffer[obp++]=(char)0xDD;
|
---|
| 708 | OpBuffer[obp++]=(char)0x85;
|
---|
| 709 | *((long *)(OpBuffer+obp))=RelativeVar.offset;
|
---|
| 710 | AddLocalVarAddrSchedule();
|
---|
| 711 | obp+=sizeof(long);
|
---|
| 712 | }
|
---|
| 713 | else if(i3==DEF_SINGLE){
|
---|
| 714 | //fld dword ptr[ebp+offset]
|
---|
| 715 | OpBuffer[obp++]=(char)0xD9;
|
---|
| 716 | OpBuffer[obp++]=(char)0x85;
|
---|
| 717 | *((long *)(OpBuffer+obp))=RelativeVar.offset;
|
---|
| 718 | AddLocalVarAddrSchedule();
|
---|
| 719 | obp+=sizeof(long);
|
---|
| 720 | }
|
---|
| 721 | else if(i3==DEF_INT64||i3==DEF_QWORD){
|
---|
| 722 | //mov eax,dword ptr[ebp+offset]
|
---|
| 723 | OpBuffer[obp++]=(char)0x8B;
|
---|
| 724 | OpBuffer[obp++]=(char)0x85;
|
---|
| 725 | *((long *)(OpBuffer+obp))=RelativeVar.offset;
|
---|
| 726 | AddLocalVarAddrSchedule();
|
---|
| 727 | obp+=sizeof(long);
|
---|
| 728 |
|
---|
| 729 | //mov edx,dword ptr[ebp+offset+sizeof(long)]
|
---|
| 730 | OpBuffer[obp++]=(char)0x8B;
|
---|
| 731 | OpBuffer[obp++]=(char)0x95;
|
---|
| 732 | *((long *)(OpBuffer+obp))=RelativeVar.offset+sizeof(long);
|
---|
| 733 | AddLocalVarAddrSchedule();
|
---|
| 734 | obp+=sizeof(long);
|
---|
| 735 | }
|
---|
| 736 | else if(i3==DEF_LONG||i3==DEF_DWORD||
|
---|
| 737 | IsPtrType(i3)){
|
---|
| 738 | //mov eax,dword ptr[ebp+offset]
|
---|
| 739 | OpBuffer[obp++]=(char)0x8B;
|
---|
| 740 | OpBuffer[obp++]=(char)0x85;
|
---|
| 741 | *((long *)(OpBuffer+obp))=RelativeVar.offset;
|
---|
| 742 | AddLocalVarAddrSchedule();
|
---|
| 743 | obp+=sizeof(long);
|
---|
| 744 | }
|
---|
| 745 | else if(i3==DEF_INTEGER||i3==DEF_WORD){
|
---|
| 746 | //xor eax,eax(eaxを0に初期化する)
|
---|
| 747 | op_zero_reg(REG_EAX);
|
---|
| 748 |
|
---|
| 749 | //mov ax,word ptr[ebp+offset]
|
---|
| 750 | OpBuffer[obp++]=(char)0x66;
|
---|
| 751 | OpBuffer[obp++]=(char)0x8B;
|
---|
| 752 | OpBuffer[obp++]=(char)0x85;
|
---|
| 753 | *((long *)(OpBuffer+obp))=RelativeVar.offset;
|
---|
| 754 | AddLocalVarAddrSchedule();
|
---|
| 755 | obp+=sizeof(long);
|
---|
| 756 | }
|
---|
| 757 | else if(i3==DEF_CHAR||i3==DEF_BYTE){
|
---|
| 758 | //xor eax,eax(eaxを0に初期化する)
|
---|
| 759 | op_zero_reg(REG_EAX);
|
---|
| 760 |
|
---|
| 761 | //mov al,byte ptr[ebp+offset]
|
---|
| 762 | OpBuffer[obp++]=(char)0x8A;
|
---|
| 763 | OpBuffer[obp++]=(char)0x85;
|
---|
| 764 | *((long *)(OpBuffer+obp))=RelativeVar.offset;
|
---|
| 765 | AddLocalVarAddrSchedule();
|
---|
| 766 | obp+=sizeof(long);
|
---|
| 767 | }
|
---|
| 768 | }
|
---|
| 769 |
|
---|
| 770 | //ローカル変数アドレススケジュール
|
---|
| 771 | for(i3=0;i3<LocalVarAddrScheduleNum;i3++){
|
---|
| 772 | *((long *)(OpBuffer+pLocalVarAddrSchedule[i3]))+=AllLocalVarSize;
|
---|
| 773 | }
|
---|
| 774 | HeapDefaultFree(pLocalVarAddrSchedule);
|
---|
| 775 | for(i3=0;i3<MaxLocalVarNum;i3++){
|
---|
| 776 | LocalVar[i3].offset=AllLocalVarSize-LocalVar[i3].offset;//後にデバッグで利用する
|
---|
| 777 | }
|
---|
| 778 |
|
---|
| 779 | //push ebp、ret用のアドレスを考慮
|
---|
| 780 | AllLocalVarSize-=sizeof(long)*2;
|
---|
| 781 |
|
---|
| 782 | //ローカル変数用メモリを確保するためのスケジュール(subコマンド)
|
---|
| 783 | *((long *)(OpBuffer+LocalVarSchedule))=AllLocalVarSize-BaseOffset;
|
---|
| 784 |
|
---|
| 785 | //pop edi
|
---|
| 786 | OpBuffer[obp++]=(char)0x5F;
|
---|
| 787 |
|
---|
| 788 | //pop esi
|
---|
| 789 | OpBuffer[obp++]=(char)0x5E;
|
---|
| 790 |
|
---|
| 791 | //pop ebx
|
---|
| 792 | op_pop(REG_EBX);
|
---|
| 793 |
|
---|
| 794 | //mov esp,ebp
|
---|
| 795 | OpBuffer[obp++]=(char)0x8B;
|
---|
| 796 | OpBuffer[obp++]=(char)0xE5;
|
---|
| 797 |
|
---|
| 798 | //pop ebp
|
---|
| 799 | op_pop(REG_EBP);
|
---|
| 800 |
|
---|
| 801 | //add esp AllLocalVarSize
|
---|
| 802 | op_add_esp(AllLocalVarSize-BaseOffset);
|
---|
| 803 |
|
---|
| 804 | if(BaseOffset==0||psi->bCdecl){
|
---|
| 805 | //ret 0
|
---|
| 806 | OpBuffer[obp++]=(char)0xC3;
|
---|
| 807 | }
|
---|
| 808 | else{
|
---|
| 809 | //ret BaseOffset(パラメータ分のスタック領域を解放)
|
---|
| 810 | OpBuffer[obp++]=(char)0xC2;
|
---|
| 811 | *((_int16 *)(OpBuffer+obp))=(_int16)BaseOffset;
|
---|
| 812 | obp+=sizeof(_int16);
|
---|
| 813 | }
|
---|
| 814 |
|
---|
| 815 | psi->EndOpAddr=obp;
|
---|
| 816 | psi->pVar=LocalVar;
|
---|
| 817 | psi->VarNum=MaxLocalVarNum;
|
---|
| 818 |
|
---|
| 819 | //ローカル変数のネーム情報は後に解放する
|
---|
| 820 | }
|
---|
| 821 | void CompileLocal(){
|
---|
| 822 | extern SUBINFO **ppSubHash;
|
---|
| 823 | int i2;
|
---|
| 824 | SUBINFO *psi;
|
---|
| 825 |
|
---|
| 826 | extern BOOL bDll;
|
---|
| 827 | if(bDll){
|
---|
| 828 | //DLLの場合はグローバル変数を初期化するための関数を一番初めにコンパイルする
|
---|
| 829 | psi=GetSubHash("_System_InitDllGlobalVariables");
|
---|
| 830 | if(psi){
|
---|
| 831 | CompileBufferInProcedure(psi);
|
---|
| 832 | }
|
---|
| 833 | else SetError(300,NULL,cp);
|
---|
| 834 | }
|
---|
| 835 |
|
---|
| 836 | //_System_InitStaticLocalVariablesは一番最後にコンパイル
|
---|
| 837 | //※一般関数内の静的変数オブジェクトをすべて収集しなければならない
|
---|
| 838 | extern SUBINFO *pSub_System_InitStaticLocalVariables;
|
---|
| 839 | pSub_System_InitStaticLocalVariables->bCompile=1;
|
---|
| 840 |
|
---|
| 841 | //_System_Call_Destructor_of_GlobalObjectは一番最後にコンパイル
|
---|
| 842 | extern SUBINFO *pSub_System_Call_Destructor_of_GlobalObject;
|
---|
| 843 | pSub_System_Call_Destructor_of_GlobalObject->bCompile=1;
|
---|
| 844 |
|
---|
| 845 | Repeat:
|
---|
| 846 | for(i2=0;i2<MAX_HASH;i2++){
|
---|
| 847 | psi=ppSubHash[i2];
|
---|
| 848 | while(psi){
|
---|
| 849 | CompileBufferInProcedure(psi);
|
---|
| 850 | psi=psi->pNextData;
|
---|
| 851 | }
|
---|
| 852 | }
|
---|
| 853 |
|
---|
| 854 | //プロシージャコンパイルによって、プロシージャコンパイルが必要になる場合
|
---|
| 855 | for(i2=0;i2<MAX_HASH;i2++){
|
---|
| 856 | psi=ppSubHash[i2];
|
---|
| 857 | while(psi){
|
---|
| 858 | if(psi->bUse&&psi->bCompile==0){
|
---|
| 859 | goto Repeat;
|
---|
| 860 | }
|
---|
| 861 |
|
---|
| 862 | psi=psi->pNextData;
|
---|
| 863 | }
|
---|
| 864 | }
|
---|
| 865 |
|
---|
| 866 | //_System_InitStaticLocalVariablesは一番最後にコンパイル
|
---|
| 867 | pSub_System_InitStaticLocalVariables->bCompile=0;
|
---|
| 868 | CompileBufferInProcedure(pSub_System_InitStaticLocalVariables);
|
---|
| 869 |
|
---|
| 870 | //_System_Call_Destructor_of_GlobalObjectは一番最後にコンパイル
|
---|
| 871 | pSub_System_Call_Destructor_of_GlobalObject->bCompile=0;
|
---|
| 872 | CompileBufferInProcedure(pSub_System_Call_Destructor_of_GlobalObject);
|
---|
| 873 | }
|
---|