Skip to content

Commit

Permalink
clean up rs2bril support
Browse files Browse the repository at this point in the history
  • Loading branch information
oflatt committed Oct 17, 2024
1 parent 558ca2c commit 3c78b6d
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 7 deletions.
7 changes: 7 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,13 @@ impl Optimizer {
{
args.push(arg);
}
} else if first_line.contains("// ARGS:") {
for arg in first_line["// ARGS: ".len()..]
.split(' ')
.map(|s| s.to_string())
{
args.push(arg);
}
}
}
args
Expand Down
9 changes: 7 additions & 2 deletions src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -303,14 +303,15 @@ impl TestProgram {
let mut file = std::fs::File::open(path.clone()).unwrap();

file.read_to_string(&mut src).unwrap();
let args = Optimizer::parse_bril_args(&src);
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![],
args,
}
}
}
Expand Down Expand Up @@ -553,7 +554,11 @@ impl Run {

let (visualizations, interpretable_out) = match self.test_type {
RunMode::Parse => (
vec![],
vec![Visualization {
result: self.prog_with_args.program.to_string(),
file_extension: ".bril".to_string(),
name: "".to_string(),
}],
Some(Interpretable::Bril(self.prog_with_args.program.clone())),
),
RunMode::BrilToJson => {
Expand Down
19 changes: 14 additions & 5 deletions tests/files.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::collections::HashSet;
use std::{collections::HashSet, ffi::OsStr};

use eggcc::util::{Run, RunMode, TestProgram};
use insta::assert_snapshot;
Expand Down Expand Up @@ -42,16 +42,23 @@ fn generate_tests(glob: &str, slow_test: bool) -> Vec<Trial> {
};

for entry in glob::glob(glob).unwrap() {
let f = entry.unwrap();
let file = entry.unwrap();

let snapshot = f.to_str().unwrap().contains("small");
let snapshot = file.to_str().unwrap().contains("small");

let testprog = match file.extension().and_then(OsStr::to_str) {
Some("rs") => TestProgram::RustFile(file.clone()),
Some("bril") => TestProgram::BrilFile(file.clone()),
Some(x) => panic!("unexpected file extension {x}"),
None => panic!("could not parse file extension"),
};

let configurations = if slow_test {
// in benchmark mode, run a special test pipeline that only runs
// a few modes, and shares intermediate results
vec![Run::test_benchmark_config(TestProgram::BrilFile(f.clone()))]
vec![Run::test_benchmark_config(testprog)]
} else {
Run::all_configurations_for(TestProgram::BrilFile(f))
Run::all_configurations_for(testprog)
};

for run in configurations {
Expand All @@ -65,6 +72,8 @@ fn generate_tests(glob: &str, slow_test: bool) -> Vec<Trial> {
fn main() {
let args = libtest_mimic::Arguments::from_args();
let mut tests = generate_tests("tests/passing/**/*.bril", false);
tests.extend(generate_tests("tests/passing/**/*.rs", false));

tests.extend(generate_tests("tests/slow/**/*.bril", true));
// also generate tests for benchmarks
tests.extend(generate_tests("benchmarks/passing/**/*.bril", true));
Expand Down
45 changes: 45 additions & 0 deletions tests/passing/brils/rs2bril-example.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// ARGS: 50 2.0 true
fn main(x: i64, f: f64, b: bool) {
let ptr: [i64; 2] = [0, 0];
let x: i64 = -1;
let y: bool = !(!true);
let z: f64 = -0.0;
z = -1.0;
f = 5.0;
f /= 2.0;
ptr[0] = 1;
ptr[1] = ptr[2 + x];

let foo: i64 = test2(1, 2);
test3();

let test: [i64; 2] = [0, 1];
let test2: [[i64; 2]; 1] = [test];
let test3: [f64; 10] = [z; 10];

if true {
let cond: i64 = 0;
while cond < 2 {
cond += 1;
}
} else {
if true {
let cond2: bool = false;
while cond2 {}
}
}

drop(test);
drop(test2);
drop(test3);
drop(ptr);
println!("{}", x);
}

fn test2(x: i64, y: i64) -> i64 {
return x;
}

fn test3() {
return;
}

0 comments on commit 3c78b6d

Please sign in to comment.