mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-20 18:22:07 +00:00
Add more tests for unionized sections + fix bugs
Implementing those tests found a few bugs... oops
This commit is contained in:
@@ -155,6 +155,10 @@ static struct Section *getSection(char const *pzName, enum SectionType type,
|
||||
if (pSect->nOrg != -1 && pSect->nOrg != org)
|
||||
fail("Section \"%s\" already declared as fixed at different address $%x",
|
||||
pSect->pzName, pSect->nOrg);
|
||||
else if (pSect->nAlign != 0
|
||||
&& ((pSect->nAlign - 1) & org))
|
||||
fail("Section \"%s\" already declared as aligned to %u bytes",
|
||||
pSect->pzName, pSect->nAlign);
|
||||
else
|
||||
/* Otherwise, just override */
|
||||
pSect->nOrg = org;
|
||||
@@ -207,7 +211,7 @@ static struct Section *getSection(char const *pzName, enum SectionType type,
|
||||
fail("Section \"%s\" already declared as unaligned",
|
||||
pSect->pzName);
|
||||
else
|
||||
fail("Section \"%s\" already declared as aligned to %u bits",
|
||||
fail("Section \"%s\" already declared as aligned to %u bytes",
|
||||
pSect->pzName, pSect->nAlign);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,6 +38,10 @@ void sect_ForEach(void (*callback)(struct Section *, void *), void *arg)
|
||||
|
||||
static void mergeSections(struct Section *target, struct Section *other)
|
||||
{
|
||||
if (target->type != other->type)
|
||||
errx(1, "Section \"%s\" is defined with conflicting types %s and %s",
|
||||
other->name,
|
||||
typeNames[target->type], typeNames[other->type]);
|
||||
if (other->isAddressFixed) {
|
||||
if (target->isAddressFixed) {
|
||||
if (target->org != other->org)
|
||||
|
||||
@@ -3,6 +3,6 @@ ERROR: section-union.asm(37):
|
||||
ERROR: section-union.asm(37):
|
||||
Section "test" already declared as fixed at $c000
|
||||
ERROR: section-union.asm(37):
|
||||
Section "test" already declared as aligned to 256 bits
|
||||
Section "test" already declared as aligned to 256 bytes
|
||||
ERROR: section-union.asm(37):
|
||||
Cannot create section "test" (3 errors)
|
||||
|
||||
10
test/link/section-union/align-conflict.asm
Normal file
10
test/link/section-union/align-conflict.asm
Normal file
@@ -0,0 +1,10 @@
|
||||
IF !DEF(SECOND)
|
||||
ATTRS equs ",ALIGN[2]"
|
||||
ELSE
|
||||
ATTRS equs "[$CAFE]"
|
||||
ENDC
|
||||
|
||||
SECTION UNION "conflicting alignment", WRAM0 ATTRS
|
||||
db
|
||||
|
||||
PURGE ATTRS
|
||||
6
test/link/section-union/align-conflict.out
Normal file
6
test/link/section-union/align-conflict.out
Normal file
@@ -0,0 +1,6 @@
|
||||
error: Section "conflicting alignment" is defined with conflicting 4-byte alignment and address $cafe
|
||||
---
|
||||
ERROR: -(18):
|
||||
Section "conflicting alignment" already declared as aligned to 4 bytes
|
||||
ERROR: -(18):
|
||||
Cannot create section "conflicting alignment" (1 errors)
|
||||
10
test/link/section-union/bad-types.asm
Normal file
10
test/link/section-union/bad-types.asm
Normal file
@@ -0,0 +1,10 @@
|
||||
IF !DEF(SECOND)
|
||||
TYPE equs "HRAM"
|
||||
ELSE
|
||||
TYPE equs "WRAM0"
|
||||
ENDC
|
||||
|
||||
SECTION UNION "conflicting types", TYPE
|
||||
db
|
||||
|
||||
PURGE TYPE
|
||||
6
test/link/section-union/bad-types.out
Normal file
6
test/link/section-union/bad-types.out
Normal file
@@ -0,0 +1,6 @@
|
||||
error: Section "conflicting types" is defined with conflicting types HRAM and WRAM0
|
||||
---
|
||||
ERROR: -(18):
|
||||
Section "conflicting types" already exists but with type HRAM
|
||||
ERROR: -(18):
|
||||
Cannot create section "conflicting types" (1 errors)
|
||||
8
test/link/section-union/bank-conflict.asm
Normal file
8
test/link/section-union/bank-conflict.asm
Normal file
@@ -0,0 +1,8 @@
|
||||
IF !DEF(SECOND)
|
||||
SECOND equs "4"
|
||||
ENDC
|
||||
|
||||
SECTION UNION "conflicting banks", WRAMX, BANK[SECOND]
|
||||
db
|
||||
|
||||
PURGE SECOND
|
||||
6
test/link/section-union/bank-conflict.out
Normal file
6
test/link/section-union/bank-conflict.out
Normal file
@@ -0,0 +1,6 @@
|
||||
error: Section "conflicting banks" is defined with conflicting banks 4 and 1
|
||||
---
|
||||
ERROR: -(14):
|
||||
Section "conflicting banks" already declared with different bank 4
|
||||
ERROR: -(14):
|
||||
Cannot create section "conflicting banks" (1 errors)
|
||||
10
test/link/section-union/data-overlay.asm
Normal file
10
test/link/section-union/data-overlay.asm
Normal file
@@ -0,0 +1,10 @@
|
||||
IF !DEF(SECOND)
|
||||
DATA equs "ds 4"
|
||||
ELSE
|
||||
DATA equs "db $aa, $bb, $cc, $dd"
|
||||
ENDC
|
||||
|
||||
SECTION UNION "overlaid data", ROM0
|
||||
DATA
|
||||
|
||||
PURGE DATA
|
||||
6
test/link/section-union/data-overlay.out
Normal file
6
test/link/section-union/data-overlay.out
Normal file
@@ -0,0 +1,6 @@
|
||||
error: Section "overlaid data" is of type ROM0, which cannot be unionized
|
||||
---
|
||||
ERROR: -(18):
|
||||
Cannot declare ROM sections as UNION
|
||||
ERROR: -(18):
|
||||
Cannot create section "overlaid data" (1 errors)
|
||||
8
test/link/section-union/different-data.asm
Normal file
8
test/link/section-union/different-data.asm
Normal file
@@ -0,0 +1,8 @@
|
||||
IF !DEF(SECOND)
|
||||
DATA = 1
|
||||
ELSE
|
||||
DATA = 2
|
||||
ENDC
|
||||
|
||||
SECTION UNION "different data", ROM0
|
||||
db DATA
|
||||
6
test/link/section-union/different-data.out
Normal file
6
test/link/section-union/different-data.out
Normal file
@@ -0,0 +1,6 @@
|
||||
error: Section "different data" is of type ROM0, which cannot be unionized
|
||||
---
|
||||
ERROR: -(16):
|
||||
Cannot declare ROM sections as UNION
|
||||
ERROR: -(16):
|
||||
Cannot create section "different data" (1 errors)
|
||||
8
test/link/section-union/different-size.asm
Normal file
8
test/link/section-union/different-size.asm
Normal file
@@ -0,0 +1,8 @@
|
||||
IF !DEF(SECOND)
|
||||
SIZE = 69
|
||||
ELSE
|
||||
SIZE = 420
|
||||
ENDC
|
||||
|
||||
SECTION UNION "different section sizes", ROM0
|
||||
ds SIZE
|
||||
6
test/link/section-union/different-size.out
Normal file
6
test/link/section-union/different-size.out
Normal file
@@ -0,0 +1,6 @@
|
||||
error: Section "different section sizes" is of type ROM0, which cannot be unionized
|
||||
---
|
||||
ERROR: -(16):
|
||||
Cannot declare ROM sections as UNION
|
||||
ERROR: -(16):
|
||||
Cannot create section "different section sizes" (1 errors)
|
||||
10
test/link/section-union/different-syntaxes.asm
Normal file
10
test/link/section-union/different-syntaxes.asm
Normal file
@@ -0,0 +1,10 @@
|
||||
IF !DEF(SECOND)
|
||||
INSTR equs "sbc a"
|
||||
ELSE
|
||||
INSTR equs "db $9f"
|
||||
ENDC
|
||||
|
||||
SECTION UNION "different syntaxes", ROM0
|
||||
INSTR
|
||||
|
||||
PURGE INSTR
|
||||
6
test/link/section-union/different-syntaxes.out
Normal file
6
test/link/section-union/different-syntaxes.out
Normal file
@@ -0,0 +1,6 @@
|
||||
error: Section "different syntaxes" is of type ROM0, which cannot be unionized
|
||||
---
|
||||
ERROR: -(18):
|
||||
Cannot declare ROM sections as UNION
|
||||
ERROR: -(18):
|
||||
Cannot create section "different syntaxes" (1 errors)
|
||||
12
test/link/section-union/no-room.asm
Normal file
12
test/link/section-union/no-room.asm
Normal file
@@ -0,0 +1,12 @@
|
||||
; NB: the error is that there is no room to place the unionized section in,
|
||||
; so RGBASM can't possibly error out.
|
||||
IF !DEF(SECOND)
|
||||
SECTION "bloat", WRAMX[$d000], BANK[2]
|
||||
ds $fe0
|
||||
|
||||
SECTION UNION "test", WRAMX, BANK[2]
|
||||
db
|
||||
ELSE
|
||||
SECTION UNION "test", WRAMX, ALIGN[6]
|
||||
db
|
||||
ENDC
|
||||
2
test/link/section-union/no-room.out
Normal file
2
test/link/section-union/no-room.out
Normal file
@@ -0,0 +1,2 @@
|
||||
error: Unable to place "test" (WRAMX section) in bank $02 with align mask ffffffc0
|
||||
---
|
||||
8
test/link/section-union/org-conflict.asm
Normal file
8
test/link/section-union/org-conflict.asm
Normal file
@@ -0,0 +1,8 @@
|
||||
IF !DEF(SECOND)
|
||||
ADDR = $BEEF
|
||||
ELSE
|
||||
ADDR = $BABE
|
||||
ENDC
|
||||
|
||||
SECTION UNION "conflicting address", SRAM[ADDR]
|
||||
db
|
||||
6
test/link/section-union/org-conflict.out
Normal file
6
test/link/section-union/org-conflict.out
Normal file
@@ -0,0 +1,6 @@
|
||||
error: Section "conflicting address" is defined with conflicting addresses $beef and $babe
|
||||
---
|
||||
ERROR: -(16):
|
||||
Section "conflicting address" already declared as fixed at different address $beef
|
||||
ERROR: -(16):
|
||||
Cannot create section "conflicting address" (1 errors)
|
||||
10
test/link/section-union/split-data.asm
Normal file
10
test/link/section-union/split-data.asm
Normal file
@@ -0,0 +1,10 @@
|
||||
IF !DEF(SECOND)
|
||||
DATA equs "ds 1\ndb $aa"
|
||||
ELSE
|
||||
DATA equs "db $bb\nds 1"
|
||||
ENDC
|
||||
|
||||
SECTION UNION "mutually-overlaid data", ROM0
|
||||
DATA
|
||||
|
||||
PURGE DATA
|
||||
6
test/link/section-union/split-data.out
Normal file
6
test/link/section-union/split-data.out
Normal file
@@ -0,0 +1,6 @@
|
||||
error: Section "mutually-overlaid data" is of type ROM0, which cannot be unionized
|
||||
---
|
||||
ERROR: -(18):
|
||||
Cannot declare ROM sections as UNION
|
||||
ERROR: -(18):
|
||||
Cannot create section "mutually-overlaid data" (1 errors)
|
||||
@@ -80,12 +80,25 @@ $RGBLINK -o $gbtemp2 $otemp
|
||||
i="high-low.asm" tryCmp $gbtemp $gbtemp2
|
||||
rc=$(($? || $rc))
|
||||
|
||||
$RGBASM -o $otemp section-union/a.asm
|
||||
$RGBASM -o $gbtemp2 section-union/b.asm
|
||||
$RGBLINK -o $gbtemp -l section-union/script.link $otemp $gbtemp2
|
||||
dd if=$gbtemp count=1 bs=$(printf %s $(wc -c < section-union/ref.out.bin)) > $otemp 2>/dev/null
|
||||
i="section-union.asm" tryCmp section-union/ref.out.bin $otemp
|
||||
$RGBASM -o $otemp section-union/good/a.asm
|
||||
$RGBASM -o $gbtemp2 section-union/good/b.asm
|
||||
$RGBLINK -o $gbtemp -l section-union/good/script.link $otemp $gbtemp2
|
||||
dd if=$gbtemp count=1 bs=$(printf %s $(wc -c < section-union/good/ref.out.bin)) > $otemp 2>/dev/null
|
||||
i="section-union.asm" tryCmp section-union/good/ref.out.bin $otemp
|
||||
rc=$(($? || $rc))
|
||||
for i in section-union/*.asm; do
|
||||
$RGBASM -o $otemp $i
|
||||
$RGBASM -o $gbtemp2 $i -DSECOND
|
||||
if $RGBLINK $otemp $gbtemp2 > $outtemp 2>&1; then
|
||||
echo -e "${bold}${red}$i didn't fail to link!${rescolors}${resbold}"
|
||||
rc=1
|
||||
fi
|
||||
echo --- >> $outtemp
|
||||
# Ensure RGBASM also errors out
|
||||
echo 'SECOND equs "1"' | cat $i - $i | $RGBASM - 2>> $outtemp
|
||||
tryDiff ${i%.asm}.out $outtemp
|
||||
rc=$(($? || $rc))
|
||||
done
|
||||
|
||||
rm -f $otemp $gbtemp $gbtemp2 $outtemp
|
||||
exit $rc
|
||||
|
||||
Reference in New Issue
Block a user