diff options
| Commit | ef23f004b131588e6c4a7c20d4f4fafb88292fb9 (patch) | |
|---|---|---|
| Author | 2025-02-13 23:06:51 +0200 | |
| Committer | 2025-02-13 23:06:51 +0200 | |
| Files | 65193b1f4eec511ac47ebc36fa24ed8cdd3073a3 /assembler/src/parser/code_gen.rs | |
| tonkobali-ef23f004b131588e6c4a7c20d4f4fafb88292fb9.tar tonkobali-ef23f004b131588e6c4a7c20d4f4fafb88292fb9.tar.gz tonkobali-ef23f004b131588e6c4a7c20d4f4fafb88292fb9.zip | ||
| Parent | 0e5324f0b0cb01f624bd28ff5b8a646000d33c96 (diff) | |
feat(assembler): Generate data step
1 files changed, 23 insertions, 1 deletions
| -rw-r--r-- | assembler/src/parser/code_gen.rs | 24 |
diff --git a/assembler/src/parser/code_gen.rs b/assembler/src/parser/code_gen.rs index dd1b872..77f2c2f 100644 --- a/assembler/src/parser/code_gen.rs +++ b/assembler/src/parser/code_gen.rs @@ -1,6 +1,9 @@ -use super::{ Program, Address, Instruction }; +use crate::Word; +use super::{ Program, Address }; impl Program { + /* Intermediate code generation */ + pub(crate) fn remove_definition_addresses(&mut self) { for instr in &mut self.instructions { for arg in &mut instr.args { @@ -9,6 +12,7 @@ impl Program { } } } + self.definitions.clear(); } pub(crate) fn collapse_instructions(&mut self) { @@ -30,4 +34,22 @@ impl Program { self.instructions = collapsed; } + + /* Machine code generation */ + + pub(crate) fn instructions_to_constants(&mut self, absolute_start: usize) { + let constlen = self.constants.len(); + + for instr in &mut self.instructions { + for arg in &mut instr.args { + self.constants.push(match arg { + Address::Memory(num) => *num, + Address::Constants(num) => absolute_start + *num, + Address::Instruction(num) => constlen + absolute_start + *num, + _ => unreachable!("Definition addresses should've already been removed!"), + } as Word); + } + } + self.instructions.clear(); + } } |
