Rvalue::Len
This commit is contained in:
parent
12282a8ebc
commit
fa4a37759b
2 changed files with 15 additions and 10 deletions
10
src/base.rs
10
src/base.rs
|
|
@ -474,7 +474,15 @@ fn trans_stmt<'a, 'tcx: 'a>(
|
|||
to.write_cvalue(fx, operand);
|
||||
}
|
||||
}
|
||||
Rvalue::Len(lval) => unimpl!("rval len {:?}", lval),
|
||||
Rvalue::Len(place) => {
|
||||
let place = trans_place(fx, place);
|
||||
let size = match place {
|
||||
CPlace::Addr(_, size, _) => size.unwrap(),
|
||||
CPlace::Var(_, _) => unreachable!(),
|
||||
};
|
||||
let usize_layout = fx.layout_of(fx.tcx.types.usize);
|
||||
lval.write_cvalue(fx, CValue::ByVal(size, usize_layout));
|
||||
}
|
||||
Rvalue::NullaryOp(NullOp::Box, ty) => unimplemented!("rval box {:?}", ty),
|
||||
Rvalue::NullaryOp(NullOp::SizeOf, ty) => {
|
||||
assert!(
|
||||
|
|
|
|||
|
|
@ -433,23 +433,20 @@ impl<'a, 'tcx: 'a> CPlace<'tcx> {
|
|||
fx: &mut FunctionCx<'a, 'tcx, impl Backend>,
|
||||
index: Value,
|
||||
) -> CPlace<'tcx> {
|
||||
let addr = self.expect_addr();
|
||||
let layout = self.layout();
|
||||
if layout.is_unsized() {
|
||||
unimpl!("unsized place_field");
|
||||
}
|
||||
|
||||
match layout.ty.sty {
|
||||
match self.layout().ty.sty {
|
||||
ty::Array(elem_ty, _) => {
|
||||
let elem_layout = fx.layout_of(elem_ty);
|
||||
|
||||
let offset = fx
|
||||
.bcx
|
||||
.ins()
|
||||
.imul_imm(index, elem_layout.size.bytes() as i64);
|
||||
|
||||
let addr = self.expect_addr();
|
||||
CPlace::Addr(fx.bcx.ins().iadd(addr, offset), None, elem_layout)
|
||||
}
|
||||
ty::Slice(_elem_ty) => unimplemented!("place_index(TySlice)"),
|
||||
_ => bug!("place_index({:?})", layout.ty),
|
||||
ty::Slice(_elem_ty) => unimpl!("place_index(TySlice)"),
|
||||
_ => bug!("place_index({:?})", self.layout().ty),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue