diff options
| author | Jack | 2023-01-12 06:11:50 +0000 |
|---|---|---|
| committer | Jack | 2023-01-12 06:11:50 +0000 |
| commit | 8ba5f8d5011df70e817d3011ea4afd6976df243e (patch) | |
| tree | 5899c699e5164588c40aa7c3a7c5e62b79d7b804 /src/test/scala/chiselTests/VecToTargetSpec.scala | |
| parent | 5aa60ecda6bd2b02dfc7253a47e53c7647981a5c (diff) | |
| parent | 6a63353f2a6c3311e61b9a7b5b899d8ad904a86d (diff) | |
Merge branch '3.5.x' into 3.5-release
Diffstat (limited to 'src/test/scala/chiselTests/VecToTargetSpec.scala')
| -rw-r--r-- | src/test/scala/chiselTests/VecToTargetSpec.scala | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/src/test/scala/chiselTests/VecToTargetSpec.scala b/src/test/scala/chiselTests/VecToTargetSpec.scala new file mode 100644 index 00000000..20c6f306 --- /dev/null +++ b/src/test/scala/chiselTests/VecToTargetSpec.scala @@ -0,0 +1,86 @@ +// SPDX-License-Identifier: Apache-2.0 + +package chiselTests + +import chisel3._ +import chisel3.stage.ChiselStage + +trait VecToTargetSpecUtils extends Utils { + this: ChiselFunSpec => + + class Foo extends RawModule { + val vec = IO(Input(Vec(4, Bool()))) + + // Index a Vec with a Scala literal. + val scalaLit = 0 + val vecSubaccessScalaLit = vec(scalaLit) + + // Index a Vec with a Chisel literal. + val chiselLit = 0.U + val vecSubaccessChiselLit = vec(chiselLit) + + // Index a Vec with a node. + val node = IO(Input(UInt(2.W))) + val vecSubaccessNode = vec(node) + + // Put an otherwise un-targetable Vec subaccess into a temp. + val vecSubaccessTmp = WireInit(vecSubaccessNode) + } + + val expectedError = "You cannot target Vec subaccess:" + + def conversionSucceeds(data: InstanceId) = { + describe(".toTarget") { + it("should convert successfully") { + data.toTarget + } + } + + describe(".toNamed") { + it("should convert successfully") { + data.toNamed + } + } + } + + def conversionFails(data: InstanceId) = { + describe(".toTarget") { + it("should fail to convert with a useful error message") { + (the[ChiselException] thrownBy extractCause[ChiselException] { + data.toTarget + }).getMessage should include(expectedError) + } + } + + describe(".toNamed") { + it("should fail to convert with a useful error message") { + (the[ChiselException] thrownBy extractCause[ChiselException] { + data.toNamed + }).getMessage should include(expectedError) + } + } + } +} + +class VecToTargetSpec extends ChiselFunSpec with VecToTargetSpecUtils { + describe("Vec subaccess") { + var foo: Foo = null + ChiselStage.elaborate { foo = new Foo; foo } + + describe("with a Scala literal") { + (it should behave).like(conversionSucceeds(foo.vecSubaccessScalaLit)) + } + + describe("with a Chisel literal") { + (it should behave).like(conversionFails(foo.vecSubaccessChiselLit)) + } + + describe("with a Node") { + (it should behave).like(conversionFails(foo.vecSubaccessNode)) + } + + describe("with an un-targetable construct that is assigned to a temporary") { + (it should behave).like(conversionSucceeds(foo.vecSubaccessTmp)) + } + } +} |
