diff --git a/include/asm/main.hpp b/include/asm/main.hpp index 4a93cc3f..cb506edf 100644 --- a/include/asm/main.hpp +++ b/include/asm/main.hpp @@ -8,6 +8,13 @@ extern bool verbose; +#define verbosePrint(...) \ + do { \ + if (verbose) { \ + fprintf(stderr, __VA_ARGS__); \ + } \ + } while (0) + extern FILE *dependFile; extern std::string targetFileName; extern bool continueAfterMissingIncludes; diff --git a/include/link/main.hpp b/include/link/main.hpp index 102e8af4..a981f87d 100644 --- a/include/link/main.hpp +++ b/include/link/main.hpp @@ -29,7 +29,6 @@ extern bool beVerbose; extern bool isWRAM0Mode; extern bool disablePadding; -// Helper macro for printing verbose-mode messages #define verbosePrint(...) \ do { \ if (beVerbose) { \ diff --git a/src/asm/fstack.cpp b/src/asm/fstack.cpp index 8ea7fbae..2aa68995 100644 --- a/src/asm/fstack.cpp +++ b/src/asm/fstack.cpp @@ -120,11 +120,7 @@ void fstk_SetPreIncludeFile(std::string const &path) { warnx("Overriding pre-included filename %s", preIncludeName.c_str()); } preIncludeName = path; - // LCOV_EXCL_START - if (verbose) { - printf("Pre-included filename %s\n", preIncludeName.c_str()); - } - // LCOV_EXCL_STOP + verbosePrint("Pre-included filename %s\n", preIncludeName.c_str()); // LCOV_EXCL_LINE } static bool isValidFilePath(std::string const &path) { @@ -312,8 +308,10 @@ void fstk_RunInclude(std::string const &path, bool preInclude) { if (!fullPath) { if (generatedMissingIncludes && !preInclude) { // LCOV_EXCL_START - if (verbose && !continueAfterMissingIncludes) { - printf("Aborting (-MG) on INCLUDE file '%s' (%s)\n", path.c_str(), strerror(errno)); + if (!continueAfterMissingIncludes) { + verbosePrint( + "Aborting (-MG) on INCLUDE file '%s' (%s)\n", path.c_str(), strerror(errno) + ); } // LCOV_EXCL_STOP failedOnMissingInclude = true; diff --git a/src/asm/lexer.cpp b/src/asm/lexer.cpp index f59f5b88..19fbf77b 100644 --- a/src/asm/lexer.cpp +++ b/src/asm/lexer.cpp @@ -82,9 +82,7 @@ static char *mapFile(int fd, std::string const &path, size_t size) { // The implementation may not support MAP_PRIVATE; try again with MAP_SHARED // instead, offering, I believe, weaker guarantees about external modifications to // the file while reading it. That's still better than not opening it at all, though. - if (verbose) { - printf("mmap(%s, MAP_PRIVATE) failed, retrying with MAP_SHARED\n", path.c_str()); - } + verbosePrint("mmap(%s, MAP_PRIVATE) failed, retrying with MAP_SHARED\n", path.c_str()); mappingAddr = mmap(nullptr, size, PROT_READ, MAP_SHARED, fd, 0); } // LCOV_EXCL_STOP @@ -415,11 +413,7 @@ void LexerState::setFileAsNextState(std::string const &filePath, bool updateStat if (filePath == "-") { path = ""; content.emplace(STDIN_FILENO); - // LCOV_EXCL_START - if (verbose) { - printf("Opening stdin\n"); - } - // LCOV_EXCL_STOP + verbosePrint("Opening stdin\n"); // LCOV_EXCL_LINE } else { struct stat statBuf; if (stat(filePath.c_str(), &statBuf) != 0) { @@ -445,11 +439,7 @@ void LexerState::setFileAsNextState(std::string const &filePath, bool updateStat content.emplace( std::shared_ptr(mappingAddr, FileUnmapDeleter(size)), size ); - // LCOV_EXCL_START - if (verbose) { - printf("File \"%s\" is mmap()ped\n", path.c_str()); - } - // LCOV_EXCL_STOP + verbosePrint("File \"%s\" is mmap()ped\n", path.c_str()); // LCOV_EXCL_LINE isMmapped = true; } } @@ -458,14 +448,12 @@ void LexerState::setFileAsNextState(std::string const &filePath, bool updateStat // Sometimes mmap() fails or isn't available, so have a fallback content.emplace(fd); // LCOV_EXCL_START - if (verbose) { - if (statBuf.st_size == 0) { - printf("File \"%s\" is empty\n", path.c_str()); - } else { - printf( - "File \"%s\" is opened; errno reports: %s\n", path.c_str(), strerror(errno) - ); - } + if (statBuf.st_size == 0) { + verbosePrint("File \"%s\" is empty\n", path.c_str()); + } else { + verbosePrint( + "File \"%s\" is opened; errno reports: %s\n", path.c_str(), strerror(errno) + ); } // LCOV_EXCL_STOP } diff --git a/src/asm/main.cpp b/src/asm/main.cpp index 0c493e04..1892c0a7 100644 --- a/src/asm/main.cpp +++ b/src/asm/main.cpp @@ -329,11 +329,7 @@ int main(int argc, char *argv[]) { if (stateFileSpecs.find(name) != stateFileSpecs.end()) { warnx("Overriding state filename %s", name); } - // LCOV_EXCL_START - if (verbose) { - printf("State filename %s\n", name); - } - // LCOV_EXCL_STOP + verbosePrint("State filename %s\n", name); // LCOV_EXCL_LINE stateFileSpecs.emplace(name, std::move(features)); break; } @@ -421,9 +417,7 @@ int main(int argc, char *argv[]) { std::string mainFileName = argv[musl_optind]; - if (verbose) { - printf("Assembling %s\n", mainFileName.c_str()); // LCOV_EXCL_LINE - } + verbosePrint("Assembling %s\n", mainFileName.c_str()); // LCOV_EXCL_LINE if (dependFile) { if (targetFileName.empty()) { diff --git a/src/asm/output.cpp b/src/asm/output.cpp index 72a919c9..a8c42963 100644 --- a/src/asm/output.cpp +++ b/src/asm/output.cpp @@ -374,11 +374,7 @@ void out_SetFileName(std::string const &name) { warnx("Overriding output filename %s", objectFileName.c_str()); } objectFileName = name; - // LCOV_EXCL_START - if (verbose) { - printf("Output filename %s\n", objectFileName.c_str()); - } - // LCOV_EXCL_STOP + verbosePrint("Output filename %s\n", objectFileName.c_str()); // LCOV_EXCL_LINE } static void dumpString(std::string const &escape, FILE *file) {