From 71ed95246502875331e97a4be98431b032247d83 Mon Sep 17 00:00:00 2001 From: Scott Olson Date: Thu, 17 Mar 2016 03:36:06 -0600 Subject: [PATCH] Simplify primitive type reprs. --- src/interpreter.rs | 19 +++++++++---------- src/memory.rs | 25 +++++++------------------ 2 files changed, 16 insertions(+), 28 deletions(-) diff --git a/src/interpreter.rs b/src/interpreter.rs index 9c5e505671a..ca0a96a1767 100644 --- a/src/interpreter.rs +++ b/src/interpreter.rs @@ -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()), diff --git a/src/memory.rs b/src/memory.rs index deea5e29dec..612f8e4938e 100644 --- a/src/memory.rs +++ b/src/memory.rs @@ -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::() { - 4 => Repr::I32, - 8 => Repr::I64, - _ => unimplemented!(), - } + Repr::Primitive { size: mem::size_of::() } } // 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::() { - 4 => Repr::U32, - 8 => Repr::U64, - _ => unimplemented!(), - } + Repr::Primitive { size: mem::size_of::() } } 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,