diff --git a/Cargo.lock b/Cargo.lock index 01823de20..7a0645a65 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -119,7 +119,7 @@ dependencies = [ "argh_shared", "proc-macro2", "quote", - "syn 2.0.57", + "syn 2.0.58", ] [[package]] @@ -182,6 +182,16 @@ dependencies = [ "generic-array", ] +[[package]] +name = "bril-rs" +version = "0.1.0" +source = "git+https://github.com/ajpal/bril?rev=af21f1c#af21f1cf91e833522420e09302b79d23bc75fc9c" +dependencies = [ + "serde", + "serde_json", + "thiserror", +] + [[package]] name = "bril-rs" version = "0.1.0" @@ -195,9 +205,9 @@ dependencies = [ [[package]] name = "bril2json" version = "0.1.0" -source = "git+https://github.com/sampsyo/bril?rev=b20cc2d#b20cc2d797943aee0ec91f9bff562ad26162da99" +source = "git+https://github.com/ajpal/bril?rev=af21f1c#af21f1cf91e833522420e09302b79d23bc75fc9c" dependencies = [ - "bril-rs", + "bril-rs 0.1.0 (git+https://github.com/ajpal/bril?rev=af21f1c)", "clap", "lalrpop", "lalrpop-util", @@ -207,10 +217,10 @@ dependencies = [ [[package]] name = "brilift" version = "0.1.0" -source = "git+https://github.com/sampsyo/bril?rev=b20cc2d#b20cc2d797943aee0ec91f9bff562ad26162da99" +source = "git+https://github.com/ajpal/bril?rev=af21f1c#af21f1cf91e833522420e09302b79d23bc75fc9c" dependencies = [ "argh", - "bril-rs", + "bril-rs 0.1.0 (git+https://github.com/ajpal/bril?rev=af21f1c)", "cranelift-codegen", "cranelift-frontend", "cranelift-jit", @@ -224,9 +234,9 @@ dependencies = [ [[package]] name = "brilirs" version = "0.1.0" -source = "git+https://github.com/sampsyo/bril?rev=b20cc2d#b20cc2d797943aee0ec91f9bff562ad26162da99" +source = "git+https://github.com/ajpal/bril?rev=af21f1c#af21f1cf91e833522420e09302b79d23bc75fc9c" dependencies = [ - "bril-rs", + "bril-rs 0.1.0 (git+https://github.com/ajpal/bril?rev=af21f1c)", "bril2json", "clap", "fxhash", @@ -290,7 +300,7 @@ dependencies = [ "heck 0.5.0", "proc-macro2", "quote", - "syn 2.0.57", + "syn 2.0.58", ] [[package]] @@ -490,7 +500,7 @@ dependencies = [ name = "dag_in_context" version = "0.1.0" dependencies = [ - "bril-rs", + "bril-rs 0.1.0 (git+https://github.com/sampsyo/bril?rev=b20cc2d)", "dot-structures", "egglog", "graphviz-rust 0.8.0", @@ -559,7 +569,7 @@ checksum = "675e35c02a51bb4d4618cb4885b3839ce6d1787c97b664474d9208d074742e20" name = "eggcc" version = "0.1.0" dependencies = [ - "bril-rs", + "bril-rs 0.1.0 (git+https://github.com/ajpal/bril?rev=af21f1c)", "bril2json", "brilift", "brilirs", @@ -579,8 +589,10 @@ dependencies = [ "log", "ordered-float", "petgraph", + "rs2bril", "serde_json", "smallvec", + "syn 2.0.58", "thiserror", ] @@ -664,7 +676,7 @@ checksum = "f282cfdfe92516eb26c2af8589c274c7c17681f5ecc03c18255fe741c6aa64eb" dependencies = [ "proc-macro2", "quote", - "syn 2.0.57", + "syn 2.0.58", ] [[package]] @@ -1218,7 +1230,7 @@ dependencies = [ "pest_meta", "proc-macro2", "quote", - "syn 2.0.57", + "syn 2.0.58", ] [[package]] @@ -1399,6 +1411,17 @@ dependencies = [ "winapi", ] +[[package]] +name = "rs2bril" +version = "0.1.0" +source = "git+https://github.com/ajpal/bril?rev=af21f1c#af21f1cf91e833522420e09302b79d23bc75fc9c" +dependencies = [ + "bril-rs 0.1.0 (git+https://github.com/ajpal/bril?rev=af21f1c)", + "clap", + "proc-macro2", + "syn 2.0.58", +] + [[package]] name = "rustc-hash" version = "1.1.0" @@ -1462,7 +1485,7 @@ checksum = "7eb0b34b42edc17f6b7cac84a52a1c5f0e1bb2227e997ca9011ea3dd34e8610b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.57", + "syn 2.0.58", ] [[package]] @@ -1564,7 +1587,7 @@ dependencies = [ "proc-macro2", "quote", "rustversion", - "syn 2.0.57", + "syn 2.0.58", ] [[package]] @@ -1590,9 +1613,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.57" +version = "2.0.58" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "11a6ae1e52eb25aab8f3fb9fca13be982a373b8f1157ca14b897a825ba4a2d35" +checksum = "44cfb93f38070beee36b3fef7d4f5a16f27751d94b187b666a5cc5e9b0d30687" dependencies = [ "proc-macro2", "quote", @@ -1654,7 +1677,7 @@ checksum = "c61f3ba182994efc43764a46c018c347bc492c79f024e705f46567b418f6d4f7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.57", + "syn 2.0.58", ] [[package]] @@ -1942,5 +1965,5 @@ checksum = "9ce1b18ccd8e73a9321186f97e46f9f04b778851177567b1975109d26a08d2a6" dependencies = [ "proc-macro2", "quote", - "syn 2.0.57", + "syn 2.0.58", ] diff --git a/Cargo.toml b/Cargo.toml index 12c715555..2c113b183 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,10 +20,12 @@ indexmap = "2.0" fixedbitset = "0.4.2" smallvec = "1.11.1" -bril2json = { git = "https://github.com/sampsyo/bril", rev = "b20cc2d" } -brilirs = { git = "https://github.com/sampsyo/bril", rev = "b20cc2d" } -bril-rs = { git = "https://github.com/sampsyo/bril", rev = "b20cc2d" } -brilift = { git = "https://github.com/sampsyo/bril", rev = "b20cc2d" } +syn = {version = "2.0", features = ["full", "extra-traits"]} +bril2json = { git = "https://github.com/ajpal/bril", rev = "af21f1c" } +brilirs = { git = "https://github.com/ajpal/bril", rev = "af21f1c" } +bril-rs = { git = "https://github.com/ajpal/bril", rev = "af21f1c" } +brilift = { git = "https://github.com/ajpal/bril", rev = "af21f1c" } +rs2bril = { git = "https://github.com/ajpal/bril", rev = "af21f1c", features = ["import"]} ordered-float = { version = "3.7" } serde_json = "1.0.103" dot-structures = "0.1.1" diff --git a/src/main.rs b/src/main.rs index 4fb2aa3bf..14b4bb49e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,6 @@ use clap::Parser; use eggcc::util::{visualize, Run, RunType, TestProgram}; -use std::path::PathBuf; +use std::{ffi::OsStr, path::PathBuf}; #[derive(Debug, Parser)] struct Args { @@ -44,7 +44,7 @@ fn main() { let args = Args::parse(); if let Some(debug_dir) = args.debug_dir { - if let Result::Err(error) = visualize(TestProgram::File(args.file.clone()), debug_dir) { + if let Result::Err(error) = visualize(TestProgram::BrilFile(args.file.clone()), debug_dir) { eprintln!("{}", error); return; } @@ -58,8 +58,15 @@ fn main() { return; } + let file = match args.file.extension().and_then(OsStr::to_str) { + Some("rs") => TestProgram::RustFile(args.file.clone()), + Some("bril") => TestProgram::BrilFile(args.file.clone()), + Some(x) => panic!("unexpected file extension {x}"), + None => panic!("could not parse file extension"), + }; + let run = Run { - prog_with_args: TestProgram::File(args.file.clone()).read_program(), + prog_with_args: file.read_program(), test_type: args.run_mode, interp: args.interp, profile_out: args.profile_out, diff --git a/src/util.rs b/src/util.rs index db9cb2cf7..8d75cedf9 100644 --- a/src/util.rs +++ b/src/util.rs @@ -9,6 +9,7 @@ use graphviz_rust::cmd::Format; use graphviz_rust::exec; use graphviz_rust::printer::PrinterContext; use std::fmt::Debug; +use std::io::Read; use std::{ ffi::OsStr, fmt::{Display, Formatter}, @@ -159,7 +160,7 @@ where pub enum RunType { /// Do nothing to the input bril program besides parse it. /// Output the original program. - Nothing, + Parse, /// Convert the input bril program to the tree encoding, optimize the program /// using egglog, and output the resulting bril program. /// The default way to run this tool. @@ -212,7 +213,7 @@ impl RunType { /// that can be interpreted. pub fn produces_interpretable(&self) -> bool { match self { - RunType::Nothing => true, + RunType::Parse => true, RunType::Optimize => true, RunType::RvsdgConversion => false, RunType::RvsdgRoundTrip => true, @@ -242,14 +243,15 @@ pub struct ProgWithArguments { #[derive(Clone)] pub enum TestProgram { Prog(ProgWithArguments), - File(PathBuf), + BrilFile(PathBuf), + RustFile(PathBuf), } impl TestProgram { pub fn read_program(self) -> ProgWithArguments { match self { TestProgram::Prog(prog) => prog, - TestProgram::File(path) => { + TestProgram::BrilFile(path) => { let program_read = std::fs::read_to_string(path.clone()).unwrap(); let args = Optimizer::parse_bril_args(&program_read); let program = Optimizer::parse_bril(&program_read).unwrap(); @@ -261,6 +263,21 @@ impl TestProgram { args, } } + TestProgram::RustFile(path) => { + let mut src = String::new(); + let mut file = std::fs::File::open(path.clone()).unwrap(); + + file.read_to_string(&mut src).unwrap(); + let syntax = syn::parse_file(&src).unwrap(); + let name = path.display().to_string(); + let program = rs2bril::from_file_to_program(syntax, false, Some(name.clone())); + + ProgWithArguments { + program, + name, + args: vec![], + } + } } } } @@ -390,7 +407,7 @@ impl Run { }; let (visualizations, interpretable_out) = match self.test_type { - RunType::Nothing => ( + RunType::Parse => ( vec![], Some(Interpretable::Bril(self.prog_with_args.program.clone())), ), diff --git a/tests/files.rs b/tests/files.rs index ac8dcf25c..a15577ec4 100644 --- a/tests/files.rs +++ b/tests/files.rs @@ -49,7 +49,7 @@ fn generate_tests(glob: &str) -> Vec { let snapshot = f.to_str().unwrap().contains("small"); - for run in Run::all_configurations_for(TestProgram::File(f)) { + for run in Run::all_configurations_for(TestProgram::BrilFile(f)) { mk_trial(run, snapshot); } }