Commit da9db63a by lvzhengyang

aggregate the repo

parent 4055a7ab
## CDFG generation
## e.g. RTL2CDFG This repo wraps the third-party RTL2CDFG flow with per-case configuration.
### Configure a case
Create or edit `cases/<case>/config.toml` with a `[cdfg]` section:
```toml
[cdfg]
top = "eth_fifo"
rtl_files = [
"rtl/timescale.v",
"rtl/ethmac_defines.v",
"rtl/eth_fifo.v",
]
divide = false
yosys = "yosys"
# Optional override. Defaults to results/<case>/cdfg.
# output_dir = "results/eth_fifo/cdfg"
```
### Build CDFG
```bash
./main.py build_cdfg --case eth_fifo
```
The generated CDFG is copied to `results/<case>/cdfg` by default (or the `output_dir` you set).
---
## Legacy RTL2CDFG example
``` ```
cd thirdparty/RTL2CDFG/v2cdfg cd thirdparty/RTL2CDFG/v2cdfg
./cdfg_generator.sh --yosys /nfs_global/S/lvzhengyang/auto-assumption.misc/thirdparty/oss-cad-suite/bin/yosys ../../../cases/eth_fifo/rtl/timescale.v ../../../cases/eth_fifo/rtl/ethmac_defines.v ../../../cases/eth_fifo/rtl/eth_fifo.v ./cdfg_generator.sh --yosys /nfs_global/S/lvzhengyang/auto-assumption.misc/thirdparty/oss-cad-suite/bin/yosys ../../../cases/eth_fifo/rtl/timescale.v ../../../cases/eth_fifo/rtl/ethmac_defines.v ../../../cases/eth_fifo/rtl/eth_fifo.v
./cdfg_generator.sh ../../../cases/eth_fifo/rtl/timescale.v ../../../cases/eth_fifo/rtl/ethmac_defines.v ../../../cases/eth_fifo/rtl/eth_fifo.v
``` ```
[cdfg]
top = "eth_fifo"
rtl_files = [
"rtl/timescale.v",
"rtl/ethmac_defines.v",
"rtl/eth_fifo.v",
]
divide = false
# Use the system yosys by default. Set an absolute path if needed.
yosys = "yosys"
# Optional override for output location. Defaults to results/<case>/cdfg.
# output_dir = "results/eth_fifo/cdfg"
#!/usr/bin/env python3
import argparse
import shutil
import subprocess
import sys
from pathlib import Path
try:
import tomllib # Python 3.11+
except ModuleNotFoundError:
import tomli as tomllib
REPO_ROOT = Path(__file__).resolve().parent
def _load_case_config(case_name: str) -> dict:
config_path = REPO_ROOT / "cases" / case_name / "config.toml"
if not config_path.exists():
raise FileNotFoundError(f"Missing config: {config_path}")
with config_path.open("rb") as f:
return tomllib.load(f)
def _resolve_rtl_files(case_dir: Path, rtl_files: list[str]) -> list[str]:
resolved = []
missing = []
for rtl in rtl_files:
rtl_path = Path(rtl)
if not rtl_path.is_absolute():
rtl_path = case_dir / rtl_path
rtl_path = rtl_path.resolve()
if not rtl_path.exists():
missing.append(str(rtl_path))
else:
resolved.append(str(rtl_path))
if missing:
missing_list = "\n".join(f"- {p}" for p in missing)
raise FileNotFoundError(f"RTL files not found:\n{missing_list}")
return resolved
def _build_cdfg(case_name: str) -> int:
case_dir = REPO_ROOT / "cases" / case_name
if not case_dir.exists():
raise FileNotFoundError(f"Case directory not found: {case_dir}")
config = _load_case_config(case_name)
if "cdfg" not in config:
raise KeyError("Missing [cdfg] section in config.toml")
cdfg_cfg = config["cdfg"]
top = cdfg_cfg.get("top")
rtl_files = cdfg_cfg.get("rtl_files")
yosys_bin = cdfg_cfg.get("yosys", "yosys")
divide = bool(cdfg_cfg.get("divide", False))
if not top:
raise KeyError("Missing cdfg.top in config.toml")
if not rtl_files or not isinstance(rtl_files, list):
raise KeyError("Missing cdfg.rtl_files list in config.toml")
rtl_paths = _resolve_rtl_files(case_dir, rtl_files)
v2cdfg_dir = REPO_ROOT / "thirdparty" / "RTL2CDFG" / "v2cdfg"
if not v2cdfg_dir.exists():
raise FileNotFoundError(f"v2cdfg directory not found: {v2cdfg_dir}")
cdfg_work_dir = v2cdfg_dir / "cdfg"
if cdfg_work_dir.exists():
shutil.rmtree(cdfg_work_dir)
cdfg_work_dir.mkdir(parents=True, exist_ok=True)
cmd = ["./cdfg_generator.sh"]
cmd.append("-divide" if divide else "-nodivide")
cmd.extend(["--top", top])
if yosys_bin:
cmd.extend(["--yosys", yosys_bin])
cmd.extend(rtl_paths)
print("[build_cdfg] Running:")
print(" ".join(cmd))
result = subprocess.run(cmd, cwd=v2cdfg_dir)
if result.returncode != 0:
return result.returncode
output_dir_cfg = cdfg_cfg.get("output_dir")
if output_dir_cfg:
output_dir = Path(output_dir_cfg)
if not output_dir.is_absolute():
output_dir = (REPO_ROOT / output_dir).resolve()
else:
output_dir = (REPO_ROOT / "results" / case_name / "cdfg").resolve()
if output_dir.exists():
shutil.rmtree(output_dir)
output_dir.parent.mkdir(parents=True, exist_ok=True)
shutil.copytree(cdfg_work_dir, output_dir)
print(f"[build_cdfg] CDFG saved to {output_dir}")
return 0
def main() -> int:
parser = argparse.ArgumentParser(description="CDFG utilities")
subparsers = parser.add_subparsers(dest="command", required=True)
build_parser = subparsers.add_parser("build_cdfg", help="Generate CDFG from RTL")
build_parser.add_argument("--case", required=True, help="Case name under cases/")
args = parser.parse_args()
if args.command == "build_cdfg":
return _build_cdfg(args.case)
parser.print_help()
return 1
if __name__ == "__main__":
try:
sys.exit(main())
except Exception as exc:
print(f"[error] {exc}", file=sys.stderr)
sys.exit(1)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment