Skip to content

Commit

Permalink
Enable users to dump the body of an instance
Browse files Browse the repository at this point in the history
  • Loading branch information
celinval committed Mar 20, 2024
1 parent ff504a0 commit 5f62574
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
3 changes: 2 additions & 1 deletion compiler/stable_mir/src/mir/body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
6 changes: 6 additions & 0 deletions compiler/stable_mir/src/mir/mono.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 5f62574

Please sign in to comment.