ref: e3b7339dd626efd40224e58f22b660dc0367f0aa
parent: 69d7f845025dfcc3017e58453273be46a0107993
author: ISSOtm <eldredhabert0@gmail.com>
date: Fri May 21 05:47:27 EDT 2021
Save UNION stack when using PUSHS as well This allows using the latter within the former
--- a/src/asm/section.c
+++ b/src/asm/section.c
@@ -20,6 +20,12 @@
uint8_t fillByte;
+struct UnionStackEntry {
+ uint32_t start;
+ uint32_t size;
+ struct UnionStackEntry *next;
+} *unionStack = NULL;
+
struct SectionStackEntry {
struct Section *section;
struct Section *loadSection;
@@ -26,6 +32,7 @@
char const *scope; /* Section's symbol scope */
uint32_t offset;
int32_t loadOffset;
+ struct UnionStackEntry *unionStack;
struct SectionStackEntry *next;
};
@@ -35,12 +42,6 @@
static struct Section *currentLoadSection = NULL;
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
*/
@@ -428,6 +429,11 @@
void sect_SetLoadSection(char const *name, uint32_t type, uint32_t org,
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())
return;
@@ -548,6 +554,11 @@
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) {
error("UNIONs must be inside a SECTION\n");
return;
@@ -964,22 +975,24 @@
*/
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));
- sect->section = currentSection;
- sect->loadSection = currentLoadSection;
- sect->scope = sym_GetCurrentSymbolScope();
- sect->offset = curOffset;
- sect->loadOffset = loadOffset;
- sect->next = sectionStack;
- sectionStack = sect;
+ entry->section = currentSection;
+ entry->loadSection = currentLoadSection;
+ entry->scope = sym_GetCurrentSymbolScope();
+ entry->offset = curOffset;
+ entry->loadOffset = loadOffset;
+ entry->unionStack = unionStack;
+ entry->next = sectionStack;
+ sectionStack = entry;
// Reset the section scope
currentSection = NULL;
currentLoadSection = NULL;
sym_SetCurrentSymbolScope(NULL);
+ unionStack = NULL;
}
void sect_PopSection(void)
@@ -998,6 +1011,7 @@
sym_SetCurrentSymbolScope(entry->scope);
curOffset = entry->offset;
loadOffset = entry->loadOffset;
+ unionStack = entry->unionStack;
sectionStack = entry->next;
free(entry);
--- /dev/null
+++ b/test/asm/union-pushs.asm
@@ -1,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
+
--- /dev/null
+++ b/test/asm/union-pushs.out.bin
@@ -1,0 +1,1 @@
+v
\ No newline at end of file