C Bindings

GenC produces a C header declaring the DPI-C interface for a given root interface hierarchy. It is designed to pair with the GenSV DPI glue package so that C code can call into SystemVerilog interface methods across the DPI boundary.

Generated Artifacts

The generator requires a --root-if argument identifying the root interface:

$ python -m ml_hpi generate --spec spec.yaml --outdir gen/ --lang c \
    --root-if pkg.RegIf

This produces pkg_RegIf_dpi.h containing:

  • extern declarations for DPI export functions (SV provides, C calls).

  • Prototype declarations for completion import functions (C provides, SV calls on blocking method finish).

  • Package init / scope helper declarations.

Example output (abbreviated):

#ifndef PKG_REGIF_DPI_H
#define PKG_REGIF_DPI_H

#include <stdint.h>
#include <stdbool.h>
#include "svdpi.h"

#ifdef __cplusplus
extern "C" {
#endif

/* DPI exports -- implemented in SystemVerilog, called from C */
extern void pkg_RegIf_write32(int root_id, int path,
                               uint64_t addr, uint32_t data, void *cb);
extern void pkg_RegIf_read32(int root_id, int path,
                              uint64_t addr, void *cb);

/* Completion imports -- implemented in C, called from SystemVerilog */
void pkg_RegIf_write32_complete(void *cb);
void pkg_RegIf_read32_complete(void *cb, uint32_t rval);

int  pkg_RegIf_dpi_init(void);
void pkg_RegIf_dpi_set_scope(void);

#ifdef __cplusplus
}
#endif

#endif

Type Mapping

ml-hpi

C

void

void

bool

bool

int8 / uint8

int8_t / uint8_t

int16 / uint16

int16_t / uint16_t

int32 / uint32

int32_t / uint32_t

int64 / uint64

int64_t / uint64_t

addr / addr32 / addr64

uint32_t or uint64_t (based on --addr-bits)

uintptr

uintptr_t

Limitations

  • There is no C parser. C headers generated by GenC are DPI glue and do not contain enough semantic information to reconstruct an MlHpiDoc.

  • Blocking methods use an opaque void *cb callback handle; the C side must call the corresponding _complete function when the operation finishes.