Skip to content

bjwanneng/veriflow-cc / src/claude_skills/vf-rtl

vf-rtl

Verified

FileKindSize
SELF_IMPROVE.mdmarkdown3.8 KB
SKILL.mdskill md11.2 KB
SKILL_INDEX.mdmarkdown5.5 KB
analysis/bug_pattern_match.pyscript26.9 KB
analysis/corner_case_generator.pyscript4.9 KB
analysis/coverage_analyzer.pyscript5.3 KB
analysis/design_graph.pyscript8.9 KB
analysis/expected_trace_gen.pyscript12.5 KB
analysis/timing_contract_checker.pyscript25.4 KB
analysis/timing_diagnostic.pyscript21.1 KB
analysis/vcd2table.pyscript31.3 KB
bug_patterns.mdmarkdown23.2 KB
coding_style.mdmarkdown9.4 KB
core/init.pyscript13.8 KB
core/rtl_utils.pyscript7.5 KB
core/state.pyscript38.9 KB
design_rules.mdmarkdown2.9 KB
error_recovery.mdmarkdown7.0 KB
kb/knowledge_base.pyscript11.7 KB
kb/reference_kb.pyscript5.6 KB
kb/self_improve.pyscript24.4 KB
references/arbiter_round_robin.vother1.4 KB
references/counter.vother545 B
references/fifo.vother1.3 KB
references/fsm_moore.vother847 B
references/handshake_valid_ready.vother1.1 KB
references/pipeline_aligner.vother760 B
runners/benchmark_runner.pyscript23.6 KB
runners/cocotb_runner.pyscript26.3 KB
runners/iverilog_runner.pyscript26.3 KB
runners/yosys_equiv.pyscript14.2 KB
stage1_spec_golden.mdmarkdown6.1 KB
stage2_codegen.mdmarkdown5.9 KB
stage3_verify_fix.mdmarkdown17.0 KB
stage4_lint_synth.mdmarkdown6.3 KB
templates/cocotb_template.pyscript42.4 KB
templates/golden_model_template.pyscript8.7 KB
templates/spec_template.jsonconfig8.5 KB
templates/tb_integration_template.vother12.4 KB
verify/candidate_selector.pyscript7.0 KB
verify/formal_prove.pyscript12.1 KB
verify/synth_score.pyscript4.4 KB

verify/synth_score.py

View on GitHub
#!/usr/bin/env python3
"""Synthesis-quality scoring for VeriFlow-CC.

Parses a yosys `stat` report (or runs a quick `synth`) into a compact numeric
score used to rank RTL candidates and tie-break fixes. yosys generic synth
reports cell counts only (no area / critical path / max frequency without a
liberty file), so the score is cell-based: fewer cells = better, with FF and
MUX counts exposed for finer tie-breaking.

Usage:
    python synth_score.py --rtl workspace/rtl/top.v --module top
    python synth_score.py --report workspace/synth/synth_report.txt
"""

from __future__ import annotations

import argparse
import json
import re
import shutil
import subprocess
import sys
import tempfile
from pathlib import Path


# Breakdown total: "  10158 cells"
_CELLS_TOTAL_RE = re.compile(r"^\s*(\d+)\s+cells\s*$", re.MULTILINE)
# Stats header summary: "Number of cells: 10158"
_NUM_CELLS_RE = re.compile(r"Number of cells:\s*(\d+)")
# Per-type line: "   1024   $_DFFE_PP_" — type names may contain underscores,
# so capture the whole "$_..._" token and strip the wrappers.
_CELL_TYPE_RE = re.compile(r"^\s+(\d+)\s+(\$_[A-Za-z0-9_]+_)\s*$", re.MULTILINE)


def parse_synth_report(text: str) -> dict:
    """Parse a yosys stat report into a score dict.

    Returns {"cells", "ffs", "mux", "logic", "score"}. All zero if no stats
    found (degrades gracefully so callers can still rank by other signals).
    """
    cells = 0
    m = _CELLS_TOTAL_RE.search(text) or _NUM_CELLS_RE.search(text)
    if m:
        cells = int(m.group(1))

    ffs = 0
    mux = 0
    for cm in _CELL_TYPE_RE.finditer(text):
        count = int(cm.group(1))
        token = cm.group(2)            # e.g. "$_DFFE_PP_"
        celltype = token[2:-1]         # strip "$_" prefix and trailing "_" -> "DFFE_PP"
        if "DFF" in celltype:          # $_DFF* / $_DFFE* / $_SDFF* / $_ADFF* ...
            ffs += count
        elif celltype.startswith("MUX"):
            mux += count

    logic = max(cells - ffs - mux, 0)
    return {
        "cells": cells,
        "ffs": ffs,
        "mux": mux,
        "logic": logic,
        "score": cells,   # fewer is better; FF/MUX exposed for tie-break
    }


def quick_synth(
    rtl_file: str, module: str, build_dir: str, yosys: str = "yosys",
    timeout: int = 120,
) -> dict:
    """Run `yosys -p 'read_verilog <rtl>; synth -top <module>; stat'` and score.

    Returns parse_synth_report() output plus "error" on failure. Mirrors the
    subprocess + timeout + cleanup discipline of yosys_equiv.check_equivalence.
    """
    yosys_path = shutil.which(yosys)
    if yosys_path is None:
        return {**parse_synth_report(""), "error": f"yosys not found: {yosys}"}

    Path(build_dir).mkdir(parents=True, exist_ok=True)
    script = (
        f"read_verilog \"{rtl_file}\"; "
        f"synth -top {module}; "
        f"stat"
    )
    try:
        result = subprocess.run(
            [yosys_path, "-p", script],
            capture_output=True, text=True, timeout=timeout,
            cwd=str(build_dir),
        )
    except subprocess.TimeoutExpired:
        return {**parse_synth_report(""), "error": f"yosys timed out after {timeout}s"}
    except Exception as e:  # pragma: no cover - defensive
        return {**parse_synth_report(""), "error": str(e)}

    if result.returncode != 0:
        return {
            **parse_synth_report(result.stdout or ""),
            "error": f"yosys exited {result.returncode}: {(result.stderr or '')[:200]}",
        }
    return parse_synth_report(result.stdout or "")


def main(argv: list[str] | None = None) -> int:
    parser = argparse.ArgumentParser(description="Score RTL synthesis quality")
    parser.add_argument("--rtl", help="RTL .v file (runs a quick synth)")
    parser.add_argument("--module", help="Top module name (with --rtl)")
    parser.add_argument("--report", help="Existing yosys stat report to parse")
    args = parser.parse_args(argv)

    if args.report:
        text = Path(args.report).read_text(encoding="utf-8")
        print(json.dumps(parse_synth_report(text), indent=2))
        return 0
    if args.rtl and args.module:
        with tempfile.TemporaryDirectory() as tmp:
            r = quick_synth(args.rtl, args.module, tmp)
        print(json.dumps(r, indent=2))
        return 0 if "error" not in r else 2
    parser.error("provide --report or --rtl + --module")
    return 2  # unreachable: parser.error exits


if __name__ == "__main__":
    sys.exit(main())
slack-gif-creatoranthropics/skillsKnowledge and utilities for creating animated GIFs optimized for Slack. Provides constraints, validation tools, and animation concepts. Use when users request animated GIFs for Slack like "make me a GIF of X doing Y for Slack."Stars: 198kUpdated Claude CodeCodexVerifiedInstall
ponytailDietrichGebert/ponytailLazy senior dev mode for any coding task: the smallest change that fully solves it, and a reply a busy human understands in one read.Stars: 194kUpdated Claude CodeCodexVerifiedInstall
ponytail-debtDietrichGebert/ponytailHarvest every shortcut: comment into one debt ledger, so deferrals get tracked instead of forgotten. One-shot report.Stars: 194kUpdated Claude CodeCodexVerifiedInstall
ponytail-debtDietrichGebert/ponytailList every `shortcut:` comment (and older `ponytail:` ones) as a debt ledger. One-shot report, changes nothing. Use for "ponytail debt", "what did ponytail defer", "list the shortcuts", /ponytail-debt.Stars: 194kUpdated Claude CodeCodexVerifiedInstall