0.5.0 -- tuples and more optimizations #12
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,5 +1,6 @@
|
||||
target
|
||||
*.ic10
|
||||
*.snap.new
|
||||
release
|
||||
csharp_mod/bin
|
||||
obj
|
||||
|
||||
@@ -1,33 +0,0 @@
|
||||
---
|
||||
source: libs/integration_tests/src/lib.rs
|
||||
assertion_line: 103
|
||||
expression: output
|
||||
---
|
||||
## Unoptimized Output
|
||||
|
||||
j main
|
||||
compute:
|
||||
pop r8
|
||||
push sp
|
||||
push ra
|
||||
move r9 20
|
||||
add r1 r8 1
|
||||
move r15 r1
|
||||
j __internal_L1
|
||||
__internal_L1:
|
||||
pop ra
|
||||
pop sp
|
||||
j ra
|
||||
|
||||
## Optimized Output
|
||||
|
||||
j main
|
||||
pop r8
|
||||
push sp
|
||||
push ra
|
||||
add r1 r8 1
|
||||
move r15 r1
|
||||
j 7
|
||||
pop ra
|
||||
pop sp
|
||||
j ra
|
||||
@@ -1,108 +0,0 @@
|
||||
---
|
||||
source: libs/integration_tests/src/lib.rs
|
||||
assertion_line: 173
|
||||
expression: output
|
||||
---
|
||||
## Unoptimized Output
|
||||
|
||||
j main
|
||||
add:
|
||||
pop r8
|
||||
pop r9
|
||||
push sp
|
||||
push ra
|
||||
add r1 r9 r8
|
||||
move r15 r1
|
||||
j __internal_L1
|
||||
__internal_L1:
|
||||
pop ra
|
||||
pop sp
|
||||
j ra
|
||||
multiply:
|
||||
pop r8
|
||||
pop r9
|
||||
push sp
|
||||
push ra
|
||||
mul r1 r9 2
|
||||
move r15 r1
|
||||
j __internal_L2
|
||||
__internal_L2:
|
||||
pop ra
|
||||
pop sp
|
||||
j ra
|
||||
complex:
|
||||
pop r8
|
||||
pop r9
|
||||
push sp
|
||||
push ra
|
||||
push r8
|
||||
push r9
|
||||
push r9
|
||||
push r8
|
||||
jal add
|
||||
pop r9
|
||||
pop r8
|
||||
move r10 r15
|
||||
push r8
|
||||
push r9
|
||||
push r10
|
||||
push r10
|
||||
push 2
|
||||
jal multiply
|
||||
pop r10
|
||||
pop r9
|
||||
pop r8
|
||||
move r11 r15
|
||||
move r15 r11
|
||||
j __internal_L3
|
||||
__internal_L3:
|
||||
pop ra
|
||||
pop sp
|
||||
j ra
|
||||
|
||||
## Optimized Output
|
||||
|
||||
j main
|
||||
pop r8
|
||||
pop r9
|
||||
push sp
|
||||
push ra
|
||||
add r1 r9 r8
|
||||
move r15 r1
|
||||
j 8
|
||||
pop ra
|
||||
pop sp
|
||||
j ra
|
||||
pop r9
|
||||
push sp
|
||||
push ra
|
||||
add r1 r9 r9
|
||||
move r15 r1
|
||||
j 17
|
||||
pop ra
|
||||
pop sp
|
||||
j ra
|
||||
pop r8
|
||||
pop r9
|
||||
push sp
|
||||
push ra
|
||||
push r8
|
||||
push r9
|
||||
push r9
|
||||
push r8
|
||||
jal 1
|
||||
pop r9
|
||||
pop r8
|
||||
move r10 r15
|
||||
push r8
|
||||
push r9
|
||||
push r10
|
||||
push r10
|
||||
push 2
|
||||
jal 11
|
||||
move r11 r15
|
||||
move r15 r11
|
||||
j 41
|
||||
pop ra
|
||||
pop sp
|
||||
j ra
|
||||
@@ -51,7 +51,7 @@ pub fn remove_redundant_jumps<'a>(
|
||||
) -> (Vec<InstructionNode<'a>>, bool) {
|
||||
let mut output = Vec::with_capacity(input.len());
|
||||
let mut changed = false;
|
||||
|
||||
|
||||
for (i, node) in input.iter().enumerate() {
|
||||
// Check if this is a jump to the next line number
|
||||
if let Instruction::Jump(Operand::Number(target)) = &node.instruction {
|
||||
@@ -64,7 +64,7 @@ pub fn remove_redundant_jumps<'a>(
|
||||
}
|
||||
output.push(node.clone());
|
||||
}
|
||||
|
||||
|
||||
(output, changed)
|
||||
}
|
||||
|
||||
|
||||
@@ -92,9 +92,9 @@ pub fn optimize<'a>(instructions: Instructions<'a>) -> Instructions<'a> {
|
||||
|
||||
// Final Pass: Resolve Labels to Line Numbers
|
||||
let mut instructions = resolve_labels(instructions);
|
||||
|
||||
|
||||
// Post-resolution Pass: Remove redundant jumps (must run after label resolution)
|
||||
let (instructions, _) = remove_redundant_jumps(instructions);
|
||||
|
||||
|
||||
Instructions::new(instructions)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user