updated compiler IR codegen. still broken but getting there. next job is figuring out how we handle Lvalues.

This commit is contained in:
2026-08-25 00:49:23 +01:00
parent 97e43b8b85
commit a130ef2cf6
6 changed files with 555 additions and 556 deletions
+51 -138
View File
@@ -1,138 +1,51 @@
// GENERATED BY DSC COMPILER
// Generated at 2026-08-21 19:34:30
// Imports
include alloc: "./lib/memory/block_alloc.dsa"
include print: "./lib/io/print.dsa"
// Globals & Reserved Memory
// Entry Point
dw stack: 0x010000
db message: "Process Exited with code:"
_init:
ldw stack, bpr, 0
mov bpr, spr
push zero
call main
call print::print_newline
lwi message, rg0
push rg0
call print::print
pop zero
call print::print_hex_word
pop zero
hlt
// Return
_ret:
mov bpr, spr
pop bpr
ret
db str_8: "successful free of ptr"
// fn main() -> u32
main:
push bpr
mov spr, bpr
lli 32, rg0
lli 64, rg1
// push arg 1
push rg0
// push arg 0
push rg1
call alloc::init
pop rg2
pop zero
push rg2
// push arg 0
push rg2
call print::print_hex_word
pop zero
call print::print_newline
ldw spr, rg0, 0
stw rg0, spr, 0
// push arg 0
push rg0
call alloc::alloc
pop rg1
push rg1
// push arg 0
push rg1
call print::print_hex_word
pop zero
lli 200, rg0
ldw spr, rg1, 0
stw rg0, rg1, 0
stw rg1, spr, 0
call print::print_newline
ldw spr, rg0, 4
stw rg0, spr, 4
// push arg 0
push rg0
call alloc::alloc
pop rg2
push rg2
// push arg 0
push rg2
call print::print_hex_word
pop zero
call print::print_newline
ldw spr, rg0, 4
ldw rg0, rg2, 0
stw rg0, spr, 4
// push arg 0
push rg2
call print::print_num
pop zero
ldw spr, rg2, 4
stw rg2, spr, 4
addi spr, 4, rg3
ldw spr, rg2, 8
stw rg2, spr, 8
// push arg 1
push rg3
// push arg 0
push rg2
call alloc::free
pop zero
pop zero
ldw spr, rg2, 8
stw rg2, spr, 8
// push arg 0
push rg2
call alloc::alloc
pop rg3
push rg3
call print::print_newline
ldw spr, rg2, 0
stw rg2, spr, 0
// push arg 0
push rg2
call print::print_hex_word
pop zero
call print::print_newline
ldw spr, rg2, 8
stw rg2, spr, 8
// push arg 0
push rg2
call print::print_hex_word
pop zero
ldw spr, rg2, 8
lli 0, rg4
ieq rg2, rg4, rg5
jez rg5, _else_6
_then_5:
lwi str_8, rg4
stw rg2, spr, 8
// push arg 0
push rg4
call print::print
pop zero
jmp _end_7
_else_6:
nop
_end_7:
lli 0, rg4
stw rg4, bpr, 8
jmp _ret
fn main() {
__main_0:
v1 = literal 64
v2 = literal 32
v0_allocator = alloc::init(v1, v2)
v3 = copy v0_allocator
_v = print::print_hex_word(v3)
_v = print::print_newline()
v5 = copy v0_allocator
v4_ptr = alloc::alloc(v5)
v6 = copy v4_ptr
_v = print::print_hex_word(v6)
v7 = copy v4_ptr
v8 = literal 200
store v7, v8
_v = print::print_newline()
v10 = copy v0_allocator
v9_p2 = alloc::alloc(v10)
v11 = copy v9_p2
_v = print::print_hex_word(v11)
_v = print::print_newline()
v13 = copy v4_ptr
v12 = load v13
_v = print::print_num(v12)
v14 = copy v0_allocator
v16 = copy v4_ptr
no-op
_v = alloc::free(v14, v15)
v18 = copy v0_allocator
v17_ptr3 = alloc::alloc(v18)
_v = print::print_newline()
v19 = copy v17_ptr3
_v = print::print_hex_word(v19)
_v = print::print_newline()
v20 = copy v4_ptr
_v = print::print_hex_word(v20)
v22 = copy v4_ptr
v23 = literal 0
v21 = v22 == v23
if v21 then __then_2 else __else_2
__then_2:
_v = print::print(v24)
jump __endif_2
__else_2:
jump __endif_2
__endif_2:
v25 = literal 0
return v25
__unreachable_3:
return
}