commit b5563ea6c2c09b21761fc609adaf282fc2751dd1
parent 2e7c7c3c67197d9e845c15d9d15cc38d92b30d60
Author: Nihal Jere <nihal@nihaljere.xyz>
Date: Sat, 15 Jan 2022 20:52:02 -0600
x64: consider active registers and curi when calculating block length
Since we push and pop active regiters from the stack, the length in
machine code depends on the number of active registers, which depends
on the current instruction. So give these to emitblock as parameters.
Diffstat:
1 file changed, 5 insertions(+), 7 deletions(-)
diff --git a/x64.c b/x64.c
@@ -748,16 +748,14 @@ emitsyscall(struct data *text, uint8_t paramcount)
}
size_t
-emitblock(struct data *text, struct iproc *proc, struct instr *start, struct instr *end, uint64_t end_label)
+emitblock(struct data *text, struct iproc *proc, struct instr *start, struct instr *end, uint64_t end_label, uint16_t active, uint16_t curi)
{
struct instr *ins = start ? start : proc->data;
end = end ? end : &proc->data[proc->len];
- uint16_t active = 0;
-
uint64_t dest, src, size, count, tmp, label;
int64_t offset;
- uint64_t localalloc = 0, curi = 0;
+ uint64_t localalloc = 0;
size_t total = 0;
if (!start) {
@@ -778,7 +776,7 @@ emitblock(struct data *text, struct iproc *proc, struct instr *start, struct ins
// FIXME: we don't handle jumps backward yet
case IR_JUMP:
assert(ins->valtype == VT_LABEL);
- total += jmp(text, emitblock(NULL, proc, ins + 1, end, ins->val));
+ total += jmp(text, emitblock(NULL, proc, ins + 1, end, ins->val, active, curi));
NEXT;
break;
case IR_RETURN:
@@ -843,7 +841,7 @@ emitblock(struct data *text, struct iproc *proc, struct instr *start, struct ins
NEXT;
assert(ins->op == IR_EXTRA);
if (ins->val == tmp) {
- total += jne(text, emitblock(NULL, proc, ins + 1, end, label));
+ total += jne(text, emitblock(NULL, proc, ins + 1, end, label, active, curi));
}
NEXT;
}
@@ -987,5 +985,5 @@ done:
size_t
emitproc(struct data *text, struct iproc *proc)
{
- return emitblock(text, proc, NULL, NULL, 0);
+ return emitblock(text, proc, NULL, NULL, 0, 0, 0);
}