Skip to content

Commit 5e04aeb

Browse files
committed
connected to dot file production
1 parent 9ab8101 commit 5e04aeb

2 files changed

Lines changed: 27 additions & 16 deletions

File tree

src/mk_graph/mod.rs

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -145,20 +145,7 @@ fn is_std_rt_lang_start(kind: &MonoItemKind) -> bool {
145145

146146
/// Entry point to write the DOT file
147147
pub fn emit_dotfile(tcx: TyCtxt<'_>) {
148-
let smir = collect_smir(tcx);
149-
150-
if skip_lang_start() {
151-
let ctx = GraphContext::from_smir(&smir);
152-
let excluded = compute_lang_start_exclusions(&smir.items, &ctx);
153-
println!("SKIP_LANG_START: excluding {} items:", excluded.len());
154-
let mut sorted: Vec<_> = excluded.iter().collect();
155-
sorted.sort();
156-
for name in sorted {
157-
println!(" - {}", name);
158-
}
159-
}
160-
161-
let smir_dot = smir.to_dot_file();
148+
let smir_dot = collect_smir(tcx).to_dot_file();
162149

163150
match tcx.output_filenames(()).path(OutputType::Mir) {
164151
OutFileName::Stdout => {

src/mk_graph/output/dot.rs

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,25 @@ use crate::MonoItemKind;
1212

1313
use crate::mk_graph::context::GraphContext;
1414
use crate::mk_graph::util::{block_name, is_unqualified, name_lines, short_name, GraphLabelString};
15+
use crate::mk_graph::{compute_lang_start_exclusions, skip_lang_start};
1516

1617
impl SmirJson<'_> {
1718
/// Convert the MIR to DOT (Graphviz) format
18-
pub fn to_dot_file(self) -> String {
19+
pub fn to_dot_file(mut self) -> String {
1920
let mut bytes = Vec::new();
2021

2122
// Build context BEFORE consuming self
2223
let ctx = GraphContext::from_smir(&self);
2324

25+
// Optionally filter out lang_start items and their unique descendants
26+
let excluded: HashSet<String> = if skip_lang_start() {
27+
let excluded = compute_lang_start_exclusions(&self.items, &ctx);
28+
self.items.retain(|i| !excluded.contains(&i.symbol_name));
29+
excluded
30+
} else {
31+
HashSet::new()
32+
};
33+
2434
{
2535
let mut writer = DotWriter::from(&mut bytes);
2636

@@ -57,7 +67,7 @@ impl SmirJson<'_> {
5767

5868
// first create all nodes for functions not in the items list
5969
for f in ctx.functions.values() {
60-
if !item_names.contains(f) {
70+
if !item_names.contains(f) && !excluded.contains(f) {
6171
graph
6272
.node_named(block_name(f, 0))
6373
.set_label(&name_lines(f))
@@ -245,6 +255,20 @@ impl SmirJson<'_> {
245255

246256
match &b.terminator.kind {
247257
TerminatorKind::Call { func, args, .. } => {
258+
// Skip call edges to excluded nodes
259+
if let Operand::Constant(ConstOperand {
260+
const_, ..
261+
}) = func
262+
{
263+
if ctx
264+
.functions
265+
.get(&const_.ty())
266+
.is_some_and(|c| excluded.contains(c))
267+
{
268+
continue;
269+
}
270+
}
271+
248272
let e = match func {
249273
Operand::Constant(ConstOperand {
250274
const_, ..

0 commit comments

Comments
 (0)