Skip to content

Commit

Permalink
Wrap elaboration in ChiselException
Browse files Browse the repository at this point in the history
Signed-off-by: Schuyler Eldridge <schuyler.eldridge@ibm.com>

squash! Wrap elaboration in ChiselException
  • Loading branch information
seldridge committed Mar 11, 2020
1 parent d83235f commit d67c410
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/main/scala/chisel3/stage/ChiselAnnotations.scala
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ case class ChiselGeneratorAnnotation(gen: () => RawModule) extends NoTargetAnnot
} catch {
case e @ (_: OptionsException | _: ChiselException) => throw e
case e: Throwable =>
throw new OptionsException(s"Exception thrown when elaborating ChiselGeneratorAnnotation", e)
throw new ChiselException(s"Exception thrown when elaborating ChiselGeneratorAnnotation", e)
}

}
Expand Down
5 changes: 2 additions & 3 deletions src/test/scala/chiselTests/ChiselSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import org.scalatest.prop._
import org.scalacheck._
import chisel3._
import chisel3.testers._
import firrtl.options.OptionsException
import firrtl.{AnnotationSeq, CommonOptions, ExecutionOptionsManager, FirrtlExecutionFailure, FirrtlExecutionSuccess, HasFirrtlOptions}
import firrtl.util.BackendCompilationUtilities
import java.io.ByteArrayOutputStream
Expand Down Expand Up @@ -100,7 +99,7 @@ class ChiselTestUtilitiesSpec extends ChiselFlatSpec {
import org.scalatest.exceptions.TestFailedException
// Who tests the testers?
"assertKnownWidth" should "error when the expected width is wrong" in {
val caught = intercept[OptionsException] {
val caught = intercept[ChiselException] {
assertKnownWidth(7) {
Wire(UInt(8.W))
}
Expand All @@ -123,7 +122,7 @@ class ChiselTestUtilitiesSpec extends ChiselFlatSpec {
}

"assertInferredWidth" should "error if the width is known" in {
val caught = intercept[OptionsException] {
val caught = intercept[ChiselException] {
assertInferredWidth(8) {
Wire(UInt(8.W))
}
Expand Down
16 changes: 12 additions & 4 deletions src/test/scala/chiselTests/OneHotMuxSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package chiselTests

import chisel3._
import chisel3.experimental.FixedPoint
import chisel3.internal.ChiselException
import chisel3.testers.BasicTester
import chisel3.util.{Mux1H, UIntToOH}
import org.scalatest._
Expand Down Expand Up @@ -31,23 +32,31 @@ class OneHotMuxSpec extends FreeSpec with Matchers with ChiselRunners {
assertTesterPasses(new ParameterizedAggregateOneHotTester)
}
"simple one hot mux with all aggregates containing inferred width fixed values should NOT work" in {
intercept[ChiselException] {
intercept [ChiselException] {
assertTesterPasses(new InferredWidthAggregateOneHotTester)
}
}
"simple one hot mux with all fixed width bundles but with different bundles should Not work" in {
intercept[IllegalArgumentException] {
try {
assertTesterPasses(new DifferentBundleOneHotTester)
} catch {
case a: ChiselException => a.getCause match {
case _: IllegalArgumentException =>
}
}
}
"UIntToOH with output width greater than 2^(input width)" in {
assertTesterPasses(new UIntToOHTester)
}
"UIntToOH should not accept width of zero (until zero-width wires are fixed" in {
intercept[java.lang.IllegalArgumentException] {
try {
assertTesterPasses(new BasicTester {
val out = UIntToOH(0.U, 0)
})
} catch {
case a: ChiselException => a.getCause match {
case _: IllegalArgumentException =>
}
}
}

Expand Down Expand Up @@ -305,4 +314,3 @@ class UIntToOHTester extends BasicTester {

stop()
}

0 comments on commit d67c410

Please sign in to comment.