codegen working? pogU?
This commit is contained in:
parent
105c052e95
commit
2ca60ace59
|
|
@ -21,11 +21,9 @@ section .rdata
|
||||||
GLOBAL_LEN equ $ - GLOBAL_
|
GLOBAL_LEN equ $ - GLOBAL_
|
||||||
COLON_NL db ":", 10
|
COLON_NL db ":", 10
|
||||||
COLON_NL_LEN equ $ - COLON_NL
|
COLON_NL_LEN equ $ - COLON_NL
|
||||||
RET_NL db "ret", 10
|
|
||||||
RET_NL_LEN equ $ - RET_NL
|
|
||||||
PROLOGUE db "push rbp", 10, "mov rbp, rsp", 10
|
PROLOGUE db "push rbp", 10, "mov rbp, rsp", 10
|
||||||
PROLOGUE_LEN equ $ - PROLOGUE
|
PROLOGUE_LEN equ $ - PROLOGUE
|
||||||
EPILOGUE db "mov rsp, rbp", 10, "pop rbp", 10, "ret", 10
|
EPILOGUE db "pop rbp", 10, "ret", 10
|
||||||
EPILOGUE_LEN equ $ - EPILOGUE
|
EPILOGUE_LEN equ $ - EPILOGUE
|
||||||
MOV_RAX db "mov rax, "
|
MOV_RAX db "mov rax, "
|
||||||
MOV_RAX_LEN equ $ - MOV_RAX
|
MOV_RAX_LEN equ $ - MOV_RAX
|
||||||
|
|
@ -49,6 +47,8 @@ section .rdata
|
||||||
SUB_RSP_LEN equ $ - SUB_RSP
|
SUB_RSP_LEN equ $ - SUB_RSP
|
||||||
ADD_RSP db "add rsp, "
|
ADD_RSP db "add rsp, "
|
||||||
ADD_RSP_LEN equ $ - ADD_RSP
|
ADD_RSP_LEN equ $ - ADD_RSP
|
||||||
|
BODY db ".body:", 10
|
||||||
|
BODY_LEN equ $ - BODY
|
||||||
|
|
||||||
|
|
||||||
REGISTER_NAMES db "abcdsidibpspr8r9r10r11r12r13r14r15"
|
REGISTER_NAMES db "abcdsidibpspr8r9r10r11r12r13r14r15"
|
||||||
|
|
@ -359,6 +359,7 @@ codegen_function:
|
||||||
bts word [rsp + 72], 7 ; mark rsp as used
|
bts word [rsp + 72], 7 ; mark rsp as used
|
||||||
bts word [rsp + 72], 6 ; mark rbp as used
|
bts word [rsp + 72], 6 ; mark rbp as used
|
||||||
bts word [rsp + 72], 0 ; mark rax as used
|
bts word [rsp + 72], 0 ; mark rax as used
|
||||||
|
mov word [rsp + 76], 0 ; dirtied_register_bitset = 0
|
||||||
|
|
||||||
; push "section .text\n"
|
; push "section .text\n"
|
||||||
mov rdi, [rsp] ; ctx
|
mov rdi, [rsp] ; ctx
|
||||||
|
|
@ -442,9 +443,9 @@ codegen_function:
|
||||||
|
|
||||||
mov [rsp + 104], rsi ; scratch
|
mov [rsp + 104], rsi ; scratch
|
||||||
mov rax, [rsp + 24] ; current_stack_size
|
mov rax, [rsp + 24] ; current_stack_size
|
||||||
mov [rsp + 112], rax
|
|
||||||
add rax, 8 ; size_of::<u64>
|
add rax, 8 ; size_of::<u64>
|
||||||
mov [rsp + 24], rax ; current_stack_size += size_of::<u64>
|
mov [rsp + 24], rax ; current_stack_size += size_of::<u64>
|
||||||
|
mov [rsp + 112], rax
|
||||||
lea rdi, [rsp + 32] ; stack-vars
|
lea rdi, [rsp + 32] ; stack-vars
|
||||||
lea rsi, [rsp + 104] ; &scratch: &(index, offset)
|
lea rsi, [rsp + 104] ; &scratch: &(index, offset)
|
||||||
mov rdx, stackvar_cmp
|
mov rdx, stackvar_cmp
|
||||||
|
|
@ -472,6 +473,12 @@ codegen_function:
|
||||||
|
|
||||||
; "jmp .body\n"
|
; "jmp .body\n"
|
||||||
; ".body:\n"
|
; ".body:\n"
|
||||||
|
mov rdi, [rsp] ; ctx
|
||||||
|
lea rdi, [rdi + 8] ; &ctx.text
|
||||||
|
lea rsi, [rel BODY]
|
||||||
|
mov rdx, BODY_LEN
|
||||||
|
call vec_extend
|
||||||
|
|
||||||
|
|
||||||
mov rdi, [rsp] ; ctx
|
mov rdi, [rsp] ; ctx
|
||||||
lea rsi, [rsp + 24] ; &function_ctx
|
lea rsi, [rsp + 24] ; &function_ctx
|
||||||
|
|
@ -491,7 +498,7 @@ codegen_function:
|
||||||
mov rdi, [rsp] ; ctx
|
mov rdi, [rsp] ; ctx
|
||||||
lea rdi, [rdi + 8] ; &ctx.text
|
lea rdi, [rdi + 8] ; &ctx.text
|
||||||
lea rsi, [rsp + 24] ; &function_ctx
|
lea rsi, [rsp + 24] ; &function_ctx
|
||||||
mov rdx, 0 ; push = false
|
mov rdx, 1 ; pop = true
|
||||||
call codegen_push_pop_dirtied_registers
|
call codegen_push_pop_dirtied_registers
|
||||||
|
|
||||||
; "add rsp, {current_stack_size}\n"
|
; "add rsp, {current_stack_size}\n"
|
||||||
|
|
@ -508,13 +515,6 @@ codegen_function:
|
||||||
mov rcx, 10 ; radix
|
mov rcx, 10 ; radix
|
||||||
call int_to_str2
|
call int_to_str2
|
||||||
|
|
||||||
; ; push "\n"
|
|
||||||
; mov rdi, [rsp] ; ctx
|
|
||||||
; lea rdi, [rdi + 8] ; &ctx.text
|
|
||||||
; lea rsi, [rel COLON_NL]
|
|
||||||
; inc rsi
|
|
||||||
; call vec_push
|
|
||||||
|
|
||||||
mov rdi, [rsp] ; ctx
|
mov rdi, [rsp] ; ctx
|
||||||
lea rdi, [rdi + 8] ; &ctx.text
|
lea rdi, [rdi + 8] ; &ctx.text
|
||||||
lea rsi, [rax + rdx]
|
lea rsi, [rax + rdx]
|
||||||
|
|
@ -523,11 +523,19 @@ codegen_function:
|
||||||
mov rdx, rdx ; length from int_to_str2
|
mov rdx, rdx ; length from int_to_str2
|
||||||
call vec_extend
|
call vec_extend
|
||||||
|
|
||||||
|
; push "\n"
|
||||||
|
mov rdi, [rsp] ; ctx
|
||||||
|
lea rdi, [rdi + 8] ; &ctx.text
|
||||||
|
lea rsi, [rel COLON_NL]
|
||||||
|
inc rsi
|
||||||
|
call vec_push
|
||||||
|
|
||||||
|
; "pop rbp\n"
|
||||||
; "ret\n"
|
; "ret\n"
|
||||||
mov rdi, [rsp] ; ctx
|
mov rdi, [rsp] ; ctx
|
||||||
lea rdi, [rdi + 8] ; &ctx.text
|
lea rdi, [rdi + 8] ; &ctx.text
|
||||||
lea rsi, [rel RET_NL]
|
lea rsi, [rel EPILOGUE]
|
||||||
mov rdx, RET_NL_LEN
|
mov rdx, EPILOGUE_LEN
|
||||||
call vec_extend
|
call vec_extend
|
||||||
|
|
||||||
; ".prologue:\n"
|
; ".prologue:\n"
|
||||||
|
|
@ -551,13 +559,6 @@ codegen_function:
|
||||||
mov rcx, 10 ; radix
|
mov rcx, 10 ; radix
|
||||||
call int_to_str2
|
call int_to_str2
|
||||||
|
|
||||||
; ; push "\n"
|
|
||||||
; mov rdi, [rsp] ; ctx
|
|
||||||
; lea rdi, [rdi + 8] ; &ctx.text
|
|
||||||
; lea rsi, [rel COLON_NL]
|
|
||||||
; inc rsi
|
|
||||||
; call vec_push
|
|
||||||
|
|
||||||
mov rdi, [rsp] ; ctx
|
mov rdi, [rsp] ; ctx
|
||||||
lea rdi, [rdi + 8] ; &ctx.text
|
lea rdi, [rdi + 8] ; &ctx.text
|
||||||
lea rsi, [rax + rdx]
|
lea rsi, [rax + rdx]
|
||||||
|
|
@ -566,11 +567,18 @@ codegen_function:
|
||||||
mov rdx, rdx ; length from int_to_str2
|
mov rdx, rdx ; length from int_to_str2
|
||||||
call vec_extend
|
call vec_extend
|
||||||
|
|
||||||
|
; push "\n"
|
||||||
|
mov rdi, [rsp] ; ctx
|
||||||
|
lea rdi, [rdi + 8] ; &ctx.text
|
||||||
|
lea rsi, [rel COLON_NL]
|
||||||
|
inc rsi
|
||||||
|
call vec_push
|
||||||
|
|
||||||
; "push{dirtied registers}\n"
|
; "push{dirtied registers}\n"
|
||||||
mov rdi, [rsp] ; ctx
|
mov rdi, [rsp] ; ctx
|
||||||
lea rdi, [rdi + 8] ; &ctx.text
|
lea rdi, [rdi + 8] ; &ctx.text
|
||||||
lea rsi, [rsp + 24] ; &function_ctx
|
lea rsi, [rsp + 24] ; &function_ctx
|
||||||
mov rdx, 1 ; push = false
|
mov rdx, 0 ; pop = false
|
||||||
call codegen_push_pop_dirtied_registers
|
call codegen_push_pop_dirtied_registers
|
||||||
|
|
||||||
; "jmp .args\n"
|
; "jmp .args\n"
|
||||||
|
|
@ -594,7 +602,7 @@ codegen_function:
|
||||||
|
|
||||||
;; rdi: *text
|
;; rdi: *text
|
||||||
;; rsi: &function_ctx
|
;; rsi: &function_ctx
|
||||||
;; rdx: push: bool
|
;; rdx: pop: bool
|
||||||
codegen_push_pop_dirtied_registers:
|
codegen_push_pop_dirtied_registers:
|
||||||
push rbp
|
push rbp
|
||||||
mov rbp, rsp
|
mov rbp, rsp
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue