Website Summary Files Commits Branches @commit @diff @stats
path: root / assembler / src / parser / code_gen.rs
diff options
context:
space:
mode:
Commit9c656c296827172589243d588f57f9ab2745efc6 (patch)
Author
 Syndamia <kamen@syndamia.com>
2025-02-14 08:50:49 +0200
Committer
 Syndamia <kamen@syndamia.com>
2025-02-14 08:50:49 +0200
Filesac637c6034d5e8e2dcb50f609b4b063ca7422add /assembler/src/parser/code_gen.rs
tonkobali-9c656c296827172589243d588f57f9ab2745efc6.tar
tonkobali-9c656c296827172589243d588f57f9ab2745efc6.tar.gz
tonkobali-9c656c296827172589243d588f57f9ab2745efc6.zip
Parent9517d3d05e86621b6c4ed58edd7f5821632e0872 (diff)
feat(assembler): Implement beq and mov instructions
1 files changed, 16 insertions, 0 deletions
-rw-r--r--assembler/src/parser/code_gen.rs16
diff --git a/assembler/src/parser/code_gen.rs b/assembler/src/parser/code_gen.rs
index 74a4fad..1c5b95a 100644
--- a/assembler/src/parser/code_gen.rs
+++ b/assembler/src/parser/code_gen.rs
@@ -5,6 +5,22 @@ impl Program {
/* Intermediate code generation */
pub(crate) fn collapse_instructions(&mut self) {
+ // Fix instruction addresses
+ let mut offsets = Vec::new();
+ for instr in &self.instructions {
+ offsets.push(instr.collapse_len() + offsets.last().unwrap_or(&0));
+ }
+ offsets.insert(0, 0);
+
+ for instr in &mut self.instructions {
+ for arg in &mut instr.args {
+ if let Address::Instruction(num) = arg {
+ *arg = Address::Instruction(offsets[*num]);
+ }
+ }
+ }
+
+ // Collapse all instructions
let mut collapsed = Vec::new();
for instr in &mut self.instructions {