Skip to content

Commit

Permalink
test(dataflow): Turnt the manually verified programs for reaching def…
Browse files Browse the repository at this point in the history
…initions
  • Loading branch information
ethanuppal committed Feb 14, 2025
1 parent d70c1a1 commit 8c5c14c
Show file tree
Hide file tree
Showing 13 changed files with 236 additions and 5 deletions.
10 changes: 10 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,17 @@ jobs:
- name: Install Python tools
run: cd bril/bril-txt ; flit install --symlink

- name: Install Turnt
# run: pip install turnt # Use instead if pip turnt version >= 1.7
uses: actions/checkout@v4
with:
repository: cucapra/turnt
path: './turnt'
- name: Install Turnt part 2
run: cd turnt ; flit install --symlink

- name: Test dataflow
run: |
cd lesson4/dataflow
python3 check.py def ../../bril/benchmarks/**/*.bril ../../bril/examples/test/df/*.bril
cd turnt && turnt df_copied_from_bril/*.bril
2 changes: 1 addition & 1 deletion lesson4/dataflow/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def check_file(args):
(file, analysis) = args
print(f"\x1b[33m{file} START\x1b[m")
result = subprocess.run(
f"bril2json <{file} | cargo run --quiet -- --analysis {analysis}",
f"bril2json <{file} | cargo run --package dataflow --quiet -- --analysis {analysis}",
shell=True,
capture_output=True,
)
Expand Down
15 changes: 11 additions & 4 deletions lesson4/dataflow/src/reaching_definitions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ pub fn reaching_definitions(cfg: &FunctionCfg) {
}
inputs
}
println!("\x1b[33;1m@{}\x1b[m {{", cfg.signature.name);
println!("@{} {{", cfg.signature.name);
for (block, solution) in solve_dataflow(
cfg,
Direction::Forward,
Expand All @@ -86,10 +86,17 @@ pub fn reaching_definitions(cfg: &FunctionCfg) {
transfer,
) {
if let Some(label) = &cfg.vertices[block].label {
println!("\x1b[1;33m .{}:\x1b[m", label.name);
println!(" .{}", label.name);
}
for definition in &solution {
println!("\x1b[2m {} = {:?}\x1b[m", definition.0, definition.1);
let mut printouts = solution
.iter()
.map(|definition| {
format!(" {} = {:?}", definition.0, definition.1)
})
.collect::<Vec<_>>();
printouts.sort();
for printout in printouts {
println!("{}", printout);
}

for definition in solution {
Expand Down
16 changes: 16 additions & 0 deletions lesson4/dataflow/turnt/df_copied_from_bril/cond-args.bril
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
@main(cond: bool) {
a: int = const 47;
b: int = const 42;
br cond .left .right;
.left:
b: int = const 1;
c: int = const 5;
jmp .end;
.right:
a: int = const 2;
c: int = const 10;
jmp .end;
.end:
d: int = sub a c;
print d;
}
24 changes: 24 additions & 0 deletions lesson4/dataflow/turnt/df_copied_from_bril/cond-args.def.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
@main {
a = Constant("47", false)
b = Constant("42", false)
cond = Argument
.left
a = Constant("47", false)
b = Constant("1", false)
c = Constant("5", false)
cond = Argument
.right
a = Constant("2", false)
b = Constant("42", false)
c = Constant("10", false)
cond = Argument
.end
a = Constant("2", false)
a = Constant("47", false)
b = Constant("1", false)
b = Constant("42", false)
c = Constant("10", false)
c = Constant("5", false)
cond = Argument
d = Op("sub", ["a", "c"], [], [])
}
24 changes: 24 additions & 0 deletions lesson4/dataflow/turnt/df_copied_from_bril/cond-args.defined.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
@main {
a = Constant("47", false)
b = Constant("42", false)
cond = Argument
.left
a = Constant("47", false)
b = Constant("1", false)
c = Constant("5", false)
cond = Argument
.right
a = Constant("2", false)
b = Constant("42", false)
c = Constant("10", false)
cond = Argument
.end
a = Constant("2", false)
a = Constant("47", false)
b = Constant("1", false)
b = Constant("42", false)
c = Constant("10", false)
c = Constant("5", false)
cond = Argument
d = Op("sub", ["a", "c"], [], [])
}
17 changes: 17 additions & 0 deletions lesson4/dataflow/turnt/df_copied_from_bril/cond.bril
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
@main {
a: int = const 47;
b: int = const 42;
cond: bool = const true;
br cond .left .right;
.left:
b: int = const 1;
c: int = const 5;
jmp .end;
.right:
a: int = const 2;
c: int = const 10;
jmp .end;
.end:
d: int = sub a c;
print d;
}
24 changes: 24 additions & 0 deletions lesson4/dataflow/turnt/df_copied_from_bril/cond.def.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
@main {
a = Constant("47", false)
b = Constant("42", false)
cond = Constant("true", false)
.left
a = Constant("47", false)
b = Constant("1", false)
c = Constant("5", false)
cond = Constant("true", false)
.right
a = Constant("2", false)
b = Constant("42", false)
c = Constant("10", false)
cond = Constant("true", false)
.end
a = Constant("2", false)
a = Constant("47", false)
b = Constant("1", false)
b = Constant("42", false)
c = Constant("10", false)
c = Constant("5", false)
cond = Constant("true", false)
d = Op("sub", ["a", "c"], [], [])
}
24 changes: 24 additions & 0 deletions lesson4/dataflow/turnt/df_copied_from_bril/cond.defined.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
@main {
a = Constant("47", false)
b = Constant("42", false)
cond = Constant("true", false)
.left
a = Constant("47", false)
b = Constant("1", false)
c = Constant("5", false)
cond = Constant("true", false)
.right
a = Constant("2", false)
b = Constant("42", false)
c = Constant("10", false)
cond = Constant("true", false)
.end
a = Constant("2", false)
a = Constant("47", false)
b = Constant("1", false)
b = Constant("42", false)
c = Constant("10", false)
c = Constant("5", false)
cond = Constant("true", false)
d = Op("sub", ["a", "c"], [], [])
}
22 changes: 22 additions & 0 deletions lesson4/dataflow/turnt/df_copied_from_bril/fact.bril
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
@main {
result: int = const 1;
i: int = const 8;

.header:
# Enter body if i >= 0.
zero: int = const 0;
cond: bool = gt i zero;
br cond .body .end;

.body:
result: int = mul result i;

# i--
one: int = const 1;
i: int = sub i one;

jmp .header;

.end:
print result;
}
26 changes: 26 additions & 0 deletions lesson4/dataflow/turnt/df_copied_from_bril/fact.def.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
@main {
i = Constant("8", false)
result = Constant("1", false)
.header
cond = Op("gt", ["i", "zero"], [], [])
i = Constant("8", false)
i = Op("sub", ["i", "one"], [], [])
one = Constant("1", false)
result = Constant("1", false)
result = Op("mul", ["result", "i"], [], [])
zero = Constant("0", false)
.body
cond = Op("gt", ["i", "zero"], [], [])
i = Op("sub", ["i", "one"], [], [])
one = Constant("1", false)
result = Op("mul", ["result", "i"], [], [])
zero = Constant("0", false)
.end
cond = Op("gt", ["i", "zero"], [], [])
i = Constant("8", false)
i = Op("sub", ["i", "one"], [], [])
one = Constant("1", false)
result = Constant("1", false)
result = Op("mul", ["result", "i"], [], [])
zero = Constant("0", false)
}
26 changes: 26 additions & 0 deletions lesson4/dataflow/turnt/df_copied_from_bril/fact.defined.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
@main {
i = Constant("8", false)
result = Constant("1", false)
.header
cond = Op("gt", ["i", "zero"], [], [])
i = Constant("8", false)
i = Op("sub", ["i", "one"], [], [])
one = Constant("1", false)
result = Constant("1", false)
result = Op("mul", ["result", "i"], [], [])
zero = Constant("0", false)
.body
cond = Op("gt", ["i", "zero"], [], [])
i = Op("sub", ["i", "one"], [], [])
one = Constant("1", false)
result = Op("mul", ["result", "i"], [], [])
zero = Constant("0", false)
.end
cond = Op("gt", ["i", "zero"], [], [])
i = Constant("8", false)
i = Op("sub", ["i", "one"], [], [])
one = Constant("1", false)
result = Constant("1", false)
result = Op("mul", ["result", "i"], [], [])
zero = Constant("0", false)
}
11 changes: 11 additions & 0 deletions lesson4/dataflow/turnt/turnt.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[envs.def]
command = "bril2json < {filename} | cargo run --quiet -- --analysis def"
output."def.out" = "-"

# [envs.live]
# command = "bril2json < {filename} | python3 ../../df.py live"
# output."live.out" = "-"
#
# [envs.cprop]
# command = "bril2json < {filename} | python3 ../../df.py cprop"
# output."cprop.out" = "-"

0 comments on commit 8c5c14c

Please sign in to comment.