mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-20 18:22:07 +00:00
Reinstate PUSHS clearing the SECTION scope (#870)
* Reinstate PUSHS clearing the SECTION scope Otherwise you can use `PUSHS` to simulate the old `ds -21`, and possibly cause bugs * Have PUSHS push LOAD block state as well It does not make sense not to, and coud cause bugs.
This commit is contained in:
@@ -17,7 +17,7 @@ struct Expression;
|
||||
struct FileStackNode;
|
||||
|
||||
extern char *objectName;
|
||||
extern struct Section *sectionList, *currentSection;
|
||||
extern struct Section *sectionList;
|
||||
|
||||
void out_RegisterNode(struct FileStackNode *node);
|
||||
void out_ReplaceNode(struct FileStackNode *node);
|
||||
|
||||
@@ -40,6 +40,8 @@ struct SectionSpec {
|
||||
uint16_t alignOfs;
|
||||
};
|
||||
|
||||
extern struct Section *currentSection;
|
||||
|
||||
struct Section *out_FindSectionByName(const char *name);
|
||||
void out_NewSection(char const *name, uint32_t secttype, uint32_t org,
|
||||
struct SectionSpec const *attributes,
|
||||
|
||||
@@ -53,8 +53,7 @@ struct Assertion {
|
||||
|
||||
char *objectName;
|
||||
|
||||
/* TODO: shouldn't `currentSection` be somewhere else? */
|
||||
struct Section *sectionList, *currentSection;
|
||||
struct Section *sectionList;
|
||||
|
||||
/* Linked list of symbols to put in the object file */
|
||||
static struct Symbol *objectSymbols = NULL;
|
||||
|
||||
@@ -22,13 +22,16 @@ uint8_t fillByte;
|
||||
|
||||
struct SectionStackEntry {
|
||||
struct Section *section;
|
||||
struct Section *loadSection;
|
||||
char const *scope; /* Section's symbol scope */
|
||||
uint32_t offset;
|
||||
int32_t loadOffset;
|
||||
struct SectionStackEntry *next;
|
||||
};
|
||||
|
||||
struct SectionStackEntry *sectionStack;
|
||||
uint32_t curOffset; /* Offset into the current section (see sect_GetSymbolOffset) */
|
||||
struct Section *currentSection = NULL;
|
||||
static struct Section *currentLoadSection = NULL;
|
||||
int32_t loadOffset; /* Offset into the LOAD section's parent (see sect_GetOutputOffset) */
|
||||
|
||||
@@ -44,7 +47,7 @@ struct UnionStackEntry {
|
||||
static void checksection(void)
|
||||
{
|
||||
if (currentSection == NULL)
|
||||
fatalerror("Code generation before SECTION directive\n");
|
||||
fatalerror("Cannot output data outside of a SECTION\n");
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -898,10 +901,17 @@ void out_PushSection(void)
|
||||
if (sect == NULL)
|
||||
fatalerror("No memory for section stack: %s\n", strerror(errno));
|
||||
sect->section = currentSection;
|
||||
sect->loadSection = currentLoadSection;
|
||||
sect->scope = sym_GetCurrentSymbolScope();
|
||||
sect->offset = curOffset;
|
||||
sect->loadOffset = loadOffset;
|
||||
sect->next = sectionStack;
|
||||
sectionStack = sect;
|
||||
|
||||
// Reset the section scope
|
||||
currentSection = NULL;
|
||||
currentLoadSection = NULL;
|
||||
sym_SetCurrentSymbolScope(NULL);
|
||||
}
|
||||
|
||||
void out_PopSection(void)
|
||||
@@ -917,8 +927,10 @@ void out_PopSection(void)
|
||||
sect = sectionStack;
|
||||
changeSection();
|
||||
currentSection = sect->section;
|
||||
currentLoadSection = sect->loadSection;
|
||||
sym_SetCurrentSymbolScope(sect->scope);
|
||||
curOffset = sect->offset;
|
||||
loadOffset = sect->loadOffset;
|
||||
|
||||
sectionStack = sect->next;
|
||||
free(sect);
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
FATAL: align-pc-outside-section.asm(1):
|
||||
Code generation before SECTION directive
|
||||
Cannot output data outside of a SECTION
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
ERROR: pops-restore-no-section.asm(9):
|
||||
Label "DisallowedContent" created outside of a SECTION
|
||||
FATAL: pops-restore-no-section.asm(10):
|
||||
Code generation before SECTION directive
|
||||
Cannot output data outside of a SECTION
|
||||
|
||||
5
test/asm/pushs.asm
Normal file
5
test/asm/pushs.asm
Normal file
@@ -0,0 +1,5 @@
|
||||
SECTION "This is invalid", ROM0
|
||||
ds 10, 42
|
||||
PUSHS
|
||||
; We should be outside of section scope now
|
||||
db 69
|
||||
2
test/asm/pushs.err
Normal file
2
test/asm/pushs.err
Normal file
@@ -0,0 +1,2 @@
|
||||
FATAL: pushs.asm(5):
|
||||
Cannot output data outside of a SECTION
|
||||
0
test/asm/pushs.out
Normal file
0
test/asm/pushs.out
Normal file
Reference in New Issue
Block a user