diff --git a/lang/src/codegen.asm b/lang/src/codegen.asm index 087614d..04bb712 100644 --- a/lang/src/codegen.asm +++ b/lang/src/codegen.asm @@ -358,7 +358,7 @@ codegen_allocate_value: mov rsi, [rsp + 8] ; width or eax, esi ; Operand.width shl eax, 4 - or eax, rbx ; Operand.register + or eax, ebx ; Operand.register shl eax, 8 or eax, OPERAND_REGISTER ; Operand.kind mov rdx, 0 ; Operand.value = 0 @@ -923,6 +923,10 @@ codegen_expr: lea rdx, [rsp + 16] ; src call codegen_move_dst_src + mov rdi, [rsp + 8] ; &function_ctx + lea rsi, [rsp + 16] ; src + call codegen_free_operand + ; push "jmp .epilogue\n" mov rdi, [rsp] ; ctx lea rdi, [rdi + 8] ; &ctx.text @@ -945,25 +949,20 @@ codegen_expr: .number: ; rax = *AstNode mov [rsp + 16], rax ; scratch = *AstNode - mov rbx, [rax + 8] ; AstNode.data = value - mov [rsp + 40], rbx ; Operand.value - mov rdi, [rsp + 8] ; &function_ctx - call codegen_allocate_register - - xor rbx, rbx - or rbx, 8 ; width = 8 - shl rbx, 4 - or rbx, rax ; register - shl rbx, 8 - or rbx, OPERAND_REGISTER ; kind - mov [rsp + 16], rbx ; - mov qword [rsp + 24], 0 ; value = 0 mov byte [rsp + 32], OPERAND_IMMEDIATE ; Operand.kind mov bl, 8 ; width = 8 shl bl, 4 ; register = undef mov byte [rsp + 33], bl ; Operand.register_and_width mov word [rsp + 34], 0 ; Operand.len = 0 + mov rbx, [rax + 8] ; AstNode.data + mov [rsp + 40], rbx ; Operand.value + + mov rdi, [rsp + 8] ; &function_ctx + mov rsi, 8 ; width + call codegen_allocate_value + mov [rsp + 16], rax + mov [rsp + 24], rdx mov rdi, [rsp] ; ctx lea rdi, [rdi + 8] ; &ctx.text diff --git a/lang/tests/shared/defs.rs b/lang/tests/shared/defs.rs index 51f9e0b..9624c7a 100644 --- a/lang/tests/shared/defs.rs +++ b/lang/tests/shared/defs.rs @@ -20,6 +20,8 @@ unsafe extern "C" { pub unsafe fn get_register_name(reg_idx: u8, width: u8, buffer: *mut u8) -> FFISlice; pub unsafe fn stackvar_cmp(a: *const (u64, u64), b: *const (u64, u64)) -> i32; pub unsafe fn codegen_allocate_register(ctx: *mut FunctionCtx) -> u8; + pub unsafe fn codegen_allocate_value(ctx: *mut FunctionCtx, width: u16) -> Operand; + pub unsafe fn codegen_free_operand(ctx: *mut FunctionCtx, operand: *const Operand) -> (); pub unsafe fn codegen_function(ast: *const CodegenCtx, func_idx: u64) -> (); pub unsafe fn codegen_expr(ctx: *const CodegenCtx, function_ctx: &FunctionCtx, expr_idx: u64) -> (u64, bool); pub unsafe fn vec_insert_many(vec: *mut BlobVec, index: usize, data: *const u8, count: usize);