A Clang plugin for creating printers for OpenBSD list macro declarations.
The following instructions assume an Ubuntu 22.04 LTS operating system:
-
Ninja
sudo apt install ninja-build
-
CMake 3.29.1 (click here for download and install instructions)
-
wget -qO- https://apt.llvm.org/llvm-snapshot.gpg.key | sudo tee /etc/apt/trusted.gpg.d/apt.llvm.org.asc sudo apt install llvm-17 clang-17 libclang-17-dev
-
Configure the plugin:
cmake -S . -B build -G "Ninja Multi-Config" \ -D CMAKE_C_COMPILER=<path to clang-17 compiler> \ -D CMAKE_CXX_COMPILER=<path to clang++-17 compiler> \ -D Clang_DIR=<path to ClangConfig.cmake> \ -D LLVM_DIR=<path to LLVMConfig.cmake>
-
Build the plugin:
cmake --build build --config=Release
Assuming you are currently at the project root, then you can run the shared library on the following platforms as follows:
Ubuntu:
/usr/bin/clang-17 \
-fplugin=./build/lib/Debug/libopenbsd_list_macro_printer.so \
-fsyntax-only \
test/slist.c
MacOS:
/opt/homebrew/opt/llvm@17/bin/clang \
-fplugin=./build/lib/Debug/libopenbsd_list_macro_printer.dylib \
-fsyntax-only \
test/slist.c
The output should be:
{
struct entry * __openbsd_list_iterator;
SLIST_FOREACH(__openbsd_list_iterator, &head, entries) {
printf("%d", __openbsd_list_iterator->a);
printf("%d", __openbsd_list_iterator->b);
printf("%s", __openbsd_list_iterator->s);
printf("%s", __openbsd_list_iterator->t);
}
}
We recommend downloading the clangd
C/C++ language server to ease development.
This project also provides a .clang-format
file for formatting. If you would
like to contribute, please ensure that you've formatted your code with
clang-format
before committing
it. Assuming you are on Ubuntu, you can download clang-format
with the
following command:
sudo apt install clang-format