File: showloc.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 (181 lines) | stat: -rw-r--r-- 6,900 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
; 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 "../loader/descriptions")
(include-book "../loader/inject-comments")
(include-book "../util/print")
(local (include-book "../util/arithmetic"))


; Location display.
;
; When the user clicks on a particular location, we want to display a nice
; page that essentially shows something like this:
;
;  module mod ( ... );    } "startline"
;
;  ...                    } "hidden before context"  (HBC)
;
;  wire w;                } "before" context    (BC)
;  wire v;                }
;
;  assign w = ... ;       } "goal line"
;
;  assign v = ... ;       } "after context" (AC)
;  assign q = ... ;       }
;
;  ...                    } "hidden after context" (HAC)
;
;  endmodule              } "lastline"


(define vl-find-description-for-loc ((loc vl-location-p)
                                     (x   vl-descriptionlist-p))
  :returns (desc (iff (vl-description-p desc)
                      desc))
  ;; Find the first module that contains the desired location.
  (cond ((atom x)
         nil)
        ((vl-location-between-p loc
                                (vl-description->minloc (car x))
                                (vl-description->maxloc (car x)))
         (vl-description-fix (car x)))
        (t
         (vl-find-description-for-loc loc (cdr x)))))


(define vls-showloc-print-bc (contents start goal &key (ps 'ps))
  ;; Assumes the starting line has already been printed
  :guard (and (stringp contents)
              (posp start)
              (posp goal))
  ;; The before-context is everything between start and goal, exclusive.
  (b* ((bc-start  (+ 1 start))
       (bc-stop   (- goal 1))
       (bc-nlines (+ 1 (- goal bc-start))))
    (cond
     ((< bc-stop bc-start)
      ;; There's no before context at all, so there's nothing to print.
      ps)

     ((<= bc-nlines 5)
      ;; The before-context is pretty small, so don't hide any of it.
      (vl-ps-seq
       (vl-println-markup "<div id=\"showloc_bc\">")
       (vl-print (str::strlines bc-start bc-stop contents))
       (vl-println-markup "</div>")))

     (t
      ;; The before-context is pretty large.
      (vl-ps-seq
       (vl-println-markup "  <a id=\"showloc_hbc_link\" href=\"javascript:void(0)\" onclick=\"showloc_hbc()\">...</a>")
       (vl-println-markup "<div id=\"showloc_hbc\" style=\"display: none\">")
       (vl-print (str::strlines bc-start (- bc-stop 4) contents))
       (vl-println-markup "</div>") ;
       (vl-println-markup "<div id=\"showloc_bc\">")
       (vl-print (str::strlines (- bc-stop 3) bc-stop contents))
       (vl-println-markup "</div>"))))))

(define vls-showloc-print-ac (contents goal end &key (ps 'ps))
  ;; Assumes everything up through and including the goal line have already
  ;; been printed.
  :guard (and (stringp contents)
              (posp goal)
              (posp end))
  ;; The after-context is everything between goal and end, exclusive.
  (b* ((ac-start (+ goal 1))
       (ac-stop  (- end 1))
       (ac-nlines (+ 1 (- end ac-start))))
      (cond
       ((< ac-stop ac-start)
        ;; No after-context, so nothing to print
        ps)

       ((<= ac-nlines 5)
        ;; The before-context is pretty small, so don't hide any of it.
        (vl-ps-seq
         (vl-println-markup "<div id=\"showloc_ac\">")
         (vl-print (str::strlines ac-start ac-stop contents))
         (vl-println-markup "</div>")))

       (t
        ;; The before-context is pretty large.
        (vl-ps-seq
         (vl-println-markup "<div id=\"showloc_ac\">")
         (vl-print (str::strlines ac-start (+ ac-start 3) contents))
         (vl-println-markup "</div>")
         (vl-println-markup "<a id=\"showloc_hac_link\" href=\"javascript:void(0)\" onClick=\"showloc_hac()\">...</a>")
         (vl-println-markup "<div id=\"showloc_hac\" style=\"display: none\">")
         (vl-print (str::strlines (+ ac-start 4) ac-stop contents))
         (vl-println-markup "</div>")
         )))))

(define vls-showloc-print-goal (line col &key (ps 'ps))
  :guard (and (stringp line)
              (natp col))
  (vl-ps-seq
   (vl-println-markup "<div id=\"showloc_goal\">")
   (vl-println-markup "<a name=\"hac_goal\">")
   (let ((len (length line)))
     (if (>= col len)
         ;; Really this is an error, there's no such column on the goal line.
         ;; We'll just print whatever the line is.
         (vl-println line)
       (vl-ps-seq
        (vl-print (subseq line 0 col))
        (vl-print-markup "<span class=\"showloc_goalcol\">")
        (vl-print (char line col))
        (vl-print-markup "</span>")
        (vl-println (subseq line (+ col 1) nil)))))
   (vl-println-markup "</a>")
   (vl-println-markup "</div>")))

(define vls-showloc-print (contents min max line col &key (ps 'ps))
  :guard (and (stringp contents)
              (posp min)
              (posp max)
              (posp line)
              (natp col))
  (vl-ps-seq
   (if (equal min line)
       ps
     (vl-ps-seq (vl-println-markup "<div id=\"showloc_start\">")
                (vl-println (str::strline min contents))
                (vl-println-markup "</div>")))
   (vls-showloc-print-bc contents min line)
   (vls-showloc-print-goal (str::strline line contents) col)
   (vls-showloc-print-ac contents line max)
   (if (equal max line)
       ps
     (vl-ps-seq (vl-println-markup "<div id=\"showloc_end\">")
                (vl-println (str::strline max contents))
                (vl-println-markup "</div>")))))