Avoid hard-coding a redundant "FATAL:" in RGBLINK

This commit is contained in:
Rangi42
2025-07-27 20:07:53 -04:00
parent 8b1a5244f7
commit d16751f56a
5 changed files with 46 additions and 11 deletions

View File

@@ -379,15 +379,15 @@ static void categorizeSection(Section &section) {
sections.insert(pos, &section);
}
static std::vector<Section *> checkOverlayCompat() {
std::vector<Section *> unfixedSections;
static std::vector<Section const *> checkOverlayCompat() {
std::vector<Section const *> unfixedSections;
if (!options.overlayFileName) {
return unfixedSections;
}
for (uint8_t constraints = std::size(unassignedSections); constraints--;) {
if ((constraints & (BANK_CONSTRAINED | ORG_CONSTRAINED))
if (((constraints & BANK_CONSTRAINED) && (constraints & ORG_CONSTRAINED))
|| unassignedSections[constraints].empty()) {
continue;
}
@@ -418,17 +418,26 @@ void assign_AssignSections() {
});
// Overlaying requires only fully-constrained sections
if (std::vector<Section *> unfixedSections = checkOverlayCompat(); !unfixedSections.empty()) {
if (std::vector<Section const *> unfixedSections = checkOverlayCompat();
!unfixedSections.empty()) {
size_t nbUnfixedSections = unfixedSections.size();
fputs("FATAL: All sections must be fixed when using an overlay file", stderr);
for (size_t i = 0; i < nbUnfixedSections; ++i) {
fprintf(stderr, "%c \"%s\"", i == 0 ? ';' : ',', unfixedSections[i]->name.c_str());
std::string unfixedList;
for (Section const *section : unfixedSections) {
unfixedList += "\n- \"";
unfixedList += section->name;
unfixedList += '"';
}
if (nbSectionsToAssign != nbUnfixedSections) {
fprintf(stderr, " and %" PRIu64 " more", nbSectionsToAssign - nbUnfixedSections);
if (nbSectionsToAssign > nbUnfixedSections) {
unfixedList += "\n- and ";
unfixedList += std::to_string(nbSectionsToAssign - nbUnfixedSections);
unfixedList += " more";
}
fprintf(stderr, " %s not\n", nbSectionsToAssign == 1 ? "is" : "are");
exit(1);
fatal(
"All sections must be fixed when using an overlay file; %" PRIu64 " %s not:%s",
nbSectionsToAssign,
nbSectionsToAssign == 1 ? "is" : "are",
unfixedList.c_str()
);
}
// Assign sections in decreasing constraint order

View File

@@ -0,0 +1,4 @@
FOR n, 15
SECTION "test {d:n}", ROM0
db n
ENDR

View File

@@ -0,0 +1,13 @@
FATAL: All sections must be fixed when using an overlay file; 15 are not:
- "test 14"
- "test 13"
- "test 12"
- "test 11"
- "test 10"
- "test 9"
- "test 8"
- "test 7"
- "test 6"
- "test 5"
- and 5 more
Linking aborted with 1 error

File diff suppressed because one or more lines are too long

View File

@@ -233,6 +233,14 @@ tryDiff "$test"/out.err "$outtemp"
tryCmp "$test"/out.gb "$gbtemp"
evaluateTest
test="overlay/unfixed"
startTest
"$RGBASM" -o "$otemp" "$test"/a.asm
continueTest
rgblinkQuiet -o "$gbtemp" -O "$test"/overlay.gb "$otemp" 2>"$outtemp"
tryDiff "$test"/out.err "$outtemp"
evaluateTest
test="overlay/tiny"
startTest
"$RGBASM" -o "$otemp" "$test"/a.asm