This directory contains the wit-codegen tool that uses the generated ANTLR WIT grammar library.
A code generator that reads WIT files and generates C++ host function bindings using cmcpp types.
Usage:
./build/tools/wit-codegen/wit-codegen <wit-file> <output-prefix>Example:
./build/tools/wit-codegen/wit-codegen test-example.wit host_functionsThis generates:
host_functions.hpp- Header with function declarationshost_functions.cpp- Implementation stubs with TODO commentshost_functions_bindings.cpp- WAMR NativeSymbol bindings
See docs/wit-codegen.md for detailed documentation.
tools/
└── wit-codegen/
├── CMakeLists.txt
└── wit-codegen.cpp # wit-codegen tool
The tool is built automatically when you enable grammar generation:
cd build
cmake -DBUILD_GRAMMAR=ON ..
cmake --build . --target wit-codegenOr build everything:
cmake --build .- The tool links directly against ANTLR4 runtime (platform-specific:
antlr4_sharedon Windows,antlr4_staticon Linux) - Generated ANTLR source files are compiled into the tool
- Depends on the
generate-grammarCMake target to ensure grammar code is generated first - Generated grammar headers are available via:
#include "grammar/WitLexer.h"#include "grammar/WitParser.h"#include "grammar/WitBaseVisitor.h"
- The grammar code is generated in the build tree and not installed
- Uses
WitBaseVisitorto implement custom visitor for parse tree traversal