This project is an experimental playground for understanding and exploring the internals of the QBE compiler backend.
The main goal is to study how code is lowered and processed by QBE by compiling a main.py file through a QBE-based backend pipeline, while leveraging the stb_lexer library for lexical analysis.
- Explore the design and structure of the QBE backend
- Understand intermediate representations (IR)
- Experiment with code generation workflows
- Study how source code can be transformed before reaching QBE
- Gain hands-on experience with low-level compilation concepts
This project works by:
- Reading and processing
main.py - Tokenizing or lexing input using stb_lexer
- Transforming the parsed data into an intermediate representation
- Passing the generated IR to QBE
- Producing compiled output via QBE
The focus is not on building a production-ready compiler, but rather on experimentation, learning, and backend exploration.
- QBE
- stb_lexer
- A C compiler (
gccorclang) - Python (for
main.pyinput file) - nob.h
- arena.h
Clone and build QBE:
git clone https://c9x.me/git/qbe.git
cd qbe
makeEnsure qbe is available in your PATH.
Compile your project using your preferred build system:
make runThe program will:
- Compiles
compiler - Runs the compiler to reads
main.pyfile to emit QBE IR files - Compiles QBE IR file using QBE
This project is experimental and intended for educational purposes. It is not a full Python compiler and does not aim to implement the entire Python language specification.
- QBE Official Site: https://c9x.me/compile/
- STB Libraries: https://github.com/nothings/stb
- Tsoding
nob.h: https://github.com/tsoding/nob.h - Tsoding
arena.h: https://github.com/tsoding/arena