Skip to content

Commit efac93e

Browse files
authored
Merge pull request #4817 from chipsalliance/mergify/bp/6.x/pr-4816
Deprecate ChiselStage.convert, replace with elaborate (backport #4816)
2 parents ce0757e + a7f796b commit efac93e

File tree

11 files changed

+58
-27
lines changed

11 files changed

+58
-27
lines changed

core/src/main/scala/chisel3/experimental/hierarchy/core/Definition.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ final case class Definition[+A] private[chisel3] (private[chisel3] val underlyin
6969
object Definition extends SourceInfoDoc {
7070
implicit class DefinitionBaseModuleExtensions[T <: BaseModule](d: Definition[T]) {
7171

72+
/** The name of the Module definition */
73+
def name: String = d.proto.name
74+
7275
/** If this is an instance of a Module, returns the toTarget of this instance
7376
* @return target of this instance
7477
*/

docs/src/cookbooks/hierarchy.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ class Top extends Module {
164164
```scala mdoc:passthrough
165165
println("```")
166166
// Run elaboration so that the println above shows up
167-
circt.stage.ChiselStage.convert(new Top)
167+
circt.stage.ChiselStage.elaborate(new Top)
168168
println("```")
169169
```
170170

docs/src/explanations/chisel-type-vs-scala-type.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,7 @@ class MyModule(gen: () => MyBundle) extends Module {
6060

6161
```scala mdoc:invisible
6262
// Just here to compile check the above
63-
def elaborate(module: => chisel3.RawModule) = {
64-
circt.stage.ChiselStage.convert(module)
65-
}
63+
import circt.stage.ChiselStage.elaborate
6664
elaborate(new MyModule(() => new MyBundle(3)))
6765
```
6866

integration-tests/src/test/scala/chiselTest/util/SparseVecSpec.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ class SparseVecSpec extends ChiselFlatSpec with Utils {
341341

342342
"SparseVec error behavior" should "disallow indices large than the size" in {
343343
val exception = intercept[IllegalArgumentException] {
344-
ChiselStage.convert(new Module {
344+
ChiselStage.elaborate(new Module {
345345
new SparseVec(1, UInt(1.W), Seq(0, 1))
346346
})
347347
}
@@ -350,7 +350,7 @@ class SparseVecSpec extends ChiselFlatSpec with Utils {
350350

351351
it should "disallow non-unique indices" in {
352352
val exception = intercept[ChiselException] {
353-
ChiselStage.convert(new Module {
353+
ChiselStage.elaborate(new Module {
354354
new SparseVec(2, UInt(1.W), Seq(0, 0))
355355
})
356356
}
@@ -359,7 +359,7 @@ class SparseVecSpec extends ChiselFlatSpec with Utils {
359359

360360
it should "disallow a SparseVec write" in {
361361
val exception = intercept[ChiselException] {
362-
ChiselStage.convert(new Module {
362+
ChiselStage.elaborate(new Module {
363363
val vec = Wire(new SparseVec(2, UInt(1.W), Seq(0, 1)))
364364
vec(0.U(1.W)) := 1.U
365365
})

src/main/scala/circt/stage/ChiselStage.scala

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,27 @@ object ChiselStage {
6767
)
6868
)
6969

70+
/** Run elaboration and return the `ElaboratedCircuit`
71+
*
72+
* @param gen a call-by-name Chisel module
73+
* @param args additional command line arguments to pass to Chisel
74+
* @return the `ElaboratedCircuit`
75+
*/
76+
def elaborate(
77+
gen: => RawModule,
78+
args: Array[String] = Array.empty
79+
): ElaboratedCircuit = {
80+
val annos = Seq(
81+
ChiselGeneratorAnnotation(() => gen),
82+
CIRCTTargetAnnotation(CIRCTTarget.CHIRRTL)
83+
) ++ (new Shell("circt")).parse(args)
84+
85+
phase
86+
.transform(annos)
87+
.collectFirst { case a: ChiselCircuitAnnotation => a.elaboratedCircuit }
88+
.get
89+
}
90+
7091
/** Elaborate a Chisel circuit into a CHIRRTL string */
7192
def emitCHIRRTL(
7293
gen: => RawModule,
@@ -110,6 +131,7 @@ object ChiselStage {
110131
*
111132
* @param gen a call-by-name Chisel module
112133
*/
134+
@deprecated("Use elaborate or one of the emit* methods instead", "Chisel 6.8.0")
113135
def convert(
114136
gen: => RawModule,
115137
args: Array[String] = Array.empty

src/test/scala/chisel3/experimental/dataview/ReifySpec.scala

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ class ReifySpec extends AnyFunSpec {
8080
describe("dataview.reify") {
8181

8282
it("should reify single targets and identity for all non-view Elements") {
83-
ChiselStage.convert(new Module {
83+
ChiselStage.elaborate(new Module {
8484
val wires = (new AllElementsBundle).getElements.map(Wire(_))
8585

8686
// .getElements returns Data so we have to match that these are Elements.
@@ -94,7 +94,7 @@ class ReifySpec extends AnyFunSpec {
9494
}
9595

9696
it("should reify single targets and identity for all non-view Elements even as children of an Aggregate") {
97-
ChiselStage.convert(new Module {
97+
ChiselStage.elaborate(new Module {
9898
val bundle = IO(new AllElementsBundle)
9999

100100
// .getElements returns Data so we have to match that these are Elements.
@@ -108,7 +108,7 @@ class ReifySpec extends AnyFunSpec {
108108
}
109109

110110
it("should reify single targets and identity for all Elements in an Aggregate identity-view") {
111-
ChiselStage.convert(new Module {
111+
ChiselStage.elaborate(new Module {
112112
val bundle = IO(new AllElementsBundle)
113113
val view = bundle.viewAs[AllElementsBundle]
114114

@@ -126,7 +126,7 @@ class ReifySpec extends AnyFunSpec {
126126
}
127127

128128
it("should reify single targets and identity for all Elements in an Aggregate non-identity and non-1-1 view") {
129-
ChiselStage.convert(new Module {
129+
ChiselStage.elaborate(new Module {
130130
val wires = (new AllElementsBundle).getElements.map(Wire(_))
131131
val view = wires.viewAs[AllElementsBundle]
132132

@@ -144,7 +144,7 @@ class ReifySpec extends AnyFunSpec {
144144
}
145145

146146
it("should distinguish identity views from single-target views (even if the single target is the same type!") {
147-
ChiselStage.convert(new Module {
147+
ChiselStage.elaborate(new Module {
148148
val vec = IO(Vec(2, UInt(8.W)))
149149
val view = vec.viewAs[ReversedVec[UInt]]
150150

@@ -164,7 +164,7 @@ class ReifySpec extends AnyFunSpec {
164164
}
165165

166166
it("should correctly reify single-target views despite complex hierarchy") {
167-
ChiselStage.convert(new Module {
167+
ChiselStage.elaborate(new Module {
168168
val in0 = IO(Input(UInt(8.W)))
169169
val in1 = IO(Input(new TargetBundle))
170170
val view = (in0, in1).viewAs[ViewBundle]
@@ -191,7 +191,7 @@ class ReifySpec extends AnyFunSpec {
191191
class MyModule extends RawModule {
192192
@public val ios = (new AllElementsBundle).getElements.map(IO(_))
193193
}
194-
ChiselStage.convert(new RawModule {
194+
ChiselStage.elaborate(new RawModule {
195195

196196
val child = Instantiate(new MyModule)
197197

@@ -210,7 +210,7 @@ class ReifySpec extends AnyFunSpec {
210210
class MyModule extends RawModule {
211211
@public val bundle = IO(new AllElementsBundle)
212212
}
213-
ChiselStage.convert(new Module {
213+
ChiselStage.elaborate(new Module {
214214
val child = Instantiate(new MyModule)
215215

216216
// .getElements returns Data so we have to match that these are Elements.
@@ -229,7 +229,7 @@ class ReifySpec extends AnyFunSpec {
229229
@public val bundle = IO(new AllElementsBundle)
230230
@public val view = bundle.viewAs[AllElementsBundle]
231231
}
232-
ChiselStage.convert(new Module {
232+
ChiselStage.elaborate(new Module {
233233
val child = Instantiate(new MyModule)
234234

235235
_reifyIdentityView(child.view) should be(Some(child.bundle))
@@ -251,7 +251,7 @@ class ReifySpec extends AnyFunSpec {
251251
@public val wires = (new AllElementsBundle).getElements.map(Wire(_))
252252
@public val view = wires.viewAs[AllElementsBundle]
253253
}
254-
ChiselStage.convert(new Module {
254+
ChiselStage.elaborate(new Module {
255255
val child = Instantiate(new MyModule)
256256

257257
_reifyIdentityView(child.view) should be(None)
@@ -273,7 +273,7 @@ class ReifySpec extends AnyFunSpec {
273273
@public val vec = IO(Vec(2, UInt(8.W)))
274274
@public val view = vec.viewAs[ReversedVec[UInt]]
275275
}
276-
ChiselStage.convert(new Module {
276+
ChiselStage.elaborate(new Module {
277277
val child = Instantiate(new MyModule)
278278
val vec = child.vec
279279
val view = child.view
@@ -300,7 +300,7 @@ class ReifySpec extends AnyFunSpec {
300300
@public val in1 = IO(Input(new TargetBundle))
301301
@public val view = (in0, in1).viewAs[ViewBundle]
302302
}
303-
ChiselStage.convert(new Module {
303+
ChiselStage.elaborate(new Module {
304304
val child = Instantiate(new MyModule)
305305
val in0 = child.in0
306306
val in1 = child.in1

src/test/scala/chiselTests/CloneModuleSpec.scala

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ package chiselTests
44

55
import chisel3._
66
import circt.stage.ChiselStage
7+
import chisel3.aop.Select
78
import chisel3.util.{log2Ceil, Decoupled, DeqIO, EnqIO, Queue, QueueIO}
89
import chisel3.experimental.CloneModuleAsRecord
910
import chisel3.testers.BasicTester
@@ -93,8 +94,9 @@ class CloneModuleSpec extends ChiselPropSpec {
9394
}
9495

9596
property("QueueClone's cloned queues should share the same module") {
96-
val c = ChiselStage.convert(new QueueClone)
97-
assert(c.modules.length == 2)
97+
val c = ChiselStage.elaborate(new QueueClone)
98+
val modules = Select.allDefinitionsOf[RawModule](c.topDefinition)
99+
assert(modules.length == 2)
98100
}
99101

100102
property("Clone of Module should simulate correctly") {
@@ -104,14 +106,15 @@ class CloneModuleSpec extends ChiselPropSpec {
104106
}
105107

106108
property("Clones of Modules should share the same module") {
107-
val c = ChiselStage.convert(new QueueClone(multiIO = true))
108-
assert(c.modules.length == 3)
109+
val c = ChiselStage.elaborate(new QueueClone(multiIO = true))
110+
val modules = Select.allDefinitionsOf[RawModule](c.topDefinition)
111+
assert(modules.length == 3)
109112
}
110113

111114
property("Cloned Modules should annotate correctly") {
112115
// Hackily get the actually Module object out
113116
var mod: CloneModuleAsRecordAnnotate = null
114-
val res = ChiselStage.convert {
117+
val res = ChiselStage.elaborate {
115118
mod = new CloneModuleAsRecordAnnotate
116119
mod
117120
}

src/test/scala/chiselTests/Direction.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import chisel3._
88
import chisel3.experimental.{ExtModule, OpaqueType}
99

1010
import circt.stage.ChiselStage
11+
import scala.annotation.nowarn
1112
import scala.collection.immutable.SeqMap
1213

1314
class DirectionedBundle extends Bundle {
@@ -44,6 +45,7 @@ class TopDirectionOutput extends Module {
4445
io.out := 117.U
4546
}
4647

48+
@nowarn("msg=method convert in object ChiselStage is deprecated")
4749
class DirectionSpec extends ChiselPropSpec with Matchers with Utils {
4850

4951
//TODO: In Chisel3 these are actually FIRRTL errors. Remove from tests?

src/test/scala/chiselTests/ReadOnlySpec.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ class ReadOnlySpec extends ChiselFlatSpec with Utils {
8383

8484
def check(m: => RawModule)(implicit pos: Position): Unit = {
8585
val e = the[ChiselException] thrownBy {
86-
ChiselStage.convert(m, Array("--throw-on-first-error"))
86+
ChiselStage.elaborate(m, Array("--throw-on-first-error"))
8787
}
8888
e.getMessage should include("Cannot connect to read-only value")
8989
}
@@ -263,7 +263,7 @@ class ReadOnlySpec extends ChiselFlatSpec with Utils {
263263
op(out, z)
264264
})
265265
// But note that it's fine if x (not flipped) is readOnly.
266-
ChiselStage.convert(new RawModule {
266+
ChiselStage.elaborate(new RawModule {
267267
val x, y = Wire(UInt(8.W))
268268
val z = (x.readOnly, y).viewAs[BidirectionalBundle]
269269
val out = IO(new BidirectionalBundle)

src/test/scala/chiselTests/experimental/hierarchy/InstantiateSpec.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import chisel3.experimental.hierarchy._
1010
import circt.stage.ChiselStage.convert
1111
import chisel3.experimental.{ExtModule, IntrinsicModule}
1212

13+
import scala.annotation.nowarn
14+
1315
// Note, the instantiable classes must not be inner classes because the materialized WeakTypeTags
1416
// will be different and they will not give the same hashCode when looking up the Definition in the
1517
// cache
@@ -184,6 +186,7 @@ class ParameterizedReset(hasAsyncNotSyncReset: Boolean) extends Module {
184186
override def resetType = if (hasAsyncNotSyncReset) Module.ResetType.Asynchronous else Module.ResetType.Synchronous
185187
}
186188

189+
@nowarn("msg=method convert in object ChiselStage is deprecated")
187190
class InstantiateSpec extends ChiselFunSpec with Utils {
188191

189192
import InstantiateSpec._

0 commit comments

Comments
 (0)