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