mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-20 10:12:06 +00:00
Use std::deque (iterable) for section stack
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
#ifndef RGBDS_ASM_OUTPUT_H
|
||||
#define RGBDS_ASM_OUTPUT_H
|
||||
|
||||
#include <deque>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "linkdefs.hpp"
|
||||
@@ -11,7 +12,7 @@ struct Expression;
|
||||
struct FileStackNode;
|
||||
|
||||
extern const char *objectName;
|
||||
extern struct Section *sectionList;
|
||||
extern std::deque<struct Section *> sectionList;
|
||||
|
||||
void out_RegisterNode(struct FileStackNode *node);
|
||||
void out_ReplaceNode(struct FileStackNode *node);
|
||||
|
||||
@@ -23,7 +23,6 @@ struct Section {
|
||||
uint32_t bank;
|
||||
uint8_t align; // Exactly as specified in `ALIGN[]`
|
||||
uint16_t alignOfs;
|
||||
struct Section *next;
|
||||
struct Patch *patches;
|
||||
uint8_t *data;
|
||||
};
|
||||
|
||||
@@ -2,7 +2,9 @@
|
||||
|
||||
// Outputs an objectfile
|
||||
|
||||
#include <algorithm>
|
||||
#include <assert.h>
|
||||
#include <deque>
|
||||
#include <errno.h>
|
||||
#include <inttypes.h>
|
||||
#include <stdio.h>
|
||||
@@ -44,7 +46,7 @@ struct Assertion {
|
||||
|
||||
const char *objectName;
|
||||
|
||||
struct Section *sectionList;
|
||||
std::deque<struct Section *> sectionList;
|
||||
|
||||
// Linked list of symbols to put in the object file
|
||||
static struct Symbol *objectSymbols = NULL;
|
||||
@@ -55,17 +57,6 @@ static struct Assertion *assertions = NULL;
|
||||
|
||||
static struct FileStackNode *fileStackNodes = NULL;
|
||||
|
||||
// Count the number of sections used in this object
|
||||
static uint32_t countSections(void)
|
||||
{
|
||||
uint32_t count = 0;
|
||||
|
||||
for (struct Section const *sect = sectionList; sect; sect = sect->next)
|
||||
count++;
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
// Count the number of patches used in this object
|
||||
static uint32_t countPatches(struct Section const *sect)
|
||||
{
|
||||
@@ -154,17 +145,12 @@ This is code intended to replace a node, which is pretty useless until ref count
|
||||
// Return a section's ID
|
||||
static uint32_t getsectid(struct Section const *sect)
|
||||
{
|
||||
struct Section const *sec = sectionList;
|
||||
uint32_t ID = 0;
|
||||
auto search = std::find(RANGE(sectionList), sect);
|
||||
|
||||
while (sec) {
|
||||
if (sec == sect)
|
||||
return ID;
|
||||
ID++;
|
||||
sec = sec->next;
|
||||
}
|
||||
if (search == sectionList.end())
|
||||
fatalerror("Unknown section '%s'\n", sect->name);
|
||||
|
||||
fatalerror("Unknown section '%s'\n", sect->name);
|
||||
return search - sectionList.begin();
|
||||
}
|
||||
|
||||
static uint32_t getSectIDIfAny(struct Section const *sect)
|
||||
@@ -497,7 +483,7 @@ void out_WriteObject(void)
|
||||
putlong(RGBDS_OBJECT_REV, f);
|
||||
|
||||
putlong(nbSymbols, f);
|
||||
putlong(countSections(), f);
|
||||
putlong(sectionList.size(), f);
|
||||
|
||||
putlong(getNbFileStackNodes(), f);
|
||||
for (struct FileStackNode const *node = fileStackNodes; node; node = node->next) {
|
||||
@@ -511,7 +497,7 @@ void out_WriteObject(void)
|
||||
for (struct Symbol const *sym = objectSymbols; sym; sym = sym->next)
|
||||
writesymbol(sym, f);
|
||||
|
||||
for (struct Section *sect = sectionList; sect; sect = sect->next) {
|
||||
for (struct Section *sect : sectionList) {
|
||||
writesection(sect, f);
|
||||
freesection(sect);
|
||||
}
|
||||
|
||||
@@ -108,7 +108,7 @@ attr_(warn_unused_result) static bool reserveSpace(uint32_t delta_size)
|
||||
|
||||
struct Section *sect_FindSectionByName(char const *name)
|
||||
{
|
||||
for (struct Section *sect = sectionList; sect; sect = sect->next) {
|
||||
for (struct Section *sect : sectionList) {
|
||||
if (strcmp(name, sect->name) == 0)
|
||||
return sect;
|
||||
}
|
||||
@@ -283,7 +283,6 @@ static struct Section *createSection(char const *name, enum SectionType type,
|
||||
sect->bank = bank;
|
||||
sect->align = alignment;
|
||||
sect->alignOfs = alignOffset;
|
||||
sect->next = NULL;
|
||||
sect->patches = NULL;
|
||||
|
||||
// It is only needed to allocate memory for ROM sections.
|
||||
@@ -369,8 +368,7 @@ static struct Section *getSection(char const *name, enum SectionType type, uint3
|
||||
} else {
|
||||
sect = createSection(name, type, org, bank, alignment, alignOffset, mod);
|
||||
// Add the new section to the list (order doesn't matter)
|
||||
sect->next = sectionList;
|
||||
sectionList = sect;
|
||||
sectionList.push_front(sect);
|
||||
}
|
||||
|
||||
return sect;
|
||||
|
||||
Reference in New Issue
Block a user