-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.scala
103 lines (95 loc) · 4.16 KB
/
main.scala
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import chisel3._
import chisel3.util._
import chisel3.iotesters.{ChiselFlatSpec, Driver, PeekPokeTester}
object main_gen {
// Convenience function to invoke Chisel and grab emitted Verilog.
def getVerilog(dut: => chisel3.core.UserModule): String = {
import firrtl._
return chisel3.Driver.execute(Array[String](), { () => dut }) match {
case s: chisel3.ChiselExecutionSuccess => s.firrtlResultOption match {
case Some(f: FirrtlExecutionSuccess) => f.emitted
}
}
}
// Convenience function to invoke Chisel and grab emitted FIRRTL.
def getFirrtl(dut: => chisel3.core.UserModule): String = {
return chisel3.Driver.emit({ () => dut })
}
def compileFIRRTL(
inputFirrtl: String,
compiler: firrtl.Compiler,
customTransforms: Seq[firrtl.Transform] = Seq.empty,
infoMode: firrtl.Parser.InfoMode = firrtl.Parser.IgnoreInfo,
annotations: firrtl.AnnotationSeq = firrtl.AnnotationSeq(Seq.empty)
): String = {
import firrtl.{Compiler, AnnotationSeq, CircuitState, ChirrtlForm, FIRRTLException}
import firrtl.Parser._
import scala.io.Source
import scala.util.control.ControlThrowable
import firrtl.passes._
val outputBuffer = new java.io.CharArrayWriter
try {
//val parsedInput = firrtl.Parser.parse(Source.fromFile(input).getLines(), infoMode)
val parsedInput = firrtl.Parser.parse(inputFirrtl.split("\n").toIterator, infoMode)
compiler.compile(
CircuitState(parsedInput, ChirrtlForm, annotations),
outputBuffer,
customTransforms)
}
catch {
// Rethrow the exceptions which are expected or due to the runtime environment (out of memory, stack overflow)
case p: ControlThrowable => throw p
case p: PassException => throw p
case p: FIRRTLException => throw p
// Treat remaining exceptions as internal errors.
case e: Exception => firrtl.Utils.throwInternalError(exception = Some(e))
}
val outputString = outputBuffer.toString
outputString
}
def stringifyAST(firrtlAST: firrtl.ir.Circuit): String = {
var ntabs = 0
val buf = new StringBuilder
val string = firrtlAST.toString
string.zipWithIndex.foreach { case (c, idx) =>
c match {
case ' ' =>
case '(' =>
ntabs += 1
buf ++= "(\n" + "| " * ntabs
case ')' =>
ntabs -= 1
buf ++= "\n" + "| " * ntabs + ")"
case ',' => buf ++= ",\n" + "| " * ntabs
case c if idx > 0 && string(idx - 1) == ')' =>
buf ++= "\n" + "| " * ntabs + c
case c => buf += c
}
}
buf.toString
}
def main(args: Array[String]): Unit = {
chisel3.Driver.execute(Array[String](), () => new Accumulator())
chisel3.Driver.execute(Array[String](), () => new Adder(12))
chisel3.Driver.execute(Array[String](), () => new Counter())
chisel3.Driver.execute(Array[String](), () => new DynamicMemorySearch(10, 8))
chisel3.Driver.execute(Array[String](), () => new Max2())
chisel3.Driver.execute(Array[String](), () => new MaxN(10, 8))
chisel3.Driver.execute(Array[String](), () => new Memo())
chisel3.Driver.execute(Array[String](), () => new Mul())
chisel3.Driver.execute(Array[String](), () => new Mux4())
chisel3.Driver.execute(Array[String](), () => new RealGCD())
chisel3.Driver.execute(Array[String](), () => new VecShiftRegister())
chisel3.Driver.execute(Array[String](), () => new VecShiftRegisterParam(10, 8))
chisel3.Driver.execute(Array[String](), () => new VecShiftRegisterSimple())
chisel3.Driver.execute(Array[String](), () => new VendingMachine())
chisel3.Driver.execute(Array[String](), () => new VendingMachineSwitch())
chisel3.Driver.execute(Array[String](), () => new MyOperators())
chisel3.Driver.execute(Array[String](), () => new LastConnect())
chisel3.Driver.execute(Array[String](), () => new Max3())
chisel3.Driver.execute(Array[String](), () => new Sort4())
chisel3.Driver.execute(Array[String](), () => new GCD())
chisel3.Driver.execute(Array[String](), () => new LFSR16())
//println(getVerilog(new GCD))
}
}