C++ Bindings¶
GenCpp produces one .hpp header per package containing abstract
classes with pure virtual methods inside a namespace.
Generated Artifacts¶
$ python -m ml_hpi generate --spec spec.yaml --outdir gen/ --lang cpp
For a spec whose interfaces share the package prefix pkg, the generator
produces pkg.hpp:
#pragma once
#include <cstdint>
#include <functional>
namespace pkg {
class RegIf;
class BusIf;
class ExtRegIf;
class RegIf {
public:
virtual ~RegIf() = default;
virtual void write32(uint64_t addr, uint32_t data) = 0;
virtual void write32(uint64_t addr, uint32_t data, std::function<void()> cb) = 0;
virtual uint32_t read32(uint64_t addr) = 0;
virtual void read32(uint64_t addr, std::function<void(uint32_t)> cb) = 0;
virtual void reset() = 0;
};
class BusIf {
public:
virtual ~BusIf() = default;
virtual RegIf *regs() = 0;
virtual RegIf *ports_at(int idx) = 0;
virtual int ports_size() = 0;
};
class ExtRegIf : public virtual RegIf {
public:
virtual ~ExtRegIf() = default;
virtual void configure(uint32_t mode) = 0;
};
} // namespace pkg
Blocking methods are emitted in two forms: a synchronous signature and an
asynchronous callback overload using std::function. Pass
--no-cpp-async to suppress the callback overloads.
Method Mapping¶
ml-hpi construct |
C++ output |
|---|---|
Method (non-blocking) |
|
Method (blocking, sync) |
|
Method (blocking, async) |
|
Member (field) |
|
Member (array) |
virtual {IfType} *{name}_at(int idx) = 0;virtual int {name}_size() = 0; |
Inheritance |
|
Type Mapping¶
ml-hpi |
C++ |
|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
C++ Parser¶
ParseCpp uses cxxheaderparser to parse abstract class headers back
to an MlHpiDoc.
$ python -m ml_hpi parse --lang cpp --input pkg.hpp --output recovered.yaml
Limitations:
target/solveattributes cannot be inferred from C++ and default to unset.blockingis inferred only when both sync and async overloads exist for the same method name. If the header was generated with--no-cpp-async, blocking cannot be recovered.addrvs concrete integer width (uint64) is ambiguous.