From 457ee7c3eec11e1eb4d8d6e9312039e750819a8b Mon Sep 17 00:00:00 2001 From: Nathaniel Navarro Date: Tue, 31 Dec 2024 13:02:34 +0200 Subject: [PATCH] Readd external-to-ref pass when wrapping with axi. This ensures output calyx files are valid (otherwise we might pass in concrete cells to non-ref cells). Also sticking with the more complex sed which removes everything until the first `component main` line, as opposed to just removing `^import` lines to avoid polluting files with `external` blocks --- fud2/scripts/axi.rhai | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/fud2/scripts/axi.rhai b/fud2/scripts/axi.rhai index b9a647730..b0705610d 100644 --- a/fud2/scripts/axi.rhai +++ b/fud2/scripts/axi.rhai @@ -18,10 +18,9 @@ op( }, ); -export let wrapper_setup = wrapper_setup; fn wrapper_setup(e) { // Define a `gen-axi` rule that invokes our Python code generator program. - // For now point to standalone axi_generator.py. Can maybe turn this into a rsrc file? + // For now point to standalone axi-generator.py. Can maybe turn this into a rsrc file? let dynamic = e.config_constrained_or("dynamic", ["true", "false"], "false"); let generator_path = if dynamic == "true" { @@ -37,9 +36,11 @@ fn wrapper_setup(e) { // Define a simple `combine` rule that just concatenates any numer of files. e.rule("combine", "cat $in > $out"); + // Removes imports and `external` primitive blocks added by passes by removing + // everything up until the first line containing `component main` e.rule( "remove-imports", - "sed '/^import/d' $in > $out", + "sed '1,/component main/{/component main/!d; }' $in > $out", ); } @@ -52,17 +53,22 @@ fn replace_ext(path, new_ext) { return `${path}.${new_ext}`; } } + fn axi_wrapped_op(e, input, output) { let file_name = input.split("/")[-1]; let tmp_yxi = replace_ext(file_name, "yxi"); e.build_cmd([tmp_yxi], "yxi", [input], []); + let refified_calyx = replace_ext(`refified_${file_name}`, "futil"); + e.build_cmd([refified_calyx], "calyx-pass", [input], []); + e.arg("pass", "external-to-ref"); + let axi_wrapper = "axi_wrapper.futil"; e.build_cmd([axi_wrapper], "gen-axi", [tmp_yxi], []); - let no_imports_calyx = `no_imports_${file_name}`; - e.build_cmd([no_imports_calyx], "remove-imports", [input], []); + let no_imports_calyx = `no_imports_${refified_calyx}`; + e.build_cmd([no_imports_calyx], "remove-imports", [refified_calyx], []); e.build_cmd([output], "combine", [axi_wrapper, no_imports_calyx], []); }