aboutsummaryrefslogtreecommitdiff
path: root/README.md
blob: 292cefb1e0dcb7b6e4a8c334cccb9f51a4703053 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
This is a C compiler for the MAR ([Much-Assembly-Required](https://muchassemblyrequired.com/)) 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.

Hints:

- 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
}
```