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
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
###############################################################################
# Copyright (c) 2001-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
#       Load HyperFault Logfile
#   @namespace
#       HyperFaultLog
#   @section
#       Read Side Files and Annotate Data
#   @description
#       Parse and display a HyperFault report or log file.
#   @test
#       ModuleTest
#   @files
#       hyperfault/hyperfault_log.tcl
#       hyperfault/bus85.flt
#   @example
#       demo/verilog/bus85.f
#       demo/verilog/bus85.sym
#   @cmdline
#       -verilog
#       -F @example[0]
#       -symlib @example[1]
#       -userware2 @files[0] @files[1]
#   @tag
#       verilog netlist gui
###############################################################################


# =============================================================================
# Init - Unset old values and initialize HyperFault array.
# =============================================================================
#
proc HyperFaultLog:Init {argc argv} {
    global HyperFaultLog

    set db [gui database get]

    HyperFaultLog:ResetVariables $db

    gui menu command {"Userware" "Load Hyperfault Log"} \
        [list HyperFaultLog:loadFile $db]
    gui menu command {"Userware" "Set Hyperfault Log Prefix"} \
        [list HyperFaultLog:setPrefix]

    if {$argc == 1} {
        set HyperFaultLog(cmd) \
            [list HyperFaultLog:ResetVariablesAndLoadFile [lindex $argv 0]]
    } else {
        set HyperFaultLog(cmd) HyperFaultLog:ResetVariables
    }

    gui database registerChangedCallback $HyperFaultLog(cmd)
}


# =============================================================================
# Finit - Finalize the plugin.
# =============================================================================
#
proc HyperFaultLog:Finit {} {
    global HyperFaultLog

    gui menu removeEntry  {"Userware" "Load Hyperfault Log"}
    gui menu removeEntry  {"Userware" "Set Hyperfault Log Prefix"}

    gui database removeChangedCallback [lindex $HyperFaultLog(cmd) 0]
}


# =============================================================================
# ResetVariablesAndLoadFile - Reset variables and load the given file.
# =============================================================================
#
proc HyperFaultLog:ResetVariablesAndLoadFile {file db} {
    HyperFaultLog:ResetVariables $db

    ##
    # If db is close do no load file again.
    #
    if {$db ne {}} {
        HyperFaultLog:showFile $file
    }
}


# =============================================================================
# ResetVariables - Reset internal variables.
# =============================================================================
#
proc HyperFaultLog:ResetVariables {db} {
    global HyperFaultLog

    set HyperFaultLog(prefix)           "stimulate.dm."
    set HyperFaultLog(db)               $db
    set HyperFaultLog(displayAttribute) 0
    if {$db == {}} {
        return
    }
    $db foreach top top {
        set HyperFaultLog(top) [$db oid oname $top]
        break
    }
}


# -----------------------------------------------------------------------------
# loadFile - Show a browse file dialog to open a HyperFaultLog file.
# -----------------------------------------------------------------------------
#
proc HyperFaultLog:loadFile {{db {}}} {
    global HyperFaultLog

    if {![info exists HyperFaultLog(db)]} {
        HyperFaultLog:ResetVariables $db
    } else {
        set db $HyperFaultLog(db)
    }

    if {$HyperFaultLog(db) == {}} {
        set msg "No database loaded."
        zmessage print ERR $msg
        tk_messageBox -message $msg -icon error -parent . -title "Error:"
        return
    }

    set fileTypes {{"HyperFaultLog-File" {".flt"}}}
    set f [gui window fileDialog openFile \
        "Open a HyperFault Log file" $fileTypes]
    if {$f == "" } {
        return
    }
    HyperFaultLog:showFile $f
}


# -----------------------------------------------------------------------------
# showFile -
# -----------------------------------------------------------------------------
#
proc HyperFaultLog:showFile {file} {
    global HyperFaultLog

    if {[winfo exists .hyperLog]} {
        destroy .hyperLog
    }
    toplevel     .hyperLog
    wm transient .hyperLog .
    wm group     .hyperLog .
    wm title     .hyperLog HyperFaultLog
    wm withdraw  .hyperLog

    ##
    # Listbox with y scrollbars.
    #
    ttk::frame .hyperLog.l
    listbox .hyperLog.l.pinList -exportselection   0                           \
                                -selectborderwidth 0                           \
                                -selectmode        single                      \
                                -yscrollcommand    [list .hyperLog.l.ysb set]
    ttk::scrollbar .hyperLog.l.ysb -orient vertical \
                                -command [list .hyperLog.l.pinList yview]
    grid .hyperLog.l.pinList    -column 0 -row 0 -sticky news
    grid .hyperLog.l.ysb        -column 1 -row 0 -sticky ns
    grid rowconfigure    .hyperLog.l 0 -weight 1
    grid columnconfigure .hyperLog.l 0 -weight 1
    grid columnconfigure .hyperLog.l 1 -weight 0

    ##
    # Text widget with x and y scrollbars.
    #
    ttk::frame .hyperLog.r
    text .hyperLog.r.lineNo   -bd             0                                \
                              -font           TkFixedFont                      \
                              -cursor         {}                               \
                              -width          4                                \
                              -wrap           none                             \
                              -state          disabled                         \
                              -yscrollcommand [list .hyperLog.r.ysb set]       \
                              -xscrollcommand [list .hyperLog.r.xsb set]
    text .hyperLog.r.source   -bd             0                                \
                              -font           TkFixedFont                      \
                              -cursor         {}                               \
                              -wrap           none                             \
                              -state          disabled                         \
                              -takefocus      1                                \
                              -yscrollcommand [list .hyperLog.r.ysb set]       \
                              -xscrollcommand [list .hyperLog.r.xsb set]
    ttk::scrollbar .hyperLog.r.ysb -orient vertical \
                              -command [list HyperFaultLog:scrollText]
    ttk::scrollbar .hyperLog.r.xsb -orient horizontal \
                              -command [list .hyperLog.r.source xview]

    grid .hyperLog.r.lineNo  -column 0 -row 0 -sticky news
    grid .hyperLog.r.source  -column 1 -row 0 -sticky news
    grid .hyperLog.r.xsb     -column 0 -row 1 -sticky we   -columnspan 2
    grid .hyperLog.r.ysb     -column 2 -row 0 -sticky ns
    grid rowconfigure    .hyperLog.r 0 -weight 1
    grid columnconfigure .hyperLog.r 1 -weight 1

    .hyperLog.r.source tag configure highlight -foreground #FF0000
    .hyperLog.r.lineNo configure -foreground #777777

    bind .hyperLog.r.source <Double-ButtonPress-1> {
        HyperFaultLog:gotoSelected %W %x %y
        break
    }
    bind .hyperLog.l.pinList <Double-ButtonPress-1> {
        HyperFaultLog:gotoSelected %W %x %y
        break
    }
    bind .hyperLog.r.source <B2-Motion>  {break}
    bind .hyperLog.r.source <MouseWheel> {break}
    bind .hyperLog.r.lineNo <B2-Motion>  {break}
    bind .hyperLog.r.lineNo <MouseWheel> {break}

    ##
    # Frame with window selection radiobuttons.
    #
    ttk::frame  .hyperLog.bl -relief sunken -borderwidth 1
    label       .hyperLog.bl.winLab -text     "Window:"
    ttk::radiobutton .hyperLog.bl.winSrc -text "Source" \
                                    -value    .hyperLog.r                      \
                                    -variable HyperFaultLog(showWindow)        \
                                    -command  [list raise .hyperLog.r]
    ttk::radiobutton .hyperLog.bl.winPin -text "Pins" \
                                    -value    .hyperLog.l                      \
                                    -variable HyperFaultLog(showWindow)        \
                                    -command  [list raise .hyperLog.l]
    pack .hyperLog.bl.winLab .hyperLog.bl.winSrc .hyperLog.bl.winPin -side left

    ##
    # Frame with attribute selection radiobuttons.
    #
    set HyperFaultLog(displayAttribute) 1
    ttk::frame .hyperLog.br -relief sunken -borderwidth 1
    label       .hyperLog.br.winLab -text     "Attribute:"
    ttk::radiobutton .hyperLog.br.winSrc -text "Fault" \
                               -value    1                                     \
                               -variable HyperFaultLog(displayAttribute)       \
                               -command  HyperFaultLog:displayAttributes
    ttk::radiobutton .hyperLog.br.winPin -text "None" \
                               -value    0                                     \
                               -variable HyperFaultLog(displayAttribute)       \
                               -command  HyperFaultLog:displayAttributes
    pack .hyperLog.br.winLab .hyperLog.br.winSrc .hyperLog.br.winPin -side left

    ##
    # The cancel button.
    #
    ttk::button .hyperLog.cancel -text "Cancel" \
        -command [list destroy .hyperLog]

    ##
    # Pack all with a grid layout.
    #
    grid .hyperLog.l      -row 0 -column 0 -sticky news -columnspan 3
    grid .hyperLog.r      -row 0 -column 0 -sticky news -columnspan 3
    grid .hyperLog.bl     -row 1 -column 0 -sticky we   -pady 2 -padx 1
    grid .hyperLog.br     -row 1 -column 1 -sticky we   -pady 2 -padx 1
    grid .hyperLog.cancel -row 1 -column 2 -sticky e    -pady 2 -padx 2

    grid rowconfigure    .hyperLog 0 -weight 1
    grid rowconfigure    .hyperLog 1 -weight 0
    grid columnconfigure .hyperLog 0 -weight 0
    grid columnconfigure .hyperLog 1 -weight 1

    HyperFaultLog:Parse $file $HyperFaultLog(db)
    wm deiconify .hyperLog
    set HyperFaultLog(showWindow) .hyperLog.r
    HyperFaultLog:displayAttributes
}


# =============================================================================
# Parse - Parse the HyperFaultLog file.
# =============================================================================
#
proc HyperFaultLog:Parse {file db} {
    global HyperFaultLog

    set id [open $file "r"]

    .hyperLog.r.lineNo configure -state normal
    .hyperLog.r.source configure -state normal

    set HyperFaultLog(pinList) {}
    set lineNumber 0
    set type       {}

    set prefix $HyperFaultLog(prefix)

    set typeExpr "\\.ISLOW|\\.SLOW|\\.ISHIGH|\\.SHIGH"
    set pinExpr  "\\+(( %(time|soft)%=\[1234567890\\.\]*)| )"

    while {[gets $id line]>=0} {
        incr lineNumber

        .hyperLog.r.lineNo insert end "${lineNumber}:\n"
        .hyperLog.r.source insert end "$line\n"

        ##
        # comments or empty lines are ignored
        #
        if {([string length $line] == 0) || [string match "//*" $line]} {
            continue
        }

        ##
        # match the type
        #
        if {[regexp -indices -nocase -- $typeExpr $line res]} {
            set i [lindex $res 0]
            if {$i == 0} {
                set type [string range $line 1 [lindex $res 1]]
            }
        }

        ##
        # \n|(+[ %(time)|(soft)%]|=<number>] <pin>\n)
        #
        if {[regexp -indices -nocase -- $pinExpr $line res]} {
            ##
            # extract the pin
            #
            set pinStr [string range $line [expr {[lindex $res 1] + 1}] end]
            set pinStr [string trim  $pinStr]

            ##
            # strip of the quotations
            #
            set pinStr [string range $pinStr 1 \
                                        [expr {[string length $pinStr] - 2}]]

            ##
            # set the obj
            #
            if {![string match "${prefix}*" $pinStr]} {
                set    msg "Hyperfault_log parser $file:$lineNumber - Expecting"
                append msg " \"$prefix\" as prefix in pin Description $pinStr"
                zmessage print ERR $msg
                continue
            }
            set pinStr  [string range $pinStr [string length $prefix] end]
            set pinList [split $pinStr .]
            set oid     [concat pin $HyperFaultLog(top) $pinList]
            .hyperLog.r.source tag add $oid $lineNumber.0 $lineNumber.end
            .hyperLog.l.pinList insert end "$type pin $pinList"
            lappend HyperFaultLog(pinList) $oid
        }
    }
    .hyperLog.r.lineNo configure -state disabled
    .hyperLog.r.source configure -state disabled
    raise .hyperLog.r.source
}


# -----------------------------------------------------------------------------
# displayAttributes - Display values in the schematic and cone window.
# -----------------------------------------------------------------------------
#
proc HyperFaultLog:displayAttributes {} {
    global HyperFaultLog

    if {$HyperFaultLog(displayAttribute)} {
        set show "value\n%HyperFault"
    } else {
        set show "value\n%none"
    }

    $HyperFaultLog(db) attr -db set @nlv:pin=%$show
    $HyperFaultLog(db) attr -db set @nlv:pinBus=%$show
    $HyperFaultLog(db) attr -db set @nlv:port=%$show
    $HyperFaultLog(db) attr -db set @nlv:portBus=%$show
    gui attribute changed
}


# -----------------------------------------------------------------------------
# gotoSelected - Highlight the double clicked pin and call gui * goto.
# -----------------------------------------------------------------------------
#
proc HyperFaultLog:gotoSelected {w x y} {
    global HyperFaultLog

    set index [$w index @$x,$y]
    set oid {}
    if {$w == ".hyperLog.r.source"} {
        foreach oid [$w tag names $index] {
            if {[string match "pin*" $oid]} {
                set from  [$w index $oid.first]
                set to    [$w index $oid.last]
                set index [lsearch $HyperFaultLog(pinList) $oid]
                break
            }
        }
    } else {
        set oid   [lindex $HyperFaultLog(pinList) $index]
        set range [.hyperLog.r.source tag ranges $oid]
        set from  [lindex $range 0]
        set to    [lindex $range 1]
    }
    .hyperLog.r.source tag remove highlight 1.0 end
    .hyperLog.l.pinList selection clear 0 end

    if {$oid == {}} {
        return
    }

    .hyperLog.r.source tag add highlight $from $to
    .hyperLog.r.source see $from
    .hyperLog.r.lineNo see $from

    .hyperLog.l.pinList selection set $index
    .hyperLog.l.pinList see $index

    gui goto -class Schem [list $oid]
    gui tree setCurrentModule   $oid
}


# -----------------------------------------------------------------------------
# scrollText - Scroll source and lineno text widget.
# -----------------------------------------------------------------------------
#
proc HyperFaultLog:scrollText {args} {
    eval .hyperLog.r.source yview $args
    eval .hyperLog.r.lineNo yview $args
}


# -----------------------------------------------------------------------------
# setPrefix - Create a dialog to set the prefix
# -----------------------------------------------------------------------------
#
proc HyperFaultLog:setPrefix {} {
    global HyperFaultLog

    set n .hyperfault_changeprefix
    toplevel $n

    wm transient $n .
    wm group $n .
    wm title $n "Set Hyperfault_log Pin Prefix"

    ttk::frame $n.e
    label $n.e.l -text "Prefix: "
    ttk::entry $n.e.e
    $n.e.e insert 0 $HyperFaultLog(prefix)
    pack $n.e.l -side left -padx 5
    pack $n.e.e -side left -expand yes -fill x -padx 5

    set cmd "set HyperFaultLog(prefix) \[$n.e.e get \]; destroy $n"

    ttk::frame $n.b
    ttk::button $n.b.ok -text "Ok" -command $cmd
    bind $n <Key-Return> $cmd

    ttk::button $n.b.cancel -text "Cancel" -command [list destroy $n]
    pack $n.b.ok $n.b.cancel -side left -padx 5

    pack $n.e -expand yes -fill both -side top -pady 5
    pack $n.b -side top -pady 5

    grab $n
    tkwait window $n
}


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