Intermediate representation - mfichman/jogo GitHub Wiki
The Jogo IR (intermediate representation) is a register-based, 3-address, (almost) SSA, RISC-inspired instruction set. There is currently no fixed binary format for the IR, but that is a goal for the project -- a binary format would support JIT compilation and interpreters. The IR needs Phi functions to be truly SSA across basic blocks -- this is another goal. The IR below is very simple, to make porting to multiple architectures easy. It translates fairly well to x86, and very well (in theory) to ARM/MIPS.
Opcode | Op1 | Op2 | Op3 | Description |
---|---|---|---|---|
mov | r1 | r2 | . | r1 = r2 |
sub | r1 | r2 | r3 | r1 = r2 + r3 |
add | r1 | r2 | r3 | r1 = r2 - r3 |
mul | r1 | r2 | r3 | r1 = r2 * r3 |
div | r1 | r2 | r3 | r1 = r2 / r3 |
neg | r1 | r2 | . | r1 = -r2 |
andb | r1 | r2 | r3 | r1 = r2 and r3 |
orb | r1 | r2 | r3 | r1 = r2 or r3 |
notb | r1 | r2 | . | r1 = not r2 |
load | r1 | r2 | . | r1 = mem[r2] |
load | r1 | r2, offset | . | r1 = mem[r2+offset] |
load | r1 | offset | . | r1 = mem[frame pointer+offset] |
load | r1 | label | r1 = mem[label] | |
load | r1 | immediate | . | r1 = immediate |
store | . | r2 | r3 | mem[r2] = r3 |
store | . | r2, offset | r3 | mem[r2+offset] = r3 |
store | r1 | offset | . | mem[frame pointer+offset] = r3 |
store | . | label | r3 | mem[label] = r3 |
call | . | label | . | call function at label |
jump | . | label | . | goto label |
bne | r1 | r2 | label | if r1 != r2 goto label |
be | r1 | . | label | if r1 == r2 goto label |
bnz | r1 | . | label | if r1 != 0 goto label |
bz | r1 | r2 | label | if r1 == 0 goto label |
bg | r1 | r2 | label | if r1 > r2 goto label |
bl | r1 | r2 | label | if r1 < r2 goto label |
bge | r1 | r2 | label | if r1 >= r2 goto label |
ret | . | . | . | return from function |
nop | . | . | . | no-op (do nothing) |