aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJack2015-10-06 16:03:48 -0700
committerJack2015-10-06 16:03:48 -0700
commit45946bba6942378970ae42502f7b2829c2d3c58f (patch)
treef114016cb92250c37cd6e0e9f672c95daa1dea2a /src
parent0a9dfbe9f58338fc8af11015f6e9227e0cb46ea4 (diff)
Added ability to test scala FIRRTL
Diffstat (limited to 'src')
-rw-r--r--src/main/scala/firrtl/Test.scala61
1 files changed, 61 insertions, 0 deletions
diff --git a/src/main/scala/firrtl/Test.scala b/src/main/scala/firrtl/Test.scala
new file mode 100644
index 00000000..09329685
--- /dev/null
+++ b/src/main/scala/firrtl/Test.scala
@@ -0,0 +1,61 @@
+package firrtl
+
+import java.io._
+import Utils._
+
+object Test
+{
+ private val usage = """
+ Usage: java -jar firrtl.jar firrtl.Test [options] -i <input> -o <output>
+ """
+ private val defaultOptions = Map[Symbol, Any]().withDefaultValue(false)
+
+ // Parse input file and print to output
+ private def highFIRRTL(input: String, output: String)
+ {
+ val ast = Parser.parse(input)
+ val writer = new PrintWriter(new File(output))
+ writer.write(ast.serialize)
+ writer.close()
+ }
+
+ def main(args: Array[String])
+ {
+ val arglist = args.toList
+ type OptionMap = Map[Symbol, Any]
+
+ def nextOption(map: OptionMap, list: List[String]): OptionMap = {
+ def isSwitch(s: String) = (s(0) == '-')
+ list match {
+ case Nil => map
+ case "-X" :: value :: tail =>
+ nextOption(map ++ Map('compiler -> value), tail)
+ //case "-d" :: tail =>
+ // nextOption(map ++ Map('debug -> true), tail)
+ case "-i" :: value :: tail =>
+ nextOption(map ++ Map('input -> value), tail)
+ case "-o" :: value :: tail =>
+ nextOption(map ++ Map('output -> value), tail)
+ case option :: tail =>
+ throw new Exception("Unknown option " + option)
+ }
+ }
+ val options = nextOption(defaultOptions, arglist)
+ println(options)
+
+ val input = options('input) match {
+ case s: String => s
+ case false => throw new Exception("No input file provided!" + usage)
+ }
+ val output = options('output) match {
+ case s: String => s
+ case false => throw new Exception("No output file provided!" + usage)
+ }
+
+ options('compiler) match {
+ case "Verilog" => throw new Exception("Verilog compiler not currently supported!")
+ case "HighFIRRTL" => highFIRRTL(input, output)
+ case other => throw new Exception("Invalid compiler! " + other)
+ }
+ }
+}