Allow STARTOF(SECTTYPE) and SIZEOF(SECTTYPE) to be constant when possible (#2131)

This commit is contained in:
Rangi authored and GitHub committed 2026-09-26 19:08:28 +02:00
1 parent 548a11c3ef
commit e0ee6c9013
6 files changed
+45 -6

No files matched your search

+11 -2
View File
@@ -772,7 +772,15 @@ and no longer the current section).
If If
.Ar arg .Ar arg
is a section type keyword, it returns the size of that section type. is a section type keyword, it returns the size of that section type.
The result is not constant, since only RGBLINK can compute its value. The result is a known constant except for
.Ic ROM0
and
.Ic WRAM0 ,
since their sizes may be affected by RGBLINK options
.Fl t
and
.Fl w
respectively.
.Pp .Pp
If If
.Ar arg .Ar arg
@@ -786,7 +794,8 @@ The result is a known constant if the section has a fixed address.
If If
.Ar arg .Ar arg
is a section type keyword, it returns the starting address of that section type. is a section type keyword, it returns the starting address of that section type.
The result is not constant, since only RGBLINK can compute its value. .Pp
The result is always a known constant at assembly time.
.El .El
.Sh SECTIONS .Sh SECTIONS
Before you can start writing code, you must define a section. Before you can start writing code, you must define a section.
+10 -4
View File
@@ -142,14 +142,20 @@ void Expression::makeStartOfSection(std::string const &sectName) {
void Expression::makeSizeOfSectionType(SectionType type) { void Expression::makeSizeOfSectionType(SectionType type) {
assume(rpn.empty()); assume(rpn.empty());
data = "Section type's size is not known"; if (type == SECTTYPE_WRAM0) {
rpn.emplace_back(RPN_SIZEOF_SECTTYPE, static_cast<uint8_t>(type)); data = "Section type WRAM0's size is not known (can be affected by RGBLINK '-w/--wramx')";
rpn.emplace_back(RPN_SIZEOF_SECTTYPE, static_cast<uint8_t>(type));
} else if (type == SECTTYPE_ROM0) {
data = "Section type ROM0's size is not known (can be affected by RGBLINK '-t/--tiny')";
rpn.emplace_back(RPN_SIZEOF_SECTTYPE, static_cast<uint8_t>(type));
} else {
data = static_cast<int32_t>(sectionTypeInfo[type].size);
}
} }
void Expression::makeStartOfSectionType(SectionType type) { void Expression::makeStartOfSectionType(SectionType type) {
assume(rpn.empty()); assume(rpn.empty());
data = "Section type's start is not known"; data = static_cast<int32_t>(sectionTypeInfo[type].startAddr);
rpn.emplace_back(RPN_STARTOF_SECTTYPE, static_cast<uint8_t>(type));
} }
static bool tryConstZero(Expression const &lhs, Expression const &rhs) { static bool tryConstZero(Expression const &lhs, Expression const &rhs) {
@@ -0,0 +1,5 @@
SECTION "ROM0", ROM0[STARTOF(ROM0)]
Label:: ds SIZEOF(ROM0)
SECTION "WRAM0", WRAM0[STARTOF(WRAM0)]
wLabel:: ds SIZEOF(WRAM0)
@@ -0,0 +1,5 @@
error: Expected constant expression: Section type ROM0's size is not known (can be affected by RGBLINK '-t/--tiny')
at secttype-sizeof-startof-unknown.asm(2)
error: Expected constant expression: Section type WRAM0's size is not known (can be affected by RGBLINK '-w/--wramx')
at secttype-sizeof-startof-unknown.asm(5)
Assembly aborted with 2 errors
+13
View File
@@ -0,0 +1,13 @@
SECTION "ROMX", ROMX[STARTOF(ROMX)], BANK[1]
xLabel:: ds SIZEOF(ROMX), $22
SECTION "VRAM", VRAM[STARTOF(VRAM)], BANK[0]
vLabel:: ds SIZEOF(VRAM)
SECTION "ROM0", ROM0[STARTOF(ROM0)]
ASSERT !ISCONST(SIZEOF(ROM0)) ; rgblink may have -t/--tiny
Label:: ds $4000, $11
SECTION "WRAM0", WRAM0[STARTOF(WRAM0)]
ASSERT !ISCONST(SIZEOF(WRAM0)) ; rgblink may have -w/--wramx
wLabel:: ds $1000
+1
View File
@@ -0,0 +1 @@
Line truncated