blob: db781e3244f233c438310acd9a51ad2c3d9b2055 [file] [log] [blame]
Tim Edwards282d9542020-07-15 17:52:08 -04001#!/usr/bin/env python3
2#
3# Convert VNB and VPB layers in a LEF file from "li1" or "met1" to
4# "pwell" and "nwell" masterslice layers, as they should be.
5#
6
7import os
8import sys
9import re
10
11if len(sys.argv) < 3:
12 print("Usage: vpb_vnb_convert.py <lef_file_in> <lef_file_out>")
13 sys.exit(1)
14
15lef_file_in = sys.argv[1]
16lef_file_out = sys.argv[2]
17
18print("Input: " + lef_file_in)
19print("Output: " + lef_file_out)
20
21with open(lef_file_in, 'r') as ifile:
22 leflines = ifile.read().splitlines()
23
24layrex = re.compile('[ \t]*LAYER[ \t]+([^ \t]+)[ \t]+;')
25pinrex = re.compile('[ \t]*PIN[ \t]+([^ \t\n]+)')
26endrex = re.compile('[ \t]*END[ \t]+([^ \t\n]+)')
27subrex = re.compile('([ \t]*LAYER[ \t]+)([^ \t]+)([ \t]+;)')
28
29vpbpin = False
30vnbpin = False
31
32linesout = []
33
34for line in leflines:
35 lineout = line
36
37 lmatch = layrex.match(line)
38 pmatch = pinrex.match(line)
39 ematch = endrex.match(line)
40
41 if pmatch:
42 pinname = pmatch.group(1)
43
44 if pinname == 'VNB':
45 vnbpin = True
46 elif pinname == 'VPB':
47 vpbpin = True
48
49 elif ematch:
50 pinname = ''
51 vnbpin = False
52 vpbpin = False
53
54 elif lmatch:
55 if vpbpin:
56 lineout = subrex.sub(r'\1nwell\3', line)
57 elif vnbpin:
58 lineout = subrex.sub(r'\1pwell\3', line)
59
60 linesout.append(lineout)
61
62with open(lef_file_out, 'w') as ofile:
63 for line in linesout:
64 print(line, file=ofile)