[206] | 1 | #include "stdafx.h"
|
---|
| 2 |
|
---|
[225] | 3 | #include <Compiler.h>
|
---|
| 4 |
|
---|
[3] | 5 | #include "../BasicCompiler_Common/common.h"
|
---|
| 6 | #include "Opcode.h"
|
---|
| 7 |
|
---|
| 8 | void SetReg_RealVariable(int type,RELATIVE_VAR *pRelativeVar){
|
---|
| 9 | if(pRelativeVar->dwKind==VAR_GLOBAL){
|
---|
| 10 | if(pRelativeVar->bOffsetOffset){
|
---|
| 11 | //fld ptr[ecx+offset]
|
---|
[225] | 12 | compiler.codeGenerator.op_fld_base_offset(type,REG_ECX,(int)pRelativeVar->offset);
|
---|
[3] | 13 | obp-=sizeof(long);
|
---|
| 14 | pobj_GlobalVarSchedule->add();
|
---|
| 15 | obp+=sizeof(long);
|
---|
| 16 | }
|
---|
| 17 | else{
|
---|
| 18 | //mov ecx,offset
|
---|
[225] | 19 | compiler.codeGenerator.op_mov_RV(REG_ECX,(int)pRelativeVar->offset);
|
---|
[3] | 20 | obp-=sizeof(long);
|
---|
| 21 | pobj_GlobalVarSchedule->add();
|
---|
| 22 | obp+=sizeof(long);
|
---|
| 23 |
|
---|
| 24 | //fld ptr[ecx]
|
---|
[225] | 25 | compiler.codeGenerator.op_fld_basereg(type,REG_ECX);
|
---|
[3] | 26 | }
|
---|
| 27 | }
|
---|
[62] | 28 | else if(pRelativeVar->dwKind==VAR_REFGLOBAL){
|
---|
| 29 | SetError(300,NULL,cp);
|
---|
| 30 | }
|
---|
[3] | 31 | else if(pRelativeVar->dwKind==VAR_LOCAL){
|
---|
| 32 | if(pRelativeVar->bOffsetOffset){
|
---|
| 33 | //fld ptr[ebp+ecx+offset]
|
---|
[225] | 34 | compiler.codeGenerator.op_fld_base_offset_ex(type,REG_EBP,REG_ECX,(int)pRelativeVar->offset,USE_OFFSET);
|
---|
[3] | 35 | obp-=sizeof(long);
|
---|
| 36 | AddLocalVarAddrSchedule();
|
---|
| 37 | obp+=sizeof(long);
|
---|
| 38 | }
|
---|
| 39 | else{
|
---|
| 40 | //fld ptr[ebp+offset]
|
---|
[225] | 41 | compiler.codeGenerator.op_fld_base_offset(type,REG_EBP,(int)pRelativeVar->offset);
|
---|
[3] | 42 | obp-=sizeof(long);
|
---|
| 43 | AddLocalVarAddrSchedule();
|
---|
| 44 | obp+=sizeof(long);
|
---|
| 45 | }
|
---|
| 46 | }
|
---|
| 47 | else if(pRelativeVar->dwKind==VAR_REFLOCAL){
|
---|
| 48 | if(pRelativeVar->bOffsetOffset){
|
---|
| 49 | //add ecx,qword ptr[ebp+offset]
|
---|
[225] | 50 | compiler.codeGenerator.op_add_RM(sizeof(long),REG_ECX,REG_EBP,(int)pRelativeVar->offset,MOD_BASE_DISP32);
|
---|
[3] | 51 | obp-=sizeof(long);
|
---|
| 52 | AddLocalVarAddrSchedule();
|
---|
| 53 | obp+=sizeof(long);
|
---|
| 54 | }
|
---|
| 55 | else{
|
---|
| 56 | //mov ecx,qword ptr[ebp+offset]
|
---|
[225] | 57 | compiler.codeGenerator.op_mov_RM(sizeof(long),REG_ECX,REG_EBP,(int)pRelativeVar->offset,MOD_BASE_DISP32);
|
---|
[3] | 58 | obp-=sizeof(long);
|
---|
| 59 | AddLocalVarAddrSchedule();
|
---|
| 60 | obp+=sizeof(long);
|
---|
| 61 | }
|
---|
| 62 |
|
---|
| 63 | goto directmem;
|
---|
| 64 | }
|
---|
| 65 | else if(pRelativeVar->dwKind==VAR_DIRECTMEM){
|
---|
| 66 | directmem:
|
---|
| 67 | //fld ptr[ecx]
|
---|
[225] | 68 | compiler.codeGenerator.op_fld_basereg(type,REG_ECX);
|
---|
[3] | 69 | }
|
---|
| 70 | }
|
---|
[97] | 71 | void SetReg_WholeVariable(int type,RELATIVE_VAR *pRelativeVar,int reg, bool is64Head){
|
---|
[66] | 72 | int varSize;
|
---|
[3] | 73 |
|
---|
[66] | 74 | varSize=GetTypeSize(type,-1);
|
---|
[3] | 75 |
|
---|
[66] | 76 | if(varSize==sizeof(_int64)){
|
---|
[3] | 77 | //64ビットの場合はedx:eaxにロード
|
---|
| 78 | if(reg!=REG_EAX){
|
---|
| 79 | SetError(300,NULL,cp);
|
---|
| 80 | return;
|
---|
| 81 | }
|
---|
| 82 |
|
---|
| 83 | //下位32ビットをeaxにロード
|
---|
| 84 | SetReg_WholeVariable(DEF_LONG,pRelativeVar,REG_EAX);
|
---|
| 85 |
|
---|
| 86 | //上位32ビットをedxにロード
|
---|
[97] | 87 | SetReg_WholeVariable(DEF_LONG,pRelativeVar,REG_EDX, true);
|
---|
[3] | 88 |
|
---|
| 89 | return;
|
---|
| 90 | }
|
---|
| 91 |
|
---|
[97] | 92 | int offsetOf64Head = 0;
|
---|
| 93 | if( is64Head ){
|
---|
| 94 | offsetOf64Head = sizeof(long);
|
---|
| 95 | }
|
---|
| 96 |
|
---|
[3] | 97 | if(pRelativeVar->dwKind==VAR_GLOBAL){
|
---|
| 98 | if(pRelativeVar->bOffsetOffset){
|
---|
| 99 | //mov reg, ptr[ecx+offset]
|
---|
[225] | 100 | compiler.codeGenerator.op_mov_RM(varSize,reg,REG_ECX,(int)pRelativeVar->offset + offsetOf64Head,MOD_BASE_DISP32);
|
---|
[3] | 101 | }
|
---|
| 102 | else{
|
---|
| 103 | //mov reg, ptr[offset]
|
---|
[225] | 104 | compiler.codeGenerator.op_mov_RM(varSize,reg,0,(int)pRelativeVar->offset + offsetOf64Head,MOD_DISP32);
|
---|
[3] | 105 | }
|
---|
[62] | 106 | obp-=sizeof(long);
|
---|
| 107 | pobj_GlobalVarSchedule->add();
|
---|
| 108 | obp+=sizeof(long);
|
---|
[3] | 109 | }
|
---|
[62] | 110 | else if(pRelativeVar->dwKind==VAR_REFGLOBAL){
|
---|
| 111 | if(pRelativeVar->bOffsetOffset){
|
---|
| 112 | //add ecx,qword ptr[offset]
|
---|
[225] | 113 | compiler.codeGenerator.op_add_RM(varSize,REG_ECX,REG_NON,(int)pRelativeVar->offset,MOD_DISP32);
|
---|
[62] | 114 | }
|
---|
| 115 | else{
|
---|
| 116 | //mov ecx,qword ptr[offset]
|
---|
[225] | 117 | compiler.codeGenerator.op_mov_RM(varSize,REG_ECX,REG_NON,(int)pRelativeVar->offset,MOD_DISP32);
|
---|
[62] | 118 | }
|
---|
| 119 | obp-=sizeof(long);
|
---|
| 120 | pobj_GlobalVarSchedule->add();
|
---|
| 121 | obp+=sizeof(long);
|
---|
| 122 |
|
---|
| 123 | goto directmem;
|
---|
| 124 | }
|
---|
[3] | 125 | else if(pRelativeVar->dwKind==VAR_LOCAL){
|
---|
| 126 | if(pRelativeVar->bOffsetOffset){
|
---|
| 127 | //mov reg, ptr[ebp+ecx+offset]
|
---|
[225] | 128 | compiler.codeGenerator.op_mov_RM_ex(varSize,reg,REG_EBP,REG_ECX,(int)pRelativeVar->offset + offsetOf64Head,USE_OFFSET);
|
---|
[3] | 129 | }
|
---|
| 130 | else{
|
---|
| 131 | //mov reg, ptr[ebp+offset]
|
---|
[225] | 132 | compiler.codeGenerator.op_mov_RM(varSize,reg,REG_EBP,(int)pRelativeVar->offset + offsetOf64Head,MOD_BASE_DISP32);
|
---|
[3] | 133 | }
|
---|
[62] | 134 | obp-=sizeof(long);
|
---|
| 135 | AddLocalVarAddrSchedule();
|
---|
| 136 | obp+=sizeof(long);
|
---|
[3] | 137 | }
|
---|
| 138 | else if(pRelativeVar->dwKind==VAR_REFLOCAL){
|
---|
| 139 | if(pRelativeVar->bOffsetOffset){
|
---|
| 140 | //add ecx,qword ptr[ebp+offset]
|
---|
[225] | 141 | compiler.codeGenerator.op_add_RM(varSize,REG_ECX,REG_EBP,(int)pRelativeVar->offset,MOD_BASE_DISP32);
|
---|
[3] | 142 | }
|
---|
| 143 | else{
|
---|
| 144 | //mov ecx,qword ptr[ebp+offset]
|
---|
[225] | 145 | compiler.codeGenerator.op_mov_RM(varSize,REG_ECX,REG_EBP,(int)pRelativeVar->offset,MOD_BASE_DISP32);
|
---|
[3] | 146 | }
|
---|
[62] | 147 | obp-=sizeof(long);
|
---|
| 148 | AddLocalVarAddrSchedule();
|
---|
| 149 | obp+=sizeof(long);
|
---|
[3] | 150 |
|
---|
| 151 | goto directmem;
|
---|
| 152 | }
|
---|
| 153 | else if(pRelativeVar->dwKind==VAR_DIRECTMEM){
|
---|
| 154 | directmem:
|
---|
[97] | 155 | if( is64Head ){
|
---|
| 156 | //mov reg, ptr[ecx]
|
---|
[225] | 157 | compiler.codeGenerator.op_mov_RM(varSize,reg,REG_ECX,offsetOf64Head,MOD_BASE_DISP8);
|
---|
[97] | 158 | }
|
---|
| 159 | else{
|
---|
| 160 | //mov reg, ptr[ecx]
|
---|
[225] | 161 | compiler.codeGenerator.op_mov_RM(varSize,reg,REG_ECX,0,MOD_BASE);
|
---|
[97] | 162 | }
|
---|
[3] | 163 | }
|
---|
| 164 | }
|
---|
| 165 |
|
---|
| 166 |
|
---|
| 167 |
|
---|
| 168 | void PushLongVariable(RELATIVE_VAR *pRelativeVar){
|
---|
| 169 | if(pRelativeVar->dwKind==VAR_GLOBAL){
|
---|
| 170 | if(pRelativeVar->bOffsetOffset){
|
---|
| 171 | //push dword ptr[ecx+offset]
|
---|
| 172 | OpBuffer[obp++]=(char)0xFF;
|
---|
| 173 | OpBuffer[obp++]=(char)0xB1;
|
---|
| 174 | *((long *)(OpBuffer+obp))=pRelativeVar->offset;
|
---|
| 175 | pobj_GlobalVarSchedule->add();
|
---|
| 176 | obp+=sizeof(long);
|
---|
| 177 | }
|
---|
| 178 | else{
|
---|
| 179 | //push dword ptr[offset]
|
---|
| 180 | OpBuffer[obp++]=(char)0xFF;
|
---|
| 181 | OpBuffer[obp++]=(char)0x35;
|
---|
| 182 | *((long *)(OpBuffer+obp))=pRelativeVar->offset;
|
---|
| 183 | pobj_GlobalVarSchedule->add();
|
---|
| 184 | obp+=sizeof(long);
|
---|
| 185 | }
|
---|
| 186 | }
|
---|
[62] | 187 | else if(pRelativeVar->dwKind==VAR_REFGLOBAL){
|
---|
| 188 | //mov eax,dword ptr[offset]
|
---|
[225] | 189 | compiler.codeGenerator.op_mov_RM( sizeof(long), REG_EAX, REG_NON, (int)pRelativeVar->offset, MOD_DISP32 );
|
---|
[62] | 190 | obp-=sizeof(long);
|
---|
| 191 | pobj_GlobalVarSchedule->add();
|
---|
| 192 | obp+=sizeof(long);
|
---|
| 193 |
|
---|
| 194 | if(pRelativeVar->bOffsetOffset){
|
---|
| 195 | //add eax,ecx
|
---|
[225] | 196 | compiler.codeGenerator.op_add_RR( REG_EAX, REG_ECX );
|
---|
[62] | 197 | }
|
---|
| 198 |
|
---|
| 199 | //push dword ptr[eax]
|
---|
[225] | 200 | compiler.codeGenerator.op_push_M( REG_EAX );
|
---|
[62] | 201 | }
|
---|
[3] | 202 | else if(pRelativeVar->dwKind==VAR_LOCAL){
|
---|
| 203 | if(pRelativeVar->bOffsetOffset){
|
---|
| 204 | //add ecx,offset
|
---|
| 205 | OpBuffer[obp++]=(char)0x81;
|
---|
| 206 | OpBuffer[obp++]=(char)0xC1;
|
---|
| 207 | *((long *)(OpBuffer+obp))=pRelativeVar->offset;
|
---|
| 208 | AddLocalVarAddrSchedule();
|
---|
| 209 | obp+=sizeof(long);
|
---|
| 210 |
|
---|
| 211 | //push dword ptr[ebp+ecx]
|
---|
[225] | 212 | compiler.codeGenerator.PutOld(
|
---|
| 213 | (char)0xFF,
|
---|
| 214 | (char)0x74,
|
---|
| 215 | (char)0x0D,
|
---|
| 216 | (char)0x00
|
---|
| 217 | );
|
---|
[3] | 218 | }
|
---|
| 219 | else{
|
---|
| 220 | //push dword ptr[ebp+offset]
|
---|
| 221 | OpBuffer[obp++]=(char)0xFF;
|
---|
| 222 | OpBuffer[obp++]=(char)0xB5;
|
---|
| 223 | *((long *)(OpBuffer+obp))=pRelativeVar->offset;
|
---|
| 224 | AddLocalVarAddrSchedule();
|
---|
| 225 | obp+=sizeof(long);
|
---|
| 226 | }
|
---|
| 227 | }
|
---|
| 228 | else if(pRelativeVar->dwKind==VAR_REFLOCAL){
|
---|
| 229 | //mov eax,dword ptr[ebp+offset]
|
---|
| 230 | OpBuffer[obp++]=(char)0x8B;
|
---|
| 231 | OpBuffer[obp++]=(char)0x85;
|
---|
| 232 | *((long *)(OpBuffer+obp))=pRelativeVar->offset;
|
---|
| 233 | AddLocalVarAddrSchedule();
|
---|
| 234 | obp+=sizeof(long);
|
---|
| 235 |
|
---|
| 236 | if(pRelativeVar->bOffsetOffset){
|
---|
| 237 | //add eax,ecx
|
---|
[225] | 238 | compiler.codeGenerator.op_add_RR( REG_EAX, REG_ECX );
|
---|
[3] | 239 | }
|
---|
| 240 |
|
---|
| 241 | //push dword ptr[eax]
|
---|
[225] | 242 | compiler.codeGenerator.op_push_M( REG_EAX );
|
---|
[3] | 243 | }
|
---|
| 244 | else if(pRelativeVar->dwKind==VAR_DIRECTMEM){
|
---|
| 245 | //push dword ptr[ecx]
|
---|
[225] | 246 | compiler.codeGenerator.op_push_M( REG_ECX );
|
---|
[3] | 247 | }
|
---|
| 248 | }
|
---|