diff options
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(); + } } |
