File: packages.lisp

package info (click to toggle)
acl2 8.5dfsg-5
  • links: PTS
  • area: main
  • in suites: bookworm
  • size: 991,452 kB
  • sloc: lisp: 15,567,759; javascript: 22,820; cpp: 13,929; ansic: 12,092; perl: 7,150; java: 4,405; xml: 3,884; makefile: 3,507; sh: 3,187; ruby: 2,633; ml: 763; python: 746; yacc: 723; awk: 295; csh: 186; php: 171; lex: 154; tcl: 49; asm: 23; haskell: 17
file content (226 lines) | stat: -rw-r--r-- 10,739 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
; VL 2014 -- VL Verilog Toolkit, 2014 Edition
; Copyright (C) 2008-2015 Centaur Technology
;
; Contact:
;   Centaur Technology Formal Verification Group
;   7600-C N. Capital of Texas Highway, Suite 300, Austin, TX 78731, USA.
;   http://www.centtech.com/
;
; License: (An MIT/X11-style license)
;
;   Permission is hereby granted, free of charge, to any person obtaining a
;   copy of this software and associated documentation files (the "Software"),
;   to deal in the Software without restriction, including without limitation
;   the rights to use, copy, modify, merge, publish, distribute, sublicense,
;   and/or sell copies of the Software, and to permit persons to whom the
;   Software is furnished to do so, subject to the following conditions:
;
;   The above copyright notice and this permission notice shall be included in
;   all copies or substantial portions of the Software.
;
;   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
;   IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
;   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
;   AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
;   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
;   FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
;   DEALINGS IN THE SOFTWARE.
;
; Original author: Jared Davis <jared@centtech.com>

(in-package "VL2014")
(include-book "elements")
(local (include-book "../../util/arithmetic"))

(defxdoc parse-packages
  :parents (parser)
  :short "Functions for parsing SystemVerilog packages.")

(local (xdoc::set-default-parents parse-packages))

;; package_item ::=
;; package_or_generate_item_declaration
;; | anonymous_program
;; | package_export_declaration
;; | timeunits_declaration

;; package_or_generate_item_declaration ::=
;; net_declaration
;; | data_declaration
;; | task_declaration
;; | function_declaration
;; | checker_declaration
;; | dpi_import_export
;; | extern_constraint_declaration
;; | class_declaration
;; | class_constructor_declaration
;; | local_parameter_declaration ;
;; | parameter_declaration ;
;; | covergroup_declaration
;; | overload_declaration
;; | assertion_item_declaration
;; | ;

;; anonymous_program ::= program ; { anonymous_program_item } endprogram

;; anonymous_program_item ::=
;; task_declaration
;; | function_declaration
;; | class_declaration
;; | covergroup_declaration
;; | class_constructor_declaration
;; | ;

;; anonymous_program_item ::=
;; task_declaration
;; | function_declaration
;; | class_declaration
;; | covergroup_declaration
;; | class_constructor_declaration
;; | ;

(defparser vl-skip-through-endpackage (pkgname)
  :short "Special error recovery for parse errors encountered during packages."
  :guard (stringp pkgname)
  :result (vl-token-p val)
  :resultp-of-nil nil
  :fails gracefully
  :count strong
  (seq tokstream
        (unless (vl-is-token? :vl-kwd-endpackage)
          (:s= (vl-match-any))
          (endkwd := (vl-skip-through-endpackage pkgname))
          (return endkwd))
        (endkwd := (vl-match))
        (:= (vl-parse-endblock-name pkgname "package/endpackage"))
        (return endkwd)))

(define vl-make-package-with-parse-error ((name   stringp)
                                          (minloc vl-location-p)
                                          (maxloc vl-location-p)
                                          (err    vl-warning-p)
                                          (tokens vl-tokenlist-p))
  :returns (package vl-package-p)
  (b* (;; We also generate a second error message.
       ;;  - This lets us always show the remaining part of the token stream
       ;;    in each case.
       ;;  - It ensures that any module with a parse error always, absolutely,
       ;;    certainly has a fatal warning, even if somehow the real warning
       ;;    isn't marked as fatal.
       (warn2 (make-vl-warning :type :vl-parse-error
                               :msg "[[ Remaining ]]: ~s0 ~s1.~%"
                               :args (list (vl-tokenlist->string-with-spaces
                                            (take (min 4 (len tokens))
                                                  (list-fix tokens)))
                                           (if (> (len tokens) 4) "..." ""))
                               :fatalp t
                               :fn __function__)))
    (make-vl-package :name name
                     :minloc minloc
                     :maxloc maxloc
                     :warnings (list err warn2))))

(defparser vl-parse-package-declaration (atts)
  ;; package_declaration ::= { attribute_instance } package [ lifetime ] package_identifier ;
  ;;                           [ timeunits_declaration ]
  ;;                           { { attribute_instance } package_item }
  ;;                         endpackage [ : package_identifier ]
  :guard (vl-atts-p atts)
  :result (vl-package-p val)
  :resultp-of-nil nil
  :fails gracefully
  :count strong
  (seq tokstream
        (startkwd := (vl-match-token :vl-kwd-package))
        (lifetime := (vl-maybe-parse-lifetime))
        (name     := (vl-match-token :vl-idtoken))
        (return-raw
         (b* ((backup (vl-tokstream-save))

              ;; Temporarily clear out the warnings so that we can associate any
              ;; warnings encountered while parsing the package with the package
              ;; itself.
              (orig-warnings (vl-parsestate->warnings (vl-tokstream->pstate)))
              (tokstream     (vl-tokstream-update-pstate
                              (change-vl-parsestate (vl-tokstream->pstate) :warnings nil)))

              ;; Now try to parse the rest of the package declaration.
              ((mv err pkg tokstream)
               (seq tokstream
                    (:= (vl-match-token :vl-semi))
                    ;; BOZO parse timeunits declaration stuff.
                    (items  := (vl-parse-genelements-until :vl-kwd-endpackage))
                    (endkwd := (vl-match-token :vl-kwd-endpackage))
                    (:= (vl-parse-endblock-name (vl-idtoken->name name) "package/endpackage"))
                    (return
                     (b* ((warnings (vl-parsestate->warnings (vl-tokstream->pstate)))
                          (bad-item (vl-genelementlist-findbad items
                                                               '(;; :vl-generate -- not allowed
                                                                 ;; :vl-port     -- not allowed
                                                                 ;; :vl-portdecl -- not allowed
                                                                 ;; :vl-assign   -- not allowed
                                                                 ;; :vl-alias   -- bozo, let's not permit these yet
                                                                 :vl-vardecl
                                                                 :vl-paramdecl
                                                                 :vl-fundecl
                                                                 :vl-taskdecl
                                                                 ;; :vl-modinst  -- not allowed
                                                                 ;; :vl-gateinst -- not allowed
                                                                 ;; :vl-always   -- not allowed
                                                                 ;; :vl-initial  -- not allowed
                                                                 :vl-typedef
                                                                 :vl-import
                                                                 ;; :vl-fwdtypedef -- not allowed
                                                                 ;; :vl-modport    -- not allowed
                                                                 )))
                          (warnings
                           (if (not bad-item)
                               warnings
                             (fatal :type :vl-bad-package-item
                                    :msg "~a0: a package may not contain ~x1s."
                                    :args (list bad-item (tag bad-item)))))

                          ((vl-genblob c) (vl-sort-genelements items)))
                       (make-vl-package :name (vl-idtoken->name name)
                                        :minloc (vl-token->loc startkwd)
                                        :maxloc (vl-token->loc endkwd)
                                        :lifetime lifetime
                                        :vardecls c.vardecls
                                        :paramdecls c.paramdecls
                                        :fundecls c.fundecls
                                        :taskdecls c.taskdecls
                                        :typedefs c.typedefs
                                        :imports c.imports
                                        :warnings warnings
                                        :atts atts
                                        ;; bozo timeunits stuff
                                        ;; bozo package items stuff
                                        )))))

              ((unless err)
               ;; We read the whole thing and made a valid package, so that's great.
               ;; We just need to restore the original warnings and return our answer.
               (let ((tokstream (vl-tokstream-update-pstate
                                 (change-vl-parsestate (vl-tokstream->pstate) :warnings orig-warnings))))
                 (mv nil pkg tokstream)))

              ;; There was some error parsing the package.  Stop everything, go
              ;; back to 'package foo' part.  Scan for a matching 'endpackage'.
              ;; Throw away everything in between and create a fake package
              ;; full of errors.
              (errtokens
               ;; To get the tokens at the point of the error, we need to do this
               ;; before restoring the tokstream!
               (vl-tokstream->tokens))
              (tokstream (vl-tokstream-restore backup)))
           (seq tokstream
                (endkwd := (vl-skip-through-endpackage (vl-idtoken->name name)))
                (return
                 (vl-make-package-with-parse-error (vl-idtoken->name name)
                                                   (vl-token->loc startkwd)
                                                   (vl-token->loc endkwd)
                                                   err
                                                   errtokens)))))))