Simplify primitive type reprs.
This commit is contained in:
parent
c55d4b07fd
commit
71ed952465
2 changed files with 16 additions and 28 deletions
|
@ -571,19 +571,18 @@ impl<'a, 'tcx: 'a> Interpreter<'a, 'tcx> {
|
|||
fn ty_to_repr(&self, ty: ty::Ty<'tcx>) -> Repr {
|
||||
use syntax::ast::{IntTy, UintTy};
|
||||
match ty.subst(self.tcx, self.current_substs()).sty {
|
||||
ty::TyBool => Repr::Bool,
|
||||
|
||||
ty::TyBool => Repr::Primitive { size: 1 },
|
||||
ty::TyInt(IntTy::Is) => Repr::isize(),
|
||||
ty::TyInt(IntTy::I8) => Repr::I8,
|
||||
ty::TyInt(IntTy::I16) => Repr::I16,
|
||||
ty::TyInt(IntTy::I32) => Repr::I32,
|
||||
ty::TyInt(IntTy::I64) => Repr::I64,
|
||||
ty::TyInt(IntTy::I8) => Repr::Primitive { size: 1 },
|
||||
ty::TyInt(IntTy::I16) => Repr::Primitive { size: 2 },
|
||||
ty::TyInt(IntTy::I32) => Repr::Primitive { size: 4 },
|
||||
ty::TyInt(IntTy::I64) => Repr::Primitive { size: 8 },
|
||||
|
||||
ty::TyUint(UintTy::Us) => Repr::usize(),
|
||||
ty::TyUint(UintTy::U8) => Repr::U8,
|
||||
ty::TyUint(UintTy::U16) => Repr::U16,
|
||||
ty::TyUint(UintTy::U32) => Repr::U32,
|
||||
ty::TyUint(UintTy::U64) => Repr::U64,
|
||||
ty::TyUint(UintTy::U8) => Repr::Primitive { size: 1 },
|
||||
ty::TyUint(UintTy::U16) => Repr::Primitive { size: 2 },
|
||||
ty::TyUint(UintTy::U32) => Repr::Primitive { size: 4 },
|
||||
ty::TyUint(UintTy::U64) => Repr::Primitive { size: 8 },
|
||||
|
||||
ty::TyTuple(ref fields) => self.make_product_repr(fields.iter().cloned()),
|
||||
|
||||
|
|
|
@ -40,9 +40,10 @@ pub struct FieldRepr {
|
|||
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub enum Repr {
|
||||
Bool,
|
||||
I8, I16, I32, I64,
|
||||
U8, U16, U32, U64,
|
||||
/// Representation for a primitive type such as a boolean, integer, or character.
|
||||
Primitive {
|
||||
size: usize
|
||||
},
|
||||
|
||||
Pointer,
|
||||
FatPointer,
|
||||
|
@ -361,29 +362,17 @@ impl Pointer {
|
|||
impl Repr {
|
||||
// TODO(tsion): Choice is based on host machine's type size. Should this be how miri works?
|
||||
pub fn isize() -> Self {
|
||||
match mem::size_of::<isize>() {
|
||||
4 => Repr::I32,
|
||||
8 => Repr::I64,
|
||||
_ => unimplemented!(),
|
||||
}
|
||||
Repr::Primitive { size: mem::size_of::<isize>() }
|
||||
}
|
||||
|
||||
// TODO(tsion): Choice is based on host machine's type size. Should this be how miri works?
|
||||
pub fn usize() -> Self {
|
||||
match mem::size_of::<isize>() {
|
||||
4 => Repr::U32,
|
||||
8 => Repr::U64,
|
||||
_ => unimplemented!(),
|
||||
}
|
||||
Repr::Primitive { size: mem::size_of::<usize>() }
|
||||
}
|
||||
|
||||
pub fn size(&self) -> usize {
|
||||
match *self {
|
||||
Repr::Bool => 1,
|
||||
Repr::I8 | Repr::U8 => 1,
|
||||
Repr::I16 | Repr::U16 => 2,
|
||||
Repr::I32 | Repr::U32 => 4,
|
||||
Repr::I64 | Repr::U64 => 8,
|
||||
Repr::Primitive { size } => size,
|
||||
Repr::Product { size, .. } => size,
|
||||
Repr::Sum { discr_size, max_variant_size, .. } => discr_size + max_variant_size,
|
||||
Repr::Array { elem_size, length } => elem_size * length,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue