Changes for sky130_sram macros. Changed sram spice source from *.sp to *.lvs.sp because *.sp doesn’t have the correct memory cell parasitic devices. Changed l and w units from meters to micrometers. Reversed bus order in sram top subckt pins.
diff --git a/sky130/Makefile.in b/sky130/Makefile.in index 32bd1a0..fae19ff 100644 --- a/sky130/Makefile.in +++ b/sky130/Makefile.in
@@ -1331,7 +1331,7 @@ -lef %l/*/*.lef \ -lib %l/*/*.lib \ -gds %l/*/*.gds options=custom/scripts/gds_import_sram.tcl \ - -spice %l/*/*[0-9].sp filter=custom/scripts/sp_to_spice.py \ + -spice %l/*/*.lvs.sp filter=custom/scripts/sp_to_spice.py \ -verilog %l/*/*.v \ -library general sky130_sram_macros 2>&1 | tee -a ${SKY130A}_make.log
diff --git a/sky130/custom/scripts/sp_to_spice.py b/sky130/custom/scripts/sp_to_spice.py index bbcc641..1d0c91d 100755 --- a/sky130/custom/scripts/sp_to_spice.py +++ b/sky130/custom/scripts/sp_to_spice.py
@@ -10,6 +10,7 @@ # the value to "filter=" for the model install in the sky130 Makefile. import os +import re import sys def filter(inname): @@ -24,9 +25,69 @@ print('No such file ' + inname) return 1 - print('Renaming file ' + filename + ' to ' + newname) - os.rename(inname, outname) - return 0 + print('Converting file ' + filename + ' to ' + newname + ' by reversing buses and scaling l and w.') + # Read input + try: + with open(inname, 'r') as inFile: + stext = inFile.read() + slines = stext.splitlines() + except: + print('sp_to_spice.py: failed to open ' + inname + ' for reading.', file=sys.stderr) + return 1 + + fixedlines = [] + modified = False + base_rex = re.compile(r'([^\[]*).*') # regular expression for matching base signal + + for line in slines: + + # remove 'u' suffix from 'l' and 'w' parameters + newline = re.sub('([ \t][lL]=[0-9\.]*)u', r'\1', line) + newline = re.sub('([ \t][wW]=[0-9\.]*)u', r'\1', newline) + + # reverse bus indices - NOTE: Only works if all ports are on the subckt line + if newline.startswith(".subckt ") or newline.startswith(".SUBCKT "): + tokens = newline.split() + if tokens[1] == filebits[0]: # top subckt + bus_start = 2 + last_base = base_rex.match(tokens[2])[1] + i = 3 + while i < len(tokens): + base_match = base_rex.match(tokens[i]) # always matches one base net + if last_base != base_match[1]: + tokens[bus_start:i] = tokens[i-1:bus_start-1:-1] # reverse the bus indices + bus_start = i + last_base = base_match[1] + i += 1 + tokens[bus_start:i] = tokens[i-1:bus_start-1:-1] + newline = " ".join(tokens) + + if line != newline: + modified = True + + fixedlines.append(newline) + + # Write output + if outname == None: + for i in fixedlines: + print(i) + else: + # If the output is a symbolic link but no modifications have been made, + # then leave it alone. If it was modified, then remove the symbolic + # link before writing. + if os.path.islink(outname): + if not modified: + return 0 + else: + os.unlink(outname) + try: + with open(outname, 'w') as outFile: + for i in fixedlines: + print(i, file=outFile) + except: + print('sp_to_spice.py: failed to open ' + outname + ' for writing.', file=sys.stderr) + return 1 + if __name__ == '__main__':