SystemVerilog Bindings¶
ml-hpi produces two distinct SystemVerilog outputs from a single spec:
Interface class declarations (
GenSVInterface) – the SV-native hierarchical API.DPI glue package (
GenSV) – a flat DPI bridge that lets C code call into the SV interface hierarchy.
This page documents both.
Interface Class Generator¶
GenSVInterface emits one .sv file per package containing
interface class declarations. Each ml-hpi interface becomes a
SystemVerilog interface class; methods become pure virtual function
or pure virtual task declarations; members become accessor methods.
Generated Artifacts¶
For a spec whose interfaces share the package prefix pkg, the generator
produces pkg.sv:
$ python -m ml_hpi generate --spec spec.yaml --outdir gen/ --lang sv
Output structure:
package pkg;
interface class RegIf;
pure virtual task write32(longint unsigned addr, int unsigned data);
pure virtual task read32(output int unsigned rval, input longint unsigned addr);
pure virtual function void reset();
endclass
interface class BusIf;
pure virtual function RegIf regs();
pure virtual function RegIf ports_at(int idx);
pure virtual function int ports_size();
endclass
interface class ExtRegIf extends RegIf;
pure virtual function void configure(int unsigned mode);
endclass
endpackage
Method Mapping¶
ml-hpi construct |
SystemVerilog output |
|---|---|
Method (non-blocking) |
|
Method (blocking, void return) |
|
Method (blocking, non-void return) |
|
Member (field) |
|
Member (array) |
pure virtual function {IfType} {name}_at(int idx);pure virtual function int {name}_size(); |
Inheritance |
|
Type Mapping¶
ml-hpi |
SystemVerilog |
|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DPI Glue Generator¶
GenSV produces a DPI bridge package that allows C code to invoke SV
interface methods through the DPI-C mechanism. It emits a root registry
class, a navigate() function, and DPI export wrappers.
This generator requires a --root-if argument identifying the root
interface of the hierarchy:
$ python -m ml_hpi generate --spec spec.yaml --outdir gen/ --lang sv \
--root-if pkg.RegIf
See the C bindings page for the matching C header.
SV Parser¶
ParseSV uses pyslang to parse interface class declarations back
to an MlHpiDoc.
$ python -m ml_hpi parse --lang sv --input pkg.sv --output recovered.yaml
Limitations:
target/solveattributes are not expressible in SV interface class syntax and default to unset in the parsed output. Add// ml-hpi:target=truepragma comments to preserve them.addr64vsuint64ambiguity: the parser defaults touint64.pyslangis a hard requirement; no fallback parser is provided.