diff --git a/calyx-opt/src/passes/synthesis_papercut.rs b/calyx-opt/src/passes/synthesis_papercut.rs index 186ad25ccb..d215122baf 100644 --- a/calyx-opt/src/passes/synthesis_papercut.rs +++ b/calyx-opt/src/passes/synthesis_papercut.rs @@ -84,7 +84,7 @@ impl Visitor for SynthesisPapercut { if self.memories.contains(parent) { let has_external = cell.get_attribute(ir::BoolAttr::External); - if has_external.is_none() { + if has_external.is_none() && !cell.is_reference() { return Some(cell.name()); } } diff --git a/tests/passes/papercut-ref-read-only.expect b/tests/passes/papercut-ref-read-only.expect new file mode 100644 index 0000000000..ba1db3aa9b --- /dev/null +++ b/tests/passes/papercut-ref-read-only.expect @@ -0,0 +1,31 @@ +import "primitives/memories/comb.futil"; +component main(@go go: 1, @clk clk: 1, @reset reset: 1) -> (@done done: 1) { + cells { + @external mem_0 = comb_mem_d1(32, 4, 2); + read_only_instance = read_only(); + } + wires {} + control { + seq { + invoke read_only_instance[ref_mem_0 = mem_0]()(); + } + } +} +component read_only(@go go: 1, @clk clk: 1, @reset reset: 1) -> (@done done: 1) { + cells { + ref ref_mem_0 = comb_mem_d1(32, 4, 2); + } + wires { + group read_data { + ref_mem_0.write_en = 1'd1; + ref_mem_0.write_data = 32'd3; + ref_mem_0.addr0 = 2'd0; + read_data[done] = ref_mem_0.done; + } + } + control { + seq { + read_data; + } + } +} diff --git a/tests/passes/papercut-ref-read-only.futil b/tests/passes/papercut-ref-read-only.futil new file mode 100644 index 0000000000..e76a3adc76 --- /dev/null +++ b/tests/passes/papercut-ref-read-only.futil @@ -0,0 +1,36 @@ +// -p papercut + +import "primitives/memories/comb.futil"; + +component main(@go go: 1, @clk clk: 1, @reset reset: 1) -> (@done done: 1) { + cells { + @external mem_0 = comb_mem_d1(32, 4, 2); + read_only_instance = read_only(); + } + wires { + } + control { + seq { + invoke read_only_instance[ref_mem_0 = mem_0]()(); + } + } +} + +component read_only(@go go: 1, @clk clk: 1, @reset reset: 1) -> (@done done: 1) { + cells { + ref ref_mem_0 = comb_mem_d1(32, 4, 2); + } + wires { + group read_data { + ref_mem_0.write_en = 1'b1; + ref_mem_0.write_data = 32'd3; + ref_mem_0.addr0 = 2'b0; + read_data[done] = ref_mem_0.done; + } + } + control { + seq { + read_data; + } + } +} \ No newline at end of file