diff options
| author | Adam Izraelevitz | 2020-07-29 20:48:31 -0700 |
|---|---|---|
| committer | GitHub | 2020-07-29 20:48:31 -0700 |
| commit | 164490c8fbf132ca65644d05d6ff8d0d7a3beb20 (patch) | |
| tree | 862750b85dca5b8496c40c24b3a4e5e67c268bd4 /src/test/scala/chiselTests/ChiselSpec.scala | |
| parent | 8aeb39b9b3755ccd0e3aa600b813ed4220ac72d8 (diff) | |
Improved Chisel Naming via Compiler Plugins + Prefixing (#1448)
Added prefixing and a compiler plugin to improve naming. Only works for Scala 2.12 and above.
Co-authored-by: Jack Koenig <koenig@sifive.com>
Diffstat (limited to 'src/test/scala/chiselTests/ChiselSpec.scala')
| -rw-r--r-- | src/test/scala/chiselTests/ChiselSpec.scala | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/src/test/scala/chiselTests/ChiselSpec.scala b/src/test/scala/chiselTests/ChiselSpec.scala index 2ee6fbcf..7980e772 100644 --- a/src/test/scala/chiselTests/ChiselSpec.scala +++ b/src/test/scala/chiselTests/ChiselSpec.scala @@ -14,6 +14,9 @@ import firrtl.annotations.DeletedAnnotation import firrtl.util.BackendCompilationUtilities import java.io.ByteArrayOutputStream import java.security.Permission + +import chisel3.aop.Aspect +import chisel3.stage.{ChiselGeneratorAnnotation, ChiselStage, NoRunFirrtlCompilerAnnotation, PrintFullStackTraceAnnotation} import org.scalatestplus.scalacheck.ScalaCheckPropertyChecks import scala.reflect.ClassTag @@ -270,6 +273,27 @@ trait Utils { } } + + /** A tester which runs generator and uses an aspect to check the returned object + * @param gen function to generate a Chisel module + * @param f a function to check the Chisel module + * @tparam T the Chisel module class + */ + def aspectTest[T <: RawModule](gen: () => T)(f: T => Unit)(implicit scalaMajorVersion: Int): Unit = { + // Runs chisel stage + def run[T <: RawModule](gen: () => T, annotations: AnnotationSeq): AnnotationSeq = { + new ChiselStage().run(Seq(ChiselGeneratorAnnotation(gen), NoRunFirrtlCompilerAnnotation, PrintFullStackTraceAnnotation) ++ annotations) + } + // Creates a wrapping aspect to contain checking function + case object BuiltAspect extends Aspect[T] { + override def toAnnotation(top: T): AnnotationSeq = {f(top); Nil} + } + val currentMajorVersion = scala.util.Properties.versionNumberString.split('.')(1).toInt + if(currentMajorVersion >= scalaMajorVersion) { + run(gen, Seq(BuiltAspect)) + } + } + /** Run some code and rethrow an exception with a specific type if an exception of that type occurs anywhere in the * stack trace. * @@ -306,5 +330,4 @@ trait Utils { } } - } |
