Add a helper method with an explicit name instead of hand rolling a match 3x
This commit is contained in:
parent
7839cb963f
commit
c3aec3056e
2 changed files with 9 additions and 3 deletions
|
@ -286,7 +286,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
|
||||||
|
|
||||||
let newval = match (r_t_in, r_t_out) {
|
let newval = match (r_t_in, r_t_out) {
|
||||||
(CastTy::Int(i), CastTy::Int(_)) => {
|
(CastTy::Int(i), CastTy::Int(_)) => {
|
||||||
bx.intcast(llval, ll_t_out, matches!(i, IntTy::I))
|
bx.intcast(llval, ll_t_out, i.is_signed())
|
||||||
}
|
}
|
||||||
(CastTy::Float, CastTy::Float) => {
|
(CastTy::Float, CastTy::Float) => {
|
||||||
let srcsz = bx.cx().float_width(ll_t_in);
|
let srcsz = bx.cx().float_width(ll_t_in);
|
||||||
|
@ -300,7 +300,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
(CastTy::Int(i), CastTy::Float) => {
|
(CastTy::Int(i), CastTy::Float) => {
|
||||||
if matches!(i, IntTy::I) {
|
if i.is_signed() {
|
||||||
bx.sitofp(llval, ll_t_out)
|
bx.sitofp(llval, ll_t_out)
|
||||||
} else {
|
} else {
|
||||||
bx.uitofp(llval, ll_t_out)
|
bx.uitofp(llval, ll_t_out)
|
||||||
|
@ -311,7 +311,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
|
||||||
}
|
}
|
||||||
(CastTy::Int(i), CastTy::Ptr(_)) => {
|
(CastTy::Int(i), CastTy::Ptr(_)) => {
|
||||||
let usize_llval =
|
let usize_llval =
|
||||||
bx.intcast(llval, bx.cx().type_isize(), matches!(i, IntTy::I));
|
bx.intcast(llval, bx.cx().type_isize(), i.is_signed());
|
||||||
bx.inttoptr(usize_llval, ll_t_out)
|
bx.inttoptr(usize_llval, ll_t_out)
|
||||||
}
|
}
|
||||||
(CastTy::Float, CastTy::Int(IntTy::I)) => {
|
(CastTy::Float, CastTy::Int(IntTy::I)) => {
|
||||||
|
|
|
@ -15,6 +15,12 @@ pub enum IntTy {
|
||||||
Char,
|
Char,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl IntTy {
|
||||||
|
pub fn is_signed(self) -> bool {
|
||||||
|
matches!(self, Self::I)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Valid types for the result of a non-coercion cast
|
// Valid types for the result of a non-coercion cast
|
||||||
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
|
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
|
||||||
pub enum CastTy<'tcx> {
|
pub enum CastTy<'tcx> {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue