Skip to content

Commit 5f62574

Browse files
committed
Enable users to dump the body of an instance
1 parent ff504a0 commit 5f62574

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

compiler/stable_mir/src/mir/body.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@ impl Body {
9191
self.locals.iter().enumerate()
9292
}
9393

94-
pub(crate) fn dump<W: io::Write>(&self, w: &mut W, fn_name: &str) -> io::Result<()> {
94+
/// Emit the body using the provided name for the signature.
95+
pub fn dump<W: io::Write>(&self, w: &mut W, fn_name: &str) -> io::Result<()> {
9596
function_body(w, self, fn_name)
9697
}
9798

compiler/stable_mir/src/mir/mono.rs

+6
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use crate::mir::Body;
44
use crate::ty::{Allocation, ClosureDef, ClosureKind, FnDef, GenericArgs, IndexedVal, Ty};
55
use crate::{with, CrateItem, DefId, Error, ItemKind, Opaque, Symbol};
66
use std::fmt::{Debug, Formatter};
7+
use std::io;
78

89
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
910
pub enum MonoItem {
@@ -157,6 +158,11 @@ impl Instance {
157158
pub fn try_const_eval(&self, const_ty: Ty) -> Result<Allocation, Error> {
158159
with(|cx| cx.eval_instance(self.def, const_ty))
159160
}
161+
162+
/// Emit the body of this instance if it has one.
163+
pub fn emit_mir<W: io::Write>(&self, w: &mut W) -> io::Result<()> {
164+
if let Some(body) = self.body() { body.dump(w, &self.name()) } else { Ok(()) }
165+
}
160166
}
161167

162168
impl Debug for Instance {

0 commit comments

Comments
 (0)