diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index ca22c8f..fde3674 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -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 diff --git a/lesson4/dataflow/check.py b/lesson4/dataflow/check.py index 1da4780..3616f85 100644 --- a/lesson4/dataflow/check.py +++ b/lesson4/dataflow/check.py @@ -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, ) diff --git a/lesson4/dataflow/src/reaching_definitions.rs b/lesson4/dataflow/src/reaching_definitions.rs index b902f48..b4824e7 100644 --- a/lesson4/dataflow/src/reaching_definitions.rs +++ b/lesson4/dataflow/src/reaching_definitions.rs @@ -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, @@ -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::>(); + printouts.sort(); + for printout in printouts { + println!("{}", printout); } for definition in solution { diff --git a/lesson4/dataflow/turnt/df_copied_from_bril/cond-args.bril b/lesson4/dataflow/turnt/df_copied_from_bril/cond-args.bril new file mode 100644 index 0000000..1c17264 --- /dev/null +++ b/lesson4/dataflow/turnt/df_copied_from_bril/cond-args.bril @@ -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; +} diff --git a/lesson4/dataflow/turnt/df_copied_from_bril/cond-args.def.out b/lesson4/dataflow/turnt/df_copied_from_bril/cond-args.def.out new file mode 100644 index 0000000..a516b11 --- /dev/null +++ b/lesson4/dataflow/turnt/df_copied_from_bril/cond-args.def.out @@ -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"], [], []) +} diff --git a/lesson4/dataflow/turnt/df_copied_from_bril/cond-args.defined.out b/lesson4/dataflow/turnt/df_copied_from_bril/cond-args.defined.out new file mode 100644 index 0000000..a516b11 --- /dev/null +++ b/lesson4/dataflow/turnt/df_copied_from_bril/cond-args.defined.out @@ -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"], [], []) +} diff --git a/lesson4/dataflow/turnt/df_copied_from_bril/cond.bril b/lesson4/dataflow/turnt/df_copied_from_bril/cond.bril new file mode 100644 index 0000000..0b0ceef --- /dev/null +++ b/lesson4/dataflow/turnt/df_copied_from_bril/cond.bril @@ -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; +} diff --git a/lesson4/dataflow/turnt/df_copied_from_bril/cond.def.out b/lesson4/dataflow/turnt/df_copied_from_bril/cond.def.out new file mode 100644 index 0000000..fadfbdb --- /dev/null +++ b/lesson4/dataflow/turnt/df_copied_from_bril/cond.def.out @@ -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"], [], []) +} diff --git a/lesson4/dataflow/turnt/df_copied_from_bril/cond.defined.out b/lesson4/dataflow/turnt/df_copied_from_bril/cond.defined.out new file mode 100644 index 0000000..fadfbdb --- /dev/null +++ b/lesson4/dataflow/turnt/df_copied_from_bril/cond.defined.out @@ -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"], [], []) +} diff --git a/lesson4/dataflow/turnt/df_copied_from_bril/fact.bril b/lesson4/dataflow/turnt/df_copied_from_bril/fact.bril new file mode 100644 index 0000000..b5def64 --- /dev/null +++ b/lesson4/dataflow/turnt/df_copied_from_bril/fact.bril @@ -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; +} diff --git a/lesson4/dataflow/turnt/df_copied_from_bril/fact.def.out b/lesson4/dataflow/turnt/df_copied_from_bril/fact.def.out new file mode 100644 index 0000000..576162c --- /dev/null +++ b/lesson4/dataflow/turnt/df_copied_from_bril/fact.def.out @@ -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) +} diff --git a/lesson4/dataflow/turnt/df_copied_from_bril/fact.defined.out b/lesson4/dataflow/turnt/df_copied_from_bril/fact.defined.out new file mode 100644 index 0000000..576162c --- /dev/null +++ b/lesson4/dataflow/turnt/df_copied_from_bril/fact.defined.out @@ -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) +} diff --git a/lesson4/dataflow/turnt/turnt.toml b/lesson4/dataflow/turnt/turnt.toml new file mode 100644 index 0000000..2400b23 --- /dev/null +++ b/lesson4/dataflow/turnt/turnt.toml @@ -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" = "-"