mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-27 21:42:06 +00:00
Implement unionized sections in RGBASM
This touched a lot more code than initially expected, for two reasons. First, this broke a big RGBASM assumption: that sections are always being written to at their end. This plus other problems required touching basically the entirety of `section.c`. Second, I tried different solutions to solve the above problem, and along the way I cleaned up many things around. (I believe that keeping this to "cleanup" commits yields subpar results, and since it's boring they get postponed anyways.) RGBLINK support still needs to be added, but this will come next.
This commit is contained in:
@@ -393,20 +393,19 @@ static void startUnion(void)
|
||||
if (nUnionDepth > MAXUNIONS)
|
||||
fatalerror("Too many nested UNIONs");
|
||||
|
||||
unionStart[unionIndex] = nPC;
|
||||
unionStart[unionIndex] = curOffset;
|
||||
unionSize[unionIndex] = 0;
|
||||
}
|
||||
|
||||
static void updateUnion(void)
|
||||
{
|
||||
uint32_t unionIndex = nUnionDepth - 1;
|
||||
uint32_t size = nPC - unionStart[unionIndex];
|
||||
uint32_t size = curOffset - unionStart[unionIndex];
|
||||
|
||||
if (size > unionSize[unionIndex])
|
||||
unionSize[unionIndex] = size;
|
||||
|
||||
nPC = unionStart[unionIndex];
|
||||
pCurrentSection->nPC = unionStart[unionIndex];
|
||||
curOffset = unionStart[unionIndex];
|
||||
}
|
||||
|
||||
static size_t strlenUTF8(const char *s)
|
||||
@@ -601,7 +600,8 @@ static void strsubUTF8(char *dest, const char *src, uint32_t pos, uint32_t len)
|
||||
%token T_SECT_WRAM0 T_SECT_VRAM T_SECT_ROMX T_SECT_ROM0 T_SECT_HRAM
|
||||
%token T_SECT_WRAMX T_SECT_SRAM T_SECT_OAM
|
||||
|
||||
%type <macroArg> macroargs;
|
||||
%type <nConstValue> sectunion
|
||||
%type <macroArg> macroargs
|
||||
|
||||
%token T_Z80_ADC T_Z80_ADD T_Z80_AND
|
||||
%token T_Z80_BIT
|
||||
@@ -815,7 +815,8 @@ assert_type : /* empty */ { $$ = ASSERT_ERROR; }
|
||||
assert : T_POP_ASSERT assert_type relocexpr
|
||||
{
|
||||
if (!rpn_isKnown(&$3)) {
|
||||
if (!out_CreateAssert($2, &$3, ""))
|
||||
if (!out_CreateAssert($2, &$3, "",
|
||||
sect_GetOutputOffset()))
|
||||
yyerror("Assertion creation failed: %s",
|
||||
strerror(errno));
|
||||
} else if ($3.nVal == 0) {
|
||||
@@ -836,7 +837,8 @@ assert : T_POP_ASSERT assert_type relocexpr
|
||||
| T_POP_ASSERT assert_type relocexpr ',' string
|
||||
{
|
||||
if (!rpn_isKnown(&$3)) {
|
||||
if (!out_CreateAssert($2, &$3, $5))
|
||||
if (!out_CreateAssert($2, &$3, $5,
|
||||
sect_GetOutputOffset()))
|
||||
yyerror("Assertion creation failed: %s",
|
||||
strerror(errno));
|
||||
} else if ($3.nVal == 0) {
|
||||
@@ -968,8 +970,7 @@ endu : T_POP_ENDU {
|
||||
updateUnion();
|
||||
|
||||
nUnionDepth--;
|
||||
nPC = unionStart[nUnionDepth] + unionSize[nUnionDepth];
|
||||
pCurrentSection->nPC = nPC;
|
||||
curOffset = unionStart[nUnionDepth] + unionSize[nUnionDepth];
|
||||
}
|
||||
;
|
||||
|
||||
@@ -1418,11 +1419,14 @@ string : T_STRING {
|
||||
}
|
||||
;
|
||||
|
||||
section : T_POP_SECTION string ',' sectiontype sectorg sectattrs {
|
||||
out_NewSection($2, $4, $5, &$6);
|
||||
section : T_POP_SECTION sectunion string ',' sectiontype sectorg sectattrs {
|
||||
out_NewSection($3, $5, $6, &$7, $2);
|
||||
}
|
||||
;
|
||||
|
||||
sectunion : /* empty */ { $$ = false; }
|
||||
| T_POP_UNION { $$ = true; }
|
||||
|
||||
sectiontype : T_SECT_WRAM0 { $$ = SECTTYPE_WRAM0; }
|
||||
| T_SECT_VRAM { $$ = SECTTYPE_VRAM; }
|
||||
| T_SECT_ROMX { $$ = SECTTYPE_ROMX; }
|
||||
|
||||
Reference in New Issue
Block a user