diff --git a/include/asm/fstack.hpp b/include/asm/fstack.hpp index 43ced126..b1654077 100644 --- a/include/asm/fstack.hpp +++ b/include/asm/fstack.hpp @@ -56,7 +56,7 @@ std::shared_ptr fstk_GetUniqueIDStr(); MacroArgs *fstk_GetCurrentMacroArgs(); void fstk_AddIncludePath(std::string const &path); -void fstk_SetPreIncludeFile(std::string const &path); +void fstk_AddPreIncludeFile(std::string const &path); std::optional fstk_FindFile(std::string const &path); bool fstk_FileError(std::string const &path, char const *functionName); diff --git a/man/rgbasm.1 b/man/rgbasm.1 index bfbe9ea7..5ccb395d 100644 --- a/man/rgbasm.1 +++ b/man/rgbasm.1 @@ -176,6 +176,7 @@ This acts as if a .Ql Ic INCLUDE Qq Ar include_file was read before the input .Ar asmfile . +Multiple files can be pre-included in the order they were provided. .It Fl p Ar pad_value , Fl \-pad-value Ar pad_value Use this as the value for .Ic DS diff --git a/src/asm/fstack.cpp b/src/asm/fstack.cpp index 7a8d5645..b643022e 100644 --- a/src/asm/fstack.cpp +++ b/src/asm/fstack.cpp @@ -3,6 +3,7 @@ #include "asm/fstack.hpp" #include +#include #include #include #include @@ -46,7 +47,7 @@ size_t maxRecursionDepth; // The first include path for `fstk_FindFile` to try is none at all static std::vector includePaths = {""}; -static std::string preIncludeName; +static std::deque preIncludeNames; std::string const &FileStackNode::dump(uint32_t curLineNo) const { if (std::holds_alternative>(data)) { @@ -115,12 +116,9 @@ void fstk_AddIncludePath(std::string const &path) { } } -void fstk_SetPreIncludeFile(std::string const &path) { - if (!preIncludeName.empty()) { - warnx("Overriding pre-included filename %s", preIncludeName.c_str()); - } - preIncludeName = path; - verbosePrint("Pre-included filename %s\n", preIncludeName.c_str()); // LCOV_EXCL_LINE +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) { @@ -413,13 +411,11 @@ void fstk_Init(std::string const &mainPath, size_t maxDepth) { maxRecursionDepth = maxDepth; - if (!preIncludeName.empty()) { - if (std::optional fullPath = fstk_FindFile(preIncludeName); fullPath) { + for (std::string const &name : preIncludeNames) { + if (std::optional fullPath = fstk_FindFile(name); fullPath) { newFileContext(*fullPath, false); } else { - error( - "Error reading pre-included file '%s': %s", preIncludeName.c_str(), strerror(errno) - ); + error("Error reading pre-included file '%s': %s", name.c_str(), strerror(errno)); } } } diff --git a/src/asm/main.cpp b/src/asm/main.cpp index df00fc25..e6bae650 100644 --- a/src/asm/main.cpp +++ b/src/asm/main.cpp @@ -270,7 +270,7 @@ int main(int argc, char *argv[]) { break; case 'P': - fstk_SetPreIncludeFile(musl_optarg); + fstk_AddPreIncludeFile(musl_optarg); break; unsigned long padByte; diff --git a/test/asm/preinclude.inc b/test/asm/preinclude-1.inc similarity index 100% rename from test/asm/preinclude.inc rename to test/asm/preinclude-1.inc diff --git a/test/asm/preinclude-2.inc b/test/asm/preinclude-2.inc new file mode 100644 index 00000000..64ec4ae6 --- /dev/null +++ b/test/asm/preinclude-2.inc @@ -0,0 +1,4 @@ +warn "another pre-included file" + +def v1 += 10 +def v2 -= 10 diff --git a/test/asm/preinclude.err b/test/asm/preinclude.err index dc9d2404..ab246b53 100644 --- a/test/asm/preinclude.err +++ b/test/asm/preinclude.err @@ -1,4 +1,6 @@ -warning: preinclude.asm(0) -> preinclude.inc(1): [-Wuser] +warning: preinclude.asm(0) -> preinclude-2.inc(0) -> preinclude-1.inc(1): [-Wuser] pre-included file +warning: preinclude.asm(0) -> preinclude-2.inc(1): [-Wuser] + another pre-included file warning: preinclude.asm(1): [-Wuser] main file diff --git a/test/asm/preinclude.flags b/test/asm/preinclude.flags index 3a0a2380..e58876d2 100644 --- a/test/asm/preinclude.flags +++ b/test/asm/preinclude.flags @@ -1 +1 @@ --Weverything -P preinclude.inc +-Weverything -P preinclude-1.inc -P preinclude-2.inc diff --git a/test/asm/preinclude.out b/test/asm/preinclude.out index 68668268..a3c99ffe 100644 --- a/test/asm/preinclude.out +++ b/test/asm/preinclude.out @@ -4,4 +4,4 @@ rept 3 for 0/3 for 1/3 for 2/3 -12 + 34 = 46 +22 + 24 = 46