From 5352a235773514492962eb46a6d76d17442151c8 Mon Sep 17 00:00:00 2001 From: Tim Edwards Date: Wed, 15 Nov 2023 11:46:22 -0500 Subject: [PATCH] Updated the SPICE import routine in the toolkit so that it will correctly handle subcircuits that are used before they are defined, and will determine whether the imported spice does or does not contain a top level, and either return to the top level or any top level cell found in the netlist. --- VERSION | 2 +- tcltk/toolkit.tcl | 38 +++++++++++++++++++++++++++++++++++++- 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/VERSION b/VERSION index efcf0035..1376da5e 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -8.3.448 +8.3.449 diff --git a/tcltk/toolkit.tcl b/tcltk/toolkit.tcl index d5663fa1..9062bb91 100644 --- a/tcltk/toolkit.tcl +++ b/tcltk/toolkit.tcl @@ -375,7 +375,30 @@ proc magic::netlist_to_layout {netfile library} { set ignorekeys {.global .ic .option .end} - # Parse the file + # Parse the file once and find all subcircuits being defined, to + # catch any issues with subcircuits being used before they are + # defined. + set allsubs {} + foreach line $fdata { + set ftokens [split $line] + set keyword [string tolower [lindex $ftokens 0]] + if {$keyword == ".subckt"} { + set subname [lindex $ftokens 1] + lappend allsubs $subname + } + } + # Generate list of pre-existing top level cells + set existing [cellname list top] + # Pre-generate placeholders for all subcircuits. + set curtop [cellname list self] + + foreach subckt $allsubs { + puts stdout "Test: pre-generating subcircuit $subckt" + load $subckt -silent + } + load $curtop + + # Parse the file and process all lines foreach line $fdata { if {$incmd} { if {[regexp -nocase {^[ \t]*\.endc} $line]} { @@ -421,7 +444,20 @@ proc magic::netlist_to_layout {netfile library} { # Add in any top-level components (not in subcircuits) if {[llength $toplist] > 0} { + # Make sure the top level cell is loaded before adding top-level + # components. + load $curtop magic::generate_layout_add $topname "" $toplist $library + } else { + # There was no top level, so load the first new top cell that + # was generated by the import. + set allcells [cellname list top] + foreach cell $allcells { + if {[lsearch $existing $cell] < 0} { + load $cell + break + } + } } # resumeall