From 814d1728aafea39c6f6a1ca76eee88c73fae1800 Mon Sep 17 00:00:00 2001 From: Jakob Stoklund Olesen Date: Thu, 3 Nov 2016 17:55:41 -0700 Subject: [PATCH] Add a Value::unwrap_direct() method. When it is known that a value is the first result of an instruction, it is safe to unwrap the instruction reference. --- lib/cretonne/src/ir/entities.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/lib/cretonne/src/ir/entities.rs b/lib/cretonne/src/ir/entities.rs index 384e4d3ae9..df7d81988f 100644 --- a/lib/cretonne/src/ir/entities.rs +++ b/lib/cretonne/src/ir/entities.rs @@ -164,6 +164,19 @@ impl Value { Table(index) } } + + /// Assuming that this is a direct value, get the referenced instruction. + /// + /// # Panics + /// + /// If this is not a value created with `new_direct()`. + pub fn unwrap_direct(&self) -> Inst { + if let ExpandedValue::Direct(inst) = self.expand() { + inst + } else { + panic!("{} is not a direct value", self) + } + } } /// Display a `Value` reference as "v7" or "v2x".