Simplify some handling of target_pointer_width
This commit is contained in:
parent
2bc71971e5
commit
3cc4450a8a
2 changed files with 6 additions and 35 deletions
|
@ -1778,14 +1778,7 @@ unsupported {} from `{}` with element `{}` of size `{}` to `{}`"#,
|
||||||
fn int_type_width_signed(ty: Ty, cx: &CodegenCx) -> Option<(u64, bool)> {
|
fn int_type_width_signed(ty: Ty, cx: &CodegenCx) -> Option<(u64, bool)> {
|
||||||
match ty.sty {
|
match ty.sty {
|
||||||
ty::TyInt(t) => Some((match t {
|
ty::TyInt(t) => Some((match t {
|
||||||
ast::IntTy::Isize => {
|
ast::IntTy::Isize => cx.tcx.sess.target.isize_ty.bit_width().unwrap() as u64,
|
||||||
match &cx.tcx.sess.target.target.target_pointer_width[..] {
|
|
||||||
"16" => 16,
|
|
||||||
"32" => 32,
|
|
||||||
"64" => 64,
|
|
||||||
tws => bug!("Unsupported target word size for isize: {}", tws),
|
|
||||||
}
|
|
||||||
},
|
|
||||||
ast::IntTy::I8 => 8,
|
ast::IntTy::I8 => 8,
|
||||||
ast::IntTy::I16 => 16,
|
ast::IntTy::I16 => 16,
|
||||||
ast::IntTy::I32 => 32,
|
ast::IntTy::I32 => 32,
|
||||||
|
@ -1793,14 +1786,7 @@ fn int_type_width_signed(ty: Ty, cx: &CodegenCx) -> Option<(u64, bool)> {
|
||||||
ast::IntTy::I128 => 128,
|
ast::IntTy::I128 => 128,
|
||||||
}, true)),
|
}, true)),
|
||||||
ty::TyUint(t) => Some((match t {
|
ty::TyUint(t) => Some((match t {
|
||||||
ast::UintTy::Usize => {
|
ast::UintTy::Usize => cx.tcx.sess.target.usize_ty.bit_width().unwrap() as u64,
|
||||||
match &cx.tcx.sess.target.target.target_pointer_width[..] {
|
|
||||||
"16" => 16,
|
|
||||||
"32" => 32,
|
|
||||||
"64" => 64,
|
|
||||||
tws => bug!("Unsupported target word size for usize: {}", tws),
|
|
||||||
}
|
|
||||||
},
|
|
||||||
ast::UintTy::U8 => 8,
|
ast::UintTy::U8 => 8,
|
||||||
ast::UintTy::U16 => 16,
|
ast::UintTy::U16 => 16,
|
||||||
ast::UintTy::U32 => 32,
|
ast::UintTy::U32 => 32,
|
||||||
|
@ -1813,14 +1799,9 @@ fn int_type_width_signed(ty: Ty, cx: &CodegenCx) -> Option<(u64, bool)> {
|
||||||
|
|
||||||
// Returns the width of a float TypeVariant
|
// Returns the width of a float TypeVariant
|
||||||
// Returns None if the type is not a float
|
// Returns None if the type is not a float
|
||||||
fn float_type_width<'tcx>(sty: &ty::TypeVariants<'tcx>)
|
fn float_type_width<'tcx>(sty: &ty::TypeVariants<'tcx>) -> Option<u64> {
|
||||||
-> Option<u64> {
|
|
||||||
use rustc::ty::TyFloat;
|
|
||||||
match *sty {
|
match *sty {
|
||||||
TyFloat(t) => Some(match t {
|
ty::TyFloat(t) => Some(t.bit_width() as u64),
|
||||||
ast::FloatTy::F32 => 32,
|
|
||||||
ast::FloatTy::F64 => 64,
|
|
||||||
}),
|
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -733,18 +733,8 @@ fn get_overflow_intrinsic(oop: OverflowOp, bx: &Builder<'_, 'll, '_>, ty: Ty) ->
|
||||||
let tcx = bx.tcx();
|
let tcx = bx.tcx();
|
||||||
|
|
||||||
let new_sty = match ty.sty {
|
let new_sty = match ty.sty {
|
||||||
TyInt(Isize) => match &tcx.sess.target.target.target_pointer_width[..] {
|
TyInt(Isize) => TyInt(tcx.sess.target.isize_ty),
|
||||||
"16" => TyInt(I16),
|
TyUint(Usize) => TyUint(tcx.sess.target.usize_ty),
|
||||||
"32" => TyInt(I32),
|
|
||||||
"64" => TyInt(I64),
|
|
||||||
_ => panic!("unsupported target word size")
|
|
||||||
},
|
|
||||||
TyUint(Usize) => match &tcx.sess.target.target.target_pointer_width[..] {
|
|
||||||
"16" => TyUint(U16),
|
|
||||||
"32" => TyUint(U32),
|
|
||||||
"64" => TyUint(U64),
|
|
||||||
_ => panic!("unsupported target word size")
|
|
||||||
},
|
|
||||||
ref t @ TyUint(_) | ref t @ TyInt(_) => t.clone(),
|
ref t @ TyUint(_) | ref t @ TyInt(_) => t.clone(),
|
||||||
_ => panic!("tried to get overflow intrinsic for op applied to non-int type")
|
_ => panic!("tried to get overflow intrinsic for op applied to non-int type")
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue