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.
This commit is contained in:
Jakob Stoklund Olesen
2016-11-03 17:55:41 -07:00
parent 0543bb049c
commit 814d1728aa

View File

@@ -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".