mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-20 18:22:07 +00:00
Use C++ iterator for fragment/union "pieces" of RGBLINK sections
This commit is contained in:
@@ -53,9 +53,9 @@ static void initFreeSpace() {
|
||||
static void assignSection(Section §ion, MemoryLocation const &location) {
|
||||
// Propagate the assigned location to all UNIONs/FRAGMENTs
|
||||
// so `jr` patches in them will have the correct offset
|
||||
for (Section *piece = §ion; piece != nullptr; piece = piece->nextPiece.get()) {
|
||||
piece->org = location.address;
|
||||
piece->bank = location.bank;
|
||||
for (Section &piece : section.pieces()) {
|
||||
piece.org = location.address;
|
||||
piece.bank = location.bank;
|
||||
}
|
||||
out_AddSection(section);
|
||||
}
|
||||
|
||||
@@ -251,8 +251,8 @@ void layout_PlaceSection(std::string const &name, bool isOptional) {
|
||||
);
|
||||
} else {
|
||||
// SDCC areas don't have a type assigned yet, so the linker script gives them one.
|
||||
for (Section *piece = section; piece != nullptr; piece = piece->nextPiece.get()) {
|
||||
piece->type = activeType;
|
||||
for (Section &piece : section->pieces()) {
|
||||
piece.type = activeType;
|
||||
}
|
||||
}
|
||||
} else if (section->type != activeType) {
|
||||
|
||||
@@ -317,13 +317,13 @@ static bool compareSymbols(SortedSymbol const &sym1, SortedSymbol const &sym2) {
|
||||
template<typename F>
|
||||
static void forEachSortedSection(SortedSections const &bankSections, F callback) {
|
||||
for (Section const *sect : bankSections.zeroLenSections) {
|
||||
for (; sect != nullptr; sect = sect->nextPiece.get()) {
|
||||
callback(*sect);
|
||||
for (Section const &piece : sect->pieces()) {
|
||||
callback(piece);
|
||||
}
|
||||
}
|
||||
for (Section const *sect : bankSections.sections) {
|
||||
for (; sect != nullptr; sect = sect->nextPiece.get()) {
|
||||
callback(*sect);
|
||||
for (Section const &piece : sect->pieces()) {
|
||||
callback(piece);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -433,31 +433,32 @@ uint16_t forEachSection(SortedSections const §List, F callback) {
|
||||
return used;
|
||||
}
|
||||
|
||||
static void writeMapSymbols(Section const *sect) {
|
||||
uint16_t org = sect->org;
|
||||
|
||||
for (bool announced = true; sect != nullptr; sect = sect->nextPiece.get(), announced = false) {
|
||||
for (Symbol *sym : sect->symbols) {
|
||||
static void writeMapSymbols(Section const §) {
|
||||
bool announced = true;
|
||||
for (Section const &piece : sect.pieces()) {
|
||||
for (Symbol *sym : piece.symbols) {
|
||||
// Don't output symbols that begin with an illegal character
|
||||
if (sym->name.empty() || !startsIdentifier(sym->name[0])) {
|
||||
continue;
|
||||
}
|
||||
// Announce this "piece" before its contents
|
||||
if (!announced) {
|
||||
if (sect->modifier == SECTION_UNION) {
|
||||
assume(sect.modifier == piece.modifier);
|
||||
if (sect.modifier == SECTION_UNION) {
|
||||
fputs("\t ; Next union\n", mapFile);
|
||||
} else if (sect->modifier == SECTION_FRAGMENT) {
|
||||
} else if (sect.modifier == SECTION_FRAGMENT) {
|
||||
fputs("\t ; Next fragment\n", mapFile);
|
||||
}
|
||||
announced = true;
|
||||
}
|
||||
assume(std::holds_alternative<Label>(sym->data));
|
||||
uint32_t address = std::get<Label>(sym->data).offset + org;
|
||||
uint32_t address = std::get<Label>(sym->data).offset + sect.org;
|
||||
// Space matches "\tSECTION: $xxxx ..."
|
||||
fprintf(mapFile, "\t $%04" PRIx32 " = ", address);
|
||||
writeSymName(sym->name, mapFile);
|
||||
putc('\n', mapFile);
|
||||
}
|
||||
announced = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -487,7 +488,7 @@ static void writeMapBank(SortedSections const §List, SectionType type, uint3
|
||||
|
||||
if (!options.noSymInMap) {
|
||||
// Also print symbols in the following "pieces"
|
||||
writeMapSymbols(§);
|
||||
writeMapSymbols(sect);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -586,8 +586,8 @@ static void applyPatches(Section §ion) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (Section *piece = §ion; piece != nullptr; piece = piece->nextPiece.get()) {
|
||||
applyFilePatches(*piece, section);
|
||||
for (Section &piece : section.pieces()) {
|
||||
applyFilePatches(piece, section);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user