Changeset 64 in dev for BasicCompiler32/increment.cpp
- Timestamp:
- Mar 8, 2007, 2:49:34 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
BasicCompiler32/increment.cpp
r62 r64 1 1 #include "../BasicCompiler_Common/common.h" 2 2 #include "Opcode.h" 3 4 5 void SetRealVariable(int type,RELATIVE_VAR *pRelativeVar){6 if(pRelativeVar->dwKind==VAR_GLOBAL){7 if(pRelativeVar->bOffsetOffset){8 //fstp ptr[ecx+offset]9 op_fstp_base_offset(type,REG_ECX,(int)pRelativeVar->offset);10 obp-=sizeof(long);11 pobj_GlobalVarSchedule->add();12 obp+=sizeof(long);13 }14 else{15 //mov ecx,offset16 op_mov_RV(REG_ECX,(int)pRelativeVar->offset);17 obp-=sizeof(long);18 pobj_GlobalVarSchedule->add();19 obp+=sizeof(long);20 21 //fstp ptr[ecx]22 op_fstp_basereg(type,REG_ECX);23 }24 }25 else if(pRelativeVar->dwKind==VAR_REFGLOBAL){26 if(pRelativeVar->bOffsetOffset){27 //add ecx,qword ptr[offset]28 op_add_RM(sizeof(long),REG_ECX,REG_NON,(int)pRelativeVar->offset,MOD_DISP32);29 }30 else{31 //mov ecx,qword ptr[offset]32 op_mov_RM(sizeof(long),REG_ECX,REG_NON,(int)pRelativeVar->offset,MOD_DISP32);33 }34 obp-=sizeof(long);35 pobj_GlobalVarSchedule->add();36 obp+=sizeof(long);37 38 goto directmem;39 }40 else if(pRelativeVar->dwKind==VAR_LOCAL){41 if(pRelativeVar->bOffsetOffset){42 //fstp ptr[ebp+ecx+offset]43 op_fstp_base_offset_ex(type,REG_EBP,REG_ECX,(int)pRelativeVar->offset,USE_OFFSET);44 }45 else{46 //fstp ptr[ebp+offset]47 op_fstp_base_offset(type,REG_EBP,(int)pRelativeVar->offset);48 }49 obp-=sizeof(long);50 AddLocalVarAddrSchedule();51 obp+=sizeof(long);52 }53 else if(pRelativeVar->dwKind==VAR_REFLOCAL){54 if(pRelativeVar->bOffsetOffset){55 //add ecx,qword ptr[ebp+offset]56 op_add_RM(sizeof(long),REG_ECX,REG_EBP,(int)pRelativeVar->offset,MOD_BASE_DISP32);57 }58 else{59 //mov ecx,qword ptr[ebp+offset]60 op_mov_RM(sizeof(long),REG_ECX,REG_EBP,(int)pRelativeVar->offset,MOD_BASE_DISP32);61 }62 obp-=sizeof(long);63 AddLocalVarAddrSchedule();64 obp+=sizeof(long);65 66 goto directmem;67 }68 else if(pRelativeVar->dwKind==VAR_DIRECTMEM){69 directmem:70 //fstp ptr[ecx]71 op_fstp_basereg(type,REG_ECX);72 }73 }74 75 void ExtendTypeTo32(int type,int reg);76 void ExtendTypeTo64(int type){77 if(Is64Type(type)) return;78 79 ExtendTypeTo32(type,REG_EAX);80 81 if(IsSignedType(type)){82 //cdq83 op_cdq();84 }85 else{86 //xor edx,edx87 op_zero_reg(REG_EDX);88 }89 }90 void ExtendTypeTo32(int type,int reg){91 if(type==DEF_INTEGER || (isUnicode&&type==DEF_CHAR)){92 //movsx reg32,reg1693 op_movsx_R32R16(reg,reg);94 }95 else if(type==DEF_WORD){96 //and reg,0000FFFFh97 op_and_RV(reg,(int)0x0000FFFF);98 }99 else if(type==DEF_SBYTE || (isUnicode==false&&type==DEF_CHAR)){100 //movsx reg32,reg8101 op_movsx_R32R8(reg,reg);102 }103 else if(type==DEF_BYTE||type==DEF_BOOLEAN){104 //and reg,000000FFh105 op_and_RV(reg,(int)0xFF);106 }107 }108 void ExtendTypeTo16(int type,int reg){109 if(type==DEF_SBYTE || (isUnicode==false&&type==DEF_CHAR)){110 //movsx reg16,reg8111 op_movsx_R16R8(reg,reg);112 }113 else if(type==DEF_BYTE||type==DEF_BOOLEAN){114 //and reg,000000FFh115 op_and_RV(reg,(int)0xFF);116 }117 }118 119 void SetWholeVariable(int var_size,int type,RELATIVE_VAR *pRelative,int reg){120 if(type==DEF_DOUBLE){121 //Double型122 123 }124 else if(type==DEF_SINGLE){125 //Single型126 127 }128 else{129 //その他の整数130 131 if(var_size==sizeof(_int64)){132 //eaxの値を64ビット(edx:eax)に拡張する133 ExtendTypeTo64(type);134 }135 else if(var_size==sizeof(long)){136 //レジスタの値を32ビット(eax)に拡張する137 ExtendTypeTo32(type,reg);138 }139 else if(var_size==sizeof(short)){140 //レジスタの値を16ビット(ax)に拡張する141 ExtendTypeTo16(type,reg);142 }143 //8ビットは拡張なし144 }145 146 if(var_size==sizeof(_int64)){147 //下位32ビット148 SetWholeVariable(sizeof(long),DEF_LONG,pRelative,REG_EAX);149 150 //上位32ビット151 pRelative->offset+=sizeof(long);152 SetWholeVariable(sizeof(long),DEF_LONG,pRelative,REG_EDX);153 pRelative->offset-=sizeof(long);154 155 return;156 }157 158 if(pRelative->dwKind==VAR_GLOBAL){159 if(pRelative->bOffsetOffset){160 //mov ptr[ecx+offset],eax/ax/al161 op_mov_MR(var_size,reg,REG_ECX,(int)pRelative->offset,MOD_BASE_DISP32);162 }163 else{164 //mov ptr[offset],eax/ax/al165 op_mov_MR(var_size,reg,0,(int)pRelative->offset,MOD_DISP32);166 }167 obp-=sizeof(long);168 pobj_GlobalVarSchedule->add();169 obp+=sizeof(long);170 }171 else if(pRelative->dwKind==VAR_REFGLOBAL){172 if(pRelative->bOffsetOffset){173 //add ecx,qword ptr[offset]174 op_add_RM(var_size,REG_ECX,REG_NON,(int)pRelative->offset,MOD_DISP32);175 }176 else{177 //mov ecx,qword ptr[offset]178 op_mov_RM(var_size,REG_ECX,REG_NON,(int)pRelative->offset,MOD_DISP32);179 }180 obp-=sizeof(long);181 pobj_GlobalVarSchedule->add();182 obp+=sizeof(long);183 184 goto directmem;185 }186 else if(pRelative->dwKind==VAR_LOCAL){187 if(pRelative->bOffsetOffset){188 //mov ptr[ebp+ecx+offset],eax/ax/al189 op_mov_MR_ex(var_size,reg,REG_EBP,REG_ECX,(int)pRelative->offset,USE_OFFSET);190 }191 else{192 //mov ptr[ebp+offset],eax/ax/al193 op_mov_MR(var_size,reg,REG_EBP,(int)pRelative->offset,MOD_BASE_DISP32);194 }195 obp-=sizeof(long);196 AddLocalVarAddrSchedule();197 obp+=sizeof(long);198 }199 else if(pRelative->dwKind==VAR_REFLOCAL){200 if(pRelative->bOffsetOffset){201 //add ecx,qword ptr[ebp+offset]202 op_add_RM(var_size,REG_ECX,REG_EBP,(int)pRelative->offset,MOD_BASE_DISP32);203 }204 else{205 //mov ecx,qword ptr[ebp+offset]206 op_mov_RM(var_size,REG_ECX,REG_EBP,(int)pRelative->offset,MOD_BASE_DISP32);207 }208 obp-=sizeof(long);209 AddLocalVarAddrSchedule();210 obp+=sizeof(long);211 212 goto directmem;213 }214 else if(pRelative->dwKind==VAR_DIRECTMEM){215 directmem:216 217 //mov ptr[ecx],eax/ax/al218 op_mov_MR(var_size,reg,REG_ECX,0,MOD_BASE);219 }220 }221 222 void SetVariableFromReg(int VarType,int CalcType,RELATIVE_VAR *pRelativeVar){223 /////////////////////////////////////////////////224 // raxの内容を変数にコピーするコードを抽出225 /////////////////////////////////////////////////226 227 if(VarType==DEF_DOUBLE){228 //Double型変数へスタックの内容を格納する229 SetRealVariable(VarType,pRelativeVar);230 }231 else if(VarType==DEF_SINGLE){232 //Single型変数へスタックの内容を格納する233 SetRealVariable(VarType,pRelativeVar);234 }235 else{236 //整数型237 SetWholeVariable(GetTypeSize(VarType,-1),CalcType,pRelativeVar,REG_EAX);238 }239 }240 241 3 242 4 void IncDec(int idCalc, char *lpszLeft, char *lpszRight){ … … 438 200 } 439 201 440 SetVariableFrom Reg(VarType,VarType,&VarRelativeVar);202 SetVariableFromEax(VarType,VarType,&VarRelativeVar); 441 203 }
Note:
See TracChangeset
for help on using the changeset viewer.