diff options
Diffstat (limited to 'src/main/stanza/errors.stanza')
| -rw-r--r-- | src/main/stanza/errors.stanza | 109 |
1 files changed, 67 insertions, 42 deletions
diff --git a/src/main/stanza/errors.stanza b/src/main/stanza/errors.stanza index 6cdd1dca..8727f762 100644 --- a/src/main/stanza/errors.stanza +++ b/src/main/stanza/errors.stanza @@ -45,38 +45,40 @@ public defmethod pass (b:CheckHighForm) -> (Circuit -> Circuit) : check-high-for public defmethod name (b:CheckHighForm) -> String : "High Form Check" public defmethod short-name (b:CheckHighForm) -> String : "high-form-check" +var mname = "" + ;----------------- Errors ------------------------ defn NotUnique (info:FileInfo, name:Symbol) : PassException $ string-join $ - [info ": Reference " name " does not have a unique name."] + [info ": [module " mname "] Reference " name " does not have a unique name."] defn IsPrefix (info:FileInfo, prefix:Symbol) : PassException $ string-join $ - [info ": Symbol " prefix " is a prefix."] - + [info ": [module " mname "] Symbol " prefix " is a prefix."] + defn InvalidLOC (info:FileInfo) : PassException $ string-join $ - [info ": Invalid connect to an expression that is not a reference or a WritePort."] + [info ": [module " mname "] Invalid connect to an expression that is not a reference or a WritePort."] defn NegUInt (info:FileInfo) : PassException $ string-join $ - [info ": UIntValue cannot be negative."] + [info ": [module " mname "] UIntValue cannot be negative."] defn UndeclaredReference (info:FileInfo, name:Symbol) : PassException $ string-join $ - [info ": Reference " name " is not declared."] + [info ": [module " mname "] Reference " name " is not declared."] defn MemWithFlip (info:FileInfo, name:Symbol) : PassException $ string-join $ - [info ": Memory " name " cannot be a bundle type with flips."] + [info ": [module " mname "] Memory " name " cannot be a bundle type with flips."] defn InvalidSubfield (info:FileInfo) : PassException $ string-join $ - [info ": Invalid subfield access to non-reference."] + [info ": [module " mname "] Invalid subfield access to non-reference."] defn InvalidIndex (info:FileInfo) : PassException $ string-join $ - [info ": Invalid index access to non-reference."] + [info ": [module " mname "] Invalid index access to non-reference."] defn NoTopModule (info:FileInfo, name:Symbol) : PassException $ string-join $ @@ -92,19 +94,19 @@ defn ModuleNotDefined (info:FileInfo, name:Symbol) : defn IncorrectNumArgs (info:FileInfo, op:Symbol, n:Int) : PassException $ string-join $ - [info ": Primop " op " requires " n " expression arguments."] + [info ": [module " mname "] Primop " op " requires " n " expression arguments."] defn IncorrectNumConsts (info:FileInfo, op:Symbol, n:Int) : PassException $ string-join $ - [info ": Primop " op " requires " n " integer arguments."] + [info ": [module " mname "] Primop " op " requires " n " integer arguments."] defn NegWidth (info:FileInfo) : PassException $ string-join $ - [info ": Width cannot be negative."] + [info ": [module " mname "] Width cannot be negative."] defn NegVecSize (info:FileInfo) : PassException $ string-join $ - [info ": Vector type size cannot be negative."] + [info ": [module " mname "] Vector type size cannot be negative."] ;---------------- Helper Functions -------------- defn has-flip? (t:Type) -> True|False : @@ -218,6 +220,8 @@ defn check-high-form-primop (e:DoPrim, errors:Vector<PassException>,info:FileInf GREATER-EQ-OP : correct-num(2,0) EQUAL-OP : correct-num(2,0) NEQUAL-OP : correct-num(2,0) + EQUIV-OP : correct-num(2,0) + NEQUIV-OP : correct-num(2,0) MUX-OP : correct-num(3,0) PAD-OP : correct-num(1,1) AS-UINT-OP : correct-num(1,0) @@ -278,7 +282,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) @@ -335,6 +339,7 @@ public defn check-high-form (c:Circuit) -> Circuit : s }() defn check-high-form-m (m:Module) -> False : + mname = name(m) val names = HashTable<Symbol,True>(symbol-hash) val mnames = HashTable<Symbol,True>(symbol-hash) for m in modules(c) do : @@ -382,15 +387,15 @@ public defmethod short-name (b:CheckKinds) -> String : "check-kinds" ;----------------- Errors --------------------- defn NotMem (info:FileInfo, name:Symbol) : PassException $ string-join $ - [info ": Reference " name " must be a mem."] + [info ": [module " mname "] Reference " name " must be a mem."] defn IsMem (info:FileInfo, name:Symbol) : PassException $ string-join $ - [info ": Reference " name " cannot be a mem."] + [info ": [module " mname "] Reference " name " cannot be a mem."] defn OnResetNotReg (info:FileInfo, name:Symbol) : PassException $ string-join $ - [info ": Illegal on-reset to non-reg reference " name "."] + [info ": [module " mname "] Illegal on-reset to non-reg reference " name "."] ;----------------- Check Kinds Pass --------------------- ; I may have been overeager in looking for places where mems can't be, as mems are guaranteed to have a vector @@ -437,6 +442,7 @@ public defn check-kinds (c:Circuit) -> Circuit : do(check-kinds-s,s) for m in modules(c) do : + mname = name(m) match(m) : (m:ExModule) : false (m:InModule) : check-kinds-s(body(m)) @@ -463,55 +469,55 @@ public defmethod short-name (b:CheckTypes) -> String : "check-types" ;----------------- Errors --------------------- defn SubfieldNotInBundle (info:FileInfo, name:Symbol) : PassException $ string-join $ - [info ": Subfield " name " is not in bundle."] + [info ": [module " mname "] Subfield " name " is not in bundle."] defn SubfieldOnNonBundle (info:FileInfo, name:Symbol) : PassException $ string-join $ - [info ": Subfield " name " is accessed on a non-bundle."] + [info ": [module " mname "] Subfield " name " is accessed on a non-bundle."] defn IndexTooLarge (info:FileInfo, value:Int) : PassException $ string-join $ - [info ": Index with value " value " is too large."] + [info ": [module " mname "] Index with value " value " is too large."] defn IndexOnNonVector (info:FileInfo) : PassException $ string-join $ - [info ": Index illegal on non-vector type."] + [info ": [module " mname "] Index illegal on non-vector type."] defn IndexNotUInt (info:FileInfo) : PassException $ string-join $ - [info ": Index is not of UIntType."] + [info ": [module " mname "] Index is not of UIntType."] defn EnableNotUInt (info:FileInfo) : PassException $ string-join $ - [info ": Enable is not of UIntType."] + [info ": [module " mname "] Enable is not of UIntType."] defn InvalidConnect (info:FileInfo) : PassException $ string-join $ - [info ": Type mismatch."] + [info ": [module " mname "] Type mismatch."] defn PredNotUInt (info:FileInfo) : PassException $ string-join $ - [info ": Predicate not a UIntType."] + [info ": [module " mname "] Predicate not a UIntType."] defn OpNotGround (info:FileInfo, op:Symbol) : PassException $ string-join $ - [info ": Primop " op " cannot operate on non-ground types."] + [info ": [module " mname "] Primop " op " cannot operate on non-ground types."] defn OpNotUInt (info:FileInfo, op:Symbol,e:Symbol) : PassException $ string-join $ - [info ": Primop " op " requires argument " e " to be a UInt type."] + [info ": [module " mname "] Primop " op " requires argument " e " to be a UInt type."] defn OpNotAllUInt (info:FileInfo, op:Symbol) : PassException $ string-join $ - [info ": Primop " op " requires all arguments to be UInt type."] + [info ": [module " mname "] Primop " op " requires all arguments to be UInt type."] defn OpNotAllSameType (info:FileInfo, op:Symbol) : PassException $ string-join $ - [info ": Primop " op " requires all operands to have the same type."] + [info ": [module " mname "] Primop " op " requires all operands to have the same type."] defn NodeWithFlips (info:FileInfo) : PassException $ string-join $ - [info ": Node cannot be a bundle type with flips."] + [info ": [module " mname "] Node cannot be a bundle type with flips."] ;---------------- Helper Functions -------------- @@ -568,8 +574,10 @@ defn check-types-primop (e:DoPrim, errors:Vector<PassException>,info:FileInfo) - LESS-EQ-OP : false GREATER-OP : false GREATER-EQ-OP : false - EQUAL-OP : all-same-type(args(e)) - NEQUAL-OP : all-same-type(args(e)) + EQUAL-OP : false + NEQUAL-OP : false + EQUIV-OP : all-same-type(args(e)) + NEQUIV-OP : all-same-type(args(e)) MUX-OP : all-same-type(tail(args(e))) is-uint(head(args(e))) @@ -618,6 +626,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) : @@ -628,6 +638,7 @@ public defn check-types (c:Circuit) -> Circuit : s }() for m in modules(c) do : + mname = name(m) match(m) : (m:ExModule) : false (m:InModule) : check-types-s(body(m)) @@ -648,11 +659,11 @@ 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 ": [module " mname "] Expression " expr " is used as a " wrong " but can only be used as a " right "."] defn InferDirection (info:FileInfo,name:Symbol) : PassException $ string-join $ - [info ": Accessor " name " has a direction that requires inference."] + [info ": [module " mname "] Accessor " name " has a direction that requires inference."] ;---------------- Helper Functions -------------- defn dir-to-gender (d:PortDirection) -> Gender : @@ -667,14 +678,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) : @@ -701,6 +722,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 @@ -730,6 +752,7 @@ public defn check-genders (c:Circuit) -> Circuit : for m in modules(c) do : + mname = name(m) val genders = HashTable<Symbol,Gender>(symbol-hash) for p in ports(m) do : genders[name(p)] = dir-to-gender(direction(p)) @@ -756,27 +779,27 @@ public defmethod short-name (b:CheckLowForm) -> String : "low-form-check" ;----------------- Errors ------------------------ defn InvalidVec (info:FileInfo,name:Symbol) : PassException $ string-join $ - [info ": Expression " name " has an illegal vector type."] + [info ": [module " mname "] Expression " name " has an illegal vector type."] defn InvalidBundle (info:FileInfo,name:Symbol) : PassException $ string-join $ - [info ": Expression " name " has an illegal bundle type."] + [info ": [module " mname "] Expression " name " has an illegal bundle type."] defn NoWhen (info:FileInfo) : PassException $ string-join $ - [info ": Illegal when statement. No when statements with multiple statements are allowed in low firrtl."] + [info ": [module " mname "] Illegal when statement. No when statements with multiple statements are allowed in low firrtl."] defn SingleAssignment (info:FileInfo,name:Symbol) : PassException $ string-join $ - [info ": Illegal assignment to " name ". Wires can only be assigned to once."] + [info ": [module " mname "] Illegal assignment to " name ". Wires can only be assigned to once."] defn NoOnReset (info:FileInfo) : PassException $ string-join $ - [info ": Invalid use of on-reset. No on-resets are allowed in low firrtl."] + [info ": [module " mname "] Invalid use of on-reset. No on-resets are allowed in low firrtl."] defn NoBulkConnect (info:FileInfo) : PassException $ string-join $ - [info ": Invalid use of <>. No <>'s are allowed in low firrtl."] + [info ": [module " mname "] Invalid use of <>. No <>'s are allowed in low firrtl."] ;---------------- Helper Functions -------------- @@ -843,6 +866,7 @@ public defn check-low-form (c:Circuit) -> Circuit : false for m in modules(c) do : + mname = name(m) check-low-form-m(m) throw(PassExceptions(errors)) when not empty?(errors) c @@ -860,7 +884,7 @@ public defmethod short-name (b:CheckInitialization) -> String : "check-init" defn RefNotInitialized (info:FileInfo, name:Symbol) : PassException $ string-join $ - [info ": Reference " name " is not fully initialized."] + [info ": [module " mname "] Reference " name " is not fully initialized."] ;------------ Helper Functions ------------- @@ -903,6 +927,7 @@ public defn check-init (c:Circuit) : (v) : false for m in modules(c) do : + mname = name(m) match(m) : (m:InModule) : check-init-m(m) (m) : false |
