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
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
###############################################################################
# Copyright (c) 2019-2024 by Altair Engineering, Inc.
# All rights reserved.
#
# Altair Engineering, Inc. makes this software available as part of the Vision
# tool platform.  As long as you are a licensee of the Vision tool platform
# you may make copies of the software and modify it to be used within the
# Vision tool platform, but you must include all of this notice on any copy.
# Redistribution without written permission to any third party, with or
# without modification, is not permitted.
# Altair Engineering, Inc. does not warrant that this software is error free
# or fit for any purpose.  Altair Engineering, Inc. disclaims any liability for
# all claims, expenses, losses, damages and costs any user may incur as a
# result of using, copying or modifying the software.
# =============================================================================
#   @plugin
#       Read Voltage Collision Report
#   @namespace
#       VoltageCollision
#   @section
#       Read Side Files and Annotate Data
#   @description
#       Parse a VoltageCollision report file and display all paths in a custom
#       widget.
#   @files
#       cust31/voltageCollision.tcl
#   @tag
#       spice gui
###############################################################################


# =============================================================================
# Init - Initialize the plugin.
# =============================================================================
#
proc VoltageCollision:Init {argc argv} {
    global VoltageCollision

    ##
    # Add menu entries.
    #
    gui menu command {"Voltage Collision" "Load Report"} \
        [list VoltageCollision:_loadReport]
    gui menu command {"Voltage Collision" "Close Tab"} \
        [list VoltageCollision:_closeWidget]
    gui menu customizeEntry {"Voltage Collision" "Close Tab"} \
        [list VoltageCollision:_customizeCloseMenu]

    set VoltageCollision(title) "Voltage Collisions"

    if {$argc > 0} {
        VoltageCollision:_loadReport [lindex $argv 0]
    }
}


# =============================================================================
# Finit - Finalize the plugin.
# =============================================================================
#
proc VoltageCollision:Finit {} {
    ##
    # Undo modifications of the GUI.
    #
    gui menu removeEntry {"Voltage Collision" "Load Report"}
    gui menu removeEntry {"Voltage Collision" "Close Tab"}

    ##
    # Close tab.
    #
    VoltageCollision:_closeWidget
}


# -----------------------------------------------------------------------------
# _loadReport -
# -----------------------------------------------------------------------------
#
proc VoltageCollision:_loadReport {{fname ""}} {
    if {$fname eq ""} {
        set fname [gui window fileDialog openFile  \
            "Open a Voltage Collision Report File" \
            {{"Voltage Collision Report" {"*"}}}]
    }
    if {$fname eq ""} {
        return
    }

    VoltageCollision:_closeWidget
    set w [VoltageCollision:_createWidget]
    update

    zprogress begin
    VoltageCollision:_parseReport $w $fname
    zprogress end
}


# -----------------------------------------------------------------------------
# _createWidget -
# -----------------------------------------------------------------------------
#
proc VoltageCollision:_createWidget {} {
    global VoltageCollision

    set w [gui window insertCustomWidget $VoltageCollision(title) \
                -pluginNamespace "VoltageCollision"]
    set VoltageCollision(widget) $w

    panedwindow $w.pane -orient horizontal

    ##
    # Left side widget.
    #
    ttk::frame $w.pane.left
    ttk::scrollbar $w.pane.left.x \
        -orient  horizontal \
        -command [list $w.pane.left.list xview]
    ttk::scrollbar $w.pane.left.y \
        -orient  vertical \
        -command [list $w.pane.left.list yview]
    ttk::treeview $w.pane.left.list  \
        -xscrollcommand [list $w.pane.left.x set] \
        -yscrollcommand [list $w.pane.left.y set]

    grid $w.pane.left.list -row 0 -column 0 -sticky news
    grid $w.pane.left.x    -row 1 -column 0 -sticky we
    grid $w.pane.left.y    -row 0 -column 1 -sticky ns
    grid rowconfigure    $w.pane.left 0 -weight 1
    grid columnconfigure $w.pane.left 0 -weight 1
    bind $w.pane.left.list <<TreeviewSelect>> \
        [list VoltageCollision:_show $w]

    ##
    # Right side widget.
    #
    ttk::frame $w.pane.right
    ttk::scrollbar $w.pane.right.x \
        -orient  horizontal \
        -command [list $w.pane.right.text xview]
    ttk::scrollbar $w.pane.right.y \
        -orient  vertical \
        -command [list $w.pane.right.text yview]
    text $w.pane.right.text -state disabled \
        -wrap none \
        -xscrollcommand [list $w.pane.right.x set] \
        -yscrollcommand [list $w.pane.right.y set]

    grid $w.pane.right.text -row 0 -column 0 -sticky news
    grid $w.pane.right.x    -row 1 -column 0 -sticky we
    grid $w.pane.right.y    -row 0 -column 1 -sticky ns
    grid rowconfigure    $w.pane.right 0 -weight 1
    grid columnconfigure $w.pane.right 0 -weight 1

    $w.pane add $w.pane.left  -stretch always
    $w.pane add $w.pane.right -stretch always

    grid $w.pane -row 0 -column 0 -sticky news
    grid rowconfigure    $w 0 -weight 1
    grid columnconfigure $w 0 -weight 1

    return $w
}


# -----------------------------------------------------------------------------
# _customizeCloseMenu - Disable the 'Close Tab' menu entry if the tab is
#                       already closed.
# -----------------------------------------------------------------------------
#
proc VoltageCollision:_customizeCloseMenu {menuId} {
    global VoltageCollision

    set state "disabled"
    if {[info exists VoltageCollision(widget)]} {
        set state "normal"
    }
    $menuId entryconfigure end -state $state
}


# -----------------------------------------------------------------------------
# _closeWidget - Destroy the Voltage Collision tab.
# -----------------------------------------------------------------------------
#
proc VoltageCollision:_closeWidget {} {
    global VoltageCollision

    if {[info exists VoltageCollision(widget)]} {
        gui window removeCustomWidget $VoltageCollision(title)
        destroy $VoltageCollision(widget)
        array unset VoltageCollision widget
    }
}


# -----------------------------------------------------------------------------
# _parseReport -
# -----------------------------------------------------------------------------
#
proc VoltageCollision:_parseReport {w fname} {
    global VoltageCollision

    $w.pane.left.list delete [$w.pane.left.list children {}]
    $w.pane.right.text configure -state normal
    $w.pane.right.text delete 1.0 end

    set pattern "ERROR: Voltage Collision on net:*"
    set len [string length $pattern]
    set in [open $fname rb]
    set lineno 0
    set id   ""
    set pwr1 ""
    set pwr2 ""
    set pwr1_cnt 0
    set pwr2_cnt 0

    zprogress push "Parse Report" 1.0
    set reportSize [file size $fname]
    set readBytes  0

    while {![eof $in]} {
        incr readBytes [gets $in line]

        if {[zprogress update "" [incr readBytes] $reportSize]} {
            break
        }

        incr lineno
        $w.pane.right.text insert end $line
        $w.pane.right.text insert end "\n"

        if {[string match $pattern $line]} {
            set pwr1 [lindex $line end-2]
            set pwr2 [lindex $line end]
            set net  [lindex $line end-2]
            set text [string range $line $len end]
            set id   [$w.pane.left.list insert {} end -text $text]
            set VoltageCollision(pwr1:$id)      $pwr1
            set VoltageCollision(pwr2:$id)      $pwr2
            set VoltageCollision(startLine:$id) $lineno
            continue
        }
        if {($id ne "") && ($pwr1 ne "") && ($pwr1 ne "")} {
            if {[string match "*${pwr1}*" $line]} {
                if {$pwr1_cnt == 0} {
                    set equalPos [string first ") = (" $line]
                    incr equalPos 4
                    set VoltageCollision(obj1:$id) \
                        [string range $line $equalPos end-1]
                }
                incr pwr1_cnt
            } elseif {[string match "*${pwr2}*" $line]} {
                if {$pwr2_cnt == 0} {
                    set equalPos [string first ") = (" $line]
                    incr equalPos 4
                    set VoltageCollision(obj2:$id) \
                        [string range $line $equalPos end-1]
                }
                incr pwr2_cnt
            }
        }
        if {($id ne "") && ($pwr1_cnt == 2) && ($pwr2_cnt == 2)} {
            set VoltageCollision(endLine:$id) $lineno
            set id   ""
            set pwr1 ""
            set pwr2 ""
            set pwr1_cnt 0
            set pwr2_cnt 0
        }
    }
    close $in
    $w.pane.right.text configure -state disabled
    zprogress pop
}


# -----------------------------------------------------------------------------
# _getCellName -
# -----------------------------------------------------------------------------
#
proc VoltageCollision:_getCellName {s} {
    set s [string trim $s "()"]
    set pathInfo [split $s "("]

    if {[llength $pathInfo] == 1} {
        set idx 0
    } else {
        set idx 1
    }
    set s [lindex $pathInfo $idx]
    set pos [string first "->" $s]
    set cellName [string range $s 0 [expr {$pos - 1}]]
    return $cellName
}


# -----------------------------------------------------------------------------
# _getPortName -
# -----------------------------------------------------------------------------
#
proc VoltageCollision:_getPortName {s} {
    set s [string trim $s "()"]
    set pathInfo [split $s "("]

    if {[llength $pathInfo] == 1} {
        set idx 0
    } else {
        set idx 1
    }
    set s [lindex $pathInfo $idx]
    set pos [string first "->" $s]
    set portName [string range $s [expr {$pos + 2}] end]
    return $portName
}


# -----------------------------------------------------------------------------
# _getInstName -
# -----------------------------------------------------------------------------
#
proc VoltageCollision:_getInstName {s} {
    set s [string trim $s "()"]
    set pathInfo [split $s "("]

    if {[llength $pathInfo] == 1} {
        return ""
    }
    set instName [lindex $pathInfo 0]
    return $instName
}


# -----------------------------------------------------------------------------
# _findObj -
# -----------------------------------------------------------------------------
#
proc VoltageCollision:_findObj {db obj id} {
    global VoltageCollision

    set top [$db get_top_design]
    set root ""
    set parent ""
    set resList {}
    set splitItems [split $VoltageCollision($obj:$id) "/"]
    set itemCount  [llength $splitItems]
    set i 0

    foreach item $splitItems {
        if {[zprogress update $item [incr i] $itemCount]} {
            break
        }

        ##
        # Extract the cell from the report line.
        #
        set cellName [VoltageCollision:_getCellName $item]
        set cell [$db search cell $cellName]
        if {[$db oid isnull $cell]} {
            zmessage print ERR "Cannot find cell: '$cellName'."
            break
        }

        if {$root eq ""} {
            set root $cell
        }

        set portName [VoltageCollision:_getPortName $item]
        set port [$db search port $cell $portName]
        lappend resList $cell $port

        if {$parent eq ""} {
            set parent $cell
            continue
        }

        set instName [VoltageCollision:_getInstName $item]
        if {$instName ne ""} {
            set inst [$db search inst $parent $instName]
            if {![$db oid isnull $inst]} {
                lappend resList $inst
            }

            set pin [$db search pin $inst $portName]
            if {![$db oid isnull $pin]} {
                lappend resList $pin
            }
        }
        set parent $cell
    }
    return $resList
}


# -----------------------------------------------------------------------------
# _show -
# -----------------------------------------------------------------------------
#
proc VoltageCollision:_show {w} {
    global VoltageCollision

    set db [gui database get]
    if {$db == {}}  {
        return
    }

    set id [$w.pane.left.list focus]
    set startLine $VoltageCollision(startLine:$id)
    set endLine   $VoltageCollision(endLine:$id)
    set seeLine   [expr {$startLine -2}]
    $w.pane.right.text tag delete highlight
    $w.pane.right.text tag configure highlight -background yellow
    $w.pane.right.text tag add highlight $startLine.0 [incr endLine].0
    $w.pane.right.text yview ${seeLine}.0
    update

    zprogress begin
    zprogress push "Find Obj 1" 0.5
    set res1 [VoltageCollision:_findObj $db obj1 $id]
    if {![zprogress pop]} {
        zprogress push "Find Obj 2" 1.0
        set res2 [VoltageCollision:_findObj $db obj2 $id]
        zprogress pop
    }
    set isInterrupted [zprogress isinterrupted]
    zprogress end

    if {$isInterrupted} {
        return
    }

    set resList [concat $res1 $res2]

    gui window show Mem
    gui window show Cone
    gui mem clear
    gui mem append $resList
    gui cone load $resList
}


# =============================================================================
# Call the initialization procedure.
# =============================================================================
#
VoltageCollision:Init $argc $argv