mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-21 18:52:07 +00:00
Remove now-unnecessary struct keyword (#1320)
C++ acts like structs are `typedef`ed by default We do have to keep `struct stat`, since there's ambiguity with the function also called `stat`.
This commit is contained in:
@@ -27,11 +27,11 @@ struct MemoryLocation {
|
||||
struct FreeSpace {
|
||||
uint16_t address;
|
||||
uint16_t size;
|
||||
struct FreeSpace *next, *prev;
|
||||
FreeSpace *next, *prev;
|
||||
};
|
||||
|
||||
// Table of free space for each bank
|
||||
struct FreeSpace *memory[SECTTYPE_INVALID];
|
||||
FreeSpace *memory[SECTTYPE_INVALID];
|
||||
|
||||
uint64_t nbSectionsToAssign;
|
||||
|
||||
@@ -39,13 +39,13 @@ uint64_t nbSectionsToAssign;
|
||||
static void initFreeSpace(void)
|
||||
{
|
||||
for (enum SectionType type : EnumSeq(SECTTYPE_INVALID)) {
|
||||
memory[type] = (struct FreeSpace *)malloc(sizeof(*memory[type]) * nbbanks(type));
|
||||
memory[type] = (FreeSpace *)malloc(sizeof(*memory[type]) * nbbanks(type));
|
||||
if (!memory[type])
|
||||
err("Failed to init free space for region %d", type);
|
||||
|
||||
for (uint32_t bank = 0; bank < nbbanks(type); bank++) {
|
||||
memory[type][bank].next =
|
||||
(struct FreeSpace *)malloc(sizeof(*memory[type][0].next));
|
||||
(FreeSpace *)malloc(sizeof(*memory[type][0].next));
|
||||
if (!memory[type][bank].next)
|
||||
err("Failed to init free space for region %d bank %" PRIu32,
|
||||
type, bank);
|
||||
@@ -62,14 +62,14 @@ static void initFreeSpace(void)
|
||||
* @param section The section to assign
|
||||
* @param location The location to assign the section to
|
||||
*/
|
||||
static void assignSection(struct Section *section, struct MemoryLocation const *location)
|
||||
static void assignSection(Section *section, MemoryLocation const *location)
|
||||
{
|
||||
section->org = location->address;
|
||||
section->bank = location->bank;
|
||||
|
||||
// Propagate the assigned location to all UNIONs/FRAGMENTs
|
||||
// so `jr` patches in them will have the correct offset
|
||||
for (struct Section *next = section->nextu; next != NULL; next = next->nextu) {
|
||||
for (Section *next = section->nextu; next != NULL; next = next->nextu) {
|
||||
next->org = section->org;
|
||||
next->bank = section->bank;
|
||||
}
|
||||
@@ -88,9 +88,8 @@ static void assignSection(struct Section *section, struct MemoryLocation const *
|
||||
* @param location The location to attempt placing the section at
|
||||
* @return True if the location is suitable, false otherwise.
|
||||
*/
|
||||
static bool isLocationSuitable(struct Section const *section,
|
||||
struct FreeSpace const *freeSpace,
|
||||
struct MemoryLocation const *location)
|
||||
static bool isLocationSuitable(Section const *section, FreeSpace const *freeSpace,
|
||||
MemoryLocation const *location)
|
||||
{
|
||||
if (section->isAddressFixed && section->org != location->address)
|
||||
return false;
|
||||
@@ -108,12 +107,11 @@ static bool isLocationSuitable(struct Section const *section,
|
||||
/*
|
||||
* Finds a suitable location to place a section at.
|
||||
* @param section The section to be placed
|
||||
* @param location A pointer to a location struct that will be filled
|
||||
* @param location A pointer to a memory location that will be filled
|
||||
* @return A pointer to the free space encompassing the location, or NULL if
|
||||
* none was found
|
||||
*/
|
||||
static struct FreeSpace *getPlacement(struct Section const *section,
|
||||
struct MemoryLocation *location)
|
||||
static FreeSpace *getPlacement(Section const *section, MemoryLocation *location)
|
||||
{
|
||||
static uint16_t curScrambleROM = 0;
|
||||
static uint8_t curScrambleWRAM = 0;
|
||||
@@ -137,7 +135,7 @@ static struct FreeSpace *getPlacement(struct Section const *section,
|
||||
} else {
|
||||
location->bank = sectionTypeInfo[section->type].firstBank;
|
||||
}
|
||||
struct FreeSpace *space;
|
||||
FreeSpace *space;
|
||||
|
||||
for (;;) {
|
||||
// Switch to the beginning of the next bank
|
||||
@@ -226,9 +224,9 @@ static struct FreeSpace *getPlacement(struct Section const *section,
|
||||
* sections of decreasing size.
|
||||
* @param section The section to place
|
||||
*/
|
||||
static void placeSection(struct Section *section)
|
||||
static void placeSection(Section *section)
|
||||
{
|
||||
struct MemoryLocation location;
|
||||
MemoryLocation location;
|
||||
|
||||
// Specially handle 0-byte SECTIONs, as they can't overlap anything
|
||||
if (section->size == 0) {
|
||||
@@ -246,7 +244,7 @@ static void placeSection(struct Section *section)
|
||||
|
||||
// Place section using first-fit decreasing algorithm
|
||||
// https://en.wikipedia.org/wiki/Bin_packing_problem#First-fit_algorithm
|
||||
struct FreeSpace *freeSpace = getPlacement(section, &location);
|
||||
FreeSpace *freeSpace = getPlacement(section, &location);
|
||||
|
||||
if (freeSpace) {
|
||||
assignSection(section, &location);
|
||||
@@ -266,7 +264,7 @@ static void placeSection(struct Section *section)
|
||||
free(freeSpace);
|
||||
} else if (!noLeftSpace && !noRightSpace) {
|
||||
// The free space is split in two
|
||||
struct FreeSpace *newSpace = (struct FreeSpace *)malloc(sizeof(*newSpace));
|
||||
FreeSpace *newSpace = (FreeSpace *)malloc(sizeof(*newSpace));
|
||||
|
||||
if (!newSpace)
|
||||
err("Failed to split new free space");
|
||||
@@ -334,14 +332,14 @@ static void placeSection(struct Section *section)
|
||||
#define BANK_CONSTRAINED (1 << 2)
|
||||
#define ORG_CONSTRAINED (1 << 1)
|
||||
#define ALIGN_CONSTRAINED (1 << 0)
|
||||
static std::deque<struct Section *> unassignedSections[1 << 3];
|
||||
static std::deque<Section *> unassignedSections[1 << 3];
|
||||
|
||||
/*
|
||||
* Categorize a section depending on how constrained it is
|
||||
* This is so the most-constrained sections are placed first
|
||||
* @param section The section to categorize
|
||||
*/
|
||||
static void categorizeSection(struct Section *section)
|
||||
static void categorizeSection(Section *section)
|
||||
{
|
||||
uint8_t constraints = 0;
|
||||
|
||||
@@ -353,7 +351,7 @@ static void categorizeSection(struct Section *section)
|
||||
else if (section->isAlignFixed)
|
||||
constraints |= ALIGN_CONSTRAINED;
|
||||
|
||||
std::deque<struct Section *> §ions = unassignedSections[constraints];
|
||||
std::deque<Section *> §ions = unassignedSections[constraints];
|
||||
auto pos = sections.begin();
|
||||
|
||||
// Insert section while keeping the list sorted by decreasing size
|
||||
@@ -380,7 +378,7 @@ void assign_AssignSections(void)
|
||||
|
||||
// Specially process fully-constrained sections because of overlaying
|
||||
verbosePrint("Assigning bank+org-constrained...\n");
|
||||
for (struct Section *section : unassignedSections[BANK_CONSTRAINED | ORG_CONSTRAINED])
|
||||
for (Section *section : unassignedSections[BANK_CONSTRAINED | ORG_CONSTRAINED])
|
||||
placeSection(section);
|
||||
|
||||
// If all sections were fully constrained, we have nothing left to do
|
||||
@@ -392,9 +390,9 @@ void assign_AssignSections(void)
|
||||
if (overlayFileName) {
|
||||
fprintf(stderr, "FATAL: All sections must be fixed when using an overlay file");
|
||||
uint8_t nbSections = 0;
|
||||
for (int8_t constraints = BANK_CONSTRAINED | ALIGN_CONSTRAINED;
|
||||
constraints >= 0; constraints--) {
|
||||
for (struct Section *section : unassignedSections[constraints]) {
|
||||
for (int8_t constraints = BANK_CONSTRAINED | ALIGN_CONSTRAINED; constraints >= 0;
|
||||
constraints--) {
|
||||
for (Section *section : unassignedSections[constraints]) {
|
||||
fprintf(stderr, "%c \"%s\"", nbSections == 0 ? ';': ',',
|
||||
section->name.c_str());
|
||||
nbSections++;
|
||||
@@ -411,9 +409,8 @@ max_out:
|
||||
}
|
||||
|
||||
// Assign all remaining sections by decreasing constraint order
|
||||
for (int8_t constraints = BANK_CONSTRAINED | ALIGN_CONSTRAINED;
|
||||
constraints >= 0; constraints--) {
|
||||
for (struct Section *section : unassignedSections[constraints])
|
||||
for (int8_t constraints = BANK_CONSTRAINED | ALIGN_CONSTRAINED; constraints >= 0; constraints--) {
|
||||
for (Section *section : unassignedSections[constraints])
|
||||
placeSection(section);
|
||||
|
||||
if (!nbSectionsToAssign)
|
||||
@@ -427,11 +424,10 @@ void assign_Cleanup(void)
|
||||
{
|
||||
for (enum SectionType type : EnumSeq(SECTTYPE_INVALID)) {
|
||||
for (uint32_t bank = 0; bank < nbbanks(type); bank++) {
|
||||
struct FreeSpace *ptr =
|
||||
memory[type][bank].next;
|
||||
FreeSpace *ptr = memory[type][bank].next;
|
||||
|
||||
while (ptr) {
|
||||
struct FreeSpace *next = ptr->next;
|
||||
FreeSpace *next = ptr->next;
|
||||
|
||||
free(ptr);
|
||||
ptr = next;
|
||||
|
||||
@@ -72,7 +72,7 @@ std::string const &FileStackNode::name() const {
|
||||
}
|
||||
|
||||
// Helper function to dump a file stack to stderr
|
||||
std::string const *dumpFileStack(struct FileStackNode const *node)
|
||||
std::string const *dumpFileStack(FileStackNode const *node)
|
||||
{
|
||||
std::string const *lastName;
|
||||
|
||||
@@ -96,7 +96,7 @@ std::string const *dumpFileStack(struct FileStackNode const *node)
|
||||
}
|
||||
|
||||
void printDiag(char const *fmt, va_list args, char const *type,
|
||||
struct FileStackNode const *where, uint32_t lineNo)
|
||||
FileStackNode const *where, uint32_t lineNo)
|
||||
{
|
||||
fputs(type, stderr);
|
||||
fputs(": ", stderr);
|
||||
@@ -108,7 +108,7 @@ void printDiag(char const *fmt, va_list args, char const *type,
|
||||
putc('\n', stderr);
|
||||
}
|
||||
|
||||
void warning(struct FileStackNode const *where, uint32_t lineNo, char const *fmt, ...)
|
||||
void warning(FileStackNode const *where, uint32_t lineNo, char const *fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
|
||||
@@ -117,7 +117,7 @@ void warning(struct FileStackNode const *where, uint32_t lineNo, char const *fmt
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
void error(struct FileStackNode const *where, uint32_t lineNo, char const *fmt, ...)
|
||||
void error(FileStackNode const *where, uint32_t lineNo, char const *fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
|
||||
@@ -143,7 +143,7 @@ void argErr(char flag, char const *fmt, ...)
|
||||
nbErrors++;
|
||||
}
|
||||
|
||||
[[noreturn]] void fatal(struct FileStackNode const *where, uint32_t lineNo, char const *fmt, ...)
|
||||
[[noreturn]] void fatal(FileStackNode const *where, uint32_t lineNo, char const *fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
|
||||
@@ -172,7 +172,7 @@ static const char *optstring = "dl:m:Mn:O:o:p:S:s:tVvWwx";
|
||||
* This is because long opt matching, even to a single char, is prioritized
|
||||
* over short opt matching
|
||||
*/
|
||||
static struct option const longopts[] = {
|
||||
static option const longopts[] = {
|
||||
{ "dmg", no_argument, NULL, 'd' },
|
||||
{ "linkerscript", required_argument, NULL, 'l' },
|
||||
{ "map", required_argument, NULL, 'm' },
|
||||
|
||||
@@ -25,9 +25,9 @@
|
||||
#include "linkdefs.hpp"
|
||||
#include "version.hpp"
|
||||
|
||||
static std::deque<std::vector<struct Symbol>> symbolLists;
|
||||
static std::vector<std::vector<struct FileStackNode>> nodes;
|
||||
static std::deque<struct Assertion> assertions;
|
||||
static std::deque<std::vector<Symbol>> symbolLists;
|
||||
static std::vector<std::vector<FileStackNode>> nodes;
|
||||
static std::deque<Assertion> assertions;
|
||||
|
||||
// Helper functions for reading object files
|
||||
|
||||
@@ -128,10 +128,10 @@ static int64_t readlong(FILE *file)
|
||||
* @param i The ID of the node in the array
|
||||
* @param fileName The filename to report in errors
|
||||
*/
|
||||
static void readFileStackNode(FILE *file, std::vector<struct FileStackNode> &fileNodes, uint32_t i,
|
||||
static void readFileStackNode(FILE *file, std::vector<FileStackNode> &fileNodes, uint32_t i,
|
||||
char const *fileName)
|
||||
{
|
||||
struct FileStackNode &node = fileNodes[i];
|
||||
FileStackNode &node = fileNodes[i];
|
||||
uint32_t parentID;
|
||||
|
||||
tryReadlong(parentID, file,
|
||||
@@ -167,11 +167,11 @@ static void readFileStackNode(FILE *file, std::vector<struct FileStackNode> &fil
|
||||
/*
|
||||
* Reads a symbol from a file.
|
||||
* @param file The file to read from
|
||||
* @param symbol The struct to fill
|
||||
* @param symbol The symbol to fill
|
||||
* @param fileName The filename to report in errors
|
||||
*/
|
||||
static void readSymbol(FILE *file, struct Symbol *symbol, char const *fileName,
|
||||
std::vector<struct FileStackNode> const &fileNodes)
|
||||
static void readSymbol(FILE *file, Symbol *symbol, char const *fileName,
|
||||
std::vector<FileStackNode> const &fileNodes)
|
||||
{
|
||||
tryReadstring(symbol->name, file, "%s: Cannot read symbol name: %s", fileName);
|
||||
tryGetc(enum ExportLevel, symbol->type, file, "%s: Cannot read \"%s\"'s type: %s",
|
||||
@@ -198,12 +198,12 @@ static void readSymbol(FILE *file, struct Symbol *symbol, char const *fileName,
|
||||
/*
|
||||
* Reads a patch from a file.
|
||||
* @param file The file to read from
|
||||
* @param patch The struct to fill
|
||||
* @param patch The patch to fill
|
||||
* @param fileName The filename to report in errors
|
||||
* @param i The number of the patch to report in errors
|
||||
*/
|
||||
static void readPatch(FILE *file, struct Patch *patch, char const *fileName, std::string const §Name,
|
||||
uint32_t i, std::vector<struct FileStackNode> const &fileNodes)
|
||||
static void readPatch(FILE *file, Patch *patch, char const *fileName, std::string const §Name,
|
||||
uint32_t i, std::vector<FileStackNode> const &fileNodes)
|
||||
{
|
||||
uint32_t nodeID, rpnSize;
|
||||
enum PatchType type;
|
||||
@@ -243,9 +243,9 @@ static void readPatch(FILE *file, struct Patch *patch, char const *fileName, std
|
||||
|
||||
/*
|
||||
* Sets a patch's pcSection from its pcSectionID.
|
||||
* @param patch The struct to fix
|
||||
* @param patch The patch to fix
|
||||
*/
|
||||
static void linkPatchToPCSect(struct Patch *patch, std::vector<struct Section *> const &fileSections)
|
||||
static void linkPatchToPCSect(Patch *patch, std::vector<Section *> const &fileSections)
|
||||
{
|
||||
patch->pcSection = patch->pcSectionID != (uint32_t)-1 ? fileSections[patch->pcSectionID]
|
||||
: NULL;
|
||||
@@ -254,11 +254,11 @@ static void linkPatchToPCSect(struct Patch *patch, std::vector<struct Section *>
|
||||
/*
|
||||
* Reads a section from a file.
|
||||
* @param file The file to read from
|
||||
* @param section The struct to fill
|
||||
* @param section The section to fill
|
||||
* @param fileName The filename to report in errors
|
||||
*/
|
||||
static void readSection(FILE *file, struct Section *section, char const *fileName,
|
||||
std::vector<struct FileStackNode> const &fileNodes)
|
||||
static void readSection(FILE *file, Section *section, char const *fileName,
|
||||
std::vector<FileStackNode> const &fileNodes)
|
||||
{
|
||||
int32_t tmp;
|
||||
uint8_t byte;
|
||||
@@ -330,7 +330,7 @@ static void readSection(FILE *file, struct Section *section, char const *fileNam
|
||||
* @param symbol The symbol to link
|
||||
* @param section The section to link
|
||||
*/
|
||||
static void linkSymToSect(struct Symbol &symbol, struct Section *section)
|
||||
static void linkSymToSect(Symbol &symbol, Section *section)
|
||||
{
|
||||
uint32_t a = 0, b = section->symbols.size();
|
||||
|
||||
@@ -349,11 +349,11 @@ static void linkSymToSect(struct Symbol &symbol, struct Section *section)
|
||||
/*
|
||||
* Reads an assertion from a file
|
||||
* @param file The file to read from
|
||||
* @param assert The struct to fill
|
||||
* @param assert The assertion to fill
|
||||
* @param fileName The filename to report in errors
|
||||
*/
|
||||
static void readAssertion(FILE *file, struct Assertion *assert, char const *fileName, uint32_t i,
|
||||
std::vector<struct FileStackNode> const &fileNodes)
|
||||
static void readAssertion(FILE *file, Assertion *assert, char const *fileName, uint32_t i,
|
||||
std::vector<FileStackNode> const &fileNodes)
|
||||
{
|
||||
char assertName[sizeof("Assertion #4294967295")]; // UINT32_MAX
|
||||
|
||||
@@ -363,7 +363,7 @@ static void readAssertion(FILE *file, struct Assertion *assert, char const *file
|
||||
tryReadstring(assert->message, file, "%s: Cannot read assertion's message: %s", fileName);
|
||||
}
|
||||
|
||||
static struct Section *getMainSection(struct Section *section)
|
||||
static Section *getMainSection(Section *section)
|
||||
{
|
||||
if (section->modifier != SECTION_NORMAL)
|
||||
section = sect_GetSection(section->name);
|
||||
@@ -406,7 +406,7 @@ void obj_ReadFile(char const *fileName, unsigned int fileID)
|
||||
.data = fileName
|
||||
});
|
||||
|
||||
std::vector<struct Symbol> &fileSymbols = symbolLists.emplace_front();
|
||||
std::vector<Symbol> &fileSymbols = symbolLists.emplace_front();
|
||||
|
||||
sdobj_ReadFile(&nodes[fileID].back(), file, fileSymbols);
|
||||
return;
|
||||
@@ -446,13 +446,13 @@ void obj_ReadFile(char const *fileName, unsigned int fileID)
|
||||
readFileStackNode(file, nodes[fileID], i, fileName);
|
||||
|
||||
// This file's symbols, kept to link sections to them
|
||||
std::vector<struct Symbol> &fileSymbols = symbolLists.emplace_front(nbSymbols);
|
||||
std::vector<Symbol> &fileSymbols = symbolLists.emplace_front(nbSymbols);
|
||||
std::vector<uint32_t> nbSymPerSect(nbSections, 0);
|
||||
|
||||
verbosePrint("Reading %" PRIu32 " symbols...\n", nbSymbols);
|
||||
for (uint32_t i = 0; i < nbSymbols; i++) {
|
||||
// Read symbol
|
||||
struct Symbol &symbol = fileSymbols[i];
|
||||
Symbol &symbol = fileSymbols[i];
|
||||
|
||||
readSymbol(file, &symbol, fileName, nodes[fileID]);
|
||||
|
||||
@@ -463,12 +463,12 @@ void obj_ReadFile(char const *fileName, unsigned int fileID)
|
||||
}
|
||||
|
||||
// This file's sections, stored in a table to link symbols to them
|
||||
std::vector<struct Section *> fileSections(nbSections, NULL);
|
||||
std::vector<Section *> fileSections(nbSections, NULL);
|
||||
|
||||
verbosePrint("Reading %" PRIu32 " sections...\n", nbSections);
|
||||
for (uint32_t i = 0; i < nbSections; i++) {
|
||||
// Read section
|
||||
fileSections[i] = new(std::nothrow) struct Section();
|
||||
fileSections[i] = new(std::nothrow) Section();
|
||||
if (!fileSections[i])
|
||||
err("%s: Failed to create new section", fileName);
|
||||
|
||||
@@ -483,7 +483,7 @@ void obj_ReadFile(char const *fileName, unsigned int fileID)
|
||||
// Give patches' PC section pointers to their sections
|
||||
for (uint32_t i = 0; i < nbSections; i++) {
|
||||
if (sect_HasData(fileSections[i]->type)) {
|
||||
for (struct Patch &patch : fileSections[i]->patches)
|
||||
for (Patch &patch : fileSections[i]->patches)
|
||||
linkPatchToPCSect(&patch, fileSections);
|
||||
}
|
||||
}
|
||||
@@ -495,7 +495,7 @@ void obj_ReadFile(char const *fileName, unsigned int fileID)
|
||||
if (sectionID == -1) {
|
||||
fileSymbols[i].section = NULL;
|
||||
} else {
|
||||
struct Section *section = fileSections[sectionID];
|
||||
Section *section = fileSections[sectionID];
|
||||
|
||||
// Give the section a pointer to the symbol as well
|
||||
linkSymToSect(fileSymbols[i], section);
|
||||
@@ -515,7 +515,7 @@ void obj_ReadFile(char const *fileName, unsigned int fileID)
|
||||
tryReadlong(nbAsserts, file, "%s: Cannot read number of assertions: %s", fileName);
|
||||
verbosePrint("Reading %" PRIu32 " assertions...\n", nbAsserts);
|
||||
for (uint32_t i = 0; i < nbAsserts; i++) {
|
||||
struct Assertion &assertion = assertions.emplace_front();
|
||||
Assertion &assertion = assertions.emplace_front();
|
||||
|
||||
readAssertion(file, &assertion, fileName, i, nodes[fileID]);
|
||||
linkPatchToPCSect(&assertion.patch, fileSections);
|
||||
@@ -540,9 +540,9 @@ void obj_Setup(unsigned int nbFiles)
|
||||
nodes.resize(nbFiles);
|
||||
}
|
||||
|
||||
static void freeSection(struct Section *section)
|
||||
static void freeSection(Section *section)
|
||||
{
|
||||
for (struct Section *next; section; section = next) {
|
||||
for (Section *next; section; section = next) {
|
||||
next = section->nextu;
|
||||
delete section;
|
||||
};
|
||||
|
||||
@@ -30,16 +30,16 @@ FILE *symFile;
|
||||
FILE *mapFile;
|
||||
|
||||
struct SortedSymbol {
|
||||
struct Symbol const *sym;
|
||||
Symbol const *sym;
|
||||
uint16_t addr;
|
||||
};
|
||||
|
||||
struct SortedSections {
|
||||
std::deque<struct Section const *> sections;
|
||||
std::deque<struct Section const *> zeroLenSections;
|
||||
std::deque<Section const *> sections;
|
||||
std::deque<Section const *> zeroLenSections;
|
||||
};
|
||||
|
||||
static std::deque<struct SortedSections> sections[SECTTYPE_INVALID];
|
||||
static std::deque<SortedSections> sections[SECTTYPE_INVALID];
|
||||
|
||||
// Defines the order in which types are output to the sym and map files
|
||||
static enum SectionType typeMap[SECTTYPE_INVALID] = {
|
||||
@@ -53,7 +53,7 @@ static enum SectionType typeMap[SECTTYPE_INVALID] = {
|
||||
SECTTYPE_HRAM
|
||||
};
|
||||
|
||||
void out_AddSection(struct Section const *section)
|
||||
void out_AddSection(Section const *section)
|
||||
{
|
||||
static const uint32_t maxNbBanks[SECTTYPE_INVALID] = {
|
||||
1, // SECTTYPE_WRAM0
|
||||
@@ -77,7 +77,7 @@ void out_AddSection(struct Section const *section)
|
||||
for (uint32_t i = sections[section->type].size(); i < minNbBanks; i++)
|
||||
sections[section->type].emplace_back();
|
||||
|
||||
std::deque<struct Section const *> *ptr = section->size
|
||||
std::deque<Section const *> *ptr = section->size
|
||||
? §ions[section->type][targetBank].sections
|
||||
: §ions[section->type][targetBank].zeroLenSections;
|
||||
auto pos = ptr->begin();
|
||||
@@ -88,11 +88,11 @@ void out_AddSection(struct Section const *section)
|
||||
ptr->insert(pos, section);
|
||||
}
|
||||
|
||||
struct Section const *out_OverlappingSection(struct Section const *section)
|
||||
Section const *out_OverlappingSection(Section const *section)
|
||||
{
|
||||
uint32_t bank = section->bank - sectionTypeInfo[section->type].firstBank;
|
||||
|
||||
for (struct Section const *ptr : sections[section->type][bank].sections) {
|
||||
for (Section const *ptr : sections[section->type][bank].sections) {
|
||||
if (ptr->org < section->org + section->size && section->org < ptr->org + ptr->size)
|
||||
return ptr;
|
||||
}
|
||||
@@ -159,13 +159,12 @@ static void coverOverlayBanks(uint32_t nbOverlayBanks)
|
||||
* @param baseOffset The address of the bank's first byte in GB address space
|
||||
* @param size The size of the bank
|
||||
*/
|
||||
static void writeBank(std::deque<struct Section const *> *bankSections, uint16_t baseOffset,
|
||||
uint16_t size)
|
||||
static void writeBank(std::deque<Section const *> *bankSections, uint16_t baseOffset, uint16_t size)
|
||||
{
|
||||
uint16_t offset = 0;
|
||||
|
||||
if (bankSections) {
|
||||
for (struct Section const *section : *bankSections) {
|
||||
for (Section const *section : *bankSections) {
|
||||
assert(section->offset == 0);
|
||||
// Output padding up to the next SECTION
|
||||
while (offset + baseOffset < section->org) {
|
||||
@@ -288,7 +287,7 @@ static void printSymName(char const *name)
|
||||
|
||||
// Comparator function for `std::stable_sort` to sort symbols
|
||||
// Symbols are ordered by address, then by parentage
|
||||
static int compareSymbols(struct SortedSymbol const &sym1, struct SortedSymbol const &sym2)
|
||||
static int compareSymbols(SortedSymbol const &sym1, SortedSymbol const &sym2)
|
||||
{
|
||||
if (sym1.addr != sym2.addr)
|
||||
return sym1.addr < sym2.addr ? -1 : 1;
|
||||
@@ -318,16 +317,15 @@ static int compareSymbols(struct SortedSymbol const &sym1, struct SortedSymbol c
|
||||
* Write a bank's contents to the sym file
|
||||
* @param bankSections The bank's sections
|
||||
*/
|
||||
static void writeSymBank(struct SortedSections const &bankSections,
|
||||
enum SectionType type, uint32_t bank)
|
||||
static void writeSymBank(SortedSections const &bankSections, enum SectionType type, uint32_t bank)
|
||||
{
|
||||
#define forEachSortedSection(sect, ...) do { \
|
||||
for (auto it = bankSections.zeroLenSections.begin(); it != bankSections.zeroLenSections.end(); it++) { \
|
||||
for (struct Section const *sect = *it; sect; sect = sect->nextu) \
|
||||
for (Section const *sect = *it; sect; sect = sect->nextu) \
|
||||
__VA_ARGS__ \
|
||||
} \
|
||||
for (auto it = bankSections.sections.begin(); it != bankSections.sections.end(); it++) { \
|
||||
for (struct Section const *sect = *it; sect; sect = sect->nextu) \
|
||||
for (Section const *sect = *it; sect; sect = sect->nextu) \
|
||||
__VA_ARGS__ \
|
||||
} \
|
||||
} while (0)
|
||||
@@ -341,12 +339,12 @@ static void writeSymBank(struct SortedSections const &bankSections,
|
||||
if (!nbSymbols)
|
||||
return;
|
||||
|
||||
std::vector<struct SortedSymbol> symList;
|
||||
std::vector<SortedSymbol> symList;
|
||||
|
||||
symList.reserve(nbSymbols);
|
||||
|
||||
forEachSortedSection(sect, {
|
||||
for (struct Symbol const *sym : sect->symbols) {
|
||||
for (Symbol const *sym : sect->symbols) {
|
||||
// Don't output symbols that begin with an illegal character
|
||||
if (!sym->name.empty() && canStartSymName(sym->name[0]))
|
||||
symList.push_back({ .sym = sym, .addr = (uint16_t)(sym->offset + sect->org) });
|
||||
@@ -359,7 +357,7 @@ static void writeSymBank(struct SortedSections const &bankSections,
|
||||
|
||||
uint32_t symBank = bank + sectionTypeInfo[type].firstBank;
|
||||
|
||||
for (struct SortedSymbol &sym : symList) {
|
||||
for (SortedSymbol &sym : symList) {
|
||||
fprintf(symFile, "%02" PRIx32 ":%04" PRIx16 " ", symBank, sym.addr);
|
||||
printSymName(sym.sym->name.c_str());
|
||||
putc('\n', symFile);
|
||||
@@ -379,8 +377,7 @@ static void writeEmptySpace(uint16_t begin, uint16_t end)
|
||||
/*
|
||||
* Write a bank's contents to the map file
|
||||
*/
|
||||
static void writeMapBank(struct SortedSections const §List, enum SectionType type,
|
||||
uint32_t bank)
|
||||
static void writeMapBank(SortedSections const §List, enum SectionType type, uint32_t bank)
|
||||
{
|
||||
fprintf(mapFile, "\n%s bank #%" PRIu32 ":\n", sectionTypeInfo[type].name.c_str(),
|
||||
bank + sectionTypeInfo[type].firstBank);
|
||||
@@ -395,7 +392,7 @@ static void writeMapBank(struct SortedSections const §List, enum SectionType
|
||||
auto &pickedSection = section == sectList.sections.end() ? zeroLenSection
|
||||
: zeroLenSection == sectList.zeroLenSections.end() ? section
|
||||
: (*section)->org < (*zeroLenSection)->org ? section : zeroLenSection;
|
||||
struct Section const *sect = *pickedSection;
|
||||
Section const *sect = *pickedSection;
|
||||
|
||||
used += sect->size;
|
||||
assert(sect->offset == 0);
|
||||
@@ -416,7 +413,7 @@ static void writeMapBank(struct SortedSections const §List, enum SectionType
|
||||
if (!noSymInMap) {
|
||||
// Also print symbols in the following "pieces"
|
||||
for (uint16_t org = sect->org; sect; sect = sect->nextu) {
|
||||
for (struct Symbol *sym : sect->symbols)
|
||||
for (Symbol *sym : sect->symbols)
|
||||
// Space matches "\tSECTION: $xxxx ..."
|
||||
fprintf(mapFile, "\t $%04" PRIx32 " = %s\n",
|
||||
sym->offset + org, sym->name.c_str());
|
||||
|
||||
@@ -22,7 +22,7 @@ struct RPNStackEntry {
|
||||
bool errorFlag; // Whether the value is a placeholder inserted for error recovery
|
||||
};
|
||||
|
||||
std::deque<struct RPNStackEntry> rpnStack;
|
||||
std::deque<RPNStackEntry> rpnStack;
|
||||
|
||||
static void pushRPN(int32_t value, bool comesFromError)
|
||||
{
|
||||
@@ -33,12 +33,12 @@ static void pushRPN(int32_t value, bool comesFromError)
|
||||
// has popped any values with the error flag set.
|
||||
static bool isError = false;
|
||||
|
||||
static int32_t popRPN(struct FileStackNode const *node, uint32_t lineNo)
|
||||
static int32_t popRPN(FileStackNode const *node, uint32_t lineNo)
|
||||
{
|
||||
if (rpnStack.empty())
|
||||
fatal(node, lineNo, "Internal error, RPN stack empty");
|
||||
|
||||
struct RPNStackEntry entry = rpnStack.front();
|
||||
RPNStackEntry entry = rpnStack.front();
|
||||
|
||||
rpnStack.pop_front();
|
||||
isError |= entry.errorFlag;
|
||||
@@ -48,7 +48,7 @@ static int32_t popRPN(struct FileStackNode const *node, uint32_t lineNo)
|
||||
// RPN operators
|
||||
|
||||
static uint32_t getRPNByte(uint8_t const **expression, int32_t *size,
|
||||
struct FileStackNode const *node, uint32_t lineNo)
|
||||
FileStackNode const *node, uint32_t lineNo)
|
||||
{
|
||||
if (!(*size)--)
|
||||
fatal(node, lineNo, "Internal error, RPN expression overread");
|
||||
@@ -56,10 +56,10 @@ static uint32_t getRPNByte(uint8_t const **expression, int32_t *size,
|
||||
return *(*expression)++;
|
||||
}
|
||||
|
||||
static struct Symbol const *getSymbol(std::vector<struct Symbol> const &symbolList, uint32_t index)
|
||||
static Symbol const *getSymbol(std::vector<Symbol> const &symbolList, uint32_t index)
|
||||
{
|
||||
assert(index != (uint32_t)-1); // PC needs to be handled specially, not here
|
||||
struct Symbol const &symbol = symbolList[index];
|
||||
Symbol const &symbol = symbolList[index];
|
||||
|
||||
// If the symbol is defined elsewhere...
|
||||
if (symbol.type == SYMTYPE_IMPORT)
|
||||
@@ -76,8 +76,7 @@ static struct Symbol const *getSymbol(std::vector<struct Symbol> const &symbolLi
|
||||
* @return isError Set if an error occurred during evaluation, and further
|
||||
* errors caused by the value should be suppressed.
|
||||
*/
|
||||
static int32_t computeRPNExpr(struct Patch const *patch,
|
||||
std::vector<struct Symbol> const &fileSymbols)
|
||||
static int32_t computeRPNExpr(Patch const *patch, std::vector<Symbol> const &fileSymbols)
|
||||
{
|
||||
// Small shortcut to avoid a lot of repetition
|
||||
#define popRPN() popRPN(patch->src, patch->lineNo)
|
||||
@@ -99,9 +98,9 @@ static int32_t computeRPNExpr(struct Patch const *patch,
|
||||
// So, if there are two `popRPN` in the same expression, make
|
||||
// sure the operation is commutative.
|
||||
switch (command) {
|
||||
struct Symbol const *symbol;
|
||||
Symbol const *symbol;
|
||||
char const *name;
|
||||
struct Section const *sect;
|
||||
Section const *sect;
|
||||
|
||||
case RPN_ADD:
|
||||
value = popRPN() + popRPN();
|
||||
@@ -410,11 +409,11 @@ static int32_t computeRPNExpr(struct Patch const *patch,
|
||||
#undef popRPN
|
||||
}
|
||||
|
||||
void patch_CheckAssertions(std::deque<struct Assertion> &assertions)
|
||||
void patch_CheckAssertions(std::deque<Assertion> &assertions)
|
||||
{
|
||||
verbosePrint("Checking assertions...\n");
|
||||
|
||||
for (struct Assertion &assert : assertions) {
|
||||
for (Assertion &assert : assertions) {
|
||||
int32_t value = computeRPNExpr(&assert.patch, *assert.fileSymbols);
|
||||
enum AssertionType type = (enum AssertionType)assert.patch.type;
|
||||
|
||||
@@ -448,10 +447,10 @@ void patch_CheckAssertions(std::deque<struct Assertion> &assertions)
|
||||
* @param section The section component to patch
|
||||
* @param dataSection The section to patch
|
||||
*/
|
||||
static void applyFilePatches(struct Section *section, struct Section *dataSection)
|
||||
static void applyFilePatches(Section *section, Section *dataSection)
|
||||
{
|
||||
verbosePrint("Patching section \"%s\"...\n", section->name.c_str());
|
||||
for (struct Patch &patch : section->patches) {
|
||||
for (Patch &patch : section->patches) {
|
||||
int32_t value = computeRPNExpr(&patch, *section->fileSymbols);
|
||||
uint16_t offset = patch.offset + section->offset;
|
||||
|
||||
@@ -497,12 +496,12 @@ static void applyFilePatches(struct Section *section, struct Section *dataSectio
|
||||
* Applies all of a section's patches, iterating over "components" of unionized sections
|
||||
* @param section The section to patch
|
||||
*/
|
||||
static void applyPatches(struct Section *section)
|
||||
static void applyPatches(Section *section)
|
||||
{
|
||||
if (!sect_HasData(section->type))
|
||||
return;
|
||||
|
||||
for (struct Section *component = section; component; component = component->nextu)
|
||||
for (Section *component = section; component; component = component->nextu)
|
||||
applyFilePatches(component, section);
|
||||
}
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ enum NumberType {
|
||||
OCT = 8, // Q
|
||||
};
|
||||
|
||||
static void consumeLF(struct FileStackNode const *where, uint32_t lineNo, FILE *file) {
|
||||
static void consumeLF(FileStackNode const *where, uint32_t lineNo, FILE *file) {
|
||||
if (getc(file) != '\n')
|
||||
fatal(where, lineNo, "Bad line ending (CR without LF)");
|
||||
}
|
||||
@@ -33,7 +33,7 @@ static void consumeLF(struct FileStackNode const *where, uint32_t lineNo, FILE *
|
||||
static char const *delim = " \f\n\r\t\v"; // Whitespace according to the C and POSIX locales
|
||||
|
||||
static int nextLine(std::vector<char> &lineBuf, uint32_t &lineNo,
|
||||
struct FileStackNode const *where, FILE *file) {
|
||||
FileStackNode const *where, FILE *file) {
|
||||
retry:
|
||||
++lineNo;
|
||||
int firstChar = getc(file);
|
||||
@@ -88,7 +88,7 @@ static uint32_t readNumber(char const *restrict str, char const **endptr, enum N
|
||||
}
|
||||
}
|
||||
|
||||
static uint32_t parseNumber(struct FileStackNode const *where, uint32_t lineNo, char const *restrict str, enum NumberType base) {
|
||||
static uint32_t parseNumber(FileStackNode const *where, uint32_t lineNo, char const *restrict str, enum NumberType base) {
|
||||
if (str[0] == '\0')
|
||||
fatal(where, lineNo, "Expected number, got empty string");
|
||||
|
||||
@@ -100,7 +100,7 @@ static uint32_t parseNumber(struct FileStackNode const *where, uint32_t lineNo,
|
||||
return res;
|
||||
}
|
||||
|
||||
static uint8_t parseByte(struct FileStackNode const *where, uint32_t lineNo, char const *restrict str, enum NumberType base) {
|
||||
static uint8_t parseByte(FileStackNode const *where, uint32_t lineNo, char const *restrict str, enum NumberType base) {
|
||||
uint32_t num = parseNumber(where, lineNo, str, base);
|
||||
|
||||
if (num > UINT8_MAX)
|
||||
@@ -133,7 +133,7 @@ enum RelocFlags {
|
||||
| 1 << RELOC_EXPR24 | 1 << RELOC_BANKBYTE,
|
||||
};
|
||||
|
||||
void sdobj_ReadFile(struct FileStackNode const *where, FILE *file, std::vector<struct Symbol> &fileSymbols) {
|
||||
void sdobj_ReadFile(FileStackNode const *where, FILE *file, std::vector<Symbol> &fileSymbols) {
|
||||
std::vector<char> line(256);
|
||||
char const *token;
|
||||
|
||||
@@ -216,10 +216,10 @@ void sdobj_ReadFile(struct FileStackNode const *where, FILE *file, std::vector<s
|
||||
// Now, let's parse the rest of the lines as they come!
|
||||
|
||||
struct FileSection {
|
||||
struct Section *section;
|
||||
Section *section;
|
||||
uint16_t writeIndex;
|
||||
};
|
||||
std::vector<struct FileSection> fileSections;
|
||||
std::vector<FileSection> fileSections;
|
||||
std::vector<uint8_t> data;
|
||||
|
||||
for (;;) {
|
||||
@@ -236,7 +236,7 @@ void sdobj_ReadFile(struct FileStackNode const *where, FILE *file, std::vector<s
|
||||
if (fileSections.size() == expectedNbAreas)
|
||||
warning(where, lineNo, "Got more 'A' lines than the expected %" PRIu32,
|
||||
expectedNbAreas);
|
||||
struct Section *curSection = new(std::nothrow) struct Section();
|
||||
Section *curSection = new(std::nothrow) Section();
|
||||
|
||||
if (!curSection)
|
||||
fatal(where, lineNo, "Failed to alloc new area: %s", strerror(errno));
|
||||
@@ -244,7 +244,7 @@ void sdobj_ReadFile(struct FileStackNode const *where, FILE *file, std::vector<s
|
||||
getToken(line.data(), "'A' line is too short");
|
||||
assert(strlen(token) != 0); // This should be impossible, tokens are non-empty
|
||||
// The following is required for fragment offsets to be reliably predicted
|
||||
for (struct FileSection &entry : fileSections) {
|
||||
for (FileSection &entry : fileSections) {
|
||||
if (!strcmp(token, entry.section->name.c_str()))
|
||||
fatal(where, lineNo, "Area \"%s\" already defined earlier",
|
||||
token);
|
||||
@@ -327,7 +327,7 @@ void sdobj_ReadFile(struct FileStackNode const *where, FILE *file, std::vector<s
|
||||
if (fileSymbols.size() == expectedNbSymbols)
|
||||
warning(where, lineNo, "Got more 'S' lines than the expected %" PRIu32,
|
||||
expectedNbSymbols);
|
||||
struct Symbol &symbol = fileSymbols.emplace_back();
|
||||
Symbol &symbol = fileSymbols.emplace_back();
|
||||
|
||||
// Init other members
|
||||
symbol.objFileName = where->name().c_str();
|
||||
@@ -358,7 +358,7 @@ void sdobj_ReadFile(struct FileStackNode const *where, FILE *file, std::vector<s
|
||||
} else {
|
||||
// All symbols are exported
|
||||
symbol.type = SYMTYPE_EXPORT;
|
||||
struct Symbol const *other = sym_GetSymbol(symbol.name);
|
||||
Symbol const *other = sym_GetSymbol(symbol.name);
|
||||
|
||||
if (other) {
|
||||
// The same symbol can only be defined twice if neither
|
||||
@@ -422,7 +422,7 @@ void sdobj_ReadFile(struct FileStackNode const *where, FILE *file, std::vector<s
|
||||
fatal(where, lineNo, "'R' line references area #%" PRIu16 ", but there are only %zu (so far)",
|
||||
areaIdx, fileSections.size());
|
||||
assert(!fileSections.empty()); // There should be at least one, from the above check
|
||||
struct Section *section = fileSections[areaIdx].section;
|
||||
Section *section = fileSections[areaIdx].section;
|
||||
uint16_t *writeIndex = &fileSections[areaIdx].writeIndex;
|
||||
uint8_t writtenOfs = ADDR_SIZE; // Bytes before this have been written to `->data`
|
||||
uint16_t addr = data[0] | data[1] << 8;
|
||||
@@ -489,7 +489,7 @@ void sdobj_ReadFile(struct FileStackNode const *where, FILE *file, std::vector<s
|
||||
warning(where, lineNo, "Unknown reloc flags 0x%x", flags & ~RELOC_ALL_FLAGS);
|
||||
|
||||
// Turn this into a Patch
|
||||
struct Patch &patch = section->patches.emplace_back();
|
||||
Patch &patch = section->patches.emplace_back();
|
||||
|
||||
patch.lineNo = lineNo;
|
||||
patch.src = where;
|
||||
@@ -520,7 +520,7 @@ void sdobj_ReadFile(struct FileStackNode const *where, FILE *file, std::vector<s
|
||||
if (idx >= fileSymbols.size())
|
||||
fatal(where, lineNo, "Reloc refers to symbol #%" PRIu16 " out of %zu",
|
||||
idx, fileSymbols.size());
|
||||
struct Symbol const &sym = fileSymbols[idx];
|
||||
Symbol const &sym = fileSymbols[idx];
|
||||
|
||||
// SDCC has a bunch of "magic symbols" that start with a
|
||||
// letter and an underscore. These are not compatibility
|
||||
@@ -571,7 +571,7 @@ void sdobj_ReadFile(struct FileStackNode const *where, FILE *file, std::vector<s
|
||||
if (fileSections[idx].section->isAddressFixed)
|
||||
baseValue -= fileSections[idx].section->org;
|
||||
std::string const &name = fileSections[idx].section->name;
|
||||
struct Section const *other = sect_GetSection(name);
|
||||
Section const *other = sect_GetSection(name);
|
||||
|
||||
// Unlike with `s_<AREA>`, referencing an area in this way
|
||||
// wants the beginning of this fragment, so we must add the
|
||||
@@ -678,8 +678,8 @@ void sdobj_ReadFile(struct FileStackNode const *where, FILE *file, std::vector<s
|
||||
|
||||
nbSectionsToAssign += fileSections.size();
|
||||
|
||||
for (struct FileSection &entry : fileSections) {
|
||||
struct Section *section = entry.section;
|
||||
for (FileSection &entry : fileSections) {
|
||||
Section *section = entry.section;
|
||||
|
||||
// RAM sections can have a size, but don't get any data (they shouldn't have any)
|
||||
if (entry.writeIndex != section->size && entry.writeIndex != 0)
|
||||
@@ -690,7 +690,7 @@ void sdobj_ReadFile(struct FileStackNode const *where, FILE *file, std::vector<s
|
||||
|
||||
if (section->modifier == SECTION_FRAGMENT) {
|
||||
// Add the fragment's offset to all of its symbols
|
||||
for (struct Symbol *symbol : section->symbols)
|
||||
for (Symbol *symbol : section->symbols)
|
||||
symbol->offset += section->offset;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,15 +13,15 @@
|
||||
#include "error.hpp"
|
||||
#include "linkdefs.hpp"
|
||||
|
||||
std::map<std::string, struct Section *> sections;
|
||||
std::map<std::string, Section *> sections;
|
||||
|
||||
void sect_ForEach(void (*callback)(struct Section *))
|
||||
void sect_ForEach(void (*callback)(Section *))
|
||||
{
|
||||
for (auto &it : sections)
|
||||
callback(it.second);
|
||||
}
|
||||
|
||||
static void checkSectUnionCompat(struct Section *target, struct Section *other)
|
||||
static void checkSectUnionCompat(Section *target, Section *other)
|
||||
{
|
||||
if (other->isAddressFixed) {
|
||||
if (target->isAddressFixed) {
|
||||
@@ -59,7 +59,7 @@ static void checkSectUnionCompat(struct Section *target, struct Section *other)
|
||||
}
|
||||
}
|
||||
|
||||
static void checkFragmentCompat(struct Section *target, struct Section *other)
|
||||
static void checkFragmentCompat(Section *target, Section *other)
|
||||
{
|
||||
if (other->isAddressFixed) {
|
||||
uint16_t org = other->org - target->size;
|
||||
@@ -107,7 +107,7 @@ static void checkFragmentCompat(struct Section *target, struct Section *other)
|
||||
}
|
||||
}
|
||||
|
||||
static void mergeSections(struct Section *target, struct Section *other, enum SectionModifier mod)
|
||||
static void mergeSections(Section *target, Section *other, enum SectionModifier mod)
|
||||
{
|
||||
// Common checks
|
||||
|
||||
@@ -144,7 +144,7 @@ static void mergeSections(struct Section *target, struct Section *other, enum Se
|
||||
if (!other->data.empty()) {
|
||||
target->data.insert(target->data.end(), RANGE(other->data));
|
||||
// Adjust patches' PC offsets
|
||||
for (struct Patch &patch : other->patches)
|
||||
for (Patch &patch : other->patches)
|
||||
patch.pcOffset += other->offset;
|
||||
} else if (!target->data.empty()) {
|
||||
assert(other->size == 0);
|
||||
@@ -159,10 +159,10 @@ static void mergeSections(struct Section *target, struct Section *other, enum Se
|
||||
target->nextu = other;
|
||||
}
|
||||
|
||||
void sect_AddSection(struct Section *section)
|
||||
void sect_AddSection(Section *section)
|
||||
{
|
||||
// Check if the section already exists
|
||||
if (struct Section *other = sect_GetSection(section->name); other) {
|
||||
if (Section *other = sect_GetSection(section->name); other) {
|
||||
if (section->modifier != other->modifier)
|
||||
errx("Section \"%s\" defined as %s and %s", section->name.c_str(),
|
||||
sectionModNames[section->modifier], sectionModNames[other->modifier]);
|
||||
@@ -179,13 +179,13 @@ void sect_AddSection(struct Section *section)
|
||||
}
|
||||
}
|
||||
|
||||
struct Section *sect_GetSection(std::string const &name)
|
||||
Section *sect_GetSection(std::string const &name)
|
||||
{
|
||||
auto search = sections.find(name);
|
||||
return search != sections.end() ? search->second : NULL;
|
||||
}
|
||||
|
||||
static void doSanityChecks(struct Section *section)
|
||||
static void doSanityChecks(Section *section)
|
||||
{
|
||||
// Sanity check the section's type
|
||||
if (section->type < 0 || section->type >= SECTTYPE_INVALID) {
|
||||
|
||||
@@ -11,12 +11,12 @@
|
||||
|
||||
#include "error.hpp"
|
||||
|
||||
std::map<std::string, struct Symbol *> symbols;
|
||||
std::map<std::string, Symbol *> symbols;
|
||||
|
||||
void sym_AddSymbol(struct Symbol *symbol)
|
||||
void sym_AddSymbol(Symbol *symbol)
|
||||
{
|
||||
// Check if the symbol already exists
|
||||
if (struct Symbol *other = sym_GetSymbol(symbol->name); other) {
|
||||
if (Symbol *other = sym_GetSymbol(symbol->name); other) {
|
||||
fprintf(stderr, "error: \"%s\" both in %s from ", symbol->name.c_str(), symbol->objFileName);
|
||||
dumpFileStack(symbol->src);
|
||||
fprintf(stderr, "(%" PRIu32 ") and in %s from ", symbol->lineNo, other->objFileName);
|
||||
@@ -29,7 +29,7 @@ void sym_AddSymbol(struct Symbol *symbol)
|
||||
symbols[symbol->name] = symbol;
|
||||
}
|
||||
|
||||
struct Symbol *sym_GetSymbol(std::string const &name)
|
||||
Symbol *sym_GetSymbol(std::string const &name)
|
||||
{
|
||||
auto search = symbols.find(name);
|
||||
return search != symbols.end() ? search->second : NULL;
|
||||
|
||||
Reference in New Issue
Block a user