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