blob: 4b5d700b3919c1fa390dd936d3e63f8c266dd106 [file] [log] [blame]
#!/usr/bin/env python3
# Copyright 2020 Efabless Corporation
#
# 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
#
# http://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.
import re
import argparse
EXAMPLE_INPUT = """
li1 X 0.23 0.46
li1 Y 0.17 0.34
met1 X 0.17 0.34
met1 Y 0.17 0.34
met2 X 0.23 0.46
met2 Y 0.23 0.46
met3 X 0.34 0.68
met3 Y 0.34 0.68
met4 X 0.46 0.92
met4 Y 0.46 0.92
met5 X 1.70 3.40
met5 Y 1.70 3.40
"""
def old_to_new_tracks(old_tracks: str) -> str:
"""
>>> old_to_new_tracks(EXAMPLE_INPUT)
'make_tracks li1 -x_offset 0.23 -x_pitch 0.46 -y_offset 0.17 -y_pitch 0.34\\nmake_tracks met1 -x_offset 0.17 -x_pitch 0.34 -y_offset 0.17 -y_pitch 0.34\\nmake_tracks met2 -x_offset 0.23 -x_pitch 0.46 -y_offset 0.23 -y_pitch 0.46\\nmake_tracks met3 -x_offset 0.34 -x_pitch 0.68 -y_offset 0.34 -y_pitch 0.68\\nmake_tracks met4 -x_offset 0.46 -x_pitch 0.92 -y_offset 0.46 -y_pitch 0.92\\nmake_tracks met5 -x_offset 1.70 -x_pitch 3.40 -y_offset 1.70 -y_pitch 3.40\\n'
"""
old_tracks_lines = old_tracks.split("\n")
layers = {}
for line in old_tracks_lines:
if re.match(r"^\s*$", line):
continue
layer, cardinal, offset, pitch = re.split(r"\s+", line)
layers[layer] = layers.get(layer) or {}
layers[layer][cardinal] = (offset, pitch)
final_str = ""
for layer, data in layers.items():
x_offset, x_pitch = data["X"]
y_offset, y_pitch = data["Y"]
final_str += f"make_tracks {layer} -x_offset {x_offset} -x_pitch {x_pitch} -y_offset {y_offset} -y_pitch {y_pitch}\n"
return final_str
if __name__ == "__main__":
parser = argparse.ArgumentParser(
description="Converts an old tracks.info file to a new .tracks file as dictated by OpenROAD."
)
parser.add_argument("--input_file", "-i", required=True, help="input tracks.info")
parser.add_argument(
"--output_file", "-o", required=True, help="output .tracks file"
)
args = parser.parse_args()
tracks_info_str = open(args.input_file).read()
with open(args.output_file, "w") as f:
f.write(old_to_new_tracks(tracks_info_str))