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 | ###############################################################################
# Copyright (c) 2014-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
# Get Symbol String for Built-In Shapes
# @section
# Miscellaneous Userware Examples
# @description
# Example code to extract the DEF string for the built-in symbol shapes.
# @files
# getSymbol.tcl
# @tag
# gui
###############################################################################
# =============================================================================
# GetBuiltinSymbolShape - Return the DEF string for the built-in symbol shape
# of the given function and the given number of ports.
# =============================================================================
#
proc GetBuiltinSymbolShape {inputPortList outputPortList function} {
##
# Create a new database.
#
set db [zdb new]
##
# Load a primitive with the given function.
#
$db load primitive $function $function
##
# Add all output ports to the just created primitive.
#
foreach output $outputPortList {
$db load port $output output
}
##
# Add all input ports to the just created primitive.
#
foreach input $inputPortList {
$db load port $input input
}
##
# Load a module and create an instance of the above primitive.
#
$db load module MODULE -top
$db load inst i1 $function
##
# Validate the created database (e.g. check that the created ports
# match the given function).
#
$db validate
##
# Inform the GUI that the database is ready (this command will render the
# toplevel schematic).
#
gui database changed $db
##
# Get the widget path to the Schem window of the main Visualizer and search
# for the def string of the symbol for the loaded primitive.
#
# Please note that this is 'search -def symbol' command is an undocumented
# API call.
#
set nlv [gui schem nlv]
set symDef [$nlv search -def symbol $function]
##
# Close the database to avoid memory leaks and update the GUI.
#
$db close
gui database changed {}
##
# Return the def string (the only element in the result list)
# of the symbol shape.
#
return [lindex $symDef 0]
}
# =============================================================================
# RemoveCellNameDisplayLocation - Remove the cell name display location:
# 'attrdsp @cell ...'
# from the given symbol string.
# =============================================================================
#
proc RemoveCellNameDisplayLocation {symDef} {
##
# Initialize the return value, a new symbol definition string.
#
set newSymDef {}
##
# Loop over all elements of the symbol definition.
#
for {set i 0} {$i < [llength $symDef]} {incr i} {
##
# Extract the current item from the symbol string.
#
set item [lindex $symDef $i]
##
# If this item is 'attrdsp' and the next item is '@cell' then
# skip all 5 elements.
#
if {($item == "attrdsp") &&
([lindex $symDef [expr {$i+ 1}]] == "@cell")} {
incr i 5
continue
}
##
# Add this item to the new symbol definition string.
#
lappend newSymDef $item
}
##
# Return the new symbol definition string.
#
return $newSymDef
}
##
# Example for 2 input AND.
#
set symDef [GetBuiltinSymbolShape [list A B] [list O] AND]
set symDef [RemoveCellNameDisplayLocation $symDef]
##
# Example for 3 input NOR.
#
set symDef [GetBuiltinSymbolShape [list i0 i1 i2] [list Y] NOR]
set symDef [RemoveCellNameDisplayLocation $symDef]
##
# Example that loops over all known primitive functions and tries to
# extract the symbol definition string for a 2-input primitive.
# This may fail: see doc/api/tprim.html for more details about the expected
# number of input and output ports for each primitive function.
#
foreach func [zdb primFuncList] {
if {[catch {GetBuiltinSymbolShape [list A B] [list O] $func} msg]} {
zmessage print ERR "Failed to create '$func': $msg"
}
}
|