summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/src/main/scala/chisel3/Aggregate.scala2
-rw-r--r--core/src/main/scala/chisel3/Data.scala2
-rw-r--r--core/src/main/scala/chisel3/experimental/ChiselEnum.scala (renamed from core/src/main/scala/chisel3/StrongEnum.scala)16
-rw-r--r--core/src/main/scala/chisel3/experimental/package.scala1
-rw-r--r--core/src/main/scala/chisel3/internal/Builder.scala52
-rw-r--r--core/src/main/scala/chisel3/internal/MonoConnect.scala2
-rw-r--r--core/src/main/scala/chisel3/package.scala4
7 files changed, 60 insertions, 19 deletions
diff --git a/core/src/main/scala/chisel3/Aggregate.scala b/core/src/main/scala/chisel3/Aggregate.scala
index b6836ea7..dbf6969f 100644
--- a/core/src/main/scala/chisel3/Aggregate.scala
+++ b/core/src/main/scala/chisel3/Aggregate.scala
@@ -8,7 +8,7 @@ import chisel3.experimental.dataview.{isView, reifySingleData, InvalidViewExcept
import scala.collection.immutable.{SeqMap, VectorMap}
import scala.collection.mutable.{HashSet, LinkedHashMap}
import scala.language.experimental.macros
-import chisel3.experimental.{BaseModule, BundleLiteralException, ChiselEnum, EnumType, OpaqueType, VecLiteralException}
+import chisel3.experimental.{BaseModule, BundleLiteralException, OpaqueType, VecLiteralException}
import chisel3.internal._
import chisel3.internal.Builder.pushCommand
import chisel3.internal.firrtl._
diff --git a/core/src/main/scala/chisel3/Data.scala b/core/src/main/scala/chisel3/Data.scala
index dddc0d5d..259e6545 100644
--- a/core/src/main/scala/chisel3/Data.scala
+++ b/core/src/main/scala/chisel3/Data.scala
@@ -5,7 +5,7 @@ package chisel3
import chisel3.experimental.dataview.reify
import scala.language.experimental.macros
-import chisel3.experimental.{Analog, BaseModule, DataMirror, EnumType, FixedPoint, Interval}
+import chisel3.experimental.{Analog, BaseModule, DataMirror, FixedPoint, Interval}
import chisel3.internal.Builder.pushCommand
import chisel3.internal._
import chisel3.internal.firrtl._
diff --git a/core/src/main/scala/chisel3/StrongEnum.scala b/core/src/main/scala/chisel3/experimental/ChiselEnum.scala
index 3c9f4105..37c6fb58 100644
--- a/core/src/main/scala/chisel3/StrongEnum.scala
+++ b/core/src/main/scala/chisel3/experimental/ChiselEnum.scala
@@ -69,9 +69,11 @@ object EnumAnnotations {
override def toFirrtl: Annotation = EnumDefAnnotation(typeName, definition)
}
}
+
import EnumAnnotations._
-abstract class EnumType(private[chisel3] val factory: EnumFactory, selfAnnotating: Boolean = true) extends Element {
+@deprecated("This type has moved to chisel3", "Chisel 3.5")
+abstract class EnumType(private[chisel3] val factory: ChiselEnum, selfAnnotating: Boolean = true) extends Element {
// Use getSimpleName instead of enumTypeName because for debugging purposes
// the fully qualified name isn't necessary (compared to for the
@@ -240,11 +242,13 @@ abstract class EnumType(private[chisel3] val factory: EnumFactory, selfAnnotatin
case None => EnumComponentChiselAnnotation(this, enumTypeName)
}
- if (!Builder.annotations.contains(anno)) {
+ if (!Builder.enumAnnos.contains(anno)) {
+ Builder.enumAnnos += anno
annotate(anno)
}
- if (!Builder.annotations.contains(factory.globalAnnotation)) {
+ if (!Builder.enumAnnos.contains(factory.globalAnnotation)) {
+ Builder.enumAnnos += factory.globalAnnotation
annotate(factory.globalAnnotation)
}
}
@@ -275,6 +279,7 @@ abstract class EnumType(private[chisel3] val factory: EnumFactory, selfAnnotatin
}
}
+@deprecated("This type has been moved and renamed to chisel3.ChiselEnum", "Chisel 3.5")
abstract class EnumFactory {
class Type extends EnumType(this)
object Type {
@@ -431,11 +436,11 @@ private[chisel3] object EnumMacros {
private[chisel3] class UnsafeEnum(override val width: Width) extends EnumType(UnsafeEnum, selfAnnotating = false) {
override def cloneType: this.type = new UnsafeEnum(width).asInstanceOf[this.type]
}
-private object UnsafeEnum extends EnumFactory
+private object UnsafeEnum extends ChiselEnum
/** Suppress enum cast warnings
*
- * Users should use [[EnumFactory.safe <EnumType>.safe]] when possible.
+ * Users should use [[ChiselEnum.safe <EnumType>.safe]] when possible.
*
* This is primarily used for casting from [[UInt]] to a Bundle type that contains an Enum.
* {{{
@@ -450,6 +455,7 @@ private object UnsafeEnum extends EnumFactory
* }
* }}}
*/
+@deprecated("This type has moved to chisel3", "Chisel 3.5")
object suppressEnumCastWarning {
def apply[T](block: => T): T = {
val parentWarn = Builder.suppressEnumCastWarning
diff --git a/core/src/main/scala/chisel3/experimental/package.scala b/core/src/main/scala/chisel3/experimental/package.scala
index 42ec9666..2b493aab 100644
--- a/core/src/main/scala/chisel3/experimental/package.scala
+++ b/core/src/main/scala/chisel3/experimental/package.scala
@@ -22,6 +22,7 @@ package object experimental {
implicit def fromDoubleToDoubleParam(x: Double): DoubleParam = DoubleParam(x)
implicit def fromStringToStringParam(x: String): StringParam = StringParam(x)
+ @deprecated("This type has moved to chisel3", "Chisel 3.5")
type ChiselEnum = EnumFactory
// Rocket Chip-style clonemodule
diff --git a/core/src/main/scala/chisel3/internal/Builder.scala b/core/src/main/scala/chisel3/internal/Builder.scala
index d06b7992..ab1435c5 100644
--- a/core/src/main/scala/chisel3/internal/Builder.scala
+++ b/core/src/main/scala/chisel3/internal/Builder.scala
@@ -299,25 +299,31 @@ private[chisel3] trait HasId extends InstanceId {
// Builder.deprecated mechanism, we have to create our own one off ErrorLog and print the
// warning right away.
// It's especially bad because --warnings-as-errors does not work with these warnings
- val nameGuess = _computeName(None) match {
- case Some(name) => s": '$name'"
- case None => ""
- }
- val parentGuess = _parent match {
- case Some(ViewParent) => s", in module '${reifyParent.pathName}'"
- case Some(p) => s", in module '${p.pathName}'"
- case None => ""
- }
val errors = new ErrorLog(false)
val logger = new _root_.logger.Logger(this.getClass.getName)
val msg =
- "Accessing the .instanceName or .toTarget of non-hardware Data is deprecated" + nameGuess + parentGuess + ". " +
+ "Accessing the .instanceName or .toTarget of non-hardware Data is deprecated" + _errorContext + ". " +
"This will become an error in Chisel 3.6."
errors.deprecated(msg, None)
errors.checkpoint(logger)
_computeName(None).get
}
+ private[chisel3] def _errorContext: String = {
+ val nameGuess: String = _computeName(None) match {
+ case Some(name) => s": '$name'"
+ case None => ""
+ }
+
+ val parentGuess: String = _parent match {
+ case Some(ViewParent) => s", in module '${reifyParent.pathName}'"
+ case Some(p) => s", in module '${p.pathName}'"
+ case None => ""
+ }
+
+ nameGuess + parentGuess
+ }
+
// Helper for reifying views if they map to a single Target
private[chisel3] def reifyTarget: Option[Data] = this match {
case d: Data => reifySingleData(d) // Only Data can be views
@@ -393,13 +399,16 @@ private[chisel3] trait NamedComponent extends HasId {
/** Returns a FIRRTL ComponentName that references this object
* @note Should not be called until circuit elaboration is complete
*/
- final def toNamed: ComponentName =
+ final def toNamed: ComponentName = {
+ assertValidTarget()
ComponentName(this.instanceName, ModuleName(this.parentModName, CircuitName(this.circuitName)))
+ }
/** Returns a FIRRTL ReferenceTarget that references this object
* @note Should not be called until circuit elaboration is complete
*/
final def toTarget: ReferenceTarget = {
+ assertValidTarget()
val name = this.instanceName
if (!validComponentName(name)) throwException(s"Illegal component name: $name (note: literals are illegal)")
import _root_.firrtl.annotations.{Target, TargetToken}
@@ -423,6 +432,21 @@ private[chisel3] trait NamedComponent extends HasId {
case None => localTarget
}
}
+
+ private def assertValidTarget(): Unit = {
+ val isVecSubaccess = getOptionRef.map {
+ case Index(_, _: ULit) => true // Vec literal indexing
+ case Index(_, _: Node) => true // Vec dynamic indexing
+ case _ => false
+ }.getOrElse(false)
+
+ if (isVecSubaccess) {
+ throwException(
+ s"You cannot target Vec subaccess" + _errorContext +
+ ". Instead, assign it to a temporary (for example, with WireInit) and target the temporary."
+ )
+ }
+ }
}
// Mutable global state for chisel that can appear outside a Builder context
@@ -485,6 +509,10 @@ private[chisel3] class DynamicContext(
val newAnnotations = ArrayBuffer[ChiselMultiAnnotation]()
var currentModule: Option[BaseModule] = None
+ // Enum annotations are added every time a ChiselEnum is bound
+ // To keep the number down, we keep them unique in the annotations
+ val enumAnnos = mutable.HashSet[ChiselAnnotation]()
+
/** Contains a mapping from a elaborated module to their aspect
* Set by [[ModuleAspect]]
*/
@@ -553,6 +581,8 @@ private[chisel3] object Builder extends LazyLogging {
def components: ArrayBuffer[Component] = dynamicContext.components
def annotations: ArrayBuffer[ChiselAnnotation] = dynamicContext.annotations
+ def enumAnnos: mutable.HashSet[ChiselAnnotation] = dynamicContext.enumAnnos
+
// TODO : Unify this with annotations in the future - done this way for backward compatability
def newAnnotations: ArrayBuffer[ChiselMultiAnnotation] = dynamicContext.newAnnotations
diff --git a/core/src/main/scala/chisel3/internal/MonoConnect.scala b/core/src/main/scala/chisel3/internal/MonoConnect.scala
index 4e762a7c..a0cca4a6 100644
--- a/core/src/main/scala/chisel3/internal/MonoConnect.scala
+++ b/core/src/main/scala/chisel3/internal/MonoConnect.scala
@@ -3,7 +3,7 @@
package chisel3.internal
import chisel3._
-import chisel3.experimental.{Analog, BaseModule, EnumType, FixedPoint, Interval, UnsafeEnum}
+import chisel3.experimental.{Analog, BaseModule, FixedPoint, Interval, UnsafeEnum}
import chisel3.internal.Builder.pushCommand
import chisel3.internal.firrtl.{Connect, Converter, DefInvalid}
import chisel3.experimental.dataview.{isView, reify, reifyToAggregate}
diff --git a/core/src/main/scala/chisel3/package.scala b/core/src/main/scala/chisel3/package.scala
index 87024683..afffad1c 100644
--- a/core/src/main/scala/chisel3/package.scala
+++ b/core/src/main/scala/chisel3/package.scala
@@ -14,6 +14,10 @@ package object chisel3 {
import scala.language.implicitConversions
+ type ChiselEnum = experimental.ChiselEnum
+ type EnumType = experimental.EnumType
+ val suppressEnumCastWarning = experimental.suppressEnumCastWarning
+
/**
* These implicit classes allow one to convert [[scala.Int]] or [[scala.BigInt]] to
* Chisel.UInt|Chisel.SInt by calling .asUInt|.asSInt on them, respectively.