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

hercules_hbin_dump

parent 3abe3edc
No related branches found
No related tags found
1 merge request!24Handle arrays properly in the runtime (part 1)
......@@ -639,34 +639,23 @@ dependencies = [
]
[[package]]
name = "hercules_cpu_beta"
version = "0.1.0"
dependencies = [
"clap",
"hercules_cg",
"hercules_ir",
"hercules_opt",
"rand",
]
[[package]]
name = "hercules_dot"
name = "hercules_driver"
version = "0.1.0"
dependencies = [
"clap",
"hercules_ir",
"hercules_opt",
"rand",
"ron",
]
[[package]]
name = "hercules_driver"
name = "hercules_hbin_dump"
version = "0.1.0"
dependencies = [
"clap",
"hercules_ir",
"hercules_opt",
"ron",
"postcard",
"serde",
]
[[package]]
......@@ -729,7 +718,6 @@ dependencies = [
"async-std",
"clap",
"hercules_rt",
"rand",
]
[[package]]
......
......@@ -8,8 +8,7 @@ members = [
"hercules_rt_proc",
"hercules_tools/hercules_driver",
"hercules_tools/hercules_dot",
"hercules_tools/hercules_cpu_beta",
"hercules_tools/hercules_hbin_dump",
"juno_frontend",
......
......@@ -68,15 +68,14 @@ pub struct FunctionManifest {
}
/*
* Rules for validity of provided dynamic constants. Integers refer to dynamic
* constant parameters of a function.
* Rules for validity of provided dynamic constants
*/
#[derive(Debug, Serialize, Deserialize, Hash, PartialEq, Eq)]
pub enum DynamicConstantRule {
// Generated from subtraction.
LessThan(u32, u32),
LessThan(DynamicConstantID, DynamicConstantID),
// Generated from division.
Divides(u32, u32),
Divides(DynamicConstantID, DynamicConstantID),
}
#[derive(Debug, Serialize, Deserialize, Hash, PartialEq, Eq)]
......
......@@ -7,5 +7,4 @@ edition = "2021"
[dependencies]
clap = { version = "*", features = ["derive"] }
hercules_rt = { path = "../../hercules_rt" }
rand = "*"
async-std = "*"
extern crate clap;
use std::fs::File;
use std::io::prelude::*;
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_cpu_beta 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).expect("PANIC: Failed to parse Hercules IR file.");
let mut pm = hercules_opt::pass::PassManager::new(module);
pm.add_pass(hercules_opt::pass::Pass::Verify);
pm.add_pass(hercules_opt::pass::Pass::CCP);
pm.add_pass(hercules_opt::pass::Pass::DCE);
pm.add_pass(hercules_opt::pass::Pass::GVN);
pm.add_pass(hercules_opt::pass::Pass::DCE);
pm.add_pass(hercules_opt::pass::Pass::Forkify);
pm.add_pass(hercules_opt::pass::Pass::DCE);
pm.add_pass(hercules_opt::pass::Pass::Predication);
pm.add_pass(hercules_opt::pass::Pass::DCE);
pm.run_passes();
pm.make_typing();
pm.make_reverse_postorders();
pm.make_def_uses();
pm.make_bbs();
pm.make_antideps();
pm.make_fork_join_maps();
pm.make_fork_join_nests();
let typing = pm.typing.as_ref().unwrap().clone();
let reverse_postorders = pm.reverse_postorders.as_ref().unwrap().clone();
let def_uses = pm.def_uses.as_ref().unwrap().clone();
let bbs = pm.bbs.as_ref().unwrap().clone();
let antideps = pm.antideps.as_ref().unwrap().clone();
let fork_join_maps = pm.fork_join_maps.as_ref().unwrap().clone();
let fork_join_nests = pm.fork_join_nests.as_ref().unwrap().clone();
let module = pm.get_module();
let mut file = File::create("test.ll").unwrap();
let mut contents = String::new();
hercules_cg::cpu_beta::cpu_beta_codegen(
&module,
&typing,
&reverse_postorders,
&def_uses,
&bbs,
&antideps,
&fork_join_maps,
&fork_join_nests,
&mut contents,
)
.unwrap();
file.write_all(contents.as_bytes()).unwrap();
}
[package]
name = "hercules_dot"
version = "0.1.0"
authors = ["Russel Arbore <rarbore2@illinois.edu>"]
[dependencies]
clap = { version = "*", features = ["derive"] }
hercules_ir = { path = "../../hercules_ir" }
hercules_opt = { path = "../../hercules_opt" }
rand = "*"
extern crate clap;
extern crate rand;
use std::fs::File;
use std::io::prelude::*;
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).expect("PANIC: Failed to parse Hercules IR file.");
let mut pm = hercules_opt::pass::PassManager::new(module);
pm.add_pass(hercules_opt::pass::Pass::Verify);
pm.add_pass(hercules_opt::pass::Pass::CCP);
pm.add_pass(hercules_opt::pass::Pass::DCE);
pm.add_pass(hercules_opt::pass::Pass::GVN);
pm.add_pass(hercules_opt::pass::Pass::DCE);
pm.add_pass(hercules_opt::pass::Pass::Forkify);
pm.add_pass(hercules_opt::pass::Pass::DCE);
pm.add_pass(hercules_opt::pass::Pass::Predication);
pm.add_pass(hercules_opt::pass::Pass::DCE);
if args.output.is_empty() {
pm.add_pass(hercules_opt::pass::Pass::Xdot(true));
pm.run_passes();
} else {
let mut file = File::create(args.output).expect("PANIC: Unable to open output file.");
let mut contents = String::new();
pm.run_passes();
pm.make_reverse_postorders();
pm.make_doms();
pm.make_fork_join_maps();
pm.make_plans();
let reverse_postorders = pm.reverse_postorders.as_ref().unwrap().clone();
let doms = pm.doms.as_ref().unwrap().clone();
let fork_join_maps = pm.fork_join_maps.as_ref().unwrap().clone();
let plans = pm.plans.as_ref().unwrap().clone();
let module = pm.get_module();
hercules_ir::dot::write_dot(
&module,
&reverse_postorders,
Some(&doms),
Some(&fork_join_maps),
Some(&plans),
&mut contents,
)
.expect("PANIC: Unable to generate output file contents.");
file.write_all(contents.as_bytes())
.expect("PANIC: Unable to write output file contents.");
}
}
[package]
name = "hercules_cpu_beta"
name = "hercules_hbin_dump"
version = "0.1.0"
authors = ["Russel Arbore <rarbore2@illinois.edu>"]
edition = "2021"
[dependencies]
clap = { version = "*", features = ["derive"] }
hercules_ir = { path = "../../hercules_ir" }
hercules_opt = { path = "../../hercules_opt" }
hercules_cg = { path = "../../hercules_cg" }
rand = "*"
postcard = { version = "*", features = ["alloc"] }
serde = { version = "*", features = ["derive"] }
hercules_ir = { path = "../../hercules_ir" }
\ No newline at end of file
extern crate clap;
extern crate hercules_ir;
extern crate postcard;
use std::fs::File;
use std::io::prelude::*;
use clap::Parser;
#[derive(Parser, Debug)]
#[command(author, version, about, long_about = None)]
struct Args {
hbin_file: String,
}
fn main() {
let args = Args::parse();
if !args.hbin_file.ends_with(".hbin") {
eprintln!("WARNING: Running hercules_hbin_dump on a file without a .hbin extension - interpreting as a Hercules binary file.");
}
let mut f = File::open(args.hbin_file).unwrap();
let mut buffer = vec![];
f.read_to_end(&mut buffer).unwrap();
let (manifest, _): (hercules_ir::ModuleManifest, Vec<u8>) =
postcard::from_bytes(&buffer).unwrap();
println!("{:#?}", manifest);
}
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