From 19444649e7f5c230a22a1a3142003ab91a8b7d86 Mon Sep 17 00:00:00 2001 From: Ujjwal Sharma Date: Tue, 1 Oct 2019 14:26:35 +0530 Subject: [PATCH] [codegen] add to_static_str method to IntCC Add a method to_static_str to objects of type IntCC which consumes the object to basically do the opposite of IntCC::new. Refs: https://github.com/CraneStation/cranelift/pull/1081#discussion_r329042331 --- cranelift/codegen/shared/src/condcodes.rs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/cranelift/codegen/shared/src/condcodes.rs b/cranelift/codegen/shared/src/condcodes.rs index 1171eef2f6..d151c49466 100644 --- a/cranelift/codegen/shared/src/condcodes.rs +++ b/cranelift/codegen/shared/src/condcodes.rs @@ -95,10 +95,11 @@ impl CondCode for IntCC { } } -impl Display for IntCC { - fn fmt(&self, f: &mut Formatter) -> fmt::Result { +impl IntCC { + /// Get the corresponding string condition code for the IntCC object. + pub fn to_static_str(self) -> &'static str { use self::IntCC::*; - f.write_str(match *self { + match self { Equal => "eq", NotEqual => "ne", SignedGreaterThan => "sgt", @@ -111,7 +112,13 @@ impl Display for IntCC { UnsignedLessThanOrEqual => "ule", Overflow => "of", NotOverflow => "nof", - }) + } + } +} + +impl Display for IntCC { + fn fmt(&self, f: &mut Formatter) -> fmt::Result { + f.write_str(self.to_static_str()) } }