aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJack2015-10-06 16:03:48 -0700
committerJack2015-10-06 16:03:48 -0700
commit45946bba6942378970ae42502f7b2829c2d3c58f (patch)
treef114016cb92250c37cd6e0e9f672c95daa1dea2a
parent0a9dfbe9f58338fc8af11015f6e9227e0cb46ea4 (diff)
Added ability to test scala FIRRTL
-rw-r--r--Makefile22
-rw-r--r--build.sbt23
-rw-r--r--project/assembly.sbt1
-rw-r--r--src/main/scala/firrtl/Test.scala61
-rw-r--r--test/parser/gcd.fir52
-rwxr-xr-xutils/bin/firrtl-scala7
6 files changed, 156 insertions, 10 deletions
diff --git a/Makefile b/Makefile
index 3085bfaa..9e67e3e1 100644
--- a/Makefile
+++ b/Makefile
@@ -20,13 +20,13 @@ install-mac:
cd src/lib/stanza && sudo ./stanza -platform os-x -install /usr/local/bin/stanza
build-deploy:
- cd $(firrtl_dir) && stanza -i firrtl-main.stanza -o $(root_dir)/utils/bin/firrtl
+ cd $(firrtl_dir) && stanza -i firrtl-main.stanza -o $(root_dir)/utils/bin/firrtl-stanza
build:
- cd $(firrtl_dir) && stanza -i firrtl-test-main.stanza -o $(root_dir)/utils/bin/firrtl
+ cd $(firrtl_dir) && stanza -i firrtl-test-main.stanza -o $(root_dir)/utils/bin/firrtl-stanza
build-fast:
- cd $(firrtl_dir) && stanza -i firrtl-test-main.stanza -o $(root_dir)/utils/bin/firrtl -flags OPTIMIZE
+ cd $(firrtl_dir) && stanza -i firrtl-test-main.stanza -o $(root_dir)/utils/bin/firrtl-stanza -flags OPTIMIZE
check:
cd $(test_dir) && lit -v . --path=$(root_dir)/utils/bin/
@@ -66,4 +66,18 @@ done: build check
fail:
say "fail"
-.PHONY: all install build-deploy build check clean fail succeed regress
+# Scala Added Makefile commands
+
+build-scala:
+ sbt "assembly"
+
+test-scala:
+ cd $(test_dir)/parser && lit -v . --path=$(root_dir)/utils/bin/
+
+set-scala:
+ ln -f -s $(root_dir)/utils/bin/firrtl-scala $(root_dir)/utils/bin/firrtl
+
+set-stanza:
+ ln -f -s $(root_dir)/utils/bin/firrtl-stanza $(root_dir)/utils/bin/firrtl
+
+.PHONY: all install build-deploy build check clean fail succeed regress set-scala set-stanza build-scala
diff --git a/build.sbt b/build.sbt
index 0a083994..dcc38280 100644
--- a/build.sbt
+++ b/build.sbt
@@ -1,9 +1,20 @@
-lazy val root = (project in file(".")).
- settings(
- name := "firrtl",
- version := "1.0",
- scalaVersion := "2.11.4"
- )
+organization := "edu.berkeley.cs"
+
+name := "firrtl"
+
+version := "0.1-SNAPSHOT"
+
+scalaVersion := "2.11.4"
+
+// Assembly
+
+assemblyJarName in assembly := "firrtl.jar"
+
+test in assembly := {} // Should there be tests?
+
+assemblyOutputPath in assembly := file("./utils/bin/firrtl.jar")
+
+// ANTLRv4
antlr4Settings
diff --git a/project/assembly.sbt b/project/assembly.sbt
new file mode 100644
index 00000000..a815d584
--- /dev/null
+++ b/project/assembly.sbt
@@ -0,0 +1 @@
+addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.14.0")
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)
+ }
+ }
+}
diff --git a/test/parser/gcd.fir b/test/parser/gcd.fir
new file mode 100644
index 00000000..03eb6ba9
--- /dev/null
+++ b/test/parser/gcd.fir
@@ -0,0 +1,52 @@
+; RUN: firrtl -i %s -o %s.out -X HighFIRRTL && cat %s.out | FileCheck %s
+circuit GCD :
+ module GCD :
+ input e : UInt<1>
+ input clk : Clock
+ input reset : UInt<1>
+ output z : UInt<16>
+ output v : UInt<1>
+ input a : UInt<16>
+ input b : UInt<16>
+
+ reg x : UInt<16>,clk,reset
+ reg y : UInt<16>,clk,reset
+ node T_17 = gt(x, y)
+ when T_17 :
+ node T_18 = subw(x, y)
+ x := T_18
+ else :
+ node T_19 = subw(y, x)
+ y := T_19
+ when e :
+ x := a
+ y := b
+ z := x
+ node T_20 = eq(y, UInt<1>(0))
+ v := T_20
+
+; CHECK: circuit GCD :
+; CHECK: module GCD :
+; CHECK: input e : UInt<1>
+; CHECK: input clk : Clock
+; CHECK: input reset : UInt<1>
+; CHECK: output z : UInt<16>
+; CHECK: output v : UInt<1>
+; CHECK: input a : UInt<16>
+; CHECK: input b : UInt<16>
+; CHECK: reg x : UInt<16>, clk, reset
+; CHECK: reg y : UInt<16>, clk, reset
+; CHECK: node T_17 = gt(x, y)
+; CHECK: when T_17 :
+; CHECK: node T_18 = subw(x, y)
+; CHECK: x := T_18
+; CHECK: else :
+; CHECK: node T_19 = subw(y, x)
+; CHECK: y := T_19
+; CHECK: when e :
+; CHECK: x := a
+; CHECK: y := b
+; CHECK: z := x
+; CHECK: node T_20 = eq(y, UInt<1>("h00"))
+; CHECK: v := T_20
+
diff --git a/utils/bin/firrtl-scala b/utils/bin/firrtl-scala
new file mode 100755
index 00000000..4d208178
--- /dev/null
+++ b/utils/bin/firrtl-scala
@@ -0,0 +1,7 @@
+#!/bin/bash
+
+# This may be a brittle way to find $(root_dir)/utils/bin, is there a better way?
+path=`dirname "$0"`
+cmd="java -cp ${path}/firrtl.jar firrtl.Test ${@:1}"
+eval $cmd
+