This is a C compiler for the MAR (Much-Assembly-Required) virtual machine, written in C. It is pretty unsophisticated at the moment, but should be able to compile VERY rudimentary C programs, like those in test/.

Note that even though this claims to be a "C compiler" written in C, it is VERY far from being able to compile itself.

The compiler depends on flex and bison, and of course a working C compiler (tested with clang and gcc; the makefile uses gcc). Install those, then run make to build, and ./ccomp to run.


  • Don't define any names starting with __. Stuff will blow up.
  • Asm literals are possible, and the instructions are actually parsed by the compiler. This is to enable inlining variable references and possible optimisations later. Note that because of this, the syntax might be more restricted than you'd like (e.g. 1 + 2 is not allowed). Literals look as follows:
asm {
    mov a, 3
    mov b, 42
    hwi 9