Skip to main content

An IEEE-1364 VPI interface for CXXRTL (Yosys C++ simulation backend), so cocotb can drive CXXRTL models

Project description

cxxrtl-vpi

PyPI License: ISC

An IEEE-1364 VPI interface for CXXRTL, the Yosys C++ simulation backend.

CXXRTL compiles a (System)Verilog design into a fast, embeddable C++ model, but exposes only its own cxxrtl_capi C API — it does not speak VPI. This project implements a VPI provider on top of cxxrtl_capi, turning any CXXRTL-generated model into a VPI-capable simulator.

The immediate motivation is cocotb (Python testbenches) — cocotb drives any VPI/VHPI/FLI simulator, but ships no CXXRTL backend. With cxxrtl-vpi, cocotb's existing generic VPI consumer can drive a CXXRTL model unmodified. But the VPI layer is deliberately client-agnostic: any VPI tool (debuggers, custom harnesses) can use it.

Status: working. Unmodified cocotb testbenches run against CXXRTL models and pass. Measured against cocotb 2.0's own core regression suite, the scheduler/timing/callback core is at Verilator parity (~91% of the runnable core suite; the rest is the inherent CXXRTL-is-a-synthesizer boundary — real/string, folded parameters), and ahead on force/release (which cocotb does not support on Verilator). Implemented over cxxrtl_capi: object access, callbacks/time/control, hierarchy + parent-nav, generate-scope arrays (dut.lane[i].sig), memories, wide signals, net/reg classification, ranges, picosecond time, init-fuzzing, VCD tracing, and an optional yosys-slang frontend for full SystemVerilog. See docs/vpi-coverage.md for the coverage matrix and limits.

Why this is an engine adapter, not a cocotb plugin

This mirrors how Verilator integrates with cocotb:

Piece Owner for Verilator Intended owner here
The VPI implementation Verilator itself (verilated_vpi) this repo → upstream to Yosys/CXXRTL
VPI consumer bootstrap (libcocotbvpi_*) cocotb cocotb (thin glue)
Harness main() cocotb (verilator.cpp) cocotb (thin glue) — prototyped here under examples/

The heavy, reusable piece — making CXXRTL speak VPI — is a simulator capability, so its natural home is the engine (Yosys), exactly as Verilator owns its own VPI. This repo is the incubator: it depends only on two stable, public contracts and is unblocked regardless of either project's review cycle:

  • cxxrtl/capi/cxxrtl_capi.h (Yosys — stable, external-facing)
  • vpi_user.h (IEEE 1364 — standard)

See docs/design.md for the full rationale and upstreaming plan.

Layout

include/cxxrtl_vpi/   public headers for the model wrapper + VPI provider
src/
  model.cc            thin wrapper over cxxrtl_capi (create/eval/step/signals)
  vpi_provider.cc     IEEE-1364 VPI entry points implemented over cxxrtl_capi
  harness.cc          main(): build model, run VPI startup, drive the sim loop
examples/cocotb_counter/   end-to-end cocotb example (the first consumer)
cxxrtl_vpi/           small Python helper: locate includes, build, run
docs/                 design rationale + VPI coverage matrix

Install

pip install cxxrtl-vpi

The cocotb path requires Python ≤ 3.13 (cocotb's cap), plus Yosys (yosys / yosys-config) and a C++14 compiler on PATH — the same external toolchain every simulator needs. (Latest from git: pip install git+https://github.com/lanserge/cxxrtl-vpi.) The quickest way to see it work is the cocotb example:

PYTHON=/path/to/venv/bin/python bash examples/cocotb_counter/run_cocotb.sh
# -> test_count_up passed ... TESTS=1 PASS=1 FAIL=0

The provider library alone also builds standalone with CMake:

cmake -S . -B build && cmake --build build

License

ISC — the same license as Yosys/CXXRTL. This keeps the VPI core trivially upstreamable into the Yosys tree (matching file headers, no relicensing), and is permissively compatible with cocotb (BSD-3-Clause) for the consumer glue.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cxxrtl_vpi-0.0.2.tar.gz (21.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cxxrtl_vpi-0.0.2-py3-none-any.whl (24.1 kB view details)

Uploaded Python 3

File details

Details for the file cxxrtl_vpi-0.0.2.tar.gz.

File metadata

  • Download URL: cxxrtl_vpi-0.0.2.tar.gz
  • Upload date:
  • Size: 21.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for cxxrtl_vpi-0.0.2.tar.gz
Algorithm Hash digest
SHA256 bb972f4af1f076e85db28b9ef30c887be416df98f83a8df79ae45724a37e01b2
MD5 0d1564bfa94908047f8cfc22581792dc
BLAKE2b-256 524be3f7abde3e896a36ba293ca6c3e53b5a1fd8a03e5014f0bd1fe2a481e510

See more details on using hashes here.

Provenance

The following attestation bundles were made for cxxrtl_vpi-0.0.2.tar.gz:

Publisher: release.yml on lanserge/cxxrtl-vpi

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file cxxrtl_vpi-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: cxxrtl_vpi-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 24.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for cxxrtl_vpi-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 e61fa7cf7d64f453883e63c3acdebf22b1d3e4503079108889ad4e01b885082d
MD5 046d9bfa623b088ac6ea54806c2dfcdb
BLAKE2b-256 ccb58fe7de36a55047e766235838f9225bc3c3ca1d86bc74a866304bf082a101

See more details on using hashes here.

Provenance

The following attestation bundles were made for cxxrtl_vpi-0.0.2-py3-none-any.whl:

Publisher: release.yml on lanserge/cxxrtl-vpi

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page