From 8c1c4225c340dc658f7d0956e8b231050c122abc Mon Sep 17 00:00:00 2001 From: azidar Date: Thu, 19 Feb 2015 08:28:54 -0800 Subject: Added compiler flags to allow tests to select which passes they test. Changed package names from chipper to firrtl --- .gitignore | 1 + Makefile | 11 +++------- src/main/stanza/firrtl-ir.stanza | 2 +- src/main/stanza/firrtl-main.stanza | 27 ++++------------------- src/main/stanza/ir-parser.stanza | 4 ++-- src/main/stanza/ir-utils.stanza | 26 ++++++++++++++++++++-- src/main/stanza/passes.stanza | 44 ++++++++++++++++++++------------------ test/unit/gcd.fir | 4 ++++ test/unit/simple.fir | 2 +- 9 files changed, 63 insertions(+), 58 deletions(-) diff --git a/.gitignore b/.gitignore index 9861eaad..71d91bfd 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,4 @@ src/*/__MACOSX src/main/stanza/firrtl-main utils/bin/firrtl test/unit/Output +test/unit/*.out diff --git a/Makefile b/Makefile index cf869d2b..cf8c0c22 100644 --- a/Makefile +++ b/Makefile @@ -1,22 +1,17 @@ # Installs stanza into /usr/local/bin # TODO Talk to Patrick to fill this in root_dir ?= $(PWD) -test_src_dir ?= $(root_dir)/test/unit -test_out_dir ?= $(root_dir)/test/unit/out +test_dir ?= $(root_dir)/test firrtl_dir ?= $(root_dir)/src/main/stanza all: build check install-stanza: - - build: cd $(firrtl_dir) && stanzam -i firrtl-main.stanza -o $(root_dir)/utils/bin/firrtl # Runs single test check: - ./firrtl $(test_src_dir)/gcd.fir | tee $(test_out_dir)/gcd.out - -diff: - diff test/unit/out/* test/unit/cor/* + cd $(test_dir) && lit -v . --path=$(root_dir)/utils/bin/ + cat $(test_dir)/unit/gcd.fir.out diff --git a/src/main/stanza/firrtl-ir.stanza b/src/main/stanza/firrtl-ir.stanza index d924bdef..53902c1c 100644 --- a/src/main/stanza/firrtl-ir.stanza +++ b/src/main/stanza/firrtl-ir.stanza @@ -1,4 +1,4 @@ -defpackage chipper.ir2 : +defpackage firrtl.ir2 : import core import verse diff --git a/src/main/stanza/firrtl-main.stanza b/src/main/stanza/firrtl-main.stanza index 17672f3d..e8e01fd5 100644 --- a/src/main/stanza/firrtl-main.stanza +++ b/src/main/stanza/firrtl-main.stanza @@ -12,38 +12,19 @@ include("widthsolver.stanza") defpackage chmain : import core import verse - import chipper.parser - import chipper.passes + import firrtl.parser + import firrtl.passes import stanza.lexer import stanza.parser + import firrtl.ir-utils -defn split (s:String,c:Char) -> List : - val empty = "" - - defn next-word (s:String,i:Int) -> String|False : - if i == length(s) : false - else: - if (s[i] == c): substring(s,0,i) - else: next-word(s,i + 1) - - val next-str = next-word(s,0) - if next-str == false : list() - else if next-str == empty : split(substring(s,1,length(s)),c) - else : - val str = next-str as String - List(str,split(substring(s,length(str)+1,length(s)),c)) - defn main () : val arg = commandline-arguments() - println(arg) val args = split(arg,' ') - println(args) - println(length(args)) - val lexed = lex-file(args[1]) val c = parse-firrtl(lexed) println(c) - run-passes(c) + run-passes(c,to-list(args[2])) main() diff --git a/src/main/stanza/ir-parser.stanza b/src/main/stanza/ir-parser.stanza index 679f1362..176a812c 100644 --- a/src/main/stanza/ir-parser.stanza +++ b/src/main/stanza/ir-parser.stanza @@ -1,7 +1,7 @@ -defpackage chipper.parser : +defpackage firrtl.parser : import core import verse - import chipper.ir2 + import firrtl.ir2 import stanza.rdparser import stanza.lexer diff --git a/src/main/stanza/ir-utils.stanza b/src/main/stanza/ir-utils.stanza index 9eac350c..7edbcb1c 100644 --- a/src/main/stanza/ir-utils.stanza +++ b/src/main/stanza/ir-utils.stanza @@ -1,7 +1,7 @@ -defpackage chipper.ir-utils : +defpackage firrtl.ir-utils : import core import verse - import chipper.ir2 + import firrtl.ir2 ;============== PRINTERS =================================== defmethod print (o:OutputStream, d:Direction) : @@ -227,3 +227,25 @@ defmethod children (c:Stmt) : (c:Begin) : body(c) (c) : List() +;=================== STRING OPS =============================== +public defn split (s:String,c:Char) -> List : + val empty = "" + defn next-word (s:String,i:Int) -> String|False : + if i == length(s) : false + else: + if (s[i] == c): substring(s,0,i) + else: next-word(s,i + 1) + + val next-str = next-word(s,0) + if next-str == false : list() + else if next-str == empty : split(substring(s,1,length(s)),c) + else : + val str = next-str as String + List(str,split(substring(s,length(str)+1,length(s)),c)) + +public defn contains (l:List, c:Char) : + label myret : + for x in l do : + if x == c : myret(true) + false + diff --git a/src/main/stanza/passes.stanza b/src/main/stanza/passes.stanza index 03a9583b..6051ac8d 100644 --- a/src/main/stanza/passes.stanza +++ b/src/main/stanza/passes.stanza @@ -1,8 +1,8 @@ -defpackage chipper.passes : +defpackage firrtl.passes : import core import verse - import chipper.ir2 - import chipper.ir-utils + import firrtl.ir2 + import firrtl.ir-utils import widthsolver ;============== EXCEPTIONS ================================= @@ -1856,28 +1856,30 @@ defn inline-instances (c:Circuit) : ;============= DRIVER ====================================== -public defn run-passes (c: Circuit) : +public defn run-passes (c: Circuit, p: List) : var c*:Circuit = c defn do-stage (name:String, f: Circuit -> Circuit) : println(name) c* = f(c*) - println(c*) - println("\n\n\n\n") - - do-stage("Working IR", to-working-ir) - do-stage("Resolve Kinds", resolve-kinds) - ;do-stage("Make Explicit Reset", make-explicit-reset) - ;do-stage("Infer Types", infer-types) - ;do-stage("Infer Directions", infer-directions) - ;do-stage("Expand Accessors", expand-accessors) - ;do-stage("Flatten Bundles", flatten-bundles) - ;do-stage("Expand Bundles", expand-bundles) - ;do-stage("Expand Multi Connects", expand-multi-connects) - ;do-stage("Expand Whens", expand-whens) - ;do-stage("Structural Form", structural-form) - ;do-stage("Infer Widths", infer-widths) - ;do-stage("Pad Widths", pad-widths) - ;do-stage("Inline Instances", inline-instances) + + + if contains(p,'a') : do-stage("Working IR", to-working-ir) + if contains(p,'b') : do-stage("Resolve Kinds", resolve-kinds) + if contains(p,'c') : do-stage("Make Explicit Reset", make-explicit-reset) + if contains(p,'d') : do-stage("Infer Types", infer-types) + if contains(p,'e') : do-stage("Infer Directions", infer-directions) + if contains(p,'f') : do-stage("Expand Accessors", expand-accessors) + if contains(p,'g') : do-stage("Flatten Bundles", flatten-bundles) + if contains(p,'h') : do-stage("Expand Bundles", expand-bundles) + if contains(p,'i') : do-stage("Expand Multi Connects", expand-multi-connects) + if contains(p,'j') : do-stage("Expand Whens", expand-whens) + if contains(p,'k') : do-stage("Structural Form", structural-form) + if contains(p,'l') : do-stage("Infer Widths", infer-widths) + if contains(p,'m') : do-stage("Pad Widths", pad-widths) + if contains(p,'n') : do-stage("Inline Instances", inline-instances) + + println(c*) + println("\n\n\n\n") ;; println("Shim for Jonathan's Passes") diff --git a/test/unit/gcd.fir b/test/unit/gcd.fir index 1d4d54af..1da09070 100644 --- a/test/unit/gcd.fir +++ b/test/unit/gcd.fir @@ -1,9 +1,12 @@ +; RUN: firrtl %s ab | tee %s.out | FileCheck %s + circuit top : module subtracter : input x : UInt input y : UInt output z : UInt z := sub-mod(x, y) +; CHECK: port:z := sub-mod(port:x, port:y) module gcd : input a : UInt(16) input b : UInt(16) @@ -17,6 +20,7 @@ circuit top : when greater(x, y) : inst s of subtracter s.x := x +; CHECK: inst:s.x := reg:x s.y := y x := s.z else : diff --git a/test/unit/simple.fir b/test/unit/simple.fir index 01389604..d00f8f7a 100644 --- a/test/unit/simple.fir +++ b/test/unit/simple.fir @@ -1,4 +1,4 @@ -; RUN: firrtl %s | FileCheck %s +; RUN: firrtl %s ab | tee %s.out | FileCheck %s circuit top : module subtracter : -- cgit v1.2.3