| #!/usr/bin/env python3 |
| |
| import re |
| |
| |
| header = """\ |
| * Copyright 2020 The SkyWater PDK Authors |
| * |
| * Licensed under the Apache License, Version 2.0 (the "License"); |
| * you may not use this file except in compliance with the License. |
| * You may obtain a copy of the License at |
| * |
| * https://www.apache.org/licenses/LICENSE-2.0 |
| * |
| * Unless required by applicable law or agreed to in writing, software |
| * distributed under the License is distributed on an "AS IS" BASIS, |
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| * See the License for the specific language governing permissions and |
| * limitations under the License. |
| * |
| * SPDX-License-Identifier: Apache-2.0 |
| |
| """ |
| |
| |
| RE_CONTINUES = re.compile('\\n\\+ ') |
| RE_SUBCKT = re.compile('.SUBCKT (?P<name>[^ ]*) (?P<ports>[^\\n]*)(?P<contents>.*?)\\n.ENDS(\\s+(?P=name))?\\n', re.I|re.DOTALL) |
| |
| |
| def change_names(new_lib, contents): |
| contents = RE_CONTINUES.sub('', contents) |
| output = [] |
| info = {} |
| |
| last_subckt_endpos = 0 |
| for subckt in RE_SUBCKT.finditer(contents): |
| between = contents[last_subckt_endpos:subckt.start(0)] |
| if between.strip(): |
| for l in between.splitlines(): |
| assert not l or l.strip().startswith('*'), l |
| if between: |
| output.append(between) |
| last_subckt_endpos = subckt.end(0) |
| |
| old_subcktname = subckt.group('name') |
| |
| subckt_ports = subckt.group('ports').split() |
| |
| subckt_data = subckt.group(0) |
| for p in subckt_ports: |
| subckt_data = re.sub(f'\\b{p}\\b', p.upper(), subckt_data) |
| |
| output.append(subckt_data) |
| |
| print() |
| print("="*75) |
| print(subckt_data) |
| print("-") |
| print(subckt_ports) |
| print("="*75) |
| |
| |
| output.append(contents[last_subckt_endpos:]) |
| print(output) |
| return "".join(output) |