mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-21 18:52:07 +00:00
Remove errx and errors.hpp (#1737)
This commit is contained in:
@@ -9,7 +9,7 @@
|
||||
#include <string.h>
|
||||
#include <vector>
|
||||
|
||||
#include "error.hpp"
|
||||
#include "diagnostics.hpp"
|
||||
#include "helpers.hpp"
|
||||
#include "itertools.hpp"
|
||||
#include "linkdefs.hpp"
|
||||
@@ -299,7 +299,7 @@ static void placeSection(Section §ion) {
|
||||
|
||||
// If a section failed to go to several places, nothing we can report
|
||||
if (!section.isBankFixed || !section.isAddressFixed) {
|
||||
errx(
|
||||
fatal(
|
||||
"Unable to place \"%s\" (%s section) %s",
|
||||
section.name.c_str(),
|
||||
sectionTypeInfo[section.type].name.c_str(),
|
||||
@@ -308,7 +308,7 @@ static void placeSection(Section §ion) {
|
||||
}
|
||||
// If the section just can't fit the bank, report that
|
||||
else if (section.org + section.size > endaddr(section.type) + 1) {
|
||||
errx(
|
||||
fatal(
|
||||
"Unable to place \"%s\" (%s section) %s: section runs past end of region ($%04x > "
|
||||
"$%04x)",
|
||||
section.name.c_str(),
|
||||
@@ -320,7 +320,7 @@ static void placeSection(Section §ion) {
|
||||
}
|
||||
// Otherwise there is overlap with another section
|
||||
else {
|
||||
errx(
|
||||
fatal(
|
||||
"Unable to place \"%s\" (%s section) %s: section overlaps with \"%s\"",
|
||||
section.name.c_str(),
|
||||
sectionTypeInfo[section.type].name.c_str(),
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "error.hpp"
|
||||
#include "diagnostics.hpp"
|
||||
#include "extern/getopt.hpp"
|
||||
#include "helpers.hpp" // assume
|
||||
#include "itertools.hpp"
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
#include <string.h>
|
||||
#include <vector>
|
||||
|
||||
#include "error.hpp"
|
||||
#include "diagnostics.hpp"
|
||||
#include "helpers.hpp"
|
||||
#include "linkdefs.hpp"
|
||||
#include "platform.hpp"
|
||||
@@ -37,7 +37,7 @@ static std::vector<std::vector<FileStackNode>> nodes;
|
||||
FILE *tmpFile = file; \
|
||||
type tmpVal = func(tmpFile); \
|
||||
if (tmpVal == (errval)) { \
|
||||
errx(__VA_ARGS__, feof(tmpFile) ? "Unexpected end of file" : strerror(errno)); \
|
||||
fatal(__VA_ARGS__, feof(tmpFile) ? "Unexpected end of file" : strerror(errno)); \
|
||||
} \
|
||||
var = static_cast<vartype>(tmpVal); \
|
||||
} while (0)
|
||||
@@ -78,7 +78,7 @@ static int64_t readLong(FILE *file) {
|
||||
std::string &tmpVal = var; \
|
||||
for (int tmpByte = getc(tmpFile); tmpByte != '\0'; tmpByte = getc(tmpFile)) { \
|
||||
if (tmpByte == EOF) { \
|
||||
errx(__VA_ARGS__, feof(tmpFile) ? "Unexpected end of file" : strerror(errno)); \
|
||||
fatal(__VA_ARGS__, feof(tmpFile) ? "Unexpected end of file" : strerror(errno)); \
|
||||
} else { \
|
||||
tmpVal.push_back(tmpByte); \
|
||||
} \
|
||||
@@ -136,8 +136,6 @@ static void readFileStackNode(
|
||||
}
|
||||
if (!node.parent) {
|
||||
fatal(
|
||||
nullptr,
|
||||
0,
|
||||
"%s is not a valid object file: root node (#%" PRIu32 ") may not be REPT",
|
||||
fileName,
|
||||
nodeID
|
||||
@@ -275,7 +273,7 @@ static void readPatch(
|
||||
size_t nbElementsRead = fread(patch.rpnExpression.data(), 1, rpnSize, file);
|
||||
|
||||
if (nbElementsRead != rpnSize) {
|
||||
errx(
|
||||
fatal(
|
||||
"%s: Cannot read \"%s\"'s patch #%" PRIu32 "'s RPN expression: %s",
|
||||
fileName,
|
||||
sectName.c_str(),
|
||||
@@ -314,7 +312,7 @@ static void readSection(
|
||||
);
|
||||
tryReadLong(tmp, file, "%s: Cannot read \"%s\"'s' size: %s", fileName, section.name.c_str());
|
||||
if (tmp < 0 || tmp > UINT16_MAX) {
|
||||
errx("\"%s\"'s section size ($%" PRIx32 ") is invalid", section.name.c_str(), tmp);
|
||||
fatal("\"%s\"'s section size ($%" PRIx32 ") is invalid", section.name.c_str(), tmp);
|
||||
}
|
||||
section.size = tmp;
|
||||
section.offset = 0;
|
||||
@@ -322,7 +320,7 @@ static void readSection(
|
||||
uint8_t, byte, file, "%s: Cannot read \"%s\"'s type: %s", fileName, section.name.c_str()
|
||||
);
|
||||
if (uint8_t type = byte & 0x3F; type >= SECTTYPE_INVALID) {
|
||||
errx("\"%s\" has unknown section type 0x%02x", section.name.c_str(), type);
|
||||
fatal("\"%s\" has unknown section type 0x%02x", section.name.c_str(), type);
|
||||
} else {
|
||||
section.type = SectionType(type);
|
||||
}
|
||||
@@ -336,7 +334,7 @@ static void readSection(
|
||||
tryReadLong(tmp, file, "%s: Cannot read \"%s\"'s org: %s", fileName, section.name.c_str());
|
||||
section.isAddressFixed = tmp >= 0;
|
||||
if (tmp > UINT16_MAX) {
|
||||
error(nullptr, 0, "\"%s\"'s org is too large ($%" PRIx32 ")", section.name.c_str(), tmp);
|
||||
error("\"%s\"'s org is too large ($%" PRIx32 ")", section.name.c_str(), tmp);
|
||||
tmp = UINT16_MAX;
|
||||
}
|
||||
section.org = tmp;
|
||||
@@ -360,13 +358,7 @@ static void readSection(
|
||||
tmp, file, "%s: Cannot read \"%s\"'s alignment offset: %s", fileName, section.name.c_str()
|
||||
);
|
||||
if (tmp > UINT16_MAX) {
|
||||
error(
|
||||
nullptr,
|
||||
0,
|
||||
"\"%s\"'s alignment offset is too large ($%" PRIx32 ")",
|
||||
section.name.c_str(),
|
||||
tmp
|
||||
);
|
||||
error("\"%s\"'s alignment offset is too large ($%" PRIx32 ")", section.name.c_str(), tmp);
|
||||
tmp = UINT16_MAX;
|
||||
}
|
||||
section.alignOfs = tmp;
|
||||
@@ -376,7 +368,7 @@ static void readSection(
|
||||
section.data.resize(section.size);
|
||||
if (size_t nbRead = fread(section.data.data(), 1, section.size, file);
|
||||
nbRead != section.size) {
|
||||
errx(
|
||||
fatal(
|
||||
"%s: Cannot read \"%s\"'s data: %s",
|
||||
fileName,
|
||||
section.name.c_str(),
|
||||
@@ -446,7 +438,7 @@ void obj_ReadFile(char const *fileName, unsigned int fileID) {
|
||||
file = stdin;
|
||||
}
|
||||
if (!file) {
|
||||
errx("Failed to open file \"%s\": %s", fileName, strerror(errno));
|
||||
fatal("Failed to open file \"%s\": %s", fileName, strerror(errno));
|
||||
}
|
||||
Defer closeFile{[&] { fclose(file); }};
|
||||
|
||||
@@ -457,7 +449,7 @@ void obj_ReadFile(char const *fileName, unsigned int fileID) {
|
||||
ungetc(c, file); // Guaranteed to work
|
||||
switch (c) {
|
||||
case EOF:
|
||||
fatal(nullptr, 0, "File \"%s\" is empty!", fileName);
|
||||
fatal("File \"%s\" is empty!", fileName);
|
||||
|
||||
case 'R':
|
||||
break;
|
||||
@@ -484,7 +476,7 @@ void obj_ReadFile(char const *fileName, unsigned int fileID) {
|
||||
|
||||
if (fscanf(file, RGBDS_OBJECT_VERSION_STRING "%n", &matchedElems) == 1
|
||||
&& matchedElems != literal_strlen(RGBDS_OBJECT_VERSION_STRING)) {
|
||||
errx("%s: Not a RGBDS object file", fileName);
|
||||
fatal("%s: Not a RGBDS object file", fileName);
|
||||
}
|
||||
|
||||
verbosePrint("Reading object file %s\n", fileName);
|
||||
@@ -493,7 +485,7 @@ void obj_ReadFile(char const *fileName, unsigned int fileID) {
|
||||
|
||||
tryReadLong(revNum, file, "%s: Cannot read revision number: %s", fileName);
|
||||
if (revNum != RGBDS_OBJECT_REV) {
|
||||
errx(
|
||||
fatal(
|
||||
"%s: Unsupported object file for rgblink %s; try rebuilding \"%s\"%s"
|
||||
" (expected revision %d, got %d)",
|
||||
fileName,
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
#include <string.h>
|
||||
#include <vector>
|
||||
|
||||
#include "error.hpp"
|
||||
#include "diagnostics.hpp"
|
||||
#include "extern/utf8decoder.hpp"
|
||||
#include "helpers.hpp"
|
||||
#include "linkdefs.hpp"
|
||||
@@ -71,7 +71,7 @@ void out_AddSection(Section const §ion) {
|
||||
uint32_t minNbBanks = targetBank + 1;
|
||||
|
||||
if (minNbBanks > maxNbBanks[section.type]) {
|
||||
errx(
|
||||
fatal(
|
||||
"Section \"%s\" has an invalid bank range (%" PRIu32 " > %" PRIu32 ")",
|
||||
section.name.c_str(),
|
||||
section.bank,
|
||||
@@ -213,7 +213,7 @@ static void writeROM() {
|
||||
outputFile = stdout;
|
||||
}
|
||||
if (!outputFile) {
|
||||
errx("Failed to open output file \"%s\": %s", outputFileName, strerror(errno));
|
||||
fatal("Failed to open output file \"%s\": %s", outputFileName, strerror(errno));
|
||||
}
|
||||
}
|
||||
Defer closeOutputFile{[&] {
|
||||
@@ -231,7 +231,7 @@ static void writeROM() {
|
||||
overlayFile = stdin;
|
||||
}
|
||||
if (!overlayFile) {
|
||||
errx("Failed to open overlay file \"%s\": %s", overlayFileName, strerror(errno));
|
||||
fatal("Failed to open overlay file \"%s\": %s", overlayFileName, strerror(errno));
|
||||
}
|
||||
}
|
||||
Defer closeOverlayFile{[&] {
|
||||
@@ -574,7 +574,7 @@ static void writeSym() {
|
||||
symFile = stdout;
|
||||
}
|
||||
if (!symFile) {
|
||||
errx("Failed to open sym file \"%s\": %s", symFileName, strerror(errno));
|
||||
fatal("Failed to open sym file \"%s\": %s", symFileName, strerror(errno));
|
||||
}
|
||||
Defer closeSymFile{[&] { fclose(symFile); }};
|
||||
|
||||
@@ -625,7 +625,7 @@ static void writeMap() {
|
||||
mapFile = stdout;
|
||||
}
|
||||
if (!mapFile) {
|
||||
errx("Failed to open map file \"%s\": %s", mapFileName, strerror(errno));
|
||||
fatal("Failed to open map file \"%s\": %s", mapFileName, strerror(errno));
|
||||
}
|
||||
Defer closeMapFile{[&] { fclose(mapFile); }};
|
||||
|
||||
|
||||
@@ -150,8 +150,6 @@ optional:
|
||||
|
||||
#define scriptError(context, fmt, ...) \
|
||||
::error( \
|
||||
nullptr, \
|
||||
0, \
|
||||
"%s(%" PRIu32 "): " fmt, \
|
||||
context.path.c_str(), \
|
||||
context.lineNo __VA_OPT__(, ) __VA_ARGS__ \
|
||||
@@ -746,7 +744,7 @@ void script_ProcessScript(char const *path) {
|
||||
auto &newContext = lexerStack.emplace_back(std::string(path));
|
||||
|
||||
if (!newContext.file.open(newContext.path, std::ios_base::in)) {
|
||||
error(nullptr, 0, "Failed to open linker script \"%s\"", newContext.path.c_str());
|
||||
error("Failed to open linker script \"%s\"", newContext.path.c_str());
|
||||
lexerStack.clear();
|
||||
} else {
|
||||
yy::parser linkerScriptParser;
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
#include <string.h>
|
||||
#include <unordered_map>
|
||||
|
||||
#include "error.hpp"
|
||||
#include "diagnostics.hpp"
|
||||
#include "helpers.hpp"
|
||||
|
||||
#include "link/warning.hpp"
|
||||
@@ -219,7 +219,7 @@ void sect_AddSection(std::unique_ptr<Section> &§ion) {
|
||||
if (Section *target = sect_GetSection(section->name); target) {
|
||||
mergeSections(*target, std::move(section));
|
||||
} else if (section->modifier == SECTION_UNION && sect_HasData(section->type)) {
|
||||
errx(
|
||||
fatal(
|
||||
"Section \"%s\" is of type %s, which cannot be unionized",
|
||||
section->name.c_str(),
|
||||
sectionTypeInfo[section->type].name.c_str()
|
||||
@@ -242,10 +242,7 @@ static void doSanityChecks(Section §ion) {
|
||||
// This is trapped early in RGBDS objects (because then the format is not parseable),
|
||||
// which leaves SDAS objects.
|
||||
error(
|
||||
nullptr,
|
||||
0,
|
||||
"Section \"%s\" has not been assigned a type by a linker script",
|
||||
section.name.c_str()
|
||||
"Section \"%s\" has not been assigned a type by a linker script", section.name.c_str()
|
||||
);
|
||||
return;
|
||||
}
|
||||
@@ -253,8 +250,6 @@ static void doSanityChecks(Section §ion) {
|
||||
if (is32kMode && section.type == SECTTYPE_ROMX) {
|
||||
if (section.isBankFixed && section.bank != 1) {
|
||||
error(
|
||||
nullptr,
|
||||
0,
|
||||
"Section \"%s\" has type ROMX, which must be in bank 1 (if any) with option `-t`",
|
||||
section.name.c_str()
|
||||
);
|
||||
@@ -265,8 +260,6 @@ static void doSanityChecks(Section §ion) {
|
||||
if (isWRAM0Mode && section.type == SECTTYPE_WRAMX) {
|
||||
if (section.isBankFixed && section.bank != 1) {
|
||||
error(
|
||||
nullptr,
|
||||
0,
|
||||
"Section \"%s\" has type WRAMX, which must be in bank 1 with options `-w` or `-d`",
|
||||
section.name.c_str()
|
||||
);
|
||||
@@ -276,8 +269,6 @@ static void doSanityChecks(Section §ion) {
|
||||
}
|
||||
if (isDmgMode && section.type == SECTTYPE_VRAM && section.bank == 1) {
|
||||
error(
|
||||
nullptr,
|
||||
0,
|
||||
"Section \"%s\" has type VRAM, which must be in bank 0 with option `-d`",
|
||||
section.name.c_str()
|
||||
);
|
||||
@@ -292,8 +283,6 @@ static void doSanityChecks(Section §ion) {
|
||||
// Too large an alignment may not be satisfiable
|
||||
if (section.isAlignFixed && (section.alignMask & sectionTypeInfo[section.type].startAddr)) {
|
||||
error(
|
||||
nullptr,
|
||||
0,
|
||||
"Section \"%s\" has type %s, which cannot be aligned to $%04x bytes",
|
||||
section.name.c_str(),
|
||||
sectionTypeInfo[section.type].name.c_str(),
|
||||
@@ -306,8 +295,6 @@ static void doSanityChecks(Section §ion) {
|
||||
|
||||
if (section.isBankFixed && section.bank < minbank && section.bank > maxbank) {
|
||||
error(
|
||||
nullptr,
|
||||
0,
|
||||
minbank == maxbank
|
||||
? "Cannot place section \"%s\" in bank %" PRIu32 ", it must be %" PRIu32
|
||||
: "Cannot place section \"%s\" in bank %" PRIu32 ", it must be between %" PRIu32
|
||||
@@ -322,8 +309,6 @@ static void doSanityChecks(Section §ion) {
|
||||
// Check if section has a chance to be placed
|
||||
if (section.size > sectionTypeInfo[section.type].size) {
|
||||
error(
|
||||
nullptr,
|
||||
0,
|
||||
"Section \"%s\" is bigger than the max size for that type: $%" PRIx16 " > $%" PRIx16,
|
||||
section.name.c_str(),
|
||||
section.size,
|
||||
@@ -343,8 +328,6 @@ static void doSanityChecks(Section §ion) {
|
||||
if (section.isAlignFixed) {
|
||||
if ((section.org & section.alignMask) != section.alignOfs) {
|
||||
error(
|
||||
nullptr,
|
||||
0,
|
||||
"Section \"%s\"'s fixed address doesn't match its alignment",
|
||||
section.name.c_str()
|
||||
);
|
||||
@@ -356,8 +339,6 @@ static void doSanityChecks(Section §ion) {
|
||||
if (section.org < sectionTypeInfo[section.type].startAddr
|
||||
|| section.org > endaddr(section.type)) {
|
||||
error(
|
||||
nullptr,
|
||||
0,
|
||||
"Section \"%s\"'s fixed address $%04" PRIx16 " is outside of range [$%04" PRIx16
|
||||
"; $%04" PRIx16 "]",
|
||||
section.name.c_str(),
|
||||
@@ -369,8 +350,6 @@ static void doSanityChecks(Section §ion) {
|
||||
|
||||
if (section.org + section.size > endaddr(section.type) + 1) {
|
||||
error(
|
||||
nullptr,
|
||||
0,
|
||||
"Section \"%s\"'s end address $%04x is greater than last address $%04x",
|
||||
section.name.c_str(),
|
||||
section.org + section.size,
|
||||
|
||||
@@ -10,10 +10,9 @@
|
||||
static uint32_t nbErrors = 0;
|
||||
|
||||
static void printDiag(
|
||||
char const *fmt, va_list args, char const *type, FileStackNode const *where, uint32_t lineNo
|
||||
FileStackNode const *where, uint32_t lineNo, char const *fmt, va_list args, char const *type
|
||||
) {
|
||||
fputs(type, stderr);
|
||||
fputs(": ", stderr);
|
||||
fprintf(stderr, "%s: ", type);
|
||||
if (where) {
|
||||
where->dump(lineNo);
|
||||
fputs(": ", stderr);
|
||||
@@ -22,22 +21,54 @@ static void printDiag(
|
||||
putc('\n', stderr);
|
||||
}
|
||||
|
||||
static void incrementErrors() {
|
||||
if (nbErrors != UINT32_MAX) {
|
||||
nbErrors++;
|
||||
}
|
||||
}
|
||||
|
||||
[[noreturn]]
|
||||
static void abortLinking(char const *verb) {
|
||||
fprintf(
|
||||
stderr,
|
||||
"Linking %s with %" PRIu32 " error%s\n",
|
||||
verb ? verb : "aborted",
|
||||
nbErrors,
|
||||
nbErrors == 1 ? "" : "s"
|
||||
);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
void warning(FileStackNode const *where, uint32_t lineNo, char const *fmt, ...) {
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
printDiag(fmt, args, "warning", where, lineNo);
|
||||
printDiag(where, lineNo, fmt, args, "warning");
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
void warning(char const *fmt, ...) {
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
printDiag(nullptr, 0, fmt, args, "warning");
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
void error(FileStackNode const *where, uint32_t lineNo, char const *fmt, ...) {
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
printDiag(fmt, args, "error", where, lineNo);
|
||||
printDiag(where, lineNo, fmt, args, "error");
|
||||
va_end(args);
|
||||
|
||||
if (nbErrors != UINT32_MAX) {
|
||||
nbErrors++;
|
||||
}
|
||||
incrementErrors();
|
||||
}
|
||||
|
||||
void error(char const *fmt, ...) {
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
printDiag(nullptr, 0, fmt, args, "error");
|
||||
va_end(args);
|
||||
|
||||
incrementErrors();
|
||||
}
|
||||
|
||||
void errorNoDump(char const *fmt, ...) {
|
||||
@@ -47,9 +78,7 @@ void errorNoDump(char const *fmt, ...) {
|
||||
vfprintf(stderr, fmt, args);
|
||||
va_end(args);
|
||||
|
||||
if (nbErrors != UINT32_MAX) {
|
||||
nbErrors++;
|
||||
}
|
||||
incrementErrors();
|
||||
}
|
||||
|
||||
void argErr(char flag, char const *fmt, ...) {
|
||||
@@ -60,33 +89,33 @@ void argErr(char flag, char const *fmt, ...) {
|
||||
va_end(args);
|
||||
putc('\n', stderr);
|
||||
|
||||
if (nbErrors != UINT32_MAX) {
|
||||
nbErrors++;
|
||||
}
|
||||
incrementErrors();
|
||||
}
|
||||
|
||||
[[noreturn]]
|
||||
void fatal(FileStackNode const *where, uint32_t lineNo, char const *fmt, ...) {
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
printDiag(fmt, args, "FATAL", where, lineNo);
|
||||
printDiag(where, lineNo, fmt, args, "FATAL");
|
||||
va_end(args);
|
||||
|
||||
if (nbErrors != UINT32_MAX) {
|
||||
nbErrors++;
|
||||
}
|
||||
incrementErrors();
|
||||
abortLinking(nullptr);
|
||||
}
|
||||
|
||||
fprintf(
|
||||
stderr, "Linking aborted after %" PRIu32 " error%s\n", nbErrors, nbErrors == 1 ? "" : "s"
|
||||
);
|
||||
exit(1);
|
||||
[[noreturn]]
|
||||
void fatal(char const *fmt, ...) {
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
printDiag(nullptr, 0, fmt, args, "FATAL");
|
||||
va_end(args);
|
||||
|
||||
incrementErrors();
|
||||
abortLinking(nullptr);
|
||||
}
|
||||
|
||||
void requireZeroErrors() {
|
||||
if (nbErrors != 0) {
|
||||
fprintf(
|
||||
stderr, "Linking failed with %" PRIu32 " error%s\n", nbErrors, nbErrors == 1 ? "" : "s"
|
||||
);
|
||||
exit(1);
|
||||
abortLinking("failed");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user