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
###############################################################################
# Copyright (c) 2021-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
#       Tempus Timing Report
#   @namespace
#       Tempus
#   @section
#       Read Side Files and Annotate Data
#   @description
#       Parse a Tempus report file and display all paths in a custom window.
#       Timing values are annotated in the schematic view.
#       Individual paths can be displayed in the Cone window.
#
#   @files
#       tempus/tempus.tcl
#       tempus/timingpaths.txt
#   @example
#       demo/verilog/bus85.f
#   @cmdline
#       -verilog
#       -F @example[0]
#       -userware2 @files[0] @files[1]
#   @tag
#       netlist verilog gui
###############################################################################


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

    ##
    # Add menu entry.
    #
    gui menu command        {"Tempus" "Load Report"} Tempus:_loadFile
    gui menu command        {"Tempus" "Close Tab"}   Tempus:_closeWidget
    gui menu customizeEntry {"Tempus" "Close Tab"}   Tempus:_customizeCloseMenu

    if {[llength $argv] > 0} {
        set Tempus(fileName) [lindex $argv 0]
    } else {
        set Tempus(fileName) {}
    }

    ##
    # Install callback and run it immediately if there already is a database.
    #
    gui database runAndRegisterChangedCallback [list Tempus:_initialize]
}


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

    ##
    # Undo modifications of the GUI.
    #
    gui menu removeEntry {"Tempus"}

    ##
    # Remove callback.
    #
    gui database removeChangedCallback Tempus:_initialize

    ##
    # Close tab.
    #
    Tempus:_closeWidget

    array unset Tempus
}


# -----------------------------------------------------------------------------
# _initialize - Unset old values and initialize the Tempus array.
# -----------------------------------------------------------------------------
#
proc Tempus:_initialize {db} {
    global Tempus

    set Tempus(db)           $db

    if {$db == {}} {
        return
    }

    if {$Tempus(fileName) ne ""} {
        Tempus:_showFile $Tempus(fileName)
    }
}


# -----------------------------------------------------------------------------
# _showFile - Create a dialog to visualize a Tempus file.
# -----------------------------------------------------------------------------
#
proc Tempus:_showFile {file} {
    Tempus:_createWidget
    Tempus:_parse $file
}


# -----------------------------------------------------------------------------
# _loadFile - Show a browse file dialog to open a Tempus report file.
# -----------------------------------------------------------------------------
#
proc Tempus:_loadFile {{db {}}} {
    global Tempus

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

    set f [gui window fileDialog openFile "Open a Tempus Report File" \
                                   {{"Tempus-File" {".timing" ".txt"}}}]
    if {$f eq "" } {
        return
    }
    Tempus:_showFile $f
}


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

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


# -----------------------------------------------------------------------------
# _closeWidget - Destroy the NanoTime tab.
# -----------------------------------------------------------------------------
#
proc Tempus:_closeWidget {} {
    global Tempus

    if {[info exists Tempus(widget)]} {
        gui window removeCustomWidget "Tempus"
        array unset Tempus widget
    }
}


# -----------------------------------------------------------------------------
# _createWidget - Create NanoTime widget.
# -----------------------------------------------------------------------------
#
proc Tempus:_createWidget {} {
    global Tempus

    Tempus:_closeWidget

    set w [gui window insertCustomWidget -pluginNamespace "Tempus" "Tempus"]
    set Tempus(widget) $w

    ##
    # List of items + scrollbar.
    #
    ttk::frame $w.l
    ttk::treeview $w.pathList \
        -show       tree      \
        -selectmode browse
    gui window autoscroll $w.l $w.pathList -direction y
    bind $w.pathList <<TreeviewSelect>> {Tempus:_showPath %W}

    ttk::frame $w.t
    text $w.reportFile \
        -font TkFixedFont \
        -wrap none \
        -state disabled \
        -cursor {} \
        -borderwidth 0 \
        -undo off \
        -takefocus 0 \
        -highlightthickness 0 \
        -padx 0 \
        -inactiveselectbackground {}
    gui window autoscroll $w.t $w.reportFile

    $w.reportFile tag configure pathHighlight \
        -background [gui settings get "color:srcSelectBackground"] \
        -foreground [gui settings get "color:srcSelectForeground"]

    grid $w.l -row 0 -column 0 -sticky news
    grid $w.t -row 0 -column 1 -sticky news
    grid rowconfigure    $w 0 -weight 1
    grid columnconfigure $w 1 -weight 1
}


# -----------------------------------------------------------------------------
# _parse - Parse the Tempus report file.
# -----------------------------------------------------------------------------
#
proc Tempus:_parse {file} {
    global Tempus

    if {![file exists $file]} {
        return
    }

    ##
    # Open the file for reading in binary mode.
    #
    set f [open $file r]
    chan configure $f -translation binary

    set db  $Tempus(db)
    set top [$db get_top_design]

    set state "outside"
    set lineNumber 0

    set l $Tempus(widget).pathList
    set t $Tempus(widget).reportFile

    array set pathInfo {}
    set pathList {}

    $t configure -state normal

    ##
    # Read the file line by line.
    #
    while {![eof $f]} {
        gets $f line
        $t insert end $line\n

        incr lineNumber
        switch -glob -- $line {
            "Path *: *" {
                set colon [string first ":" $line]
                set label [string range $line 0 [incr colon -1]]
                set pathInfo($label) {}
                lappend pathList $label
                set pathInfo($label:pinList) {}
                set pathInfo($label:PathStart:line) $lineNumber
            }
            "#--------------------------------*" {
                switch -exact -- $state {
                    "outside" {
                        set state "header"
                    }
                    "header" {
                        set state "path"
                        set pathInfo($label:PathHeader:line) $lineNumber
                    }
                    "path" {
                        set state "outside"
                        set pathInfo($label:PathEnd:line) $lineNumber
                    }
                    default {}
                }
            }
            default {
                switch -exact -- $state {
                    "outside" -
                    "header" {
                        continue
                    }
                    "path" {
                        set pin [lindex $line end]
                        if {[catch {
                            set oid [$db oid createFromString pin $top $pin "/"]
                        } msg]} {
                            zmessage print ERR $msg
                            continue
                        }
                        lappend pathInfo($label:pinList) $oid

                        set pathInfo($label:$oid:Arc)     [lindex $line 1]
                        set pathInfo($label:$oid:Edge)    [lindex $line 2]
                        set pathInfo($label:$oid:Delay)   [lindex $line 3]
                        set pathInfo($label:$oid:Arrival) [lindex $line 4]
                        set pathInfo($label:$oid:Load)    [lindex $line 5]
                        set pathInfo($label:$oid:Trans)   [lindex $line 6]
                        set pathInfo($label:$oid:Fanout)  [lindex $line 7]
                    }
                    default {}
                }
            }
        }
    }

    $t configure -state disabled

    foreach label $pathList {
        $l insert {} end -text $label -values [array get pathInfo $label:*]
    }

    ##
    # Close the input file.
    #
    close $f
}


# -----------------------------------------------------------------------------
# _showPath - Display the selected path in the Cone window.
# -----------------------------------------------------------------------------
#
proc Tempus:_showPath {w} {
    global Tempus

    set item [$w focus]
    set label [$w item $item -text]
    array set pathInfo [$w item $item -values]

    set t $Tempus(widget).reportFile

    $t tag remove pathHighlight 1.0 end
    $t tag add pathHighlight \
        $pathInfo($label:PathStart:line).0 \
        $pathInfo($label:PathEnd:line).0
    $t see $pathInfo($label:PathStart:line).0

    set db [gui database get]
    set cone {}
    set start ""
    foreach pin $pathInfo($label:pinList) {
        lappend cone $pin

        Tempus:_setAttr $db $label $pin pathInfo

        if {[$db oid type $pin] eq "pin"} {
            set in     [lindex [split $pathInfo($label:$pin:Arc) "->"] 0]
            set inst   [$db oid convertTo inst $pin]
            set target [$db search pin $inst $in]
            if {[$db oid isnull $target]} {
                set target $pin
            }
            if {$start ne ""} {
                set path [$db cone -shortestPath -targetObj $start $target]
                lappend cone {*}$path
            }
        }

        set start $pin
    }

    Tempus:_displayAttributes $db

    gui window show Cone
    gui cone load $cone
    gui cone zoom fullfit
}


# -----------------------------------------------------------------------------
# _setAttr -
# -----------------------------------------------------------------------------
#
proc Tempus:_setAttr {db label oid arrayName} {
    upvar 1 $arrayName pathInfo

    foreach attrName {Delay Arrival Load Trans Fanout} {
        if {[info exists pathInfo($label:$oid:$attrName)]} {
            $db flatattr $oid set "$attrName=$pathInfo($label:$oid:$attrName)"
        }
    }

    if {[info exists pathInfo($label:$oid:Edge)]} {
        set edge [string tolower $pathInfo($label:$oid:Edge)]
        if {$edge eq "f"} {
            $db flatattr $oid set "Edge=ef,+#ff0000"
        }
        if {$edge eq "r"} {
            $db flatattr $oid set "Edge=er,+#00ff00"
        }
    }
}


# -----------------------------------------------------------------------------
# _displayAttributes - Display the timing values in the Schem and Cone window.
# -----------------------------------------------------------------------------
#
proc Tempus:_displayAttributes {db} {
    set    show "Delay=%Delay\n"
    append show "Arrival=%Arrival\n"
    append show "Load=%Load\n"
    append show "Trans=%Trans\n"
    append show "Fanout=%Fanout"

    $db attr -db set @nlv:pin=$show
    $db attr -db set @nlv:pinBus=$show
    $db attr -db set @nlv:port=$show
    $db attr -db set @nlv:portBus=$show
    $db attr -db set @nlv:marks=%Edge

    gui attribute changed
}


# =============================================================================
# Call the initialization procedure.
# =============================================================================
#
Tempus:Init $argv