mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-20 10:12:06 +00:00
Prefer pre-inc/dec unless post-inc/dec are necessary
This commit is contained in:
@@ -71,7 +71,7 @@ static inline int ctz(unsigned int x) {
|
|||||||
|
|
||||||
while (!(x & 1)) {
|
while (!(x & 1)) {
|
||||||
x >>= 1;
|
x >>= 1;
|
||||||
cnt++;
|
++cnt;
|
||||||
}
|
}
|
||||||
return cnt;
|
return cnt;
|
||||||
}
|
}
|
||||||
@@ -81,7 +81,7 @@ static inline int clz(unsigned int x) {
|
|||||||
|
|
||||||
while (x <= UINT_MAX / 2) {
|
while (x <= UINT_MAX / 2) {
|
||||||
x <<= 1;
|
x <<= 1;
|
||||||
cnt++;
|
++cnt;
|
||||||
}
|
}
|
||||||
return cnt;
|
return cnt;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -238,13 +238,13 @@ size_t charmap_ConvertNext(std::string_view &input, std::vector<int32_t> *output
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
inputIdx++; // Consume that char
|
++inputIdx; // Consume that char
|
||||||
|
|
||||||
if (charmap.nodes[nodeIdx].isTerminal()) {
|
if (charmap.nodes[nodeIdx].isTerminal()) {
|
||||||
matchIdx = nodeIdx; // This node matches, register it
|
matchIdx = nodeIdx; // This node matches, register it
|
||||||
rewindDistance = 0; // If no longer match is found, rewind here
|
rewindDistance = 0; // If no longer match is found, rewind here
|
||||||
} else {
|
} else {
|
||||||
rewindDistance++;
|
++rewindDistance;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -271,7 +271,7 @@ size_t charmap_ConvertNext(std::string_view &input, std::vector<int32_t> *output
|
|||||||
codepointLen = 1;
|
codepointLen = 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
codepointLen++;
|
++codepointLen;
|
||||||
if (state == UTF8_ACCEPT) {
|
if (state == UTF8_ACCEPT) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -189,7 +189,7 @@ bool yywrap() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Advance to the next iteration
|
// Advance to the next iteration
|
||||||
fileInfoIters.front()++;
|
++fileInfoIters.front();
|
||||||
// If this wasn't the last iteration, wrap instead of popping
|
// If this wasn't the last iteration, wrap instead of popping
|
||||||
if (fileInfoIters.front() <= context.nbReptIters) {
|
if (fileInfoIters.front() <= context.nbReptIters) {
|
||||||
lexer_RestartRept(context.fileInfo->lineNo);
|
lexer_RestartRept(context.fileInfo->lineNo);
|
||||||
|
|||||||
@@ -373,7 +373,7 @@ void LexerState::clear(uint32_t lineNo_) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void nextLine() {
|
static void nextLine() {
|
||||||
lexerState->lineNo++;
|
++lexerState->lineNo;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t lexer_GetIFDepth() {
|
uint32_t lexer_GetIFDepth() {
|
||||||
@@ -501,7 +501,7 @@ LexerState::~LexerState() {
|
|||||||
|
|
||||||
bool Expansion::advance() {
|
bool Expansion::advance() {
|
||||||
assume(offset <= size());
|
assume(offset <= size());
|
||||||
offset++;
|
++offset;
|
||||||
return offset > size();
|
return offset > size();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -511,12 +511,11 @@ BufferedContent::~BufferedContent() {
|
|||||||
|
|
||||||
void BufferedContent::advance() {
|
void BufferedContent::advance() {
|
||||||
assume(offset < std::size(buf));
|
assume(offset < std::size(buf));
|
||||||
offset++;
|
if (++offset == std::size(buf)) {
|
||||||
if (offset == std::size(buf)) {
|
|
||||||
offset = 0; // Wrap around if necessary
|
offset = 0; // Wrap around if necessary
|
||||||
}
|
}
|
||||||
if (size > 0) {
|
if (size > 0) {
|
||||||
size--;
|
--size;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -810,11 +809,11 @@ static int peek() {
|
|||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
lexerState->macroArgScanDistance++; // Do not consider again
|
++lexerState->macroArgScanDistance; // Do not consider again
|
||||||
|
|
||||||
if (c == '\\' && !lexerState->disableMacroArgs) {
|
if (c == '\\' && !lexerState->disableMacroArgs) {
|
||||||
// If character is a backslash, check for a macro arg
|
// If character is a backslash, check for a macro arg
|
||||||
lexerState->macroArgScanDistance++;
|
++lexerState->macroArgScanDistance;
|
||||||
c = lexerState->peekCharAhead();
|
c = lexerState->peekCharAhead();
|
||||||
if (isMacroChar(c)) {
|
if (isMacroChar(c)) {
|
||||||
shiftChar();
|
shiftChar();
|
||||||
@@ -854,10 +853,10 @@ static void shiftChar() {
|
|||||||
if (lexerState->captureBuf) {
|
if (lexerState->captureBuf) {
|
||||||
lexerState->captureBuf->push_back(peek());
|
lexerState->captureBuf->push_back(peek());
|
||||||
}
|
}
|
||||||
lexerState->captureSize++;
|
++lexerState->captureSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
lexerState->macroArgScanDistance--;
|
--lexerState->macroArgScanDistance;
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
if (!lexerState->expansions.empty()) {
|
if (!lexerState->expansions.empty()) {
|
||||||
@@ -871,7 +870,7 @@ static void shiftChar() {
|
|||||||
} else {
|
} else {
|
||||||
// Advance within the file contents
|
// Advance within the file contents
|
||||||
if (std::holds_alternative<ViewedContent>(lexerState->content)) {
|
if (std::holds_alternative<ViewedContent>(lexerState->content)) {
|
||||||
std::get<ViewedContent>(lexerState->content).offset++;
|
++std::get<ViewedContent>(lexerState->content).offset;
|
||||||
} else {
|
} else {
|
||||||
std::get<BufferedContent>(lexerState->content).advance();
|
std::get<BufferedContent>(lexerState->content).advance();
|
||||||
}
|
}
|
||||||
@@ -1008,7 +1007,7 @@ static std::string readAnonLabelRef(char c) {
|
|||||||
// We come here having already peeked at one char, so no need to do it again
|
// We come here having already peeked at one char, so no need to do it again
|
||||||
do {
|
do {
|
||||||
shiftChar();
|
shiftChar();
|
||||||
n++;
|
++n;
|
||||||
} while (peek() == c);
|
} while (peek() == c);
|
||||||
|
|
||||||
return sym_MakeAnonLabelName(n, c == '-');
|
return sym_MakeAnonLabelName(n, c == '-');
|
||||||
@@ -1273,7 +1272,7 @@ static uint32_t readGfxConstant() {
|
|||||||
bitPlaneUpper = bitPlaneUpper << 1 | (pixel >> 1);
|
bitPlaneUpper = bitPlaneUpper << 1 | (pixel >> 1);
|
||||||
}
|
}
|
||||||
if (width < 9) {
|
if (width < 9) {
|
||||||
width++;
|
++width;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2124,13 +2123,13 @@ static Token yylex_RAW() {
|
|||||||
|
|
||||||
case '(': // Open parentheses inside macro args
|
case '(': // Open parentheses inside macro args
|
||||||
if (parenDepth < UINT_MAX) {
|
if (parenDepth < UINT_MAX) {
|
||||||
parenDepth++;
|
++parenDepth;
|
||||||
}
|
}
|
||||||
goto append;
|
goto append;
|
||||||
|
|
||||||
case ')': // Close parentheses inside macro args
|
case ')': // Close parentheses inside macro args
|
||||||
if (parenDepth > 0) {
|
if (parenDepth > 0) {
|
||||||
parenDepth--;
|
--parenDepth;
|
||||||
}
|
}
|
||||||
goto append;
|
goto append;
|
||||||
|
|
||||||
@@ -2358,11 +2357,11 @@ static Token yylex_SKIP_TO_ENDR() {
|
|||||||
switch (readIdentifier(c, false).type) {
|
switch (readIdentifier(c, false).type) {
|
||||||
case T_(POP_FOR):
|
case T_(POP_FOR):
|
||||||
case T_(POP_REPT):
|
case T_(POP_REPT):
|
||||||
depth++;
|
++depth;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case T_(POP_ENDR):
|
case T_(POP_ENDR):
|
||||||
depth--;
|
--depth;
|
||||||
// `lexer_CaptureRept` has already guaranteed that the `ENDR`s are balanced
|
// `lexer_CaptureRept` has already guaranteed that the `ENDR`s are balanced
|
||||||
assume(depth > 0);
|
assume(depth > 0);
|
||||||
break;
|
break;
|
||||||
@@ -2483,12 +2482,12 @@ Capture lexer_CaptureRept() {
|
|||||||
switch (readIdentifier(c, false).type) {
|
switch (readIdentifier(c, false).type) {
|
||||||
case T_(POP_REPT):
|
case T_(POP_REPT):
|
||||||
case T_(POP_FOR):
|
case T_(POP_FOR):
|
||||||
depth++;
|
++depth;
|
||||||
break; // Ignore the rest of that line
|
break; // Ignore the rest of that line
|
||||||
|
|
||||||
case T_(POP_ENDR):
|
case T_(POP_ENDR):
|
||||||
if (depth) {
|
if (depth) {
|
||||||
depth--;
|
--depth;
|
||||||
break; // Ignore the rest of that line
|
break; // Ignore the rest of that line
|
||||||
}
|
}
|
||||||
endCapture(capture);
|
endCapture(capture);
|
||||||
|
|||||||
@@ -293,7 +293,7 @@ int main(int argc, char *argv[]) {
|
|||||||
case 'Q':
|
case 'Q':
|
||||||
precisionArg = musl_optarg;
|
precisionArg = musl_optarg;
|
||||||
if (precisionArg[0] == '.') {
|
if (precisionArg[0] == '.') {
|
||||||
precisionArg++;
|
++precisionArg;
|
||||||
}
|
}
|
||||||
precision = strtoul(precisionArg, &endptr, 0);
|
precision = strtoul(precisionArg, &endptr, 0);
|
||||||
|
|
||||||
|
|||||||
@@ -91,7 +91,7 @@ void opt_Parse(char const *s) {
|
|||||||
case 'Q':
|
case 'Q':
|
||||||
precisionArg = &s[1];
|
precisionArg = &s[1];
|
||||||
if (precisionArg[0] == '.') {
|
if (precisionArg[0] == '.') {
|
||||||
precisionArg++;
|
++precisionArg;
|
||||||
}
|
}
|
||||||
if (strlen(precisionArg) <= 2) {
|
if (strlen(precisionArg) <= 2) {
|
||||||
int result;
|
int result;
|
||||||
|
|||||||
@@ -2830,7 +2830,7 @@ static size_t strlenUTF8(std::string const &str, bool printErrors) {
|
|||||||
state = UTF8_ACCEPT;
|
state = UTF8_ACCEPT;
|
||||||
// fallthrough
|
// fallthrough
|
||||||
case UTF8_ACCEPT:
|
case UTF8_ACCEPT:
|
||||||
len++;
|
++len;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2840,7 +2840,7 @@ static size_t strlenUTF8(std::string const &str, bool printErrors) {
|
|||||||
if (printErrors) {
|
if (printErrors) {
|
||||||
error("STRLEN: Incomplete UTF-8 character");
|
error("STRLEN: Incomplete UTF-8 character");
|
||||||
}
|
}
|
||||||
len++;
|
++len;
|
||||||
}
|
}
|
||||||
|
|
||||||
return len;
|
return len;
|
||||||
@@ -2861,10 +2861,10 @@ static std::string strsliceUTF8(std::string const &str, uint32_t start, uint32_t
|
|||||||
state = UTF8_ACCEPT;
|
state = UTF8_ACCEPT;
|
||||||
// fallthrough
|
// fallthrough
|
||||||
case UTF8_ACCEPT:
|
case UTF8_ACCEPT:
|
||||||
curIdx++;
|
++curIdx;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
index++;
|
++index;
|
||||||
}
|
}
|
||||||
|
|
||||||
// An index 1 past the end of the string is allowed, but will trigger the
|
// An index 1 past the end of the string is allowed, but will trigger the
|
||||||
@@ -2887,16 +2887,16 @@ static std::string strsliceUTF8(std::string const &str, uint32_t start, uint32_t
|
|||||||
state = UTF8_ACCEPT;
|
state = UTF8_ACCEPT;
|
||||||
// fallthrough
|
// fallthrough
|
||||||
case UTF8_ACCEPT:
|
case UTF8_ACCEPT:
|
||||||
curIdx++;
|
++curIdx;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
index++;
|
++index;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check for partial code point.
|
// Check for partial code point.
|
||||||
if (state != UTF8_ACCEPT) {
|
if (state != UTF8_ACCEPT) {
|
||||||
error("STRSLICE: Incomplete UTF-8 character");
|
error("STRSLICE: Incomplete UTF-8 character");
|
||||||
curIdx++;
|
++curIdx;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (curIdx < stop) {
|
if (curIdx < stop) {
|
||||||
@@ -2925,10 +2925,10 @@ static std::string strsubUTF8(std::string const &str, uint32_t pos, uint32_t len
|
|||||||
state = UTF8_ACCEPT;
|
state = UTF8_ACCEPT;
|
||||||
// fallthrough
|
// fallthrough
|
||||||
case UTF8_ACCEPT:
|
case UTF8_ACCEPT:
|
||||||
curPos++;
|
++curPos;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
index++;
|
++index;
|
||||||
}
|
}
|
||||||
|
|
||||||
// A position 1 past the end of the string is allowed, but will trigger the
|
// A position 1 past the end of the string is allowed, but will trigger the
|
||||||
@@ -2950,16 +2950,16 @@ static std::string strsubUTF8(std::string const &str, uint32_t pos, uint32_t len
|
|||||||
state = UTF8_ACCEPT;
|
state = UTF8_ACCEPT;
|
||||||
// fallthrough
|
// fallthrough
|
||||||
case UTF8_ACCEPT:
|
case UTF8_ACCEPT:
|
||||||
curLen++;
|
++curLen;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
index++;
|
++index;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check for partial code point.
|
// Check for partial code point.
|
||||||
if (state != UTF8_ACCEPT) {
|
if (state != UTF8_ACCEPT) {
|
||||||
error("STRSUB: Incomplete UTF-8 character");
|
error("STRSUB: Incomplete UTF-8 character");
|
||||||
curLen++;
|
++curLen;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (curLen < len) {
|
if (curLen < len) {
|
||||||
@@ -3147,7 +3147,7 @@ static std::string
|
|||||||
fmt.appendString(str, std::get<std::string>(args[argIndex]));
|
fmt.appendString(str, std::get<std::string>(args[argIndex]));
|
||||||
}
|
}
|
||||||
|
|
||||||
argIndex++;
|
++argIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (argIndex < args.size()) {
|
if (argIndex < args.size()) {
|
||||||
|
|||||||
@@ -98,7 +98,7 @@ Section *sect_FindSectionByName(std::string const &name) {
|
|||||||
#define sectError(...) \
|
#define sectError(...) \
|
||||||
do { \
|
do { \
|
||||||
error(__VA_ARGS__); \
|
error(__VA_ARGS__); \
|
||||||
nbSectErrors++; \
|
++nbSectErrors; \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
static unsigned int mergeSectUnion(
|
static unsigned int mergeSectUnion(
|
||||||
|
|||||||
@@ -545,7 +545,7 @@ Symbol *sym_AddAnonLabel() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::string anon = sym_MakeAnonLabelName(0, true); // The direction is important!
|
std::string anon = sym_MakeAnonLabelName(0, true); // The direction is important!
|
||||||
anonLabelID++;
|
++anonLabelID;
|
||||||
return addLabel(anon);
|
return addLabel(anon);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -565,8 +565,8 @@ std::string sym_MakeAnonLabelName(uint32_t ofs, bool neg) {
|
|||||||
id = anonLabelID - ofs;
|
id = anonLabelID - ofs;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
ofs--; // We're referencing symbols that haven't been created yet...
|
// We're referencing symbols that haven't been created yet...
|
||||||
if (ofs > UINT32_MAX - anonLabelID) {
|
if (--ofs > UINT32_MAX - anonLabelID) {
|
||||||
// LCOV_EXCL_START
|
// LCOV_EXCL_START
|
||||||
error(
|
error(
|
||||||
"Reference to anonymous label %" PRIu32 " after, when only %" PRIu32
|
"Reference to anonymous label %" PRIu32 " after, when only %" PRIu32
|
||||||
|
|||||||
@@ -81,8 +81,7 @@ static void printDiag(
|
|||||||
|
|
||||||
static void incrementErrors() {
|
static void incrementErrors() {
|
||||||
// This intentionally makes 0 act as "unlimited" (or at least "limited to sizeof(unsigned)")
|
// This intentionally makes 0 act as "unlimited" (or at least "limited to sizeof(unsigned)")
|
||||||
nbErrors++;
|
if (++nbErrors == maxErrors) {
|
||||||
if (nbErrors == maxErrors) {
|
|
||||||
fprintf(
|
fprintf(
|
||||||
stderr,
|
stderr,
|
||||||
"Assembly aborted after the maximum of %u error%s! (configure with "
|
"Assembly aborted after the maximum of %u error%s! (configure with "
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ std::pair<WarningState, std::optional<uint8_t>> getInitialWarningState(std::stri
|
|||||||
}
|
}
|
||||||
param = param * 10 + (*ptr - '0');
|
param = param * 10 + (*ptr - '0');
|
||||||
|
|
||||||
ptr++;
|
++ptr;
|
||||||
} while (*ptr);
|
} while (*ptr);
|
||||||
|
|
||||||
// If we reached the end of the string, truncate it at the '='
|
// If we reached the end of the string, truncate it at the '='
|
||||||
|
|||||||
26
src/extern/getopt.cpp
vendored
26
src/extern/getopt.cpp
vendored
@@ -57,7 +57,7 @@ static int getopt(int argc, char *argv[], char const *optstring) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!musl_optpos) {
|
if (!musl_optpos) {
|
||||||
musl_optpos++;
|
++musl_optpos;
|
||||||
}
|
}
|
||||||
k = mbtowc(&c, argv[musl_optind] + musl_optpos, MB_LEN_MAX);
|
k = mbtowc(&c, argv[musl_optind] + musl_optpos, MB_LEN_MAX);
|
||||||
if (k < 0) {
|
if (k < 0) {
|
||||||
@@ -68,12 +68,12 @@ static int getopt(int argc, char *argv[], char const *optstring) {
|
|||||||
musl_optpos += k;
|
musl_optpos += k;
|
||||||
|
|
||||||
if (!argv[musl_optind][musl_optpos]) {
|
if (!argv[musl_optind][musl_optpos]) {
|
||||||
musl_optind++;
|
++musl_optind;
|
||||||
musl_optpos = 0;
|
musl_optpos = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (optstring[0] == '-' || optstring[0] == '+') {
|
if (optstring[0] == '-' || optstring[0] == '+') {
|
||||||
optstring++;
|
++optstring;
|
||||||
}
|
}
|
||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
@@ -83,7 +83,7 @@ static int getopt(int argc, char *argv[], char const *optstring) {
|
|||||||
if (l > 0) {
|
if (l > 0) {
|
||||||
i += l;
|
i += l;
|
||||||
} else {
|
} else {
|
||||||
i++;
|
++i;
|
||||||
}
|
}
|
||||||
} while (l && d != c);
|
} while (l && d != c);
|
||||||
|
|
||||||
@@ -185,11 +185,11 @@ static int musl_getopt_long_core(
|
|||||||
|
|
||||||
opt = start;
|
opt = start;
|
||||||
if (*opt == '-') {
|
if (*opt == '-') {
|
||||||
opt++;
|
++opt;
|
||||||
}
|
}
|
||||||
while (*opt && *opt != '=' && *opt == *name) {
|
while (*opt && *opt != '=' && *opt == *name) {
|
||||||
name++;
|
++name;
|
||||||
opt++;
|
++opt;
|
||||||
}
|
}
|
||||||
if (*opt && *opt != '=') {
|
if (*opt && *opt != '=') {
|
||||||
continue;
|
continue;
|
||||||
@@ -200,7 +200,7 @@ static int musl_getopt_long_core(
|
|||||||
cnt = 1;
|
cnt = 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
cnt++;
|
++cnt;
|
||||||
}
|
}
|
||||||
if (cnt == 1 && longonly && arg - start == mblen(start, MB_LEN_MAX)) {
|
if (cnt == 1 && longonly && arg - start == mblen(start, MB_LEN_MAX)) {
|
||||||
int l = arg - start;
|
int l = arg - start;
|
||||||
@@ -209,10 +209,10 @@ static int musl_getopt_long_core(
|
|||||||
int j = 0;
|
int j = 0;
|
||||||
|
|
||||||
while (j < l && start[j] == optstring[i + j]) {
|
while (j < l && start[j] == optstring[i + j]) {
|
||||||
j++;
|
++j;
|
||||||
}
|
}
|
||||||
if (j == l) {
|
if (j == l) {
|
||||||
cnt++;
|
++cnt;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -220,7 +220,7 @@ static int musl_getopt_long_core(
|
|||||||
if (cnt == 1) {
|
if (cnt == 1) {
|
||||||
i = match;
|
i = match;
|
||||||
opt = arg;
|
opt = arg;
|
||||||
musl_optind++;
|
++musl_optind;
|
||||||
if (*opt == '=') {
|
if (*opt == '=') {
|
||||||
if (!longopts[i].has_arg) {
|
if (!longopts[i].has_arg) {
|
||||||
musl_optopt = longopts[i].val;
|
musl_optopt = longopts[i].val;
|
||||||
@@ -254,7 +254,7 @@ static int musl_getopt_long_core(
|
|||||||
);
|
);
|
||||||
return '?';
|
return '?';
|
||||||
}
|
}
|
||||||
musl_optind++;
|
++musl_optind;
|
||||||
}
|
}
|
||||||
if (idx) {
|
if (idx) {
|
||||||
*idx = i;
|
*idx = i;
|
||||||
@@ -275,7 +275,7 @@ static int musl_getopt_long_core(
|
|||||||
strlen(argv[musl_optind] + 2)
|
strlen(argv[musl_optind] + 2)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
musl_optind++;
|
++musl_optind;
|
||||||
return '?';
|
return '?';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -90,7 +90,7 @@ static void error(char const *fmt, ...) {
|
|||||||
putc('\n', stderr);
|
putc('\n', stderr);
|
||||||
|
|
||||||
if (nbErrors != UINT32_MAX) {
|
if (nbErrors != UINT32_MAX) {
|
||||||
nbErrors++;
|
++nbErrors;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -104,7 +104,7 @@ static void fatal(char const *fmt, ...) {
|
|||||||
putc('\n', stderr);
|
putc('\n', stderr);
|
||||||
|
|
||||||
if (nbErrors != UINT32_MAX) {
|
if (nbErrors != UINT32_MAX) {
|
||||||
nbErrors++;
|
++nbErrors;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -206,6 +206,18 @@ static void printAcceptedMBCNames() {
|
|||||||
|
|
||||||
static uint8_t tpp1Rev[2];
|
static uint8_t tpp1Rev[2];
|
||||||
|
|
||||||
|
static void skipWhitespace(char const *&ptr) {
|
||||||
|
while (*ptr == ' ' || *ptr == '\t') {
|
||||||
|
++ptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void skipMBCSpace(char const *&ptr) {
|
||||||
|
while (*ptr == ' ' || *ptr == '\t' || *ptr == '_') {
|
||||||
|
++ptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static bool readMBCSlice(char const *&name, char const *expected) {
|
static bool readMBCSlice(char const *&name, char const *expected) {
|
||||||
while (*expected) {
|
while (*expected) {
|
||||||
char c = *name++;
|
char c = *name++;
|
||||||
@@ -237,7 +249,7 @@ static MbcType parseMBC(char const *name) {
|
|||||||
int base = 0;
|
int base = 0;
|
||||||
|
|
||||||
if (name[0] == '$') {
|
if (name[0] == '$') {
|
||||||
name++;
|
++name;
|
||||||
base = 16;
|
base = 16;
|
||||||
}
|
}
|
||||||
// Parse number, and return it as-is (unless it's too large)
|
// Parse number, and return it as-is (unless it's too large)
|
||||||
@@ -257,10 +269,7 @@ static MbcType parseMBC(char const *name) {
|
|||||||
uint16_t mbc;
|
uint16_t mbc;
|
||||||
char const *ptr = name;
|
char const *ptr = name;
|
||||||
|
|
||||||
// Trim off leading whitespace
|
skipWhitespace(ptr); // Trim off leading whitespace
|
||||||
while (*ptr == ' ' || *ptr == '\t') {
|
|
||||||
ptr++;
|
|
||||||
}
|
|
||||||
|
|
||||||
#define tryReadSlice(expected) \
|
#define tryReadSlice(expected) \
|
||||||
do { \
|
do { \
|
||||||
@@ -274,11 +283,9 @@ static MbcType parseMBC(char const *name) {
|
|||||||
case 'r':
|
case 'r':
|
||||||
tryReadSlice("OM");
|
tryReadSlice("OM");
|
||||||
// Handle optional " ONLY"
|
// Handle optional " ONLY"
|
||||||
while (*ptr == ' ' || *ptr == '\t' || *ptr == '_') {
|
skipMBCSpace(ptr);
|
||||||
ptr++;
|
|
||||||
}
|
|
||||||
if (*ptr == 'O' || *ptr == 'o') {
|
if (*ptr == 'O' || *ptr == 'o') {
|
||||||
ptr++;
|
++ptr;
|
||||||
tryReadSlice("NLY");
|
tryReadSlice("NLY");
|
||||||
}
|
}
|
||||||
mbc = ROM;
|
mbc = ROM;
|
||||||
@@ -351,9 +358,7 @@ static MbcType parseMBC(char const *name) {
|
|||||||
case 'P': {
|
case 'P': {
|
||||||
tryReadSlice("P1");
|
tryReadSlice("P1");
|
||||||
// Parse version
|
// Parse version
|
||||||
while (*ptr == ' ' || *ptr == '_') {
|
skipMBCSpace(ptr);
|
||||||
ptr++;
|
|
||||||
}
|
|
||||||
// Major
|
// Major
|
||||||
char *endptr;
|
char *endptr;
|
||||||
unsigned long val = strtoul(ptr, &endptr, 10);
|
unsigned long val = strtoul(ptr, &endptr, 10);
|
||||||
@@ -420,23 +425,18 @@ static MbcType parseMBC(char const *name) {
|
|||||||
// clang-format on
|
// clang-format on
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
// Trim off trailing whitespace
|
skipWhitespace(ptr); // Trim off trailing whitespace
|
||||||
while (*ptr == ' ' || *ptr == '\t' || *ptr == '_') {
|
|
||||||
ptr++;
|
|
||||||
}
|
|
||||||
|
|
||||||
// If done, start processing "features"
|
// If done, start processing "features"
|
||||||
if (!*ptr) {
|
if (!*ptr) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
// We expect a '+' at this point
|
// We expect a '+' at this point
|
||||||
|
skipMBCSpace(ptr);
|
||||||
if (*ptr++ != '+') {
|
if (*ptr++ != '+') {
|
||||||
return MBC_BAD;
|
return MBC_BAD;
|
||||||
}
|
}
|
||||||
// Trim off leading whitespace
|
skipMBCSpace(ptr);
|
||||||
while (*ptr == ' ' || *ptr == '\t' || *ptr == '_') {
|
|
||||||
ptr++;
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (*ptr++) {
|
switch (*ptr++) {
|
||||||
case 'B': // BATTERY
|
case 'B': // BATTERY
|
||||||
@@ -502,7 +502,7 @@ static MbcType parseMBC(char const *name) {
|
|||||||
case MBC1:
|
case MBC1:
|
||||||
case MMM01:
|
case MMM01:
|
||||||
if (features == RAM) {
|
if (features == RAM) {
|
||||||
mbc++;
|
++mbc;
|
||||||
} else if (features == (RAM | BATTERY)) {
|
} else if (features == (RAM | BATTERY)) {
|
||||||
mbc += 2;
|
mbc += 2;
|
||||||
} else if (features) {
|
} else if (features) {
|
||||||
@@ -534,7 +534,7 @@ static MbcType parseMBC(char const *name) {
|
|||||||
MBC3_TIMER_BATTERY + 1 == MBC3_TIMER_RAM_BATTERY, "Enum sanity check failed!"
|
MBC3_TIMER_BATTERY + 1 == MBC3_TIMER_RAM_BATTERY, "Enum sanity check failed!"
|
||||||
);
|
);
|
||||||
if (features == RAM) {
|
if (features == RAM) {
|
||||||
mbc++;
|
++mbc;
|
||||||
} else if (features == (RAM | BATTERY)) {
|
} else if (features == (RAM | BATTERY)) {
|
||||||
mbc += 2;
|
mbc += 2;
|
||||||
} else if (features) {
|
} else if (features) {
|
||||||
@@ -552,7 +552,7 @@ static MbcType parseMBC(char const *name) {
|
|||||||
static_assert(MBC5_RUMBLE + 1 == MBC5_RUMBLE_RAM, "Enum sanity check failed!");
|
static_assert(MBC5_RUMBLE + 1 == MBC5_RUMBLE_RAM, "Enum sanity check failed!");
|
||||||
static_assert(MBC5_RUMBLE + 2 == MBC5_RUMBLE_RAM_BATTERY, "Enum sanity check failed!");
|
static_assert(MBC5_RUMBLE + 2 == MBC5_RUMBLE_RAM_BATTERY, "Enum sanity check failed!");
|
||||||
if (features == RAM) {
|
if (features == RAM) {
|
||||||
mbc++;
|
++mbc;
|
||||||
} else if (features == (RAM | BATTERY)) {
|
} else if (features == (RAM | BATTERY)) {
|
||||||
mbc += 2;
|
mbc += 2;
|
||||||
} else if (features) {
|
} else if (features) {
|
||||||
@@ -604,10 +604,7 @@ static MbcType parseMBC(char const *name) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Trim off trailing whitespace
|
skipWhitespace(ptr); // Trim off trailing whitespace
|
||||||
while (*ptr == ' ' || *ptr == '\t') {
|
|
||||||
ptr++;
|
|
||||||
}
|
|
||||||
|
|
||||||
// If there is still something past the whitespace, error out
|
// If there is still something past the whitespace, error out
|
||||||
if (*ptr) {
|
if (*ptr) {
|
||||||
@@ -1050,7 +1047,7 @@ static void
|
|||||||
fatal("\"%s\" has more than 65536 banks", name);
|
fatal("\"%s\" has more than 65536 banks", name);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
nbBanks++;
|
++nbBanks;
|
||||||
|
|
||||||
// Update global checksum, too
|
// Update global checksum, too
|
||||||
for (uint16_t i = 0; i < bankLen; i++) {
|
for (uint16_t i = 0; i < bankLen; i++) {
|
||||||
@@ -1375,7 +1372,7 @@ int main(int argc, char *argv[]) {
|
|||||||
default:
|
default:
|
||||||
warnx("Ignoring '%c' in fix spec", *musl_optarg);
|
warnx("Ignoring '%c' in fix spec", *musl_optarg);
|
||||||
}
|
}
|
||||||
musl_optarg++;
|
++musl_optarg;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|||||||
@@ -37,6 +37,12 @@ void requireZeroErrors() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void incrementErrors() {
|
||||||
|
if (nbErrors != std::numeric_limits<decltype(nbErrors)>::max()) {
|
||||||
|
++nbErrors;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void error(char const *fmt, ...) {
|
void error(char const *fmt, ...) {
|
||||||
va_list ap;
|
va_list ap;
|
||||||
fputs("error: ", stderr);
|
fputs("error: ", stderr);
|
||||||
@@ -45,9 +51,7 @@ void error(char const *fmt, ...) {
|
|||||||
va_end(ap);
|
va_end(ap);
|
||||||
putc('\n', stderr);
|
putc('\n', stderr);
|
||||||
|
|
||||||
if (nbErrors != std::numeric_limits<decltype(nbErrors)>::max()) {
|
incrementErrors();
|
||||||
nbErrors++;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[[noreturn]]
|
[[noreturn]]
|
||||||
@@ -59,10 +63,7 @@ void fatal(char const *fmt, ...) {
|
|||||||
va_end(ap);
|
va_end(ap);
|
||||||
putc('\n', stderr);
|
putc('\n', stderr);
|
||||||
|
|
||||||
if (nbErrors != std::numeric_limits<decltype(nbErrors)>::max()) {
|
incrementErrors();
|
||||||
nbErrors++;
|
|
||||||
}
|
|
||||||
|
|
||||||
giveUp();
|
giveUp();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -89,9 +90,7 @@ void warning(WarningID id, char const *fmt, ...) {
|
|||||||
va_end(ap);
|
va_end(ap);
|
||||||
putc('\n', stderr);
|
putc('\n', stderr);
|
||||||
|
|
||||||
if (nbErrors != std::numeric_limits<decltype(nbErrors)>::max()) {
|
incrementErrors();
|
||||||
nbErrors++;
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ static void assignSection(Section §ion, MemoryLocation const &location) {
|
|||||||
next->bank = location.bank;
|
next->bank = location.bank;
|
||||||
}
|
}
|
||||||
|
|
||||||
nbSectionsToAssign--;
|
--nbSectionsToAssign;
|
||||||
|
|
||||||
out_AddSection(section);
|
out_AddSection(section);
|
||||||
}
|
}
|
||||||
@@ -151,7 +151,7 @@ static ssize_t getPlacement(Section const §ion, MemoryLocation &location) {
|
|||||||
location.address += section.alignMask + 1 + section.alignOfs;
|
location.address += section.alignMask + 1 + section.alignOfs;
|
||||||
} else {
|
} else {
|
||||||
// Any location is fine, so, next free block
|
// Any location is fine, so, next free block
|
||||||
spaceIdx++;
|
++spaceIdx;
|
||||||
if (spaceIdx < bankMem.size()) {
|
if (spaceIdx < bankMem.size()) {
|
||||||
location.address = bankMem[spaceIdx].address;
|
location.address = bankMem[spaceIdx].address;
|
||||||
}
|
}
|
||||||
@@ -161,7 +161,7 @@ static ssize_t getPlacement(Section const §ion, MemoryLocation &location) {
|
|||||||
// go forwards until that is no longer the case.
|
// go forwards until that is no longer the case.
|
||||||
while (spaceIdx < bankMem.size()
|
while (spaceIdx < bankMem.size()
|
||||||
&& location.address >= bankMem[spaceIdx].address + bankMem[spaceIdx].size) {
|
&& location.address >= bankMem[spaceIdx].address + bankMem[spaceIdx].size) {
|
||||||
spaceIdx++;
|
++spaceIdx;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try again with the new location/free space combo
|
// Try again with the new location/free space combo
|
||||||
@@ -174,7 +174,7 @@ static ssize_t getPlacement(Section const §ion, MemoryLocation &location) {
|
|||||||
return -1;
|
return -1;
|
||||||
} else if (scrambleROMX && section.type == SECTTYPE_ROMX && location.bank <= scrambleROMX) {
|
} else if (scrambleROMX && section.type == SECTTYPE_ROMX && location.bank <= scrambleROMX) {
|
||||||
if (location.bank > typeInfo.firstBank) {
|
if (location.bank > typeInfo.firstBank) {
|
||||||
location.bank--;
|
--location.bank;
|
||||||
} else if (scrambleROMX < typeInfo.lastBank) {
|
} else if (scrambleROMX < typeInfo.lastBank) {
|
||||||
location.bank = scrambleROMX + 1;
|
location.bank = scrambleROMX + 1;
|
||||||
} else {
|
} else {
|
||||||
@@ -183,7 +183,7 @@ static ssize_t getPlacement(Section const §ion, MemoryLocation &location) {
|
|||||||
} else if (scrambleWRAMX && section.type == SECTTYPE_WRAMX
|
} else if (scrambleWRAMX && section.type == SECTTYPE_WRAMX
|
||||||
&& location.bank <= scrambleWRAMX) {
|
&& location.bank <= scrambleWRAMX) {
|
||||||
if (location.bank > typeInfo.firstBank) {
|
if (location.bank > typeInfo.firstBank) {
|
||||||
location.bank--;
|
--location.bank;
|
||||||
} else if (scrambleWRAMX < typeInfo.lastBank) {
|
} else if (scrambleWRAMX < typeInfo.lastBank) {
|
||||||
location.bank = scrambleWRAMX + 1;
|
location.bank = scrambleWRAMX + 1;
|
||||||
} else {
|
} else {
|
||||||
@@ -191,14 +191,14 @@ static ssize_t getPlacement(Section const §ion, MemoryLocation &location) {
|
|||||||
}
|
}
|
||||||
} else if (scrambleSRAM && section.type == SECTTYPE_SRAM && location.bank <= scrambleSRAM) {
|
} else if (scrambleSRAM && section.type == SECTTYPE_SRAM && location.bank <= scrambleSRAM) {
|
||||||
if (location.bank > typeInfo.firstBank) {
|
if (location.bank > typeInfo.firstBank) {
|
||||||
location.bank--;
|
--location.bank;
|
||||||
} else if (scrambleSRAM < typeInfo.lastBank) {
|
} else if (scrambleSRAM < typeInfo.lastBank) {
|
||||||
location.bank = scrambleSRAM + 1;
|
location.bank = scrambleSRAM + 1;
|
||||||
} else {
|
} else {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
} else if (location.bank < typeInfo.lastBank) {
|
} else if (location.bank < typeInfo.lastBank) {
|
||||||
location.bank++;
|
++location.bank;
|
||||||
} else {
|
} else {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@@ -355,11 +355,11 @@ static void categorizeSection(Section §ion) {
|
|||||||
// Insert section while keeping the list sorted by decreasing size
|
// Insert section while keeping the list sorted by decreasing size
|
||||||
auto pos = sections.begin();
|
auto pos = sections.begin();
|
||||||
while (pos != sections.end() && (*pos)->size > section.size) {
|
while (pos != sections.end() && (*pos)->size > section.size) {
|
||||||
pos++;
|
++pos;
|
||||||
}
|
}
|
||||||
sections.insert(pos, §ion);
|
sections.insert(pos, §ion);
|
||||||
|
|
||||||
nbSectionsToAssign++;
|
++nbSectionsToAssign;
|
||||||
}
|
}
|
||||||
|
|
||||||
void assign_AssignSections() {
|
void assign_AssignSections() {
|
||||||
@@ -395,8 +395,7 @@ void assign_AssignSections() {
|
|||||||
constraints--) {
|
constraints--) {
|
||||||
for (Section *section : unassignedSections[constraints]) {
|
for (Section *section : unassignedSections[constraints]) {
|
||||||
fprintf(stderr, "%c \"%s\"", nbSections == 0 ? ';' : ',', section->name.c_str());
|
fprintf(stderr, "%c \"%s\"", nbSections == 0 ? ';' : ',', section->name.c_str());
|
||||||
nbSections++;
|
if (++nbSections == 10) {
|
||||||
if (nbSections == 10) {
|
|
||||||
goto max_out; // Can't `break` out of a nested loop
|
goto max_out; // Can't `break` out of a nested loop
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -209,7 +209,7 @@ static void parseScrambleSpec(char const *spec) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (*spec == '=') {
|
if (*spec == '=') {
|
||||||
spec++; // `strtoul` will skip the whitespace on its own
|
++spec; // `strtoul` will skip the whitespace on its own
|
||||||
unsigned long limit;
|
unsigned long limit;
|
||||||
char *endptr;
|
char *endptr;
|
||||||
|
|
||||||
|
|||||||
@@ -527,7 +527,7 @@ void obj_ReadFile(char const *fileName, unsigned int fileID) {
|
|||||||
|
|
||||||
sym_AddSymbol(symbol);
|
sym_AddSymbol(symbol);
|
||||||
if (std::holds_alternative<Label>(symbol.data)) {
|
if (std::holds_alternative<Label>(symbol.data)) {
|
||||||
nbSymPerSect[std::get<Label>(symbol.data).sectionID]++;
|
++nbSymPerSect[std::get<Label>(symbol.data).sectionID];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -90,7 +90,7 @@ void out_AddSection(Section const §ion) {
|
|||||||
// Insert section while keeping the list sorted by increasing org
|
// Insert section while keeping the list sorted by increasing org
|
||||||
auto pos = bankSections.begin();
|
auto pos = bankSections.begin();
|
||||||
while (pos != bankSections.end() && (*pos)->org < section.org) {
|
while (pos != bankSections.end() && (*pos)->org < section.org) {
|
||||||
pos++;
|
++pos;
|
||||||
}
|
}
|
||||||
bankSections.insert(pos, §ion);
|
bankSections.insert(pos, §ion);
|
||||||
}
|
}
|
||||||
@@ -178,7 +178,7 @@ static void
|
|||||||
// Output padding up to the next SECTION
|
// Output padding up to the next SECTION
|
||||||
while (offset + baseOffset < section->org) {
|
while (offset + baseOffset < section->org) {
|
||||||
putc(getNextFillByte(), outputFile);
|
putc(getNextFillByte(), outputFile);
|
||||||
offset++;
|
++offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Output the section itself
|
// Output the section itself
|
||||||
@@ -196,7 +196,7 @@ static void
|
|||||||
if (!disablePadding) {
|
if (!disablePadding) {
|
||||||
while (offset < size) {
|
while (offset < size) {
|
||||||
putc(getNextFillByte(), outputFile);
|
putc(getNextFillByte(), outputFile);
|
||||||
offset++;
|
++offset;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -419,7 +419,7 @@ uint16_t forEachSection(SortedSections const §List, F callback) {
|
|||||||
: zeroLenSection;
|
: zeroLenSection;
|
||||||
used += (*pickedSection)->size;
|
used += (*pickedSection)->size;
|
||||||
callback(**pickedSection);
|
callback(**pickedSection);
|
||||||
pickedSection++;
|
++pickedSection;
|
||||||
}
|
}
|
||||||
return used;
|
return used;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ static void printDiag(
|
|||||||
|
|
||||||
static void incrementErrors() {
|
static void incrementErrors() {
|
||||||
if (nbErrors != UINT32_MAX) {
|
if (nbErrors != UINT32_MAX) {
|
||||||
nbErrors++;
|
++nbErrors;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user