aboutsummaryrefslogtreecommitdiff
path: root/src/main/scala/firrtl
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/scala/firrtl')
-rw-r--r--src/main/scala/firrtl/Parser.scala23
-rw-r--r--src/main/scala/firrtl/Translator.scala24
2 files changed, 36 insertions, 11 deletions
diff --git a/src/main/scala/firrtl/Parser.scala b/src/main/scala/firrtl/Parser.scala
index 35e41222..40956ab7 100644
--- a/src/main/scala/firrtl/Parser.scala
+++ b/src/main/scala/firrtl/Parser.scala
@@ -11,6 +11,29 @@ import antlr._
object Parser
{
+ def parseModule(string: String): Module = {
+ val fixedInput = Translator.addBrackets(Iterator(string))
+ val antlrStream = new ANTLRInputStream(fixedInput.result)
+ val lexer = new FIRRTLLexer(antlrStream)
+ val tokens = new CommonTokenStream(lexer)
+ val parser = new FIRRTLParser(tokens)
+
+ // FIXME Dangerous
+ parser.getInterpreter.setPredictionMode(PredictionMode.SLL)
+
+ // Concrete Syntax Tree
+ val cst = parser.module
+
+ val visitor = new Visitor("none")
+ //val ast = visitor.visitCircuit(cst) match {
+ val ast = visitor.visit(cst) match {
+ case m: Module => m
+ case x => throw new ClassCastException("Error! AST not rooted with Module node!")
+ }
+
+ ast
+
+ }
/** Takes a firrtl filename, returns AST (root node is Circuit)
*
diff --git a/src/main/scala/firrtl/Translator.scala b/src/main/scala/firrtl/Translator.scala
index 152cd88e..e7bd6821 100644
--- a/src/main/scala/firrtl/Translator.scala
+++ b/src/main/scala/firrtl/Translator.scala
@@ -31,19 +31,21 @@ object Translator
if( !it.hasNext ) throw new Exception("Empty file!")
- // Find circuit before starting scope checks
- var line = it.next
- while ( it.hasNext && !line._1.contains("circuit") ) {
- ret ++= line._1 + "\n"
- line = it.next
- }
- ret ++= line._1 + " { \n"
- if( !it.hasNext ) throw new Exception("No circuit in file!")
+ //// Find circuit before starting scope checks
+ //var line = it.next
+ //while ( it.hasNext && !line._1.contains("circuit") ) {
+ // ret ++= line._1 + "\n"
+ // line = it.next
+ //}
+ //ret ++= line._1 + " { \n"
+ //if( !it.hasNext ) throw new Exception("No circuit in file!")
val scope = Stack[Int]()
- scope.push(countSpaces(line._1))
- var newScope = true // indicates if increasing scope spacing is legal on next line
+ scope.push(0)
+ var newScope = false
+ //scope.push(countSpaces(line._1))
+ //var newScope = true // indicates if increasing scope spacing is legal on next line
while( it.hasNext ) {
it.next match { case (lineText, lineNum) =>
@@ -52,7 +54,7 @@ object Translator
val l = if (text.length > spaces ) { // Check that line has text in it
if (newScope) {
- if( spaces == scope.top ) scope.push(spaces+2) // Hack for one-line scopes
+ if( spaces <= scope.top ) scope.push(spaces+2) // Hack for one-line scopes
else scope.push(spaces)
}