ref: 21b59c46519eb80ea48211cae6ab055d487cea57
parent: 3ffdd5090974da5914d1fea150ed937e440053d3
author: Eldred Habert <eldredhabert0@gmail.com>
date: Sat May 1 19:30:09 EDT 2021
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.
--- a/include/asm/output.h
+++ b/include/asm/output.h
@@ -17,7 +17,7 @@
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);
--- a/include/asm/section.h
+++ b/include/asm/section.h
@@ -40,6 +40,8 @@
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,
--- a/src/asm/output.c
+++ b/src/asm/output.c
@@ -53,8 +53,7 @@
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;
--- a/src/asm/section.c
+++ b/src/asm/section.c
@@ -22,13 +22,16 @@
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 @@
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 @@
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 @@
sect = sectionStack;
changeSection();
currentSection = sect->section;
+ currentLoadSection = sect->loadSection;
sym_SetCurrentSymbolScope(sect->scope);
curOffset = sect->offset;
+ loadOffset = sect->loadOffset;
sectionStack = sect->next;
free(sect);
--- a/test/asm/align-pc-outside-section.err
+++ b/test/asm/align-pc-outside-section.err
@@ -1,2 +1,2 @@
FATAL: align-pc-outside-section.asm(1):
- Code generation before SECTION directive
+ Cannot output data outside of a SECTION
--- a/test/asm/pops-restore-no-section.err
+++ b/test/asm/pops-restore-no-section.err
@@ -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
--- /dev/null
+++ b/test/asm/pushs.asm
@@ -1,0 +1,5 @@
+SECTION "This is invalid", ROM0
+ ds 10, 42
+ PUSHS
+ ; We should be outside of section scope now
+ db 69
--- /dev/null
+++ b/test/asm/pushs.err
@@ -1,0 +1,2 @@
+FATAL: pushs.asm(5):
+ Cannot output data outside of a SECTION