Implement From traits on ArgAction for convenience.

This commit is contained in:
Jakob Stoklund Olesen
2017-03-07 15:13:55 -08:00
parent 40fc5da3d8
commit 2de210ddb6
2 changed files with 18 additions and 10 deletions

View File

@@ -23,6 +23,18 @@ pub enum ArgAction {
Convert(ValueConversion), Convert(ValueConversion),
} }
impl From<ArgumentLoc> for ArgAction {
fn from(x: ArgumentLoc) -> ArgAction {
ArgAction::Assign(x)
}
}
impl From<ValueConversion> for ArgAction {
fn from(x: ValueConversion) -> ArgAction {
ArgAction::Convert(x)
}
}
/// Legalization action to be applied to a value that is being passed to or from a legalized ABI. /// Legalization action to be applied to a value that is being passed to or from a legalized ABI.
#[derive(Clone, Copy, Debug, PartialEq, Eq)] #[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum ValueConversion { pub enum ValueConversion {

View File

@@ -41,7 +41,7 @@ impl ArgAssigner for Args {
// Check for a legal type. // Check for a legal type.
// RISC-V doesn't have SIMD at all, so break all vectors down. // RISC-V doesn't have SIMD at all, so break all vectors down.
if !ty.is_scalar() { if !ty.is_scalar() {
return ArgAction::Convert(ValueConversion::VectorSplit); return ValueConversion::VectorSplit.into();
} }
// Large integers and booleans are broken down to fit in a register. // Large integers and booleans are broken down to fit in a register.
@@ -49,19 +49,15 @@ impl ArgAssigner for Args {
// Align registers and stack to a multiple of two pointers. // Align registers and stack to a multiple of two pointers.
self.regs = align(self.regs, 2); self.regs = align(self.regs, 2);
self.offset = align(self.offset, 2 * self.pointer_bytes); self.offset = align(self.offset, 2 * self.pointer_bytes);
return ArgAction::Convert(ValueConversion::IntSplit); return ValueConversion::IntSplit.into();
} }
// Small integers are extended to the size of a pointer register. // Small integers are extended to the size of a pointer register.
if ty.is_int() && ty.bits() < self.pointer_bits { if ty.is_int() && ty.bits() < self.pointer_bits {
match arg.extension { match arg.extension {
ArgumentExtension::None => {} ArgumentExtension::None => {}
ArgumentExtension::Uext => { ArgumentExtension::Uext => return ValueConversion::Uext(self.pointer_type).into(),
return ArgAction::Convert(ValueConversion::Uext(self.pointer_type)) ArgumentExtension::Sext => return ValueConversion::Sext(self.pointer_type).into(),
}
ArgumentExtension::Sext => {
return ArgAction::Convert(ValueConversion::Sext(self.pointer_type))
}
} }
} }
@@ -73,12 +69,12 @@ impl ArgAssigner for Args {
GPR.unit(10 + self.regs as usize) GPR.unit(10 + self.regs as usize)
}; };
self.regs += 1; self.regs += 1;
ArgAction::Assign(ArgumentLoc::Reg(reg)) ArgumentLoc::Reg(reg).into()
} else { } else {
// Assign a stack location. // Assign a stack location.
let loc = ArgumentLoc::Stack(self.offset); let loc = ArgumentLoc::Stack(self.offset);
self.offset += self.pointer_bytes; self.offset += self.pointer_bytes;
ArgAction::Assign(loc) loc.into()
} }
} }
} }