mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-20 10:12:06 +00:00
Use automatic allocation for section symbols
This commit is contained in:
@@ -48,7 +48,7 @@ struct Section {
|
|||||||
std::vector<struct Patch> patches;
|
std::vector<struct Patch> patches;
|
||||||
// Extra info computed during linking
|
// Extra info computed during linking
|
||||||
std::vector<struct Symbol> *fileSymbols;
|
std::vector<struct Symbol> *fileSymbols;
|
||||||
std::vector<struct Symbol *> *symbols;
|
std::vector<struct Symbol *> symbols;
|
||||||
struct Section *nextu; // The next "component" of this unionized sect
|
struct Section *nextu; // The next "component" of this unionized sect
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -356,18 +356,18 @@ static void readSection(FILE *file, struct Section *section, char const *fileNam
|
|||||||
*/
|
*/
|
||||||
static void linkSymToSect(struct Symbol &symbol, struct Section *section)
|
static void linkSymToSect(struct Symbol &symbol, struct Section *section)
|
||||||
{
|
{
|
||||||
uint32_t a = 0, b = section->symbols->size();
|
uint32_t a = 0, b = section->symbols.size();
|
||||||
|
|
||||||
while (a != b) {
|
while (a != b) {
|
||||||
uint32_t c = (a + b) / 2;
|
uint32_t c = (a + b) / 2;
|
||||||
|
|
||||||
if ((*section->symbols)[c]->offset > symbol.offset)
|
if (section->symbols[c]->offset > symbol.offset)
|
||||||
b = c;
|
b = c;
|
||||||
else
|
else
|
||||||
a = c + 1;
|
a = c + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
section->symbols->insert(section->symbols->begin() + a, &symbol);
|
section->symbols.insert(section->symbols.begin() + a, &symbol);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -499,10 +499,7 @@ void obj_ReadFile(char const *fileName, unsigned int fileID)
|
|||||||
fileSections[i]->nextu = NULL;
|
fileSections[i]->nextu = NULL;
|
||||||
readSection(file, fileSections[i], fileName, nodes[fileID]);
|
readSection(file, fileSections[i], fileName, nodes[fileID]);
|
||||||
fileSections[i]->fileSymbols = &fileSymbols;
|
fileSections[i]->fileSymbols = &fileSymbols;
|
||||||
fileSections[i]->symbols = new(std::nothrow) std::vector<struct Symbol *>();
|
fileSections[i]->symbols.reserve(nbSymPerSect[i]);
|
||||||
if (!fileSections[i]->symbols)
|
|
||||||
err("%s: Failed to link to symbols", fileName);
|
|
||||||
fileSections[i]->symbols->reserve(nbSymPerSect[i]);
|
|
||||||
|
|
||||||
sect_AddSection(fileSections[i]);
|
sect_AddSection(fileSections[i]);
|
||||||
}
|
}
|
||||||
@@ -574,7 +571,6 @@ static void freeSection(struct Section *section)
|
|||||||
|
|
||||||
if (sect_HasData(section->type))
|
if (sect_HasData(section->type))
|
||||||
delete section->data;
|
delete section->data;
|
||||||
delete section->symbols;
|
|
||||||
delete section;
|
delete section;
|
||||||
|
|
||||||
section = next;
|
section = next;
|
||||||
|
|||||||
@@ -335,7 +335,7 @@ static void writeSymBank(struct SortedSections const &bankSections,
|
|||||||
uint32_t nbSymbols = 0;
|
uint32_t nbSymbols = 0;
|
||||||
|
|
||||||
forEachSortedSection(sect, {
|
forEachSortedSection(sect, {
|
||||||
nbSymbols += sect->symbols->size();
|
nbSymbols += sect->symbols.size();
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!nbSymbols)
|
if (!nbSymbols)
|
||||||
@@ -346,7 +346,7 @@ static void writeSymBank(struct SortedSections const &bankSections,
|
|||||||
symList.reserve(nbSymbols);
|
symList.reserve(nbSymbols);
|
||||||
|
|
||||||
forEachSortedSection(sect, {
|
forEachSortedSection(sect, {
|
||||||
for (struct Symbol const *sym : *sect->symbols) {
|
for (struct Symbol const *sym : sect->symbols) {
|
||||||
// Don't output symbols that begin with an illegal character
|
// Don't output symbols that begin with an illegal character
|
||||||
if (!sym->name->empty() && canStartSymName((*sym->name)[0]))
|
if (!sym->name->empty() && canStartSymName((*sym->name)[0]))
|
||||||
symList.push_back({ .sym = sym, .addr = (uint16_t)(sym->offset + sect->org) });
|
symList.push_back({ .sym = sym, .addr = (uint16_t)(sym->offset + sect->org) });
|
||||||
@@ -416,7 +416,7 @@ static void writeMapBank(struct SortedSections const §List, enum SectionType
|
|||||||
if (!noSymInMap) {
|
if (!noSymInMap) {
|
||||||
// Also print symbols in the following "pieces"
|
// Also print symbols in the following "pieces"
|
||||||
for (uint16_t org = sect->org; sect; sect = sect->nextu) {
|
for (uint16_t org = sect->org; sect; sect = sect->nextu) {
|
||||||
for (struct Symbol *sym : *sect->symbols)
|
for (struct Symbol *sym : sect->symbols)
|
||||||
// Space matches "\tSECTION: $xxxx ..."
|
// Space matches "\tSECTION: $xxxx ..."
|
||||||
fprintf(mapFile, "\t $%04" PRIx32 " = %s\n",
|
fprintf(mapFile, "\t $%04" PRIx32 " = %s\n",
|
||||||
sym->offset + org, sym->name->c_str());
|
sym->offset + org, sym->name->c_str());
|
||||||
|
|||||||
@@ -340,10 +340,6 @@ void sdobj_ReadFile(struct FileStackNode const *where, FILE *file, std::vector<s
|
|||||||
// The array will be allocated if the section does contain data
|
// The array will be allocated if the section does contain data
|
||||||
curSection->data = NULL;
|
curSection->data = NULL;
|
||||||
curSection->fileSymbols = &fileSymbols; // IDs are instead per-section
|
curSection->fileSymbols = &fileSymbols; // IDs are instead per-section
|
||||||
curSection->symbols = new(std::nothrow) std::vector<struct Symbol *>();
|
|
||||||
if (!curSection->symbols)
|
|
||||||
fatal(where, lineNo, "Failed to alloc new area's symbol list: %s",
|
|
||||||
strerror(errno));
|
|
||||||
curSection->nextu = NULL;
|
curSection->nextu = NULL;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -409,7 +405,7 @@ void sdobj_ReadFile(struct FileStackNode const *where, FILE *file, std::vector<s
|
|||||||
fatal(where, lineNo, "'S' line is neither \"Def\" nor \"Ref\"");
|
fatal(where, lineNo, "'S' line is neither \"Def\" nor \"Ref\"");
|
||||||
|
|
||||||
if (!fileSections.empty())
|
if (!fileSections.empty())
|
||||||
fileSections.back().section->symbols->push_back(&symbol);
|
fileSections.back().section->symbols.push_back(&symbol);
|
||||||
|
|
||||||
expectEol("'S' line is too long");
|
expectEol("'S' line is too long");
|
||||||
break;
|
break;
|
||||||
@@ -730,7 +726,7 @@ void sdobj_ReadFile(struct FileStackNode const *where, FILE *file, std::vector<s
|
|||||||
|
|
||||||
if (section->modifier == SECTION_FRAGMENT) {
|
if (section->modifier == SECTION_FRAGMENT) {
|
||||||
// Add the fragment's offset to all of its symbols
|
// Add the fragment's offset to all of its symbols
|
||||||
for (struct Symbol *symbol : *section->symbols)
|
for (struct Symbol *symbol : section->symbols)
|
||||||
symbol->offset += section->offset;
|
symbol->offset += section->offset;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user