Changeset 64 in dev for BasicCompiler32/Compile_Set_Var.cpp
- Timestamp:
- Mar 8, 2007, 2:49:34 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
BasicCompiler32/Compile_Set_Var.cpp
r63 r64 7 7 } 8 8 9 void SetObjectVariable(LONG_PTR lpVarIndex,int CalcType,LONG_PTR lpCalcIndex,BOOL bUseHeap){ 9 void SetStructVariable(LONG_PTR lpVarIndex,int CalcType,LONG_PTR lpCalcIndex,BOOL bUseHeap){ 10 /* 11 TODO: 消す 10 12 /////////////////////////////////////////////////////////////////// 11 13 // オペレータ '=' のオーバーロード関数を呼ぶ … … 32 34 //成功したとき、またはエラーが発行されたとき 33 35 return; 34 } 35 36 37 if( CalcType == DEF_ OBJECT ){36 }*/ 37 38 39 if( CalcType == DEF_STRUCT ){ 38 40 CClass *pVarClass = (CClass *)lpVarIndex; 39 41 CClass *pCalcClass = (CClass *)lpCalcIndex; 40 42 41 43 42 if( pVarClass->IsEquals( pCalcClass ) //等しい 43 || pVarClass->IsSubClass( pCalcClass ) ){ //派生・継承関係 44 if( pVarClass->IsEquals( pCalcClass ) ){ //等しい 44 45 45 46 //双方のオブジェクト型が一致、または派生・継承関係にあるとき … … 81 82 } 82 83 84 85 void SetRealVariable(int VarType,int CalcType,RELATIVE_VAR *pRelativeVar){ 86 if( !IsRealNumberType( CalcType ) ){ 87 // 実数へ変換 88 // 64bit edx:eax -> st(0) 89 // 32bit eax -> st(0) 90 91 if( Is64Type( CalcType ) ){ 92 //64ビット整数型 93 94 //push edx 95 op_push( REG_EDX ); 96 97 //push eax 98 op_push( REG_EAX ); 99 100 //fild qword ptr[esp] 101 op_fld_ptr_esp(DEF_INT64); 102 103 //pop 104 op_pop( REG_NON ); 105 106 //pop 107 op_pop( REG_NON ); 108 } 109 else{ 110 //push eax 111 op_push( REG_EAX ); 112 113 //fild qword ptr[esp] 114 op_fld_ptr_esp(DEF_LONG); 115 116 //pop 117 op_pop( REG_NON ); 118 } 119 } 120 121 if(pRelativeVar->dwKind==VAR_GLOBAL){ 122 if(pRelativeVar->bOffsetOffset){ 123 //fstp ptr[ecx+offset] 124 op_fstp_base_offset(VarType,REG_ECX,(int)pRelativeVar->offset); 125 obp-=sizeof(long); 126 pobj_GlobalVarSchedule->add(); 127 obp+=sizeof(long); 128 } 129 else{ 130 //mov ecx,offset 131 op_mov_RV(REG_ECX,(int)pRelativeVar->offset); 132 obp-=sizeof(long); 133 pobj_GlobalVarSchedule->add(); 134 obp+=sizeof(long); 135 136 //fstp ptr[ecx] 137 op_fstp_basereg(VarType,REG_ECX); 138 } 139 } 140 else if(pRelativeVar->dwKind==VAR_REFGLOBAL){ 141 if(pRelativeVar->bOffsetOffset){ 142 //add ecx,qword ptr[offset] 143 op_add_RM(sizeof(long),REG_ECX,REG_NON,(int)pRelativeVar->offset,MOD_DISP32); 144 } 145 else{ 146 //mov ecx,qword ptr[offset] 147 op_mov_RM(sizeof(long),REG_ECX,REG_NON,(int)pRelativeVar->offset,MOD_DISP32); 148 } 149 obp-=sizeof(long); 150 pobj_GlobalVarSchedule->add(); 151 obp+=sizeof(long); 152 153 goto directmem; 154 } 155 else if(pRelativeVar->dwKind==VAR_LOCAL){ 156 if(pRelativeVar->bOffsetOffset){ 157 //fstp ptr[ebp+ecx+offset] 158 op_fstp_base_offset_ex(VarType,REG_EBP,REG_ECX,(int)pRelativeVar->offset,USE_OFFSET); 159 } 160 else{ 161 //fstp ptr[ebp+offset] 162 op_fstp_base_offset(VarType,REG_EBP,(int)pRelativeVar->offset); 163 } 164 obp-=sizeof(long); 165 AddLocalVarAddrSchedule(); 166 obp+=sizeof(long); 167 } 168 else if(pRelativeVar->dwKind==VAR_REFLOCAL){ 169 if(pRelativeVar->bOffsetOffset){ 170 //add ecx,qword ptr[ebp+offset] 171 op_add_RM(sizeof(long),REG_ECX,REG_EBP,(int)pRelativeVar->offset,MOD_BASE_DISP32); 172 } 173 else{ 174 //mov ecx,qword ptr[ebp+offset] 175 op_mov_RM(sizeof(long),REG_ECX,REG_EBP,(int)pRelativeVar->offset,MOD_BASE_DISP32); 176 } 177 obp-=sizeof(long); 178 AddLocalVarAddrSchedule(); 179 obp+=sizeof(long); 180 181 goto directmem; 182 } 183 else if(pRelativeVar->dwKind==VAR_DIRECTMEM){ 184 directmem: 185 //fstp ptr[ecx] 186 op_fstp_basereg(VarType,REG_ECX); 187 } 188 } 189 190 void SetBooleanVariable(int type,RELATIVE_VAR *pRelative){ 191 if(type==DEF_DOUBLE){ 192 // TODO: 実装 193 SetError(); 194 } 195 else if(type==DEF_SINGLE){ 196 // TODO: 実装 197 SetError(); 198 } 199 else if(type==DEF_INT64||type==DEF_QWORD){ 200 //cmp eax,0 201 op_cmp_value(GetTypeSize(type,-1),REG_EAX,0); 202 203 //setne al 204 op_setne( REG_EAX ); 205 206 //cmp edx,0 207 op_cmp_value(GetTypeSize(type,-1),REG_EDX,0); 208 209 //setne cl 210 op_setne( REG_ECX ); 211 212 //or al,cl 213 op_or_RR( sizeof( _int8 ), REG_EAX, REG_ECX ); 214 } 215 else{ 216 if(!IsWholeNumberType(type)){ 217 //不正な型の場合 218 SetError(9,NULL,cp); 219 return; 220 } 221 } 222 223 //cmp eax,0 224 op_cmp_value(GetTypeSize(type,-1),REG_EAX,0); 225 226 //setne al 227 op_setne( REG_EAX ); 228 229 SetWholeVariable( sizeof(char), DEF_BYTE, pRelative ); 230 } 231 232 void ExtendTypeTo32(int type,int reg); 233 void ExtendTypeTo64(int type){ 234 if(Is64Type(type)) return; 235 236 ExtendTypeTo32(type,REG_EAX); 237 238 if(IsSignedType(type)){ 239 //cdq 240 op_cdq(); 241 } 242 else{ 243 //xor edx,edx 244 op_zero_reg(REG_EDX); 245 } 246 } 247 void ExtendTypeTo32(int type,int reg){ 248 if(type==DEF_INTEGER || (isUnicode&&type==DEF_CHAR)){ 249 //movsx reg32,reg16 250 op_movsx_R32R16(reg,reg); 251 } 252 else if(type==DEF_WORD){ 253 //and reg,0000FFFFh 254 op_and_RV(reg,(int)0x0000FFFF); 255 } 256 else if(type==DEF_SBYTE || (isUnicode==false&&type==DEF_CHAR)){ 257 //movsx reg32,reg8 258 op_movsx_R32R8(reg,reg); 259 } 260 else if(type==DEF_BYTE||type==DEF_BOOLEAN){ 261 //and reg,000000FFh 262 op_and_RV(reg,(int)0xFF); 263 } 264 } 265 void ExtendTypeTo16(int type,int reg){ 266 if(type==DEF_SBYTE || (isUnicode==false&&type==DEF_CHAR)){ 267 //movsx reg16,reg8 268 op_movsx_R16R8(reg,reg); 269 } 270 else if(type==DEF_BYTE||type==DEF_BOOLEAN){ 271 //and reg,000000FFh 272 op_and_RV(reg,(int)0xFF); 273 } 274 } 275 276 void SetWholeVariable(int var_size,int type,RELATIVE_VAR *pRelative){ 277 if(type==DEF_DOUBLE){ 278 //Double型 279 // st(0)の内容をedx:eaxに変換 280 281 //TODO: 実装 282 SetError(); 283 } 284 else if(type==DEF_SINGLE){ 285 //Single型 286 // st(0)の内容をeaxに変換 287 288 //TODO: 実装 289 SetError(); 290 } 291 else{ 292 //その他の整数 293 294 if(var_size==sizeof(_int64)){ 295 //eaxの値を64ビット(edx:eax)に拡張する 296 ExtendTypeTo64(type); 297 } 298 else if(var_size==sizeof(long)){ 299 //レジスタの値を32ビット(eax)に拡張する 300 ExtendTypeTo32(type,REG_EAX); 301 } 302 else if(var_size==sizeof(short)){ 303 //レジスタの値を16ビット(ax)に拡張する 304 ExtendTypeTo16(type,REG_EAX); 305 } 306 //8ビットは拡張なし 307 } 308 309 if(var_size==sizeof(_int64)){ 310 //下位32ビット 311 SetWholeVariable(sizeof(long),DEF_LONG,pRelative); 312 313 //mov eax,edx 314 op_mov_RR( REG_EAX, REG_EDX ); 315 316 //上位32ビット 317 if( pRelative->dwKind == VAR_DIRECTMEM ){ 318 //add ecx,sizeof(long) 319 op_add_RV8( REG_ECX, sizeof(long) ); 320 } 321 pRelative->offset+=sizeof(long); 322 SetWholeVariable(sizeof(long),DEF_LONG,pRelative); 323 pRelative->offset-=sizeof(long); 324 325 return; 326 } 327 328 if(pRelative->dwKind==VAR_GLOBAL){ 329 if(pRelative->bOffsetOffset){ 330 //mov ptr[ecx+offset],eax/ax/al 331 op_mov_MR(var_size,REG_EAX,REG_ECX,(int)pRelative->offset,MOD_BASE_DISP32); 332 } 333 else{ 334 //mov ptr[offset],eax/ax/al 335 op_mov_MR(var_size,REG_EAX,0,(int)pRelative->offset,MOD_DISP32); 336 } 337 obp-=sizeof(long); 338 pobj_GlobalVarSchedule->add(); 339 obp+=sizeof(long); 340 } 341 else if(pRelative->dwKind==VAR_REFGLOBAL){ 342 if(pRelative->bOffsetOffset){ 343 //add ecx,qword ptr[offset] 344 op_add_RM(var_size,REG_ECX,REG_NON,(int)pRelative->offset,MOD_DISP32); 345 } 346 else{ 347 //mov ecx,qword ptr[offset] 348 op_mov_RM(var_size,REG_ECX,REG_NON,(int)pRelative->offset,MOD_DISP32); 349 } 350 obp-=sizeof(long); 351 pobj_GlobalVarSchedule->add(); 352 obp+=sizeof(long); 353 354 goto directmem; 355 } 356 else if(pRelative->dwKind==VAR_LOCAL){ 357 if(pRelative->bOffsetOffset){ 358 //mov ptr[ebp+ecx+offset],eax/ax/al 359 op_mov_MR_ex(var_size,REG_EAX,REG_EBP,REG_ECX,(int)pRelative->offset,USE_OFFSET); 360 } 361 else{ 362 //mov ptr[ebp+offset],eax/ax/al 363 op_mov_MR(var_size,REG_EAX,REG_EBP,(int)pRelative->offset,MOD_BASE_DISP32); 364 } 365 obp-=sizeof(long); 366 AddLocalVarAddrSchedule(); 367 obp+=sizeof(long); 368 } 369 else if(pRelative->dwKind==VAR_REFLOCAL){ 370 if(pRelative->bOffsetOffset){ 371 //add ecx,qword ptr[ebp+offset] 372 op_add_RM(var_size,REG_ECX,REG_EBP,(int)pRelative->offset,MOD_BASE_DISP32); 373 } 374 else{ 375 //mov ecx,qword ptr[ebp+offset] 376 op_mov_RM(var_size,REG_ECX,REG_EBP,(int)pRelative->offset,MOD_BASE_DISP32); 377 } 378 obp-=sizeof(long); 379 AddLocalVarAddrSchedule(); 380 obp+=sizeof(long); 381 382 goto directmem; 383 } 384 else if(pRelative->dwKind==VAR_DIRECTMEM){ 385 directmem: 386 387 //mov ptr[ecx],eax/ax/al 388 op_mov_MR(var_size,REG_EAX,REG_ECX,0,MOD_BASE); 389 } 390 } 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 /* 417 TODO: 消す 83 418 void SetDoubleVariable(int type,DWORD VarKind,DWORD offset,BOOL bOffsetOffset){ 84 419 ChangeTypeToDouble(type); … … 972 1307 } 973 1308 } 974 void SetBooleanVariable(int type,RELATIVE_VAR *pRelative){ 975 if(type==DEF_DOUBLE){ 976 // TODO: 実装 977 } 978 else if(type==DEF_SINGLE){ 979 // TODO: 実装 980 } 981 else if(type==DEF_INT64||type==DEF_QWORD){ 982 // TODO: 実装 983 984 //pop eax 985 op_pop(REG_EAX); 986 987 //cmp eax,0 988 op_cmp_value(GetTypeSize(type,-1),REG_EAX,0); 989 990 //setne al 991 op_setne( REG_EAX ); 992 993 //pop ecx 994 op_pop(REG_ECX); 995 996 //cmp ecx,0 997 op_cmp_value(GetTypeSize(type,-1),REG_ECX,0); 998 999 //setne cl 1000 op_setne( REG_ECX ); 1001 1002 //or al,cl 1003 op_or_RR( sizeof( _int8 ), REG_EAX, REG_ECX ); 1004 } 1005 else{ 1006 if(!IsWholeNumberType(type)){ 1007 //不正な型の場合 1008 SetError(9,NULL,cp); 1009 return; 1010 } 1011 1012 //pop eax 1013 op_pop(REG_EAX); 1014 } 1015 1016 //cmp eax,0 1017 op_cmp_value(GetTypeSize(type,-1),REG_EAX,0); 1018 1019 //setne al 1020 op_setne( REG_EAX ); 1021 1022 //push eax 1023 op_push(REG_EAX); 1024 1025 Set8Variable(DEF_BYTE,pRelative->dwKind,pRelative->offset,pRelative->bOffsetOffset); 1026 } 1309 */
Note:
See TracChangeset
for help on using the changeset viewer.