diff options
| author | azidar | 2015-02-18 17:20:11 -0800 |
|---|---|---|
| committer | azidar | 2015-02-18 17:20:11 -0800 |
| commit | 50b5ce57d1b823a03725dd0aa2141f300c244bf1 (patch) | |
| tree | 6fd005a2e07034ff017dfb6bada6b1eeddad2783 | |
| parent | afde65773fc7b19dd99e0c65f718a96d0466541b (diff) | |
Added more testing infrastructre, and Makefile to build firrtl
| -rw-r--r-- | .gitignore | 2 | ||||
| -rw-r--r-- | Makefile | 20 | ||||
| -rw-r--r-- | README.md | 3 | ||||
| -rw-r--r-- | notes/notes.02.17.15.txt | 4 | ||||
| -rw-r--r-- | notes/notes.02.18.15.txt | 11 | ||||
| -rw-r--r-- | src/main/stanza/firrtl-main.stanza | 47 | ||||
| -rw-r--r-- | src/main/stanza/passes.stanza | 36 | ||||
| -rw-r--r-- | test/lit.cfg | 4 | ||||
| -rw-r--r-- | test/unit/gcd.fir (renamed from src/test/firrtl/firrtl-test.txt) | 2 | ||||
| -rw-r--r-- | test/unit/hello.fir | 2 | ||||
| -rw-r--r-- | test/unit/simple.fir | 11 | ||||
| -rwxr-xr-x | utils/bin/FileCheck | bin | 0 -> 1017048 bytes |
12 files changed, 126 insertions, 16 deletions
@@ -9,3 +9,5 @@ src/*/*/*/*.DS_STORE src/lib/stanzam src/*/__MACOSX src/main/stanza/firrtl-main +utils/bin/firrtl +test/unit/Output @@ -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/* @@ -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<String> : + 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<Int> myret : +; for i in 0 to 10 do : +; if i == 5: +; myret(i) +; 0 + +; val v = Vector<Int>() +; 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<Symbol,Kind>) : 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/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/src/test/firrtl/firrtl-test.txt b/test/unit/gcd.fir index 1f3db390..1d4d54af 100644 --- a/src/test/firrtl/firrtl-test.txt +++ b/test/unit/gcd.fir @@ -38,3 +38,5 @@ circuit top : 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 Binary files differnew file mode 100755 index 00000000..2ab52bb6 --- /dev/null +++ b/utils/bin/FileCheck |
