Commit 3ca1c3f
committed
Backend labels and jumps
This commit adds support for labels and jumps in the following ways:
* Adds a new instruction `OP_LABEL`, which writes the label at that point in the IR
* Adds a new operand type `EIR_LABEL_NAME`, which references a label in an instruction
* Adds 3 new jump instructions, `OP_JUMP_EQ`, `OP_JUMP_NE`, and `OP_JUMP_OVF`. The first two take two operands to compare against first, then a label operand to jump to. The last one just takes the label operand.
* When we're writing out X86, we add an additional pass through the IR that first registers all of the labels with `cb_new_label`. If there are multiple references to the same label, they are deduped by checking against the labels that have already been registers within the coddeblock object. Once they're registered, we transform them into `EIR_LABEL_IDX` operands, which represent the index in the codeblock object. Finally at the end we call `cb_link_labels` to have the X86 assembler do its thing.1 parent 16d9873 commit 3ca1c3f
2 files changed
+217
-50
lines changed
0 commit comments