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:
Eldred Habert
2021-05-01 23:30:09 +02:00
committed by GitHub
parent 3ffdd50909
commit 21b59c4651
9 changed files with 26 additions and 6 deletions

View File

@@ -17,7 +17,7 @@ struct Expression;
struct FileStackNode; struct FileStackNode;
extern char *objectName; extern char *objectName;
extern struct Section *sectionList, *currentSection; extern struct Section *sectionList;
void out_RegisterNode(struct FileStackNode *node); void out_RegisterNode(struct FileStackNode *node);
void out_ReplaceNode(struct FileStackNode *node); void out_ReplaceNode(struct FileStackNode *node);

View File

@@ -40,6 +40,8 @@ struct SectionSpec {
uint16_t alignOfs; uint16_t alignOfs;
}; };
extern struct Section *currentSection;
struct Section *out_FindSectionByName(const char *name); struct Section *out_FindSectionByName(const char *name);
void out_NewSection(char const *name, uint32_t secttype, uint32_t org, void out_NewSection(char const *name, uint32_t secttype, uint32_t org,
struct SectionSpec const *attributes, struct SectionSpec const *attributes,

View File

@@ -53,8 +53,7 @@ struct Assertion {
char *objectName; char *objectName;
/* TODO: shouldn't `currentSection` be somewhere else? */ struct Section *sectionList;
struct Section *sectionList, *currentSection;
/* Linked list of symbols to put in the object file */ /* Linked list of symbols to put in the object file */
static struct Symbol *objectSymbols = NULL; static struct Symbol *objectSymbols = NULL;

View File

@@ -22,13 +22,16 @@ uint8_t fillByte;
struct SectionStackEntry { struct SectionStackEntry {
struct Section *section; struct Section *section;
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;
struct SectionStackEntry *next; struct SectionStackEntry *next;
}; };
struct SectionStackEntry *sectionStack; struct SectionStackEntry *sectionStack;
uint32_t curOffset; /* Offset into the current section (see sect_GetSymbolOffset) */ uint32_t curOffset; /* Offset into the current section (see sect_GetSymbolOffset) */
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) */
@@ -44,7 +47,7 @@ struct UnionStackEntry {
static void checksection(void) static void checksection(void)
{ {
if (currentSection == NULL) 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) if (sect == NULL)
fatalerror("No memory for section stack: %s\n", strerror(errno)); fatalerror("No memory for section stack: %s\n", strerror(errno));
sect->section = currentSection; sect->section = currentSection;
sect->loadSection = currentLoadSection;
sect->scope = sym_GetCurrentSymbolScope(); sect->scope = sym_GetCurrentSymbolScope();
sect->offset = curOffset; sect->offset = curOffset;
sect->loadOffset = loadOffset;
sect->next = sectionStack; sect->next = sectionStack;
sectionStack = sect; sectionStack = sect;
// Reset the section scope
currentSection = NULL;
currentLoadSection = NULL;
sym_SetCurrentSymbolScope(NULL);
} }
void out_PopSection(void) void out_PopSection(void)
@@ -917,8 +927,10 @@ void out_PopSection(void)
sect = sectionStack; sect = sectionStack;
changeSection(); changeSection();
currentSection = sect->section; currentSection = sect->section;
currentLoadSection = sect->loadSection;
sym_SetCurrentSymbolScope(sect->scope); sym_SetCurrentSymbolScope(sect->scope);
curOffset = sect->offset; curOffset = sect->offset;
loadOffset = sect->loadOffset;
sectionStack = sect->next; sectionStack = sect->next;
free(sect); free(sect);

View File

@@ -1,2 +1,2 @@
FATAL: align-pc-outside-section.asm(1): FATAL: align-pc-outside-section.asm(1):
Code generation before SECTION directive Cannot output data outside of a SECTION

View File

@@ -1,4 +1,4 @@
ERROR: pops-restore-no-section.asm(9): ERROR: pops-restore-no-section.asm(9):
Label "DisallowedContent" created outside of a SECTION Label "DisallowedContent" created outside of a SECTION
FATAL: pops-restore-no-section.asm(10): 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
View 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
View File

@@ -0,0 +1,2 @@
FATAL: pushs.asm(5):
Cannot output data outside of a SECTION

0
test/asm/pushs.out Normal file
View File