Compiler Backend

QBE aims to be a pure C embeddable backend that provides 70% of the performance of advanced compilers in 10% of the code. Its small size serves both its aspirations of correctness and our ability to understand, fix, and improve it. It also serves its users by providing trivial integration and great flexibility.


git clone git://c9x.me/qbe.git

QBE is known to compile and pass its test suite on amd64 Linux, FreeBSD, and OSX. Compiling QBE requires GNU Make and a C99 compiler. The HTML documentation is generated from regular text files by an OCaml program.


Patches and discussions about QBE are hosted on the mailing list ~mpu/qbe@lists.sr.ht.

IRC: irc.eigenstate.org in #myrddin (nick: mpu).


QBE is in constant change. It is a young project and I still have many ideas to try. The core of it should now work pretty reliably for simple language experiments. To palliate the youth and lack of users, complex parts of the register allocator and the ABI implementation have been thoroughly fuzz tested.

Some smartness is already baked in at this time.

You might encounter some friction because of these points.


Projects using QBE.

Hello World

The intermediate language used as input to QBE is spoken by all the compilation passes and can be dumped anytime in the compiler pipeline using command line options. The example program below can call the C function printf out of the box, with no special syntax. C compatibility is baked in. Similarly C can call any function compiled with QBE.

function w $add(w %a, w %b) {              # Define a function add
	%c =w add %a, %b                   # Adds the 2 arguments
	ret %c                             # Return the result
export function w $main() {                # Main function
	%r =w call $add(w 1, w 1)          # Call add(1, 1)
	call $printf(l $fmt, w %r, ...)    # Show the result
	ret 0
data $fmt = { b "One and one make %d!\n", b 0 }

Toss the above in a file, then run qbe -o asm.s file.ssa && cc asm.s. You should get a binary executable file ready to rock.