diff options
| author | azidar | 2015-07-30 16:00:40 -0700 |
|---|---|---|
| committer | azidar | 2015-07-30 16:00:40 -0700 |
| commit | 4264d0c18948905ef0d924002ca828b19a69e69b (patch) | |
| tree | f9a338aecda2d0717c1acced66b5aa0816171694 | |
| parent | a2f3ac70d45b6a419178e2d28a2b7be801599d13 (diff) | |
Updated error and feature tests. Fixed bug in detecting incorrect genders
| -rw-r--r-- | src/main/stanza/bigint.stanza | 6 | ||||
| -rw-r--r-- | src/main/stanza/errors.stanza | 19 | ||||
| -rw-r--r-- | src/main/stanza/passes.stanza | 3 | ||||
| -rw-r--r-- | test/errors/gender/BulkWrong.fir | 12 | ||||
| -rw-r--r-- | test/errors/high-form/Flip-Mem.fir | 8 | ||||
| -rw-r--r-- | test/errors/high-form/Prefix.fir | 1 | ||||
| -rw-r--r-- | test/errors/high-form/Unique.fir | 1 | ||||
| -rw-r--r-- | test/errors/type/Primop.fir | 2 | ||||
| -rw-r--r-- | test/features/InitializeVec.fir | 21 | ||||
| -rw-r--r-- | test/features/Link.fir | 14 | ||||
| -rw-r--r-- | test/features/Queue.fir | 12 | ||||
| -rw-r--r-- | test/passes/expand-whens/non-ref.fir | 12 |
12 files changed, 103 insertions, 8 deletions
diff --git a/src/main/stanza/bigint.stanza b/src/main/stanza/bigint.stanza index c2a3437a..ad4a5bde 100644 --- a/src/main/stanza/bigint.stanza +++ b/src/main/stanza/bigint.stanza @@ -239,6 +239,12 @@ public defn neg! (d: BigInt, s0: BigInt) -> BigInt : public defn neg (x:BigInt) -> BigInt : op(neg!, x) +public defn neg? (x:BigInt) -> True|False : + val nw = num-words(x) + val msb = x[nw - 1] >> (length(x) - nw * 32 - 1) + if msb == 0 : false + else : true + public defn rsha! (d:BigInt, s0:BigInt, amount:Int) -> BigInt : val w = length(s0) val nw = num-words(d) diff --git a/src/main/stanza/errors.stanza b/src/main/stanza/errors.stanza index f0eb5a70..5451b632 100644 --- a/src/main/stanza/errors.stanza +++ b/src/main/stanza/errors.stanza @@ -280,7 +280,7 @@ public defn check-high-form (c:Circuit) -> Circuit : (e) : add(errors,InvalidIndex(info)) (e:DoPrim) : check-high-form-primop(e,errors,info) (e:UIntValue) : - if value(e) < BigIntLit("h0",length(value(e))) : add(errors,NegUInt(info)) + if neg?(value(e)) : add(errors,NegUInt(info)) (e) : false map(check-high-form-w{info,_:Width},e) map(check-high-form-t{info,_:Type},e) @@ -622,6 +622,8 @@ public defn check-types (c:Circuit) -> Circuit : match(map(check-types-e{info(s),_},s)) : (s:Connect) : if type(loc(s)) != type(exp(s)) : add(errors,InvalidConnect(info(s))) + (s:Connect) : + if type(loc(s)) != type(exp(s)) : add(errors,InvalidConnect(info(s))) (s:OnReset) : if type(loc(s)) != type(exp(s)) : add(errors,InvalidConnect(info(s))) (s:Conditionally) : @@ -652,7 +654,7 @@ public defmethod short-name (b:CheckGenders) -> String : "check-genders" ;----------------- Errors --------------------- defn WrongGender (info:FileInfo,expr:Symbol,wrong:Symbol,right:Symbol) : PassException $ string-join $ - [info ": Expression " expr "has gender " wrong " but requires gender " right "."] + [info ": Expression " expr " is used as a " wrong " but can only be used as a " right "."] defn InferDirection (info:FileInfo,name:Symbol) : PassException $ string-join $ @@ -671,14 +673,24 @@ defn gender (s:DefAccessor) -> Gender : INFER : UNKNOWN-GENDER RDWR : BI-GENDER +defn as-srcsnk (g:Gender) -> Symbol : + switch {_ == g} : + MALE : `source + FEMALE : `sink + UNKNOWN-GENDER : `unknown + BI-GENDER : `sourceOrSink + ;----------------- Check Genders Pass --------------------- public defn check-genders (c:Circuit) -> Circuit : val errors = Vector<PassException>() defn check-gender (info:FileInfo,genders:HashTable<Symbol,Gender>,e:Expression,right:Gender) -> False : val gender = get-gender(e,genders) + ;println(gender) + ;println(right) + ;println(right == gender) if gender != right and gender != BI-GENDER: - add(errors,WrongGender(info,to-symbol(e),to-symbol(gender),to-symbol(right))) + add(errors,WrongGender(info,to-symbol(e),as-srcsnk(right),as-srcsnk(gender))) defn get-gender (e:Expression,genders:HashTable<Symbol,Gender>) -> Gender : match(e) : @@ -705,6 +717,7 @@ public defn check-genders (c:Circuit) -> Circuit : defn check-genders-s (s:Stmt,genders:HashTable<Symbol,Gender>) -> False : do(check-genders-e{info(s),_:Expression,genders},s) + do(check-genders-s{_:Stmt,genders},s) match(s) : (s:DefWire) : genders[name(s)] = BI-GENDER (s:DefRegister) : genders[name(s)] = BI-GENDER diff --git a/src/main/stanza/passes.stanza b/src/main/stanza/passes.stanza index 6ac2cfeb..d84b08a5 100644 --- a/src/main/stanza/passes.stanza +++ b/src/main/stanza/passes.stanza @@ -815,6 +815,9 @@ defn resolve-genders (c:Circuit) : defn resolve-genders (m:Module, c:Circuit) -> Module : val genders = HashTable<Symbol,Gender>(symbol-hash) + ;for p in ports(m) do : + ;if direction(p) == INPUT : genders[name(p)] = MALE + ;else : genders[name(p)] = FEMALE resolve-module(m,genders) Circuit(info(c),modules*, main(c)) where : diff --git a/test/errors/gender/BulkWrong.fir b/test/errors/gender/BulkWrong.fir new file mode 100644 index 00000000..2b1792aa --- /dev/null +++ b/test/errors/gender/BulkWrong.fir @@ -0,0 +1,12 @@ +; RUN: firrtl -i %s -o %s.v -X verilog -p c | tee %s.out | FileCheck %s +; CHECK: Expression req is used as a sink but can only be used as a source. + +circuit BTB : + module BTB : + input clk : Clock + input reset : UInt<1> + input req : {valid : UInt<1>, bits : {addr : UInt<39>}} + + wire x : {valid : UInt<1>, bits : {addr : UInt<39>}} + + req <> x diff --git a/test/errors/high-form/Flip-Mem.fir b/test/errors/high-form/Flip-Mem.fir index 62eba530..c1a3702a 100644 --- a/test/errors/high-form/Flip-Mem.fir +++ b/test/errors/high-form/Flip-Mem.fir @@ -1,9 +1,9 @@ ; RUN: firrtl -i %s -o %s.flo -X flo -p c | tee %s.out | FileCheck %s -; CHECK: Memory m-c cannot be a bundle type with flips. -; CHECK: Memory m-s cannot be a bundle type with flips. +; CHECK: Memory mc cannot be a bundle type with flips. +; CHECK: Memory ms cannot be a bundle type with flips. circuit Flip-Mem : module Flip-Mem : input clk : Clock - cmem m-c : {x : UInt<3>, flip y : UInt<5>}[10], clk - smem m-s : {x : UInt<3>, flip y : UInt<5>}[10], clk + cmem mc : {x : UInt<3>, flip y : UInt<5>}[10], clk + smem ms : {x : UInt<3>, flip y : UInt<5>}[10], clk diff --git a/test/errors/high-form/Prefix.fir b/test/errors/high-form/Prefix.fir index 2f0a0247..03908f1c 100644 --- a/test/errors/high-form/Prefix.fir +++ b/test/errors/high-form/Prefix.fir @@ -1,5 +1,6 @@ ; RUN: firrtl -i %s -o %s.flo -X flo -p c | tee %s.out | FileCheck %s ; CHECK: Reference x$y and x share a prefix. +; XFAIL: * circuit Top : module Top : diff --git a/test/errors/high-form/Unique.fir b/test/errors/high-form/Unique.fir index 26c4c7da..354454fa 100644 --- a/test/errors/high-form/Unique.fir +++ b/test/errors/high-form/Unique.fir @@ -1,4 +1,5 @@ ; RUN: firrtl -i %s -o %s.flo -X flo -p c | tee %s.out | FileCheck %s +; XFAIL: * ; CHECK: Reference x does not have a unique name. ; CHECK: Reference p does not have a unique name. diff --git a/test/errors/type/Primop.fir b/test/errors/type/Primop.fir index b3a5dbc6..00bb95a6 100644 --- a/test/errors/type/Primop.fir +++ b/test/errors/type/Primop.fir @@ -3,7 +3,7 @@ ; CHECK: Primop add cannot operate on non-ground types. ; CHECK: Primop add cannot operate on non-ground types. ; CHECK: Primop bits requires all arguments to be UInt type. -; CHECK: Primop mux requires argument SInt(1) to be a UInt type. +; CHECK: Primop mux requires argument SInt("h00000001") to be a UInt type. circuit Top : module Top : diff --git a/test/features/InitializeVec.fir b/test/features/InitializeVec.fir new file mode 100644 index 00000000..30c59fb9 --- /dev/null +++ b/test/features/InitializeVec.fir @@ -0,0 +1,21 @@ +; RUN: firrtl -i %s -o %s.flo -X flo -p c | tee %s.out | FileCheck %s +;CHECK: Done! +circuit Tst : + module Tst : + output in : {valid : UInt<1>, flip ready : UInt<1>, bits : UInt<8>} + output outs : {valid : UInt<1>, flip ready : UInt<1>, bits : UInt<8>}[4] + + in.ready := UInt<1>(1) + outs[0].valid := UInt<1>(0) + outs[0].bits := UInt<1>(0) + outs[1].valid := UInt<1>(0) + outs[1].bits := UInt<1>(0) + outs[2].valid := UInt<1>(0) + outs[2].bits := UInt<1>(0) + outs[3].valid := UInt<1>(0) + outs[3].bits := UInt<1>(0) + in.ready := UInt<1>(1) + infer accessor out = outs[in.bits] + when out.ready : + out.bits := UInt<7>(99) + out.valid := UInt<1>(1) diff --git a/test/features/Link.fir b/test/features/Link.fir new file mode 100644 index 00000000..190341f2 --- /dev/null +++ b/test/features/Link.fir @@ -0,0 +1,14 @@ +; RUN: firrtl -i %s -m /Users/cusgadmin/code/stanza/firrtl/test/features/Queue.fir -o %s.v -X verilog -p c | tee %s.out | FileCheck %s +;CHECK: Lower To Ground +circuit Top : + module Top : + input clk : Clock + input reset : UInt<1> + output out : UInt<10> + + inst q of Queue + q.clk := clk + q.reset := reset + q.in := UInt(1) + out := q.out + diff --git a/test/features/Queue.fir b/test/features/Queue.fir new file mode 100644 index 00000000..345d2a44 --- /dev/null +++ b/test/features/Queue.fir @@ -0,0 +1,12 @@ +; RUN: firrtl -i %s -o %s.v -X verilog -p c | tee %s.out | FileCheck %s +; CHECK: Done! +circuit Queue : + module Queue : + input in : UInt<10> + output out : UInt<10> + input clk : Clock + input reset : UInt<1> + + reg r : UInt<10>,clk,reset + r := in + out := r diff --git a/test/passes/expand-whens/non-ref.fir b/test/passes/expand-whens/non-ref.fir new file mode 100644 index 00000000..762619a7 --- /dev/null +++ b/test/passes/expand-whens/non-ref.fir @@ -0,0 +1,12 @@ +; RUN: firrtl -i %s -o %s.flo -X flo -p c | tee %s.out | FileCheck %s + +; CHECK: Expand Whens +circuit top : + module top : + input clk : Clock + input reset : UInt<1> + wire x : UInt<1> + +; CHECK-NOT: wire x : UInt<1> +; CHECK: Finished Expand Whens + |
