Skip to content
Snippets Groups Projects
Commit ba77289a authored by Russel Arbore's avatar Russel Arbore
Browse files

Binary tool to view dot graphs for HIR modules

parent 2c938323
No related branches found
No related tags found
No related merge requests found
/target /target
*.dot
...@@ -2,12 +2,112 @@ ...@@ -2,12 +2,112 @@
# It is not intended for manual editing. # It is not intended for manual editing.
version = 3 version = 3
[[package]]
name = "anstream"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b1f58811cfac344940f1a400b6e6231ce35171f614f26439e80f8c1465c5cc0c"
dependencies = [
"anstyle",
"anstyle-parse",
"anstyle-query",
"anstyle-wincon",
"colorchoice",
"utf8parse",
]
[[package]]
name = "anstyle"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "15c4c2c83f81532e5845a733998b6971faca23490340a418e9b72a3ec9de12ea"
[[package]]
name = "anstyle-parse"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "938874ff5980b03a87c5524b3ae5b59cf99b1d6bc836848df7bc5ada9643c333"
dependencies = [
"utf8parse",
]
[[package]]
name = "anstyle-query"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5ca11d4be1bab0c8bc8734a9aa7bf4ee8316d462a08c6ac5052f888fef5b494b"
dependencies = [
"windows-sys",
]
[[package]]
name = "anstyle-wincon"
version = "2.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "58f54d10c6dfa51283a066ceab3ec1ab78d13fae00aa49243a45e4571fb79dfd"
dependencies = [
"anstyle",
"windows-sys",
]
[[package]] [[package]]
name = "autocfg" name = "autocfg"
version = "1.1.0" version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
[[package]]
name = "clap"
version = "4.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6a13b88d2c62ff462f88e4a121f17a82c1af05693a2f192b5c38d14de73c19f6"
dependencies = [
"clap_builder",
"clap_derive",
]
[[package]]
name = "clap_builder"
version = "4.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2bb9faaa7c2ef94b2743a21f5a29e6f0010dff4caa69ac8e9d6cf8b6fa74da08"
dependencies = [
"anstream",
"anstyle",
"clap_lex",
"strsim",
]
[[package]]
name = "clap_derive"
version = "4.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0862016ff20d69b84ef8247369fabf5c008a7417002411897d40ee1f4532b873"
dependencies = [
"heck",
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "clap_lex"
version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cd7cc57abe963c6d3b9d8be5b06ba7c8957a930305ca90304f24ef040aa6f961"
[[package]]
name = "colorchoice"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7"
[[package]]
name = "heck"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8"
[[package]] [[package]]
name = "hercules_ir" name = "hercules_ir"
version = "0.1.0" version = "0.1.0"
...@@ -16,6 +116,14 @@ dependencies = [ ...@@ -16,6 +116,14 @@ dependencies = [
"ordered-float", "ordered-float",
] ]
[[package]]
name = "hercules_tools"
version = "0.1.0"
dependencies = [
"clap",
"hercules_ir",
]
[[package]] [[package]]
name = "memchr" name = "memchr"
version = "2.6.3" version = "2.6.3"
...@@ -55,3 +163,116 @@ checksum = "2a54938017eacd63036332b4ae5c8a49fc8c0c1d6d629893057e4f13609edd06" ...@@ -55,3 +163,116 @@ checksum = "2a54938017eacd63036332b4ae5c8a49fc8c0c1d6d629893057e4f13609edd06"
dependencies = [ dependencies = [
"num-traits", "num-traits",
] ]
[[package]]
name = "proc-macro2"
version = "1.0.66"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "18fb31db3f9bddb2ea821cde30a9f70117e3f119938b5ee630b7403aa6e2ead9"
dependencies = [
"unicode-ident",
]
[[package]]
name = "quote"
version = "1.0.33"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae"
dependencies = [
"proc-macro2",
]
[[package]]
name = "strsim"
version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623"
[[package]]
name = "syn"
version = "2.0.31"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "718fa2415bcb8d8bd775917a1bf12a7931b6dfa890753378538118181e0cb398"
dependencies = [
"proc-macro2",
"quote",
"unicode-ident",
]
[[package]]
name = "unicode-ident"
version = "1.0.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "301abaae475aa91687eb82514b328ab47a211a533026cb25fc3e519b86adfc3c"
[[package]]
name = "utf8parse"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a"
[[package]]
name = "windows-sys"
version = "0.48.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9"
dependencies = [
"windows-targets",
]
[[package]]
name = "windows-targets"
version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c"
dependencies = [
"windows_aarch64_gnullvm",
"windows_aarch64_msvc",
"windows_i686_gnu",
"windows_i686_msvc",
"windows_x86_64_gnu",
"windows_x86_64_gnullvm",
"windows_x86_64_msvc",
]
[[package]]
name = "windows_aarch64_gnullvm"
version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8"
[[package]]
name = "windows_aarch64_msvc"
version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc"
[[package]]
name = "windows_i686_gnu"
version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e"
[[package]]
name = "windows_i686_msvc"
version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406"
[[package]]
name = "windows_x86_64_gnu"
version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e"
[[package]]
name = "windows_x86_64_gnullvm"
version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc"
[[package]]
name = "windows_x86_64_msvc"
version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538"
[workspace] [workspace]
members = [ members = [
"hercules_ir" "hercules_ir",
"hercules_tools"
] ]
...@@ -4,7 +4,7 @@ use std::collections::HashMap; ...@@ -4,7 +4,7 @@ use std::collections::HashMap;
use crate::*; use crate::*;
fn parse(ir_test: &str) -> Module { pub fn parse(ir_test: &str) -> Module {
parse_module(ir_test, Context::default()).unwrap().1 parse_module(ir_test, Context::default()).unwrap().1
} }
...@@ -347,9 +347,5 @@ fn add(x: i32, y: i32) -> i32 ...@@ -347,9 +347,5 @@ fn add(x: i32, y: i32) -> i32
z = add(start, x, y) z = add(start, x, y)
", ",
); );
println!("{:?}", module);
let mut dot = String::new();
write_dot(&module, &mut dot).unwrap();
println!("{}", dot);
} }
} }
[package]
name = "hercules_tools"
version = "0.1.0"
authors = ["Russel Arbore <rarbore2@illinois.edu>"]
[[bin]]
name = "hercules_dot"
path = "src/hercules_dot/main.rs"
[dependencies]
clap = { version = "*", features = ["derive"] }
hercules_ir = { path = "../hercules_ir" }
extern crate clap;
use std::env::temp_dir;
use std::fs::File;
use std::io::prelude::*;
use std::process::Command;
use clap::Parser;
#[derive(Parser, Debug)]
#[command(author, version, about, long_about = None)]
struct Args {
hir_file: String,
#[arg(short, long, default_value_t = String::new())]
output: String,
}
fn main() {
let args = Args::parse();
if !args.hir_file.ends_with(".hir") {
eprintln!("WARNING: Running hercules_dot on a file without a .hir extension - interpreting as a textual Hercules IR file.");
}
let mut file = File::open(args.hir_file).expect("PANIC: Unable to open input file.");
let mut contents = String::new();
file.read_to_string(&mut contents)
.expect("PANIC: Unable to read input file contents.");
let module = hercules_ir::parse::parse(&contents);
if args.output.is_empty() {
let mut tmp_path = temp_dir();
tmp_path.push("hercules_dot.dot");
let mut file = File::create(tmp_path.clone()).expect("PANIC: Unable to open output file.");
let mut contents = String::new();
hercules_ir::dot::write_dot(&module, &mut contents)
.expect("PANIC: Unable to generate output file contents.");
file.write_all(contents.as_bytes())
.expect("PANIC: Unable to write output file contents.");
Command::new("xdot")
.args([tmp_path])
.output()
.expect("PANIC: Couldn't execute xdot.");
} else {
let mut file = File::create(args.output).expect("PANIC: Unable to open output file.");
let mut contents = String::new();
hercules_ir::dot::write_dot(&module, &mut contents)
.expect("PANIC: Unable to generate output file contents.");
file.write_all(contents.as_bytes())
.expect("PANIC: Unable to write output file contents.");
}
}
digraph "Module" {
compound=true
subgraph add {
label="add"
bgcolor=ivory4
cluster=true
start_0_0 [label="start"];
parameter_0_1 [label="param #1"];
parameter_0_2 [label="param #2"];
constant_0_3 [label="Integer8(5)"];
add_0_6 [label="add"];
start_0_0 -> add_0_6 [style="dashed"];
parameter_0_1 -> add_0_6;
parameter_0_2 -> add_0_6;
add_0_4 [label="add"];
start_0_0 -> add_0_4 [style="dashed"];
add_0_6 -> add_0_4;
constant_0_3 -> add_0_4;
return_0_5 [label="return"];
start_0_0 -> return_0_5 [style="dashed"];
add_0_4 -> return_0_5;
}
subgraph myfunc {
label="myfunc"
bgcolor=ivory4
cluster=true
start_1_0 [label="start"];
parameter_1_1 [label="param #1"];
parameter_1_1 -> call_1_2;
parameter_1_1 -> call_1_2;
call_1_2 [label="call(add)"];
start_1_0 -> call_1_2 [style="dashed"];
call_1_2 -> start_0_0 [lhead=add];
return_1_3 [label="return"];
start_1_0 -> return_1_3 [style="dashed"];
call_1_2 -> return_1_3;
}
}
fn myfunc(x: i32) -> i32
y = call(start, add, x, x)
r = return(start, y)
fn add(x: i32, y: i32) -> i32
c = constant(i8, 5)
r = return(start, w)
w = add(start, z, c)
z = add(start, x, y)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment