Skip to content

Commit

Permalink
Add DeletedPath for targets that no longer exist. (#3937)
Browse files Browse the repository at this point in the history
(cherry picked from commit 0e91187)
  • Loading branch information
mikeurbach authored and mergify[bot] committed Mar 15, 2024
1 parent e36bb51 commit a2cbf2f
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
24 changes: 20 additions & 4 deletions core/src/main/scala/chisel3/properties/Path.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ import firrtl.ir.{PathPropertyLiteral}
/** Represent a Path type for referencing a hardware instance or member in a Property[Path]
*/
sealed abstract class Path {
private[chisel3] def convert(): PathPropertyLiteral
}

/** Represent a Path type with a known target.
*/
private[properties] sealed abstract class TargetPath extends Path {
private[chisel3] def toTarget(): IsMember
private[chisel3] def isMemberPath: Boolean

Expand All @@ -32,14 +38,20 @@ sealed abstract class Path {
}
}

/** Represent a Path type for a target that no longer exists.
*/
private[properties] object DeletedPath extends Path {
private[chisel3] def convert(): PathPropertyLiteral = PathPropertyLiteral("OMDeleted:")
}

object Path {

/** Construct a Path that refers to a Module
*/
def apply(module: BaseModule): Path = apply(module, false)
def apply(module: BaseModule, isMemberPath: Boolean): Path = {
val _isMemberPath = isMemberPath // avoid name shadowing below
new Path {
new TargetPath {
def toTarget(): IsMember = module.toAbsoluteTarget
def isMemberPath: Boolean = _isMemberPath
}
Expand All @@ -50,7 +62,7 @@ object Path {
def apply(data: Data): Path = apply(data, false)
def apply(data: Data, isMemberPath: Boolean): Path = {
val _isMemberPath = isMemberPath // avoid name shadowing below
new Path {
new TargetPath {
def toTarget(): IsMember = data.toAbsoluteTarget
def isMemberPath: Boolean = _isMemberPath
}
Expand All @@ -61,7 +73,7 @@ object Path {
def apply(mem: MemBase[_]): Path = apply(mem, false)
def apply(mem: MemBase[_], isMemberPath: Boolean): Path = {
val _isMemberPath = isMemberPath // avoid name shadowing below
new Path {
new TargetPath {
def toTarget(): IsMember = mem.toAbsoluteTarget
def isMemberPath: Boolean = _isMemberPath
}
Expand All @@ -72,9 +84,13 @@ object Path {
def apply(target: IsMember): Path = apply(target, false)
def apply(target: IsMember, isMemberPath: Boolean): Path = {
val _isMemberPath = isMemberPath // avoid name shadowing below
new Path {
new TargetPath {
def toTarget(): IsMember = target
def isMemberPath: Boolean = _isMemberPath
}
}

/** Construct a Path for a target that no longer exists.
*/
def deleted: Path = DeletedPath
}
11 changes: 11 additions & 0 deletions src/test/scala/chiselTests/properties/PropertySpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,17 @@ class PropertySpec extends ChiselFlatSpec with MatchesAndOmits {
)()
}

it should "support deleted paths when requested" in {
val chirrtl = ChiselStage.emitCHIRRTL(new RawModule {
val propOut = IO(Output(Property[Path]()))
propOut := Property(Path.deleted)
})

matchesAndOmits(chirrtl)(
"""propassign propOut, path("OMDeleted:")"""
)()
}

it should "support Properties on an ExtModule" in {
// See: https://github.com/chipsalliance/chisel/issues/3509
class Bar extends experimental.ExtModule {
Expand Down

0 comments on commit a2cbf2f

Please sign in to comment.