diff options
| -rw-r--r-- | compiler/stable_mir/src/mir/body.rs | 3 | ||||
| -rw-r--r-- | compiler/stable_mir/src/mir/mono.rs | 6 |
2 files changed, 8 insertions, 1 deletions
diff --git a/compiler/stable_mir/src/mir/body.rs b/compiler/stable_mir/src/mir/body.rs index 4f67a76e24c..e4a012d8c47 100644 --- a/compiler/stable_mir/src/mir/body.rs +++ b/compiler/stable_mir/src/mir/body.rs @@ -91,7 +91,8 @@ impl Body { self.locals.iter().enumerate() } - pub(crate) fn dump<W: io::Write>(&self, w: &mut W, fn_name: &str) -> io::Result<()> { + /// Emit the body using the provided name for the signature. + pub fn dump<W: io::Write>(&self, w: &mut W, fn_name: &str) -> io::Result<()> { function_body(w, self, fn_name) } diff --git a/compiler/stable_mir/src/mir/mono.rs b/compiler/stable_mir/src/mir/mono.rs index 38e5776c48c..aafa89c03e0 100644 --- a/compiler/stable_mir/src/mir/mono.rs +++ b/compiler/stable_mir/src/mir/mono.rs @@ -4,6 +4,7 @@ use crate::mir::Body; use crate::ty::{Allocation, ClosureDef, ClosureKind, FnDef, GenericArgs, IndexedVal, Ty}; use crate::{with, CrateItem, DefId, Error, ItemKind, Opaque, Symbol}; use std::fmt::{Debug, Formatter}; +use std::io; #[derive(Clone, Debug, PartialEq, Eq, Hash)] pub enum MonoItem { @@ -157,6 +158,11 @@ impl Instance { pub fn try_const_eval(&self, const_ty: Ty) -> Result<Allocation, Error> { with(|cx| cx.eval_instance(self.def, const_ty)) } + + /// Emit the body of this instance if it has one. + pub fn emit_mir<W: io::Write>(&self, w: &mut W) -> io::Result<()> { + if let Some(body) = self.body() { body.dump(w, &self.name()) } else { Ok(()) } + } } impl Debug for Instance { |
