Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add suggestName method to HasTarget #3881

Merged
merged 4 commits into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion core/src/main/scala/chisel3/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -414,12 +414,19 @@ package object chisel3 {

final val deprecatedPublicAPIMsg = "APIs in chisel3.internal are not intended to be public"

/** Contains universal methods for target accesses.
/** Exposes target information and suggestName functionality of a NamedComponent.
*/
sealed trait HasTarget {
def toTarget: ReferenceTarget
def toAbsoluteTarget: ReferenceTarget
def toRelativeTarget(root: Option[BaseModule]): ReferenceTarget

/** Exposes the suggestName method of the NamedComponent so users can
* provide a seed to influence the name generation of this component.
*
* @param seed seed for the name of this component
*/
def suggestName(seed: String): Unit
}

object HasTarget {
Expand All @@ -431,6 +438,8 @@ package object chisel3 {
def toTarget = t.toTarget
def toAbsoluteTarget = t.toAbsoluteTarget
def toRelativeTarget(root: Option[BaseModule]) = t.toRelativeTarget(root)

def suggestName(seed: String): Unit = t.suggestName(seed)
}

}
Expand Down
28 changes: 28 additions & 0 deletions src/test/scala/chiselTests/util/SRAMSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,32 @@ class SRAMSpec extends ChiselFlatSpec {
dummyAnno should be(Some("~Top|Top>sram_mem"))
}

it should "Get emitted with a custom name when one is suggested" in {

class Top extends Module {
val sramInterface = SRAM(
size = 32,
tpe = UInt(8.W),
numReadPorts = 0,
numWritePorts = 0,
numReadwritePorts = 1
)
require(sramInterface.underlying.nonEmpty)
sramInterface.underlying.get.suggestName("carrot")
annotate(new ChiselAnnotation {
override def toFirrtl: Annotation = DummyAnno(sramInterface.underlying.get.toTarget)
})
}
val (chirrtlCircuit, annos) = getFirrtlAndAnnos(new Top)
val chirrtl = chirrtlCircuit.serialize
chirrtl should include("module Top :")
chirrtl should include("smem carrot : UInt<8> [32]")
chirrtl should include(
"wire sramInterface : { readPorts : { flip address : UInt<5>, flip enable : UInt<1>, data : UInt<8>}[0], writePorts : { flip address : UInt<5>, flip enable : UInt<1>, flip data : UInt<8>}[0], readwritePorts : { flip address : UInt<5>, flip enable : UInt<1>, flip isWrite : UInt<1>, readData : UInt<8>, flip writeData : UInt<8>}[1]}"
)

val dummyAnno = annos.collectFirst { case DummyAnno(t) => (t.toString) }
dummyAnno should be(Some("~Top|Top>carrot"))
}

}
Loading