diff options
| Commit | 0e5324f0b0cb01f624bd28ff5b8a646000d33c96 (patch) | |
|---|---|---|
| Author | 2025-02-13 22:40:13 +0200 | |
| Committer | 2025-02-13 22:40:13 +0200 | |
| Files | c90bea68ca0ee94f9cfe190bcda2b9cd78e6a56e /assembler/src/parser/code_gen.rs | |
| tonkobali-0e5324f0b0cb01f624bd28ff5b8a646000d33c96.tar tonkobali-0e5324f0b0cb01f624bd28ff5b8a646000d33c96.tar.gz tonkobali-0e5324f0b0cb01f624bd28ff5b8a646000d33c96.zip | ||
| Parent | d17f1356cbe20f8c464668c74a2eb005643b80ba (diff) | |
feat(assembler): Add instruction collapse code gen step
1 files changed, 21 insertions, 1 deletions
| -rw-r--r-- | assembler/src/parser/code_gen.rs | 22 |
diff --git a/assembler/src/parser/code_gen.rs b/assembler/src/parser/code_gen.rs index 375a8cb..dd1b872 100644 --- a/assembler/src/parser/code_gen.rs +++ b/assembler/src/parser/code_gen.rs @@ -1,4 +1,4 @@ -use super::{ Program, Address }; +use super::{ Program, Address, Instruction }; impl Program { pub(crate) fn remove_definition_addresses(&mut self) { @@ -10,4 +10,24 @@ impl Program { } } } + + pub(crate) fn collapse_instructions(&mut self) { + let mut collapsed = Vec::new(); + let mut update_addrs = Vec::new(); + + for instr in &mut self.instructions { + update_addrs.push(collapsed.len()); + collapsed.extend(instr.collapse()); + } + + for instr in &mut self.instructions { + for arg in &mut instr.args { + if let Address::Instruction(num) = arg { + *arg = Address::Instruction(update_addrs[*num]); + } + } + } + + self.instructions = collapsed; + } } |
