~ubuntu-branches/ubuntu/wily/acl2/wily

« back to all changes in this revision

Viewing changes to books/centaur/vl/lint/bit-use-set.lisp

  • Committer: Package Import Robot
  • Author(s): Camm Maguire
  • Date: 2015-01-16 10:35:45 UTC
  • mfrom: (3.3.26 sid)
  • Revision ID: package-import@ubuntu.com-20150116103545-prehe9thgo79o8w8
Tags: 7.0-1
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
 
31
31
(in-package "VL")
32
32
(include-book "../toe/toe-preliminary")
33
 
(include-book "../wf-reasonable-p")
 
33
;; (include-book "../wf-reasonable-p")
34
34
(include-book "disconnected")
35
35
(include-book "../mlib/hierarchy")
 
36
(include-book "../mlib/hierarchy-basic")
36
37
(include-book "../mlib/allexprs")
37
38
(include-book "../mlib/lvalues")
38
39
(include-book "../mlib/reportcard")
 
40
(include-book "../mlib/find")
 
41
(include-book "../mlib/modnamespace")
39
42
(include-book "../util/cwtime")
40
43
(include-book "use-set-ignore")
41
44
(include-book "std/bitsets/bitsets" :dir :system)
246
249
 
247
250
;; BOZO axe all-wirealists, memoizing vl-module-wirealist seems better...
248
251
 
 
252
(local (std::add-default-post-define-hook :fix))
 
253
 
249
254
(define vl-modulelist-all-wirealists
250
255
  :parents (vl-wirealist-p)
251
256
  :short "Safely generate the (fast) wirealists for a list of modules."
254
259
  (mv (reportcard vl-reportcard-p :hyp :fguard)
255
260
      (all-wirealists
256
261
       "Fast alist binding every module name to its wirealist."
257
 
       (equal (hons-assoc-equal name all-wirealists)
258
 
              (let ((mod (vl-find-module name x)))
259
 
                (and mod
260
 
                     (cons name (mv-nth 2 (vl-module-wirealist mod nil))))))
261
 
       :hyp :fguard))
 
262
       (implies (stringp name)
 
263
                (equal (hons-assoc-equal name all-wirealists)
 
264
                       (let ((mod (vl-find-module name x)))
 
265
                         (and mod
 
266
                              (cons name (mv-nth 2 (vl-module-wirealist mod nil)))))))
 
267
       :hints(("Goal" :in-theory (enable vl-find-module)))))
262
268
 
263
269
  (b* (((when (atom x))
264
270
        (mv nil nil))
 
271
       (first (vl-module-fix (car x)))
265
272
 
266
 
       (car-name (vl-module->name (car x)))
 
273
       (car-name (vl-module->name first))
267
274
 
268
275
       ((mv reportcard cdr-wire-alists)
269
276
        (vl-modulelist-all-wirealists (cdr x)))
270
277
 
271
278
       ((mv ?successp car-warnings car-wire-alist)
272
 
        (vl-module-wirealist (car x) nil))
 
279
        (vl-module-wirealist first nil))
273
280
 
274
281
       (reportcard
275
282
        (if (consp car-warnings)
400
407
 
401
408
 
402
409
 
 
410
(define vl-wirealist-fix ((x vl-wirealist-p))
 
411
  :returns (x-prime vl-wirealist-p)
 
412
  :inline t
 
413
  :hooks nil
 
414
  (mbe :logic (if (vl-wirealist-p x) x 'acl2::bad-default-wirealist)
 
415
       :exec x)
 
416
  ///
 
417
  (defthm vl-wirealist-fix-when-vl-wirealist-p
 
418
    (implies (vl-wirealist-p x)
 
419
             (equal (vl-wirealist-fix x) x)))
 
420
 
 
421
  (fty::deffixtype vl-wirealist :pred vl-wirealist-p :fix vl-wirealist-fix
 
422
    :equiv vl-wirealist-equiv :define t))
 
423
 
 
424
 
 
425
 
403
426
(define us-portdecllist-bits
404
427
  :short "Generate all the bits for the port declarations."
405
428
  ((x      vl-portdecllist-p)
413
436
 
414
437
  (b* (((when (atom x))
415
438
        (mv t nil nil))
416
 
       (lookup (hons-get (vl-portdecl->name (car x)) walist))
 
439
       (first (vl-portdecl-fix (car x)))
 
440
       (walist (vl-wirealist-fix walist))
 
441
       (lookup (hons-get (vl-portdecl->name first) walist))
417
442
       ((unless lookup)
418
443
        (b* ((w (make-vl-warning :type :vl-bad-portdecl
419
444
                                 :msg "~a0: no corresponding wires."
420
 
                                 :args (list (car x))
 
445
                                 :args (list first)
421
446
                                 :fatalp t
422
447
                                 :fn __function__)))
423
448
          (mv nil (list w) nil)))
444
469
   (walist vl-wirealist-p)
445
470
   (reportcard vl-reportcard-p))
446
471
 
447
 
  :returns (new-reportcard vl-reportcard-p
448
 
                        :hyp (and (force (vl-module-p x))
449
 
                                  (force (vl-reportcard-p reportcard))))
 
472
  :returns (new-reportcard vl-reportcard-p)
450
473
 
451
474
  (b* (((vl-module x) x)
 
475
       (reportcard (vl-reportcard-fix reportcard))
 
476
       (walist (vl-wirealist-fix walist))
452
477
 
453
478
       ((mv successp warnings port-bits) (vl-portlist-msb-bit-pattern x.ports walist))
454
479
       ((unless successp)
543
568
   (reportcard     vl-reportcard-p))
544
569
  :guard (subsetp-equal (redundant-list-fix x)
545
570
                        (redundant-list-fix mods))
546
 
  :returns (new-reportcard vl-reportcard-p
547
 
                        :hyp (and (force (vl-modulelist-p x))
548
 
                                  (force (vl-reportcard-p reportcard))))
 
571
  :returns (new-reportcard vl-reportcard-p)
549
572
  (b* (((when (atom x))
550
 
        reportcard)
 
573
        (vl-reportcard-fix reportcard))
551
574
       (mod1    (car x))
552
575
       (walist1 (cdr (hons-get (vl-module->name mod1) all-walists)))
553
576
       (reportcard (us-check-port-bits mod1 walist1 reportcard)))
559
582
 
560
583
 
561
584
 
 
585
 
 
586
 
 
587
 
562
588
(defsection us-db-p
563
589
 
564
590
; Use-Set Database (for an individual module).  Associates wire names to
584
610
                                                *us-truly-used-abovep*
585
611
                                                0))
586
612
 
587
 
  (defalist us-db-p (x)
588
 
    :key (vl-emodwire-p x)
589
 
    :val (natp x)
590
 
    :keyp-of-nil nil
591
 
    :valp-of-nil nil))
592
 
 
593
 
 
594
 
(defalist us-dbalist-p (x)
 
613
  (fty::defalist us-db :key-type vl-emodwire :val-type natp
 
614
    :keyp-of-nil nil :valp-of-nil nil))
 
615
 
 
616
 
 
617
(fty::defalist us-dbalist
595
618
 
596
619
; A 'dbalist' is a (typically fast) alist mapping module names to their Use-Set
597
620
; Databases (us-db-ps).  This is used so that we can look up whether the ports
598
621
; of submodules are used/set when we are processing module instances.
599
622
 
600
 
  :key (stringp x)
601
 
  :val (us-db-p x)
 
623
  :key-type string
 
624
  :val-type us-db
602
625
  :keyp-of-nil nil
603
626
  :valp-of-nil t)
604
627
 
617
640
      (+ (len (car x))
618
641
         (sum-lens (cdr x)))))
619
642
 
620
 
  (define us-initialize-db-aux1 ((wires vl-emodwirelist-p) acc)
 
643
  (define us-initialize-db-aux1 ((wires vl-emodwirelist-p) (acc us-db-p))
621
644
    :parents (us-initialize-db)
622
645
    :short "Bind each wire in a list to the empty set."
623
 
    :returns (acc us-db-p :hyp (and (force (vl-emodwirelist-p wires))
624
 
                                    (force (us-db-p acc))))
 
646
    :returns (acc us-db-p)
625
647
    (if (atom wires)
626
 
        acc
627
 
      (hons-acons (car wires) 0 (us-initialize-db-aux1 (cdr wires) acc))))
 
648
        (us-db-fix acc)
 
649
      (hons-acons (vl-emodwire-fix (car wires)) 0 (us-initialize-db-aux1 (cdr wires) acc))))
628
650
 
629
 
  (define us-initialize-db-exec ((walist vl-wirealist-p) acc)
 
651
  (define us-initialize-db-exec ((walist vl-wirealist-p) (acc us-db-p))
630
652
    :parents (us-initialize-db)
631
653
    :short "Bind each wire in a wirealist to the empty set."
632
 
    :returns (acc us-db-p :hyp (and (force (vl-wirealist-p walist))
633
 
                                    (force (us-db-p acc))))
634
 
    (if (atom walist)
635
 
        acc
636
 
      (let ((acc (us-initialize-db-aux1 (cdar walist) acc)))
637
 
        (us-initialize-db-exec (cdr walist) acc))))
 
654
    :returns (acc us-db-p)
 
655
    :measure (len walist)
 
656
    :prepwork ((local (in-theory (enable vl-wirealist-fix))))
 
657
    (let ((walist (vl-wirealist-fix walist)))
 
658
      (if (atom walist)
 
659
          (us-db-fix acc)
 
660
        (let ((acc (us-initialize-db-aux1 (cdar walist) acc)))
 
661
          (us-initialize-db-exec (cdr walist) acc)))))
638
662
 
639
663
  (define us-initialize-db ((walist vl-wirealist-p))
640
 
    :returns (db us-db-p :hyp :fguard)
641
 
    (us-initialize-db-exec walist (- (sum-lens walist)
642
 
                                     (len walist)))))
 
664
    :returns (db us-db-p)
 
665
    (let ((walist (vl-wirealist-fix walist)))
 
666
      (us-initialize-db-exec walist (- (sum-lens walist)
 
667
                                       (len walist))))))
643
668
 
644
669
 
645
670
 
665
690
                        (warnings vl-warninglist-p)
666
691
                        (elem     vl-modelement-p))
667
692
    :returns (mv (warnings vl-warninglist-p)
668
 
                 (db       us-db-p          :hyp :fguard))
669
 
    (b* ((curr (hons-get wire db))
 
693
                 (db       us-db-p))
 
694
    (b* ((db (us-db-fix db))
 
695
         (wire (vl-emodwire-fix wire))
 
696
         (elem (vl-modelement-fix elem))
 
697
         (curr (hons-get wire db)) 
670
698
         ((unless curr)
671
699
          (mv (warn :type :use-set-fudging
672
700
                    :msg "~a0: expected use-set db entry for ~x1."
673
701
                    :args (list elem wire))
674
702
              db))
675
 
         (val (acl2::bitset-union mask (cdr curr)))
 
703
         (val (acl2::bitset-union (lnfix mask) (cdr curr)))
676
704
         ;; dumb optimization: avoid consing if not necessary
677
705
         (db (if (= val (cdr curr))
678
706
                 db
685
713
                         (warnings vl-warninglist-p)
686
714
                         (elem     vl-modelement-p))
687
715
    :returns (mv (warnings vl-warninglist-p)
688
 
                 (db       us-db-p          :hyp :fguard))
 
716
                 (db       us-db-p))
689
717
    (b* (((when (atom wires))
690
 
          (mv (ok) db))
 
718
          (mv (ok) (us-db-fix db)))
691
719
         ((mv warnings db)
692
720
          (us-mark-wire mask (car wires) db warnings elem)))
693
721
      (us-mark-wires mask (cdr wires) db warnings elem)))
737
765
   (db       us-db-p)
738
766
   (warnings vl-warninglist-p))
739
767
  :returns (mv (warnings vl-warninglist-p)
740
 
               (db       us-db-p          :hyp :fguard))
 
768
               (db       us-db-p))
741
769
  :verify-guards nil
742
770
  (b* (((when (atom x))
743
 
        (mv (ok) db))
 
771
        (mv (ok) (us-db-fix db)))
 
772
       (walist (vl-wirealist-fix walist))
 
773
       (first (vl-portdecl-fix (car x)))
744
774
       ((mv warnings db)
745
775
        (us-mark-toplevel-port-bits (cdr x) walist db warnings))
746
 
       (entry (hons-get (vl-portdecl->name (car x)) walist))
 
776
       (entry (hons-get (vl-portdecl->name first) walist))
747
777
       (wires (cdr entry))
748
778
       ((unless entry)
749
779
        (b* ((w (make-vl-warning :type :vl-bad-portdecl
750
780
                                 :msg "~a0: no corresponding wires."
751
 
                                 :args (list (car x))
 
781
                                 :args (list first)
752
782
                                 :fatalp t
753
783
                                 :fn 'us-mark-toplevel-port-bits-for-module)))
754
784
          (mv (cons w warnings) db)))
755
785
       ((mv warnings db)
756
 
        (case (vl-portdecl->dir (car x))
757
 
          (:vl-input  (us-mark-wires-set-above wires db warnings (car x)))
758
 
          (:vl-output (us-mark-wires-used-above wires db warnings (car x)))
759
 
          (:vl-inout  (us-mark-wires-used/set-above wires db warnings (car x)))
 
786
        (case (vl-portdecl->dir first)
 
787
          (:vl-input  (us-mark-wires-set-above wires db warnings first))
 
788
          (:vl-output (us-mark-wires-used-above wires db warnings first))
 
789
          (:vl-inout  (us-mark-wires-used/set-above wires db warnings first))
760
790
          (otherwise  (prog2$ (impossible)
761
791
                              (mv warnings db))))))
762
792
    (mv warnings db))
783
813
     (warnings vl-warninglist-p)
784
814
     (elem     vl-modelement-p))
785
815
    :returns (mv (warnings vl-warninglist-p)
786
 
                 (db us-db-p :hyp :fguard))
 
816
                 (db us-db-p))
787
817
    (b* (((vl-plainarg x) x)
 
818
         (walist (vl-wirealist-fix walist))
 
819
         (x (vl-plainarg-fix x))
 
820
         (elem (vl-modelement-fix elem))
788
821
         ((unless x.expr)
789
822
          ;; Fine, there's nothing to do.
790
 
          (mv (ok) db))
 
823
          (mv (ok) (us-db-fix db)))
791
824
 
792
825
         (warnings (if x.dir
793
826
                       (ok)
809
842
                                           (warnings vl-warninglist-p)
810
843
                                           (elem     vl-modelement-p))
811
844
    :returns (mv (warnings vl-warninglist-p)
812
 
                 (db       us-db-p :hyp :fguard))
 
845
                 (db       us-db-p))
813
846
    (b* (((when (atom x))
814
 
          (mv (ok) db))
 
847
          (mv (ok) (us-db-fix db)))
815
848
         ((mv warnings db)
816
849
          (us-mark-wires-for-gateinst-arg (car x) walist db warnings elem)))
817
850
      (us-mark-wires-for-gateinst-args (cdr x) walist db warnings elem)))
821
854
                                      (db       us-db-p)
822
855
                                      (warnings vl-warninglist-p))
823
856
    :returns (mv (warnings vl-warninglist-p)
824
 
                 (db       us-db-p :hyp :fguard))
825
 
    (b* (((vl-gateinst x) x))
 
857
                 (db       us-db-p))
 
858
    (b* (((vl-gateinst x) (vl-gateinst-fix x)))
826
859
      (us-mark-wires-for-gateinst-args x.args walist db warnings x)))
827
860
 
828
861
  (define us-mark-wires-for-gateinstlist ((x        vl-gateinstlist-p)
830
863
                                          (db       us-db-p)
831
864
                                          (warnings vl-warninglist-p))
832
865
    :returns (mv (warnings vl-warninglist-p)
833
 
                 (db       us-db-p :hyp :fguard))
 
866
                 (db       us-db-p))
834
867
    (b* (((when (atom x))
835
 
          (mv (ok) db))
 
868
          (mv (ok) (us-db-fix db)))
836
869
         ((mv warnings db) (us-mark-wires-for-gateinst (car x) walist db warnings)))
837
870
      (us-mark-wires-for-gateinstlist (cdr x) walist db warnings))))
838
871
 
856
889
                                    (db       us-db-p)
857
890
                                    (warnings vl-warninglist-p))
858
891
    :returns (mv (warnings vl-warninglist-p)
859
 
                 (db       us-db-p :hyp :fguard))
860
 
    (b* (((vl-assign x) x)
 
892
                 (db       us-db-p))
 
893
    (b* (((vl-assign x) (vl-assign-fix x))
 
894
         (walist (vl-wirealist-fix walist))
 
895
         (warnings (vl-warninglist-fix warnings))
861
896
         ((mv warnings1 rhs-wires) (vl-expr-allwires x.expr walist))
862
897
         ((mv warnings2 lhs-wires) (vl-expr-allwires x.lvalue walist))
863
898
         (warnings (append warnings1 warnings2 warnings))
870
905
                                        (db       us-db-p)
871
906
                                        (warnings vl-warninglist-p))
872
907
    :returns (mv (warnings vl-warninglist-p)
873
 
                 (db       us-db-p :hyp :fguard))
 
908
                 (db       us-db-p))
874
909
    (b* (((when (atom x))
875
 
          (mv (ok) db))
 
910
          (mv (ok) (us-db-fix db)))
876
911
         ((mv warnings db) (us-mark-wires-for-assign (car x) walist db warnings))
877
912
         ((mv warnings db) (us-mark-wires-for-assignlist (cdr x) walist db warnings)))
878
913
      (mv warnings db))))
879
914
 
880
915
 
881
 
(defsection us-mark-wires-for-netdecllist
 
916
(defsection us-mark-wires-for-vardecllist
882
917
 
883
 
  (define us-mark-wires-for-netdecl
 
918
  (define us-mark-wires-for-vardecl
884
919
    :short "If a net is declared to be a supply0 or a supply1, then we want to
885
 
          think about it as being driven."
886
 
    ((x        vl-netdecl-p)
 
920
            think of it as driven."
 
921
    ((x        vl-vardecl-p)
887
922
     (walist   vl-wirealist-p)
888
923
     (db       us-db-p)
889
924
     (warnings vl-warninglist-p))
890
925
    :returns (mv (warnings vl-warninglist-p)
891
 
                 (db       us-db-p :hyp :fguard))
892
 
    (b* (((vl-netdecl x) x)
893
 
         ((unless (or (eq x.type :vl-supply0)
894
 
                      (eq x.type :vl-supply1)))
 
926
                 (db       us-db-p))
 
927
    (b* (((vl-vardecl x) (vl-vardecl-fix x))
 
928
         (walist (vl-wirealist-fix walist))
 
929
         (db (us-db-fix db))
 
930
         ((unless (member x.nettype '(:vl-supply0 :vl-supply1)))
895
931
          (mv (ok) db))
896
932
 
897
933
         (entry (hons-get x.name walist))
898
934
         (wires (cdr entry))
899
935
         ((unless entry)
900
 
          (mv (fatal :type :vl-bad-netdecl
 
936
          (mv (fatal :type :vl-bad-vardecl
901
937
                     :msg "~a0: no corresponding wires."
902
938
                     :args (list (car x)))
903
939
              db))
905
941
         ((mv warnings db) (us-mark-wires-truly-set wires db warnings x)))
906
942
      (mv warnings db)))
907
943
 
908
 
  (define us-mark-wires-for-netdecllist ((x        vl-netdecllist-p)
 
944
  (define us-mark-wires-for-vardecllist ((x        vl-vardecllist-p)
909
945
                                         (walist   vl-wirealist-p)
910
946
                                         (db       us-db-p)
911
947
                                         (warnings vl-warninglist-p))
912
948
    :returns (mv (warnings vl-warninglist-p)
913
 
                 (db       us-db-p :hyp :fguard))
 
949
                 (db       us-db-p))
914
950
    (b* (((when (atom x))
915
 
          (mv (ok) db))
916
 
         ((mv warnings db) (us-mark-wires-for-netdecl (car x) walist db warnings))
917
 
         ((mv warnings db) (us-mark-wires-for-netdecllist (cdr x) walist db warnings)))
 
951
          (mv (ok) (us-db-fix db)))
 
952
         ((mv warnings db) (us-mark-wires-for-vardecl (car x) walist db warnings))
 
953
         ((mv warnings db) (us-mark-wires-for-vardecllist (cdr x) walist db warnings)))
918
954
      (mv warnings db))))
919
955
 
920
956
 
921
957
(define vl-evatom-allwires ((x vl-evatom-p)
922
958
                            (walist vl-wirealist-p))
923
959
  :returns (mv (warnings vl-warninglist-p)
924
 
               (wires    vl-emodwirelist-p :hyp :fguard))
925
 
  (vl-expr-allwires (vl-evatom->expr x) walist))
 
960
               (wires    vl-emodwirelist-p))
 
961
  (vl-expr-allwires (vl-evatom->expr x) (vl-wirealist-fix walist)))
926
962
 
927
963
(define vl-evatomlist-allwires ((x      vl-evatomlist-p)
928
964
                                (walist vl-wirealist-p))
929
965
  :returns (mv (warnings vl-warninglist-p)
930
 
               (wires    vl-emodwirelist-p :hyp :fguard))
 
966
               (wires    vl-emodwirelist-p))
931
967
  (b* (((when (atom x))
932
968
        (mv nil nil))
933
969
       ((mv car-warnings car-wires) (vl-evatom-allwires (car x) walist))
938
974
(define vl-eventcontrol-allwires ((x      vl-eventcontrol-p)
939
975
                                  (walist vl-wirealist-p))
940
976
  :returns (mv (warnings vl-warninglist-p)
941
 
               (wires    vl-emodwirelist-p :hyp :fguard))
 
977
               (wires    vl-emodwirelist-p))
942
978
  (vl-evatomlist-allwires (vl-eventcontrol->atoms x) walist))
943
979
 
944
980
(define vl-repeateventcontrol-allwires ((x      vl-repeateventcontrol-p)
945
981
                                        (walist vl-wirealist-p))
946
982
  :returns (mv (warnings vl-warninglist-p)
947
 
               (wires    vl-emodwirelist-p :hyp :fguard))
 
983
               (wires    vl-emodwirelist-p))
948
984
  (b* (((vl-repeateventcontrol x) x)
 
985
       (walist (vl-wirealist-fix walist))
949
986
       ((mv warnings1 wires1) (vl-expr-allwires x.expr walist))
950
987
       ((mv warnings2 wires2) (vl-eventcontrol-allwires x.ctrl walist)))
951
988
    (mv (append-without-guard warnings1 warnings2)
954
991
(define vl-delayoreventcontrol-allwires ((x      vl-delayoreventcontrol-p)
955
992
                                         (walist vl-wirealist-p))
956
993
  :returns (mv (warnings vl-warninglist-p)
957
 
               (wires    vl-emodwirelist-p :hyp :fguard))
958
 
  (b* ((x (vl-delayoreventcontrol-fix x)))
 
994
               (wires    vl-emodwirelist-p))
 
995
  (b* ((x (vl-delayoreventcontrol-fix x))
 
996
       (walist (vl-wirealist-fix walist)))
959
997
    (case (tag x)
960
998
      (:vl-delaycontrol (vl-expr-allwires (vl-delaycontrol->value x) walist))
961
999
      (:vl-eventcontrol (vl-eventcontrol-allwires x walist))
969
1007
                                  (warnings vl-warninglist-p)
970
1008
                                  (elem     vl-modelement-p))
971
1009
    :returns (mv (warnings vl-warninglist-p)
972
 
                 (db       us-db-p :hyp :fguard))
 
1010
                 (db       us-db-p))
973
1011
    :measure (vl-stmt-count x)
974
1012
    :verify-guards nil
975
1013
    (b* ((x (vl-stmt-fix x))
 
1014
         (db (us-db-fix db))
 
1015
         (elem (vl-modelement-fix elem))
 
1016
         (walist (vl-wirealist-fix walist))
976
1017
         (warnings (vl-warninglist-fix warnings))
977
1018
 
978
1019
         ((when (vl-atomicstmt-p x))
979
 
          (case (tag (vl-stmt-kind x))
 
1020
          (case (vl-stmt-kind x)
980
1021
            ;; - Nothing to do for null statements.
981
1022
            ;; - Don't think we want to do anything for eventtriggerstmts?
982
1023
            ;; - Don't think we want to do anything for deassign statements?
1005
1046
          ;; Additionally mark all test expression wires as used since they're
1006
1047
          ;; deciding which branch to follow.
1007
1048
          (b* (((vl-casestmt x) x)
1008
 
               (exprs                (cons x.test (alist-keys x.cases)))
 
1049
               (exprs                (cons x.test (flatten (alist-keys x.caselist))))
1009
1050
               ((mv warnings1 wires) (vl-exprlist-allwires exprs walist))
1010
1051
               (warnings             (append-without-guard warnings1 warnings)))
1011
1052
            (us-mark-wires-truly-used wires db warnings elem)))
1088
1129
                                      (warnings vl-warninglist-p)
1089
1130
                                      (elem     vl-modelement-p))
1090
1131
    :returns (mv (warnings vl-warninglist-p)
1091
 
                 (db       us-db-p :hyp :fguard))
 
1132
                 (db       us-db-p))
1092
1133
    :measure (vl-stmtlist-count x)
1093
1134
    (b* (((when (atom x))
1094
 
          (mv (ok) db))
 
1135
          (mv (ok) (us-db-fix db)))
1095
1136
         ((mv warnings db) (us-mark-wires-for-stmt (car x) walist db warnings elem)))
1096
1137
      (us-mark-wires-for-stmtlist (cdr x) walist db warnings elem)))
1097
1138
  ///
1098
1139
  (verify-guards us-mark-wires-for-stmt
1099
 
    :hints(("Goal" :in-theory (enable vl-atomicstmt-p)))))
 
1140
    :hints(("Goal" :in-theory (enable vl-atomicstmt-p))))
 
1141
 
 
1142
  (fty::deffixequiv-mutual us-mark-wires-for-stmt))
1100
1143
 
1101
1144
 
1102
1145
(defsection us-mark-wires-for-alwayslist
1106
1149
                                    (db       us-db-p)
1107
1150
                                    (warnings vl-warninglist-p))
1108
1151
    :returns (mv (warnings vl-warninglist-p)
1109
 
                 (db       us-db-p :hyp :fguard))
1110
 
    (us-mark-wires-for-stmt (vl-always->stmt x) walist db warnings x))
 
1152
                 (db       us-db-p))
 
1153
    :verbosep t
 
1154
    (us-mark-wires-for-stmt (vl-always->stmt x) walist db warnings
 
1155
                            (vl-always-fix x)))
1111
1156
 
1112
1157
  (define us-mark-wires-for-alwayslist ((x        vl-alwayslist-p)
1113
1158
                                        (walist   vl-wirealist-p)
1114
1159
                                        (db       us-db-p)
1115
1160
                                        (warnings vl-warninglist-p))
1116
1161
    :returns (mv (warnings vl-warninglist-p)
1117
 
                 (db       us-db-p :hyp :fguard))
 
1162
                 (db       us-db-p))
1118
1163
    (b* (((when (atom x))
1119
 
          (mv (ok) db))
 
1164
          (mv (ok) (us-db-fix db)))
1120
1165
         ((mv warnings db) (us-mark-wires-for-always (car x) walist db warnings))
1121
1166
         ((mv warnings db) (us-mark-wires-for-alwayslist (cdr x) walist db warnings)))
1122
1167
      (mv warnings db))))
1139
1184
                                     (db       us-db-p)
1140
1185
                                     (warnings vl-warninglist-p))
1141
1186
    :returns (mv (warnings vl-warninglist-p)
1142
 
                 (db       us-db-p :hyp :fguard))
1143
 
    (us-mark-wires-for-stmt (vl-initial->stmt x) walist db warnings x))
 
1187
                 (db       us-db-p))
 
1188
    (us-mark-wires-for-stmt (vl-initial->stmt x) walist db warnings (vl-initial-fix x)))
1144
1189
 
1145
1190
  (define us-mark-wires-for-initiallist ((x        vl-initiallist-p)
1146
1191
                                         (walist   vl-wirealist-p)
1147
1192
                                         (db       us-db-p)
1148
1193
                                         (warnings vl-warninglist-p))
1149
1194
    :returns (mv (warnings vl-warninglist-p)
1150
 
                 (db       us-db-p :hyp :fguard))
 
1195
                 (db       us-db-p))
1151
1196
    (b* (((when (atom x))
1152
 
          (mv (ok) db))
 
1197
          (mv (ok) (us-db-fix db)))
1153
1198
         ((mv warnings db) (us-mark-wires-for-initial (car x) walist db warnings))
1154
1199
         ((mv warnings db) (us-mark-wires-for-initiallist (cdr x) walist db warnings)))
1155
1200
      (mv warnings db))))
1170
1215
     (warnings vl-warninglist-p  "warnings accumulator (may be extended)")
1171
1216
     (elem     vl-modelement-p   "context for warnings"))
1172
1217
    :returns (mv (warnings vl-warninglist-p)
1173
 
                 (db       us-db-p :hyp :fguard))
 
1218
                 (db       us-db-p))
1174
1219
    :verify-guards nil
1175
 
    (b* (((when (atom wires))
 
1220
    :verbosep t
 
1221
    :hooks ((:fix :hints (("goal" :in-theory (disable cons-equal)))))
 
1222
    (b* ((db (us-db-fix db))
 
1223
         (dir (vl-direction-fix dir))
 
1224
         (warnings (vl-warninglist-fix warnings))
 
1225
         (elem (vl-modelement-fix elem))
 
1226
         ((when (atom wires))
1176
1227
          (mv (ok) db))
1177
1228
 
1178
1229
         ((mv warnings db)
1179
1230
          (us-mark-false-inouts-for-portdecl-wires (cdr wires) dir db warnings elem))
1180
1231
 
1181
 
         (wire1  (car wires))
 
1232
         (wire1  (vl-emodwire-fix (car wires)))
1182
1233
         (lookup (hons-get wire1 db))
1183
1234
         ((unless lookup)
1184
1235
          (mv (warn :type :use-set-fudging
1215
1266
                                             (walist   vl-wirealist-p)
1216
1267
                                             (warnings vl-warninglist-p))
1217
1268
    :returns (mv (warnings vl-warninglist-p)
1218
 
                 (db       us-db-p :hyp :fguard))
1219
 
    (b* (((vl-portdecl x) x)
 
1269
                 (db       us-db-p))
 
1270
    (b* (((vl-portdecl x) (vl-portdecl-fix x))
 
1271
         (walist (vl-wirealist-fix walist))
 
1272
         (db (us-db-fix db))
1220
1273
         (lookup (hons-get x.name walist))
1221
1274
         ((unless lookup)
1222
1275
          (mv (warn :type :use-set-fudging
1231
1284
                                 (walist   vl-wirealist-p)
1232
1285
                                 (warnings vl-warninglist-p))
1233
1286
    :returns (mv (warnings vl-warninglist-p)
1234
 
                 (db       us-db-p :hyp :fguard))
 
1287
                 (db       us-db-p))
1235
1288
    (b* (((when (atom x))
1236
 
          (mv (ok) db))
 
1289
          (mv (ok) (us-db-fix db)))
1237
1290
         ((mv warnings db)
1238
1291
          (us-mark-false-inouts-for-portdecl (car x) db walist warnings)))
1239
1292
      (us-mark-false-inouts (cdr x) db walist warnings))))
1240
1293
 
1241
1294
 
1242
 
 
1243
1295
; We make a US-NOTE for every module instance connection:
1244
1296
 
1245
 
(defaggregate us-note
1246
 
  (submod   ; the submodule being instanced
1247
 
   formals  ; the particular wires (port bits from submod) that this note pertains to
1248
 
   actuals  ; the actual wires that are connected
 
1297
(defprod us-note
 
1298
  ((submod stringp)  ; the submodule being instanced
 
1299
   (formals vl-emodwirelist)  ; the particular wires (port bits from submod) that this note pertains to
 
1300
   (actuals vl-emodwirelist)  ; the actual wires that are connected
1249
1301
   )
1250
1302
  :tag :us-note
1251
 
  :legiblep nil
1252
 
  :require ((stringp-of-us-note->submod
1253
 
             (stringp submod)
1254
 
             :rule-classes :type-prescription)
1255
 
            (vl-emodwirelist-p-of-us-note->formals
1256
 
             (vl-emodwirelist-p formals))
1257
 
            (vl-emodwirelist-p-of-us-note->actuals
1258
 
             (vl-emodwirelist-p actuals))))
 
1303
  :layout :tree)
1259
1304
 
1260
 
(deflist us-notelist-p (x)
1261
 
  (us-note-p x)
1262
 
  :guard t
 
1305
(fty::deflist us-notelist :elt-type us-note
1263
1306
  :elementp-of-nil nil)
1264
1307
 
1265
 
(defalist us-notealist-p (x)
1266
 
  :key (stringp x)
1267
 
  :val (us-notelist-p x)
 
1308
(fty::defalist us-notealist :key-type string :val-type us-notelist
1268
1309
  :keyp-of-nil nil
1269
1310
  :valp-of-nil t)
1270
1311
 
1271
1312
 
1272
1313
 
1273
 
(defsection us-mark-wires-for-modinst-lvalue-arg
1274
 
 
1275
 
; Handler for module instance arguments whose expressions look like lvalues,
1276
 
; and hence whose bits can be lined up with the port expression.
1277
 
 
1278
 
  (defund us-mark-wires-for-modinst-lvalue-arg
1279
 
    (actual-bits ; bits for the argument
1280
 
     formal-bits ; bits for the submodule's port; matches len of actual-bits
1281
 
     sub-db      ; db for the submodule
1282
 
     db          ; db for the superior module                    (may be extended)
1283
 
     warnings    ; warnings accumulator for the superior module  (may be extended)
1284
 
     inst        ; context for warnings and notes
1285
 
     notes       ; accumulator for notes                         (may be extended)
1286
 
     )
1287
 
    "Returns (MV WARNINGS DB NOTES)"
1288
 
    (declare (xargs :guard (and (vl-emodwirelist-p actual-bits)
1289
 
                                (vl-emodwirelist-p formal-bits)
1290
 
                                (same-lengthp actual-bits formal-bits)
1291
 
                                (us-db-p sub-db)
1292
 
                                (us-db-p db)
1293
 
                                (vl-warninglist-p warnings)
1294
 
                                (vl-modinst-p inst)
1295
 
                                (us-notelist-p notes))
1296
 
                    :verify-guards nil))
1297
 
 
1298
 
    ;; We recursively process each actual-bit/formal-bit pair.
1299
 
    (b* (((when (atom actual-bits))
1300
 
          (mv warnings db notes))
1301
 
 
1302
 
         ((mv warnings db notes)
1303
 
          (us-mark-wires-for-modinst-lvalue-arg (cdr actual-bits) (cdr formal-bits)
1304
 
                                                sub-db db warnings inst notes))
1305
 
 
1306
 
         (actual1 (car actual-bits))
1307
 
         (formal1 (car formal-bits))
1308
 
         (formal1-look (hons-get formal1 sub-db))
1309
 
         ((unless formal1-look)
1310
 
          (b* ((w (make-vl-warning
1311
 
                   :type :use-set-fudging
1312
 
                   :msg "~a0: expected a binding for formal bit ~s1; not ~
 
1314
(define us-mark-wires-for-modinst-lvalue-arg ((actual-bits vl-emodwirelist-p)
 
1315
                                              (formal-bits vl-emodwirelist-p)
 
1316
                                              (sub-db us-db-p)
 
1317
                                              (db us-db-p)
 
1318
                                              (warnings vl-warninglist-p)
 
1319
                                              (inst vl-modinst-p)
 
1320
                                              (notes us-notelist-p))
 
1321
  :guard (same-lengthp actual-bits formal-bits)
 
1322
  :verify-guards nil
 
1323
  :returns (mv (warnings1 vl-warninglist-p)
 
1324
               (db1 us-db-p)
 
1325
               (notes1 us-notelist-p))
 
1326
  ;; We recursively process each actual-bit/formal-bit pair.
 
1327
  (b* ((warnings (vl-warninglist-fix warnings))
 
1328
       (db (us-db-fix db))
 
1329
       (sub-db (us-db-fix sub-db))
 
1330
       (notes (us-notelist-fix notes))
 
1331
       (inst (vl-modinst-fix inst))
 
1332
       ((when (atom actual-bits))
 
1333
        (mv warnings db notes))
 
1334
 
 
1335
       ((mv warnings db notes)
 
1336
        (us-mark-wires-for-modinst-lvalue-arg (cdr actual-bits) (cdr formal-bits)
 
1337
                                              sub-db db warnings inst notes))
 
1338
 
 
1339
       (actual1 (vl-emodwire-fix (car actual-bits)))
 
1340
       (formal1 (vl-emodwire-fix (car formal-bits)))
 
1341
       (formal1-look (hons-get formal1 sub-db))
 
1342
       ((unless formal1-look)
 
1343
        (b* ((w (make-vl-warning
 
1344
                 :type :use-set-fudging
 
1345
                 :msg "~a0: expected a binding for formal bit ~s1; not ~
1313
1346
                         inferring any use/set information for ~s2."
1314
 
                   :args (list inst formal1 actual1)
1315
 
                   :fn 'us-mark-wires-for-modinst-lvalue-arg)))
1316
 
            (mv (cons w warnings) db notes)))
1317
 
 
1318
 
         ;; We just merge in the mask from formal1.  If the formal is
1319
 
         ;; truly/falsely used, then this marks the actual as being
1320
 
         ;; truly/falsely used.  If the formal is truly/falsely set, this marks
1321
 
         ;; the actual as being truly/falsely set.
1322
 
         (formal1-mask (cdr formal1-look))
1323
 
         ;; Strip out any used above/below info
1324
 
         (formal1-mask (acl2::bitset-difference formal1-mask *us-above-mask*))
1325
 
         ((mv warnings db)
1326
 
          (us-mark-wire formal1-mask actual1 db warnings inst))
1327
 
         (note (make-us-note :submod  (vl-modinst->modname inst)
1328
 
                             :formals (list formal1)
1329
 
                             :actuals (list actual1))))
1330
 
      (mv warnings db (cons note notes))))
1331
 
 
1332
 
  (defthm us-mark-wires-for-modinst-lvalue-arg-basics
1333
 
    (implies (and (force (vl-emodwirelist-p actual-bits))
1334
 
                  (force (vl-emodwirelist-p formal-bits))
1335
 
                  (force (same-lengthp actual-bits formal-bits))
1336
 
                  (force (us-db-p sub-db))
1337
 
                  (force (us-db-p db))
1338
 
                  (force (vl-warninglist-p warnings))
1339
 
                  (force (vl-modinst-p inst))
1340
 
                  (force (us-notelist-p notes)))
1341
 
             (let ((ret (us-mark-wires-for-modinst-lvalue-arg actual-bits formal-bits
1342
 
                                                              sub-db db warnings inst
1343
 
                                                              notes)))
1344
 
               (and (vl-warninglist-p (mv-nth 0 ret))
1345
 
                    (us-db-p (mv-nth 1 ret))
1346
 
                    (us-notelist-p (mv-nth 2 ret)))))
1347
 
    :hints(("Goal" :in-theory (enable us-mark-wires-for-modinst-lvalue-arg))))
1348
 
 
 
1347
                 :args (list inst formal1 actual1)
 
1348
                 :fn 'us-mark-wires-for-modinst-lvalue-arg)))
 
1349
          (mv (cons w warnings) db notes)))
 
1350
 
 
1351
       ;; We just merge in the mask from formal1.  If the formal is
 
1352
       ;; truly/falsely used, then this marks the actual as being
 
1353
       ;; truly/falsely used.  If the formal is truly/falsely set, this marks
 
1354
       ;; the actual as being truly/falsely set.
 
1355
       (formal1-mask (cdr formal1-look))
 
1356
       ;; Strip out any used above/below info
 
1357
       (formal1-mask (acl2::bitset-difference formal1-mask *us-above-mask*))
 
1358
       ((mv warnings db)
 
1359
        (us-mark-wire formal1-mask actual1 db warnings inst))
 
1360
       (note (make-us-note :submod  (vl-modinst->modname inst)
 
1361
                           :formals (list formal1)
 
1362
                           :actuals (list actual1))))
 
1363
    (mv warnings db (cons note notes)))
 
1364
  ///
1349
1365
  (verify-guards us-mark-wires-for-modinst-lvalue-arg))
1350
1366
 
1351
1367
 
1352
1368
 
1353
1369
 
1354
 
(defsection us-mark-wires-for-modinst-rvalue-arg
 
1370
(define us-rvalue-mask
1355
1371
 
1356
1372
; Handler for module instance arguments whose expressions do NOT look like
1357
1373
; lvalues.
1386
1402
; foo and bar as used.  Similarly, if port's bits are only falsely used, we'll
1387
1403
; mark foo and bar's bits as falsely used.
1388
1404
 
1389
 
  (defund us-rvalue-mask (bits sub-db warnings elem)
1390
 
    ;; Union the masks for all bits.
1391
 
    "Returns (MV WARNINGS MASK)"
1392
 
    (declare (xargs :guard (and (vl-emodwirelist-p bits)
1393
 
                                (us-db-p sub-db)
1394
 
                                (vl-warninglist-p warnings)
1395
 
                                (vl-modelement-p elem))))
1396
 
    (b* (((when (atom bits))
 
1405
  ((bits vl-emodwirelist-p)
 
1406
   (sub-db us-db-p)
 
1407
   (warnings vl-warninglist-p)
 
1408
   (elem vl-modelement-p))
 
1409
  :returns (mv (warnings vl-warninglist-p)
 
1410
               (mask natp))
 
1411
  :verbosep t
 
1412
    (b* ((warnings (vl-warninglist-fix warnings))
 
1413
         (sub-db (us-db-fix sub-db))
 
1414
         (elem (vl-modelement-fix elem))
 
1415
         ((when (atom bits))
1397
1416
          (mv warnings 0))
1398
1417
         ((mv warnings cdr-mask)
1399
1418
          (us-rvalue-mask (cdr bits) sub-db warnings elem))
1400
 
         (lookup (hons-get (car bits) sub-db))
 
1419
         (bit (vl-emodwire-fix (car bits)))
 
1420
         (lookup (hons-get bit sub-db))
1401
1421
         ((unless lookup)
1402
1422
          (b* ((w (make-vl-warning
1403
1423
                   :type :use-set-fudging
1404
1424
                   :msg "~a0: expected database entry for port bit ~s1.  ~
1405
1425
                         Assuming it isn't used/set in the submodule"
1406
 
                   :args (list elem (car bits))
 
1426
                   :args (list elem bit)
1407
1427
                   :fn 'us-rvalue-mask)))
1408
1428
            (mv (cons w warnings) cdr-mask)))
1409
1429
         (car-mask (cdr lookup)))
1410
1430
      (mv warnings (acl2::bitset-union car-mask cdr-mask))))
1411
1431
 
1412
 
  (defthm us-rvalue-mask-basics
1413
 
    (implies (and (force (vl-emodwirelist-p bits))
1414
 
                  (force (us-db-p sub-db))
1415
 
                  (force (vl-warninglist-p warnings))
1416
 
                  (force (vl-modelement-p elem)))
1417
 
             (let ((ret (us-rvalue-mask bits sub-db warnings elem)))
1418
 
               (and (vl-warninglist-p (mv-nth 0 ret))
1419
 
                    (natp (mv-nth 1 ret)))))
1420
 
    :hints(("Goal" :in-theory (enable us-rvalue-mask))))
1421
 
 
1422
 
 
1423
 
 
1424
 
  (defund us-mark-wires-for-modinst-rvalue-arg
1425
 
    (expr        ; the "actual" expression being connected to the port
1426
 
     formal-bits ; the bits of the formal, in msb-first order
1427
 
     sub-db      ; db for the submodule
1428
 
     db       ; db for the superior module                   (may be extended)
1429
 
     walist   ; wire alist for the superior module
1430
 
     warnings ; warnings accumulator for the superior module (may be extended)
1431
 
     inst     ; context for warnings and notes
1432
 
     notes    ; accumulator for notes                        (may be extended)
 
1432
 
 
1433
(define us-mark-wires-for-modinst-rvalue-arg
 
1434
    ((expr vl-expr-p)        ; the "actual" expression being connected to the port
 
1435
     (formal-bits vl-emodwirelist-p) ; the bits of the formal, in msb-first order
 
1436
     (sub-db us-db-p)      ; db for the submodule
 
1437
     (db us-db-p)       ; db for the superior module                   (may be extended)
 
1438
     (walist vl-wirealist-p)   ; wire alist for the superior module
 
1439
     (warnings vl-warninglist-p) ; warnings accumulator for the superior module (may be extended)
 
1440
     (inst vl-modinst-p)     ; context for warnings and notes
 
1441
     (notes us-notelist-p)    ; accumulator for notes                        (may be extended)
1433
1442
     )
1434
 
    "Returns (MV WARNINGS DB NOTES)"
1435
 
    (declare (xargs :guard (and (vl-expr-p expr)
1436
 
                                (vl-emodwirelist-p formal-bits)
1437
 
                                (us-db-p sub-db)
1438
 
                                (us-db-p db)
1439
 
                                (vl-wirealist-p walist)
1440
 
                                (vl-warninglist-p warnings)
1441
 
                                (vl-modinst-p inst)
1442
 
                                (us-notelist-p notes))))
1443
 
 
1444
 
    (b* (((mv warnings1 expr-wires) (vl-expr-allwires expr walist))
 
1443
    :returns (mv (warnings1 vl-warninglist-p)
 
1444
                 (db1 us-db-p)
 
1445
                 (notes1 us-notelist-p))
 
1446
    :verbosep t
 
1447
    (b* ((expr (vl-expr-fix expr))
 
1448
         (walist (vl-wirealist-fix walist))
 
1449
         (warnings (vl-warninglist-fix warnings))
 
1450
         (notes (us-notelist-fix notes))
 
1451
         (db (us-db-fix db))
 
1452
         (formal-bits (vl-emodwirelist-fix formal-bits))
 
1453
         (inst (vl-modinst-fix inst))
 
1454
         ((mv warnings1 expr-wires) (vl-expr-allwires expr walist))
1445
1455
         (warnings (append warnings1 warnings))
1446
1456
 
1447
1457
         ;; Union of the masks for all formals.
1488
1498
                             :actuals expr-wires)))
1489
1499
      (mv warnings db (cons note notes))))
1490
1500
 
1491
 
  (defthm us-mark-wires-for-modinst-rvalue-arg-basics
1492
 
    (implies (and (force (vl-expr-p expr))
1493
 
                  (force (vl-emodwirelist-p formal-bits))
1494
 
                  (force (us-db-p sub-db))
1495
 
                  (force (us-db-p db))
1496
 
                  (force (vl-wirealist-p walist))
1497
 
                  (force (vl-warninglist-p warnings))
1498
 
                  (force (vl-modinst-p inst))
1499
 
                  (force (us-notelist-p notes)))
1500
 
             (let ((ret (us-mark-wires-for-modinst-rvalue-arg expr formal-bits
1501
 
                                                              sub-db db walist
1502
 
                                                              warnings inst notes)))
1503
 
               (and (vl-warninglist-p (mv-nth 0 ret))
1504
 
                    (us-db-p (mv-nth 1 ret))
1505
 
                    (us-notelist-p (mv-nth 2 ret)))))
1506
 
    :hints(("Goal" :in-theory (enable us-mark-wires-for-modinst-rvalue-arg)))))
1507
 
 
1508
 
 
1509
 
 
1510
 
(defsection us-mark-wires-for-modinst-arg
1511
 
 
1512
 
  (defund us-mark-wires-for-modinst-arg
1513
 
    (arg         ; the plainarg being connected to the port
1514
 
     formal-bits ; the bits of the formal, in msb-first order
1515
 
     sub-db      ; db for the submodule
1516
 
     db          ; db for the superior module                   (may be extended)
1517
 
     walist      ; wire alist for the superior module
1518
 
     warnings    ; warnings accumulator for the superior module (may be extended)
1519
 
     inst        ; context for warnings and notes
1520
 
     notes       ; accumulator for notes                        (may be extended)
1521
 
     )
1522
 
    "Returns (MV WARNINGS DB NOTES)"
1523
 
    (declare (xargs :guard (and (vl-plainarg-p arg)
1524
 
                                (vl-emodwirelist-p formal-bits)
1525
 
                                (us-db-p sub-db)
1526
 
                                (us-db-p db)
1527
 
                                (vl-wirealist-p walist)
1528
 
                                (vl-warninglist-p warnings)
1529
 
                                (vl-modinst-p inst)
1530
 
                                (us-notelist-p notes))))
1531
 
    (b* ((expr (vl-plainarg->expr arg))
1532
 
         ((unless expr)
1533
 
          ;; Okay, nothing to do.
1534
 
          (mv warnings db notes))
1535
 
         ((unless (vl-expr-lvaluep expr))
1536
 
          (us-mark-wires-for-modinst-rvalue-arg expr formal-bits
1537
 
                                                sub-db db walist
1538
 
                                                warnings inst notes))
1539
 
         ((mv successp warnings expr-bits)
1540
 
          (vl-msb-expr-bitlist expr walist warnings))
1541
 
         (len-okp (same-lengthp expr-bits formal-bits))
1542
 
         (warnings
1543
 
          (cond ((not successp)
1544
 
                 (cons (make-vl-warning
1545
 
                        :type :use-set-fudging
1546
 
                        :msg "~a0: failed to generate wires for ~a1; not ~
 
1501
 
 
1502
(define us-mark-wires-for-modinst-arg
 
1503
  ((arg vl-plainarg-p)         ; the plainarg being connected to the port
 
1504
   (formal-bits vl-emodwirelist-p) ; the bits of the formal, in msb-first order
 
1505
   (sub-db us-db-p)      ; db for the submodule
 
1506
   (db us-db-p)          ; db for the superior module                   (may be extended)
 
1507
   (walist vl-wirealist-p)      ; wire alist for the superior module
 
1508
   (warnings vl-warninglist-p)    ; warnings accumulator for the superior module (may be extended)
 
1509
   (inst vl-modinst-p)        ; context for warnings and notes
 
1510
   (notes us-notelist-p)       ; accumulator for notes                        (may be extended)
 
1511
   )
 
1512
  :returns (mv (warnings vl-warninglist-p)
 
1513
               (db us-db-p)
 
1514
               (notes us-notelist-p))
 
1515
  (b* ((arg (vl-plainarg-fix arg))         ; the plainarg being connected to the port
 
1516
       (formal-bits (vl-emodwirelist-fix formal-bits)) ; the bits of the formal, in msb-first order
 
1517
       (sub-db (us-db-fix sub-db))      ; db for the submodule
 
1518
       (db (us-db-fix db))          ; db for the superior module                   (may be extended)
 
1519
       (walist (vl-wirealist-fix walist))      ; wire alist for the superior module
 
1520
       (warnings (vl-warninglist-fix warnings))    ; warnings accumulator for the superior module (may be extended)
 
1521
       (inst (vl-modinst-fix inst))        ; context for warnings and notes
 
1522
       (notes (us-notelist-fix notes))       ; accumulator for notes                        (may be extended)
 
1523
       (expr (vl-plainarg->expr arg))
 
1524
       ((unless expr)
 
1525
        ;; Okay, nothing to do.
 
1526
        (mv warnings db notes))
 
1527
       ((unless (vl-expr-lvaluep expr))
 
1528
        (us-mark-wires-for-modinst-rvalue-arg expr formal-bits
 
1529
                                              sub-db db walist
 
1530
                                              warnings inst notes))
 
1531
       ((mv successp warnings expr-bits)
 
1532
        (vl-msb-expr-bitlist expr walist warnings))
 
1533
       (len-okp (same-lengthp expr-bits formal-bits))
 
1534
       (warnings
 
1535
        (cond ((not successp)
 
1536
               (cons (make-vl-warning
 
1537
                      :type :use-set-fudging
 
1538
                      :msg "~a0: failed to generate wires for ~a1; not ~
1547
1539
                              inferring any use/set information from this ~
1548
1540
                              port."
1549
 
                        :args (list inst expr)
1550
 
                        :fn 'us-mark-wires-for-modinst-arg)
1551
 
                       warnings))
1552
 
                ((not len-okp)
1553
 
                 (cons (make-vl-warning
1554
 
                        :type :use-set-fudging
1555
 
                        :msg "~a0: width mismatch in port connection: expected ~x1 ~
 
1541
                      :args (list inst expr)
 
1542
                      :fn 'us-mark-wires-for-modinst-arg)
 
1543
                     warnings))
 
1544
              ((not len-okp)
 
1545
               (cons (make-vl-warning
 
1546
                      :type :use-set-fudging
 
1547
                      :msg "~a0: width mismatch in port connection: expected ~x1 ~
1556
1548
                              bits (~s2) but found ~x3 bits in ~a4.  Not inferring ~
1557
1549
                              any use/set information from this port."
1558
 
                        :args (list inst
1559
 
                                    (len formal-bits)
1560
 
                                    (vl-verilogify-emodwirelist formal-bits)
1561
 
                                    (len expr-bits)
1562
 
                                    expr)
1563
 
                        :fn 'us-mark-wires-for-modinst-arg)
1564
 
                       warnings))
1565
 
                (t
1566
 
                 ;; Okay, everything is fine.
1567
 
                 warnings)))
1568
 
         ((unless (and successp len-okp))
1569
 
          (mv warnings db notes)))
1570
 
      (us-mark-wires-for-modinst-lvalue-arg expr-bits formal-bits
1571
 
                                            sub-db db warnings inst notes)))
1572
 
 
1573
 
  (defthm us-mark-wires-for-modinst-arg-basics
1574
 
    (implies (and (force (vl-plainarg-p arg))
1575
 
                  (force (vl-emodwirelist-p formal-bits))
1576
 
                  (force (us-db-p sub-db))
1577
 
                  (force (us-db-p db))
1578
 
                  (force (vl-wirealist-p walist))
1579
 
                  (force (vl-warninglist-p warnings))
1580
 
                  (force (vl-modinst-p inst))
1581
 
                  (force (us-notelist-p notes)))
1582
 
             (let ((ret (us-mark-wires-for-modinst-arg arg formal-bits
1583
 
                                                       sub-db db walist warnings
1584
 
                                                       inst notes)))
1585
 
               (and (vl-warninglist-p (mv-nth 0 ret))
1586
 
                    (us-db-p (mv-nth 1 ret))
1587
 
                    (us-notelist-p (mv-nth 2 ret)))))
1588
 
    :hints(("Goal" :in-theory (enable us-mark-wires-for-modinst-arg)))))
1589
 
 
1590
 
 
1591
 
 
1592
 
(defsection us-mark-wires-for-modinst-args
1593
 
 
1594
 
  (defund us-mark-wires-for-modinst-args
1595
 
    (actuals  ; plainarglist of the actual exprs being passed to the modinst
1596
 
     portpat  ; the port pattern for the submodule
1597
 
     sub-db   ; db for the submodule being instanced
1598
 
     db       ; db for the superior module  (may be extended)
1599
 
     walist   ; wire alist for the superior module
1600
 
     warnings ; warnings accumulator for the superior module (may be extended)
1601
 
     inst     ; the instance itself (context for any warnings and notes)
1602
 
     notes    ; accumulator for notes (may be extended)
1603
 
     )
1604
 
    "Returns (MV WARNINGS DB NOTES)"
1605
 
    (declare (xargs :guard (and (vl-plainarglist-p actuals)
1606
 
                                (vl-emodwirelistlist-p portpat)
1607
 
                                (same-lengthp actuals portpat)
1608
 
                                (us-db-p sub-db)
1609
 
                                (us-db-p db)
1610
 
                                (vl-wirealist-p walist)
1611
 
                                (vl-warninglist-p warnings)
1612
 
                                (vl-modinst-p inst)
1613
 
                                (us-notelist-p notes))))
1614
 
    (b* (((when (atom actuals))
1615
 
          (mv warnings db notes))
1616
 
         ((mv warnings db notes)
1617
 
          (us-mark-wires-for-modinst-arg (car actuals) (car portpat) sub-db db walist warnings inst notes))
1618
 
         ((mv warnings db notes)
1619
 
          (us-mark-wires-for-modinst-args (cdr actuals) (cdr portpat) sub-db db walist warnings inst notes)))
1620
 
      (mv warnings db notes)))
1621
 
 
1622
 
  (defthm us-mark-wires-for-modinst-args-basics
1623
 
    (implies (and (force (vl-plainarglist-p actuals))
1624
 
                  (force (vl-emodwirelistlist-p portpat))
1625
 
                  (force (same-lengthp actuals portpat))
1626
 
                  (force (us-db-p sub-db))
1627
 
                  (force (us-db-p db))
1628
 
                  (force (vl-wirealist-p walist))
1629
 
                  (force (vl-warninglist-p warnings))
1630
 
                  (force (vl-modinst-p inst))
1631
 
                  (force (us-notelist-p notes)))
1632
 
             (let ((ret (us-mark-wires-for-modinst-args actuals portpat
1633
 
                                                        sub-db db walist warnings
1634
 
                                                        inst notes)))
1635
 
               (and (vl-warninglist-p (mv-nth 0 ret))
1636
 
                    (us-db-p (mv-nth 1 ret))
1637
 
                    (us-notelist-p (mv-nth 2 ret)))))
1638
 
    :hints(("Goal" :in-theory (enable us-mark-wires-for-modinst-args)))))
1639
 
 
1640
 
 
1641
 
 
1642
 
(defsection us-mark-wires-for-modinst
1643
 
 
1644
 
  (defund us-mark-wires-for-modinst
1645
 
    (x           ; the modinst to process
1646
 
     walist      ; walist for the current module
1647
 
     db          ; db for the current module (may be extended)
1648
 
     mods        ; all modules
1649
 
     modalist    ; modalist for all modules
1650
 
     dbalist     ; dbalist-p that should bind every submodule (due to dependency order traversal)
1651
 
     all-walists ; precomputed walists for all mods
1652
 
     warnings    ; warnings accumulator (may be extended)
1653
 
     notes       ; notes accumulator (may be extended)
1654
 
     )
1655
 
    "Returns (MV WARNINGS DB NOTES)"
1656
 
    (declare (xargs :guard (and (vl-modinst-p x)
1657
 
                                (vl-wirealist-p walist)
1658
 
                                (us-db-p db)
1659
 
                                (vl-modulelist-p mods)
1660
 
                                (equal modalist (vl-modalist mods))
1661
 
                                (us-dbalist-p dbalist)
1662
 
                                (equal all-walists (vl-nowarn-all-wirealists mods))
1663
 
                                (vl-warninglist-p warnings)
1664
 
                                (us-notelist-p notes))))
1665
 
    (b* (((vl-modinst x) x)
1666
 
 
1667
 
         ((unless (and (not x.range)
1668
 
                       (atom (vl-arguments->args x.paramargs))
1669
 
                       (eq (vl-arguments-kind x.portargs) :plain)))
1670
 
          (b* ((w (make-vl-warning
1671
 
                   :type :use-set-fudging
1672
 
                   :msg "~a0: skipping this module instance because it has a ~
 
1550
                      :args (list inst
 
1551
                                  (len formal-bits)
 
1552
                                  (vl-verilogify-emodwirelist formal-bits)
 
1553
                                  (len expr-bits)
 
1554
                                  expr)
 
1555
                      :fn 'us-mark-wires-for-modinst-arg)
 
1556
                     warnings))
 
1557
              (t
 
1558
               ;; Okay, everything is fine.
 
1559
               warnings)))
 
1560
       ((unless (and successp len-okp))
 
1561
        (mv warnings db notes)))
 
1562
    (us-mark-wires-for-modinst-lvalue-arg expr-bits formal-bits
 
1563
                                          sub-db db warnings inst notes)))
 
1564
 
 
1565
 
 
1566
(define us-mark-wires-for-modinst-args
 
1567
  ((actuals vl-plainarglist-p)  ; plainarglist of the actual exprs being passed to the modinst
 
1568
   (portpat vl-emodwirelistlist-p)  ; the port pattern for the submodule
 
1569
   (sub-db us-db-p)   ; db for the submodule being instanced
 
1570
   (db us-db-p)       ; db for the superior module  (may be extended)
 
1571
   (walist vl-wirealist-p)   ; wire alist for the superior module
 
1572
   (warnings vl-warninglist-p) ; warnings accumulator for the superior module (may be extended)
 
1573
   (inst vl-modinst-p)     ; the instance itself (context for any warnings and notes)
 
1574
   (notes us-notelist-p)    ; accumulator for notes (may be extended)
 
1575
   )
 
1576
  :measure (len (vl-plainarglist-fix actuals))
 
1577
  :guard (same-lengthp actuals portpat)
 
1578
  :returns (mv (warnings vl-warninglist-p)
 
1579
               (db us-db-p)
 
1580
               (notes us-notelist-p))
 
1581
  (b* ((actuals (vl-plainarglist-fix actuals))  ; plainarglist of the actual exprs being passed to the modinst
 
1582
       (portpat (vl-emodwirelistlist-fix portpat))  ; the port pattern for the submodule
 
1583
       (sub-db (us-db-fix sub-db))   ; db for the submodule being instanced
 
1584
       (db (us-db-fix db))       ; db for the superior module  (may be extended)
 
1585
       (walist (vl-wirealist-fix walist))   ; wire alist for the superior module
 
1586
       (warnings (vl-warninglist-fix warnings)) ; warnings accumulator for the superior module (may be extended)
 
1587
       (inst (vl-modinst-fix inst))     ; the instance itself (context for any warnings and notes)
 
1588
       (notes (us-notelist-fix notes))
 
1589
       ((when (atom actuals))
 
1590
        (mv warnings db notes))
 
1591
       ((mv warnings db notes)
 
1592
        (us-mark-wires-for-modinst-arg (car actuals) (car portpat) sub-db db walist warnings inst notes))
 
1593
       ((mv warnings db notes)
 
1594
        (us-mark-wires-for-modinst-args (cdr actuals) (cdr portpat) sub-db db walist warnings inst notes)))
 
1595
    (mv warnings db notes)))
 
1596
 
 
1597
 
 
1598
(define us-mark-wires-for-modinst
 
1599
  ((x vl-modinst-p)          ; the modinst to process
 
1600
   (walist vl-wirealist-p)      ; walist for the current module
 
1601
   (db us-db-p)          ; db for the current module (may be extended)
 
1602
   (mods vl-modulelist-p)
 
1603
   (ss vl-scopestack-p)
 
1604
   (dbalist us-dbalist-p)     ; dbalist-p that should bind every submodule (due to dependency order traversal)
 
1605
   (all-walists (equal all-walists (vl-nowarn-all-wirealists mods))) ; precomputed walists for all mods
 
1606
   (warnings vl-warninglist-p)    ; warnings accumulator (may be extended)
 
1607
   (notes us-notelist-p)       ; notes accumulator (may be extended)
 
1608
   )
 
1609
  (declare (ignorable mods))
 
1610
  :returns (mv (warnings vl-warninglist-p)
 
1611
               (db us-db-p)
 
1612
               (notes us-notelist-p))
 
1613
  (b* ((x (vl-modinst-fix x))
 
1614
       (walist (vl-wirealist-fix walist))
 
1615
       (db (us-db-fix db))
 
1616
       (dbalist (us-dbalist-fix dbalist))
 
1617
       (warnings (vl-warninglist-fix warnings))
 
1618
       (notes (us-notelist-fix notes))
 
1619
       ((vl-modinst x) x)
 
1620
 
 
1621
       ((unless (and (not x.range)
 
1622
                     (vl-paramargs-empty-p x.paramargs)
 
1623
                     (eq (vl-arguments-kind x.portargs) :vl-arguments-plain)))
 
1624
        (b* ((w (make-vl-warning
 
1625
                 :type :use-set-fudging
 
1626
                 :msg "~a0: skipping this module instance because it has a ~
1673
1627
                       range, parameters, or unresolved arguments."
1674
 
                   :args (list x x.modname)
1675
 
                   :fn 'us-mark-wires-for-modinst)))
1676
 
            (mv (cons w warnings) db notes)))
1677
 
 
1678
 
         (actuals (vl-arguments-plain->args x.portargs))
1679
 
 
1680
 
         (submod (vl-fast-find-module x.modname mods modalist))
1681
 
         ((unless submod)
1682
 
          (b* ((w (make-vl-warning
1683
 
                   :type :use-set-fudging
1684
 
                   :msg "~a0: skipping this module instance because module ~m1 ~
 
1628
                 :args (list x x.modname)
 
1629
                 :fn 'us-mark-wires-for-modinst)))
 
1630
          (mv (cons w warnings) db notes)))
 
1631
 
 
1632
       (actuals (vl-arguments-plain->args x.portargs))
 
1633
 
 
1634
       (submod (vl-scopestack-find-definition x.modname ss))
 
1635
       ((unless (and submod (eq (tag submod) :vl-module)))
 
1636
        (b* ((w (make-vl-warning
 
1637
                 :type :use-set-fudging
 
1638
                 :msg "~a0: skipping this module instance because module ~m1 ~
1685
1639
                       was not found."
1686
 
                   :args (list x x.modname)
1687
 
                   :fn 'us-mark-wires-for-modinst)))
1688
 
            (mv (cons w warnings) db notes)))
 
1640
                 :args (list x x.modname)
 
1641
                 :fn 'us-mark-wires-for-modinst)))
 
1642
          (mv (cons w warnings) db notes)))
1689
1643
 
1690
 
         (sub-db-look (hons-get x.modname dbalist))
1691
 
         (sub-db      (cdr sub-db-look))
1692
 
         ((unless sub-db-look)
1693
 
          (b* ((w (make-vl-warning
1694
 
                   :type :use-set-fudging
1695
 
                   :msg "~a0: skipping this module instance because the use-set ~
 
1644
       (sub-db-look (hons-get x.modname dbalist))
 
1645
       (sub-db      (cdr sub-db-look))
 
1646
       ((unless sub-db-look)
 
1647
        (b* ((w (make-vl-warning
 
1648
                 :type :use-set-fudging
 
1649
                 :msg "~a0: skipping this module instance because the use-set ~
1696
1650
                       database for ~m1 was not found."
1697
 
                   :args (list x x.modname)
1698
 
                   :fn 'us-mark-wires-for-modinst)))
1699
 
            (mv (cons w warnings) db notes)))
 
1651
                 :args (list x x.modname)
 
1652
                 :fn 'us-mark-wires-for-modinst)))
 
1653
          (mv (cons w warnings) db notes)))
1700
1654
 
1701
 
         (sub-walist-look (hons-get x.modname all-walists))
1702
 
         (sub-walist      (cdr sub-walist-look))
1703
 
         ((unless sub-walist-look)
1704
 
          (b* ((w (make-vl-warning
1705
 
                   :type :use-set-fudging
1706
 
                   :msg "~a0: skipping this module instance because the wire ~
 
1655
       (sub-walist-look (hons-get x.modname all-walists))
 
1656
       (sub-walist      (cdr sub-walist-look))
 
1657
       ((unless sub-walist-look)
 
1658
        (b* ((w (make-vl-warning
 
1659
                 :type :use-set-fudging
 
1660
                 :msg "~a0: skipping this module instance because the wire ~
1707
1661
                       alist for ~m1 was not found."
1708
 
                   :args (list x x.modname)
1709
 
                   :fn 'us-mark-wires-for-modinst)))
1710
 
            (mv (cons w warnings) db notes)))
 
1662
                 :args (list x x.modname)
 
1663
                 :fn 'us-mark-wires-for-modinst)))
 
1664
          (mv (cons w warnings) db notes)))
1711
1665
 
1712
 
         ((mv successp warnings1 portpat)
1713
 
          (vl-portlist-msb-bit-pattern (vl-module->ports submod) sub-walist))
1714
 
         (warnings (append-without-guard warnings1 warnings))
1715
 
         ((unless successp)
1716
 
          (b* ((w (make-vl-warning
1717
 
                   :type :use-set-fudging
1718
 
                   :msg "~a0: skipping this module instance because the port pattern ~
 
1666
       ((mv successp warnings1 portpat)
 
1667
        (vl-portlist-msb-bit-pattern (vl-module->ports submod) sub-walist))
 
1668
       (warnings (append-without-guard warnings1 warnings))
 
1669
       ((unless successp)
 
1670
        (b* ((w (make-vl-warning
 
1671
                 :type :use-set-fudging
 
1672
                 :msg "~a0: skipping this module instance because the port pattern ~
1719
1673
                       for ~m1 was not successfully generated."
1720
 
                   :args (list x x.modname)
1721
 
                   :fn 'us-mark-wires-for-modinst)))
1722
 
            (mv (cons w warnings) db notes)))
 
1674
                 :args (list x x.modname)
 
1675
                 :fn 'us-mark-wires-for-modinst)))
 
1676
          (mv (cons w warnings) db notes)))
1723
1677
 
1724
 
         ((unless (same-lengthp portpat actuals))
1725
 
          (b* ((w (make-vl-warning
1726
 
                   :type :use-set-fudging
1727
 
                   :msg "~a0: skipping this module instance because it has ~x1 arguments ~
 
1678
       ((unless (same-lengthp portpat actuals))
 
1679
        (b* ((w (make-vl-warning
 
1680
                 :type :use-set-fudging
 
1681
                 :msg "~a0: skipping this module instance because it has ~x1 arguments ~
1728
1682
                       but we expected ~x2 arguments."
1729
 
                   :args (list x (len actuals) (len portpat))
1730
 
                   :fn 'us-mark-wires-for-modinst)))
1731
 
            (mv (cons w warnings) db notes))))
1732
 
 
1733
 
      (us-mark-wires-for-modinst-args actuals portpat
1734
 
                                      sub-db db walist
1735
 
                                      warnings x notes)))
1736
 
 
1737
 
  (defthm us-mark-wires-for-modinst-basics
1738
 
    (implies (and (force (vl-modinst-p x))
1739
 
                  (force (vl-wirealist-p walist))
1740
 
                  (force (us-db-p db))
1741
 
                  (force (vl-modulelist-p mods))
1742
 
                  (force (equal modalist (vl-modalist mods)))
1743
 
                  (force (us-dbalist-p dbalist))
1744
 
                  (force (equal all-walists (vl-nowarn-all-wirealists mods)))
1745
 
                  (force (vl-warninglist-p warnings))
1746
 
                  (force (us-notelist-p notes)))
1747
 
             (let ((ret (us-mark-wires-for-modinst x walist db mods modalist dbalist all-walists warnings notes)))
1748
 
               (and (vl-warninglist-p (mv-nth 0 ret))
1749
 
                    (us-db-p (mv-nth 1 ret))
1750
 
                    (us-notelist-p (mv-nth 2 ret)))))
1751
 
    :hints(("Goal" :in-theory (enable us-mark-wires-for-modinst)))))
1752
 
 
1753
 
 
1754
 
 
1755
 
 
1756
 
(defsection us-mark-wires-for-modinstlist
1757
 
 
1758
 
  (defund us-mark-wires-for-modinstlist
1759
 
    (x        ; the modinstlist to process
1760
 
     walist   ; walist for the current module
1761
 
     db       ; db for the current module (may be extended)
1762
 
     mods     ; all modules
1763
 
     modalist ; modalist for all modules
1764
 
     dbalist ; dbalist-p that should bind every submodule (due to dependency order traversal)
1765
 
     all-walists ; precomputed walists for all mods
1766
 
     warnings    ; warnings accumulator (may be extended)
1767
 
     notes       ; notes accumulator (may be extended)
1768
 
     )
1769
 
    "Returns (MV WARNINGS DB NOTES)"
1770
 
    (declare (xargs :guard (and (vl-modinstlist-p x)
1771
 
                                (vl-wirealist-p walist)
1772
 
                                (us-db-p db)
1773
 
                                (vl-modulelist-p mods)
1774
 
                                (equal modalist (vl-modalist mods))
1775
 
                                (us-dbalist-p dbalist)
1776
 
                                (equal all-walists (vl-nowarn-all-wirealists mods))
1777
 
                                (vl-warninglist-p warnings)
1778
 
                                (us-notelist-p notes))))
1779
 
    (b* (((when (atom x))
1780
 
          (mv warnings db notes))
1781
 
         ((mv warnings db notes)
1782
 
          (us-mark-wires-for-modinst (car x) walist db mods modalist
1783
 
                                     dbalist all-walists warnings notes))
1784
 
         ((mv warnings db notes)
1785
 
          (us-mark-wires-for-modinstlist (cdr x) walist db mods modalist
1786
 
                                         dbalist all-walists warnings notes)))
1787
 
      (mv warnings db notes)))
1788
 
 
1789
 
  (defthm us-mark-wires-for-modinstlist-basics
1790
 
    (implies (and (force (vl-modinstlist-p x))
1791
 
                  (force (vl-wirealist-p walist))
1792
 
                  (force (us-db-p db))
1793
 
                  (force (vl-modulelist-p mods))
1794
 
                  (force (equal modalist (vl-modalist mods)))
1795
 
                  (force (us-dbalist-p dbalist))
1796
 
                  (force (equal all-walists (vl-nowarn-all-wirealists mods)))
1797
 
                  (force (vl-warninglist-p warnings))
1798
 
                  (force (us-notelist-p notes)))
1799
 
             (let ((ret (us-mark-wires-for-modinstlist x walist db mods modalist dbalist all-walists
1800
 
                                                       warnings notes)))
1801
 
               (and (vl-warninglist-p (mv-nth 0 ret))
1802
 
                    (us-db-p (mv-nth 1 ret))
1803
 
                    (us-notelist-p (mv-nth 2 ret)))))
1804
 
    :hints(("Goal" :in-theory (enable us-mark-wires-for-modinstlist)))))
1805
 
 
1806
 
 
1807
 
 
1808
 
 
1809
 
 
1810
 
(defsection us-union-masks
1811
 
 
1812
 
  (defund us-union-masks (super wires db warnings)
1813
 
    "Returns (MV WARNINGS MASK)"
1814
 
    (declare (xargs :guard (and (stringp super)
1815
 
                                (vl-emodwirelist-p wires)
1816
 
                                (us-db-p db)
1817
 
                                (vl-warninglist-p warnings))))
1818
 
    (b* (((when (atom wires))
1819
 
          (mv warnings 0))
1820
 
         ((mv warnings cdr-mask)
1821
 
          (us-union-masks super (cdr wires) db warnings))
1822
 
         (entry1 (hons-get (car wires) db))
1823
 
         ((unless entry1)
1824
 
          (b* ((w (make-vl-warning
1825
 
                   :type :use-set-fudging
1826
 
                   :msg "In ~m0, expected use-set database entry for ~s1.  ~
 
1683
                 :args (list x (len actuals) (len portpat))
 
1684
                 :fn 'us-mark-wires-for-modinst)))
 
1685
          (mv (cons w warnings) db notes))))
 
1686
 
 
1687
    (us-mark-wires-for-modinst-args actuals portpat
 
1688
                                    sub-db db walist
 
1689
                                    warnings x notes)))
 
1690
 
 
1691
 
 
1692
(define us-mark-wires-for-modinstlist
 
1693
  ((x vl-modinstlist-p)        ; the modinstlist to process
 
1694
   (walist vl-wirealist-p)   ; walist for the current module
 
1695
   (db us-db-p)       ; db for the current module (may be extended)
 
1696
   (mods vl-modulelist-p)     ; all modules
 
1697
   (ss vl-scopestack-p)
 
1698
   (dbalist us-dbalist-p) ; dbalist-p that should bind every submodule (due to dependency order traversal)
 
1699
   (all-walists (equal all-walists (vl-nowarn-all-wirealists mods))) ; precomputed walists for all mods
 
1700
   (warnings vl-warninglist-p)    ; warnings accumulator (may be extended)
 
1701
   (notes us-notelist-p)       ; notes accumulator (may be extended)
 
1702
   )
 
1703
  :returns (mv (warnings vl-warninglist-p)
 
1704
               (db us-db-p)
 
1705
               (notes us-notelist-p))
 
1706
  :measure (len (vl-modinstlist-fix x))
 
1707
  (b* ((x (vl-modinstlist-fix x))
 
1708
       (walist (vl-wirealist-fix walist))
 
1709
       (db (us-db-fix db))
 
1710
       (mods (vl-modulelist-fix mods))
 
1711
       (dbalist (us-dbalist-fix dbalist))
 
1712
       (warnings (vl-warninglist-fix warnings))
 
1713
       (notes (us-notelist-fix notes))
 
1714
       ((when (atom x))
 
1715
        (mv warnings db notes))
 
1716
       ((mv warnings db notes)
 
1717
        (us-mark-wires-for-modinst (car x) walist db mods ss
 
1718
                                   dbalist all-walists warnings notes))
 
1719
       ((mv warnings db notes)
 
1720
        (us-mark-wires-for-modinstlist (cdr x) walist db mods ss
 
1721
                                       dbalist all-walists warnings notes)))
 
1722
    (mv warnings db notes)))
 
1723
 
 
1724
 
 
1725
 
 
1726
 
 
1727
 
 
1728
(define us-union-masks ((super stringp)
 
1729
                        (wires vl-emodwirelist-p)
 
1730
                        (db us-db-p)
 
1731
                        (warnings vl-warninglist-p))
 
1732
  :returns (mv (warnings vl-warninglist-p)
 
1733
               (mask natp))
 
1734
  :measure (len (vl-emodwirelist-fix wires))
 
1735
  (b* ((super (string-fix super))
 
1736
       (wires (vl-emodwirelist-fix wires))
 
1737
       (db (us-db-fix db))
 
1738
       (warnings (vl-warninglist-fix warnings))
 
1739
       ((when (atom wires))
 
1740
        (mv warnings 0))
 
1741
       ((mv warnings cdr-mask)
 
1742
        (us-union-masks super (cdr wires) db warnings))
 
1743
       (entry1 (hons-get (car wires) db))
 
1744
       ((unless entry1)
 
1745
        (b* ((w (make-vl-warning
 
1746
                 :type :use-set-fudging
 
1747
                 :msg "In ~m0, expected use-set database entry for ~s1.  ~
1827
1748
                         Assuming unused/unset.  The used/set from above info ~
1828
1749
                         for ports may be incorrect."
1829
 
                   :args (list super (car wires))
1830
 
                   :fn 'us-union-masks
1831
 
                   :fatalp nil)))
1832
 
            (mv (cons w warnings) cdr-mask)))
1833
 
         (mask (acl2::bitset-insert (cdr entry1) cdr-mask)))
1834
 
      (mv warnings mask)))
1835
 
 
1836
 
  (defthm us-union-masks-basics
1837
 
    (implies (and (force (stringp super))
1838
 
                  (force (vl-emodwirelist-p wires))
1839
 
                  (force (us-db-p db))
1840
 
                  (force (vl-warninglist-p warnings)))
1841
 
             (let ((ret (us-union-masks super wires db warnings)))
1842
 
               (and (vl-warninglist-p (mv-nth 0 ret))
1843
 
                    (natp (mv-nth 1 ret)))))
1844
 
    :hints(("Goal" :in-theory (enable us-union-masks)))))
1845
 
 
1846
 
 
1847
 
(defsection us-mark-wires-for-notes
1848
 
 
1849
 
  (defund us-mark-wires-for-notes (submod mask wires db reportcard)
1850
 
    "Returns (MV REPORTCARD DB)"
1851
 
    (declare (xargs :guard (and (stringp submod)
1852
 
                                (natp mask)
1853
 
                                (vl-emodwirelist-p wires)
1854
 
                                (us-db-p db)
1855
 
                                (vl-reportcard-p reportcard))))
1856
 
    (b* (((when (atom wires))
1857
 
          (mv reportcard db))
1858
 
         ((mv reportcard db)
1859
 
          (us-mark-wires-for-notes submod mask (cdr wires) db reportcard))
1860
 
         (wire1-look (hons-get (car wires) db))
1861
 
         ((unless wire1-look)
1862
 
          (b* ((w (make-vl-warning
1863
 
                   :type :use-set-fudging
1864
 
                   :msg "Expected use-set database entry for ~s0.  Ignoring this wire."
1865
 
                   :args (list (car wires))
1866
 
                   :fn 'us-mark-wires-for-notes
1867
 
                   :fatalp nil)))
1868
 
            (mv (vl-extend-reportcard submod w reportcard) db)))
1869
 
         (curr-mask (cdr wire1-look))
1870
 
         (new-mask  (acl2::bitset-union curr-mask mask))
1871
 
         ((when (= curr-mask new-mask))
1872
 
          ;; nothing to do
1873
 
          (mv reportcard db))
1874
 
         (db (hons-acons (car wires) new-mask db)))
1875
 
      (mv reportcard db)))
1876
 
 
1877
 
  (defthm us-mark-wires-for-notes-basics
1878
 
    (implies (and (force (stringp submod))
1879
 
                  (force (natp mask))
1880
 
                  (force (vl-emodwirelist-p wires))
1881
 
                  (force (us-db-p db))
1882
 
                  (force (vl-reportcard-p reportcard)))
1883
 
             (let ((ret (us-mark-wires-for-notes submod mask wires db reportcard)))
1884
 
               (and (vl-reportcard-p (mv-nth 0 ret))
1885
 
                    (us-db-p (mv-nth 1 ret)))))
1886
 
    :hints(("Goal" :in-theory (enable us-mark-wires-for-notes)))))
1887
 
 
1888
 
 
1889
 
(defsection us-apply-notes
1890
 
 
1891
 
  (defund us-apply-notes (super notes db dbalist reportcard)
1892
 
    "Returns (MV REPORTCARD' DBALIST')"
1893
 
    (declare (xargs :guard (and (stringp super)
1894
 
                                (us-notelist-p notes)
1895
 
                                (us-db-p db)           ; DB for the current module
1896
 
                                (us-dbalist-p dbalist) ; DBS for the submodules
1897
 
                                (vl-reportcard-p reportcard))
1898
 
                    :verify-guards nil))
1899
 
    (b* (((when (atom notes))
1900
 
          (mv reportcard dbalist))
1901
 
 
1902
 
         ((mv reportcard dbalist)
1903
 
          (us-apply-notes super (cdr notes) db dbalist reportcard))
1904
 
 
1905
 
         ((us-note note1) (car notes))
1906
 
 
1907
 
         (sub-db-look (hons-get note1.submod dbalist))
1908
 
         (sub-db      (cdr sub-db-look))
1909
 
         ((unless sub-db-look)
1910
 
          (b* ((w (make-vl-warning
1911
 
                   :type :use-set-fudging
1912
 
                   :msg "Expected an entry for ~m0 in the dbalist.  Failing to record ~
 
1750
                 :args (list super (car wires))
 
1751
                 :fn 'us-union-masks
 
1752
                 :fatalp nil)))
 
1753
          (mv (cons w warnings) cdr-mask)))
 
1754
       (mask (acl2::bitset-insert (cdr entry1) cdr-mask)))
 
1755
    (mv warnings mask)))
 
1756
 
 
1757
 
 
1758
(define us-mark-wires-for-notes ((submod stringp)
 
1759
                                 (mask natp)
 
1760
                                 (wires vl-emodwirelist-p)
 
1761
                                 (db us-db-p)
 
1762
                                 (reportcard vl-reportcard-p))
 
1763
  :returns (mv (reportcard vl-reportcard-p)
 
1764
               (db us-db-p))
 
1765
  :measure (len (vl-emodwirelist-fix wires))
 
1766
  (b* ((submod (string-fix submod))
 
1767
       (mask (lnfix mask))
 
1768
       (wires (vl-emodwirelist-fix wires))
 
1769
       (db (us-db-fix db))
 
1770
       (reportcard (vl-reportcard-fix reportcard))
 
1771
       ((when (atom wires))
 
1772
        (mv reportcard db))
 
1773
       ((mv reportcard db)
 
1774
        (us-mark-wires-for-notes submod mask (cdr wires) db reportcard))
 
1775
       (wire1-look (hons-get (car wires) db))
 
1776
       ((unless wire1-look)
 
1777
        (b* ((w (make-vl-warning
 
1778
                 :type :use-set-fudging
 
1779
                 :msg "Expected use-set database entry for ~s0.  Ignoring this wire."
 
1780
                 :args (list (car wires))
 
1781
                 :fn 'us-mark-wires-for-notes
 
1782
                 :fatalp nil)))
 
1783
          (mv (vl-extend-reportcard submod w reportcard) db)))
 
1784
       (curr-mask (cdr wire1-look))
 
1785
       (new-mask  (acl2::bitset-union curr-mask mask))
 
1786
       ((when (= curr-mask new-mask))
 
1787
        ;; nothing to do
 
1788
        (mv reportcard db))
 
1789
       (db (hons-acons (car wires) new-mask db)))
 
1790
    (mv reportcard db)))
 
1791
 
 
1792
 
 
1793
(define us-apply-notes ((super stringp)
 
1794
                        (notes us-notelist-p)
 
1795
                        (db us-db-p)           ; DB for the current module
 
1796
                        (dbalist us-dbalist-p) ; DBS for the submodules
 
1797
                        (reportcard vl-reportcard-p))
 
1798
  :returns (mv (reportcard vl-reportcard-p)
 
1799
               (dbalist us-dbalist-p))
 
1800
  :verify-guards nil
 
1801
  :measure (len (us-notelist-fix notes))
 
1802
  :hooks ((:fix :hints (("goal" :expand ((:free (super db dbalist reportcard)
 
1803
                                          (us-apply-notes super notes db dbalist reportcard))
 
1804
                                         (us-apply-notes super (us-notelist-fix notes)
 
1805
                                                         db dbalist reportcard))
 
1806
                         :do-not-induct t))))
 
1807
  (b* ((super (string-fix super))
 
1808
       (notes (us-notelist-fix notes))
 
1809
       (db (us-db-fix db))
 
1810
       (dbalist (us-dbalist-fix dbalist))
 
1811
       (reportcard (vl-reportcard-fix reportcard))
 
1812
       ((when (atom notes))
 
1813
        (mv reportcard dbalist))
 
1814
 
 
1815
       ((mv reportcard dbalist)
 
1816
        (us-apply-notes super (cdr notes) db dbalist reportcard))
 
1817
 
 
1818
       ((us-note note1) (car notes))
 
1819
 
 
1820
       (sub-db-look (hons-get note1.submod dbalist))
 
1821
       (sub-db      (cdr sub-db-look))
 
1822
       ((unless sub-db-look)
 
1823
        (b* ((w (make-vl-warning
 
1824
                 :type :use-set-fudging
 
1825
                 :msg "Expected an entry for ~m0 in the dbalist.  Failing to record ~
1913
1826
                       superior uses/sets of ~&1."
1914
 
                   :args (list note1.submod note1.formals)
1915
 
                   :fatalp nil
1916
 
                   :fn 'us-apply-notes)))
1917
 
            (mv (vl-extend-reportcard note1.submod w reportcard)
1918
 
                dbalist)))
1919
 
 
1920
 
         ((mv warnings actuals-mask)
1921
 
          (us-union-masks super note1.actuals db nil))
1922
 
 
1923
 
         (reportcard (if (consp warnings)
1924
 
                      (vl-extend-reportcard-list note1.submod warnings reportcard)
1925
 
                    reportcard))
1926
 
 
1927
 
         (above-mask 0)
1928
 
         ;; a wire is used above the submodule if used in the current module or
1929
 
         ;; used above the current module.
1930
 
         (above-mask (if (or (acl2::bitset-memberp *us-truly-setp* actuals-mask)
1931
 
                             (acl2::bitset-memberp *us-truly-set-abovep* actuals-mask))
1932
 
                         (acl2::bitset-insert *us-truly-set-abovep* above-mask)
1933
 
                       above-mask))
1934
 
         (above-mask (if (or (acl2::bitset-memberp *us-truly-usedp* actuals-mask)
1935
 
                             (acl2::bitset-memberp *us-truly-used-abovep* actuals-mask))
1936
 
                         (acl2::bitset-insert *us-truly-used-abovep* above-mask)
1937
 
                       above-mask))
1938
 
 
1939
 
         ((mv reportcard new-sub-db) (us-mark-wires-for-notes note1.submod above-mask note1.formals sub-db reportcard))
1940
 
         (dbalist                 (hons-acons note1.submod new-sub-db dbalist))
1941
 
 
1942
 
         )
1943
 
      (mv reportcard dbalist)))
1944
 
 
1945
 
  (defthm us-apply-notes-basics
1946
 
    (implies (and (force (stringp super))
1947
 
                  (force (us-notelist-p notes))
1948
 
                  (force (us-db-p db))
1949
 
                  (force (us-dbalist-p dbalist))
1950
 
                  (force (vl-reportcard-p reportcard)))
1951
 
             (let ((ret (us-apply-notes super notes db dbalist reportcard)))
1952
 
               (and (vl-reportcard-p (mv-nth 0 ret))
1953
 
                    (us-dbalist-p (mv-nth 1 ret))
1954
 
                    )))
1955
 
    :hints(("Goal"
1956
 
            :do-not '(generalize fertilize eliminate-destructors)
1957
 
            :in-theory (enable us-apply-notes))))
1958
 
 
 
1827
                 :args (list note1.submod note1.formals)
 
1828
                 :fatalp nil
 
1829
                 :fn 'us-apply-notes)))
 
1830
          (mv (vl-extend-reportcard note1.submod w reportcard)
 
1831
              dbalist)))
 
1832
 
 
1833
       ((mv warnings actuals-mask)
 
1834
        (us-union-masks super note1.actuals db nil))
 
1835
 
 
1836
       (reportcard (if (consp warnings)
 
1837
                       (vl-extend-reportcard-list note1.submod warnings reportcard)
 
1838
                     reportcard))
 
1839
 
 
1840
       (above-mask 0)
 
1841
       ;; a wire is used above the submodule if used in the current module or
 
1842
       ;; used above the current module.
 
1843
       (above-mask (if (or (acl2::bitset-memberp *us-truly-setp* actuals-mask)
 
1844
                           (acl2::bitset-memberp *us-truly-set-abovep* actuals-mask))
 
1845
                       (acl2::bitset-insert *us-truly-set-abovep* above-mask)
 
1846
                     above-mask))
 
1847
       (above-mask (if (or (acl2::bitset-memberp *us-truly-usedp* actuals-mask)
 
1848
                           (acl2::bitset-memberp *us-truly-used-abovep* actuals-mask))
 
1849
                       (acl2::bitset-insert *us-truly-used-abovep* above-mask)
 
1850
                     above-mask))
 
1851
 
 
1852
       ((mv reportcard new-sub-db) (us-mark-wires-for-notes note1.submod above-mask note1.formals sub-db reportcard))
 
1853
       (dbalist                 (hons-acons note1.submod new-sub-db dbalist))
 
1854
 
 
1855
       )
 
1856
    (mv reportcard dbalist))
 
1857
  ///
1959
1858
  (verify-guards us-apply-notes))
1960
1859
 
1961
1860
 
1962
 
 
1963
 
(defsection us-apply-notesalist
1964
 
 
1965
 
  (defund us-apply-notesalist (x notealist dbalist reportcard)
1966
 
    "Returns (MV REPORTCARD' DBALIST')"
1967
 
    (declare (xargs :guard (and (vl-modulelist-p x)
1968
 
                                (us-notealist-p notealist)
1969
 
                                (us-dbalist-p dbalist)
1970
 
                                (vl-reportcard-p reportcard))))
1971
 
    (b* (((when (atom x))
1972
 
          (mv reportcard dbalist))
1973
 
 
1974
 
         ((vl-module x1) (car x))
1975
 
         (db-look    (hons-get x1.name dbalist))
1976
 
         (notes-look (hons-get x1.name notealist))
1977
 
         (db         (cdr db-look))
1978
 
         (notes      (cdr notes-look))
1979
 
         (reportcard
1980
 
          (if (and db-look notes-look)
1981
 
              reportcard
1982
 
            (b* ((w (make-vl-warning
1983
 
                     :type :use-set-fudging
1984
 
                     :msg "Expected use-set database and notes for ~
 
1861
(define us-apply-notesalist ((x vl-modulelist-p)
 
1862
                             (notealist us-notealist-p)
 
1863
                             (dbalist us-dbalist-p)
 
1864
                             (reportcard vl-reportcard-p))
 
1865
  :returns (mv (reportcard vl-reportcard-p)
 
1866
               (dbalist us-dbalist-p))
 
1867
  :measure (len (vl-modulelist-fix x))
 
1868
  (b* ((x (vl-modulelist-fix x))
 
1869
       (notealist (us-notealist-fix notealist))
 
1870
       (dbalist (us-dbalist-fix dbalist))
 
1871
       (reportcard (vl-reportcard-fix reportcard))
 
1872
       ((when (atom x))
 
1873
        (mv reportcard dbalist))
 
1874
 
 
1875
       ((vl-module x1) (car x))
 
1876
       (db-look    (hons-get x1.name dbalist))
 
1877
       (notes-look (hons-get x1.name notealist))
 
1878
       (db         (cdr db-look))
 
1879
       (notes      (cdr notes-look))
 
1880
       (reportcard
 
1881
        (if (and db-look notes-look)
 
1882
            reportcard
 
1883
          (b* ((w (make-vl-warning
 
1884
                   :type :use-set-fudging
 
1885
                   :msg "Expected use-set database and notes for ~
1985
1886
                                 module ~m0.  Not propagating used/set from ~
1986
1887
                                 above information."
1987
 
                     :args (list x1.name)
1988
 
                     :fatalp nil
1989
 
                     :fn 'us-apply-notesalist)))
1990
 
              (vl-extend-reportcard x1.name w reportcard))))
1991
 
         ((mv reportcard dbalist)
1992
 
          (us-apply-notes x1.name notes db dbalist reportcard))
1993
 
         ((mv reportcard dbalist)
1994
 
          (us-apply-notesalist (cdr x) notealist dbalist reportcard)))
1995
 
      (mv reportcard dbalist)))
1996
 
 
1997
 
  (defthm us-apply-notesalist-basics
1998
 
    (implies (and (force (vl-modulelist-p x))
1999
 
                  (force (us-notealist-p notealist))
2000
 
                  (force (us-dbalist-p dbalist))
2001
 
                  (force (vl-reportcard-p reportcard)))
2002
 
             (let ((ret (us-apply-notesalist x notealist dbalist reportcard)))
2003
 
               (and (vl-reportcard-p (mv-nth 0 ret))
2004
 
                    (us-dbalist-p (mv-nth 1 ret)))))
2005
 
    :hints(("Goal" :in-theory (enable us-apply-notesalist)))))
2006
 
 
2007
 
 
2008
 
 
2009
 
(defalist us-results-p (x)
2010
 
  :key (natp x)
2011
 
  :val (vl-emodwirelist-p x)
 
1888
                   :args (list x1.name)
 
1889
                   :fatalp nil
 
1890
                   :fn 'us-apply-notesalist)))
 
1891
            (vl-extend-reportcard x1.name w reportcard))))
 
1892
       ((mv reportcard dbalist)
 
1893
        (us-apply-notes x1.name notes db dbalist reportcard))
 
1894
       ((mv reportcard dbalist)
 
1895
        (us-apply-notesalist (cdr x) notealist dbalist reportcard)))
 
1896
    (mv reportcard dbalist)))
 
1897
 
 
1898
 
 
1899
(fty::defalist us-results
 
1900
  :key-type natp
 
1901
  :val-type vl-emodwirelist-p
2012
1902
  :keyp-of-nil nil
2013
1903
  :valp-of-nil t)
2014
1904
 
2015
1905
 
2016
 
(defsection us-organize-results
 
1906
(define us-organize-results-aux
2017
1907
 
2018
1908
; Invert the database so that each bit-set is associated with the list of wires
2019
1909
; that have it.  This way you can extract the wires that have any particular
2022
1912
 
2023
1913
; ASSUMES THE DATABSE HAS ALREADY BEEN SHRUNK.
2024
1914
 
2025
 
  (defund us-organize-results-aux (db buckets)
2026
 
    ;; DB binds names to masks.  Buckets binds masks to names.
2027
 
    (declare (xargs :guard (us-db-p db)))
2028
 
    (b* (((when (atom db))
2029
 
          buckets)
2030
 
         (name1      (caar db))
2031
 
         (val1       (cdar db))
2032
 
         (val1-wires (cdr (hons-get val1 buckets)))
2033
 
         (buckets    (hons-acons val1 (cons name1 val1-wires) buckets)))
2034
 
      (us-organize-results-aux (cdr db) buckets)))
2035
 
 
2036
 
  (defthm us-results-p-of-us-organize-results-aux
2037
 
    (implies (and (force (us-db-p db))
2038
 
                  (force (us-results-p buckets)))
2039
 
             (us-results-p (us-organize-results-aux db buckets)))
2040
 
    :hints(("Goal"
2041
 
            :do-not '(generalize fertilize)
2042
 
            :in-theory (e/d (us-organize-results-aux)
2043
 
                            (hons-acons)))))
2044
 
 
2045
 
  (defund us-organize-results (db)
2046
 
    (declare (xargs :guard (us-db-p db)))
 
1915
  ((db us-db-p)
 
1916
   (buckets us-results-p))
 
1917
  :returns (buckets us-results-p)
 
1918
  :measure (len (us-db-fix db))
 
1919
  ;; DB binds names to masks.  Buckets binds masks to names.
 
1920
  (b* ((db (us-db-fix db))
 
1921
       (buckets (us-results-fix buckets))
 
1922
       ((when (atom db))
 
1923
        buckets)
 
1924
       (name1      (caar db))
 
1925
       (val1       (cdar db))
 
1926
       (val1-wires (cdr (hons-get val1 buckets)))
 
1927
       (buckets    (hons-acons val1 (cons name1 val1-wires) buckets)))
 
1928
    (us-organize-results-aux (cdr db) buckets)))
 
1929
 
 
1930
 
 
1931
(define us-organize-results ((db us-db-p))
 
1932
  :returns (buckets us-results-p)
2047
1933
    (b* ((temp (us-organize-results-aux db nil))
2048
1934
         (ret  (hons-shrink-alist temp nil))
2049
1935
         (-    (fast-alist-free temp))
2050
1936
         (-    (fast-alist-free ret)))
2051
1937
      ret))
2052
1938
 
2053
 
  (defthm us-results-p-of-us-organize-results
2054
 
    (implies (force (us-db-p db))
2055
 
             (us-results-p (us-organize-results db)))
2056
 
    :hints(("Goal" :in-theory (enable us-organize-results)))))
2057
 
 
2058
 
 
2059
 
(defsection us-filter-db-by-names
 
1939
 
 
1940
(define us-filter-db-by-names1
2060
1941
 
2061
1942
;; Get entries that have particular names
2062
1943
 
2063
1944
; ASSUMES THE DATABSE HAS ALREADY BEEN SHRUNK
2064
1945
 
2065
 
  (defund us-filter-db-by-names1 (names names-fal db yes no)
2066
 
    "Returns (MV YES NO), slow alists."
2067
 
    (declare (xargs :guard (and (equal names-fal (make-lookup-alist names))
2068
 
                                (us-db-p db))))
2069
 
    (b* (((when (atom db))
2070
 
          (mv yes no))
2071
 
         ((mv yes no)
2072
 
          (if (fast-memberp (caar db) names names-fal)
2073
 
              (mv (cons (car db) yes) no)
2074
 
            (mv yes (cons (car db) no)))))
2075
 
      (us-filter-db-by-names1 names names-fal (cdr db) yes no)))
2076
 
 
2077
 
  (defund us-filter-db-by-names (names db)
2078
 
    "Returns (MV YES NO), slow alists."
2079
 
    (declare (xargs :guard (us-db-p db)))
2080
 
    (b* ((fal (make-lookup-alist names))
2081
 
         ((mv yes no) (us-filter-db-by-names1 names fal db nil nil))
2082
 
         (- (fast-alist-free fal)))
2083
 
      (mv yes no)))
2084
 
 
2085
 
  (defthm us-filter-db-by-names1-basics
2086
 
    (implies (and (force (equal names-fal (make-lookup-alist names)))
2087
 
                  (force (us-db-p db))
2088
 
                  (force (us-db-p yes))
2089
 
                  (force (us-db-p no)))
2090
 
             (let ((ret (us-filter-db-by-names1 names names-fal db yes no)))
2091
 
               (and (us-db-p (mv-nth 0 ret))
2092
 
                    (us-db-p (mv-nth 1 ret)))))
2093
 
    :hints(("Goal" :in-theory (enable us-filter-db-by-names1))))
2094
 
 
2095
 
  (defthm us-filter-db-by-names-basics
2096
 
    (implies (force (us-db-p db))
2097
 
             (let ((ret (us-filter-db-by-names names db)))
2098
 
               (and (us-db-p (mv-nth 0 ret))
2099
 
                    (us-db-p (mv-nth 1 ret)))))
2100
 
    :hints(("Goal" :in-theory (enable us-filter-db-by-names)))))
2101
 
 
2102
 
 
2103
 
(defsection us-filter-db-by-bit
 
1946
  (names names-fal (db us-db-p) (yes us-db-p) (no us-db-p))
 
1947
  :returns (mv (yes us-db-p)
 
1948
               (no us-db-p))
 
1949
  :guard (equal names-fal (make-lookup-alist names))
 
1950
  :measure (len (us-db-fix db))
 
1951
  (b* ((db (us-db-fix db))
 
1952
       (yes (us-db-fix yes))
 
1953
       (no (us-db-fix no))
 
1954
       ((when (atom db))
 
1955
        (mv yes no))
 
1956
       ((mv yes no)
 
1957
        (if (fast-memberp (caar db) names names-fal)
 
1958
            (mv (cons (car db) yes) no)
 
1959
          (mv yes (cons (car db) no)))))
 
1960
    (us-filter-db-by-names1 names names-fal (cdr db) yes no)))
 
1961
 
 
1962
(define us-filter-db-by-names (names (db us-db-p))
 
1963
  :returns (mv (yes us-db-p) ;; slow alists
 
1964
               (no us-db-p))
 
1965
  (b* ((fal (make-lookup-alist names))
 
1966
       ((mv yes no) (us-filter-db-by-names1 names fal db nil nil))
 
1967
       (- (fast-alist-free fal)))
 
1968
    (mv yes no)))
 
1969
 
 
1970
 
 
1971
(define us-filter-db-by-bit1
2104
1972
 
2105
1973
  ;; Get entries that have a particular bit set
2106
1974
 
2107
1975
; ASSUMES THE DATABSE HAS ALREADY BEEN SHRUNK
2108
1976
 
2109
 
  (defund us-filter-db-by-bit1 (bit db yes no)
2110
 
    "Returns (MV YES NO), slow alists."
2111
 
    (declare (xargs :guard (and (natp bit)
2112
 
                                (us-db-p db))))
2113
 
    (b* (((when (atom db))
2114
 
          (mv yes no))
2115
 
         ((mv yes no)
2116
 
          (if (acl2::bitset-memberp bit (cdar db))
2117
 
              (mv (cons (car db) yes) no)
2118
 
            (mv yes (cons (car db) no)))))
2119
 
      (us-filter-db-by-bit1 bit (cdr db) yes no)))
2120
 
 
2121
 
  (defund us-filter-db-by-bit (bit db)
2122
 
    "Returns (MV YES NO), slow alists."
2123
 
    (declare (xargs :guard (and (natp bit)
2124
 
                                (us-db-p db))))
2125
 
    (us-filter-db-by-bit1 bit db nil nil))
2126
 
 
2127
 
  (defthm us-filter-db-by-bit1-basics
2128
 
    (implies (and (force (natp bit))
2129
 
                  (force (us-db-p db))
2130
 
                  (force (us-db-p yes))
2131
 
                  (force (us-db-p no)))
2132
 
             (let ((ret (us-filter-db-by-bit1 bit db yes no)))
2133
 
               (and (us-db-p (mv-nth 0 ret))
2134
 
                    (us-db-p (mv-nth 1 ret)))))
2135
 
    :hints(("Goal" :in-theory (enable us-filter-db-by-bit1))))
2136
 
 
2137
 
  (defthm us-filter-db-by-bit-basics
2138
 
    (implies (and (force (natp bit))
2139
 
                  (force (us-db-p db)))
2140
 
             (let ((ret (us-filter-db-by-bit bit db)))
2141
 
               (and (us-db-p (mv-nth 0 ret))
2142
 
                    (us-db-p (mv-nth 1 ret)))))
2143
 
    :hints(("Goal" :in-theory (enable us-filter-db-by-bit)))))
2144
 
 
2145
 
 
2146
 
(defsection us-filter-db-by-mask
 
1977
  ((bit natp)
 
1978
   (db us-db-p)
 
1979
   (yes us-db-p)
 
1980
   (no us-db-p))
 
1981
  :returns (mv (yes us-db-p) ;; slow alists
 
1982
               (no us-db-p))
 
1983
  :measure (len (us-db-fix db))
 
1984
  (b* ((db (us-db-fix db))
 
1985
       (yes (us-db-fix yes))
 
1986
       (no (us-db-fix no))
 
1987
       (bit (lnfix bit))
 
1988
       ((when (atom db))
 
1989
        (mv yes no))
 
1990
       ((mv yes no)
 
1991
        (if (acl2::bitset-memberp bit (cdar db))
 
1992
            (mv (cons (car db) yes) no)
 
1993
          (mv yes (cons (car db) no)))))
 
1994
    (us-filter-db-by-bit1 bit (cdr db) yes no)))
 
1995
 
 
1996
(define us-filter-db-by-bit ((bit natp) (db us-db-p))
 
1997
  :returns (mv (yes us-db-p) ;; slow alists
 
1998
               (no us-db-p))
 
1999
  (us-filter-db-by-bit1 bit db nil nil))
 
2000
 
 
2001
(define us-filter-db-by-mask1
2147
2002
 
2148
2003
  ;; Get entries that have exactly some mask
2149
2004
 
2150
2005
; ASSUMES THE DATABSE HAS ALREADY BEEN SHRUNK
2151
2006
 
2152
 
  (defund us-filter-db-by-mask1 (mask db yes no)
2153
 
    "Returns (MV YES NO), slow alists."
2154
 
    (declare (xargs :guard (and (natp mask)
2155
 
                                (us-db-p db))))
2156
 
    (b* (((when (atom db))
2157
 
          (mv yes no))
2158
 
         ((mv yes no)
2159
 
          (if (equal mask (cdar db))
2160
 
              (mv (cons (car db) yes) no)
2161
 
            (mv yes (cons (car db) no)))))
2162
 
      (us-filter-db-by-mask1 mask (cdr db) yes no)))
2163
 
 
2164
 
  (defund us-filter-db-by-mask (mask db)
2165
 
    "Returns (MV YES NO), slow alists."
2166
 
    (declare (xargs :guard (and (natp mask)
2167
 
                                (us-db-p db))))
2168
 
    (us-filter-db-by-mask1 mask db nil nil))
2169
 
 
2170
 
  (defthm us-filter-db-by-mask1-basics
2171
 
    (implies (and (force (natp mask))
2172
 
                  (force (us-db-p db))
2173
 
                  (force (us-db-p yes))
2174
 
                  (force (us-db-p no)))
2175
 
             (let ((ret (us-filter-db-by-mask1 mask db yes no)))
2176
 
               (and (us-db-p (mv-nth 0 ret))
2177
 
                    (us-db-p (mv-nth 1 ret)))))
2178
 
    :hints(("Goal" :in-theory (enable us-filter-db-by-mask1))))
2179
 
 
2180
 
  (defthm us-filter-db-by-mask-basics
2181
 
    (implies (and (force (natp mask))
2182
 
                  (force (us-db-p db)))
2183
 
             (let ((ret (us-filter-db-by-mask mask db)))
2184
 
               (and (us-db-p (mv-nth 0 ret))
2185
 
                    (us-db-p (mv-nth 1 ret)))))
2186
 
    :hints(("Goal" :in-theory (enable us-filter-db-by-mask)))))
2187
 
 
2188
 
 
2189
 
(defsection us-warn-nonport-results
2190
 
 
2191
 
  (defund us-warn-nonport-results (modname x)
2192
 
    (declare (xargs :guard (and (stringp modname)
2193
 
                                (us-results-p x))))
2194
 
    (b* (((when (atom x))
2195
 
          nil)
2196
 
         (mask  (caar x))
2197
 
         (wires (cdar x))
2198
 
         ((when (atom wires))
2199
 
          (us-warn-nonport-results modname (cdr x)))
2200
 
 
2201
 
         (- (or (not (or (acl2::bitset-memberp *us-truly-used-abovep* mask)
2202
 
                         (acl2::bitset-memberp *us-truly-set-abovep* mask)))
2203
 
                (cw "Errr... non-ports marked used/set above??? something is wrong.~%")))
2204
 
 
2205
 
         ;; used/set?
2206
 
         (usedp (acl2::bitset-memberp *us-truly-usedp* mask))
2207
 
         (setp  (acl2::bitset-memberp *us-truly-setp* mask))
2208
 
         ((when (and usedp setp))
2209
 
          ;; It's fine, no reason to warn about it.  We've already warned
2210
 
          ;; about trainwrecks earlier.
2211
 
          (us-warn-nonport-results modname (cdr x)))
2212
 
 
2213
 
         ;; falsely used/set but not truly used/set?
2214
 
         (fusedp (and (not usedp) (acl2::bitset-memberp *us-falsely-usedp* mask)))
2215
 
         (fsetp  (and (not setp)  (acl2::bitset-memberp *us-falsely-setp* mask)))
2216
 
 
2217
 
         (pluralp     (vl-plural-p wires))
2218
 
         (|wire(s)|   (if pluralp "wires" "wire"))
2219
 
         (|are|       (if pluralp "are" "is"))
2220
 
 
2221
 
         (summary-line
2222
 
          ;; New summary line for Terry
2223
 
          (cat (natstr (len wires))
2224
 
               (cond (usedp " unset bit")
2225
 
                     (setp  " unused bit")
2226
 
                     (t     " spurious bit"))
2227
 
               (if pluralp "s.  " ".  ")))
2228
 
 
2229
 
         (warning
2230
 
          (make-vl-warning
2231
 
           :type (cond (usedp (if fsetp
2232
 
                                  :use-set-warn-1-unset-tricky
2233
 
                                :use-set-warn-1-unset))
2234
 
                       (setp  (if fusedp
2235
 
                                  :use-set-warn-2-unused-tricky
2236
 
                                :use-set-warn-2-unused))
2237
 
                       (t     (if (or fusedp fsetp)
2238
 
                                  :use-set-warn-3-spurious-tricky
2239
 
                                :use-set-warn-3-spurious)))
2240
 
           :msg (cat summary-line
2241
 
                     (cond (usedp "These ~s0 ~s1 never set: ~&2.")
2242
 
                           (setp  "These ~s0 ~s1 never used: ~&2.")
2243
 
                           (t     "These ~s0 ~s1 never used or set: ~&2.")))
2244
 
           :args (list |wire(s)|
2245
 
                       |are|
2246
 
                       (cwtime (vl-verilogify-emodwirelist wires)
2247
 
                               :mintime 1/2))
2248
 
           :fatalp nil
2249
 
           :fn 'us-warn-nonport-results)))
2250
 
 
2251
 
      (cons warning
2252
 
            (us-warn-nonport-results modname (cdr x)))))
2253
 
 
2254
 
  (defthm vl-warninglist-p-of-us-warn-nonport-results
2255
 
    (vl-warninglist-p (us-warn-nonport-results modname x))
2256
 
    :hints(("Goal" :in-theory (enable us-warn-nonport-results)))))
2257
 
 
2258
 
(define vl-netdecls-for-flattened-hids ((x vl-netdecllist-p))
2259
 
  :returns (flattened-decls vl-netdecllist-p :hyp :fguard)
 
2007
  ((mask natp) (db us-db-p) (yes us-db-p) (no us-db-p))
 
2008
  :returns (mv (yes us-db-p) ;; slow alists
 
2009
               (no us-db-p))
 
2010
  :measure (len (us-db-fix db))
 
2011
  (b* ((db (us-db-fix db))
 
2012
       (yes (us-db-fix yes))
 
2013
       (no (us-db-fix no))
 
2014
       (mask (lnfix mask))
 
2015
       ((when (atom db))
 
2016
        (mv yes no))
 
2017
       ((mv yes no)
 
2018
        (if (equal mask (cdar db))
 
2019
            (mv (cons (car db) yes) no)
 
2020
          (mv yes (cons (car db) no)))))
 
2021
    (us-filter-db-by-mask1 mask (cdr db) yes no)))
 
2022
 
 
2023
(define us-filter-db-by-mask ((mask natp)
 
2024
                              (db us-db-p))
 
2025
  :returns (mv (yes us-db-p) ;; slow alists
 
2026
               (no us-db-p))
 
2027
  (declare (xargs :guard (and (natp mask)
 
2028
                              (us-db-p db))))
 
2029
  (us-filter-db-by-mask1 mask db nil nil))
 
2030
 
 
2031
 
 
2032
 
 
2033
(define us-warn-nonport-results ((modname stringp)
 
2034
                                 (x us-results-p))
 
2035
  :returns (warnings vl-warninglist-p)
 
2036
  :measure (len (us-results-fix x))
 
2037
  (b* ((modname (string-fix modname))
 
2038
       (x (us-results-fix x))
 
2039
       ((when (atom x))
 
2040
        nil)
 
2041
       (mask  (caar x))
 
2042
       (wires (cdar x))
 
2043
       ((when (atom wires))
 
2044
        (us-warn-nonport-results modname (cdr x)))
 
2045
 
 
2046
       (- (or (not (or (acl2::bitset-memberp *us-truly-used-abovep* mask)
 
2047
                       (acl2::bitset-memberp *us-truly-set-abovep* mask)))
 
2048
              (cw "Errr... non-ports marked used/set above??? something is wrong.~%")))
 
2049
 
 
2050
       ;; used/set?
 
2051
       (usedp (acl2::bitset-memberp *us-truly-usedp* mask))
 
2052
       (setp  (acl2::bitset-memberp *us-truly-setp* mask))
 
2053
       ((when (and usedp setp))
 
2054
        ;; It's fine, no reason to warn about it.  We've already warned
 
2055
        ;; about trainwrecks earlier.
 
2056
        (us-warn-nonport-results modname (cdr x)))
 
2057
 
 
2058
       ;; falsely used/set but not truly used/set?
 
2059
       (fusedp (and (not usedp) (acl2::bitset-memberp *us-falsely-usedp* mask)))
 
2060
       (fsetp  (and (not setp)  (acl2::bitset-memberp *us-falsely-setp* mask)))
 
2061
 
 
2062
       (pluralp     (vl-plural-p wires))
 
2063
       (|wire(s)|   (if pluralp "wires" "wire"))
 
2064
       (|are|       (if pluralp "are" "is"))
 
2065
 
 
2066
       (summary-line
 
2067
        ;; New summary line for Terry
 
2068
        (cat (natstr (len wires))
 
2069
             (cond (usedp " unset bit")
 
2070
                   (setp  " unused bit")
 
2071
                   (t     " spurious bit"))
 
2072
             (if pluralp "s.  " ".  ")))
 
2073
 
 
2074
       (warning
 
2075
        (make-vl-warning
 
2076
         :type (cond (usedp (if fsetp
 
2077
                                :use-set-warn-1-unset-tricky
 
2078
                              :use-set-warn-1-unset))
 
2079
                     (setp  (if fusedp
 
2080
                                :use-set-warn-2-unused-tricky
 
2081
                              :use-set-warn-2-unused))
 
2082
                     (t     (if (or fusedp fsetp)
 
2083
                                :use-set-warn-3-spurious-tricky
 
2084
                              :use-set-warn-3-spurious)))
 
2085
         :msg (cat summary-line
 
2086
                   (cond (usedp "These ~s0 ~s1 never set: ~&2.")
 
2087
                         (setp  "These ~s0 ~s1 never used: ~&2.")
 
2088
                         (t     "These ~s0 ~s1 never used or set: ~&2.")))
 
2089
         :args (list |wire(s)|
 
2090
                     |are|
 
2091
                     (cwtime (vl-verilogify-emodwirelist wires)
 
2092
                             :mintime 1/2))
 
2093
         :fatalp nil
 
2094
         :fn 'us-warn-nonport-results)))
 
2095
 
 
2096
    (cons warning
 
2097
          (us-warn-nonport-results modname (cdr x)))))
 
2098
 
 
2099
 
 
2100
(define vl-vardecls-for-flattened-hids ((x vl-vardecllist-p))
 
2101
  :returns (flattened-decls vl-vardecllist-p)
2260
2102
  (cond ((atom x)
2261
2103
         nil)
2262
 
        ((assoc-equal "VL_HID_RESOLVED_MODULE_NAME" (vl-netdecl->atts (car x)))
2263
 
         (cons (car x) (vl-netdecls-for-flattened-hids (cdr x))))
 
2104
        ((assoc-equal "VL_HID_RESOLVED_MODULE_NAME" (vl-vardecl->atts (car x)))
 
2105
         (cons (vl-vardecl-fix (car x)) (vl-vardecls-for-flattened-hids (cdr x))))
2264
2106
        (t
2265
 
         (vl-netdecls-for-flattened-hids (cdr x)))))
 
2107
         (vl-vardecls-for-flattened-hids (cdr x)))))
2266
2108
 
2267
 
(define vl-netdecllist-wires
2268
 
  ((x        vl-netdecllist-p)
 
2109
(define vl-vardecllist-wires
 
2110
  ((x        vl-vardecllist-p)
2269
2111
   (walist   vl-wirealist-p)
2270
2112
   (warnings vl-warninglist-p))
2271
2113
  :returns (mv (successp booleanp :rule-classes :type-prescription)
2272
2114
               (warnings vl-warninglist-p)
2273
 
               (wires    vl-emodwirelist-p :hyp :fguard))
 
2115
               (wires    vl-emodwirelist-p))
2274
2116
  (b* (((when (atom x))
2275
2117
        (mv t (ok) nil))
2276
 
       (car-look     (hons-get (vl-netdecl->name (car x)) walist))
 
2118
       (walist (vl-wirealist-fix walist))
 
2119
       ((vl-vardecl x1) (vl-vardecl-fix (car x)))
 
2120
       (car-look     (hons-get x1.name walist))
2277
2121
       (car-wires    (cdr car-look))
2278
2122
       (warnings     (if car-look
2279
2123
                         (ok)
2280
2124
                       (warn :type :use-set-fudging
2281
 
                             :msg "~a0: No wires for this net?"
2282
 
                             :args (list (car x)))))
 
2125
                             :msg "~a0: No wires for this variable?"
 
2126
                             :args (list x1))))
2283
2127
       ((mv cdr-successp warnings cdr-wires)
2284
 
        (vl-netdecllist-wires (cdr x) walist warnings)))
 
2128
        (vl-vardecllist-wires (cdr x) walist warnings)))
2285
2129
    (mv (and car-look cdr-successp)
2286
2130
        warnings
2287
2131
        (append car-wires cdr-wires))))
2288
2132
 
2289
2133
(define us-report-mod ((x       vl-module-p)
 
2134
                       (ss      vl-scopestack-p)
2290
2135
                       (dbalist us-dbalist-p)
2291
2136
                       (walist  vl-wirealist-p))
2292
 
  :returns (new-x vl-module-p :hyp :fguard)
2293
 
  (b* (((vl-module x) x)
 
2137
  :returns (new-x vl-module-p)
 
2138
  (b* (((vl-module x) (vl-module-fix x))
2294
2139
       (warnings x.warnings)
2295
 
 
 
2140
       (dbalist (us-dbalist-fix dbalist))
 
2141
       (walist (vl-wirealist-fix walist))
2296
2142
       (entry (hons-get x.name dbalist))
 
2143
       (ss   (vl-scopestack-push x ss))
2297
2144
       (db    (cdr entry))
2298
2145
       ((unless entry)
2299
2146
        (b* ((warnings (warn :type :use-set-fudging
2308
2155
 
2309
2156
       (ialist (vl-moditem-alist x))
2310
2157
       ((mv warnings ignore-bits)
2311
 
        (us-analyze-commentmap x.comments x ialist walist warnings))
 
2158
        (us-analyze-commentmap x.comments ss walist warnings))
2312
2159
       (- (fast-alist-free ialist))
2313
2160
 
2314
2161
       ((mv ?ignore-db1 db)
2324
2171
         db))
2325
2172
 
2326
2173
       ;; ignore hids since they'll look undriven
2327
 
       (hids (vl-netdecls-for-flattened-hids x.netdecls))
 
2174
       (hids (vl-vardecls-for-flattened-hids x.vardecls))
2328
2175
       ((mv ?hidnames-okp warnings hidwires)
2329
 
        (vl-netdecllist-wires hids walist warnings))
 
2176
        (vl-vardecllist-wires hids walist warnings))
2330
2177
       ((mv ?ignore-db2 db)
2331
2178
        (us-filter-db-by-names hidwires db))
2332
2179
 
2356
2203
(define us-report-mods
2357
2204
  ((x           vl-modulelist-p)
2358
2205
   (mods        vl-modulelist-p)
 
2206
   (ss          vl-scopestack-p)
2359
2207
   (dbalist     us-dbalist-p)
2360
2208
   (all-walists (equal all-walists (vl-nowarn-all-wirealists mods))))
2361
 
  :returns (new-x vl-modulelist-p :hyp :fguard)
 
2209
  :returns (new-x vl-modulelist-p)
2362
2210
  (if (atom x)
2363
2211
      nil
2364
2212
    (cons (us-report-mod (car x)
2365
 
                         dbalist
 
2213
                         ss dbalist
2366
2214
                         (cdr (hons-get (vl-module->name (car x)) all-walists)))
2367
 
          (us-report-mods (cdr x) mods dbalist all-walists))))
2368
 
 
2369
 
(defsection us-analyze-mod
2370
 
 
2371
 
  (defund us-analyze-mod
2372
 
    (x           ; module to analyze
2373
 
     mods        ; list of all modules
2374
 
     modalist    ; modalist for all modules
2375
 
     dbalist     ; use-set databases for previously analyzed modules
2376
 
     all-walists ; precomputed walists for all mods
2377
 
     reportcard     ; reportcard we're building
2378
 
     toplevel    ; list of top level modules
2379
 
     notealist
2380
 
     )
2381
 
    "Returns (MV X' DBALIST' REPORTCARD' NOTEALIST')"
2382
 
    (declare (xargs :guard (and (vl-module-p x)
2383
 
                                (vl-modulelist-p mods)
2384
 
                                (equal modalist (vl-modalist mods))
2385
 
                                (us-dbalist-p dbalist)
2386
 
                                (equal all-walists (vl-nowarn-all-wirealists mods))
2387
 
                                (vl-reportcard-p reportcard)
2388
 
                                (string-listp toplevel)
2389
 
                                (us-notealist-p notealist))))
2390
 
    (b* (((vl-module x) x)
2391
 
 
 
2215
          (us-report-mods (cdr x) mods ss dbalist all-walists))))
 
2216
 
 
2217
(define us-analyze-mod
 
2218
  ((x vl-module-p)           ; module to analyze
 
2219
   (mods vl-modulelist-p)        ; list of all modules
 
2220
   (ss   vl-scopestack-p)
 
2221
   (dbalist us-dbalist-p)     ; use-set databases for previously analyzed modules
 
2222
   ; precomputed walists for all mods
 
2223
   (all-walists (equal all-walists (vl-nowarn-all-wirealists mods)))
 
2224
   (reportcard vl-reportcard-p)     ; reportcard we're building
 
2225
   (toplevel string-listp)    ; list of top level modules
 
2226
   (notealist us-notealist-p))
 
2227
  :returns (mv (new-x vl-module-p)
 
2228
               (dbalist us-dbalist-p)
 
2229
               (reportcard vl-reportcard-p)
 
2230
               (notealist us-notealist-p))
 
2231
  :verbosep t
 
2232
    (b* (((vl-module x) (vl-module-fix x))
 
2233
         (toplevel (string-list-fix toplevel))
 
2234
         (dbalist (us-dbalist-fix dbalist))
 
2235
         (reportcard (vl-reportcard-fix reportcard))
 
2236
         (notealist (us-notealist-fix notealist))
2392
2237
         (walist-look (hons-get x.name all-walists))
2393
2238
         (walist      (cdr walist-look))
2394
2239
         ((unless walist-look)
2410
2255
              (us-mark-toplevel-port-bits x.portdecls walist db warnings)
2411
2256
            (mv warnings db)))
2412
2257
 
2413
 
         ((mv warnings db) (cwtime (us-mark-wires-for-netdecllist x.netdecls walist db warnings)
 
2258
         ((mv warnings db) (cwtime (us-mark-wires-for-vardecllist x.vardecls walist db warnings)
2414
2259
                                   :mintime 1/2))
2415
2260
         ((mv warnings db) (cwtime (us-mark-wires-for-assignlist x.assigns walist db warnings)
2416
2261
                                   :mintime 1/2))
2422
2267
                                   :mintime 1/2))
2423
2268
 
2424
2269
         ((mv warnings db notes)
2425
 
          (cwtime (us-mark-wires-for-modinstlist x.modinsts walist db mods modalist dbalist all-walists warnings nil)
 
2270
          (cwtime (us-mark-wires-for-modinstlist x.modinsts walist db mods ss dbalist all-walists warnings nil)
2426
2271
                  :mintime 1/2))
2427
2272
 
2428
2273
         ;; bozo ugly db/walist order
2442
2287
 
2443
2288
      (mv x-prime dbalist reportcard notealist)))
2444
2289
 
2445
 
  (defthm us-analyze-mod-basics
2446
 
    (implies (and (force (vl-module-p x))
2447
 
                  (force (vl-modulelist-p mods))
2448
 
                  (force (equal modalist (vl-modalist mods)))
2449
 
                  (force (us-dbalist-p dbalist))
2450
 
                  (force (equal all-walists (vl-nowarn-all-wirealists mods)))
2451
 
                  (force (vl-reportcard-p reportcard))
2452
 
                  (force (string-listp toplevel))
2453
 
                  (force (us-notealist-p notealist)))
2454
 
             (let ((ret (us-analyze-mod x mods modalist dbalist all-walists reportcard toplevel notealist)))
2455
 
               (and (vl-module-p (mv-nth 0 ret))
2456
 
                    (us-dbalist-p (mv-nth 1 ret))
2457
 
                    (vl-reportcard-p (mv-nth 2 ret))
2458
 
                    (us-notealist-p (mv-nth 3 ret)))))
2459
 
    :hints(("Goal" :in-theory (enable us-analyze-mod)))))
2460
 
 
2461
 
 
2462
 
 
2463
 
(defsection us-analyze-mods
2464
 
 
2465
 
  (defund us-analyze-mods-aux (x mods modalist dbalist all-walists reportcard toplevel notealist)
2466
 
    "Returns (MV X' DBALIST' REPORTCARD')"
2467
 
    (declare (xargs :guard (and (vl-modulelist-p x)
2468
 
                                (vl-modulelist-p mods)
2469
 
                                (equal modalist (vl-modalist mods))
2470
 
                                (us-dbalist-p dbalist)
2471
 
                                (equal all-walists (vl-nowarn-all-wirealists mods))
2472
 
                                (vl-reportcard-p reportcard)
2473
 
                                (string-listp toplevel)
2474
 
                                (us-notealist-p notealist))))
2475
 
    (b* (((when (atom x))
2476
 
          (mv nil dbalist reportcard notealist))
2477
 
         ((mv car-prime dbalist reportcard notealist)
2478
 
          (us-analyze-mod (car x) mods modalist dbalist
2479
 
                          all-walists reportcard toplevel notealist))
2480
 
         ((mv cdr-prime dbalist reportcard notealist)
2481
 
          (us-analyze-mods-aux (cdr x) mods modalist dbalist
2482
 
                               all-walists reportcard toplevel notealist))
2483
 
         (x-prime (cons car-prime cdr-prime)))
2484
 
      (mv x-prime dbalist reportcard notealist)))
2485
 
 
2486
 
  (defthm us-analyze-mods-aux-basics
2487
 
    (implies (and (force (vl-modulelist-p x))
2488
 
                  (force (vl-modulelist-p mods))
2489
 
                  (force (equal modalist (vl-modalist mods)))
2490
 
                  (force (us-dbalist-p dbalist))
2491
 
                  (force (equal all-walists (vl-nowarn-all-wirealists mods)))
2492
 
                  (force (vl-reportcard-p reportcard))
2493
 
                  (force (string-listp toplevel))
2494
 
                  (force (us-notealist-p notealist)))
2495
 
             (let ((ret (us-analyze-mods-aux x mods modalist dbalist all-walists reportcard toplevel notealist)))
2496
 
               (and (vl-modulelist-p (mv-nth 0 ret))
2497
 
                    (us-dbalist-p (mv-nth 1 ret))
2498
 
                    (vl-reportcard-p (mv-nth 2 ret))
2499
 
                    (us-notealist-p (mv-nth 3 ret)))))
2500
 
    :hints(("Goal" :in-theory (enable us-analyze-mods-aux))))
2501
 
 
2502
 
  (defund us-analyze-mods (x)
2503
 
    "Returns (MV X-PRIME DBALIST)"
2504
 
    (declare (xargs :guard (vl-modulelist-p x)
2505
 
                    :guard-debug t))
2506
 
    ;; bozo check port bits
2507
 
    (b* ((x        (cwtime (vl-deporder-sort x) :mintime 1/2))
2508
 
         (modalist (cwtime (vl-modalist x) :mintime 1/2))
2509
 
         (toplevel (cwtime (vl-modulelist-toplevel x) :mintime 1/2))
2510
 
         ((mv warnings-alist all-walists)
2511
 
          (cwtime (vl-modulelist-all-wirealists x)
2512
 
                  :mintime 1/2))
2513
 
 
2514
 
         ((mv x-prime dbalist warnings-alist notealist)
2515
 
          ;; pass 1: analyze the modules in dependency order, bottom-up,
2516
 
          ;; generating their initial dbalists and notes.
2517
 
          (cwtime (us-analyze-mods-aux x x modalist (len x)
2518
 
                                       all-walists warnings-alist
2519
 
                                       toplevel (len x))
2520
 
                  :mintime 1/2))
2521
 
         (- (fast-alist-free modalist))
2522
 
 
2523
 
         ((mv warnings-alist dbalist)
2524
 
          ;; pass2: apply the notes in reverse dependency order, top-down,
2525
 
          ;; marking which ports are used/set anywhere above
2526
 
          (cwtime (us-apply-notesalist (rev x-prime) notealist dbalist
2527
 
                                       warnings-alist)
2528
 
                  :mintime 1/2))
2529
 
         (- (fast-alist-free notealist))
2530
 
 
2531
 
         (x-prime
2532
 
          (cwtime (vl-modulelist-apply-reportcard x-prime warnings-alist)
2533
 
                  :mintime 1/2))
2534
 
         (- (fast-alist-free warnings-alist))
2535
 
 
2536
 
         (x-prime
2537
 
          (cwtime (us-report-mods x-prime x dbalist all-walists)
2538
 
                  :mintime 1/2))
2539
 
 
2540
 
         (- (fast-alist-free-each-alist-val all-walists))
2541
 
         (- (fast-alist-free all-walists)))
2542
 
 
2543
 
      ;; bozo probably free other stuff -- walists, etc.
2544
 
      (mv x-prime dbalist)))
2545
 
 
2546
 
  (defthm us-analyze-mods-basics
2547
 
    (implies (force (vl-modulelist-p x))
2548
 
             (let ((ret (us-analyze-mods x)))
2549
 
               (and (vl-modulelist-p (mv-nth 0 ret))
2550
 
                    (us-dbalist-p (mv-nth 1 ret)))))
2551
 
    :hints(("Goal" :in-theory (enable us-analyze-mods)))))
 
2290
 
 
2291
(define us-analyze-mods-aux ((x vl-modulelist-p)
 
2292
                             (mods vl-modulelist-p)
 
2293
                             (ss vl-scopestack-p)
 
2294
                             (dbalist us-dbalist-p)
 
2295
                             (all-walists (equal all-walists (vl-nowarn-all-wirealists mods)))
 
2296
                             (reportcard vl-reportcard-p)
 
2297
                             (toplevel string-listp)
 
2298
                             (notealist us-notealist-p))
 
2299
  "Returns (MV X' DBALIST' REPORTCARD')"
 
2300
  :returns (mv (x-prime vl-modulelist-p)
 
2301
               (dbalist us-dbalist-p)
 
2302
               (rcard   vl-reportcard-p)
 
2303
               (nalist  us-notealist-p))
 
2304
  (b* (((when (atom x))
 
2305
        (mv nil
 
2306
            (us-dbalist-fix dbalist)
 
2307
            (vl-reportcard-fix reportcard)
 
2308
            (us-notealist-fix notealist)))
 
2309
       ((mv car-prime dbalist reportcard notealist)
 
2310
        (us-analyze-mod (car x) mods ss dbalist
 
2311
                        all-walists reportcard toplevel notealist))
 
2312
       ((mv cdr-prime dbalist reportcard notealist)
 
2313
        (us-analyze-mods-aux (cdr x) mods ss dbalist
 
2314
                             all-walists reportcard toplevel notealist))
 
2315
       (x-prime (cons car-prime cdr-prime)))
 
2316
    (mv x-prime dbalist reportcard notealist)))
 
2317
 
 
2318
(define us-analyze-mods ((x vl-modulelist-p) (ss vl-scopestack-p))
 
2319
  "Returns (MV X-PRIME DBALIST)"
 
2320
  :returns (mv (x-prime vl-modulelist-p)
 
2321
               (dbalist us-dbalist-p))
 
2322
  ;; bozo check port bits
 
2323
  (b* ((toplevel (cwtime (vl-modulelist-toplevel x) :mintime 1/2))
 
2324
       ((mv warnings-alist all-walists)
 
2325
        (cwtime (vl-modulelist-all-wirealists x)
 
2326
                :mintime 1/2))
 
2327
 
 
2328
       ((mv x-prime dbalist warnings-alist notealist)
 
2329
        ;; pass 1: analyze the modules in dependency order, bottom-up,
 
2330
        ;; generating their initial dbalists and notes.
 
2331
        (cwtime (us-analyze-mods-aux x x ss (len x)
 
2332
                                     all-walists warnings-alist
 
2333
                                     toplevel (len x))
 
2334
                :mintime 1/2))
 
2335
 
 
2336
       ((mv warnings-alist dbalist)
 
2337
        ;; pass2: apply the notes in reverse dependency order, top-down,
 
2338
        ;; marking which ports are used/set anywhere above
 
2339
        (cwtime (us-apply-notesalist (rev x-prime) notealist dbalist
 
2340
                                     warnings-alist)
 
2341
                :mintime 1/2))
 
2342
       (- (fast-alist-free notealist))
 
2343
 
 
2344
       (x-prime
 
2345
        (cwtime (vl-modulelist-apply-reportcard x-prime warnings-alist)
 
2346
                :mintime 1/2))
 
2347
       (- (fast-alist-free warnings-alist))
 
2348
 
 
2349
       (x-prime
 
2350
        (cwtime (us-report-mods x-prime x ss dbalist all-walists)
 
2351
                :mintime 1/2))
 
2352
 
 
2353
       (- (fast-alist-free-each-alist-val all-walists))
 
2354
       (- (fast-alist-free all-walists)))
 
2355
 
 
2356
    ;; bozo probably free other stuff -- walists, etc.
 
2357
    (mv x-prime dbalist)))
2552
2358
 
2553
2359
(define vl-design-bit-use-set ((x vl-design-p))
2554
2360
  :returns (mv (new-x   vl-design-p)
2555
2361
               (dbalist us-dbalist-p))
2556
 
  (b* ((x (vl-design-fix x))
 
2362
  (b* (((mv okp x) (vl-design-deporder-modules x))
 
2363
       ((unless okp)
 
2364
        (raise "Somehow failed to deporder sort modules.")
 
2365
        (mv x nil))
 
2366
       (ss (vl-scopestack-init x))
2557
2367
       ((vl-design x) x)
2558
 
       ((mv new-mods dbalist) (us-analyze-mods x.mods))
 
2368
       ((mv new-mods dbalist) (us-analyze-mods x.mods ss))
2559
2369
       (new-x (change-vl-design x :mods new-mods)))
 
2370
    (vl-scopestacks-free)
2560
2371
    (mv new-x dbalist)))
2561
2372
 
2562
2373