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 | ###############################################################################
# Copyright (c) 2003-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.
# =============================================================================
# @userware
# Search for Interconnected Resistors
# @section
# Analyze the Loaded Database
# @description
# Search the loaded database to extract lists of interconnected
# resistors.
# @files
# cust1/patternSearch.tcl
# @tag
# zdb gui
###############################################################################
# =============================================================================
# This file implements (1) Single Element Search and (2) Connectivity Search
# to extract lists of interconnected resistors. All non-resistors are
# ignored in these searches. Folded hierarchy is supported. The result
# is printed to a file.
#
# Assumptions:
# - the resistors who's name match startPattern are called jj-resistors.
# - the resistors who's name match searchPattern are called kk-resistors.
#
# (1) Single Element Search
# -=-=-=-=-=-=-=-=-=-=-=-=-
#
# For all jj-resistors in the design data: search the connected kk-resistors
# to figure out if it connects to another jj-resistor within searchMaxdep
# steps; if NOT, print the jj-resistor. The result is a list of jj-resistors
# (one per line) that are not connected to another jj-resistor within
# searchMaxdep steps.
#
# (2) Connectivity Search
# -=-=-=-=-=-=-=-=-=-=-=-
#
# For all jj-resistors in the design data, print one line to the result
# file with several fields. The first field is the jj-resistor and
# the following fields are the connecting kk-resistors.
#
#
# #############################################################################
# This file contains:
#
# matchPath - creates dialog windows to set following global variables.
# If the user press OK, then call findRes.
# Global variables:
# searchMode - 1 or 2, Single/Connectivity Search
# startPattern - for start-resistor name (jj)
# searchPattern - for connected resistor name (kk)
# searchMaxdep - maximum search depth
# saveResult - name of result file
#
# findRes - calls findStart to get a list of start-resistors and then
# for each start-resistor pin, call nextRes to search the
# connected resistors.
# In searchMode 1, print start-resistor only, if nextRes
# could not find another connecting start-resistor.
# In searchMode 2, print each start-resistor before
# nextRes prints connected resistors.
#
# findStart - recursively traverse the design hierarchy tree and return
# all start-resistors (name match startPattern) in global
# startResistorList.
#
# nextRes - recursively traverse the connectivity (max searchMaxdep steps)
# but only traverse resistors whose name match searchPattern.
# Flag visited resistor pins to avoid endless loops.
# In searchMode 1, return 1/0 to indicate if we hit a
# start-resistor within max searchMaxdep steps.
# In searchMode 2, print each traversed resistor.
#
# nameOf - return the resistor name to be printed to the result file.
#
#
# =============================================================================
# Initialize global variables
# =============================================================================
#
foreach {var val} {
searchMode 2
startPattern "jj"
searchPattern "kk, nn"
searchMaxdep 100
saveResult result.out
} {
#checker -scope block exclude warnVarRef
if {[info exists $var]} {
continue
}
set $var $val
}
# -----------------------------------------------------------------------------
# matchPath - Open a popup window with 3 entry fields:
# start pattern, search pattern and output file.
# -----------------------------------------------------------------------------
#
proc matchPath {} {
if {[winfo exists .pmp]} {
raise .pmp
return
}
toplevel .pmp
wm title .pmp "Pattern Search"
foreach {
w
t
c
} {
1
"Single Element Search"
"set searchMaxdep 1; set searchPattern *"
2
"Connectivity Search"
"set searchMaxdep 100; set searchPattern {kk, nn}"
} {
ttk::radiobutton .pmp.search$w -text $t -variable searchMode -value $w \
-command $c
}
label .pmp.stl -text "Start Pattern: " -justify right
ttk::entry .pmp.ste -textvariable startPattern
label .pmp.sel -text "List of Search Pattern: "
ttk::entry .pmp.see -textvariable searchPattern
label .pmp.mal -text "Max Search Depth: "
ttk::entry .pmp.mae -textvariable searchMaxdep -width 10
label .pmp.srl -text "Save Result As: "
ttk::entry .pmp.sre -textvariable saveResult
ttk::button .pmp.srb -text "Browse" -command dlgBrowseSaveFile
ttk::frame .pmp.f
ttk::button .pmp.f.cancel -text "Cancel" -command "destroy .pmp"
ttk::button .pmp.f.ok -text "OK" -command "destroy .pmp; findRes"
bind .pmp.sre <Key-Return> ".pmp.f.ok invoke"
grid .pmp.f.cancel -row 0 -column 0 -padx 5 -pady 5
grid .pmp.f.ok -row 0 -column 1 -padx 5 -pady 5
grid .pmp.search1 -row 0 -column 1 -pady 1 -sticky w
grid .pmp.search2 -row 1 -column 1 -pady 1 -sticky w
grid .pmp.stl -row 2 -column 0 -padx 5 -pady 1 -sticky e
grid .pmp.ste -row 2 -column 1 -padx 5 -pady 1 -sticky we
grid .pmp.sel -row 3 -column 0 -padx 5 -pady 1 -sticky e
grid .pmp.see -row 3 -column 1 -padx 5 -pady 1 -sticky we
grid .pmp.mal -row 4 -column 0 -padx 5 -pady 1 -sticky e
grid .pmp.mae -row 4 -column 1 -padx 5 -pady 1 -sticky w
grid .pmp.srl -row 5 -column 0 -padx 5 -pady 1 -sticky e
grid .pmp.sre -row 5 -column 1 -padx 5 -pady 1 -sticky we
grid .pmp.srb -row 5 -column 2 -padx 5 -pady 1 -sticky we
grid columnconfigure .pmp 1 -weight 1
grid .pmp.f -row 6 -column 0 -columnspan 3 -sticky s
}
# -----------------------------------------------------------------------------
# dlgBrowseSaveFile -
# -----------------------------------------------------------------------------
#
proc dlgBrowseSaveFile {} {
global saveResult
set f [gui window fileDialog saveFile "Save Result" {} .pmp]
if {$f != ""} {
set saveResult $f
}
}
# -----------------------------------------------------------------------------
# findRes - Find resistors with pattern $startPattern and search for resistors
# matching one of the $searchPattern.
# -----------------------------------------------------------------------------
#
proc findRes {} {
global saveResult startResistorList startPattern searchMode
if {$saveResult == "" } {
zmessage print ERR "No output file."
return
}
set out [open $saveResult w]
set dbg [open $saveResult.dbg w]
##
# Get a pointer to the database.
#
set db [gui database get]
##
# Call findStart for each top module.
#
set startResistorList {}
$db foreach top mod {findStart $db $mod $out $dbg}
set len [llength $startResistorList]
gui console print "processing $len \"$startPattern\" resistors ...."
##
# Report each start-resistor - followed by all connected
# resistors as found by "nextRes".
#
zprogress begin
zprogress push "Search" 1.0
set progBar 1
set progressMax [expr {[llength $startResistorList] * 2}]
set progressCur 0
foreach inst $startResistorList {
if {$searchMode != 1} {
puts -nonewline $out "[nameOf $db $inst]"
puts $dbg [list $inst]
}
##
# Delete the flat structure to clear all "white" flags,
# then call "nextRes" for both pins to find all connected resistors.
#
$db flat free
set stop 0
$db foreach pin $inst pin {
##
# flag both pins first - to avoid nextRes from searching this inst.
#
$db flatflag $pin set white
}
set hit 0
$db foreach pin $inst pin {
incr progressCur
if {[zprogress update "$pin" $progressCur $progressMax]} {
break
}
$db flatflag $pin set white
if {$searchMode == 1} {
set hit [nextRes $db $out $dbg $pin 0]
if {$hit} {
break
}
} else {
nextRes $db $out $dbg $pin 0
}
}
if {$searchMode == 1} {
if {!$hit} {
puts $out "[nameOf $db $inst]"
puts $dbg [list $inst]
}
} else {
puts $out ""
}
flush $out
if {$stop} {
break
}
}
zprogress pop
zprogress end
close $out
close $dbg
}
# -----------------------------------------------------------------------------
# findStart - The findStart procedure actually traverses the design hierarchy
# tree by recursively calling itself for each down-module.
# It stores all start-resistors in startResistorList.
# -----------------------------------------------------------------------------
#
proc findStart {db mod out dbg} {
global startResistorList startPattern
##
# translate global $startPattern into start_pattern
#
set start_pattern *$startPattern*
$db foreach inst $mod inst {
##
# dive down into sub-modules
#
if {[$db isModule $inst]} {
set down [$db moduleOf $inst]
findStart $db $down $out $dbg
continue
}
##
# Skip all elements except resistors.
#
set func [$db primFuncOf $inst]
if { $func != "RES" } {
continue
}
if {[string match $start_pattern [$db oid oname $inst]]} {
lappend startResistorList $inst
}
}
}
# -----------------------------------------------------------------------------
# nextRes - Investigate the next $searchPattern resistor.
# -----------------------------------------------------------------------------
#
proc nextRes {db out dbg pin level} {
global searchMaxdep startPattern searchPattern searchMode
if {$level > $searchMaxdep} {
return 0
}
##
# translate global $startPattern into start_pattern
# and global $searchPattern into search_patternList
#
set start_pattern *$startPattern*
set search_patternList {}
foreach pattern [split $searchPattern ,] {
set pattern [string trim $pattern]
lappend search_patternList "*$pattern*"
}
if {[llength $search_patternList] == 0} {
lappend search_patternList *
}
set pinList {}
##
# Get the net connected to this pin.
#
set net [$db connectedNet $pin]
if {[$db isPgNet $net]} {
return 0
}
##
# Loop over all pins of the net.
#
$db flat foreach pin $net p {
##
# Do not investigate already visited pins
# (indicated by the white flag).
#
if {[$db flatflag $p is white]} {
continue
}
$db flatflag $p set white
##
# Skip all elements except resistors.
#
if {[$db oid type $p] != "pin"} {
continue
}
set func [$db primFuncOf [$db primitiveOf $p]]
if {$func != "RES"} {
continue
}
set oname [$db oid oname $p]
if {[string match $start_pattern $oname]} {
if {$searchMode == 1} {
return 1
}
}
##
# If the next resistor ($p) matches a $searchPattern, then
# store $p in pinList.
#
foreach pattern $search_patternList {
if {[string match $pattern $oname]} {
lappend pinList $p
break
}
}
}
##
# Report each resistor from $pinList and recursively call the nextRes
# procedure.
#
incr level
##
# sort pinList ?? - remove duplicates ??
#
foreach p [lsort $pinList] {
##
# compute opposite pin
#
set opin [$db tdevice oppositePin $p]
if {$searchMode == 1} {
##
# recursively call nextRes with opposite pin
#
$db flatflag $opin set white
set hit [nextRes $db $out $dbg $opin $level]
if {$hit} {
return $hit
}
} else {
##
# Report resistor at $opin
#
puts -nonewline $out "\t[nameOf $db $opin]"
puts $dbg "\t[list $opin]"
##
# recursively call nextRes with opposite pin
#
$db flatflag $opin set white
nextRes $db $out $dbg $opin $level
}
}
return 0
}
# -----------------------------------------------------------------------------
# nameOf - This procedure converts an inst or pin OID into a printable
# inst name.
# -----------------------------------------------------------------------------
#
proc nameOf {db oid} {
set p [$db oid path $oid]
lappend p [$db oid oname $oid]
return [join $p [$db hiersep]]
}
|