1
0
mirror of https://github.com/janet-lang/janet synced 2025-02-03 10:49:09 +00:00

Don't assign variables positions on the stack that clobber import info.

(return address, previous basepoint, etc.)
This commit is contained in:
Calvin Rose 2024-06-16 10:06:22 -05:00
parent dfdf734fc7
commit c413bc2b4e
2 changed files with 10 additions and 13 deletions

View File

@ -19,8 +19,8 @@
(set i (the int (+ 1 i)))
(printf "i = %d\n" i))
(printf "hello, world!\n%d\n" (the int (if x abc xyz)))
(return (* abc xyz))))
#(return (the int (simple (* abc xyz))))))
#(return (* abc xyz))))
(return (the int (simple (* abc xyz))))))
(def doloop
'(defn doloop [x:int y:int]

View File

@ -168,7 +168,7 @@ void assign_registers(JanetSysx64Context *ctx) {
/* TODO - move into sysir.c and allow reuse for multiple targets */
/* Make trivial assigments */
uint32_t next_loc = 0;
uint32_t next_loc = 16;
ctx->regs = janet_smalloc(ctx->ir->register_count * sizeof(x64Reg));
uint32_t assigned = 0;
uint32_t occupied = 0;
@ -193,7 +193,7 @@ void assign_registers(JanetSysx64Context *ctx) {
assigned |= 1 << ctx->regs[i].index;
occupied |= 1 << ctx->regs[i].index;
}
} else if (assigned < 0xFFFF) { /* skip r15 so we have some temporary registers if needed */
} else if (assigned < 0xFFFF) {
/* Assign to register */
uint32_t to = 0;
while ((1 << to) & assigned) to++;
@ -487,7 +487,6 @@ void janet_sys_ir_lower_to_x64(JanetSysIRLinkage *linkage, JanetBuffer *buffer)
ctx.ir_layouts[i] = ctx.layouts[ir->types[i]];
}
ctx.ir = ir;
//janet_assert(ir->register_count, "non-zero register count");
assign_registers(&ctx);
/* Emit prelude */
@ -631,13 +630,11 @@ void janet_sys_ir_lower_to_x64(JanetSysIRLinkage *linkage, JanetBuffer *buffer)
janet_formatb(buffer, "syscall\n");
} else {
/* Save RAX to number of floating point args for varags - for now, always 0 :) */
sysemit_pushreg(&ctx, RAX);
janet_formatb(buffer, "mov rax, 0\n");
janet_formatb(buffer, "call ");
sysemit_operand(&ctx, instruction.call.callee, "\n");
}
if (instruction.call.flags & JANET_SYS_CALLFLAG_HAS_DEST) sysemit_movreg(&ctx, RAX, instruction.call.dest);
if (instruction.opcode != JANET_SYSOP_SYSCALL) sysemit_popreg(&ctx, RAX);
if (save_r11) sysemit_popreg(&ctx, 11);
if (save_r10) sysemit_popreg(&ctx, 10);
if (save_r9) sysemit_popreg(&ctx, 9);