mirror of
https://github.com/LLVMParty/llvm-nanobind
synced 2026-06-21 13:43:38 +00:00
LLVM Python Workshop Exercise Plan
This folder is a planning scaffold for a workshop site that teaches LLVM through the new Python API.
Goals
- Teach high-value LLVM concepts first, not full API coverage.
- Make mistakes visible through deliberate pitfall exercises.
- Support interactive validation in a browser-like portal with fixed input IR.
- Keep all checks deterministic and auto-gradable.
API Surface Review (Priority Order)
The current bindings are broad, but workshop priority should follow usage and learning value:
- Core construction and inspection
Context,Module,TypeFactory,Type,ValueFunction,BasicBlock,Builder
- Correctness workflows
parse_ir,parse_bitcode_from_bytes,verify,get_verification_error
- Common compiler tasks
- arithmetic, memory ops, control flow, PHI nodes, attributes, metadata
- Optimization and target work
run_passes,PassBuilderOptions, target triple/data layout/codegen
- Advanced tooling
- debug info (
DIBuilder), disassembly, object/binary iterators
- debug info (
Safety semantics should be taught early:
LLVMMemoryErrorfor lifetime violationsLLVMAssertionErrorfor programming mistakesLLVMParseErrorfor parse failures + diagnostics
Workshop Curriculum Shape
Recommended progression:
- Foundations (IR reading/writing, module/function/block basics)
- Builder fundamentals (arithmetic, memory, casts, compare)
- Control flow + SSA (branches, loops, PHI, predecessors)
- Module-level features (globals, linkage, attributes, metadata)
- Optimization + target pipeline
- Debug info + binary inspection
- Capstone transformations
See exercises/CATALOG.md for a full exercise list.
Web Portal Validation Model
Each exercise should provide:
- fixed
input.ll(or explicit "build from scratch") - a short task prompt
- starter Python function (single entrypoint)
- deterministic checks that return structured pass/fail
Validation modes:
- IR text check: normalize and compare exact expected output
- property check: parse result and assert structural properties
- safety check: assert the correct exception type/message class
Recommended deterministic policy:
- verify generated module with
mod.verify() - avoid target-dependent codegen in early exercises
- normalize trivial IR formatting differences before compare
- avoid nondeterministic names in expected output checks
Proposed Folder Layout
exercises/
README.md
CATALOG.md
portal-schema.md
templates/
exercise.toml
exercise_output.toml
As implementation begins, add:
01-foundations/
02-builder/
03-control-flow-ssa/
04-module-attrs-metadata/
05-passes-target/
06-debug-binary/
07-capstones/
Implementation Phases
- Build exercise loader + schema validation.
- Implement 10 core exercises (Foundations + Builder).
- Implement 10 pitfall-heavy exercises (SSA + lifetime + validation).
- Implement 8 advanced exercises (passes/target/debug/binary).
- Add scoring, hints, and solution diff views in portal.