mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-21 02:32:06 +00:00
Some RGBLINK refactoring
- Consistently refer to `Section` fragments/unions as "pieces" (renaming `.nextu`) - Remove `Symbol`'s `.label()` accessors (use `std::get<Label>`) - Move some `Label`-related logic into `Symbol` methods
This commit is contained in:
@@ -90,3 +90,43 @@ void sym_TraceLocalAliasedSymbols(std::string const &name) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Symbol::linkToSection(Section §ion) {
|
||||
assume(std::holds_alternative<Label>(data));
|
||||
Label &label = std::get<Label>(data);
|
||||
// Link the symbol to the section
|
||||
label.section = §ion;
|
||||
// Link the section to the symbol, keeping the section's symbol list sorted
|
||||
uint32_t a = 0, b = section.symbols.size();
|
||||
while (a != b) {
|
||||
uint32_t c = (a + b) / 2;
|
||||
assume(std::holds_alternative<Label>(section.symbols[c]->data));
|
||||
Label const &other = std::get<Label>(section.symbols[c]->data);
|
||||
if (other.offset > label.offset) {
|
||||
b = c;
|
||||
} else {
|
||||
a = c + 1;
|
||||
}
|
||||
}
|
||||
section.symbols.insert(section.symbols.begin() + a, this);
|
||||
}
|
||||
|
||||
void Symbol::fixSectionOffset() {
|
||||
if (!std::holds_alternative<Label>(data)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Label &label = std::get<Label>(data);
|
||||
Section *section = label.section;
|
||||
assume(section);
|
||||
|
||||
if (section->modifier != SECTION_NORMAL) {
|
||||
// Associate the symbol with the main section, not the "piece"
|
||||
label.section = sect_GetSection(section->name);
|
||||
}
|
||||
if (section->modifier == SECTION_FRAGMENT) {
|
||||
// Add the fragment's offset to the symbol's
|
||||
// (`section->offset` is computed by `sect_AddSection`)
|
||||
label.offset += section->offset;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user