Skip to content

Commit f4f4e70

Browse files
Backend/Z80: Refactor checks to support macros, and add a function to collect bytes into an array to improve memory efficiency
1 parent 084a1c6 commit f4f4e70

2 files changed

Lines changed: 260 additions & 193 deletions

File tree

backend/z80/src/assembler.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,20 @@ use std::collections::VecDeque;
33

44
pub struct Assembler<InputType: Iterator<Item = Instruction<u8, u16, i32, i8>>> {
55
input: InputType,
6+
enable_macro_instructions: bool,
67
enable_undocumented_instructions: bool,
78
has_error_occured: bool,
89
queue: VecDeque<u8>,
910
}
1011

1112
impl<InputType: Iterator<Item = Instruction<u8, u16, i32, i8>>> Assembler<InputType> {
12-
pub fn new(input: InputType, enable_undocumented_instructions: bool) -> Self {
13+
pub fn new(input: InputType,
14+
enable_macro_instructions: bool,
15+
enable_undocumented_instructions: bool
16+
) -> Self {
1317
Self {
1418
input: input,
19+
enable_macro_instructions: enable_macro_instructions,
1520
enable_undocumented_instructions: enable_undocumented_instructions,
1621
has_error_occured: false,
1722
queue: VecDeque::with_capacity(4),
@@ -158,6 +163,10 @@ impl<InputType: Iterator<Item = Instruction<u8, u16, i32, i8>>> Assembler<InputT
158163
}};
159164
}
160165

166+
if !self.enable_macro_instructions {
167+
return self.convert_real_instruction(inst);
168+
}
169+
161170
match inst {
162171
| LD(arg, AddressRegister(IX)) => parse!(
163172
LD(arg, AddressRegisterWithOffset(IX, 0))
@@ -846,6 +855,11 @@ impl<InputType: Iterator<Item = Instruction<u8, u16, i32, i8>>> Assembler<InputT
846855
}
847856
}
848857
}
858+
859+
pub fn clear_and_collect_into(&mut self, collection: &mut Vec<u8>) {
860+
collection.clear();
861+
collection.extend(self);
862+
}
849863
}
850864

851865
impl<InputType: Iterator<Item = Instruction<u8, u16, i32, i8>>> Iterator for Assembler<InputType> {

0 commit comments

Comments
 (0)