Skip to content

Option to generate a dot file representing the smir-json #34

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 17 commits into from
Jan 30, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
43 changes: 25 additions & 18 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
dot-writer = "0.1.4"
tracing = "0.1"
# serde = { version = "=1.0.202", features = ["derive"] }
# serde_cbor = "0.11"
Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ To generate stable MIR output without building a binary, you can invoke the tool
./run.sh -Z no-codegen <crate_root>
```

There is experimental support for rendering the Stable-MIR items and their basic blocks as a
call graph in graphviz' dot format.

To produce a dot file `*.smir.dot` (instead of `*.smir.json`), one can invoke the driver with
_first_ argument `--dot`. When using `--json` as the first argument, the `*.smir.json` file
will be written. Any other strings given as first argument will be passed to the compiler
(like all subsequent arguments).

There are a few environment variables that can be set to control the tools output:

1. `LINK_ITEMS` - add entries to the link-time `functions` map for each monomorphic item in the crate;
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#![feature(rustc_private)]
pub mod driver;
pub mod mk_graph;
pub mod printer;
pub use driver::stable_mir_driver;
pub use printer::*;
19 changes: 17 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,23 @@ pub mod driver;
pub mod printer;
use driver::stable_mir_driver;
use printer::emit_smir;
use smir_pretty::mk_graph::emit_dotfile;

fn main() {
let args: Vec<_> = env::args().collect();
stable_mir_driver(&args, emit_smir)
let mut args: Vec<String> = env::args().collect();

match args.get(1) {
None =>
stable_mir_driver(&args, emit_smir), // backward compatibility
Some(arg) if arg == "--json" => {
args.remove(1);
stable_mir_driver(&args, emit_smir)
}
Some(arg) if arg == "--dot" => {
args.remove(1);
stable_mir_driver(&args, emit_dotfile)
}
Some(_other) =>
stable_mir_driver(&args, emit_smir), // backward compatibility
}
}
Loading