summaryrefslogtreecommitdiff
path: root/scripts/spi2xspice.py.in
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/spi2xspice.py.in')
-rwxr-xr-xscripts/spi2xspice.py.in32
1 files changed, 24 insertions, 8 deletions
diff --git a/scripts/spi2xspice.py.in b/scripts/spi2xspice.py.in
index ac46f37..4b8105f 100755
--- a/scripts/spi2xspice.py.in
+++ b/scripts/spi2xspice.py.in
@@ -140,13 +140,21 @@ def write_models(cellsused, celldefs, ofile, timing):
psubs = psubs.replace(bchar, bval)
# Handle the awkward syntax where, e.g., (A B) means (A & B)
- psubs = imprex.sub('\g<1>&\g<2>', psubs)
+ # Must be done in a loop because re.sub does not work on
+ # overlapping matches.
+
+ while True:
+ psubbed = imprex.sub('\g<1>&\g<2>', psubs)
+ if psubbed == psubs:
+ break
+ psubs = psubbed
try:
tval = eval('(' + psubs + ')&1')
except (SyntaxError, NameError):
tabstr = ''
print("Could not evaluate function " + cellrec['function'][k])
+ print("(Evaluated as " + psubs + ")")
break
if tval:
@@ -272,7 +280,9 @@ def read_spice(filein, fileout, celldefs, debug, modelfile, timing):
if xmatch:
# Replace subcircuit call with xspice call
instname = xmatch.group(1)
- conns = xmatch.group(2).split()
+ # NOTE: Parsing for common CDLisms like '/' before cellname and
+ # parameter passing to the instance.
+ conns = list(item for item in xmatch.group(2).split() if '=' not in item and item != '/')
pins = conns[0:-1]
cellname = conns[-1]
@@ -485,9 +495,12 @@ def read_spice(filein, fileout, celldefs, debug, modelfile, timing):
i = cellrec['spicepins'].index(subpin)
# "pins[i]" is the name of the connecting net
# on the top level
- inlist.append(pins[i])
- if pins[i] in pindefs:
- pindefs[pins[i]] = 'input'
+ if len(pins) > i:
+ inlist.append(pins[i])
+ if pins[i] in pindefs:
+ pindefs[pins[i]] = 'input'
+ else:
+ print('Pin ' + subpin + ' of subckt ' + cellname + ' does not have a connecting net', file=sys.stderr)
if 'outputs' in cellrec:
for subpin in cellrec['outputs']:
@@ -495,9 +508,12 @@ def read_spice(filein, fileout, celldefs, debug, modelfile, timing):
i = cellrec['spicepins'].index(subpin)
# "pins[i]" is the name of the connecting net
# on the top level
- outlist.append(pins[i])
- if pins[i] in pindefs:
- pindefs[pins[i]] = 'output'
+ if len(pins) > i:
+ outlist.append(pins[i])
+ if pins[i] in pindefs:
+ pindefs[pins[i]] = 'output'
+ else:
+ print('Pin ' + subpin + ' of subckt ' + cellname + ' does not have a connecting net', file=sys.stderr)
intext = ' '.join(inlist)
outtext = ' '.join(outlist)