QBE

A Quick 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.

Code

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

QBE is known to compile and pass its test suite on the following x64 operating systems.

Compiling QBE requires GNU Make and a C99 compiler. The HTML documentation is generated from regular text files by an OCaml program. Thanks to Ori we also have a continuous build setup.

Status

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.

Documentation

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
@start
	%c =w add %a, %b                   # Adds the 2 arguments
	ret %c                             # Return the result
}
export function w $main() {                # Main function
@start
	%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.

Contact

To report a problem with QBE or ask a question: rot13(ohtf@p9k.zr).

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