diff options
Diffstat (limited to 'src/main/stanza/errors.stanza')
| -rw-r--r-- | src/main/stanza/errors.stanza | 97 |
1 files changed, 91 insertions, 6 deletions
diff --git a/src/main/stanza/errors.stanza b/src/main/stanza/errors.stanza index e36ec06d..d8969dd3 100644 --- a/src/main/stanza/errors.stanza +++ b/src/main/stanza/errors.stanza @@ -283,20 +283,26 @@ public defn check-high-form (c:Circuit) -> Circuit : map(check-high-form-t{info,_:Type},e) e - defn check-high-form-s (s:Stmt,names:HashTable<Symbol,True>) -> Stmt : + defn check-high-form-s (s:Stmt,names:HashTable<Symbol,True>,mnames:HashTable<Symbol,True>) -> Stmt : defn check-name (info:FileInfo,name:Symbol) -> False : if key?(names,name) : add(errors,NotUnique(info,name)) map(check-high-form-t{info(s),_:Type},s) - map{check-high-form-s{_,names},_} $ { - match(map(check-high-form-e{info(s),_,names},s)) : - (s:DefWire|DefRegister) : + map{check-high-form-s{_,names,mnames},_} $ { + match(s) : ;map(check-high-form-e{info(s),_,names},s)) : + (s:DefWire) : check-name(info(s),name(s)) names[name(s)] = true + (s:DefRegister) : + check-name(info(s),name(s)) + names[name(s)] = true + check-high-form-e(info(s),reset(s),names) + check-high-form-e(info(s),clock(s),names) (s:DefMemory) : check-name(info(s),name(s)) names[name(s)] = true if has-flip?(type(s)) : add(errors, MemWithFlip(info(s), name(s))) + check-high-form-e(info(s),clock(s),names) (s:DefInstance) : if not contains?(name(module(s) as Ref),map(name,modules(c))) : add(errors, ModuleNotDefined(info(s),name(module(s) as Ref))) @@ -304,21 +310,34 @@ public defn check-high-form (c:Circuit) -> Circuit : names[name(s)] = true (s:DefNode) : check-name(info(s),name(s)) + check-high-form-e(info(s),value(s),names) names[name(s)] = true (s:DefAccessor) : check-name(info(s),name(s)) + check-high-form-e(info(s),index(s),names) + check-high-form-e(info(s),source(s),names) names[name(s)] = true (s:Connect) : check-valid-loc(info(s),loc(s)) + check-high-form-e(info(s),loc(s),names) + check-high-form-e(info(s),exp(s),names) (s:BulkConnect) : check-valid-loc(info(s),loc(s)) + check-high-form-e(info(s),loc(s),names) + check-high-form-e(info(s),exp(s),names) + (s:OnReset) : + check-high-form-e(info(s),loc(s),names) + check-high-form-e(info(s),exp(s),names) + (s:Conditionally) : + check-high-form-e(info(s),pred(s),names) (s) : false s }() defn check-high-form-m (m:Module) -> False : val names = HashTable<Symbol,True>(symbol-hash) + val mnames = HashTable<Symbol,True>(symbol-hash) for m in modules(c) do : - names[name(m)] = true + mnames[name(m)] = true for p in ports(m) do : names[name(p)] = true ;if name(p) == `reset : @@ -335,7 +354,7 @@ public defn check-high-form (c:Circuit) -> Circuit : match(m) : (m:ExModule) : false - (m:InModule) : check-high-form-s(body(m),names) + (m:InModule) : check-high-form-s(body(m),names,mnames) ;match(any-prefixes?(names,to-string(sym),to-string(sym))) : ;(s:False) : false ;(s:String) : add(errors,IsPrefix(info,to-symbol(s))) @@ -827,3 +846,69 @@ public defn check-low-form (c:Circuit) -> Circuit : throw(PassExceptions(errors)) when not empty?(errors) c + +;;================ Initialization Check ================== +; Error on all componenents that are not connected to. + +public defstruct CheckInitialization <: Pass +public defmethod pass (b:CheckInitialization) -> (Circuit -> Circuit) : check-init +public defmethod name (b:CheckInitialization) -> String : "Check Initialization" +public defmethod short-name (b:CheckInitialization) -> String : "check-init" + +;----------------- Errors ------------------------ + +defn RefNotInitialized (info:FileInfo, name:Symbol) : + PassException $ string-join $ + [info ": Reference " name " is not fully initialized."] + +;------------ Helper Functions ------------- + +;------------ Pass ------------------ + +public defn check-init (c:Circuit) : + val errors = Vector<PassException>() + + defn check-init-m (m:InModule) : + val init? = HashTable<Symbol,FileInfo|True>(symbol-hash) + defn get-name (e:Expression) -> Symbol : + match(e) : + (e:Ref) : name(e) + (e:Subfield) : symbol-join([get-name(exp(e)) `. name(e)]) + (e) : error("Shouldn't be here") + + defn check-init-s (s:Stmt) : + do(check-init-s,s) + match(s) : + (s:DefWire|DefRegister) : init?[name(s)] = info(s) + (s:DefAccessor) : + if acc-dir(s) == WRITE : init?[name(s)] = info(s) + (s:DefInstance) : + for f in fields(type(module(s)) as BundleType) do : + if flip(f) == REVERSE : + init?[symbol-join([name(s) `. name(f)])] = info(s) + (s:Connect) : + init?[get-name(loc(s))] = true + (s) : false + + for p in ports(m) do : + if direction(p) == OUTPUT : + init?[name(p)] = info(p) + + check-init-s(body(m)) + + for x in init? do : + match(value(x)) : + (v:FileInfo) : add(errors, RefNotInitialized(v,key(x))) + (v) : false + + for m in modules(c) do : + match(m) : + (m:InModule) : check-init-m(m) + (m) : false + + throw(PassExceptions(errors)) when not empty?(errors) + c + + + + |
