Skip to content

Commit

Permalink
Readd external-to-ref pass when wrapping with axi.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
nathanielnrn committed Dec 31, 2024
1 parent aa3c6d3 commit 457ee7c
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions fud2/scripts/axi.rhai
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand All @@ -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",
);
}

Expand All @@ -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], []);
}
Expand Down

0 comments on commit 457ee7c

Please sign in to comment.