FeaturesΒΆ
yace is yet another code emitter. Related code emitters, such as autopxd2, ctypeslib2 and rust-bindgen, generate bindings from the C header of the library that they wrap.
yace parses the C header into an Interface Definition, which also records what C does not state, from the doc comments of the header, and generates every target from the IR, a C header among them. The IR records the size and alignment of every record and the offset of every field. The layout matters to a systems library whose records represent the commands and payloads that a device exchanges with the host.
C is well suited to systems programming, and other languages are better suited to other tasks. A program in another language accesses a C library through a foreign-function interface (FFI).
yace generates the bindings for such an interface. Other code emitters do so as well; what yace adds is:
- Documentation
The Interface Definition requires documentation of all symbols, so the generated bindings are documented too: in Doxygen format for C code, in PyDoc for Python, and so on.
- Syntactic sugar
The Interface Definition is close to C, but has higher-level constructs, from which yace emits code that is more Pythonic, idiomatic Go and Rust, and modern C++. The generated bindings thus have a thin layer of syntactic sugar over the raw FFI of each language.
- Pretty-printers
The Interface Definition describes the data structures, so yace emits functions that pretty-print the enums, structs and unions, in YAML and JSON.
- Fields of bits
C bit-fields do not cross an FFI boundary, so a field of bits is an integer whose parts are named by masks. The Interface Definition links each mask to its field, from the doc comments, so the pretty-printers print the parts by name, and every target reads and writes them by name.
For an introduction to using yace, see Usage. For details and reference, see Interface Definition, and for the supported targets, see Targets.