Skip to content

Graph improvements #72

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
May 1, 2025
Merged
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 33 additions & 7 deletions src/mk_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,15 @@ extern crate stable_mir;
use rustc_session::config::{OutFileName, OutputType};

extern crate rustc_session;
use stable_mir::mir::{
AggregateKind, BasicBlock, BorrowKind, ConstOperand, Mutability, NonDivergingIntrinsic, NullOp,
Operand, Place, ProjectionElem, Rvalue, Statement, StatementKind, TerminatorKind, UnwindAction,
};
use stable_mir::ty::{IndexedVal, Ty};
use stable_mir::{
mir::{
AggregateKind, BasicBlock, BorrowKind, ConstOperand, Mutability, NonDivergingIntrinsic,
NullOp, Operand, Place, ProjectionElem, Rvalue, Statement, StatementKind, TerminatorKind,
UnwindAction,
},
ty::RigidTy,
};

use crate::{
printer::{collect_smir, FnSymType, SmirJson},
Expand Down Expand Up @@ -87,6 +91,16 @@ impl SmirJson<'_> {
c.set_color(Color::LightGrey);
}

// Set out the type information of the locals
let mut local_node = c.node_auto();
let mut vector: Vec<String> = vec![];
vector.push(String::from("LOCALS"));
for (index, decl) in body.clone().unwrap().local_decls() {
vector.push(format!("{index} = {}", decl.ty));
}
local_node.set_label(vector.join("\\l").to_string().as_str());
drop(local_node);

// Cannot define local functions that capture env. variables. Instead we define _closures_.
let process_block =
|cluster: &mut Scope<'_, '_>, node_id: usize, b: &BasicBlock| {
Expand Down Expand Up @@ -376,7 +390,16 @@ trait GraphLabelString {
impl GraphLabelString for Operand {
fn label(&self) -> String {
match &self {
Operand::Constant(ConstOperand { const_, .. }) => format!("const :: {}", const_.ty()),
Operand::Constant(ConstOperand { const_, .. }) => {
let ty = const_.ty();
match &ty.kind() {
stable_mir::ty::TyKind::RigidTy(RigidTy::Int(_))
| stable_mir::ty::TyKind::RigidTy(RigidTy::Uint(_)) => {
format!("const ?_{}", const_.ty())
}
_ => format!("const {}", const_.ty()),
}
}
Operand::Copy(place) => format!("cp({})", place.label()),
Operand::Move(place) => format!("mv({})", place.label()),
}
Expand All @@ -395,7 +418,7 @@ fn project(local: String, ps: &[ProjectionElem]) -> String {

fn decorate(thing: String, p: &ProjectionElem) -> String {
match p {
ProjectionElem::Deref => format!("*{}", thing),
ProjectionElem::Deref => format!("(*{})", thing),
ProjectionElem::Field(i, _) => format!("{thing}.{i}"),
ProjectionElem::Index(local) => format!("{thing}[_{local}]"),
ProjectionElem::ConstantIndex {
Expand Down Expand Up @@ -437,7 +460,10 @@ impl GraphLabelString for Rvalue {
fn label(&self) -> String {
use Rvalue::*;
match &self {
AddressOf(kind, p) => format!("&{:?} {}", kind, p.label()),
AddressOf(mutability, p) => match mutability {
Mutability::Not => format!("&raw {}", p.label()),
Mutability::Mut => format!("&raw mut {}", p.label()),
},
Aggregate(kind, operands) => {
let os: Vec<String> = operands.iter().map(|op| op.label()).collect();
format!("{} ({})", kind.label(), os.join(", "))
Expand Down