diff options
| author | Jack Koenig | 2021-06-23 17:11:22 -0700 |
|---|---|---|
| committer | Jack Koenig | 2021-06-28 14:08:21 -0700 |
| commit | d3e13ce24956871d2f0fd01ca3a7d89317e3db68 (patch) | |
| tree | 9db523d08e6725d78421ab84624facf5a5258093 /core/src/main/scala/chisel3/internal | |
| parent | 6a806918b15d78613638c8d860538adbef9425b1 (diff) | |
Fix CloneModuleAsRecord support for .toTarget
Diffstat (limited to 'core/src/main/scala/chisel3/internal')
| -rw-r--r-- | core/src/main/scala/chisel3/internal/Builder.scala | 2 | ||||
| -rw-r--r-- | core/src/main/scala/chisel3/internal/firrtl/Converter.scala | 19 | ||||
| -rw-r--r-- | core/src/main/scala/chisel3/internal/firrtl/IR.scala | 13 |
3 files changed, 27 insertions, 7 deletions
diff --git a/core/src/main/scala/chisel3/internal/Builder.scala b/core/src/main/scala/chisel3/internal/Builder.scala index e1e4d460..35c4bdf9 100644 --- a/core/src/main/scala/chisel3/internal/Builder.scala +++ b/core/src/main/scala/chisel3/internal/Builder.scala @@ -84,7 +84,7 @@ trait InstanceId { private[chisel3] trait HasId extends InstanceId { private[chisel3] def _onModuleClose: Unit = {} - private[chisel3] val _parent: Option[BaseModule] = Builder.currentModule + private[chisel3] var _parent: Option[BaseModule] = Builder.currentModule private[chisel3] val _id: Long = Builder.idGen.next diff --git a/core/src/main/scala/chisel3/internal/firrtl/Converter.scala b/core/src/main/scala/chisel3/internal/firrtl/Converter.scala index 40d3691c..093d4848 100644 --- a/core/src/main/scala/chisel3/internal/firrtl/Converter.scala +++ b/core/src/main/scala/chisel3/internal/firrtl/Converter.scala @@ -24,16 +24,24 @@ private[chisel3] object Converter { case Percent => ("%%", List.empty) } + private def reportInternalError(msg: String): Nothing = { + val link = "https://github.com/chipsalliance/chisel3/issues/new" + val fullMsg = s"Internal Error! $msg This is a bug in Chisel, please file an issue at '$link'" + throwException(fullMsg) + } + def getRef(id: HasId, sourceInfo: SourceInfo): Arg = id.getOptionRef.getOrElse { val module = id._parent.map(m => s" '$id' was defined in module '$m'.").getOrElse("") val loc = sourceInfo.makeMessage(" " + _) - val link = "https://github.com/chipsalliance/chisel3/issues/new" - val msg = s"Internal error! Could not get ref for '$id'$loc!$module " + - s"This is a bug in Chisel, please file an issue at '$link'." - throwException(msg) + reportInternalError(s"Could not get ref for '$id'$loc!$module") } + private def clonedModuleIOError(mod: BaseModule, name: String, sourceInfo: SourceInfo): Nothing = { + val loc = sourceInfo.makeMessage(" " + _) + reportInternalError(s"Trying to convert a cloned IO of $mod inside of $mod itself$loc!") + } + def convert(info: SourceInfo): fir.Info = info match { case _: NoSourceInfo => fir.NoInfo case SourceLine(fn, line, col) => fir.FileInfo(fir.StringLit(s"$fn $line:$col")) @@ -65,6 +73,9 @@ private[chisel3] object Converter { case ModuleIO(mod, name) => if (mod eq ctx.id) fir.Reference(name, fir.UnknownType) else fir.SubField(fir.Reference(getRef(mod, info).name, fir.UnknownType), name, fir.UnknownType) + case ModuleCloneIO(mod, name) => + if (mod eq ctx.id) clonedModuleIOError(mod, name, info) + else fir.Reference(name) case u @ ULit(n, UnknownWidth()) => fir.UIntLiteral(n, fir.IntWidth(u.minWidth)) case ULit(n, w) => diff --git a/core/src/main/scala/chisel3/internal/firrtl/IR.scala b/core/src/main/scala/chisel3/internal/firrtl/IR.scala index 5dc72a43..1d77802b 100644 --- a/core/src/main/scala/chisel3/internal/firrtl/IR.scala +++ b/core/src/main/scala/chisel3/internal/firrtl/IR.scala @@ -165,9 +165,18 @@ case class ModuleIO(mod: BaseModule, name: String) extends Arg { override def fullName(ctx: Component): String = if (mod eq ctx.id) name else s"${mod.getRef.name}.$name" } -case class Slot(imm: Node, name: String) extends Arg { +// For use with CloneModuleAsRecord +// Note that `name` is the name of the module instance whereas in ModuleIO it's the name of the port +// The names of ports inside of a ModuleCloneIO are the names of the Slots +case class ModuleCloneIO(mod: BaseModule, name: String) extends Arg { override def fullName(ctx: Component): String = - if (imm.fullName(ctx).isEmpty) name else s"${imm.fullName(ctx)}.${name}" + if (mod eq ctx.id) "" else name +} +case class Slot(imm: Node, name: String) extends Arg { + override def fullName(ctx: Component): String = { + val immName = imm.fullName(ctx) + if (immName.isEmpty) name else s"$immName.$name" + } } case class Index(imm: Arg, value: Arg) extends Arg { def name: String = s"[$value]" |
