Added more optimizations in regards to function invocations and backing

up and restoring registers
This commit is contained in:
2025-12-17 21:05:01 -07:00
parent ecfed65221
commit 6b18489f54
7 changed files with 108 additions and 91 deletions

View File

@@ -5,7 +5,12 @@ use pretty_assertions::assert_eq;
fn test_function_declaration_with_spillover_params() -> anyhow::Result<()> {
let compiled = compile!(debug r#"
// we need more than 4 params to 'spill' into a stack var
fn doSomething(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) {};
fn doSomething(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) {
return arg1 + arg2 + arg3 + arg4 + arg5 + arg6 + arg7 + arg8 + arg9;
};
let item1 = 1;
let returned = doSomething(item1, 2, 3, 4, 5, 6, 7, 8, 9);
"#);
assert_eq!(
@@ -21,11 +26,39 @@ fn test_function_declaration_with_spillover_params() -> anyhow::Result<()> {
pop r13
pop r14
push ra
sub r0 sp 3
get r1 db r0
sub r0 sp 2
get r2 db r0
add r3 r1 r2
add r4 r3 r14
add r5 r4 r13
add r6 r5 r12
add r7 r6 r11
add r1 r7 r10
add r2 r1 r9
add r3 r2 r8
move r15 r3
j __internal_L1
__internal_L1:
sub r0 sp 1
get ra db r0
sub sp sp 3
pop ra
sub sp sp 2
j ra
main:
move r8 1
push r8
push r8
push 2
push 3
push 4
push 5
push 6
push 7
push 8
push 9
jal doSomething
pop r8
move r9 r15
"}
);
@@ -60,9 +93,7 @@ fn test_early_return() -> anyhow::Result<()> {
move r8 3
j __internal_L1
__internal_L1:
sub r0 sp 1
get ra db r0
sub sp sp 1
pop ra
j ra
main:
jal doSomething
@@ -91,9 +122,7 @@ fn test_function_declaration_with_register_params() -> anyhow::Result<()> {
pop r9
push ra
__internal_L1:
sub r0 sp 1
get ra db r0
sub sp sp 1
pop ra
j ra
"}
);