From 45946bba6942378970ae42502f7b2829c2d3c58f Mon Sep 17 00:00:00 2001 From: Jack Date: Tue, 6 Oct 2015 16:03:48 -0700 Subject: Added ability to test scala FIRRTL --- src/main/scala/firrtl/Test.scala | 61 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 src/main/scala/firrtl/Test.scala (limited to 'src/main/scala/firrtl/Test.scala') 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 -o + """ + 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) + } + } +} -- cgit v1.2.3 From bf4488870e1def4d76297dd8fdd795a82bc4ded3 Mon Sep 17 00:00:00 2001 From: Jack Date: Mon, 12 Oct 2015 17:38:12 -0700 Subject: Added initial support for debug printing for lit based testing, most types of printVars still missing. Added Logger class for debug printing --- src/main/scala/firrtl/Test.scala | 60 ++++++++++++++++++++++++++++++++++------ 1 file changed, 52 insertions(+), 8 deletions(-) (limited to 'src/main/scala/firrtl/Test.scala') diff --git a/src/main/scala/firrtl/Test.scala b/src/main/scala/firrtl/Test.scala index 09329685..b1e45762 100644 --- a/src/main/scala/firrtl/Test.scala +++ b/src/main/scala/firrtl/Test.scala @@ -6,17 +6,18 @@ import Utils._ object Test { private val usage = """ - Usage: java -jar firrtl.jar firrtl.Test [options] -i -o + Usage: java -cp utils/bin/firrtl.jar firrtl.Test [options] -i -o """ private val defaultOptions = Map[Symbol, Any]().withDefaultValue(false) // Parse input file and print to output - private def highFIRRTL(input: String, output: String) + private def highFIRRTL(input: String, output: String, logger: Logger) { val ast = Parser.parse(input) val writer = new PrintWriter(new File(output)) - writer.write(ast.serialize) + writer.write(ast.serialize()) writer.close() + logger.printDebug(ast) } def main(args: Array[String]) @@ -24,24 +25,54 @@ object Test val arglist = args.toList type OptionMap = Map[Symbol, Any] + // Default debug mode is 'debug + def decodeDebugMode(mode: Any): Symbol = + mode match { + case s: String => Symbol(s) + case _ => 'debug + } + + def nextPrintVar(syms: List[Symbol], chars: List[Char]): List[Symbol] = + chars match { + case Nil => syms + case 't' :: tail => nextPrintVar(syms ++ List('types), tail) + case 'k' :: tail => nextPrintVar(syms ++ List('kinds), tail) + case 'w' :: tail => nextPrintVar(syms ++ List('widths), tail) + case 'T' :: tail => nextPrintVar(syms ++ List('twidths), tail) + case 'g' :: tail => nextPrintVar(syms ++ List('genders), tail) + case 'c' :: tail => nextPrintVar(syms ++ List('circuit), tail) + case 'd' :: tail => nextPrintVar(syms ++ List('debug), tail) // Currently ignored + case 'i' :: tail => nextPrintVar(syms ++ List('info), tail) + case char :: tail => throw new Exception("Unknown print option " + char) + } + 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 "-d" :: value :: tail => + nextOption(map ++ Map('debugMode -> value), tail) + case "-l" :: value :: tail => + nextOption(map ++ Map('log -> value), tail) + case "-p" :: value :: tail => + nextOption(map ++ Map('printVars -> value), tail) case "-i" :: value :: tail => nextOption(map ++ Map('input -> value), tail) case "-o" :: value :: tail => nextOption(map ++ Map('output -> value), tail) + case ("-h" | "--help") :: tail => + nextOption(map ++ Map('help -> true), tail) case option :: tail => throw new Exception("Unknown option " + option) } } val options = nextOption(defaultOptions, arglist) - println(options) + + if (options('help) == true) { + println(usage) + System.exit(0) + } val input = options('input) match { case s: String => s @@ -51,10 +82,23 @@ object Test case s: String => s case false => throw new Exception("No output file provided!" + usage) } + val debugMode = decodeDebugMode(options('debugMode)) + val printVars = options('printVars) match { + case s: String => nextPrintVar(List(), s.toList) + case false => List() + } + implicit val logger = options('log) match { + case s: String => Logger(new PrintWriter(new FileOutputStream(s)), debugMode, printVars) + case false => Logger(new PrintWriter(System.out, true), debugMode, printVars) + } + + // -p "printVars" options only print for debugMode > 'debug, warn if -p enabled and debugMode < 'debug + if( !logger.debugEnable && !printVars.isEmpty ) + logger.warn("-p options will not print unless debugMode (-d) is debug or trace") options('compiler) match { case "Verilog" => throw new Exception("Verilog compiler not currently supported!") - case "HighFIRRTL" => highFIRRTL(input, output) + case "HighFIRRTL" => highFIRRTL(input, output, logger) case other => throw new Exception("Invalid compiler! " + other) } } -- cgit v1.2.3 From 9b737de6551e7446dfd92d86cd009b4b2f95c980 Mon Sep 17 00:00:00 2001 From: Jack Date: Wed, 14 Oct 2015 13:53:22 -0700 Subject: Moved Logger to new private object DebugUtils, changed UInt/SInt value printing to match stanza implementation --- src/main/scala/firrtl/Test.scala | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) (limited to 'src/main/scala/firrtl/Test.scala') diff --git a/src/main/scala/firrtl/Test.scala b/src/main/scala/firrtl/Test.scala index b1e45762..86c3616a 100644 --- a/src/main/scala/firrtl/Test.scala +++ b/src/main/scala/firrtl/Test.scala @@ -2,6 +2,7 @@ package firrtl import java.io._ import Utils._ +import DebugUtils._ object Test { @@ -11,7 +12,7 @@ object Test private val defaultOptions = Map[Symbol, Any]().withDefaultValue(false) // Parse input file and print to output - private def highFIRRTL(input: String, output: String, logger: Logger) + private def highFIRRTL(input: String, output: String)(implicit logger: Logger) { val ast = Parser.parse(input) val writer = new PrintWriter(new File(output)) @@ -19,6 +20,21 @@ object Test writer.close() logger.printDebug(ast) } + private def verilog(input: String, output: String)(implicit logger: Logger) + { + logger.warn("Verilog compiler not fully implemented") + val ast = time("parse"){ Parser.parse(input) } + // Execute passes + //val ast2 = time("inferTypes"){ inferTypes(ast) } + val ast2 = ast + + // Output + val writer = new PrintWriter(new File(output)) + var outString = time("serialize"){ ast2.serialize() } + writer.write(outString) + writer.close() + logger.printDebug(ast2) + } def main(args: Array[String]) { @@ -89,7 +105,7 @@ object Test } implicit val logger = options('log) match { case s: String => Logger(new PrintWriter(new FileOutputStream(s)), debugMode, printVars) - case false => Logger(new PrintWriter(System.out, true), debugMode, printVars) + case false => Logger(new PrintWriter(System.err, true), debugMode, printVars) } // -p "printVars" options only print for debugMode > 'debug, warn if -p enabled and debugMode < 'debug @@ -97,9 +113,17 @@ object Test logger.warn("-p options will not print unless debugMode (-d) is debug or trace") options('compiler) match { - case "Verilog" => throw new Exception("Verilog compiler not currently supported!") - case "HighFIRRTL" => highFIRRTL(input, output, logger) + case "verilog" => verilog(input, output) + case "HighFIRRTL" => highFIRRTL(input, output) case other => throw new Exception("Invalid compiler! " + other) } } + + def time[R](str: String)(block: => R)(implicit logger: Logger): R = { + val t0 = System.currentTimeMillis() + val result = block // call-by-name + val t1 = System.currentTimeMillis() + logger.info(s"Time to ${str}: ${t1 - t0} ms") + result + } } -- cgit v1.2.3 From 7a7936c8fbddbffc1c4775fafeb5106ba1002dd4 Mon Sep 17 00:00:00 2001 From: Jack Date: Thu, 15 Oct 2015 13:50:36 -0700 Subject: Added infer-types pass, seems to work. Added infer-types error checking, modified Logger slightly, added Primops object for utility functions, minor changes in Utils --- src/main/scala/firrtl/Test.scala | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'src/main/scala/firrtl/Test.scala') diff --git a/src/main/scala/firrtl/Test.scala b/src/main/scala/firrtl/Test.scala index 86c3616a..3a89aeef 100644 --- a/src/main/scala/firrtl/Test.scala +++ b/src/main/scala/firrtl/Test.scala @@ -3,6 +3,7 @@ package firrtl import java.io._ import Utils._ import DebugUtils._ +import Passes._ object Test { @@ -18,22 +19,25 @@ object Test val writer = new PrintWriter(new File(output)) writer.write(ast.serialize()) writer.close() - logger.printDebug(ast) + logger.printlnDebug(ast) } private def verilog(input: String, output: String)(implicit logger: Logger) { logger.warn("Verilog compiler not fully implemented") val ast = time("parse"){ Parser.parse(input) } // Execute passes - //val ast2 = time("inferTypes"){ inferTypes(ast) } - val ast2 = ast + + logger.println("Infer Types") + val ast2 = time("inferTypes"){ inferTypes(ast) } + logger.printlnDebug(ast2) + logger.println("Finished Infer Types") + //val ast2 = ast // Output val writer = new PrintWriter(new File(output)) var outString = time("serialize"){ ast2.serialize() } writer.write(outString) writer.close() - logger.printDebug(ast2) } def main(args: Array[String]) -- cgit v1.2.3