Skip to content
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,8 @@ final case class Instance[+A] private[chisel3] (private[chisel3] val underlying:
}

/** Returns the definition of this Instance */
override def toDefinition: Definition[A] = {
val result = new Definition(Proto(proto))
// Because we are creating a new Definition, we should update our Builder.definitions
if (Builder.inContext && !Builder.definitions.view.map(_.proto).contains(result.proto)) {
Builder.definitions += result
}
result
}
override def toInstance: Instance[A] = this
override def toDefinition: Definition[A] = new Definition(Proto(proto))
override def toInstance: Instance[A] = this
private[chisel3] def copy[T](underlying: Underlying[T]) = new Instance(underlying)

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -945,59 +945,4 @@ class DefinitionSpec extends AnyFunSpec with Matchers with FileCheck {
)
}
}
describe("(9): Calling .toDefinition should update Builder.definitions") {
it("(9.a): calling .toDefinition from another definition's child Instance should work as expected") {
class Bar extends RawModule {
val a = WireInit(false.B)
}
@instantiable
class Foo extends RawModule {
@public val bar = Module(new Bar)
}
class Baz(d: Definition[Foo]) extends RawModule {
val bar = Instance(d.bar.toDefinition)
}
ChiselStage
.emitCHIRRTL(
{
val d = Definition(new Foo)
new Baz(d)
},
Array("--full-stacktrace")
)
.fileCheck()(
"""|CHECK: module Bar :
|CHECK: module Baz :
|""".stripMargin
)
}
it("(9.b): calling .toDefinition twice from anther definition's child Instance should work as expected") {
class Bar extends RawModule {
val a = WireInit(false.B)
}
@instantiable
class Foo extends RawModule {
@public val bar = Module(new Bar)
}
class Baz(d: Definition[Foo]) extends RawModule {
val bar = Instance(d.bar.toDefinition)
val bar2 = Instance(d.bar.toDefinition)
}
val x = ChiselStage
.emitCHIRRTL(
{
val d = Definition(new Foo)
new Baz(d)
},
Array("--full-stacktrace")
)
.fileCheck()(
"""|CHECK: module Bar :
|CHECK-NOT: module Bar_
|CHECK: module Baz :
|""".stripMargin
)
}
}

}
Loading