Tim Edwards | 282d954 | 2020-07-15 17:52:08 -0400 | [diff] [blame] | 1 | #!/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 | |
| 7 | import os |
| 8 | import sys |
| 9 | import re |
| 10 | |
| 11 | if len(sys.argv) < 3: |
| 12 | print("Usage: vpb_vnb_convert.py <lef_file_in> <lef_file_out>") |
| 13 | sys.exit(1) |
| 14 | |
| 15 | lef_file_in = sys.argv[1] |
| 16 | lef_file_out = sys.argv[2] |
| 17 | |
| 18 | print("Input: " + lef_file_in) |
| 19 | print("Output: " + lef_file_out) |
| 20 | |
| 21 | with open(lef_file_in, 'r') as ifile: |
| 22 | leflines = ifile.read().splitlines() |
| 23 | |
| 24 | layrex = re.compile('[ \t]*LAYER[ \t]+([^ \t]+)[ \t]+;') |
| 25 | pinrex = re.compile('[ \t]*PIN[ \t]+([^ \t\n]+)') |
| 26 | endrex = re.compile('[ \t]*END[ \t]+([^ \t\n]+)') |
| 27 | subrex = re.compile('([ \t]*LAYER[ \t]+)([^ \t]+)([ \t]+;)') |
| 28 | |
| 29 | vpbpin = False |
| 30 | vnbpin = False |
| 31 | |
| 32 | linesout = [] |
| 33 | |
| 34 | for 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 | |
| 62 | with open(lef_file_out, 'w') as ofile: |
| 63 | for line in linesout: |
| 64 | print(line, file=ofile) |