Skip to content

Commit

Permalink
Merge pull request rust-lang#98 from oli-obk/rustup
Browse files Browse the repository at this point in the history
rustup (i128)
  • Loading branch information
solson authored Jan 12, 2017
2 parents d6e35fe + 3a658e0 commit 57b9838
Show file tree
Hide file tree
Showing 14 changed files with 196 additions and 151 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
tex/*/out
*.dot
*.mir
*.rs.bk
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ test = false
test = false

[dependencies]
byteorder = "0.4.2"
#byteorder = "0.4.2"
byteorder = { git = "https://github.com/quininer/byteorder.git", branch = "i128", features = ["i128"]}
env_logger = "0.3.3"
log = "0.3.6"
log_settings = "0.1.1"
Expand Down
8 changes: 4 additions & 4 deletions src/bin/miri.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![feature(rustc_private)]
#![feature(rustc_private, i128_type)]

extern crate getopts;
extern crate miri;
Expand Down Expand Up @@ -51,7 +51,7 @@ fn resource_limits_from_attributes(state: &CompileState) -> miri::ResourceLimits
let mut limits = miri::ResourceLimits::default();
let krate = state.hir_crate.as_ref().unwrap();
let err_msg = "miri attributes need to be in the form `miri(key = value)`";
let extract_int = |lit: &syntax::ast::Lit| -> u64 {
let extract_int = |lit: &syntax::ast::Lit| -> u128 {
match lit.node {
syntax::ast::LitKind::Int(i, _) => i,
_ => state.session.span_fatal(lit.span, "expected an integer literal"),
Expand All @@ -64,8 +64,8 @@ fn resource_limits_from_attributes(state: &CompileState) -> miri::ResourceLimits
if let NestedMetaItemKind::MetaItem(ref inner) = item.node {
if let MetaItemKind::NameValue(ref value) = inner.node {
match &inner.name().as_str()[..] {
"memory_size" => limits.memory_size = extract_int(value),
"step_limit" => limits.step_limit = extract_int(value),
"memory_size" => limits.memory_size = extract_int(value) as u64,
"step_limit" => limits.step_limit = extract_int(value) as u64,
"stack_limit" => limits.stack_limit = extract_int(value) as usize,
_ => state.session.span_err(item.span, "unknown miri attribute"),
}
Expand Down
40 changes: 21 additions & 19 deletions src/cast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,34 +20,36 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
F32 => self.cast_float(val.to_f32()? as f64, dest_ty),
F64 => self.cast_float(val.to_f64()?, dest_ty),

I8 | I16 | I32 | I64 => self.cast_signed_int(val.to_i64()?, dest_ty),
I8 | I16 | I32 | I64 | I128 => self.cast_signed_int(val.to_i128()?, dest_ty),

Bool | Char | U8 | U16 | U32 | U64 => self.cast_int(val.to_u64()?, dest_ty, false),
Bool | Char | U8 | U16 | U32 | U64 | U128 => self.cast_int(val.to_u128()?, dest_ty, false),

FnPtr | Ptr => self.cast_ptr(val.to_ptr()?, dest_ty),
}
}

fn cast_signed_int(&self, val: i64, ty: ty::Ty<'tcx>) -> EvalResult<'tcx, PrimVal> {
self.cast_int(val as u64, ty, val < 0)
fn cast_signed_int(&self, val: i128, ty: ty::Ty<'tcx>) -> EvalResult<'tcx, PrimVal> {
self.cast_int(val as u128, ty, val < 0)
}

fn cast_int(&self, v: u64, ty: ty::Ty<'tcx>, negative: bool) -> EvalResult<'tcx, PrimVal> {
fn cast_int(&self, v: u128, ty: ty::Ty<'tcx>, negative: bool) -> EvalResult<'tcx, PrimVal> {
use rustc::ty::TypeVariants::*;
match ty.sty {
TyBool if v == 0 => Ok(PrimVal::from_bool(false)),
TyBool if v == 1 => Ok(PrimVal::from_bool(true)),
TyBool => Err(EvalError::InvalidBool),

TyInt(IntTy::I8) => Ok(PrimVal::Bytes(v as i64 as i8 as u64)),
TyInt(IntTy::I16) => Ok(PrimVal::Bytes(v as i64 as i16 as u64)),
TyInt(IntTy::I32) => Ok(PrimVal::Bytes(v as i64 as i32 as u64)),
TyInt(IntTy::I64) => Ok(PrimVal::Bytes(v as i64 as i64 as u64)),
TyInt(IntTy::I8) => Ok(PrimVal::Bytes(v as i128 as i8 as u128)),
TyInt(IntTy::I16) => Ok(PrimVal::Bytes(v as i128 as i16 as u128)),
TyInt(IntTy::I32) => Ok(PrimVal::Bytes(v as i128 as i32 as u128)),
TyInt(IntTy::I64) => Ok(PrimVal::Bytes(v as i128 as i64 as u128)),
TyInt(IntTy::I128) => Ok(PrimVal::Bytes(v as u128)),

TyUint(UintTy::U8) => Ok(PrimVal::Bytes(v as u8 as u64)),
TyUint(UintTy::U16) => Ok(PrimVal::Bytes(v as u16 as u64)),
TyUint(UintTy::U32) => Ok(PrimVal::Bytes(v as u32 as u64)),
TyUint(UintTy::U64) => Ok(PrimVal::Bytes(v)),
TyUint(UintTy::U8) => Ok(PrimVal::Bytes(v as u8 as u128)),
TyUint(UintTy::U16) => Ok(PrimVal::Bytes(v as u16 as u128)),
TyUint(UintTy::U32) => Ok(PrimVal::Bytes(v as u32 as u128)),
TyUint(UintTy::U64) => Ok(PrimVal::Bytes(v as u64 as u128)),
TyUint(UintTy::U128) => Ok(PrimVal::Bytes(v)),

TyInt(IntTy::Is) => {
let int_ty = self.tcx.sess.target.int_type;
Expand All @@ -61,15 +63,15 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
self.cast_int(v, ty, negative)
}

TyFloat(FloatTy::F64) if negative => Ok(PrimVal::from_f64(v as i64 as f64)),
TyFloat(FloatTy::F64) if negative => Ok(PrimVal::from_f64(v as i128 as f64)),
TyFloat(FloatTy::F64) => Ok(PrimVal::from_f64(v as f64)),
TyFloat(FloatTy::F32) if negative => Ok(PrimVal::from_f32(v as i64 as f32)),
TyFloat(FloatTy::F32) if negative => Ok(PrimVal::from_f32(v as i128 as f32)),
TyFloat(FloatTy::F32) => Ok(PrimVal::from_f32(v as f32)),

TyChar if v as u8 as u64 == v => Ok(PrimVal::Bytes(v)),
TyChar if v as u8 as u128 == v => Ok(PrimVal::Bytes(v)),
TyChar => Err(EvalError::InvalidChar(v)),

TyRawPtr(_) => Ok(PrimVal::Ptr(Pointer::from_int(v))),
TyRawPtr(_) => Ok(PrimVal::Ptr(Pointer::from_int(v as u64))),

_ => Err(EvalError::Unimplemented(format!("int to {:?} cast", ty))),
}
Expand All @@ -80,9 +82,9 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
match ty.sty {
// Casting negative floats to unsigned integers yields zero.
TyUint(_) if val < 0.0 => self.cast_int(0, ty, false),
TyInt(_) if val < 0.0 => self.cast_int(val as i64 as u64, ty, true),
TyInt(_) if val < 0.0 => self.cast_int(val as i128 as u128, ty, true),

TyInt(_) | ty::TyUint(_) => self.cast_int(val as u64, ty, false),
TyInt(_) | ty::TyUint(_) => self.cast_int(val as u128, ty, false),

TyFloat(FloatTy::F64) => Ok(PrimVal::from_f64(val)),
TyFloat(FloatTy::F32) => Ok(PrimVal::from_f32(val as f32)),
Expand Down
2 changes: 1 addition & 1 deletion src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub enum EvalError<'tcx> {
ExecuteMemory,
ArrayIndexOutOfBounds(Span, u64, u64),
Math(Span, ConstMathErr),
InvalidChar(u64),
InvalidChar(u128),
OutOfMemory {
allocation_size: u64,
memory_size: u64,
Expand Down
33 changes: 19 additions & 14 deletions src/eval_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,15 +169,15 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
let ptr = self.memory.allocate(s.len() as u64, 1)?;
self.memory.write_bytes(ptr, s.as_bytes())?;
self.memory.freeze(ptr.alloc_id)?;
Ok(Value::ByValPair(PrimVal::Ptr(ptr), PrimVal::from_u64(s.len() as u64)))
Ok(Value::ByValPair(PrimVal::Ptr(ptr), PrimVal::from_u128(s.len() as u128)))
}

pub(super) fn const_to_value(&mut self, const_val: &ConstVal) -> EvalResult<'tcx, Value> {
use rustc::middle::const_val::ConstVal::*;
use rustc_const_math::ConstFloat;

let primval = match *const_val {
Integral(const_int) => PrimVal::Bytes(const_int.to_u64_unchecked()),
Integral(const_int) => PrimVal::Bytes(const_int.to_u128_unchecked()),

Float(ConstFloat::F32(f)) => PrimVal::from_f32(f),
Float(ConstFloat::F64(f)) => PrimVal::from_f64(f),
Expand Down Expand Up @@ -429,7 +429,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {

General { discr, ref variants, .. } => {
if let mir::AggregateKind::Adt(adt_def, variant, _, _) = *kind {
let discr_val = adt_def.variants[variant].disr_val.to_u64_unchecked();
let discr_val = adt_def.variants[variant].disr_val.to_u128_unchecked();
let discr_size = discr.size().bytes();
let discr_offset = variants[variant].offsets[0].bytes();

Expand Down Expand Up @@ -497,7 +497,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
CEnum { .. } => {
assert_eq!(operands.len(), 0);
if let mir::AggregateKind::Adt(adt_def, variant, _, _) = *kind {
let n = adt_def.variants[variant].disr_val.to_u64_unchecked();
let n = adt_def.variants[variant].disr_val.to_u128_unchecked();
self.write_primval(dest, PrimVal::Bytes(n), dest_ty)?;
} else {
bug!("tried to assign {:?} to Layout::CEnum", kind);
Expand Down Expand Up @@ -556,7 +556,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
let src = self.eval_lvalue(lvalue)?;
let ty = self.lvalue_ty(lvalue);
let (_, len) = src.elem_ty_and_len(ty);
self.write_primval(dest, PrimVal::from_u64(len), dest_ty)?;
self.write_primval(dest, PrimVal::from_u128(len as u128), dest_ty)?;
}

Ref(_, _, ref lvalue) => {
Expand All @@ -566,7 +566,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {

let val = match extra {
LvalueExtra::None => Value::ByVal(ptr),
LvalueExtra::Length(len) => Value::ByValPair(ptr, PrimVal::from_u64(len)),
LvalueExtra::Length(len) => Value::ByValPair(ptr, PrimVal::from_u128(len as u128)),
LvalueExtra::Vtable(vtable) => Value::ByValPair(ptr, PrimVal::Ptr(vtable)),
LvalueExtra::DowncastVariant(..) =>
bug!("attempted to take a reference to an enum downcast lvalue"),
Expand Down Expand Up @@ -1028,6 +1028,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
I16 => 2,
I32 => 4,
I64 => 8,
I128 => 16,
Is => self.memory.pointer_size(),
};
PrimValKind::from_int_size(size)
Expand All @@ -1040,6 +1041,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
U16 => 2,
U32 => 4,
U64 => 8,
U128 => 16,
Us => self.memory.pointer_size(),
};
PrimValKind::from_uint_size(size)
Expand Down Expand Up @@ -1092,7 +1094,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
ty::TyBool if val.to_bytes()? > 1 => Err(EvalError::InvalidBool),

ty::TyChar if ::std::char::from_u32(val.to_bytes()? as u32).is_none()
=> Err(EvalError::InvalidChar(val.to_bytes()? as u32 as u64)),
=> Err(EvalError::InvalidChar(val.to_bytes()? as u32 as u128)),

_ => Ok(()),
}
Expand All @@ -1115,7 +1117,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
let c = self.memory.read_uint(ptr, 4)? as u32;
match ::std::char::from_u32(c) {
Some(ch) => PrimVal::from_char(ch),
None => return Err(EvalError::InvalidChar(c as u64)),
None => return Err(EvalError::InvalidChar(c as u128)),
}
}

Expand All @@ -1126,9 +1128,10 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
I16 => 2,
I32 => 4,
I64 => 8,
I128 => 16,
Is => self.memory.pointer_size(),
};
PrimVal::from_i64(self.memory.read_int(ptr, size)?)
PrimVal::from_i128(self.memory.read_int(ptr, size)?)
}

ty::TyUint(uint_ty) => {
Expand All @@ -1138,9 +1141,10 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
U16 => 2,
U32 => 4,
U64 => 8,
U128 => 16,
Us => self.memory.pointer_size(),
};
PrimVal::from_u64(self.memory.read_uint(ptr, size)?)
PrimVal::from_u128(self.memory.read_uint(ptr, size)?)
}

ty::TyFloat(FloatTy::F32) => PrimVal::from_f32(self.memory.read_f32(ptr)?),
Expand All @@ -1159,7 +1163,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
let extra = match self.tcx.struct_tail(ty).sty {
ty::TyDynamic(..) => PrimVal::Ptr(self.memory.read_ptr(extra)?),
ty::TySlice(..) |
ty::TyStr => PrimVal::from_u64(self.memory.read_usize(extra)?),
ty::TyStr => PrimVal::from_u128(self.memory.read_usize(extra)? as u128),
_ => bug!("unsized primval ptr read from {:?}", ty),
};
return Ok(Some(Value::ByValPair(PrimVal::Ptr(p), extra)));
Expand All @@ -1171,9 +1175,9 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
if let CEnum { discr, signed, .. } = *self.type_layout(ty)? {
let size = discr.size().bytes();
if signed {
PrimVal::from_i64(self.memory.read_int(ptr, size)?)
PrimVal::from_i128(self.memory.read_int(ptr, size)?)
} else {
PrimVal::from_u64(self.memory.read_uint(ptr, size)?)
PrimVal::from_u128(self.memory.read_uint(ptr, size)?)
}
} else {
return Ok(None);
Expand Down Expand Up @@ -1220,7 +1224,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
match (&src_pointee_ty.sty, &dest_pointee_ty.sty) {
(&ty::TyArray(_, length), &ty::TySlice(_)) => {
let ptr = src.read_ptr(&self.memory)?;
let len = PrimVal::from_u64(length as u64);
let len = PrimVal::from_u128(length as u128);
let ptr = PrimVal::Ptr(ptr);
self.write_value(Value::ByValPair(ptr, len), dest, dest_ty)?;
}
Expand Down Expand Up @@ -1454,6 +1458,7 @@ impl IntegerExt for layout::Integer {
I16 => Size::from_bits(16),
I32 => Size::from_bits(32),
I64 => Size::from_bits(64),
I128 => Size::from_bits(128),
}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
collections_bound,
pub_restricted,
rustc_private,
i128_type,
)]

// From rustc.
Expand Down
Loading

0 comments on commit 57b9838

Please sign in to comment.