blob: 1aaa0b561bfa83b581e2dfbf7e4e0348d8350e42 [file] [log] [blame]
Tim Edwardsb0cb0872021-08-27 09:43:55 -04001#!/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
11import os
12import re
13import sys
14
15newdevs = []
16newdevs.append('sky130_fd_pr__pnp_05v5_W3p40L3p40')
17
Tim Edwards8ae22612021-08-27 20:54:41 -040018options = []
19arguments = []
20for item in sys.argv[1:]:
21 if item.find('-', 0) == 0:
22 options.append(item[1:])
23 else:
24 arguments.append(item)
25
26if len(arguments) < 1:
27 print('Usage: fix_spice_includes.py <path_to_file> [-ef_format]')
Tim Edwardsb0cb0872021-08-27 09:43:55 -040028 sys.exit(1)
29
30else:
Tim Edwards8ae22612021-08-27 20:54:41 -040031 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 Edwardsb0cb0872021-08-27 09:43:55 -040037
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 Edwards8ae22612021-08-27 20:54:41 -040052 newline = '.include "../../libs.ref/' + libpath + newdev + '.model.spice"\n'
Tim Edwardsb0cb0872021-08-27 09:43:55 -040053 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