Extend RGBASM and RGBLINK verbosity flags to have multiple levels like RGBGFX (#1772)

This commit is contained in:
Rangi
2025-08-02 17:10:10 -04:00
committed by GitHub
parent b51056f743
commit 752b273aec
28 changed files with 688 additions and 347 deletions

View File

@@ -15,6 +15,7 @@
#include "helpers.hpp"
#include "linkdefs.hpp"
#include "platform.hpp" // S_ISDIR (stat macro)
#include "verbosity.hpp"
#include "asm/lexer.hpp"
#include "asm/macro.hpp"
@@ -88,6 +89,28 @@ bool fstk_DumpCurrent() {
return true;
}
// LCOV_EXCL_START
void fstk_VerboseOutputConfig() {
assume(checkVerbosity(VERB_CONFIG));
// -I/--include
if (includePaths.size() > 1) {
fputs("\tInclude file paths:\n", stderr);
for (std::string const &path : includePaths) {
if (!path.empty()) {
fprintf(stderr, "\t - %s\n", path.c_str());
}
}
}
// -P/--preinclude
if (!preIncludeNames.empty()) {
fputs("\tPreincluded files:\n", stderr);
for (std::string const &name : preIncludeNames) {
fprintf(stderr, "\t - %s\n", name.c_str());
}
}
}
// LCOV_EXCL_STOP
std::shared_ptr<FileStackNode> fstk_GetFileStack() {
return contextStack.empty() ? nullptr : contextStack.top().fileInfo;
}
@@ -124,7 +147,6 @@ void fstk_AddIncludePath(std::string const &path) {
void fstk_AddPreIncludeFile(std::string const &path) {
preIncludeNames.emplace_front(path);
verbosePrint("Pre-included filename %s\n", path.c_str()); // LCOV_EXCL_LINE
}
static bool isValidFilePath(std::string const &path) {
@@ -308,7 +330,11 @@ bool fstk_FileError(std::string const &path, char const *functionName) {
// LCOV_EXCL_START
if (options.missingIncludeState == GEN_EXIT) {
verbosePrint(
"Aborting (-MG) on %s file '%s' (%s)\n", functionName, path.c_str(), strerror(errno)
VERB_NOTICE,
"Aborting (-MG) on %s file '%s' (%s)\n",
functionName,
path.c_str(),
strerror(errno)
);
return true;
}

View File

@@ -18,6 +18,7 @@
#include "helpers.hpp"
#include "util.hpp"
#include "verbosity.hpp"
#include "asm/fixpoint.hpp"
#include "asm/format.hpp"
@@ -325,7 +326,7 @@ void LexerState::setFileAsNextState(std::string const &filePath, bool updateStat
if (filePath == "-") {
path = "<stdin>";
content.emplace<BufferedContent>(STDIN_FILENO);
verbosePrint("Opening stdin\n"); // LCOV_EXCL_LINE
verbosePrint(VERB_INFO, "Opening stdin\n"); // LCOV_EXCL_LINE
} else {
struct stat statBuf;
if (stat(filePath.c_str(), &statBuf) != 0) {
@@ -352,13 +353,17 @@ void LexerState::setFileAsNextState(std::string const &filePath, bool updateStat
}
content.emplace<ViewedContent>(ptr, size);
verbosePrint("File \"%s\" is fully read\n", path.c_str()); // LCOV_EXCL_LINE
// LCOV_EXCL_START
verbosePrint(VERB_INFO, "File \"%s\" is fully read\n", path.c_str());
// LCOV_EXCL_STOP
} else {
// LCOV_EXCL_START
if (statBuf.st_size == 0) {
verbosePrint("File \"%s\" is empty\n", path.c_str());
verbosePrint(VERB_INFO, "File \"%s\" is empty\n", path.c_str());
} else {
verbosePrint("Failed to stat file \"%s\": %s\n", path.c_str(), strerror(errno));
verbosePrint(
VERB_INFO, "Failed to stat file \"%s\": %s\n", path.c_str(), strerror(errno)
);
}
// LCOV_EXCL_STOP
@@ -371,7 +376,7 @@ void LexerState::setFileAsNextState(std::string const &filePath, bool updateStat
}
content.emplace<BufferedContent>(fd);
verbosePrint("File \"%s\" is opened\n", path.c_str()); // LCOV_EXCL_LINE
verbosePrint(VERB_INFO, "File \"%s\" is opened\n", path.c_str()); // LCOV_EXCL_LINE
}
}

View File

@@ -17,6 +17,7 @@
#include "parser.hpp" // Generated from parser.y
#include "usage.hpp"
#include "util.hpp" // UpperMap
#include "verbosity.hpp"
#include "version.hpp"
#include "asm/charmap.hpp"
@@ -28,23 +29,8 @@
Options options;
// Escapes Make-special chars from a string
static std::string make_escape(std::string &str) {
std::string escaped;
size_t pos = 0;
for (;;) {
// All dollars needs to be doubled
size_t nextPos = str.find('$', pos);
if (nextPos == std::string::npos) {
break;
}
escaped.append(str, pos, nextPos - pos);
escaped.append("$$");
pos = nextPos + literal_strlen("$");
}
escaped.append(str, pos, str.length() - pos);
return escaped;
}
static char const *dependFileName = nullptr; // -M
static std::unordered_map<std::string, std::vector<StateFeature>> stateFileSpecs; // -s
// Short options
static char const *optstring = "b:D:Eg:hI:M:o:P:p:Q:r:s:VvW:wX:";
@@ -105,6 +91,148 @@ static Usage usage(
);
// clang-format on
// LCOV_EXCL_START
static void verboseOutputConfig(int argc, char *argv[]) {
if (!checkVerbosity(VERB_CONFIG)) {
return;
}
fprintf(stderr, "rgbasm %s\n", get_package_version_string());
printVVVVVVerbosity();
fputs("Options:\n", stderr);
// -E/--export-all
if (options.exportAll) {
fputs("\tExport all labels by default\n", stderr);
}
// -b/--binary-digits
if (options.binDigits[0] != '0' || options.binDigits[1] != '1') {
fprintf(
stderr, "\tBinary digits: '%c', '%c'\n", options.binDigits[0], options.binDigits[1]
);
}
// -g/--gfx-chars
if (options.gfxDigits[0] != '0' || options.gfxDigits[1] != '1' || options.gfxDigits[2] != '2'
|| options.gfxDigits[3] != '3') {
fprintf(
stderr,
"\tGraphics characters: '%c', '%c', '%c', '%c'\n",
options.gfxDigits[0],
options.gfxDigits[1],
options.gfxDigits[2],
options.gfxDigits[3]
);
}
// -Q/--q-precision
fprintf(
stderr,
"\tFixed-point precision: Q%d.%" PRIu8 "\n",
32 - options.fixPrecision,
options.fixPrecision
);
// -p/--pad-value
fprintf(stderr, "\tPad value: 0x%02" PRIx8 "\n", options.padByte);
// -r/--recursion-depth
fprintf(stderr, "\tMaximum recursion depth %zu\n", options.maxRecursionDepth);
// -X/--max-errors
if (options.maxErrors) {
fprintf(stderr, "\tMaximum %" PRIu64 " errors\n", options.maxErrors);
}
// -D/--define
static bool hasDefines = false; // `static` so `sym_ForEach` callback can see it
sym_ForEach([](Symbol &sym) {
if (!sym.isBuiltin && sym.type == SYM_EQUS) {
if (!hasDefines) {
fputs("\tDefinitions:\n", stderr);
hasDefines = true;
}
fprintf(stderr, "\t - def %s equs \"%s\"\n", sym.name.c_str(), sym.getEqus()->c_str());
}
});
// -s/--state
if (!stateFileSpecs.empty()) {
fputs("\tOutput state files:\n", stderr);
static char const *featureNames[NB_STATE_FEATURES] = {
"equ",
"var",
"equs",
"char",
"macro",
};
for (auto [name, features] : stateFileSpecs) {
fprintf(stderr, "\t - %s: ", name == "-" ? "<stdout>" : name.c_str());
for (size_t i = 0; i < features.size(); ++i) {
if (i > 0) {
fputs(", ", stderr);
}
fputs(featureNames[features[i]], stderr);
}
putc('\n', stderr);
}
}
// asmfile
if (musl_optind < argc) {
fprintf(stderr, "\tInput asm file: %s", argv[musl_optind]);
if (musl_optind + 1 < argc) {
fprintf(stderr, " (and %d more)", argc - musl_optind - 1);
}
putc('\n', stderr);
}
// -o/--output
if (!options.objectFileName.empty()) {
fprintf(stderr, "\tOutput object file: %s\n", options.objectFileName.c_str());
}
fstk_VerboseOutputConfig();
if (dependFileName) {
fprintf(
stderr,
"\tOutput dependency file: %s\n",
strcmp(dependFileName, "-") ? dependFileName : "<stdout>"
);
// -MT or -MQ
if (!options.targetFileName.empty()) {
fprintf(stderr, "\tTarget file(s): %s\n", options.targetFileName.c_str());
}
// -MG or -MC
switch (options.missingIncludeState) {
case INC_ERROR:
fputs("\tExit with an error on a missing dependency\n", stderr);
break;
case GEN_EXIT:
fputs("\tExit normally on a missing dependency\n", stderr);
break;
case GEN_CONTINUE:
fputs("\tContinue processing after a missing dependency\n", stderr);
break;
}
// -MP
if (options.generatePhonyDeps) {
fputs("\tGenerate phony dependencies\n", stderr);
}
// [-MG] [-MC]
}
fputs("Ready.\n", stderr);
}
// LCOV_EXCL_STOP
static std::string escapeMakeChars(std::string &str) {
std::string escaped;
size_t pos = 0;
for (;;) {
// All dollars needs to be doubled
size_t nextPos = str.find('$', pos);
if (nextPos == std::string::npos) {
break;
}
escaped.append(str, pos, nextPos - pos);
escaped.append("$$");
pos = nextPos + literal_strlen("$");
}
escaped.append(str, pos, str.length() - pos);
return escaped;
}
// Parse a comma-separated string of '-s/--state' features
static std::vector<StateFeature> parseStateFeatures(char *str) {
std::vector<StateFeature> features;
@@ -164,10 +292,6 @@ int main(int argc, char *argv[]) {
options.maxErrors = 100;
}
// Local options
char const *dependFileName = nullptr; // -M
std::unordered_map<std::string, std::vector<StateFeature>> stateFileSpecs; // -s
for (int ch; (ch = musl_getopt_long_only(argc, argv, optstring, longopts, nullptr)) != -1;) {
switch (ch) {
char *endptr;
@@ -192,7 +316,7 @@ int main(int argc, char *argv[]) {
break;
case 'E':
sym_SetExportAll(true);
options.exportAll = true;
break;
case 'g':
@@ -211,21 +335,13 @@ int main(int argc, char *argv[]) {
break;
case 'M':
if (options.dependFile) {
warnx("Overriding dependfile %s", dependFileName);
}
if (strcmp("-", musl_optarg)) {
options.dependFile = fopen(musl_optarg, "w");
dependFileName = musl_optarg;
} else {
options.dependFile = stdout;
dependFileName = "<stdout>";
}
if (options.dependFile == nullptr) {
// LCOV_EXCL_START
fatal("Failed to open dependfile \"%s\": %s", dependFileName, strerror(errno));
// LCOV_EXCL_STOP
if (dependFileName) {
warnx(
"Overriding dependency file %s",
strcmp(dependFileName, "-") ? dependFileName : "<stdout>"
);
}
dependFileName = musl_optarg;
break;
case 'o':
@@ -233,7 +349,6 @@ int main(int argc, char *argv[]) {
warnx("Overriding output filename %s", options.objectFileName.c_str());
}
options.objectFileName = musl_optarg;
verbosePrint("Output filename %s\n", options.objectFileName.c_str()); // LCOV_EXCL_LINE
break;
case 'P':
@@ -295,7 +410,6 @@ int main(int argc, char *argv[]) {
if (stateFileSpecs.find(name) != stateFileSpecs.end()) {
warnx("Overriding state filename %s", name);
}
verbosePrint("State filename %s\n", name); // LCOV_EXCL_LINE
stateFileSpecs.emplace(name, std::move(features));
break;
}
@@ -306,7 +420,7 @@ int main(int argc, char *argv[]) {
case 'v':
// LCOV_EXCL_START
options.verbose = true;
incrementVerbosity();
break;
// LCOV_EXCL_STOP
@@ -352,7 +466,7 @@ int main(int argc, char *argv[]) {
case 'T': {
std::string newTarget = musl_optarg;
if (depType == 'Q') {
newTarget = make_escape(newTarget);
newTarget = escapeMakeChars(newTarget);
}
if (!options.targetFileName.empty()) {
options.targetFileName += ' ';
@@ -373,6 +487,8 @@ int main(int argc, char *argv[]) {
options.targetFileName = options.objectFileName;
}
verboseOutputConfig(argc, argv);
if (argc == musl_optind) {
usage.printAndExit("Please specify an input file (pass `-` to read from standard input)");
} else if (argc != musl_optind + 1) {
@@ -381,7 +497,20 @@ int main(int argc, char *argv[]) {
std::string mainFileName = argv[musl_optind];
verbosePrint("Assembling %s\n", mainFileName.c_str()); // LCOV_EXCL_LINE
verbosePrint(VERB_NOTICE, "Assembling %s\n", mainFileName.c_str()); // LCOV_EXCL_LINE
if (dependFileName) {
if (strcmp("-", dependFileName)) {
options.dependFile = fopen(dependFileName, "w");
if (options.dependFile == nullptr) {
// LCOV_EXCL_START
fatal("Failed to open dependency file \"%s\": %s", dependFileName, strerror(errno));
// LCOV_EXCL_STOP
}
} else {
options.dependFile = stdout;
}
}
if (options.dependFile && options.targetFileName.empty()) {
fatal("Dependency files can only be created if a target file is specified with either "

View File

@@ -17,6 +17,7 @@
#include "asm/fstack.hpp"
#include "asm/lexer.hpp"
#include "asm/macro.hpp"
#include "asm/main.hpp"
#include "asm/output.hpp"
#include "asm/warning.hpp"
@@ -39,8 +40,6 @@ static char savedDATE[256];
static char savedTIMESTAMP_ISO8601_LOCAL[256];
static char savedTIMESTAMP_ISO8601_UTC[256];
static bool exportAll = false; // -E
bool sym_IsPC(Symbol const *sym) {
return sym == PCSymbol;
}
@@ -497,7 +496,7 @@ static Symbol *addLabel(std::string const &symName) {
sym->type = SYM_LABEL;
sym->data = static_cast<int32_t>(sect_GetSymbolOffset());
// Don't export anonymous labels
if (exportAll && !symName.starts_with('!')) {
if (options.exportAll && !symName.starts_with('!')) {
sym->isExported = true;
}
sym->section = sect_GetSymbolSection();
@@ -635,11 +634,6 @@ Symbol *sym_Ref(std::string const &symName) {
return sym;
}
// Set whether to export all relocatable symbols by default
void sym_SetExportAll(bool set) {
exportAll = set;
}
// Define the built-in symbols
void sym_Init(time_t now) {
PCSymbol = &createSymbol("@"s);