summaryrefslogtreecommitdiff
path: root/core/src/main/scala/chisel3/internal
diff options
context:
space:
mode:
authorJack2023-01-12 06:11:50 +0000
committerJack2023-01-12 06:11:50 +0000
commit8ba5f8d5011df70e817d3011ea4afd6976df243e (patch)
tree5899c699e5164588c40aa7c3a7c5e62b79d7b804 /core/src/main/scala/chisel3/internal
parent5aa60ecda6bd2b02dfc7253a47e53c7647981a5c (diff)
parent6a63353f2a6c3311e61b9a7b5b899d8ad904a86d (diff)
Merge branch '3.5.x' into 3.5-release
Diffstat (limited to 'core/src/main/scala/chisel3/internal')
-rw-r--r--core/src/main/scala/chisel3/internal/Builder.scala52
-rw-r--r--core/src/main/scala/chisel3/internal/MonoConnect.scala2
2 files changed, 42 insertions, 12 deletions
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}