Skip to content

Commit 68e7e82

Browse files
authored
Put memories in the same directory as their parent (#8862)
By the time lower-to-hw runs, the directories have already been assigned. Colocate the memory module with its parent. Remove logic which would set the output directory to the testbench--this is not always right. This allows memories to be emitted into layer specific directories.
1 parent c97743f commit 68e7e82

File tree

2 files changed

+28
-5
lines changed

2 files changed

+28
-5
lines changed

lib/Conversion/FIRRTLToHW/LowerToHW.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3498,11 +3498,15 @@ LogicalResult FIRRTLLowering::visitDecl(MemOp op) {
34983498
memSummary.readUnderWrite, memSummary.writeUnderWrite, op.getNameAttr(),
34993499
op.getInnerSymAttr(), memInit, op.getPrefixAttr(), Attribute{});
35003500

3501-
// If the module is outside the DUT, set the appropriate output directory for
3502-
// the memory.
3503-
if (!circuitState.isInDUT(theModule))
3504-
if (auto testBenchDir = circuitState.getTestBenchDirectory())
3505-
memDecl.setOutputFileAttr(testBenchDir);
3501+
if (auto parent = op->getParentOfType<hw::HWModuleOp>()) {
3502+
if (auto file = parent->getAttrOfType<hw::OutputFileAttr>("output_file")) {
3503+
auto dir = file;
3504+
if (!file.isDirectory())
3505+
dir = hw::OutputFileAttr::getAsDirectory(builder.getContext(),
3506+
file.getDirectory());
3507+
memDecl.setOutputFileAttr(dir);
3508+
}
3509+
}
35063510

35073511
// Memories return multiple structs, one for each port, which means we
35083512
// have two layers of type to split apart.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
; RUN: firtool %s | FileCheck %s
2+
3+
FIRRTL version 5.0.0
4+
circuit Top:
5+
layer Verification, bind, "verification":
6+
7+
public module Top:
8+
input c : Clock
9+
input i : UInt<1>
10+
input j : UInt<1>
11+
input d : UInt<1>
12+
layerblock Verification:
13+
cmem memory : UInt<1>[2]
14+
infer mport rd = memory[i], c
15+
infer mport wr = memory[j], c
16+
connect wr, d
17+
assert(c, rd, UInt<1>(1), "hello")
18+
19+
; CHECK: ----- 8< ----- FILE "verification{{[/\]}}memory_2x1.sv" ----- 8< -----

0 commit comments

Comments
 (0)