File: interfaces.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 (275 lines) | stat: -rw-r--r-- 12,867 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
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
; 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")
(include-book "imports")
(include-book "../../mlib/blocks")
(local (include-book "../../util/arithmetic"))


#||

interface_declaration ::=
interface_nonansi_header [ timeunits_declaration ] { interface_item }
endinterface [ : interface_identifier ]
| interface_ansi_header [ timeunits_declaration ] { non_port_interface_item }
endinterface [ : interface_identifier ]
| { attribute_instance } interface interface_identifier ( .* ) ;
[ timeunits_declaration ] { interface_item }
endinterface [ : interface_identifier ]
| extern interface_nonansi_header
| extern interface_ansi_header

interface_nonansi_header ::=
{ attribute_instance } interface [ lifetime ] interface_identifier
{ package_import_declaration } [ parameter_port_list ] list_of_ports ;

interface_ansi_header ::=
{attribute_instance } interface [ lifetime ] interface_identifier
{ package_import_declaration }1 [ parameter_port_list ] [ list_of_port_declarations ] ;

||#

(define vl-make-interface-by-items

; Our various parsing functions for declarations, assignments, etc., return all
; kinds of different interface items.  We initially get all of these different
; kinds of items as a big list.  Then, here, we sort it into buckets by type,
; and turn it into a interface.

  ((name     stringp               "Name of the interface.")
   (params   vl-paramdecllist-p    "Parameters declarations from the #(...) list, if any.")
   (ports    vl-portlist-p         "Ports like (o, a, b).")
   (items    vl-genelementlist-p   "Items from the interface's body, i.e., until endinterface.")
   (atts     vl-atts-p)
   (minloc   vl-location-p)
   (maxloc   vl-location-p)
   (warnings vl-warninglist-p))
  :returns (mod vl-interface-p)
  (b* ((items (append-without-guard (vl-modelementlist->genelements params)
                                    items))

       (bad-item (vl-genelementlist-findbad items
                                            '(:vl-generate
                                              ;; :vl-port    -- not allowed, they were parsed separately
                                              :vl-portdecl
                                              ;; :vl-assign  -- not allowed
                                              ;; :vl-alias   -- not allowed (bozo yet?)
                                              :vl-vardecl
                                              :vl-paramdecl
                                              ;; :vl-fundecl  -- not allowed
                                              ;; :vl-taskdecl -- not allowed
                                              ;; :vl-modinst  -- not allowed
                                              ;; :vl-gateinst -- not allowed
                                              ;; :vl-always   -- not allowed
                                              ;; :vl-initial  -- not allowed
                                              ;; :vl-typedef    -- bozo? not yet
                                              :vl-import
                                              ;; :vl-fwdtypedef -- bozo? not yet
                                              :vl-modport
                                              )))
       (warnings
        (if (not bad-item)
            warnings
          (fatal :type :vl-bad-interface-item
                 :msg "~a0: an interface may not contain ~x1s."
                 :args (list bad-item (tag bad-item)))))

       ((vl-genblob c) (vl-sort-genelements items)))

     (make-vl-interface :name       name
                        :ports      ports
                        :portdecls  c.portdecls
                        :vardecls   c.vardecls
                        :paramdecls c.paramdecls
                        :modports   c.modports
                        :generates  c.generates
                        :imports    c.imports
                        :atts       atts
                        :minloc     minloc
                        :maxloc     maxloc
                        :warnings   warnings
                        :origname   name
                        :comments   nil
                        :loaditems  items
                        )))

(defparser vl-parse-interface-declaration-core (atts interface-kwd name)
  :guard (and (vl-atts-p atts)
              (vl-token-p interface-kwd)
              (vl-idtoken-p name))
  :result (vl-interface-p val)
  :resultp-of-nil nil
  :fails gracefully
  :count strong
  (seq tokstream
       (imports  := (vl-parse-0+-package-import-declarations)) ;; ignore
       (params   := (vl-maybe-parse-parameter-port-list))
       (portinfo := (vl-parse-module-port-list-top))
       (:= (vl-match-token :vl-semi))
       (items := (vl-parse-genelements-until :vl-kwd-endinterface))
       (endkwd := (vl-match-token :vl-kwd-endinterface))
       (:= (vl-parse-endblock-name (vl-idtoken->name name)
                                   "interface/endinterface"))
       (return-raw
        (b* (((vl-parsed-ports portinfo))
             (name     (vl-idtoken->name name))
             (minloc   (vl-token->loc interface-kwd))
             (maxloc   (vl-token->loc endkwd))
             (warnings (vl-parsestate->warnings (vl-tokstream->pstate)))
             ((when (and portinfo.ansi-p (vl-genelementlist->portdecls items))) ;; User's fault
              (vl-parse-error "ANSI interface cannot have internal port declarations."))
             ((when (and (not portinfo.ansi-p)
                         (or portinfo.portdecls portinfo.vardecls)))
              (vl-parse-error "Non-ANSI interface ports are somehow causing declarations?
                               Programming error."))
             (items (append (vl-modelementlist->genelements imports)
                            (vl-modelementlist->genelements portinfo.portdecls)
                            (vl-modelementlist->genelements portinfo.vardecls)
                            items))
             (interface (vl-make-interface-by-items name params portinfo.ports items
                                              atts minloc maxloc warnings)))
          (mv nil interface tokstream)))))

(defparser vl-parse-interface-main (atts interface-kwd name)
  :guard (and (vl-atts-p atts)
              (vl-token-p interface-kwd)
              (vl-idtoken-p name))
  :result (vl-interface-p val)
  :resultp-of-nil nil
  :fails gracefully
  :count strong
  ;; This is all just like vl-parse-module-main.
  (b* ((orig-warnings (vl-parsestate->warnings (vl-tokstream->pstate)))
       (tokstream (vl-tokstream-update-pstate
                   (change-vl-parsestate (vl-tokstream->pstate) :warnings nil)))
       ((mv err1 res tokstream)
        (vl-parse-interface-declaration-core atts interface-kwd name))
       (tokstream (vl-tokstream-update-pstate
                   (change-vl-parsestate (vl-tokstream->pstate) :warnings orig-warnings))))
    (mv err1 res tokstream)))

(defparser vl-skip-through-endinterface ()
  :result (vl-endinfo-p val)
  :resultp-of-nil nil
  :fails gracefully
  :count strong

; This is a special function which is used to provide more fault-tolerance in
; interface parsing.  Historically, we just advanced the token stream until
; :vl-kwd-endinterface was encountered.  For SystemVerilog, we also capture the
; "endinterface : foo" part and return a proper vl-endinfo-p.

  (seq tokstream
       (unless (vl-is-token? :vl-kwd-endinterface)
         (:s= (vl-match-any))
         (info := (vl-skip-through-endinterface))
         (return info))
       ;; Now we're at endinterface
       (end := (vl-match))
       (unless (and (vl-is-token? :vl-colon)
                    (not (eq (vl-loadconfig->edition config) :verilog-2005)))
         (return (make-vl-endinfo :name nil
                                  :loc (vl-token->loc end))))
       (:= (vl-match))
       (id := (vl-match-token :vl-idtoken))
       (return (make-vl-endinfo :name (vl-idtoken->name id)
                                :loc (vl-token->loc id)))))

(define vl-make-interface-with-parse-error ((name   stringp)
                                            (minloc vl-location-p)
                                            (maxloc vl-location-p)
                                            (err    vl-warning-p)
                                            (tokens vl-tokenlist-p))
  :returns (res vl-interface-p)
  (b* (;; Like vl-make-module-with-parse-error.
       (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-interface :name name
                       :origname name
                       :minloc minloc
                       :maxloc maxloc
                       :warnings (list err warn2))))

(defparser vl-parse-interface-declaration (atts)
  :guard (vl-atts-p atts)
  :result (vl-interface-p val)
  :resultp-of-nil nil
  :fails gracefully
  :count strong
  (seq tokstream
       (kwd := (vl-match-token :vl-kwd-interface))
       (id  := (vl-match-token :vl-idtoken))
       (return-raw
        (b* ((backup (vl-tokstream-save))
             ((mv err res tokstream)
              ;; We ignore the warnings because it traps them and associates
              ;; them with the interface, anyway.
              (vl-parse-interface-main atts kwd id))
             ((unless err)
              ;; Good deal, got the interface successfully.
              (mv err res tokstream))
             (new-tokens (vl-tokstream->tokens))
             (tokstream (vl-tokstream-restore backup))
             ;; We failed to parse a interface but we are going to try to be
             ;; somewhat fault tolerant and "recover" from the error.  The
             ;; general idea is that we should advance until "endinterface."
             ((mv recover-err endinfo tokstream)
              (vl-skip-through-endinterface))
             ((when recover-err)
              ;; Failed to even find endinterface, abandon recovery effort.
              (mv err res tokstream))

             ;; In the Verilog-2005 days, we could just look for endinterface.
             ;; But now we have to look for endinterface : foo, too.  If the
             ;; name doesn't line up, we'll abandon our recovery effort.
             ((when (and (vl-endinfo->name endinfo)
                         (not (equal (vl-idtoken->name id)
                                     (vl-endinfo->name endinfo)))))
              (mv err res tokstream))

             ;; Else, we found endinterface and, if there's a name, it seems
             ;; to line up, so it seems okay to keep going.
             (phony-interface
              (vl-make-interface-with-parse-error (vl-idtoken->name id)
                                                  (vl-token->loc kwd)
                                                  (vl-endinfo->loc endinfo)
                                                  err new-tokens)))
          ;; Subtle: we act like there's no error, because we're
          ;; recovering from it.  Get it?
          (mv nil phony-interface tokstream)))))