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