blob: e91bc210faf90496ae08161f483fb7c3846cb3aa [file] [log] [blame]
Tim Edwards88bd42e2020-12-18 15:29:48 -05001#!/usr/bin/env python3
2#
3# text2m5 ---
4#
5# This script changes magic layouts from the sky130_ml_xx_hd library
6# by recasting the layer used from metal1 to metal5, and adding a
7# scalefactor of 12 so that the characters are sized to avoid DRC
8# errors on metal5.
9#
10# This script is a filter to be run by setting the name of this script as
11# the value to "filter=" for the library install in the sky130 Makefile.
12
13import re
14import os
15import sys
16
17def filter(inname, outname):
18
19 # Read input
20 try:
21 with open(inname, 'r') as inFile:
22 spitext = inFile.read()
23 spilines = spitext.splitlines()
24 except:
Tim Edwardsb8c95cb2021-12-07 14:39:07 -050025 print('text2m5.py: failed to open ' + inname + ' for reading.', file=sys.stderr)
Tim Edwards88bd42e2020-12-18 15:29:48 -050026 return 1
27
28 # Process input with regexp
29
30 fixedlines = []
31 modified = False
32
33 for line in spilines:
34
35 # These substitutions are for files originating from cells/*/*.spice
36 fixedline = re.sub('<< metal1 >>', '<< metal5 >>', line)
37 fixedline = re.sub('tech sky130A', 'tech sky130A\nmagscale 12 1', fixedline)
38
39 fixedlines.append(fixedline)
40 if fixedline != line:
41 modified = True
42
43 # Write output
44 if outname == None:
45 for i in fixedlines:
46 print(i)
47 else:
48 # If the output is a symbolic link but no modifications have been made,
49 # then leave it alone. If it was modified, then remove the symbolic
50 # link before writing.
51 if os.path.islink(outname):
52 if not modified:
53 return 0
54 else:
55 os.unlink(outname)
56 try:
57 with open(outname, 'w') as outFile:
58 for i in fixedlines:
59 print(i, file=outFile)
60 except:
61 print('text2m5.py: failed to open ' + outname + ' for writing.', file=sys.stderr)
62 return 1
63
64
65if __name__ == '__main__':
66
67 # This script expects to get one or two arguments. One argument is
68 # mandatory and is the input file. The other argument is optional and
69 # is the output file. The output file and input file may be the same
70 # name, in which case the original input is overwritten.
71
72 options = []
73 arguments = []
74 for item in sys.argv[1:]:
75 if item.find('-', 0) == 0:
76 options.append(item[1:])
77 else:
78 arguments.append(item)
79
80 if len(arguments) > 0:
81 infilename = arguments[0]
82
83 if len(arguments) > 1:
84 outfilename = arguments[1]
85 else:
86 outfilename = None
87
88 result = filter(infilename, outfilename)
89 sys.exit(result)