Skip to content

Commit 8ba5f8d

Browse files
committed
Merge branch '3.5.x' into 3.5-release
2 parents 5aa60ec + 6a63353 commit 8ba5f8d

23 files changed

+184
-59
lines changed

core/src/main/scala/chisel3/Aggregate.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import chisel3.experimental.dataview.{isView, reifySingleData, InvalidViewExcept
88
import scala.collection.immutable.{SeqMap, VectorMap}
99
import scala.collection.mutable.{HashSet, LinkedHashMap}
1010
import scala.language.experimental.macros
11-
import chisel3.experimental.{BaseModule, BundleLiteralException, ChiselEnum, EnumType, OpaqueType, VecLiteralException}
11+
import chisel3.experimental.{BaseModule, BundleLiteralException, OpaqueType, VecLiteralException}
1212
import chisel3.internal._
1313
import chisel3.internal.Builder.pushCommand
1414
import chisel3.internal.firrtl._

core/src/main/scala/chisel3/Data.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ package chisel3
55
import chisel3.experimental.dataview.reify
66

77
import scala.language.experimental.macros
8-
import chisel3.experimental.{Analog, BaseModule, DataMirror, EnumType, FixedPoint, Interval}
8+
import chisel3.experimental.{Analog, BaseModule, DataMirror, FixedPoint, Interval}
99
import chisel3.internal.Builder.pushCommand
1010
import chisel3.internal._
1111
import chisel3.internal.firrtl._

core/src/main/scala/chisel3/StrongEnum.scala renamed to core/src/main/scala/chisel3/experimental/ChiselEnum.scala

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,11 @@ object EnumAnnotations {
6969
override def toFirrtl: Annotation = EnumDefAnnotation(typeName, definition)
7070
}
7171
}
72+
7273
import EnumAnnotations._
7374

74-
abstract class EnumType(private[chisel3] val factory: EnumFactory, selfAnnotating: Boolean = true) extends Element {
75+
@deprecated("This type has moved to chisel3", "Chisel 3.5")
76+
abstract class EnumType(private[chisel3] val factory: ChiselEnum, selfAnnotating: Boolean = true) extends Element {
7577

7678
// Use getSimpleName instead of enumTypeName because for debugging purposes
7779
// the fully qualified name isn't necessary (compared to for the
@@ -240,11 +242,13 @@ abstract class EnumType(private[chisel3] val factory: EnumFactory, selfAnnotatin
240242
case None => EnumComponentChiselAnnotation(this, enumTypeName)
241243
}
242244

243-
if (!Builder.annotations.contains(anno)) {
245+
if (!Builder.enumAnnos.contains(anno)) {
246+
Builder.enumAnnos += anno
244247
annotate(anno)
245248
}
246249

247-
if (!Builder.annotations.contains(factory.globalAnnotation)) {
250+
if (!Builder.enumAnnos.contains(factory.globalAnnotation)) {
251+
Builder.enumAnnos += factory.globalAnnotation
248252
annotate(factory.globalAnnotation)
249253
}
250254
}
@@ -275,6 +279,7 @@ abstract class EnumType(private[chisel3] val factory: EnumFactory, selfAnnotatin
275279
}
276280
}
277281

282+
@deprecated("This type has been moved and renamed to chisel3.ChiselEnum", "Chisel 3.5")
278283
abstract class EnumFactory {
279284
class Type extends EnumType(this)
280285
object Type {
@@ -431,11 +436,11 @@ private[chisel3] object EnumMacros {
431436
private[chisel3] class UnsafeEnum(override val width: Width) extends EnumType(UnsafeEnum, selfAnnotating = false) {
432437
override def cloneType: this.type = new UnsafeEnum(width).asInstanceOf[this.type]
433438
}
434-
private object UnsafeEnum extends EnumFactory
439+
private object UnsafeEnum extends ChiselEnum
435440

436441
/** Suppress enum cast warnings
437442
*
438-
* Users should use [[EnumFactory.safe <EnumType>.safe]] when possible.
443+
* Users should use [[ChiselEnum.safe <EnumType>.safe]] when possible.
439444
*
440445
* This is primarily used for casting from [[UInt]] to a Bundle type that contains an Enum.
441446
* {{{
@@ -450,6 +455,7 @@ private object UnsafeEnum extends EnumFactory
450455
* }
451456
* }}}
452457
*/
458+
@deprecated("This type has moved to chisel3", "Chisel 3.5")
453459
object suppressEnumCastWarning {
454460
def apply[T](block: => T): T = {
455461
val parentWarn = Builder.suppressEnumCastWarning

core/src/main/scala/chisel3/experimental/package.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ package object experimental {
2222
implicit def fromDoubleToDoubleParam(x: Double): DoubleParam = DoubleParam(x)
2323
implicit def fromStringToStringParam(x: String): StringParam = StringParam(x)
2424

25+
@deprecated("This type has moved to chisel3", "Chisel 3.5")
2526
type ChiselEnum = EnumFactory
2627

2728
// Rocket Chip-style clonemodule

core/src/main/scala/chisel3/internal/Builder.scala

Lines changed: 41 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -299,25 +299,31 @@ private[chisel3] trait HasId extends InstanceId {
299299
// Builder.deprecated mechanism, we have to create our own one off ErrorLog and print the
300300
// warning right away.
301301
// It's especially bad because --warnings-as-errors does not work with these warnings
302-
val nameGuess = _computeName(None) match {
303-
case Some(name) => s": '$name'"
304-
case None => ""
305-
}
306-
val parentGuess = _parent match {
307-
case Some(ViewParent) => s", in module '${reifyParent.pathName}'"
308-
case Some(p) => s", in module '${p.pathName}'"
309-
case None => ""
310-
}
311302
val errors = new ErrorLog(false)
312303
val logger = new _root_.logger.Logger(this.getClass.getName)
313304
val msg =
314-
"Accessing the .instanceName or .toTarget of non-hardware Data is deprecated" + nameGuess + parentGuess + ". " +
305+
"Accessing the .instanceName or .toTarget of non-hardware Data is deprecated" + _errorContext + ". " +
315306
"This will become an error in Chisel 3.6."
316307
errors.deprecated(msg, None)
317308
errors.checkpoint(logger)
318309
_computeName(None).get
319310
}
320311

312+
private[chisel3] def _errorContext: String = {
313+
val nameGuess: String = _computeName(None) match {
314+
case Some(name) => s": '$name'"
315+
case None => ""
316+
}
317+
318+
val parentGuess: String = _parent match {
319+
case Some(ViewParent) => s", in module '${reifyParent.pathName}'"
320+
case Some(p) => s", in module '${p.pathName}'"
321+
case None => ""
322+
}
323+
324+
nameGuess + parentGuess
325+
}
326+
321327
// Helper for reifying views if they map to a single Target
322328
private[chisel3] def reifyTarget: Option[Data] = this match {
323329
case d: Data => reifySingleData(d) // Only Data can be views
@@ -393,13 +399,16 @@ private[chisel3] trait NamedComponent extends HasId {
393399
/** Returns a FIRRTL ComponentName that references this object
394400
* @note Should not be called until circuit elaboration is complete
395401
*/
396-
final def toNamed: ComponentName =
402+
final def toNamed: ComponentName = {
403+
assertValidTarget()
397404
ComponentName(this.instanceName, ModuleName(this.parentModName, CircuitName(this.circuitName)))
405+
}
398406

399407
/** Returns a FIRRTL ReferenceTarget that references this object
400408
* @note Should not be called until circuit elaboration is complete
401409
*/
402410
final def toTarget: ReferenceTarget = {
411+
assertValidTarget()
403412
val name = this.instanceName
404413
if (!validComponentName(name)) throwException(s"Illegal component name: $name (note: literals are illegal)")
405414
import _root_.firrtl.annotations.{Target, TargetToken}
@@ -423,6 +432,21 @@ private[chisel3] trait NamedComponent extends HasId {
423432
case None => localTarget
424433
}
425434
}
435+
436+
private def assertValidTarget(): Unit = {
437+
val isVecSubaccess = getOptionRef.map {
438+
case Index(_, _: ULit) => true // Vec literal indexing
439+
case Index(_, _: Node) => true // Vec dynamic indexing
440+
case _ => false
441+
}.getOrElse(false)
442+
443+
if (isVecSubaccess) {
444+
throwException(
445+
s"You cannot target Vec subaccess" + _errorContext +
446+
". Instead, assign it to a temporary (for example, with WireInit) and target the temporary."
447+
)
448+
}
449+
}
426450
}
427451

428452
// Mutable global state for chisel that can appear outside a Builder context
@@ -485,6 +509,10 @@ private[chisel3] class DynamicContext(
485509
val newAnnotations = ArrayBuffer[ChiselMultiAnnotation]()
486510
var currentModule: Option[BaseModule] = None
487511

512+
// Enum annotations are added every time a ChiselEnum is bound
513+
// To keep the number down, we keep them unique in the annotations
514+
val enumAnnos = mutable.HashSet[ChiselAnnotation]()
515+
488516
/** Contains a mapping from a elaborated module to their aspect
489517
* Set by [[ModuleAspect]]
490518
*/
@@ -553,6 +581,8 @@ private[chisel3] object Builder extends LazyLogging {
553581
def components: ArrayBuffer[Component] = dynamicContext.components
554582
def annotations: ArrayBuffer[ChiselAnnotation] = dynamicContext.annotations
555583

584+
def enumAnnos: mutable.HashSet[ChiselAnnotation] = dynamicContext.enumAnnos
585+
556586
// TODO : Unify this with annotations in the future - done this way for backward compatability
557587
def newAnnotations: ArrayBuffer[ChiselMultiAnnotation] = dynamicContext.newAnnotations
558588

core/src/main/scala/chisel3/internal/MonoConnect.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
package chisel3.internal
44

55
import chisel3._
6-
import chisel3.experimental.{Analog, BaseModule, EnumType, FixedPoint, Interval, UnsafeEnum}
6+
import chisel3.experimental.{Analog, BaseModule, FixedPoint, Interval, UnsafeEnum}
77
import chisel3.internal.Builder.pushCommand
88
import chisel3.internal.firrtl.{Connect, Converter, DefInvalid}
99
import chisel3.experimental.dataview.{isView, reify, reifyToAggregate}

core/src/main/scala/chisel3/package.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ package object chisel3 {
1414

1515
import scala.language.implicitConversions
1616

17+
type ChiselEnum = experimental.ChiselEnum
18+
type EnumType = experimental.EnumType
19+
val suppressEnumCastWarning = experimental.suppressEnumCastWarning
20+
1721
/**
1822
* These implicit classes allow one to convert [[scala.Int]] or [[scala.BigInt]] to
1923
* Chisel.UInt|Chisel.SInt by calling .asUInt|.asSInt on them, respectively.

docs/src/cookbooks/cookbook.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -445,13 +445,12 @@ getVerilogString(new Top(new UsingCloneTypeBundle(UInt(8.W))))
445445

446446
### How do I create a finite state machine (FSM)?
447447

448-
The advised way is to use [`ChiselEnum`](https://www.chisel-lang.org/api/latest/chisel3/experimental/index.html#ChiselEnum=chisel3.experimental.EnumFactory) to construct enumerated types representing the state of the FSM.
449-
State transitions are then handled with [`switch`](https://www.chisel-lang.org/api/latest/chisel3/util/switch$.html)/[`is`](https://www.chisel-lang.org/api/latest/chisel3/util/is$.html) and [`when`](https://www.chisel-lang.org/api/latest/chisel3/when$.html)/[`.elsewhen`](https://www.chisel-lang.org/api/latest/chisel3/WhenContext.html#elsewhen(elseCond:=%3Echisel3.Bool)(block:=%3EUnit)(implicitsourceInfo:chisel3.internal.sourceinfo.SourceInfo,implicitcompileOptions:chisel3.CompileOptions):chisel3.WhenContext)/[`.otherwise`](https://www.chisel-lang.org/api/latest/chisel3/WhenContext.html#otherwise(block:=%3EUnit)(implicitsourceInfo:chisel3.internal.sourceinfo.SourceInfo,implicitcompileOptions:chisel3.CompileOptions):Unit).
448+
The advised way is to use `ChiselEnum` to construct enumerated types representing the state of the FSM.
449+
State transitions are then handled with `switch`/`is` and `when`/`.elsewhen`/`.otherwise`.
450450

451451
```scala mdoc:silent:reset
452452
import chisel3._
453453
import chisel3.util.{switch, is}
454-
import chisel3.experimental.ChiselEnum
455454

456455
object DetectTwoOnes {
457456
object State extends ChiselEnum {

docs/src/cookbooks/verilog-vs-chisel.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ This page serves as a quick introduction to Chisel for those familiar with Veril
1515
import chisel3._
1616
import chisel3.util.{switch, is}
1717
import chisel3.stage.ChiselStage
18-
import chisel3.experimental.ChiselEnum
1918
import chisel3.util.{Cat, Fill, DecoupledIO}
2019
```
2120

docs/src/explanations/chisel-enum.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ In contrast with `Chisel.util.Enum`, `ChiselEnum` are subclasses of `Data`, whic
1616
import chisel3._
1717
import chisel3.util._
1818
import chisel3.stage.ChiselStage
19-
import chisel3.experimental.ChiselEnum
20-
import chisel3.experimental.suppressEnumCastWarning
2119
```
2220

2321
```scala mdoc:invisible

src/main/scala/chisel3/util/experimental/decode/TruthTable.scala

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,35 @@
33
package chisel3.util.experimental.decode
44

55
import chisel3.util.BitPat
6+
import scala.util.hashing.MurmurHash3
67
import scala.collection.mutable
78

8-
sealed class TruthTable private (val table: Seq[(BitPat, BitPat)], val default: BitPat, val sort: Boolean) {
9+
sealed class TruthTable private (val table: Seq[(BitPat, BitPat)], val default: BitPat, _sort: Boolean) {
910
def inputWidth = table.head._1.getWidth
1011

1112
def outputWidth = table.head._2.getWidth
1213

14+
@deprecated("This field is unused and will be removed.", "Chisel 3.5")
15+
def sort: Boolean = _sort
16+
1317
override def toString: String = {
1418
def writeRow(map: (BitPat, BitPat)): String =
1519
s"${map._1.rawString}->${map._2.rawString}"
1620

1721
(table.map(writeRow) ++ Seq(s"${" " * (inputWidth + 2)}${default.rawString}")).mkString("\n")
1822
}
1923

20-
def copy(table: Seq[(BitPat, BitPat)] = this.table, default: BitPat = this.default, sort: Boolean = this.sort) =
21-
TruthTable(table, default, sort)
24+
def copy(table: Seq[(BitPat, BitPat)] = this.table, default: BitPat = this.default, sort: Boolean = _sort) =
25+
TruthTable(table, default)
2226

2327
override def equals(y: Any): Boolean = {
2428
y match {
25-
case y: TruthTable => toString == y.toString
29+
case that: TruthTable => this.table == that.table && this.default == that.default
2630
case _ => false
2731
}
2832
}
33+
34+
override lazy val hashCode: Int = MurmurHash3.productHash((table, default))
2935
}
3036

3137
object TruthTable {

src/test/scala/chiselTests/AsTypeOfTester.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
package chiselTests
44

55
import chisel3._
6-
import chisel3.experimental.{ChiselEnum, DataMirror, FixedPoint}
6+
import chisel3.experimental.{DataMirror, FixedPoint}
77
import chisel3.testers.BasicTester
88

99
class AsTypeOfBundleTester extends BasicTester {

src/test/scala/chiselTests/BundleElementsSpec.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
package chiselTests
44

55
import chisel3._
6-
import chisel3.experimental.{ChiselEnum, FixedPoint}
6+
import chisel3.experimental.FixedPoint
77
import chisel3.stage.ChiselStage
88
import chisel3.util.Decoupled
99
import org.scalatest.exceptions.TestFailedException

src/test/scala/chiselTests/BundleLiteralSpec.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import chisel3.stage.ChiselStage
77
import chisel3.testers.BasicTester
88
import chisel3.experimental.BundleLiterals._
99
import chisel3.experimental.VecLiterals.AddVecLiteralConstructor
10-
import chisel3.experimental.{BundleLiteralException, ChiselEnum, ChiselRange, FixedPoint, Interval}
10+
import chisel3.experimental.{BundleLiteralException, ChiselRange, FixedPoint, Interval}
1111

1212
class BundleLiteralSpec extends ChiselFlatSpec with Utils {
1313
object MyEnum extends ChiselEnum {

0 commit comments

Comments
 (0)