diff options
author | Ben Bridle <ben@derelict.engineering> | 2024-11-06 07:19:23 +1300 |
---|---|---|
committer | Ben Bridle <ben@derelict.engineering> | 2024-11-06 07:19:23 +1300 |
commit | 0156ab9223dc9e942620519778b58d1a7e4e8001 (patch) | |
tree | 32b2b3a63ead7d1d843de902c8f23aa00848d163 | |
parent | 72b44ea280abafc2e4708abafbd2415861427b80 (diff) | |
download | bedrock-asm-0156ab9223dc9e942620519778b58d1a7e4e8001.zip |
Fix source merging order
The source unit merge order as of commit 1f25783 was merging head files
in the correct order to ensure that macro definitions were merged before
any references, but it didn't ensure that the main file of the root
source unit was merged before any other main files. This was, in some
cases, causing library code to be inserted before program metadata and
initialisation code in the assembled program.
This was fixed by using different merge orders for head files, and for
main and tail files.
-rw-r--r-- | src/symbol_resolver.rs | 16 |
1 files changed, 7 insertions, 9 deletions
diff --git a/src/symbol_resolver.rs b/src/symbol_resolver.rs index ab4f8e1..0b89fb1 100644 --- a/src/symbol_resolver.rs +++ b/src/symbol_resolver.rs @@ -196,7 +196,7 @@ impl SymbolResolver { // The ID of a given source unit will come after the IDs of all // source units which define at least one symbol referenced in the // given source unit. - let source_order = { + let head_order = { let mut included_source_ids: Vec<usize> = Vec::new(); let mut remaining_source_ids: Vec<usize> = Vec::new(); // Reverse the order so that the root unit is the last to be added. @@ -225,22 +225,20 @@ impl SymbolResolver { let mut source_code = String::new(); - // Push head source code. - for id in &source_order { + // Push head source code in macro-definition order. + for id in &head_order { let source_unit = &self.source_units[*id]; if let Some(head) = &source_unit.source_unit.head { push_source_code_to_string(&mut source_code, head); } } - // Push main source code. - for id in source_order.iter().rev() { - let source_unit = &self.source_units[*id]; + // Push main source code in source-added order. + for source_unit in self.source_units.iter() { let main = &source_unit.source_unit.main; push_source_code_to_string(&mut source_code, &main); } - // Push tail source code. - for id in &source_order { - let source_unit = &self.source_units[*id]; + // Push tail source code in reverse source-added order. + for source_unit in self.source_units.iter().rev() { if let Some(tail) = &source_unit.source_unit.tail { push_source_code_to_string(&mut source_code, tail); } |