Skip to content

Latest commit

 

History

History
35 lines (27 loc) · 1.73 KB

File metadata and controls

35 lines (27 loc) · 1.73 KB

EuroLLVM 2026 Tutorial: Hands-on Using Clang as a library

This tutorial outlines how to use Clang as a library to enable basic C/C++ incremental compilation infrastructure by building a C++ interpreter that connects to the Python interpreter. We:

  • Learn how to use Clang as a library
  • Build a simple C++ REPL with clang::Interpreter
  • See how we can bridge compiled and interpreted code
  • Develop building blocks for a basic Compiler-as-a-Service
  • Use the CaaS layer to bridge Python and C++

Build

Requires LLVM/Clang 21, CMake ≥ 3.13, a C++17 compiler, and Python3 for exercises 4 and 5.

git clone https://github.com/compiler-research/eurollvm26-tutorial.git
cd eurollvm26-tutorial && mkdir build && cd build
cmake -DLLVM_DIR=/usr/lib/llvm-21/lib/cmake/llvm \
      -DClang_DIR=/usr/lib/llvm-21/lib/cmake/clang ..
make

Substitute whichever /usr/lib/llvm-21 with your install:

  • mac: $(brew --prefix llvm@21)/lib/cmake/...
  • source build: path/to/build/lib/cmake/....

Exercises

  • ex1 — Use Clang components as a library to build an AST, walk the translation unit, and extract a class template's Doxygen comment.
  • ex2 — Build a simple C++ REPL built leveraging IncrementalCompilerBuilder and clang::Interpreter.
  • ex3 — Use clang::Value to capture expression results, and getSymbolAddress to call JIT'd functions from compiled code.
  • ex4 — Builds a lightweight library containing Compiler-as-a-Service building blocks using Interpreter and Sema, exposing template instantiation driven from both C and Python (express MyClass<int> in Python).
  • ex5 — extends ex4 with clang::Value capture, allowing the Python template wrapper to perform expression evaluation and read the typed primitive results back.