Tim Edwards | b0cb087 | 2021-08-27 09:43:55 -0400 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
| 2 | # |
| 3 | #-------------------------------------------------------------------- |
| 4 | # fix_spice_includes.py--- |
| 5 | # |
| 6 | # This script patches the "all.spice" file to add include statements |
| 7 | # for several devices that got left out (namely the PNP and NPN |
| 8 | # devices). |
| 9 | #-------------------------------------------------------------------- |
| 10 | |
| 11 | import os |
| 12 | import re |
| 13 | import sys |
| 14 | |
| 15 | newdevs = [] |
| 16 | newdevs.append('sky130_fd_pr__pnp_05v5_W3p40L3p40') |
| 17 | |
Tim Edwards | 8ae2261 | 2021-08-27 20:54:41 -0400 | [diff] [blame] | 18 | options = [] |
| 19 | arguments = [] |
| 20 | for item in sys.argv[1:]: |
| 21 | if item.find('-', 0) == 0: |
| 22 | options.append(item[1:]) |
| 23 | else: |
| 24 | arguments.append(item) |
| 25 | |
| 26 | if len(arguments) < 1: |
| 27 | print('Usage: fix_spice_includes.py <path_to_file> [-ef_format]') |
Tim Edwards | b0cb087 | 2021-08-27 09:43:55 -0400 | [diff] [blame] | 28 | sys.exit(1) |
| 29 | |
| 30 | else: |
Tim Edwards | 8ae2261 | 2021-08-27 20:54:41 -0400 | [diff] [blame] | 31 | infile_name = arguments[0] |
| 32 | |
| 33 | libpath = 'sky130_fd_pr/spice/' |
| 34 | if len(options) > 0: |
| 35 | if options[0] == 'ef_format': |
| 36 | libpath = 'spi/sky130_fd_pr/' |
Tim Edwards | b0cb087 | 2021-08-27 09:43:55 -0400 | [diff] [blame] | 37 | |
| 38 | filepath = os.path.split(infile_name)[0] |
| 39 | outfile_name = os.path.join(filepath, 'temp') |
| 40 | |
| 41 | infile = open(infile_name, 'r') |
| 42 | outfile = open(outfile_name, 'w') |
| 43 | |
| 44 | line_number = 0 |
| 45 | replaced_something = False |
| 46 | for line in infile: |
| 47 | line_number += 1 |
| 48 | |
| 49 | if 'pnp_05v5' in line: |
| 50 | # Insert these additional lines |
| 51 | for newdev in newdevs: |
Tim Edwards | 8ae2261 | 2021-08-27 20:54:41 -0400 | [diff] [blame] | 52 | newline = '.include "../../libs.ref/' + libpath + newdev + '.model.spice"\n' |
Tim Edwards | b0cb087 | 2021-08-27 09:43:55 -0400 | [diff] [blame] | 53 | outfile.write(newline) |
| 54 | replaced_something = True |
| 55 | |
| 56 | newline = line |
| 57 | outfile.write(newline) |
| 58 | |
| 59 | infile.close() |
| 60 | outfile.close() |
| 61 | if replaced_something: |
| 62 | print("Something was replaced in '{}'".format(infile_name)) |
| 63 | os.rename(outfile_name, infile_name) |
| 64 | else: |
| 65 | print("Nothing was replaced in '{}'.".format(infile_name)) |
| 66 | os.remove(outfile_name) |
| 67 | |