diff --git a/src/asm/section.cpp b/src/asm/section.cpp index 42123425..cc13a700 100644 --- a/src/asm/section.cpp +++ b/src/asm/section.cpp @@ -120,9 +120,8 @@ Section *sect_FindSectionByName(std::string const &name) { ++nbSectErrors; \ } while (0) -static unsigned int mergeSectUnion( - Section §, SectionType type, uint32_t org, uint8_t alignment, uint16_t alignOffset -) { +static unsigned int + mergeSectUnion(Section §, uint32_t org, uint8_t alignment, uint16_t alignOffset) { unsigned int nbSectErrors = 0; assume(alignment < 16); // Should be ensured by the caller @@ -133,12 +132,6 @@ static unsigned int mergeSectUnion( uint32_t sectAlignSize = 1u << sect.align; uint32_t sectAlignMask = sectAlignSize - 1; - // Unionized sections only need "compatible" constraints, and they end up with the strictest - // combination of both. - if (sectTypeHasData(type)) { - sectError("Cannot declare ROM sections as `UNION`"); - } - if (org != UINT32_MAX) { // If both are fixed, they must be the same if (sect.org != UINT32_MAX && sect.org != org) { @@ -266,12 +259,10 @@ static void mergeSections( } else { switch (mod) { case SECTION_UNION: - case SECTION_FRAGMENT: - nbSectErrors += mod == SECTION_UNION - ? mergeSectUnion(sect, type, org, alignment, alignOffset) - : mergeFragments(sect, org, alignment, alignOffset); - - // Common checks + case SECTION_FRAGMENT: { + unsigned int (*merge)(Section &, uint32_t, uint8_t, uint16_t) = + mod == SECTION_UNION ? mergeSectUnion : mergeFragments; + nbSectErrors += merge(sect, org, alignment, alignOffset); // If the section's bank is unspecified, override it if (sect.bank == UINT32_MAX) { @@ -282,6 +273,7 @@ static void mergeSections( sectError("Section already declared with different bank %" PRIu32, sect.bank); } break; + } case SECTION_NORMAL: errorNoTrace([&]() { @@ -513,6 +505,11 @@ void sect_NewSection( } } + if (mod == SECTION_UNION && sectTypeHasData(type)) { + error("Cannot declare ROM sections as `UNION`"); + return; + } + if (currentLoadSection) { sect_EndLoadSection("SECTION"); } @@ -1121,12 +1118,12 @@ std::string sect_PushSectionFragmentLiteral() { ); } + // This section has data (ROM0 or ROMX), so it cannot be a UNION + assume(currentSection->modifier != SECTION_UNION); + if (currentLoadSection) { fatal("`LOAD` blocks cannot contain fragment literals"); } - if (currentSection->modifier == SECTION_UNION) { - fatal("`SECTION UNION` cannot contain fragment literals"); - } // A section containing a fragment literal has to become a fragment too currentSection->modifier = SECTION_FRAGMENT; diff --git a/test/asm/fragment-literal-in-union.err b/test/asm/fragment-literal-in-union.err index d4792ab2..1a57bc2b 100644 --- a/test/asm/fragment-literal-in-union.err +++ b/test/asm/fragment-literal-in-union.err @@ -1,2 +1,6 @@ -FATAL: `SECTION UNION` cannot contain fragment literals +error: Cannot declare ROM sections as `UNION` + at fragment-literal-in-union.asm(1) +error: Cannot output data outside of a `SECTION` + at fragment-literal-in-union.asm(2) +FATAL: Cannot output fragment literals outside of a `SECTION` at fragment-literal-in-union.asm(3) diff --git a/test/asm/section-union-data.asm b/test/asm/section-union-data.asm new file mode 100644 index 00000000..5baf3ea7 --- /dev/null +++ b/test/asm/section-union-data.asm @@ -0,0 +1,2 @@ +SECTION UNION "wat", ROM0 +db 42 diff --git a/test/asm/section-union-data.err b/test/asm/section-union-data.err new file mode 100644 index 00000000..41989c98 --- /dev/null +++ b/test/asm/section-union-data.err @@ -0,0 +1,5 @@ +error: Cannot declare ROM sections as `UNION` + at section-union-data.asm(1) +error: Cannot output data outside of a `SECTION` + at section-union-data.asm(2) +Assembly aborted with 2 errors! diff --git a/test/link/section-conflict/different-mod/a.asm b/test/link/section-conflict/different-mod/a.asm index f5153ec4..d6eaca60 100644 --- a/test/link/section-conflict/different-mod/a.asm +++ b/test/link/section-conflict/different-mod/a.asm @@ -1,2 +1,2 @@ -section fragment "test", rom0 -db 1 +section fragment "test", wram0 +w1:: db diff --git a/test/link/section-conflict/different-mod/b.asm b/test/link/section-conflict/different-mod/b.asm index ba1bf3cb..135a0acb 100644 --- a/test/link/section-conflict/different-mod/b.asm +++ b/test/link/section-conflict/different-mod/b.asm @@ -1,2 +1,2 @@ -section union "test", rom0 -db 2 +section union "test", wram0 +w2:: db diff --git a/test/link/section-union/data-overlay.asm b/test/link/section-union/data-overlay.asm deleted file mode 100644 index 81bf1077..00000000 --- a/test/link/section-union/data-overlay.asm +++ /dev/null @@ -1,10 +0,0 @@ -IF !DEF(SECOND) - def DATA equs "ds 4" -ELSE - def DATA equs "db $aa, $bb, $cc, $dd" -ENDC - -SECTION UNION "overlaid data", ROM0 - {DATA} - - PURGE DATA diff --git a/test/link/section-union/data-overlay.out b/test/link/section-union/data-overlay.out deleted file mode 100644 index 3779676c..00000000 --- a/test/link/section-union/data-overlay.out +++ /dev/null @@ -1,7 +0,0 @@ -FATAL: Section "overlaid data" is of type `ROM0`, which cannot be `UNION`ized -Linking aborted with 1 error ---- -error: Cannot declare ROM sections as `UNION` - at (18) -FATAL: Cannot create section "overlaid data" (1 error) - at (18) diff --git a/test/link/section-union/different-data.asm b/test/link/section-union/different-data.asm deleted file mode 100644 index ca5f0798..00000000 --- a/test/link/section-union/different-data.asm +++ /dev/null @@ -1,8 +0,0 @@ -IF !DEF(SECOND) - def DATA = 1 -ELSE - def DATA = 2 -ENDC - -SECTION UNION "different data", ROM0 - db DATA diff --git a/test/link/section-union/different-data.out b/test/link/section-union/different-data.out deleted file mode 100644 index 66eb6e7f..00000000 --- a/test/link/section-union/different-data.out +++ /dev/null @@ -1,7 +0,0 @@ -FATAL: Section "different data" is of type `ROM0`, which cannot be `UNION`ized -Linking aborted with 1 error ---- -error: Cannot declare ROM sections as `UNION` - at (16) -FATAL: Cannot create section "different data" (1 error) - at (16) diff --git a/test/link/section-union/different-size.asm b/test/link/section-union/different-size.asm deleted file mode 100644 index f221b08c..00000000 --- a/test/link/section-union/different-size.asm +++ /dev/null @@ -1,8 +0,0 @@ -IF !DEF(SECOND) - def SIZE = 69 -ELSE - def SIZE = 420 -ENDC - -SECTION UNION "different section sizes", ROM0 - ds SIZE diff --git a/test/link/section-union/different-size.out b/test/link/section-union/different-size.out deleted file mode 100644 index e4fa9ac2..00000000 --- a/test/link/section-union/different-size.out +++ /dev/null @@ -1,7 +0,0 @@ -FATAL: Section "different section sizes" is of type `ROM0`, which cannot be `UNION`ized -Linking aborted with 1 error ---- -error: Cannot declare ROM sections as `UNION` - at (16) -FATAL: Cannot create section "different section sizes" (1 error) - at (16) diff --git a/test/link/section-union/different-syntaxes.asm b/test/link/section-union/different-syntaxes.asm deleted file mode 100644 index 54f5d089..00000000 --- a/test/link/section-union/different-syntaxes.asm +++ /dev/null @@ -1,10 +0,0 @@ -IF !DEF(SECOND) - def INSTR equs "sbc a" -ELSE - def INSTR equs "db $9f" -ENDC - -SECTION UNION "different syntaxes", ROM0 - {INSTR} - - PURGE INSTR diff --git a/test/link/section-union/different-syntaxes.out b/test/link/section-union/different-syntaxes.out deleted file mode 100644 index 2ea31aa0..00000000 --- a/test/link/section-union/different-syntaxes.out +++ /dev/null @@ -1,7 +0,0 @@ -FATAL: Section "different syntaxes" is of type `ROM0`, which cannot be `UNION`ized -Linking aborted with 1 error ---- -error: Cannot declare ROM sections as `UNION` - at (18) -FATAL: Cannot create section "different syntaxes" (1 error) - at (18) diff --git a/test/link/section-union/split-data.asm b/test/link/section-union/split-data.asm deleted file mode 100644 index cc5346a5..00000000 --- a/test/link/section-union/split-data.asm +++ /dev/null @@ -1,10 +0,0 @@ -IF !DEF(SECOND) - def DATA equs "ds 1\ndb $aa" -ELSE - def DATA equs "db $bb\nds 1" -ENDC - -SECTION UNION "mutually-overlaid data", ROM0 - {DATA} - - PURGE DATA diff --git a/test/link/section-union/split-data.out b/test/link/section-union/split-data.out deleted file mode 100644 index c849cb68..00000000 --- a/test/link/section-union/split-data.out +++ /dev/null @@ -1,7 +0,0 @@ -FATAL: Section "mutually-overlaid data" is of type `ROM0`, which cannot be `UNION`ized -Linking aborted with 1 error ---- -error: Cannot declare ROM sections as `UNION` - at (18) -FATAL: Cannot create section "mutually-overlaid data" (1 error) - at (18)