Enable users to dump the body of an instance

This commit is contained in:
Celina G. Val 2024-03-20 16:00:00 -07:00
parent ff504a09fe
commit 5f6257429d
2 changed files with 8 additions and 1 deletions

View file

@ -91,7 +91,8 @@ pub fn local_decls(&self) -> impl Iterator<Item = (Local, &LocalDecl)> {
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)
}

View file

@ -4,6 +4,7 @@
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 @@ pub fn is_empty_shim(&self) -> bool {
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 {