Download chips/openroad_flow_scripts/flow/util/generate_klayout_tech.py from STAR-future/Trinity-SciData: direct link, hf CLI and curl.
- Browser
- Download file 4.03 kB
-
https://huggingface.co/datasets/STAR-future/Trinity-SciData/resolve/main/chips/openroad_flow_scripts/flow/util/generate_klayout_tech.py
- Command line
-
hf download hf://datasets/STAR-future/Trinity-SciData/chips/openroad_flow_scripts/flow/util/generate_klayout_tech.py
-
curl -L -o generate_klayout_tech.py https://huggingface.co/datasets/STAR-future/Trinity-SciData/resolve/main/chips/openroad_flow_scripts/flow/util/generate_klayout_tech.py
4.03 kB
| """Generate klayout .lyt tech file from platform template. | |
| Replaces <lef-files> and <map-file> elements with actual paths. | |
| No klayout dependency - pure XML manipulation using stdlib. | |
| """ | |
| import argparse | |
| import os | |
| import re | |
| def replace_lef_files(content, lef_files): | |
| """Replace the <lef-files>...</lef-files> element(s) with new ones. | |
| The original .lyt template has a single <lef-files> element inside | |
| <reader-options><lefdef>. We replace it with one <lef-files> element | |
| per LEF file, matching the existing sed-based behavior. | |
| """ | |
| replacement = "".join("<lef-files>{}</lef-files>".format(f) for f in lef_files) | |
| return re.sub(r"<lef-files>.*?</lef-files>", replacement, content) | |
| def replace_map_files(content, map_files): | |
| """Replace the <map-file>...</map-file> or <map-file/> element(s) with new ones.""" | |
| if not map_files: | |
| return content | |
| replacement = "".join("<map-file>{}</map-file>".format(f) for f in map_files) | |
| content = re.sub(r"<map-file>.*?</map-file>", replacement, content) | |
| content = re.sub(r"<map-file\s*/>", replacement, content) | |
| return content | |
| def blackbox_lefs(blackboxes): | |
| """The LEF of every macro AUTO_MEMORIES' blackboxes.txt lists. | |
| blackboxes.txt has a `<module> <area>` line per macro, and | |
| do-auto-memories writes <module>.lef beside it. | |
| """ | |
| directory = os.path.dirname(blackboxes) | |
| with open(blackboxes, encoding="utf-8") as f: | |
| return [ | |
| os.path.join(directory, line.split()[0] + ".lef") | |
| for line in f | |
| if line.strip() | |
| ] | |
| def generate_klayout_tech(template_lyt, output_lyt, lef_files, map_files=None): | |
| """Generate a klayout .lyt file from a platform template. | |
| Args: | |
| template_lyt: Path to the platform .lyt template file. | |
| output_lyt: Path to write the generated .lyt file. | |
| lef_files: List of LEF file paths to include. | |
| map_files: List of map file paths. | |
| """ | |
| with open(template_lyt, "r") as f: | |
| content = f.read() | |
| # Write absolute (not relative, not realpath'd) LEF paths into the LYT. | |
| # Klayout's Layout.read(def, layout_options) follows the symlinked input | |
| # DEF to its realpath at the bare execroot and resolves relative | |
| # <lef-files> entries from there. Sibling intermediates like | |
| # objects/klayout_tech.lef don't exist at the bare execroot during | |
| # action execution -- they're only at the per-action sandbox -- so | |
| # resolution fails with errno=2. Plain abspath (NOT realpath, which | |
| # would chase Bazel input-file symlinks back out to the bare execroot) | |
| # keeps klayout pointed at the in-sandbox file. | |
| resolved_lefs = [os.path.abspath(f) for f in lef_files] | |
| content = replace_lef_files(content, resolved_lefs) | |
| resolved_maps = [os.path.abspath(f) for f in (map_files or [])] | |
| content = replace_map_files(content, resolved_maps) | |
| with open(output_lyt, "w") as f: | |
| f.write(content) | |
| def main(): | |
| parser = argparse.ArgumentParser( | |
| description="Generate klayout .lyt tech file from platform template." | |
| ) | |
| parser.add_argument( | |
| "--template", required=True, help="Path to platform .lyt template" | |
| ) | |
| parser.add_argument("--output", required=True, help="Output .lyt file path") | |
| parser.add_argument( | |
| "--lef-files", nargs="*", default=[], help="LEF files to include" | |
| ) | |
| parser.add_argument( | |
| "--map-files", nargs="*", default=[], help="Map files to include" | |
| ) | |
| parser.add_argument( | |
| "--blackboxes", | |
| help="AUTO_MEMORIES' blackboxes.txt; the LEF of each macro it lists" | |
| " is included after --lef-files", | |
| ) | |
| args = parser.parse_args() | |
| lef_files = list(args.lef_files) | |
| if args.blackboxes: | |
| lef_files += blackbox_lefs(args.blackboxes) | |
| generate_klayout_tech( | |
| template_lyt=args.template, | |
| output_lyt=args.output, | |
| lef_files=lef_files, | |
| map_files=args.map_files, | |
| ) | |
| if __name__ == "__main__": | |
| main() | |