diff options
author | Ben Bridle <bridle.benjamin@gmail.com> | 2024-10-30 14:48:10 +1300 |
---|---|---|
committer | Ben Bridle <bridle.benjamin@gmail.com> | 2024-10-30 15:40:25 +1300 |
commit | 6cc0bec0e11d5fec757e90aebd7e51ed9393365c (patch) | |
tree | 9561c5a940db2389163ce62ba419c7821bc693a6 /src/gather_libraries.rs | |
parent | 2cd0c86659479774d092de727e0f0c31e27e49f2 (diff) | |
download | bedrock-asm-6cc0bec0e11d5fec757e90aebd7e51ed9393365c.zip |
Implement an intelligent source merging strategy
The previous source merging strategy was to concatenate source units
in the reverse order that they were added to the resolver, which
generally only worked when each source unit had at most one
macro-resolving parent.
An issue arose when some macros in a source unit were resolved by a
source unit which had been added earlier in the order, as the required
macro definitions would then be merged after they were referenced,
preventing the program from assembling.
The new source merging strategy finds an optimal merge order by first
recording for a given source unit the ID of each unit which resolves a
macro referenced by the given unit, and then only merging those source
units whose macro-defining dependencies have already been merged. In the
case that a cycle is detected, where two or more source units depend on
one another, a message is printed and the assembly is aborted.
Diffstat (limited to 'src/gather_libraries.rs')
-rw-r--r-- | src/gather_libraries.rs | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/src/gather_libraries.rs b/src/gather_libraries.rs index 0b5d2a6..0fd1131 100644 --- a/src/gather_libraries.rs +++ b/src/gather_libraries.rs @@ -117,15 +117,19 @@ fn parse_symbols_from_source(source_code: String, path: Option<&Path>) -> Symbol let mut references = Vec::new(); for token in token_iter { + let source = token.source; match token.variant { SynVar::LabelDefinition(name) => { - definitions.push(Symbol { name, source: token.source }); + let variant = SymbolVariant::LabelDefinition; + definitions.push(Symbol { name, source, variant }); }, SynVar::MacroDefinition(name) => { - definitions.push(Symbol { name, source: token.source }); + let variant = SymbolVariant::MacroDefinition; + definitions.push(Symbol { name, source, variant }); } SynVar::Symbol(name) => { - references.push(Symbol { name, source: token.source }); + let variant = SymbolVariant::Reference; + references.push(Symbol { name, source, variant }); }, _ => (), } @@ -181,5 +185,14 @@ pub struct Symbols { pub struct Symbol { pub name: String, + pub variant: SymbolVariant, pub source: SourceSpan, } + + +#[derive(PartialEq)] +pub enum SymbolVariant { + LabelDefinition, + MacroDefinition, + Reference, +} |