From b578aa5e45e4ac5c2a71dda42367863a577ccaa4 Mon Sep 17 00:00:00 2001 From: Megan Wachs Date: Mon, 11 Jan 2021 07:19:17 -0800 Subject: Make `toTarget` fail if called on a Literal (or would otherwise not serialize properly) (#1714) * Add (failing) Test for Data toTarget calls Add scaladoc and clean up test * Builder: don't let .toTarget pass if it won't be able to deserialize properly later * Update src/test/scala/chiselTests/ReferenceTargetSpec.scala * Rename and simplify tests for literal toTarget--- .../scala/chiselTests/LiteralToTargetSpec.scala | 31 ++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 src/test/scala/chiselTests/LiteralToTargetSpec.scala (limited to 'src') diff --git a/src/test/scala/chiselTests/LiteralToTargetSpec.scala b/src/test/scala/chiselTests/LiteralToTargetSpec.scala new file mode 100644 index 00000000..3c404f2d --- /dev/null +++ b/src/test/scala/chiselTests/LiteralToTargetSpec.scala @@ -0,0 +1,31 @@ +// SPDX-License-Identifier: Apache-2.0 + +package chiselTests + +import chisel3._ +import chisel3.stage.ChiselStage + +import org.scalatest._ +import org.scalatest.freespec.AnyFreeSpec +import org.scalatest.matchers.should.Matchers + + +class LiteralToTargetSpec extends AnyFreeSpec with Matchers { + + "Literal Data should fail to be converted to ReferenceTarget" in { + + the [chisel3.internal.ChiselException] thrownBy { + + class Bar extends RawModule { + val a = 1.U + } + + class Foo extends RawModule { + val bar = Module(new Bar) + bar.a.toTarget + } + + ChiselStage.elaborate(new Foo) + } should have message "Illegal component name: UInt<1>(\"h01\") (note: literals are illegal)" + } +} -- cgit v1.2.3