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
###############################################################################
# Copyright (c) 2019-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
#       Path to Input
#   @namespace
#       PathToInput
#   @section
#       Miscellaneous Userware Examples
#   @description
#       Use the Cone Extraction API to find a path from a given start pin or
#       node to primary input.
#       If a cell contains only transistors then this cell is treated as a
#       leaf cell, because the Cone Extraction cannot trace through
#       transistors.
#   @configuration
#   @files
#       pathToInput.tcl
#   @example
#       demo/rtl/aquarius/aquarius.f
#   @cmdline
#       -F @example[0]
#       -userware @files[0]
#   @tag
#       zdb gui
###############################################################################


# =============================================================================
# Init - Initialize the plugin.
# =============================================================================
#
proc PathToInput:Init {} {
    ##
    # Customize the Popup Menu.
    #
    gui popup append "Show Path to Input" [list PathToInput:Show]

    ##
    # Add the option to configure the number of displayed paths.
    #
    gui plugin addConfig PathToInput numberOfPaths 1 number "Number of Paths"

    ##
    # Register a callback to fill a folded leafcell module.
    #
    gui cone customUnfoldAction [list PathToInput:_fillFoldedModule]

    ##
    # Register PathToInput:_identifyLeafCells to be run on database changes
    # and immediately if there's already is a database.
    #
    gui database runAndRegisterChangedCallback \
        [list PathToInput:_identifyLeafCells]
}


# =============================================================================
# Finit - Finalize the plugin.
#         This procedure is automatically called when deactivating the plugin.
# =============================================================================
#
proc PathToInput:Finit {} {
    ##
    # Clear all defined arcs.
    #
    zdb cone cleararc

    ##
    # Undo modifications of the GUI.
    #
    gui popup remove "Show Path to Input"

    ##
    # Remove the callback registration.
    #
    gui database removeChangedCallback "PathToInput:_identifyLeafCells"
}


# =============================================================================
# Show -
# =============================================================================
#
proc PathToInput:Show {oidList} {
    ##
    # Get the database and return if the database is empty.
    #
    set db [gui database get]
    if {($db == {}) || ($oidList == {})} {
        return
    }

    ##
    # Get the configuration option with the number of paths to calculate.
    #
    set numberOfPaths [gui plugin getConfigValue PathToInput numberOfPaths]

    ##
    # Run the Cone Extraction to get the requested number of paths from the
    # given start object.
    #
    set res [$db cone                       \
                -in                         \
                -checkArcs                  \
                -targetIO                   \
                -paths                      \
                -pathLimit $numberOfPaths   \
                -excludeFlaggedNet power    \
                -excludeFlaggedNet ground   \
                -excludeFlaggedNet negpower \
                [lindex $oidList 0]]

    ##
    # Process the result list.
    #
    set flaggedModules {}
    set foldList       {}
    set oidList        {}
    foreach path $res {
        foreach oid [lrange $path 1 end] {
            ##
            # Add every result object to the oidList to be loaded later into
            # the Cone window.
            #
            lappend oidList $oid

            ##
            # If this result object is a pin of a hierarchical instance flagged
            # as a leaf cell then add this module to the list of folded modules.
            #
            if {([$db oid type $oid] eq "pin") && [$db isModule $oid]} {
                set inst   [$db oid convertTo inst   $oid]
                set module [$db oid convertTo module $inst]
                if {[$db flag $module is leafcell]} {
                    lappend flaggedModules $module
                    lappend foldList       $inst
                }
            }
        }
    }

    ##
    # Add one object per folded module to trigger the visibility of the
    # fold/unfold button.
    #
    foreach module [lsort -unique $flaggedModules] {
        $db foreach inst $module inst {
            lappend oidList $inst
            break
        }
    }

    ##
    # Activate the Cone window.
    #
    gui window show Cone

    ##
    # Load all results into the Cone window.
    #
    gui cone load $oidList

    ##
    # Fold all leaf cells in the result.
    #
    gui cone fold $foldList
}


# -----------------------------------------------------------------------------
# _defineConeArcs - Define cone arcs for the given module.
# -----------------------------------------------------------------------------
#
proc PathToInput:_defineConeArcs {db module} {
    ##
    # Create a list of input and output ports at the given module.
    #
    set inputPortList  {}
    set outputPortList {}
    $db foreach port $module port {
        if {[$db directionOf $port] eq "input"} {
            lappend inputPortList [$db oid oname $port]
        } else {
            lappend outputPortList [$db oid oname $port]
        }
    }

    ##
    # Flag this module as a leaf cell.
    #
    $db flag $module set leafcell

    ##
    # Define cone arcs from every output port to all input ports.
    #
    foreach enterPort $outputPortList {
        zdb cone definearc [$db oid oname $module] $enterPort $inputPortList
    }
}


# -----------------------------------------------------------------------------
# _identifyLeafCells - Loop over all modules in the design and identify
#                      modules that contain only transistors to flag and
#                      define cone arcs.
# -----------------------------------------------------------------------------
#
proc PathToInput:_identifyLeafCells {db} {
    if {$db == {}} {
        return
    }

    ##
    # Clear all user-defined arcs.
    #
    zdb cone cleararc

    $db foreach module module {
        set isLeafCell true
        $db foreach inst $module inst {
            if {[$db isModule $inst]} {
                set isLeafCell false
                break
            }
        }

        if {$isLeafCell} {
            PathToInput:_defineConeArcs $db $module
        }
    }
}


# -----------------------------------------------------------------------------
# _fillFoldedModule - Fill a folded leafcell module.
# -----------------------------------------------------------------------------
#
proc PathToInput:_fillFoldedModule {inst} {
    set db [gui database get]
    set module [$db moduleOf $inst]
    if {[$db flag $module is leafcell]} {
        set pinList {}
        $db foreach net $module net {
            $db foreach pin $net pin {
                if {![$db flag $pin is hide]} {
                    lappend pinList $pin
                }
            }
        }
        gui cone append $pinList
    }
    gui cone unfold [list $inst]
}


# =============================================================================
# Call the initialization procedure.
# =============================================================================
#
PathToInput:Init