mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-20 10:12:06 +00:00
Save UNION stack when using PUSHS as well
This allows using the latter within the former
This commit is contained in:
@@ -20,12 +20,19 @@
|
|||||||
|
|
||||||
uint8_t fillByte;
|
uint8_t fillByte;
|
||||||
|
|
||||||
|
struct UnionStackEntry {
|
||||||
|
uint32_t start;
|
||||||
|
uint32_t size;
|
||||||
|
struct UnionStackEntry *next;
|
||||||
|
} *unionStack = NULL;
|
||||||
|
|
||||||
struct SectionStackEntry {
|
struct SectionStackEntry {
|
||||||
struct Section *section;
|
struct Section *section;
|
||||||
struct Section *loadSection;
|
struct Section *loadSection;
|
||||||
char const *scope; /* Section's symbol scope */
|
char const *scope; /* Section's symbol scope */
|
||||||
uint32_t offset;
|
uint32_t offset;
|
||||||
int32_t loadOffset;
|
int32_t loadOffset;
|
||||||
|
struct UnionStackEntry *unionStack;
|
||||||
struct SectionStackEntry *next;
|
struct SectionStackEntry *next;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -35,12 +42,6 @@ struct Section *currentSection = NULL;
|
|||||||
static struct Section *currentLoadSection = NULL;
|
static struct Section *currentLoadSection = NULL;
|
||||||
int32_t loadOffset; /* Offset into the LOAD section's parent (see sect_GetOutputOffset) */
|
int32_t loadOffset; /* Offset into the LOAD section's parent (see sect_GetOutputOffset) */
|
||||||
|
|
||||||
struct UnionStackEntry {
|
|
||||||
uint32_t start;
|
|
||||||
uint32_t size;
|
|
||||||
struct UnionStackEntry *next;
|
|
||||||
} *unionStack = NULL;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* A quick check to see if we have an initialized section
|
* A quick check to see if we have an initialized section
|
||||||
*/
|
*/
|
||||||
@@ -428,6 +429,11 @@ void sect_NewSection(char const *name, uint32_t type, uint32_t org,
|
|||||||
void sect_SetLoadSection(char const *name, uint32_t type, uint32_t org,
|
void sect_SetLoadSection(char const *name, uint32_t type, uint32_t org,
|
||||||
struct SectionSpec const *attribs, enum SectionModifier mod)
|
struct SectionSpec const *attribs, enum SectionModifier mod)
|
||||||
{
|
{
|
||||||
|
// Important info: currently, UNION and LOAD cannot interact, since UNION is prohibited in
|
||||||
|
// "code" sections, whereas LOAD is restricted to them.
|
||||||
|
// Therefore, any interactions are NOT TESTED, so lift either of those restrictions at
|
||||||
|
// your own peril! ^^
|
||||||
|
|
||||||
if (!checkcodesection())
|
if (!checkcodesection())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -548,6 +554,11 @@ static void createPatch(enum PatchType type, struct Expression const *expr, uint
|
|||||||
|
|
||||||
void sect_StartUnion(void)
|
void sect_StartUnion(void)
|
||||||
{
|
{
|
||||||
|
// Important info: currently, UNION and LOAD cannot interact, since UNION is prohibited in
|
||||||
|
// "code" sections, whereas LOAD is restricted to them.
|
||||||
|
// Therefore, any interactions are NOT TESTED, so lift either of those restrictions at
|
||||||
|
// your own peril! ^^
|
||||||
|
|
||||||
if (!currentSection) {
|
if (!currentSection) {
|
||||||
error("UNIONs must be inside a SECTION\n");
|
error("UNIONs must be inside a SECTION\n");
|
||||||
return;
|
return;
|
||||||
@@ -964,22 +975,24 @@ cleanup:
|
|||||||
*/
|
*/
|
||||||
void sect_PushSection(void)
|
void sect_PushSection(void)
|
||||||
{
|
{
|
||||||
struct SectionStackEntry *sect = malloc(sizeof(*sect));
|
struct SectionStackEntry *entry = malloc(sizeof(*entry));
|
||||||
|
|
||||||
if (sect == NULL)
|
if (entry == NULL)
|
||||||
fatalerror("No memory for section stack: %s\n", strerror(errno));
|
fatalerror("No memory for section stack: %s\n", strerror(errno));
|
||||||
sect->section = currentSection;
|
entry->section = currentSection;
|
||||||
sect->loadSection = currentLoadSection;
|
entry->loadSection = currentLoadSection;
|
||||||
sect->scope = sym_GetCurrentSymbolScope();
|
entry->scope = sym_GetCurrentSymbolScope();
|
||||||
sect->offset = curOffset;
|
entry->offset = curOffset;
|
||||||
sect->loadOffset = loadOffset;
|
entry->loadOffset = loadOffset;
|
||||||
sect->next = sectionStack;
|
entry->unionStack = unionStack;
|
||||||
sectionStack = sect;
|
entry->next = sectionStack;
|
||||||
|
sectionStack = entry;
|
||||||
|
|
||||||
// Reset the section scope
|
// Reset the section scope
|
||||||
currentSection = NULL;
|
currentSection = NULL;
|
||||||
currentLoadSection = NULL;
|
currentLoadSection = NULL;
|
||||||
sym_SetCurrentSymbolScope(NULL);
|
sym_SetCurrentSymbolScope(NULL);
|
||||||
|
unionStack = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void sect_PopSection(void)
|
void sect_PopSection(void)
|
||||||
@@ -998,6 +1011,7 @@ void sect_PopSection(void)
|
|||||||
sym_SetCurrentSymbolScope(entry->scope);
|
sym_SetCurrentSymbolScope(entry->scope);
|
||||||
curOffset = entry->offset;
|
curOffset = entry->offset;
|
||||||
loadOffset = entry->loadOffset;
|
loadOffset = entry->loadOffset;
|
||||||
|
unionStack = entry->unionStack;
|
||||||
|
|
||||||
sectionStack = entry->next;
|
sectionStack = entry->next;
|
||||||
free(entry);
|
free(entry);
|
||||||
|
|||||||
25
test/asm/union-pushs.asm
Normal file
25
test/asm/union-pushs.asm
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
|
||||||
|
SECTION "Test", ROM0[0]
|
||||||
|
dw SIZEOF("RAM")
|
||||||
|
dw SIZEOF("HRAM")
|
||||||
|
|
||||||
|
SECTION "RAM",WRAM0
|
||||||
|
ds 654
|
||||||
|
UNION
|
||||||
|
ds 14
|
||||||
|
NEXTU
|
||||||
|
ds 897
|
||||||
|
|
||||||
|
PUSHS
|
||||||
|
|
||||||
|
SECTION "HRAM",HRAM
|
||||||
|
ds $7F
|
||||||
|
|
||||||
|
POPS
|
||||||
|
ds 75
|
||||||
|
NEXTU
|
||||||
|
ds 863
|
||||||
|
ENDU
|
||||||
|
|
||||||
|
ds 28
|
||||||
|
|
||||||
0
test/asm/union-pushs.err
Normal file
0
test/asm/union-pushs.err
Normal file
0
test/asm/union-pushs.out
Normal file
0
test/asm/union-pushs.out
Normal file
BIN
test/asm/union-pushs.out.bin
Normal file
BIN
test/asm/union-pushs.out.bin
Normal file
Binary file not shown.
Reference in New Issue
Block a user