From 50b5ce57d1b823a03725dd0aa2141f300c244bf1 Mon Sep 17 00:00:00 2001 From: azidar Date: Wed, 18 Feb 2015 17:20:11 -0800 Subject: Added more testing infrastructre, and Makefile to build firrtl --- .gitignore | 2 ++ Makefile | 20 ++++++++++++++++ README.md | 3 +++ notes/notes.02.17.15.txt | 4 ++++ notes/notes.02.18.15.txt | 11 +++++++++ src/main/stanza/firrtl-main.stanza | 47 +++++++++++++++++++++++++++++++++++-- src/main/stanza/passes.stanza | 36 +++++++++++++++++----------- src/test/firrtl/firrtl-test.txt | 40 ------------------------------- test/lit.cfg | 4 ++++ test/unit/gcd.fir | 42 +++++++++++++++++++++++++++++++++ test/unit/hello.fir | 2 ++ test/unit/simple.fir | 11 +++++++++ utils/bin/FileCheck | Bin 0 -> 1017048 bytes 13 files changed, 166 insertions(+), 56 deletions(-) create mode 100644 notes/notes.02.18.15.txt delete mode 100644 src/test/firrtl/firrtl-test.txt create mode 100644 test/lit.cfg create mode 100644 test/unit/gcd.fir create mode 100644 test/unit/hello.fir create mode 100644 test/unit/simple.fir create mode 100755 utils/bin/FileCheck diff --git a/.gitignore b/.gitignore index 335be9e9..9861eaad 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,5 @@ src/*/*/*/*.DS_STORE src/lib/stanzam src/*/__MACOSX src/main/stanza/firrtl-main +utils/bin/firrtl +test/unit/Output diff --git a/Makefile b/Makefile index 139597f9..cf869d2b 100644 --- a/Makefile +++ b/Makefile @@ -1,2 +1,22 @@ +# 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 +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/* diff --git a/README.md b/README.md index 280b623a..5db5bc8f 100644 --- a/README.md +++ b/README.md @@ -15,3 +15,6 @@ Work TODO: Secondary TODO: Need stanza version control - perhaps a sub-repo? + +Install lit: + pip install lit diff --git a/notes/notes.02.17.15.txt b/notes/notes.02.17.15.txt index 21919621..133565fd 100644 --- a/notes/notes.02.17.15.txt +++ b/notes/notes.02.17.15.txt @@ -24,3 +24,7 @@ Make stanza a git repo Write Makefile Write installation instructions for stanza Add P-Money as admin to github/firrtl (CuppoJava) + +TOTHINK +Need 2 different prints, one with IR-internal information, and another that matches correct FIRRTL +Add input file argument... diff --git a/notes/notes.02.18.15.txt b/notes/notes.02.18.15.txt new file mode 100644 index 00000000..c3d0d638 --- /dev/null +++ b/notes/notes.02.18.15.txt @@ -0,0 +1,11 @@ +unit tests +end-to-end +full programs + +dir structure + +firrtl/lib + +llvm's lit is probably overkill, but should have execution command in code, and use llvm's FileCheck to verify correctness of test + + diff --git a/src/main/stanza/firrtl-main.stanza b/src/main/stanza/firrtl-main.stanza index 574fb101..17672f3d 100644 --- a/src/main/stanza/firrtl-main.stanza +++ b/src/main/stanza/firrtl-main.stanza @@ -17,10 +17,53 @@ defpackage chmain : import stanza.lexer import stanza.parser +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 lexed = lex-file("../../test/firrtl/firrtl-test.txt") + 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) main() + +; [a b c] <- a tuple +; +; val rest = List(1,2,3) +; val b = List(0,rest) --> (0,1,2,3) +; val c = list(0,rest) --> (0,(1,2,3)) + +; label myret : +; for i in 0 to 10 do : +; if i == 5: +; myret(i) +; 0 + +; val v = Vector() +; add(v,10) +; add(v,20) +; add(v,32) +; for x in v do : +; println(x) + + diff --git a/src/main/stanza/passes.stanza b/src/main/stanza/passes.stanza index d5464d84..03a9583b 100644 --- a/src/main/stanza/passes.stanza +++ b/src/main/stanza/passes.stanza @@ -61,6 +61,18 @@ defmethod print (o:OutputStream, k:Kind) : (k:InstanceKind) : "inst:" (k:StructuralMemKind) : "smem:" +defmethod print (o:OutputStream, e:WRef) : + print-all(o,[kind(e) name(e)]) + +defmethod print (o:OutputStream, e:WField) : + print-all(o,[exp(e) "." name(e)]) + +defmethod print (o:OutputStream, e:WIndex) : + print-all(o,[exp(e) "." value(e)]) + +defmethod print (o:OutputStream, s:WDefAccessor) : + print-all(o,[dir(s) " accessor " name(s) " = " source(s) "[" index(s) "]"]) + defmethod map (f: Expression -> Expression, e: WField) : WField(f(exp(e)), name(e), type(e), dir(e)) @@ -75,7 +87,10 @@ defmulti dir (e:Expression) -> Direction defmethod dir (e:Expression) : OUTPUT -;ADAM========== Bring to Working IR ======================== +;================= Bring to Working IR ======================== +; Returns a new Circuit with Refs, Fields, Indexes and DefAccessors +; replaced with IR-internal nodes that contain additional +; information (kind, direction) defn to-working-ir (c:Circuit) : defn to-exp (e:Expression) : @@ -94,19 +109,12 @@ defn to-working-ir (c:Circuit) : for m in modules(c) map : Module(name(m), ports(m), to-stmt(body(m))) -;ADAM========== Printing =================================== - -defn print (o:OutputStream, e:WRef) : - print-all(o,[name(e)]) -defmethod print (o:OutputStream, e:WField) : - print-all(o,[exp(e) "." name(e)]) -defmethod print (o:OutputStream, e:WIndex) : - print-all(o,[exp(e) "." value(e)]) - -defmethod print (o:OutputStream, s:WDefAccessor) : - print-all(o,[dir(s) " accessor " name(s) " = " source(s) "[" index(s) "]"]) - ;=============== Resolve Kinds ============================= +; It is useful for the compiler to know information about +; objects referenced. This information is stored in the kind +; field in WRef. This pass walks the graph and returns a new +; Circuit where all WRef kinds are resolved + defn resolve-kinds (c:Circuit) : defn resolve-exp (e:Expression, kinds:HashTable) : match(e) : @@ -1858,7 +1866,7 @@ public defn run-passes (c: Circuit) : do-stage("Working IR", to-working-ir) do-stage("Resolve Kinds", resolve-kinds) - do-stage("Make Explicit Reset", make-explicit-reset) + ;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) diff --git a/src/test/firrtl/firrtl-test.txt b/src/test/firrtl/firrtl-test.txt deleted file mode 100644 index 1f3db390..00000000 --- a/src/test/firrtl/firrtl-test.txt +++ /dev/null @@ -1,40 +0,0 @@ -circuit top : - module subtracter : - input x : UInt - input y : UInt - output z : UInt - z := sub-mod(x, y) - module gcd : - input a : UInt(16) - input b : UInt(16) - input e : UInt(1) - output z : UInt(16) - output v : UInt(1) - reg x : UInt - reg y : UInt - x.init := UInt(0) - y.init := UInt(42) - when greater(x, y) : - inst s of subtracter - s.x := x - s.y := y - x := s.z - else : - inst s2 of subtracter - s2.x := x - s2.y := y - y := s2.z - when e : - x := a - y := b - v := equal(v, UInt(0)) - z := x - module top : - input a : UInt(16) - input b : UInt(16) - output z : UInt - inst i of gcd - i.a := a - i.b := b - i.e := UInt(1) - z := i.z diff --git a/test/lit.cfg b/test/lit.cfg new file mode 100644 index 00000000..71928a43 --- /dev/null +++ b/test/lit.cfg @@ -0,0 +1,4 @@ +import lit.formats + +config.test_format = lit.formats.ShTest() +config.suffixes = ['.fir'] diff --git a/test/unit/gcd.fir b/test/unit/gcd.fir new file mode 100644 index 00000000..1d4d54af --- /dev/null +++ b/test/unit/gcd.fir @@ -0,0 +1,42 @@ +circuit top : + module subtracter : + input x : UInt + input y : UInt + output z : UInt + z := sub-mod(x, y) + module gcd : + input a : UInt(16) + input b : UInt(16) + input e : UInt(1) + output z : UInt(16) + output v : UInt(1) + reg x : UInt + reg y : UInt + x.init := UInt(0) + y.init := UInt(42) + when greater(x, y) : + inst s of subtracter + s.x := x + s.y := y + x := s.z + else : + inst s2 of subtracter + s2.x := x + s2.y := y + y := s2.z + when e : + x := a + y := b + v := equal(v, UInt(0)) + z := x + module top : + input a : UInt(16) + input b : UInt(16) + output z : UInt + inst i of gcd + i.a := a + i.b := b + i.e := UInt(1) + z := i.z + + diff --git a/test/unit/hello.fir b/test/unit/hello.fir new file mode 100644 index 00000000..4a905ab9 --- /dev/null +++ b/test/unit/hello.fir @@ -0,0 +1,2 @@ +# RUN: echo hello | FileCheck %s +# CHECK: hello diff --git a/test/unit/simple.fir b/test/unit/simple.fir new file mode 100644 index 00000000..01389604 --- /dev/null +++ b/test/unit/simple.fir @@ -0,0 +1,11 @@ +; RUN: firrtl %s | FileCheck %s + +circuit top : + module subtracter : + input x : UInt + input y : UInt + output z : UInt + z := sub-mod(x, y) +; CHECK: output z : UInt +; CHECK: port:z := sub-mod(port:x, port:y) + diff --git a/utils/bin/FileCheck b/utils/bin/FileCheck new file mode 100755 index 00000000..2ab52bb6 Binary files /dev/null and b/utils/bin/FileCheck differ -- cgit v1.2.3