Skip to content

Commit

Permalink
Support creation of Paths from HasTargets (#4455)
Browse files Browse the repository at this point in the history
  • Loading branch information
debs-sifive authored Oct 9, 2024
1 parent 90a8d39 commit fddf41a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
10 changes: 10 additions & 0 deletions core/src/main/scala/chisel3/properties/Path.scala
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,16 @@ object Path {
}
}

/** Construct a Path that refers to a HasTarget
*/
def apply(hasTarget: HasTarget): Path = {
new TargetPath {
private val scope = Module.currentModule
def toTarget(): IsMember = hasTarget.toRelativeTarget(scope)
def isMemberPath: Boolean = false
}
}

/** Construct a Path from a target
*/
def apply(target: IsMember): Path = apply(target, false)
Expand Down
10 changes: 7 additions & 3 deletions src/test/scala/chiselTests/properties/PropertySpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -164,17 +164,19 @@ class PropertySpec extends ChiselFlatSpec with MatchesAndOmits {
}

it should "support path as a Property literal" in {
val chirrtl = ChiselStage.emitCHIRRTL(new RawModule {
val chirrtl = ChiselStage.emitCHIRRTL(new Module {
val propOutA = IO(Output(Property[Path]()))
val propOutB = IO(Output(Property[Path]()))
val propOutC = IO(Output(Property[Path]()))
val propOutD = IO(Output(Property[Path]()))
val propOutE = IO(Output(Property[Path]()))
val propOutF = IO(Output(Property[Path]()))
override def desiredName = "Top"
val inst = Module(new RawModule {
val inst = Module(new Module {
val localPropOut = IO(Output(Property[Path]()))
val data = WireInit(false.B)
val mem = SyncReadMem(1, Bool())
val sram = chisel3.util.SRAM(1, Bool(), 1, 1, 0)
localPropOut := Property(Path(data))
override def desiredName = "Foo"
})
Expand All @@ -183,14 +185,16 @@ class PropertySpec extends ChiselFlatSpec with MatchesAndOmits {
propOutC := Property(inst.mem)
propOutD := Property(this)
propOutE := inst.localPropOut
propOutF := Property(Path(inst.sram.underlying.get))
})
matchesAndOmits(chirrtl)(
"""propassign localPropOut, path("OMReferenceTarget:~Top|Foo>data")""",
"""propassign propOutA, path("OMInstanceTarget:~Top|Top/inst:Foo")""",
"""propassign propOutB, path("OMReferenceTarget:~Top|Top/inst:Foo>data")""",
"""propassign propOutC, path("OMReferenceTarget:~Top|Top/inst:Foo>mem")""",
"""propassign propOutD, path("OMInstanceTarget:~Top|Top")""",
"""propassign propOutE, inst.localPropOut"""
"""propassign propOutE, inst.localPropOut""",
"""propassign propOutF, path("OMReferenceTarget:~Top|Top/inst:Foo>sram_sram")"""
)()
}

Expand Down

0 comments on commit fddf41a

Please sign in to comment.