From b469d0595321c44723075632fa5414d2339cc629 Mon Sep 17 00:00:00 2001 From: Ben Bridle Date: Mon, 9 Nov 2026 16:21:17 +1300 Subject: Add support for disjoint fields in word templates The AVR instruction set requires that fields in some instructions are split across multiple ranges, requiring words that look like: #0001_11rd_dddd_rrrr This commit makes it possible to define fields with this syntax. The syntactic error DuplicateFieldNameInWord has been removed. --- src/stages/syntactic.rs | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'src/stages/syntactic.rs') diff --git a/src/stages/syntactic.rs b/src/stages/syntactic.rs index a65faf9..9635c83 100644 --- a/src/stages/syntactic.rs +++ b/src/stages/syntactic.rs @@ -250,17 +250,17 @@ fn parse_word_template(mut t: Tokeniser) -> Result> = Vec::new(); + let mut fields: Vec = Vec::new(); let mut errors: Vec> = Vec::new(); macro_rules! push_field { () => { - if fields.iter().any(|f| f.name == field_name) { - let error = SyntacticError::DuplicateFieldNameInWord(field_name); - errors.push(Tracked::from(error, t.get_source())); + let range = BitRange { width: field_width, shift: 0 }; + let tracked = Tracked::from(range, t.get_source()); + if let Some(field) = fields.iter_mut().find(|f| f.name == field_name) { + field.ranges.push(tracked); } else { - let field = BitField { name: field_name, width: field_width, shift: 0}; - fields.push(Tracked::from(field, t.get_source())); + fields.push(BitField { name: field_name, ranges: vec![tracked]}); } }; } @@ -276,7 +276,9 @@ fn parse_word_template(mut t: Tokeniser) -> Result Result 0 { t.mark_end(); -- cgit v1.3.1