From 0cfea8858a0dae2480e0cf9849f3b7ba995dbe20 Mon Sep 17 00:00:00 2001 From: Jakob Stoklund Olesen Date: Tue, 19 Sep 2017 12:59:07 -0700 Subject: [PATCH] Add uext() and sext() builder methods to ArgumentType. This makes it simpler to construct arguments like: ArgumentType::new(I32).uext() --- lib/cretonne/src/ir/extfunc.rs | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/lib/cretonne/src/ir/extfunc.rs b/lib/cretonne/src/ir/extfunc.rs index 5983182d87..8b8cc9dca0 100644 --- a/lib/cretonne/src/ir/extfunc.rs +++ b/lib/cretonne/src/ir/extfunc.rs @@ -173,6 +173,24 @@ impl ArgumentType { } } + /// Convert `self` to an argument type with the `uext` flag set. + pub fn uext(self) -> ArgumentType { + debug_assert!(self.value_type.is_int(), "uext on {} arg", self.value_type); + ArgumentType { + extension: ArgumentExtension::Uext, + ..self + } + } + + /// Convert `self` to an argument type with the `sext` flag set. + pub fn sext(self) -> ArgumentType { + debug_assert!(self.value_type.is_int(), "sext on {} arg", self.value_type); + ArgumentType { + extension: ArgumentExtension::Sext, + ..self + } + } + /// Return an object that can display `self` with correct register names. pub fn display<'a, R: Into>>(&'a self, regs: R) -> DisplayArgumentType<'a> { DisplayArgumentType(self, regs.into()) @@ -369,10 +387,11 @@ mod tests { #[test] fn argument_type() { - let mut t = ArgumentType::new(I32); + let t = ArgumentType::new(I32); assert_eq!(t.to_string(), "i32"); - t.extension = ArgumentExtension::Uext; + let mut t = t.uext(); assert_eq!(t.to_string(), "i32 uext"); + assert_eq!(t.sext().to_string(), "i32 sext"); t.purpose = ArgumentPurpose::StructReturn; assert_eq!(t.to_string(), "i32 uext sret"); }