aboutsummaryrefslogtreecommitdiff
path: root/src/test/scala/firrtlTests/AnnotationTests.scala
blob: e04b4e1403dd1616982776cc3c6f4d7b3e99f0f5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package firrtlTests

import java.io.StringWriter

import org.scalatest.FlatSpec
import org.scalatest.Matchers
import org.scalatest.junit.JUnitRunner

import firrtl.ir.Circuit
import firrtl.{
   Parser,
   Named,
   ModuleName,
   ComponentName,
   CircuitAnnotation,
   StringAnnotation,
   BrittleCircuitAnnotation,
   UnknownCAKind,
   Compiler,
   CompilerResult,
   Annotation,
   RenameMap,
   VerilogCompiler
}

/**
 * An example methodology for testing Firrtl annotations.
 */
abstract class AnnotationSpec extends FlatSpec {
   def parse (s: String): Circuit = Parser.parse(s.split("\n").toIterator)
   def compiler: Compiler
   def input: String
   def getResult (annotation: CircuitAnnotation): CompilerResult = {
      val writer = new StringWriter()
      compiler.compile(parse(input), Seq(annotation), writer)
   }
}


/**
 * An example test for testing module annotations
 */
class BrittleModuleAnnotationSpec extends AnnotationSpec with Matchers {
   val compiler = new VerilogCompiler()
   val input =
"""
circuit Top :
  module Top :
    input a : UInt<1>[2]
    node x = a
"""
   val message = "This is Top"
   val map: Map[Named, Annotation] = Map(ModuleName("Top") -> StringAnnotation(message))
   val annotation = BrittleCircuitAnnotation(UnknownCAKind, map)
   "The annotation" should "get passed through the compiler" in {
      (getResult(annotation).annotations.head == annotation) should be (true)
   }
}