|
| 1 | +import json |
| 2 | +import sys |
| 3 | +from pathlib import Path |
| 4 | + |
| 5 | +from utils.class_process import Process |
| 6 | +from utils.memory_config import MemoryConfig |
| 7 | +from utils.memory_factory import MemoryFactory |
| 8 | +from utils.timing_data import TimingData |
| 9 | +from utils.ram_liberty_exporter import RAMLibertyExporter |
| 10 | +from utils.lef_exporter import LefExporter |
| 11 | + |
| 12 | +ASAP7_PROCESS_CONFIG = { |
| 13 | + "tech_nm": 7, |
| 14 | + "voltage": 0.7, |
| 15 | + "metal_prefix": "M", |
| 16 | + "metal_layer": "M4", |
| 17 | + "pin_width_nm": 24, |
| 18 | + "pin_pitch_nm": 48, |
| 19 | + "metal_track_pitch_nm": 48, |
| 20 | + "manufacturing_grid_nm": 1, |
| 21 | + "contacted_poly_pitch_nm": 54, |
| 22 | + "fin_pitch_nm": 27, |
| 23 | + "column_mux_factor": 1, |
| 24 | + "snap_width_nm": 190, |
| 25 | + "snap_height_nm": 1400, |
| 26 | +} |
| 27 | + |
| 28 | +ASAP7_TIMING_CONFIG = { |
| 29 | + "cycle_time": 1.0, |
| 30 | + "access_time": 0.5, |
| 31 | + "setup_time": 0.1, |
| 32 | + "hold_time": 0.05, |
| 33 | + "leakage": 0.001, |
| 34 | +} |
| 35 | + |
| 36 | + |
| 37 | +def run_orfs_asap7(platform: str, out_dir: Path, json_path: Path): |
| 38 | + if platform != "asap7": |
| 39 | + sys.stderr.write(f"FakeRAM2.0 orfs_asap7: unsupported platform {platform}\n") |
| 40 | + return 1 |
| 41 | + |
| 42 | + try: |
| 43 | + data = json.loads(json_path.read_text()) |
| 44 | + memories = data.get("memories", []) |
| 45 | + except Exception as e: |
| 46 | + sys.stderr.write(f"FakeRAM2.0 orfs_asap7: failed to read {json_path}: {e}\n") |
| 47 | + return 1 |
| 48 | + |
| 49 | + out_dir.mkdir(parents=True, exist_ok=True) |
| 50 | + converted = sorted( |
| 51 | + (m for m in memories if m.get("idiomatic")), key=lambda m: m["name"] |
| 52 | + ) |
| 53 | + |
| 54 | + process = Process(ASAP7_PROCESS_CONFIG) |
| 55 | + timing_data = TimingData(ASAP7_TIMING_CONFIG) |
| 56 | + |
| 57 | + for m in converted: |
| 58 | + name = m["name"] |
| 59 | + bits = m.get("bits", 32) |
| 60 | + rows = m.get("rows", 128) |
| 61 | + |
| 62 | + sram_dict = { |
| 63 | + "name": name, |
| 64 | + "width": bits, |
| 65 | + "depth": rows, |
| 66 | + "banks": 1, |
| 67 | + } |
| 68 | + mem_config = MemoryConfig.from_json(sram_dict) |
| 69 | + ram = MemoryFactory.create(mem_config, "RAM", "SP", process, timing_data) |
| 70 | + |
| 71 | + # Export Liberty |
| 72 | + lib_path = out_dir / f"{name}.lib" |
| 73 | + with open(lib_path, "w") as f: |
| 74 | + RAMLibertyExporter(ram).export(f) |
| 75 | + |
| 76 | + pre_lib_path = out_dir / f"{name}_pre_layout.lib" |
| 77 | + with open(pre_lib_path, "w") as f: |
| 78 | + RAMLibertyExporter(ram).export(f) |
| 79 | + |
| 80 | + # Export LEF |
| 81 | + lef_path = out_dir / f"{name}.lef" |
| 82 | + with open(lef_path, "w") as f: |
| 83 | + LefExporter(ram).export(f) |
| 84 | + |
| 85 | + (out_dir / "blackboxes.txt").write_text( |
| 86 | + "".join(f"{m['name']}\n" for m in converted) |
| 87 | + ) |
| 88 | + return 0 |
0 commit comments