Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Eagerly throw error if certain annotations are used on non-hardware types #2700

Merged
merged 7 commits into from
Aug 25, 2022
Merged
Show file tree
Hide file tree
Changes from 4 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
3 changes: 3 additions & 0 deletions src/main/scala/chisel3/util/experimental/ForceNames.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
package chisel3.util.experimental

import chisel3.experimental.{annotate, ChiselAnnotation, RunFirrtlTransform}
import chisel3.internal.Builder
import firrtl.Mappers._
import firrtl._
import firrtl.annotations._
Expand All @@ -24,6 +25,7 @@ object forceName {
* @param name Name to force to
*/
def apply[T <: chisel3.Element](signal: T, name: String): T = {
if (!signal.isSynthesizable) Builder.error(s"Using forceName '$name' on non-hardware value $signal")
annotate(new ChiselAnnotation with RunFirrtlTransform {
def toFirrtl = ForceNameAnnotation(signal.toTarget, name)
override def transformClass: Class[_ <: Transform] = classOf[ForceNamesTransform]
Expand All @@ -37,6 +39,7 @@ object forceName {
* @param signal Signal to name
*/
def apply[T <: chisel3.Element](signal: T): T = {
if (!signal.isSynthesizable) Builder.error(s"Using forceName on non-hardware value $signal")
annotate(new ChiselAnnotation with RunFirrtlTransform {
def toFirrtl = ForceNameAnnotation(signal.toTarget, signal.toTarget.ref)
override def transformClass: Class[_ <: Transform] = classOf[ForceNamesTransform]
Expand Down
2 changes: 2 additions & 0 deletions src/main/scala/chisel3/util/experimental/decode/decoder.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import chisel3._
import chisel3.experimental.{annotate, ChiselAnnotation}
import chisel3.util.{pla, BitPat}
import chisel3.util.experimental.{getAnnotations, BitSet}
import chisel3.internal.Builder
import firrtl.annotations.Annotation
import logger.LazyLogging

Expand All @@ -30,6 +31,7 @@ object decoder extends LazyLogging {
val (plaInput, plaOutput) =
pla(minimizedTable.table.toSeq, BitPat(minimizedTable.default.value.U(minimizedTable.default.getWidth.W)))

if (!plaOutput.isSynthesizable) Builder.error(s"Using DecodeTableAnnotation on non-hardware value $plaOutput")
zyedidia marked this conversation as resolved.
Show resolved Hide resolved
annotate(new ChiselAnnotation {
override def toFirrtl: Annotation =
DecodeTableAnnotation(plaOutput.toTarget, truthTable.toString, minimizedTable.toString)
Expand Down
14 changes: 14 additions & 0 deletions src/test/scala/chiselTests/experimental/ForceNames.scala
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,18 @@ class ForceNamesSpec extends ChiselFlatSpec {
)
}
}
"Force Name of non-hardware value" should "error" in {
class Example extends Module {
val tpe = UInt(8.W)
forceName(tpe, "foobar")

val in = IO(Input(tpe))
val out = IO(Output(tpe))
out := in
}

a[ChiselException] shouldBe thrownBy {
chisel3.stage.ChiselStage.elaborate(new Example)
}
}
}