diff --git a/man/rgbfix.1 b/man/rgbfix.1 index 1945c732..17a22184 100644 --- a/man/rgbfix.1 +++ b/man/rgbfix.1 @@ -23,7 +23,7 @@ .Op Fl r Ar ram_size .Op Fl t Ar title_str .Op Fl W Ar warning -.Op Ar +.Ar .Sh DESCRIPTION The .Nm @@ -41,7 +41,7 @@ and to have already populated whichever fields they don't specify using .Nm . .Pp The input -.Ar asmfile +.Ar file can be a path to a file, or .Cm \- to read from standard input. diff --git a/man/rgblink.1 b/man/rgblink.1 index b36ad91d..af4ea585 100644 --- a/man/rgblink.1 +++ b/man/rgblink.1 @@ -50,7 +50,7 @@ option, which implies but also prohibits the use of banked VRAM. .Pp The input -.Ar asmfile +.Ar file can be a path to a file, or .Cm \- to read from standard input. diff --git a/src/asm/fstack.cpp b/src/asm/fstack.cpp index d3bbe04d..9c77d203 100644 --- a/src/asm/fstack.cpp +++ b/src/asm/fstack.cpp @@ -337,7 +337,7 @@ bool fstk_FileError(std::string const &path, char const *functionName) { if (options.missingIncludeState == GEN_EXIT) { verbosePrint( VERB_NOTICE, - "Aborting (-MG) on `%s` file \"%s\": %s\n", + "Aborting due to '-MG' on `%s` file \"%s\": %s\n", functionName, path.c_str(), strerror(errno) diff --git a/src/asm/output.cpp b/src/asm/output.cpp index 787bac43..94749399 100644 --- a/src/asm/output.cpp +++ b/src/asm/output.cpp @@ -159,15 +159,10 @@ static void writeRpn(std::vector &rpnexpr, std::vector const & case RPN_SYM: // The symbol name is always written expanded sym = sym_FindExactSymbol(getSymName()); - if (sym->isConstant()) { - rpnexpr[rpnptr++] = RPN_CONST; - value = sym->getConstantValue(); - } else { - rpnexpr[rpnptr++] = RPN_SYM; - registerUnregisteredSymbol(*sym); // Ensure that `sym->ID` is set - value = sym->ID; - } + registerUnregisteredSymbol(*sym); // Ensure that `sym->ID` is set + value = sym->ID; + rpnexpr[rpnptr++] = RPN_SYM; rpnexpr[rpnptr++] = value & 0xFF; rpnexpr[rpnptr++] = value >> 8; rpnexpr[rpnptr++] = value >> 16; diff --git a/src/asm/symbol.cpp b/src/asm/symbol.cpp index e6aeb42b..b77b5208 100644 --- a/src/asm/symbol.cpp +++ b/src/asm/symbol.cpp @@ -351,11 +351,8 @@ uint32_t Symbol::getConstantValue() const { } if (sym_IsPC(this)) { - if (!getSection()) { - error("PC has no value outside of a section"); - } else { - error("PC does not have a constant value; the current section is not fixed"); - } + assume(getSection()); // There's no way to reach here from outside of a section + error("PC does not have a constant value; the current section is not fixed"); } else { error("`%s` does not have a constant value", name.c_str()); } diff --git a/test/asm/abort-on-missing-incbin-slice.asm b/test/asm/abort-on-missing-incbin-slice.asm new file mode 100644 index 00000000..396e9eb2 --- /dev/null +++ b/test/asm/abort-on-missing-incbin-slice.asm @@ -0,0 +1,3 @@ +section "test", rom0 +incbin "incbin-mg-noexist.bin", 0, 2 +println "never reached" diff --git a/test/asm/abort-on-missing-incbin-slice.flags b/test/asm/abort-on-missing-incbin-slice.flags new file mode 100644 index 00000000..864229c4 --- /dev/null +++ b/test/asm/abort-on-missing-incbin-slice.flags @@ -0,0 +1 @@ +-MG diff --git a/test/asm/abort-on-missing-incbin.asm b/test/asm/abort-on-missing-incbin.asm new file mode 100644 index 00000000..4f837216 --- /dev/null +++ b/test/asm/abort-on-missing-incbin.asm @@ -0,0 +1,3 @@ +section "test", rom0 +incbin "incbin-mg-noexist.bin", 2 +println "never reached" diff --git a/test/asm/abort-on-missing-incbin.flags b/test/asm/abort-on-missing-incbin.flags new file mode 100644 index 00000000..864229c4 --- /dev/null +++ b/test/asm/abort-on-missing-incbin.flags @@ -0,0 +1 @@ +-MG diff --git a/test/asm/deprecated-functions.asm b/test/asm/deprecated-functions.asm new file mode 100644 index 00000000..bd574431 --- /dev/null +++ b/test/asm/deprecated-functions.asm @@ -0,0 +1,15 @@ +opt Wno-unmapped-char +def s equs "Hello world!" + +assert strin(#s, "l") == strfind(#s, "l") + 1 +assert strrin(#s, "l") == strrfind(#s, "l") + 1 + +assert !strcmp(strsub(#s, 7), strslice(#s, 6)) +assert !strcmp(strsub(#s, 7, 5), strslice(#s, 6, 11)) +assert !strcmp(strsub(#s, strlen(#s), 1), strslice(#s, strlen(#s) - 1, strlen(#s))) +assert !strcmp(strsub(#s, 7, 999), strslice(#s, 6, 999)) + +assert !strcmp(charsub(#s, 12), strchar(#s, 11)) +assert !strcmp(charsub(#s, -1), strchar(#s, -1)) +assert !strcmp(charsub(#s, -999), strchar(#s, -999)) +assert !strcmp(charsub(#s, 999), strchar(#s, 999)) diff --git a/test/asm/deprecated-functions.err b/test/asm/deprecated-functions.err new file mode 100644 index 00000000..425f6488 --- /dev/null +++ b/test/asm/deprecated-functions.err @@ -0,0 +1,32 @@ +warning: `STRIN` is deprecated; use 0-indexed `STRFIND` instead [-Wobsolete] + at deprecated-functions.asm(4) +warning: `STRRIN` is deprecated; use 0-indexed `STRRFIND` instead [-Wobsolete] + at deprecated-functions.asm(5) +warning: `STRSUB` is deprecated; use 0-indexed `STRSLICE` instead [-Wobsolete] + at deprecated-functions.asm(7) +warning: `STRSUB` is deprecated; use 0-indexed `STRSLICE` instead [-Wobsolete] + at deprecated-functions.asm(8) +warning: `STRSUB` is deprecated; use 0-indexed `STRSLICE` instead [-Wobsolete] + at deprecated-functions.asm(9) +warning: `STRSUB` is deprecated; use 0-indexed `STRSLICE` instead [-Wobsolete] + at deprecated-functions.asm(10) +warning: STRSUB: Length too big: 999 [-Wbuiltin-args] + at deprecated-functions.asm(10) +warning: STRSLICE: Stop index 999 is past the end of the string [-Wbuiltin-args] + at deprecated-functions.asm(10) +warning: `CHARSUB` is deprecated; use 0-indexed `STRCHAR` instead [-Wobsolete] + at deprecated-functions.asm(12) +warning: `CHARSUB` is deprecated; use 0-indexed `STRCHAR` instead [-Wobsolete] + at deprecated-functions.asm(13) +warning: `CHARSUB` is deprecated; use 0-indexed `STRCHAR` instead [-Wobsolete] + at deprecated-functions.asm(14) +warning: CHARSUB: Position starts at 1 [-Wbuiltin-args] + at deprecated-functions.asm(14) +warning: STRCHAR: Index starts at 0 [-Wbuiltin-args] + at deprecated-functions.asm(14) +warning: `CHARSUB` is deprecated; use 0-indexed `STRCHAR` instead [-Wobsolete] + at deprecated-functions.asm(15) +warning: CHARSUB: Position 999 is past the end of the string [-Wbuiltin-args] + at deprecated-functions.asm(15) +warning: STRCHAR: Index 999 is past the end of the string [-Wbuiltin-args] + at deprecated-functions.asm(15) diff --git a/test/asm/errors-after-missing-include.asm b/test/asm/errors-after-missing-include.asm index fae85b9e..901e3e2e 100644 --- a/test/asm/errors-after-missing-include.asm +++ b/test/asm/errors-after-missing-include.asm @@ -4,7 +4,9 @@ PUSHS SECTION "test", WRAM0 UNION INCLUDE "does not exist" +/* ENDU POPS POPO POPC +*/ diff --git a/test/asm/readfile-max-mg.asm b/test/asm/readfile-max-mg.asm new file mode 100644 index 00000000..92e961a3 --- /dev/null +++ b/test/asm/readfile-max-mg.asm @@ -0,0 +1,2 @@ +def s equs readfile("readfile-mg-noexist.inc", $ff) +println "unreached" diff --git a/test/asm/readfile-max-mg.flags b/test/asm/readfile-max-mg.flags new file mode 100644 index 00000000..864229c4 --- /dev/null +++ b/test/asm/readfile-max-mg.flags @@ -0,0 +1 @@ +-MG diff --git a/test/asm/readfile-mg.asm b/test/asm/readfile-mg.asm new file mode 100644 index 00000000..f6575c2f --- /dev/null +++ b/test/asm/readfile-mg.asm @@ -0,0 +1,2 @@ +def s equs readfile("readfile-mg-noexist.inc") +println "unreached" diff --git a/test/asm/readfile-mg.flags b/test/asm/readfile-mg.flags new file mode 100644 index 00000000..864229c4 --- /dev/null +++ b/test/asm/readfile-mg.flags @@ -0,0 +1 @@ +-MG diff --git a/test/link/pipeline/a.asm b/test/link/pipeline/a.asm new file mode 100644 index 00000000..04bd516f --- /dev/null +++ b/test/link/pipeline/a.asm @@ -0,0 +1,10 @@ +section "test", rom0 +db 1, 4, 9, 16 + +section "entrypoint", rom0[$100] +ld b, b +jp Start + +section "start", rom0[$150] +Start:: +jp Start diff --git a/test/link/pipeline/out.gb b/test/link/pipeline/out.gb new file mode 100644 index 00000000..31402bec Binary files /dev/null and b/test/link/pipeline/out.gb differ diff --git a/test/link/test.sh b/test/link/test.sh index 7a24c3d1..10af49c9 100755 --- a/test/link/test.sh +++ b/test/link/test.sh @@ -26,6 +26,7 @@ rescolors="$(tput op)" RGBASM=../../rgbasm RGBLINK=../../rgblink +RGBFIX=../../rgbfix startTest () { echo "${bold}${green}${test} assembling...${rescolors}${resbold}" @@ -71,7 +72,7 @@ tryCmpRomSize () { } rgblinkQuiet () { - out="$(env $RGBLINK -Weverything -B collapse "$@")" || return $? + out="$(env "$RGBLINK" -Weverything -B collapse "$@")" || return $? if [[ -n "$out" ]]; then echo "$bold${red}Linking shouldn't produce anything on stdout!${rescolors}${resbold}" false @@ -251,6 +252,16 @@ tryDiff "$test"/out.err "$outtemp" tryCmp "$test"/out.gb "$gbtemp" evaluateTest +test="pipeline" +startTest +continueTest +("$RGBASM" -Weverything -B collapse -o - - | \ + "$RGBLINK" -Weverything -B collapse -o - - | \ + "$RGBFIX" -Weverything -v -p 0xff -) < "$test"/a.asm > "$gbtemp" +# This test does not trim its output with 'dd' because it needs to verify the correct output size +tryCmp "$test"/out.gb "$gbtemp" +evaluateTest + test="same-consts" startTest "$RGBASM" -o "$otemp" "$test"/a.asm