From 6b4896976f93f7a913fed46de064f17bc5468b10 Mon Sep 17 00:00:00 2001 From: Rachit Nigam Date: Tue, 5 Nov 2024 15:24:46 -0500 Subject: [PATCH] Add `jq` stage to `fud2` (#2333) Adding `jq` stage to `fud2` but I've been having trouble getting the stage to print out the value from the command. It seems like the `jq ... > $out` call gobbles up the output. Not sure if I'm making a mistake. Any thoughts @EclecticGriffin @ekiwi or @sampsyo? --- fud2/scripts/jq.rhai | 11 +++ fud2/tests/snapshots/tests__list_ops.snap | 6 +- fud2/tests/snapshots/tests__list_states.snap | 2 +- .../snapshots/tests__test@plan_dat_to_jq.snap | 19 ++++++ fud2/tests/tests.rs | 1 + interp/tests/runt.toml | 67 ++++++++++++------- 6 files changed, 78 insertions(+), 28 deletions(-) create mode 100644 fud2/scripts/jq.rhai create mode 100644 fud2/tests/snapshots/tests__test@plan_dat_to_jq.snap diff --git a/fud2/scripts/jq.rhai b/fud2/scripts/jq.rhai new file mode 100644 index 000000000..aba164968 --- /dev/null +++ b/fud2/scripts/jq.rhai @@ -0,0 +1,11 @@ +import "rtl_sim" as sim; + +export const jq_state = state("jq", ["jq"]); + +defop dat_to_jq(json: sim::dat) >> out: jq_state { + let expr = config_or("jq.expr", "."); + let jq = config_or("jq.exe", "jq"); + let flags = config_or("jq.flags", ""); + + shell(`${jq} '${expr}' ${flags} ${json} > ${out}`); +} \ No newline at end of file diff --git a/fud2/tests/snapshots/tests__list_ops.snap b/fud2/tests/snapshots/tests__list_ops.snap index 76578bfbe..d199268f2 100644 --- a/fud2/tests/snapshots/tests__list_ops.snap +++ b/fud2/tests/snapshots/tests__list_ops.snap @@ -1,6 +1,5 @@ --- source: fud2/tests/tests.rs -snapshot_kind: text --- [ ( @@ -48,6 +47,11 @@ snapshot_kind: text "dahlia", "calyx", ), + ( + "dat_to_jq", + "dat", + "jq", + ), ( "debug", "cider", diff --git a/fud2/tests/snapshots/tests__list_states.snap b/fud2/tests/snapshots/tests__list_states.snap index fbc730d11..73b29224d 100644 --- a/fud2/tests/snapshots/tests__list_states.snap +++ b/fud2/tests/snapshots/tests__list_states.snap @@ -1,6 +1,5 @@ --- source: fud2/tests/tests.rs -snapshot_kind: text --- [ "calyx", @@ -12,6 +11,7 @@ snapshot_kind: text "firrtl", "firrtl-with-primitives", "flamegraph", + "jq", "mrxl", "primitive-uses-json", "sim", diff --git a/fud2/tests/snapshots/tests__test@plan_dat_to_jq.snap b/fud2/tests/snapshots/tests__test@plan_dat_to_jq.snap new file mode 100644 index 000000000..2c79949c8 --- /dev/null +++ b/fud2/tests/snapshots/tests__test@plan_dat_to_jq.snap @@ -0,0 +1,19 @@ +--- +source: fud2/tests/tests.rs +description: "emit plan: dat_to_jq" +--- +build-tool = fud2 +rule get-rsrc + command = $build-tool get-rsrc $out + +jq.expr = . +jq.exe = jq +jq.flags = +rule dat_to_jq_rule_1 + command = ${jq.exe} '${jq.expr}' ${jq.flags} $i0 > $o0 +build _dat_to_jq_rule_1.fake $o0: dat_to_jq_rule_1 $i0 + i0 = /input.ext + o0 = /output.ext + + +default /output.ext diff --git a/fud2/tests/tests.rs b/fud2/tests/tests.rs index d6268d004..ab334dab2 100644 --- a/fud2/tests/tests.rs +++ b/fud2/tests/tests.rs @@ -91,6 +91,7 @@ impl InstaTest for Plan { .merge(("xilinx.vitis", "/test/xilinx/vitis")) .merge(("xilinx.xrt", "/test/xilinx/xrt")) .merge(("dahlia", "/test/bin/dahlia")) + .merge(("jq.expr", ".")) .merge(("c0", "v1")); let run = Run::with_config(driver, self, config); let mut buf = vec![]; diff --git a/interp/tests/runt.toml b/interp/tests/runt.toml index e4e1922d3..298679eb6 100644 --- a/interp/tests/runt.toml +++ b/interp/tests/runt.toml @@ -16,10 +16,11 @@ expect_dir = "unit" name = "multi-comp" paths = ["multi-comp/*.futil"] cmd = """ -fud2 --from calyx --to dat \ +fud2 --from calyx --to jq \ --through cider \ -s cider.flags="--dump-registers" \ - {} | jq --sort-keys + -s jq.flags="--sort-keys" \ + {} """ timeout = 10 @@ -37,10 +38,11 @@ name = "complex" paths = ["complex/*.futil"] cmd = """ -fud2 --from calyx --to dat \ +fud2 --from calyx --to jq \ --through cider \ -s cider.flags="--dump-registers" \ - {} | jq --sort-keys + -s jq.flags="--sort-keys" \ + {} """ timeout = 10 expect_dir = "complex" @@ -49,11 +51,12 @@ expect_dir = "complex" name = "primitives" paths = ["primitives/*.futil"] cmd = """ -fud2 --from calyx --to dat \ +fud2 --from calyx --to jq \ --through cider \ -s calyx.args="--log off" \ -s cider.flags="--dump-registers" \ - {} | jq --sort-keys + -s jq.flags="--sort-keys" \ + {} """ timeout = 10 expect_dir = "primitives" @@ -71,10 +74,11 @@ expect_dir = "par-to-seq" name = "control" paths = ["control/*.futil", "control/iteration/*.futil"] cmd = """ -fud2 --from calyx --to dat \ +fud2 --from calyx --to jq \ --through cider \ -s cider.flags="--dump-registers" \ - {} | jq --sort-keys + -s jq.flags="--sort-keys" \ + {} """ timeout = 10 expect_dir = "control" @@ -83,7 +87,7 @@ expect_dir = "control" name = "invoke" paths = ["control/invoke/*.futil"] cmd = """ -fud2 {} --from calyx --to dat --through cider -s sim.data={}.data -s calyx.args="--log off" | jq --sort-keys +fud2 {} --from calyx --to jq --through cider -s sim.data={}.data -s calyx.args="--log off" -s jq.flags="--sort-keys" """ timeout = 10 @@ -91,7 +95,10 @@ timeout = 10 name = "invoke compiled" paths = ["control/invoke/*.futil"] cmd = """ -fud2 {} --from calyx --to dat --through cider -s cider.calyx-passes=" -p compile-invoke" -s sim.data={}.data -s calyx.args="--log off" | jq --sort-keys +fud2 {} --from calyx --to jq --through cider \ + -s cider.calyx-passes=" -p compile-invoke" \ + -s sim.data={}.data -s calyx.args="--log off" \ + -s jq.flags="--sort-keys" """ [[tests]] @@ -116,11 +123,12 @@ expect_dir = "tests/lowered/" name = "correctness dynamic" paths = ["../../tests/correctness/*.futil"] cmd = """ -fud2 --from calyx --to dat \ +fud2 --from calyx --to jq \ --through cider \ -s sim.data={}.data \ -s calyx.args="--log off" \ - {} | jq --sort-keys + -s jq.flags="--sort-keys" \ + {} """ [[tests]] @@ -134,13 +142,14 @@ cmd = """ name = "correctness lowered" paths = ["../../tests/correctness/*.futil"] cmd = """ -fud2 --from calyx --to dat \ +fud2 --from calyx --to jq \ --through cider \ -s sim.data={}.data \ -s calyx.args="--log off" \ -s cider.calyx-passes="-p all" \ -s cider.flags="--no-verify" \ - {} | jq --sort-keys + -s jq.flags="--sort-keys" \ + {} """ timeout = 60 @@ -149,23 +158,25 @@ timeout = 60 name = "correctness ref cells" paths = ["../../tests/correctness/ref-cells/*.futil"] cmd = """ -fud2 --from calyx --to dat \ +fud2 --from calyx --to jq \ --through cider \ -s sim.data={}.data \ -s calyx.args="--log off" \ - {} | jq --sort-keys + -s jq.flags="--sort-keys" \ + {} """ [[tests]] name = "correctness ref cells compiled" paths = ["../../tests/correctness/ref-cells/*.futil"] cmd = """ -fud2 --from calyx --to dat \ +fud2 --from calyx --to jq \ --through cider \ -s sim.data={}.data \ -s calyx.args="--log off" \ -s cider.calyx-passes=" -p compile-invoke" \ - {} | jq --sort-keys + -s jq.flags="--sort-keys" \ + {} """ [[tests]] @@ -176,45 +187,49 @@ paths = [ "../../tests/correctness/numeric-types/fixed-point/*.futil", ] cmd = """ -fud2 --from calyx --to dat \ +fud2 --from calyx --to jq \ --through cider \ -s sim.data={}.data \ -s calyx.args="--log off" \ -s cider.converter-flags="-r --legacy-quotes" \ - {} | jq --sort-keys + -s jq.flags="--sort-keys" \ + {} """ [[tests]] name = "[frontend] tcam testing" paths = ["../../tests/correctness/tcam/*.futil"] cmd = """ -fud2 --from calyx --to dat \ +fud2 --from calyx --to jq \ --through cider \ -s calyx.args="--log off" \ -s sim.data={}.data \ - {} | jq --sort-keys + -s jq.flags="--sort-keys" \ + {} """ [[tests]] name = "benchmark misc" paths = ["benchmarks/*.futil"] cmd = """ -fud2 --from calyx --to dat \ +fud2 --from calyx --to jq \ --through cider \ -s sim.data={}.data \ -s calyx.args="--log off" \ - {} | jq --sort-keys + -s jq.flags="--sort-keys" \ + {} """ [[tests]] name = "benchmark polybench" paths = ["benchmarks/polybench/*.fuse"] cmd = """ -fud2 --from dahlia --to dat \ +fud2 --from dahlia --to jq \ --through cider \ -s sim.data={}.data \ -s calyx.args="--log off" \ - {} | jq --sort-keys + -s jq.flags="--sort-keys" \ + {} """ timeout = 180