From 5b1f387d451b3ff136464dcbc71f0c2310a57d01 Mon Sep 17 00:00:00 2001 From: Miquel Sabaté Solà Date: Wed, 17 Jul 2024 16:06:34 +0200 Subject: Add basic support for macros MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Macros can now be described with the '.macro' control statement, but no parameters can be given and it's overall pretty brittle. Signed-off-by: Miquel Sabaté Solà --- lib/xixanta/src/mapping.rs | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) (limited to 'lib/xixanta/src/mapping.rs') diff --git a/lib/xixanta/src/mapping.rs b/lib/xixanta/src/mapping.rs index d2f1410..231883f 100644 --- a/lib/xixanta/src/mapping.rs +++ b/lib/xixanta/src/mapping.rs @@ -5,6 +5,12 @@ use crate::errors::ParseError; type Result = std::result::Result; lazy_static! { + pub static ref EMPTY: Vec = vec![Segment { + name: String::from("CODE"), + start: 0x0000, + size: 0xFFFF, + fill: None, + }]; pub static ref NROM: Vec = vec![ Segment { name: String::from("HEADER"), @@ -46,6 +52,8 @@ pub struct Mapping { pub segments: Vec, pub nodes: HashMap>, pub current: String, + pub macros: HashMap>, + pub current_macro: Option, } impl Mapping { @@ -63,11 +71,21 @@ impl Mapping { segments, nodes, current: current_segment.to_string(), + macros: HashMap::new(), + current_macro: None, } } pub fn reset(&mut self) { - // TODO + self.nodes = HashMap::new(); + for segment in self.segments.iter() { + self.nodes.insert(segment.name.clone(), vec![]); + } + + self.current = self.segments.first().unwrap().name.clone(); + + self.macros = HashMap::new(); + self.current_macro = None; } pub fn switch(&mut self, id: &PString) -> Result<()> { @@ -90,6 +108,9 @@ impl Mapping { } pub fn push(&mut self, node: Node) { - self.nodes.get_mut(&self.current).unwrap().push(node); + match &self.current_macro { + Some(m) => self.macros.get_mut(m).unwrap().push(node), + None => self.nodes.get_mut(&self.current).unwrap().push(node), + } } } -- cgit v1.2.3