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
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797 | ###############################################################################
# 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
# PrimeTime
# @namespace
# PrimeTime
# @section
# Read Side Files and Annotate Data
# @description
# Parse a PrimeTime report file and display all paths in a dialog window.
# Timing values are annotated in the schematic view.
# Individual paths can be displayed in the Cone window.
#
# Features:
#
# - one file may have multiple paths (sets of faultlists)
#
# - one path may have multiple pins
#
# - for each pin, different attributes may be stored and displayed
#
# - source pinlist will be displayed
#
# - parsed pinlist can be loaded to Mem window
#
# - paths can be loaded into Cone
#
# NOTE: Only one faultlist file may be active the same time.
# @test
# ModuleTest
# @files
# primetime/primetime.tcl
# primetime/bus85.timing
# primetime/bus85_single.timing
# @example
# demo/verilog/bus85.f
# @cmdline
# -verilog
# -F @example[0]
# -userware2 @files[0] @files[1]
# @tag
# netlist verilog gui
###############################################################################
# =============================================================================
# Init - Initialize the plugin.
# =============================================================================
#
proc PrimeTime:Init {argv} {
global PrimeTime
##
# Add menu entry.
#
gui menu command {"Userware" "Load PrimeTime Report"} \
[list PrimeTime:loadFile]
if {[llength $argv] > 0} {
set PrimeTime(fileName) [lindex $argv 1]
} else {
set PrimeTime(fileName) {}
}
##
# Install callback and run it immediately if there already is a database.
#
gui database runAndRegisterChangedCallback [list PrimeTime:initDB]
}
# =============================================================================
# Finit - Finalize the plugin.
# =============================================================================
#
proc PrimeTime:Finit {} {
global PrimeTime
##
# Undo modifications of the GUI.
#
gui menu removeEntry {"Userware" "Load PrimeTime Report"}
##
# Remove callback.
#
gui database removeChangedCallback PrimeTime:initDB
##
# Close dialog.
#
if {[info exists PrimeTime(dialog)] && [winfo exists $PrimeTime(dialog)]} {
destroy $PrimeTime(dialog)
}
}
# -----------------------------------------------------------------------------
# loadFile - Show a browse file dialog to open a PrimeTime file.
# -----------------------------------------------------------------------------
#
proc PrimeTime:loadFile {{db {}}} {
global PrimeTime
if {![info exists PrimeTime(db)]} {
PrimeTime:initDB $db
}
if {$PrimeTime(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 PrimeTime file" \
{{"PrimeTime-File" {".timing"}}}]
if {$f == "" } {
return
}
PrimeTime:showFile $f
}
# -----------------------------------------------------------------------------
# showFile - Create a dialog to visualize a PrimeTime file.
# -----------------------------------------------------------------------------
#
proc PrimeTime:showFile {file} {
global PrimeTime
set w $PrimeTime(dialog)
if {[winfo exists $w]} {
destroy $w
}
toplevel $w
wm transient $w .
wm group $w .
wm title $w PrimeTime
wm withdraw $w
##
# Listbox with y scrollbars.
#
ttk::frame $w.l
ttk::checkbutton $w.l.met -text "Show only Violated" \
-variable PrimeTime(violated) \
-command PrimeTime:displayPaths
set PrimeTime(pathList) $w.l.pathList
listbox $PrimeTime(pathList) -exportselection 0 \
-selectborderwidth 0 \
-selectmode single \
-yscrollcommand [list $w.l.ysb set]
ttk::scrollbar $w.l.ysb -orient vertical \
-command [list $w.l.pathList yview]
grid $w.l.met -column 0 -row 0 -sticky we
grid $w.l.pathList -column 0 -row 1 -sticky news
grid $w.l.ysb -column 1 -row 1 -sticky ns
grid rowconfigure $w.l 1 -weight 1
grid columnconfigure $w.l 0 -weight 1
grid columnconfigure $w.l 1 -weight 0
bind $PrimeTime(pathList) <ButtonRelease-1> [list PrimeTime:SelectPath %W]
##
# Text widget with x and y scrollbars.
#
ttk::frame $w.r
set PrimeTime(lineNo) $w.r.lineNo
set PrimeTime(text) $w.r.source
text $PrimeTime(lineNo) -bd 0 \
-cursor {} \
-font TkFixedFont \
-width 3 \
-wrap none \
-state disabled \
-yscrollcommand [list $w.r.ysb set] \
-xscrollcommand [list $w.r.xsb set]
text $PrimeTime(text) -bd 0 \
-cursor {} \
-font TkFixedFont \
-wrap none \
-state disabled \
-takefocus 1 \
-yscrollcommand [list $w.r.ysb set] \
-xscrollcommand [list $w.r.xsb set]
$PrimeTime(text) tag configure path -background #B9E9B9
$PrimeTime(text) tag configure highlight -foreground #FF0000
bind $PrimeTime(text) <Double-ButtonPress-1> {
PrimeTime:gotoSelected [%W index @%x,%y]
break
}
bind $PrimeTime(text) <B2-Motion> {
break
}
bind $PrimeTime(lineNo) <B2-Motion> {
break
}
ttk::scrollbar $w.r.ysb -orient vertical \
-command [list PrimeTime:scrollText $w]
ttk::scrollbar $w.r.xsb -orient horizontal \
-command [list $w.r.source xview]
grid $w.r.lineNo -column 0 -row 0 -sticky news
grid $w.r.source -column 1 -row 0 -sticky news
grid $w.r.xsb -column 0 -row 1 -sticky we -columnspan 2
grid $w.r.ysb -column 2 -row 0 -sticky ns
grid rowconfigure $w.r 0 -weight 1
grid columnconfigure $w.r 1 -weight 1
##
# Frame with checkbuttons and buttons.
#
set b [ttk::frame $w.b]
label $b.show -text "Show: "
ttk::checkbutton $b.cap -text "Cap" \
-variable PrimeTime(displayCap) \
-command PrimeTime:displayAttributes
ttk::checkbutton $b.trans -text "Trans" \
-variable PrimeTime(displayTrans) \
-command PrimeTime:displayAttributes
ttk::checkbutton $b.incr -text "Incr" \
-variable PrimeTime(displayIncr) \
-command PrimeTime:displayAttributes
ttk::checkbutton $b.path -text "Path" \
-variable PrimeTime(displayPath) \
-command PrimeTime:displayAttributes
ttk::checkbutton $b.edges -text "Raise/Fall Edges" \
-variable PrimeTime(displayEdges) \
-command PrimeTime:displayAttributes
ttk::button $b.loadCone -text "Load Cone" -command PrimeTime:LoadCone
ttk::button $b.loadMem -text "Load Mem" -command PrimeTime:LoadMem
ttk::button $b.close -text "Close" -command [list destroy $w]
pack $b.show $b.cap $b.trans $b.incr $b.path $b.edges -side left
pack $b.loadCone $b.loadMem $b.close -side right
##
# Pack all with a grid layout.
#
grid $w.l -row 0 -column 0 -sticky news
grid $w.r -row 0 -column 1 -sticky news
grid $w.b -row 1 -column 0 -sticky news -columnspan 2
grid rowconfigure $w 0 -weight 1
grid rowconfigure $w 1 -weight 0
grid columnconfigure $w 0 -weight 0
grid columnconfigure $w 1 -weight 1
PrimeTime:Parse $file
$PrimeTime(pathList) selection set 0
PrimeTime:SelectPath $PrimeTime(pathList)
wm deiconify $w
}
# =============================================================================
# SelectPath - Show the selected path in the text widget.
# =============================================================================
#
proc PrimeTime:SelectPath {w} {
global PrimeTime
set db $PrimeTime(db)
set index [$w curselection]
if {$index == {}} {
return
}
set pathName [$w get $index]
catch {$PrimeTime(text) tag remove path 1.0 end}
set startLine $PrimeTime($pathName:start)
$PrimeTime(text) see $startLine.0
$PrimeTime(lineNo) see $startLine.0
foreach p $PrimeTime($pathName) {
set oid [lindex $p 0]
set lineNo [lindex $p 1]
set origOid $oid
##
# annotate the pinBus so the attr is still visible
#
if {[$db isBusMember $oid]} {
set oid [$db busOf $oid]
}
for {set i 0} {$i < 4} {incr i} {
set name [lindex $PrimeTime(attrNames) $i]
set value ""
if {[info exists PrimeTime($pathName:$origOid:$name)]} {
set value $PrimeTime($pathName:$origOid:$name)
}
$db flatattr $oid set ${name}=${value}
}
set edge ""
if {[info exists PrimeTime($pathName:$origOid:edge)]} {
set edge $PrimeTime($pathName:$origOid:edge)
}
if {$edge == "f"} {
$db flatattr $oid set "edge=ef,+#ff0000"
}
if {$edge == "r"} {
$db flatattr $oid set "edge=er,+#00ff00"
}
$PrimeTime(text) tag add path "$lineNo.0" "[expr {$lineNo + 1}].0"
}
PrimeTime:displayAttributes
}
# =============================================================================
# LoadCone - Load the selected path into the cone window.
# =============================================================================
#
proc PrimeTime:LoadCone {} {
global PrimeTime
set index [$PrimeTime(pathList) curselection]
if {$index == ""} {
return
}
set pathName [$PrimeTime(pathList) get $index]
set oidList {}
foreach p $PrimeTime($pathName) {
lappend oidList [lindex $p 0]
}
##
# Add missing? ports (a) pass through module boundary
# and (b) primitive outputs
#
foreach oid $oidList {
if {[$PrimeTime(db) oid type $oid] != "pin"} {
continue
}
if {[$PrimeTime(db) isModule $oid]} {
lappend oidList [lreplace $oid 0 0 port]
} else {
##
# store all outputs of given primitive in outList
#
set inst [lreplace [lrange $oid 0 end-1] 0 0 inst]
set outList {}
$PrimeTime(db) foreach pin $inst pin {
if {[$PrimeTime(db) directionOf $pin] == "output"} {
lappend outList $pin
}
}
##
# for primitives with exactly one output, add that output too
#
if {[llength $outList] == 1} {
set pin [lindex $outList 0]
if {$pin != $oid} {
lappend oidList $pin
}
}
}
}
if {[gui settings get "cone:autohide"] != 1} \
{
gui settings set "cone:autohide" 1
gui settings changed
}
gui window show Cone
gui cone load $oidList
}
# =============================================================================
# LoadMem - Load the pins of the selected path into the mem window.
# =============================================================================
#
proc PrimeTime:LoadMem {} {
global PrimeTime
set index [$PrimeTime(pathList) curselection]
if {$index == ""} {
return
}
set pathName [$PrimeTime(pathList) get $index]
set oidList {}
foreach p $PrimeTime($pathName) {
lappend oidList [lindex $p 0]
}
gui mem clear
gui window show Mem
gui mem append $oidList
}
# -----------------------------------------------------------------------------
# displayAttributes - Display the timing values in the Schem and Cone window.
# -----------------------------------------------------------------------------
#
proc PrimeTime:displayAttributes {} {
global PrimeTime
##
# Make sure that the value attribute is always visible.
#
set show "%value\n"
for {set i 0} {$i < 4} {incr i} {
set name [lindex $PrimeTime(attrNames) $i]
if {$PrimeTime(display$name)} {
append show "$name=%$name\n"
}
}
set show [string range $show 0 end-1]
set db $PrimeTime(db)
$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
if {$PrimeTime(displayEdges)} {
$db attr -db set @nlv:marks=%edge
} else {
$db attr -db delete @nlv:marks
}
gui attribute changed
}
# -----------------------------------------------------------------------------
# gotoSelected - Highlight the double clicked pin and call goto.
# -----------------------------------------------------------------------------
#
proc PrimeTime:gotoSelected {index} {
global PrimeTime
set l [lindex [split $index .] 0]
if {![info exists PrimeTime($l)]} {
return
}
$PrimeTime(text) tag remove highlight 1.0 end
gui goto [list $PrimeTime($l)]
$PrimeTime(text) tag add highlight $l.0 $l.end
}
# -----------------------------------------------------------------------------
# scrollText - Scroll source and lineno text widget.
# -----------------------------------------------------------------------------
#
proc PrimeTime:scrollText {w args} {
eval $w.r.source yview $args
eval $w.r.lineNo yview $args
}
# =============================================================================
# Parse - Parse the PrimeTime file.
# =============================================================================
#
proc PrimeTime:Parse {file} {
global PrimeTime
##
# Open the file for reading in binary mode.
#
set in [open $file r]
chan configure $in -translation binary
##
# Initialize variables.
#
set state 0
set lineNumber 0
set multiLinePath 0
set attributeNames {}
set currentPath ""
set db $PrimeTime(db)
set PrimeTime(allPaths) {}
##
# Read the file line by line.
#
$PrimeTime(text) configure -state normal
$PrimeTime(lineNo) configure -state normal
while {![eof $in]} {
gets $in line
incr lineNumber
$PrimeTime(text) insert end ${line}\n
$PrimeTime(lineNo) insert end ${lineNumber}\n
if {$state == 3} {
if {[regexp "data (arrival|required) time" $line] ||
[regexp "library hold time" $line] ||
[regexp -- ------------* $line] ||
[string match "clock " $line]} {
continue
}
##
# End of a path is reached. Check if this pth 'MET' or 'VIOLATED'.
#
if {[string match "*slack*" $line]} {
if {[string match "*(MET)*" $line]} {
set PrimeTime($currentPath:slack) MET
} else {
set PrimeTime($currentPath:slack) VIOLATED
}
set headerInfo {}
set state 0
continue
}
##
# process current path: The first field describes
# the pin, the rest of the line stores the attribute
# values. We extract the first word and chop up the
# rest of the list by char positions from $headerInfo
#
if {$multiLinePath == 0} {
set type ""
set oidT "pin"
if {[llength $line] < 3} {
continue
}
set firstWord [lindex $line 0]
set type [lindex $line 1]
if {![string match "(*)" $type]} {
continue
}
if {$type == "(net)"} {
set oidT "net"
}
set oid {}
catch {
set oid [$db oid createFromString $oidT $PrimeTime(top) \
$firstWord "/" -icase]
} err
if {$oid == {}} {
set msg "Cannot create oid from string '$firstWord': $err"
zmessage print ERR $msg
continue
}
}
foreach vhead $headerInfo {
set vname [lindex $vhead 0]
if {$vname == ""} {
##
# process this noop
#
continue
}
##
# starting at the given char location we compute $start:
# go back to the first space and compute $end: go forward -
# first skip some spaces - and then to go the first space
#
set start [lindex $vhead 1]
set end $start
while {![string is space [string index $line $start]]} {
incr start -1
}
##
# skip some spaces, but not more than the length
# of the variable name in the header
#
set endLimit [expr {$end + ([string length $vname] - 1)}]
while {($end < $endLimit) && [string is space \
[string index $line $end]]} {
incr end
}
while {![string is space [string index $line $end]]} {
incr end
}
set val [string range $line $start $end]
set val [string trim $val]
if {($val == "") || (![string is double $val])} {
set multiLinePath 1
lappend PrimeTime($currentPath) [list $oid $lineNumber]
continue
}
set PrimeTime($currentPath:$oid:$vname) $val
set multiLinePath 0
}
set PrimeTime($lineNumber) $oid
if {$multiLinePath} {
continue
}
set edge [string index [string trim $line] end]
if {($edge != "f") && ($edge != "r")} {
set edge {}
}
set PrimeTime($currentPath:$oid:edge) $edge
lappend PrimeTime($currentPath) [list $oid $lineNumber]
}
if {$state == 2} {
##
# wait for "-------" after header
#
if {[regexp -- ------------* $line]} {
set state 3
}
continue
}
##
# State 1: new path starts
#
if {$state == 1} {
##
# Wait for the header line, starting with "Point"
#
if {[lindex $line 0] != "Point"} {
continue
}
##
# Analyze header line and initialize headerInfo
#
set headerInfo {}
set idx 0
set PrimeTime(Path@$lineNumber:Attrs) {}
foreach vname [lrange $line 1 end] {
##
# Compute the attribute number (index in attributeNames and
# eventually extend the ordered list of all attribute names.
#
set attrNo [lsearch -exact $attributeNames $vname]
if {$attrNo == -1} {
set attrNo [llength $attributeNames]
lappend attributeNames $vname
}
set idx [string first $vname $line $idx]
lappend PrimeTime(Path@$lineNumber:Attrs) $vname
##
# Use char position at start of variable name as reference for
# the following lines that store the attribute values.
#
lappend headerInfo [list $vname $idx $attrNo]
incr idx
}
##
# Reorder headerInfo depending on attributeNames and add noop
# entries to headerInfo
#
proc cmpHeadInfo {a b} {
return [expr {[lindex $a 2] - [lindex $b 2]}]
}
lsort -command cmpHeadInfo $headerInfo
set i 0
set hI {}
foreach head $headerInfo {
set nextI [lindex $head 2]
while { $i < $nextI } {
##
# add noop entries into headerInfo
#
lappend hI [list {} {} $i]
incr i
}
lappend hI $head
incr i
}
set headerInfo $hI
##
# start path
#
set name Path@$lineNumber
set currentPath $name
lappend PrimeTime(allPaths) $currentPath
set PrimeTime($currentPath) {}
set PrimeTime($currentPath:start) $lineNumber
set state 2
continue
}
##
# State 0: outside a path.
#
if {$state == 0} {
##
# No path found within the first 100 lines.
#
if {([llength $PrimeTime(allPaths)] == 0) && ($lineNumber > 100)} {
zmessage print ERR "Unknown file format at $lineNumber"
continue
}
if {[scan $line %s firstWord] != 1} {
continue
}
##
# New path starts
#
if {($firstWord == "Startpoint:") || ($firstWord == "Endpoint:")} {
set state 1
}
continue
}
}
$PrimeTime(text) configure -state disabled
$PrimeTime(lineNo) configure -state disabled
PrimeTime:displayPaths
##
# Close the input file.
#
close $in
}
# -----------------------------------------------------------------------------
# displayPaths - Display all paths and hide paths which are not violated
# depending on $PrimeTime(violated)
# -----------------------------------------------------------------------------
#
proc PrimeTime:displayPaths {} {
global PrimeTime
$PrimeTime(pathList) delete 0 end
foreach path $PrimeTime(allPaths) {
if {($PrimeTime($path:slack) == "MET") && $PrimeTime(violated)} {
continue
}
$PrimeTime(pathList) insert end $path
}
$PrimeTime(pathList) selection set 0
PrimeTime:SelectPath $PrimeTime(pathList)
}
# -----------------------------------------------------------------------------
# initDB - Unset old values and initialize PrimeTime array.
# -----------------------------------------------------------------------------
#
proc PrimeTime:initDB {db} {
global PrimeTime
set PrimeTime(db) $db
set PrimeTime(dialog) .primetime
set PrimeTime(displayCap) 0
set PrimeTime(displayTrans) 0
set PrimeTime(displayIncr) 1
set PrimeTime(displayPath) 1
set PrimeTime(attrNames) {Cap Trans Incr Path}
set PrimeTime(displayEdges) 1
set PrimeTime(violated) 1
if {$db == {}} {
return
}
$db foreach top top {
set PrimeTime(top) $top
break
}
if {$PrimeTime(fileName) != {}} {
PrimeTime:showFile $PrimeTime(fileName)
}
}
# =============================================================================
# Call the initialization procedure.
# =============================================================================
#
PrimeTime:Init $argv
|