Make newlines explicit in error messages

In preparation for a change a PR is about to make
This commit is contained in:
ISSOtm
2020-09-27 10:54:06 +02:00
parent c0808246e5
commit a1286e6f0e
15 changed files with 288 additions and 319 deletions

View File

@@ -62,6 +62,6 @@ noreturn_ void fatalerror(const char *fmt, ...);
* get a list of all errors at the end, making it easier to fix all of them at * get a list of all errors at the end, making it easier to fix all of them at
* once. * once.
*/ */
void yyerror(const char *fmt, ...); void error(const char *fmt, ...);
#endif #endif

View File

@@ -51,11 +51,11 @@ size_t symvaluetostring(char *dest, size_t maxLength, char *symName,
size_t i; size_t i;
if (mode) if (mode)
yyerror("Print types are only allowed for numbers"); error("Print types are only allowed for numbers\n");
for (i = 0; src[i] != 0; i++) { for (i = 0; src[i] != 0; i++) {
if (i >= maxLength) if (i >= maxLength)
fatalerror("Symbol value too long to fit buffer"); fatalerror("Symbol value too long to fit buffer\n");
dest[i] = src[i]; dest[i] = src[i];
} }
@@ -85,11 +85,11 @@ size_t symvaluetostring(char *dest, size_t maxLength, char *symName,
} }
if (fullLength < 0) { if (fullLength < 0) {
fatalerror("snprintf encoding error"); fatalerror("snprintf encoding error\n");
} else { } else {
length = (size_t)fullLength; length = (size_t)fullLength;
if (length > maxLength) if (length > maxLength)
fatalerror("Symbol value too long to fit buffer"); fatalerror("Symbol value too long to fit buffer\n");
} }
} }
@@ -161,7 +161,7 @@ static void copyrept(void)
} }
if (level != 0) if (level != 0)
fatalerror("Unterminated REPT block"); fatalerror("Unterminated REPT block\n");
len = src - pCurrentBuffer->pBuffer - 4; len = src - pCurrentBuffer->pBuffer - 4;
@@ -171,7 +171,7 @@ static void copyrept(void)
tzNewMacro = malloc(ulNewMacroSize + 1); tzNewMacro = malloc(ulNewMacroSize + 1);
if (tzNewMacro == NULL) if (tzNewMacro == NULL)
fatalerror("Not enough memory for REPT block."); fatalerror("Not enough memory for REPT block.\n");
uint32_t i; uint32_t i;
@@ -231,7 +231,7 @@ static void copymacro(void)
} }
if (level != 0) if (level != 0)
fatalerror("Unterminated MACRO definition."); fatalerror("Unterminated MACRO definition.\n");
len = src - pCurrentBuffer->pBuffer - 4; len = src - pCurrentBuffer->pBuffer - 4;
@@ -240,7 +240,7 @@ static void copymacro(void)
tzNewMacro = (char *)malloc(ulNewMacroSize + 1); tzNewMacro = (char *)malloc(ulNewMacroSize + 1);
if (tzNewMacro == NULL) if (tzNewMacro == NULL)
fatalerror("Not enough memory for MACRO definition."); fatalerror("Not enough memory for MACRO definition.\n");
uint32_t i; uint32_t i;
@@ -329,7 +329,7 @@ static void if_skip_to_else(void)
} }
if (level != 0) if (level != 0)
fatalerror("Unterminated IF construct"); fatalerror("Unterminated IF construct\n");
int32_t len = src - pCurrentBuffer->pBuffer; int32_t len = src - pCurrentBuffer->pBuffer;
@@ -374,7 +374,7 @@ static void if_skip_to_endc(void)
} }
if (level != 0) if (level != 0)
fatalerror("Unterminated IF construct"); fatalerror("Unterminated IF construct\n");
int32_t len = src - pCurrentBuffer->pBuffer; int32_t len = src - pCurrentBuffer->pBuffer;
@@ -392,7 +392,7 @@ static size_t strlenUTF8(const char *s)
while (*s) { while (*s) {
switch (decode(&state, &codep, (uint8_t)*s)) { switch (decode(&state, &codep, (uint8_t)*s)) {
case 1: case 1:
fatalerror("STRLEN: Invalid UTF-8 character"); fatalerror("STRLEN: Invalid UTF-8 character\n");
break; break;
case 0: case 0:
len++; len++;
@@ -403,7 +403,7 @@ static size_t strlenUTF8(const char *s)
/* Check for partial code point. */ /* Check for partial code point. */
if (state != 0) if (state != 0)
fatalerror("STRLEN: Invalid UTF-8 character"); fatalerror("STRLEN: Invalid UTF-8 character\n");
return len; return len;
} }
@@ -418,7 +418,7 @@ static void strsubUTF8(char *dest, const char *src, uint32_t pos, uint32_t len)
uint32_t curLen = 0; uint32_t curLen = 0;
if (pos < 1) { if (pos < 1) {
warning(WARNING_BUILTIN_ARG, "STRSUB: Position starts at 1"); warning(WARNING_BUILTIN_ARG, "STRSUB: Position starts at 1\n");
pos = 1; pos = 1;
} }
@@ -426,7 +426,7 @@ static void strsubUTF8(char *dest, const char *src, uint32_t pos, uint32_t len)
while (src[srcIndex] && curPos < pos) { while (src[srcIndex] && curPos < pos) {
switch (decode(&state, &codep, (uint8_t)src[srcIndex])) { switch (decode(&state, &codep, (uint8_t)src[srcIndex])) {
case 1: case 1:
fatalerror("STRSUB: Invalid UTF-8 character"); fatalerror("STRSUB: Invalid UTF-8 character\n");
break; break;
case 0: case 0:
curPos++; curPos++;
@@ -436,14 +436,15 @@ static void strsubUTF8(char *dest, const char *src, uint32_t pos, uint32_t len)
} }
if (!src[srcIndex] && len) if (!src[srcIndex] && len)
warning(WARNING_BUILTIN_ARG, "STRSUB: Position %lu is past the end of the string", warning(WARNING_BUILTIN_ARG,
"STRSUB: Position %lu is past the end of the string\n",
(unsigned long)pos); (unsigned long)pos);
/* Copy from source to destination. */ /* Copy from source to destination. */
while (src[srcIndex] && destIndex < MAXSTRLEN && curLen < len) { while (src[srcIndex] && destIndex < MAXSTRLEN && curLen < len) {
switch (decode(&state, &codep, (uint8_t)src[srcIndex])) { switch (decode(&state, &codep, (uint8_t)src[srcIndex])) {
case 1: case 1:
fatalerror("STRSUB: Invalid UTF-8 character"); fatalerror("STRSUB: Invalid UTF-8 character\n");
break; break;
case 0: case 0:
curLen++; curLen++;
@@ -453,11 +454,11 @@ static void strsubUTF8(char *dest, const char *src, uint32_t pos, uint32_t len)
} }
if (curLen < len) if (curLen < len)
warning(WARNING_BUILTIN_ARG, "STRSUB: Length too big: %lu", (unsigned long)len); warning(WARNING_BUILTIN_ARG, "STRSUB: Length too big: %lu\n", (unsigned long)len);
/* Check for partial code point. */ /* Check for partial code point. */
if (state != 0) if (state != 0)
fatalerror("STRSUB: Invalid UTF-8 character"); fatalerror("STRSUB: Invalid UTF-8 character\n");
dest[destIndex] = 0; dest[destIndex] = 0;
} }
@@ -466,13 +467,12 @@ static inline void failAssert(enum AssertionType type)
{ {
switch (type) { switch (type) {
case ASSERT_FATAL: case ASSERT_FATAL:
fatalerror("Assertion failed"); fatalerror("Assertion failed\n");
case ASSERT_ERROR: case ASSERT_ERROR:
yyerror("Assertion failed"); error("Assertion failed\n");
break; break;
case ASSERT_WARN: case ASSERT_WARN:
warning(WARNING_ASSERT, warning(WARNING_ASSERT, "Assertion failed\n");
"Assertion failed");
break; break;
} }
} }
@@ -481,17 +481,18 @@ static inline void failAssertMsg(enum AssertionType type, char const *msg)
{ {
switch (type) { switch (type) {
case ASSERT_FATAL: case ASSERT_FATAL:
fatalerror("Assertion failed: %s", msg); fatalerror("Assertion failed: %s\n", msg);
case ASSERT_ERROR: case ASSERT_ERROR:
yyerror("Assertion failed: %s", msg); error("Assertion failed: %s\n", msg);
break; break;
case ASSERT_WARN: case ASSERT_WARN:
warning(WARNING_ASSERT, warning(WARNING_ASSERT, "Assertion failed: %s\n", msg);
"Assertion failed: %s", msg);
break; break;
} }
} }
#define yyerror(str) error(str "\n")
%} %}
%union %union
@@ -674,7 +675,7 @@ line : label
; ;
scoped_label_bare : T_LABEL { scoped_label_bare : T_LABEL {
warning(WARNING_OBSOLETE, "Non-local labels without a colon are deprecated"); warning(WARNING_OBSOLETE, "Non-local labels without a colon are deprecated\n");
strcpy($$, $1); strcpy($$, $1);
} }
| T_LOCAL_ID { | T_LOCAL_ID {
@@ -784,17 +785,15 @@ simple_pseudoop : include
align : T_OP_ALIGN uconst { align : T_OP_ALIGN uconst {
if ($2 > 16) if ($2 > 16)
yyerror("Alignment must be between 0 and 16, not %u", error("Alignment must be between 0 and 16, not %u\n", $2);
$2);
else else
sect_AlignPC($2, 0); sect_AlignPC($2, 0);
} }
| T_OP_ALIGN uconst ',' uconst { | T_OP_ALIGN uconst ',' uconst {
if ($2 > 16) if ($2 > 16)
yyerror("Alignment must be between 0 and 16, not %u", error("Alignment must be between 0 and 16, not %u\n", $2);
$2);
else if ($4 >= 1 << $2) else if ($4 >= 1 << $2)
yyerror("Offset must be between 0 and %u, not %u", error("Offset must be between 0 and %u, not %u\n",
(1 << $2) - 1, $4); (1 << $2) - 1, $4);
else else
sect_AlignPC($2, $4); sect_AlignPC($2, $4);
@@ -827,10 +826,10 @@ pops : T_POP_POPS { out_PopSection(); }
pushs : T_POP_PUSHS { out_PushSection(); } pushs : T_POP_PUSHS { out_PushSection(); }
; ;
fail : T_POP_FAIL string { fatalerror("%s", $2); } fail : T_POP_FAIL string { fatalerror("%s\n", $2); }
; ;
warn : T_POP_WARN string { warning(WARNING_USER, "%s", $2); } warn : T_POP_WARN string { warning(WARNING_USER, "%s\n", $2); }
; ;
assert_type : /* empty */ { $$ = ASSERT_ERROR; } assert_type : /* empty */ { $$ = ASSERT_ERROR; }
@@ -844,7 +843,7 @@ assert : T_POP_ASSERT assert_type relocexpr
if (!rpn_isKnown(&$3)) { if (!rpn_isKnown(&$3)) {
if (!out_CreateAssert($2, &$3, "", if (!out_CreateAssert($2, &$3, "",
sect_GetOutputOffset())) sect_GetOutputOffset()))
yyerror("Assertion creation failed: %s", error("Assertion creation failed: %s\n",
strerror(errno)); strerror(errno));
} else if ($3.nVal == 0) { } else if ($3.nVal == 0) {
failAssert($2); failAssert($2);
@@ -856,7 +855,7 @@ assert : T_POP_ASSERT assert_type relocexpr
if (!rpn_isKnown(&$3)) { if (!rpn_isKnown(&$3)) {
if (!out_CreateAssert($2, &$3, $5, if (!out_CreateAssert($2, &$3, $5,
sect_GetOutputOffset())) sect_GetOutputOffset()))
yyerror("Assertion creation failed: %s", error("Assertion creation failed: %s\n",
strerror(errno)); strerror(errno));
} else if ($3.nVal == 0) { } else if ($3.nVal == 0) {
failAssertMsg($2, $5); failAssertMsg($2, $5);
@@ -949,21 +948,24 @@ ds : T_POP_DS uconst { out_Skip($2, true); }
/* Authorize empty entries if there is only one */ /* Authorize empty entries if there is only one */
db : T_POP_DB constlist_8bit_entry ',' constlist_8bit { db : T_POP_DB constlist_8bit_entry ',' constlist_8bit {
if (nListCountEmpty > 0) if (nListCountEmpty > 0)
warning(WARNING_EMPTY_ENTRY, "Empty entry in list of 8-bit elements (treated as padding)."); warning(WARNING_EMPTY_ENTRY,
"Empty entry in list of 8-bit elements (treated as padding).\n");
} }
| T_POP_DB constlist_8bit_entry | T_POP_DB constlist_8bit_entry
; ;
dw : T_POP_DW constlist_16bit_entry ',' constlist_16bit { dw : T_POP_DW constlist_16bit_entry ',' constlist_16bit {
if (nListCountEmpty > 0) if (nListCountEmpty > 0)
warning(WARNING_EMPTY_ENTRY, "Empty entry in list of 16-bit elements (treated as padding)."); warning(WARNING_EMPTY_ENTRY,
"Empty entry in list of 16-bit elements (treated as padding).\n");
} }
| T_POP_DW constlist_16bit_entry | T_POP_DW constlist_16bit_entry
; ;
dl : T_POP_DL constlist_32bit_entry ',' constlist_32bit { dl : T_POP_DL constlist_32bit_entry ',' constlist_32bit {
if (nListCountEmpty > 0) if (nListCountEmpty > 0)
warning(WARNING_EMPTY_ENTRY, "Empty entry in list of 32-bit elements (treated as padding)."); warning(WARNING_EMPTY_ENTRY,
"Empty entry in list of 32-bit elements (treated as padding).\n");
} }
| T_POP_DL constlist_32bit_entry | T_POP_DL constlist_32bit_entry
; ;
@@ -987,10 +989,11 @@ export : export_token export_list
export_token : T_POP_EXPORT export_token : T_POP_EXPORT
| T_POP_GLOBAL { | T_POP_GLOBAL {
warning(WARNING_OBSOLETE, "`GLOBAL` is a deprecated synonym for `EXPORT`"); warning(WARNING_OBSOLETE,
"`GLOBAL` is a deprecated synonym for `EXPORT`\n");
} }
| T_POP_XDEF { | T_POP_XDEF {
warning(WARNING_OBSOLETE, "`XDEF` is a deprecated synonym for `EXPORT`"); warning(WARNING_OBSOLETE, "`XDEF` is a deprecated synonym for `EXPORT`\n");
} }
; ;
@@ -1034,10 +1037,10 @@ incbin : T_POP_INCBIN string {
charmap : T_POP_CHARMAP string ',' const { charmap : T_POP_CHARMAP string ',' const {
if ($4 < INT8_MIN || $4 > UINT8_MAX) if ($4 < INT8_MIN || $4 > UINT8_MAX)
warning(WARNING_TRUNCATION, "Expression must be 8-bit"); warning(WARNING_TRUNCATION, "Expression must be 8-bit\n");
if (charmap_Add($2, (uint8_t)$4) == -1) if (charmap_Add($2, (uint8_t)$4) == -1)
yyerror("Error adding new charmap mapping: %s\n", strerror(errno)); error("Error adding new charmap mapping: %s\n", strerror(errno));
} }
; ;
@@ -1075,7 +1078,7 @@ if : T_POP_IF const {
elif : T_POP_ELIF const { elif : T_POP_ELIF const {
if (nIFDepth <= 0) if (nIFDepth <= 0)
fatalerror("Found ELIF outside an IF construct"); fatalerror("Found ELIF outside an IF construct\n");
if (skipElif) { if (skipElif) {
/* /*
@@ -1107,7 +1110,7 @@ elif : T_POP_ELIF const {
else : T_POP_ELSE { else : T_POP_ELSE {
if (nIFDepth <= 0) if (nIFDepth <= 0)
fatalerror("Found ELSE outside an IF construct"); fatalerror("Found ELSE outside an IF construct\n");
/* Continue parsing at ENDC keyword */ /* Continue parsing at ENDC keyword */
if_skip_to_endc(); if_skip_to_endc();
@@ -1116,7 +1119,7 @@ else : T_POP_ELSE {
endc : T_POP_ENDC { endc : T_POP_ENDC {
if (nIFDepth <= 0) if (nIFDepth <= 0)
fatalerror("Found ENDC outside an IF construct"); fatalerror("Found ENDC outside an IF construct\n");
nIFDepth--; nIFDepth--;
} }
@@ -1126,7 +1129,7 @@ const_3bit : const {
int32_t value = $1; int32_t value = $1;
if ((value < 0) || (value > 7)) { if ((value < 0) || (value > 7)) {
yyerror("Immediate value must be 3-bit"); error("Immediate value must be 3-bit\n");
$$ = 0; $$ = 0;
} else { } else {
$$ = value & 0x7; $$ = value & 0x7;
@@ -1177,7 +1180,7 @@ constlist_32bit_entry : /* empty */ {
reloc_8bit : relocexpr { reloc_8bit : relocexpr {
if(rpn_isKnown(&$1) if(rpn_isKnown(&$1)
&& ($1.nVal < -128 || $1.nVal > 255)) && ($1.nVal < -128 || $1.nVal > 255))
warning(WARNING_TRUNCATION, "Expression must be 8-bit"); warning(WARNING_TRUNCATION, "Expression must be 8-bit\n");
$$ = $1; $$ = $1;
} }
; ;
@@ -1185,7 +1188,7 @@ reloc_8bit : relocexpr {
reloc_8bit_no_str : relocexpr_no_str { reloc_8bit_no_str : relocexpr_no_str {
if(rpn_isKnown(&$1) if(rpn_isKnown(&$1)
&& ($1.nVal < -128 || $1.nVal > 255)) && ($1.nVal < -128 || $1.nVal > 255))
warning(WARNING_TRUNCATION, "Expression must be 8-bit"); warning(WARNING_TRUNCATION, "Expression must be 8-bit\n");
$$ = $1; $$ = $1;
} }
; ;
@@ -1193,7 +1196,7 @@ reloc_8bit_no_str : relocexpr_no_str {
reloc_16bit : relocexpr { reloc_16bit : relocexpr {
if (rpn_isKnown(&$1) if (rpn_isKnown(&$1)
&& ($1.nVal < -32768 || $1.nVal > 65535)) && ($1.nVal < -32768 || $1.nVal > 65535))
warning(WARNING_TRUNCATION, "Expression must be 16-bit"); warning(WARNING_TRUNCATION, "Expression must be 16-bit\n");
$$ = $1; $$ = $1;
} }
; ;
@@ -1342,14 +1345,14 @@ relocexpr_no_str : scoped_id { rpn_Symbol(&$$, $1); }
uconst : const { uconst : const {
$$ = $1; $$ = $1;
if ($$ < 0) if ($$ < 0)
fatalerror("Constant mustn't be negative: %d", fatalerror("Constant mustn't be negative: %d\n",
$1); $1);
} }
; ;
const : relocexpr { const : relocexpr {
if (!rpn_isKnown(&$1)) { if (!rpn_isKnown(&$1)) {
yyerror("Expected constant expression: %s", error("Expected constant expression: %s\n",
$1.reason); $1.reason);
$$ = 0; $$ = 0;
} else { } else {
@@ -1360,28 +1363,25 @@ const : relocexpr {
string : T_STRING { string : T_STRING {
if (snprintf($$, MAXSTRLEN + 1, "%s", $1) > MAXSTRLEN) if (snprintf($$, MAXSTRLEN + 1, "%s", $1) > MAXSTRLEN)
warning(WARNING_LONG_STR, "String is too long '%s'", warning(WARNING_LONG_STR, "String is too long '%s'\n", $1);
$1);
} }
| T_OP_STRSUB '(' string ',' uconst ',' uconst ')' { | T_OP_STRSUB '(' string ',' uconst ',' uconst ')' {
strsubUTF8($$, $3, $5, $7); strsubUTF8($$, $3, $5, $7);
} }
| T_OP_STRCAT '(' string ',' string ')' { | T_OP_STRCAT '(' string ',' string ')' {
if (snprintf($$, MAXSTRLEN + 1, "%s%s", $3, $5) > MAXSTRLEN) if (snprintf($$, MAXSTRLEN + 1, "%s%s", $3, $5) > MAXSTRLEN)
warning(WARNING_LONG_STR, "STRCAT: String too long '%s%s'", warning(WARNING_LONG_STR, "STRCAT: String too long '%s%s'\n",
$3, $5); $3, $5);
} }
| T_OP_STRUPR '(' string ')' { | T_OP_STRUPR '(' string ')' {
if (snprintf($$, MAXSTRLEN + 1, "%s", $3) > MAXSTRLEN) if (snprintf($$, MAXSTRLEN + 1, "%s", $3) > MAXSTRLEN)
warning(WARNING_LONG_STR, "STRUPR: String too long '%s'", warning(WARNING_LONG_STR, "STRUPR: String too long '%s'\n", $3);
$3);
upperstring($$); upperstring($$);
} }
| T_OP_STRLWR '(' string ')' { | T_OP_STRLWR '(' string ')' {
if (snprintf($$, MAXSTRLEN + 1, "%s", $3) > MAXSTRLEN) if (snprintf($$, MAXSTRLEN + 1, "%s", $3) > MAXSTRLEN)
warning(WARNING_LONG_STR, "STRUPR: String too long '%s'", warning(WARNING_LONG_STR, "STRUPR: String too long '%s'\n", $3);
$3);
lowerstring($$); lowerstring($$);
} }
@@ -1410,7 +1410,7 @@ sectiontype : T_SECT_WRAM0 { $$ = SECTTYPE_WRAM0; }
sectorg : /* empty */ { $$ = -1; } sectorg : /* empty */ { $$ = -1; }
| '[' uconst ']' { | '[' uconst ']' {
if ($2 < 0 || $2 >= 0x10000) { if ($2 < 0 || $2 >= 0x10000) {
yyerror("Address $%x is not 16-bit", $2); error("Address $%x is not 16-bit\n", $2);
$$ = -1; $$ = -1;
} else { } else {
$$ = $2; $$ = $2;
@@ -1425,19 +1425,17 @@ sectattrs : /* empty */ {
} }
| sectattrs ',' T_OP_ALIGN '[' uconst ']' { | sectattrs ',' T_OP_ALIGN '[' uconst ']' {
if ($5 > 16) if ($5 > 16)
yyerror("Alignment must be between 0 and 16, not %u", error("Alignment must be between 0 and 16, not %u\n", $5);
$5);
else else
$$.alignment = $5; $$.alignment = $5;
} }
| sectattrs ',' T_OP_ALIGN '[' uconst ',' uconst ']' { | sectattrs ',' T_OP_ALIGN '[' uconst ',' uconst ']' {
if ($5 > 16) { if ($5 > 16) {
yyerror("Alignment must be between 0 and 16, not %u", error("Alignment must be between 0 and 16, not %u\n", $5);
$5);
} else { } else {
$$.alignment = $5; $$.alignment = $5;
if ($7 >= 1 << $$.alignment) if ($7 >= 1 << $$.alignment)
yyerror("Alignment offset must not be greater than alignment (%u < %u)", error("Alignment offset must not be greater than alignment (%u < %u)\n",
$7, 1 << $$.alignment); $7, 1 << $$.alignment);
else else
$$.alignOfs = $7; $$.alignOfs = $7;
@@ -1701,7 +1699,7 @@ z80_ld_r : T_Z80_LD reg_r ',' reloc_8bit {
} }
| T_Z80_LD reg_r ',' reg_r { | T_Z80_LD reg_r ',' reg_r {
if (($2 == REG_HL_IND) && ($4 == REG_HL_IND)) if (($2 == REG_HL_IND) && ($4 == REG_HL_IND))
yyerror("LD [HL],[HL] not a valid instruction"); error("LD [HL],[HL] not a valid instruction\n");
else else
out_AbsByte(0x40 | ($2 << 3) | $4); out_AbsByte(0x40 | ($2 << 3) | $4);
} }
@@ -1711,13 +1709,13 @@ z80_ld_a : T_Z80_LD reg_r ',' c_ind {
if ($2 == REG_A) if ($2 == REG_A)
out_AbsByte(0xF2); out_AbsByte(0xF2);
else else
yyerror("Destination operand must be A"); error("Destination operand must be A\n");
} }
| T_Z80_LD reg_r ',' reg_rr { | T_Z80_LD reg_r ',' reg_rr {
if ($2 == REG_A) if ($2 == REG_A)
out_AbsByte(0x0A | ($4 << 4)); out_AbsByte(0x0A | ($4 << 4));
else else
yyerror("Destination operand must be A"); error("Destination operand must be A\n");
} }
| T_Z80_LD reg_r ',' op_mem_ind { | T_Z80_LD reg_r ',' op_mem_ind {
if ($2 == REG_A) { if ($2 == REG_A) {
@@ -1731,7 +1729,7 @@ z80_ld_a : T_Z80_LD reg_r ',' c_ind {
out_RelWord(&$4); out_RelWord(&$4);
} }
} else { } else {
yyerror("Destination operand must be A"); error("Destination operand must be A\n");
rpn_Free(&$4); rpn_Free(&$4);
} }
} }

View File

@@ -61,19 +61,19 @@ struct Charmap *charmap_New(const char *name, const char *baseName)
base = charmap_Get(baseName); base = charmap_Get(baseName);
if (base == NULL) if (base == NULL)
yyerror("Base charmap '%s' doesn't exist", baseName); error("Base charmap '%s' doesn't exist\n", baseName);
} }
struct Charmap *charmap = charmap_Get(name); struct Charmap *charmap = charmap_Get(name);
if (charmap != NULL) { if (charmap != NULL) {
yyerror("Charmap '%s' already exists", name); error("Charmap '%s' already exists\n", name);
return NULL; return NULL;
} }
charmap = malloc(sizeof(*charmap)); charmap = malloc(sizeof(*charmap));
if (charmap == NULL) if (charmap == NULL)
fatalerror("Failed to create charmap: %s", strerror(errno)); fatalerror("Failed to create charmap: %s\n", strerror(errno));
/* Init the new charmap's fields */ /* Init the new charmap's fields */
snprintf(charmap->name, sizeof(charmap->name), "%s", name); snprintf(charmap->name, sizeof(charmap->name), "%s", name);
@@ -100,7 +100,7 @@ void charmap_Set(const char *name)
struct Charmap *charmap = charmap_Get(name); struct Charmap *charmap = charmap_Get(name);
if (charmap == NULL) if (charmap == NULL)
yyerror("Charmap '%s' doesn't exist", name); error("Charmap '%s' doesn't exist\n", name);
else else
currentCharmap = charmap; currentCharmap = charmap;
} }
@@ -111,7 +111,7 @@ void charmap_Push(void)
stackEntry = malloc(sizeof(struct CharmapStackEntry)); stackEntry = malloc(sizeof(struct CharmapStackEntry));
if (stackEntry == NULL) if (stackEntry == NULL)
fatalerror("No memory for charmap stack"); fatalerror("No memory for charmap stack\n");
stackEntry->charmap = currentCharmap; stackEntry->charmap = currentCharmap;
stackEntry->next = charmapStack; stackEntry->next = charmapStack;
@@ -122,7 +122,7 @@ void charmap_Push(void)
void charmap_Pop(void) void charmap_Pop(void)
{ {
if (charmapStack == NULL) if (charmapStack == NULL)
fatalerror("No entries in the charmap stack"); fatalerror("No entries in the charmap stack\n");
struct CharmapStackEntry *top = charmapStack; struct CharmapStackEntry *top = charmapStack;
@@ -182,7 +182,8 @@ int32_t charmap_Convert(char **input)
output = malloc(strlen(*input)); output = malloc(strlen(*input));
if (output == NULL) if (output == NULL)
fatalerror("Not enough memory for buffer"); fatalerror("Not enough memory for charmap conversion buffer: %s\n",
strerror(errno));
length = 0; length = 0;

View File

@@ -70,7 +70,7 @@ static void pushcontext(void)
struct sContext **ppFileStack; struct sContext **ppFileStack;
if (++nFileStackDepth > nMaxRecursionDepth) if (++nFileStackDepth > nMaxRecursionDepth)
fatalerror("Recursion limit (%u) exceeded", nMaxRecursionDepth); fatalerror("Recursion limit (%u) exceeded\n", nMaxRecursionDepth);
ppFileStack = &pFileStack; ppFileStack = &pFileStack;
while (*ppFileStack) while (*ppFileStack)
@@ -79,7 +79,7 @@ static void pushcontext(void)
*ppFileStack = malloc(sizeof(struct sContext)); *ppFileStack = malloc(sizeof(struct sContext));
if (*ppFileStack == NULL) if (*ppFileStack == NULL)
fatalerror("No memory for context"); fatalerror("No memory for context\n");
(*ppFileStack)->FlexHandle = CurrentFlexHandle; (*ppFileStack)->FlexHandle = CurrentFlexHandle;
(*ppFileStack)->next = NULL; (*ppFileStack)->next = NULL;
@@ -104,7 +104,7 @@ static void pushcontext(void)
(*ppFileStack)->nREPTBodyLastLine = nCurrentREPTBodyLastLine; (*ppFileStack)->nREPTBodyLastLine = nCurrentREPTBodyLastLine;
break; break;
default: default:
fatalerror("%s: Internal error.", __func__); fatalerror("%s: Internal error.\n", __func__);
} }
(*ppFileStack)->uniqueID = macro_GetUniqueID(); (*ppFileStack)->uniqueID = macro_GetUniqueID();
@@ -147,7 +147,7 @@ static int32_t popcontext(void)
*/ */
sprintf(pREPTIterationWritePtr, "%lu", sprintf(pREPTIterationWritePtr, "%lu",
nREPTIterationNo); nREPTIterationNo);
fatalerror("Cannot write REPT count to file path"); fatalerror("Cannot write REPT count to file path\n");
} }
nLineNo = nCurrentREPTBodyFirstLine; nLineNo = nCurrentREPTBodyFirstLine;
@@ -208,7 +208,7 @@ static int32_t popcontext(void)
nCurrentREPTBodyFirstLine = pLastFile->nREPTBodyFirstLine; nCurrentREPTBodyFirstLine = pLastFile->nREPTBodyFirstLine;
break; break;
default: default:
fatalerror("%s: Internal error.", __func__); fatalerror("%s: Internal error.\n", __func__);
} }
macro_SetUniqueID(pLastFile->uniqueID); macro_SetUniqueID(pLastFile->uniqueID);
@@ -237,7 +237,7 @@ int32_t fstk_GetLine(void)
case STAT_isREPTBlock: case STAT_isREPTBlock:
break; /* Peek top file of the stack */ break; /* Peek top file of the stack */
default: default:
fatalerror("%s: Internal error.", __func__); fatalerror("%s: Internal error.\n", __func__);
} }
pLastFile = pFileStack; pLastFile = pFileStack;
@@ -254,7 +254,7 @@ int32_t fstk_GetLine(void)
* This is only reached if the lexer is in REPT or MACRO mode but there * This is only reached if the lexer is in REPT or MACRO mode but there
* are no saved contexts with the origin of said REPT or MACRO. * are no saved contexts with the origin of said REPT or MACRO.
*/ */
fatalerror("%s: Internal error.", __func__); fatalerror("%s: Internal error.\n", __func__);
} }
int yywrap(void) int yywrap(void)
@@ -290,8 +290,7 @@ void fstk_DumpToStr(char *buf, size_t buflen)
retcode = snprintf(&buf[buflen - len], len, "%s(%" PRId32 ") -> ", retcode = snprintf(&buf[buflen - len], len, "%s(%" PRId32 ") -> ",
pLastFile->tzFileName, pLastFile->nLine); pLastFile->tzFileName, pLastFile->nLine);
if (retcode < 0) if (retcode < 0)
fatalerror("Failed to dump file stack to string: %s", fatalerror("Failed to dump file stack to string: %s\n", strerror(errno));
strerror(errno));
else if (retcode >= len) else if (retcode >= len)
len = 0; len = 0;
else else
@@ -302,15 +301,14 @@ void fstk_DumpToStr(char *buf, size_t buflen)
retcode = snprintf(&buf[buflen - len], len, "%s(%" PRId32 ")", retcode = snprintf(&buf[buflen - len], len, "%s(%" PRId32 ")",
tzCurrentFileName, nLineNo); tzCurrentFileName, nLineNo);
if (retcode < 0) if (retcode < 0)
fatalerror("Failed to dump file stack to string: %s", fatalerror("Failed to dump file stack to string: %s\n", strerror(errno));
strerror(errno));
else if (retcode >= len) else if (retcode >= len)
len = 0; len = 0;
else else
len -= retcode; len -= retcode;
if (!len) if (!len)
warning(WARNING_LONG_STR, "File stack dump too long, got truncated"); warning(WARNING_LONG_STR, "File stack dump too long, got truncated\n");
} }
/* /*
@@ -333,7 +331,7 @@ void fstk_DumpStringExpansions(void)
void fstk_AddIncludePath(char *s) void fstk_AddIncludePath(char *s)
{ {
if (NextIncPath == MAXINCPATHS) if (NextIncPath == MAXINCPATHS)
fatalerror("Too many include directories passed from command line"); fatalerror("Too many include directories passed from command line\n");
// Find last occurrence of slash; is it at the end of the string? // Find last occurrence of slash; is it at the end of the string?
char const *lastSlash = strrchr(s, '/'); char const *lastSlash = strrchr(s, '/');
@@ -341,7 +339,7 @@ void fstk_AddIncludePath(char *s)
if (snprintf(IncludePaths[NextIncPath++], _MAX_PATH, pattern, if (snprintf(IncludePaths[NextIncPath++], _MAX_PATH, pattern,
s) >= _MAX_PATH) s) >= _MAX_PATH)
fatalerror("Include path too long '%s'", s); fatalerror("Include path too long '%s'\n", s);
} }
static void printdep(const char *fileName) static void printdep(const char *fileName)
@@ -425,8 +423,7 @@ void fstk_RunInclude(char *tzFileName)
oFailedOnMissingInclude = true; oFailedOnMissingInclude = true;
return; return;
} }
yyerror("Unable to open included file '%s': %s", tzFileName, error("Unable to open included file '%s': %s\n", tzFileName, strerror(errno));
strerror(errno));
return; return;
} }
@@ -456,11 +453,11 @@ void fstk_RunMacro(char *s, struct MacroArgs *args)
int nPrintedChars; int nPrintedChars;
if (sym == NULL) { if (sym == NULL) {
yyerror("Macro \"%s\" not defined", s); error("Macro \"%s\" not defined\n", s);
return; return;
} }
if (sym->type != SYM_MACRO) { if (sym->type != SYM_MACRO) {
yyerror("\"%s\" is not a macro", s); error("\"%s\" is not a macro\n", s);
return; return;
} }
@@ -474,7 +471,7 @@ void fstk_RunMacro(char *s, struct MacroArgs *args)
"%s::%s", sym->fileName, s); "%s::%s", sym->fileName, s);
if (nPrintedChars > _MAX_PATH) { if (nPrintedChars > _MAX_PATH) {
popcontext(); popcontext();
fatalerror("File name + macro name is too large to fit into buffer"); fatalerror("File name + macro name is too large to fit into buffer\n");
} }
pCurrentMacro = sym; pCurrentMacro = sym;
@@ -505,8 +502,7 @@ void fstk_RunRept(uint32_t count, int32_t nReptLineNo)
nLineNo = nReptLineNo; nLineNo = nReptLineNo;
if (strlen(tzCurrentFileName) + strlen(tzReptStr) > _MAX_PATH) if (strlen(tzCurrentFileName) + strlen(tzReptStr) > _MAX_PATH)
fatalerror("Cannot append \"%s\" to file path", fatalerror("Cannot append \"%s\" to file path\n", tzReptStr);
tzReptStr);
strcat(tzCurrentFileName, tzReptStr); strcat(tzCurrentFileName, tzReptStr);
CurrentFlexHandle = CurrentFlexHandle =
@@ -530,7 +526,7 @@ void fstk_Init(char *pFileName)
// minus 2 to account for trailing "\"\0" // minus 2 to account for trailing "\"\0"
// minus 1 to avoid a buffer overflow in extreme cases // minus 1 to avoid a buffer overflow in extreme cases
while (*c && fileNameIndex < sizeof(tzSymFileName) - 2 - 1) { while (*c && fileNameIndex < sizeof(tzSymFileName) - 2 - 1) {
if (*c == '"') { if (*c == '"') {
tzSymFileName[fileNameIndex++] = '\\'; tzSymFileName[fileNameIndex++] = '\\';
} }
@@ -550,8 +546,7 @@ void fstk_Init(char *pFileName)
} else { } else {
pCurrentFile = fopen(pFileName, "rb"); pCurrentFile = fopen(pFileName, "rb");
if (pCurrentFile == NULL) if (pCurrentFile == NULL)
fatalerror("Unable to open file '%s': %s", pFileName, fatalerror("Unable to open file '%s': %s\n", pFileName, strerror(errno));
strerror(errno));
} }
nFileStackDepth = 0; nFileStackDepth = 0;

View File

@@ -110,7 +110,7 @@ static int32_t ascii2bin(char *s)
* There are no digits after the radix prefix * There are no digits after the radix prefix
* (or the string is empty, which shouldn't happen). * (or the string is empty, which shouldn't happen).
*/ */
yyerror("Invalid integer constant"); error("Invalid integer constant\n");
} else if (radix == 4) { } else if (radix == 4) {
int32_t size = 0; int32_t size = 0;
int32_t c; int32_t c;
@@ -126,7 +126,7 @@ static int32_t ascii2bin(char *s)
* the Game Boy tile width, produces a nonsensical result. * the Game Boy tile width, produces a nonsensical result.
*/ */
if (size > 8) { if (size > 8) {
warning(WARNING_LARGE_CONSTANT, "Graphics constant '%s' is too long", warning(WARNING_LARGE_CONSTANT, "Graphics constant '%s' is too long\n",
start); start);
} }
} else { } else {
@@ -143,7 +143,7 @@ static int32_t ascii2bin(char *s)
} }
if (overflow) if (overflow)
warning(WARNING_LARGE_CONSTANT, "Integer constant '%s' is too large", warning(WARNING_LARGE_CONSTANT, "Integer constant '%s' is too large\n",
start); start);
} }
@@ -176,7 +176,7 @@ uint32_t ParseNumber(char *s, uint32_t size)
char dest[256]; char dest[256];
if (size > 255) if (size > 255)
fatalerror("Number token too long"); fatalerror("Number token too long\n");
strncpy(dest, s, size); strncpy(dest, s, size);
dest[size] = 0; dest[size] = 0;
@@ -201,10 +201,10 @@ char const *AppendMacroArg(char whichArg, char *dest, size_t *destIndex)
else if (whichArg >= '1' && whichArg <= '9') else if (whichArg >= '1' && whichArg <= '9')
marg = macro_GetArg(whichArg - '0'); marg = macro_GetArg(whichArg - '0');
else else
fatalerror("Invalid macro argument '\\%c' in symbol", whichArg); fatalerror("Invalid macro argument '\\%c' in symbol\n", whichArg);
if (!marg) if (!marg)
fatalerror("Macro argument '\\%c' not defined", whichArg); fatalerror("Macro argument '\\%c' not defined\n", whichArg);
char ch; char ch;
@@ -217,7 +217,7 @@ char const *AppendMacroArg(char whichArg, char *dest, size_t *destIndex)
|| ch == '#' || ch == '#'
|| ch == '.') { || ch == '.') {
if (*destIndex >= MAXSYMLEN) if (*destIndex >= MAXSYMLEN)
fatalerror("Symbol too long"); fatalerror("Symbol too long\n");
dest[*destIndex] = ch; dest[*destIndex] = ch;
(*destIndex)++; (*destIndex)++;
@@ -256,7 +256,7 @@ uint32_t ParseSymbol(char *src, uint32_t size)
break; break;
} else { } else {
if (destIndex >= MAXSYMLEN) if (destIndex >= MAXSYMLEN)
fatalerror("Symbol too long"); fatalerror("Symbol too long\n");
dest[destIndex++] = ch; dest[destIndex++] = ch;
} }
} }
@@ -311,9 +311,9 @@ uint32_t PutMacroArg(char *src, uint32_t size)
if (s != NULL) if (s != NULL)
yyunputstr(s); yyunputstr(s);
else else
yyerror("Macro argument '\\%c' not defined", src[1]); error("Macro argument '\\%c' not defined\n", src[1]);
} else { } else {
yyerror("Invalid macro argument '\\%c'", src[1]); error("Invalid macro argument '\\%c'\n", src[1]);
} }
return 0; return 0;
} }
@@ -330,7 +330,7 @@ uint32_t PutUniqueID(char *src, uint32_t size)
if (s != NULL) if (s != NULL)
yyunputstr(s); yyunputstr(s);
else else
yyerror("Macro unique label string not defined"); error("Macro unique label string not defined\n");
return 0; return 0;
} }

View File

@@ -89,7 +89,7 @@ void yyunputbytes(uint32_t count)
void yyunput(char c) void yyunput(char c)
{ {
if (pLexBuffer <= pLexBufferRealStart) if (pLexBuffer <= pLexBufferRealStart)
fatalerror("Buffer safety margin exceeded"); fatalerror("Buffer safety margin exceeded\n");
*(--pLexBuffer) = c; *(--pLexBuffer) = c;
} }
@@ -107,7 +107,7 @@ void yyunputstr(const char *s)
* Refer to https://github.com/rednex/rgbds/pull/411#discussion_r319779797 * Refer to https://github.com/rednex/rgbds/pull/411#discussion_r319779797
*/ */
if (pLexBuffer - pLexBufferRealStart < len) if (pLexBuffer - pLexBufferRealStart < len)
fatalerror("Buffer safety margin exceeded"); fatalerror("Buffer safety margin exceeded\n");
pLexBuffer -= len; pLexBuffer -= len;
@@ -121,15 +121,14 @@ void yyunputstr(const char *s)
void lex_BeginStringExpansion(const char *tzName) void lex_BeginStringExpansion(const char *tzName)
{ {
if (++nNbStringExpansions > nMaxRecursionDepth) if (++nNbStringExpansions > nMaxRecursionDepth)
fatalerror("Recursion limit (%u) exceeded", nMaxRecursionDepth); fatalerror("Recursion limit (%u) exceeded\n", nMaxRecursionDepth);
struct sStringExpansionPos *pNewStringExpansion = struct sStringExpansionPos *pNewStringExpansion =
malloc(sizeof(*pNewStringExpansion)); malloc(sizeof(*pNewStringExpansion));
char *tzNewExpansionName = strdup(tzName); char *tzNewExpansionName = strdup(tzName);
if (!pNewStringExpansion || !tzNewExpansionName) if (!pNewStringExpansion || !tzNewExpansionName)
fatalerror("Could not allocate memory to expand '%s'", fatalerror("Could not allocate memory to expand '%s'\n", tzName);
tzName);
pNewStringExpansion->tzName = tzNewExpansionName; pNewStringExpansion->tzName = tzNewExpansionName;
pNewStringExpansion->pBuffer = pLexBufferRealStart; pNewStringExpansion->pBuffer = pLexBufferRealStart;
@@ -196,14 +195,14 @@ YY_BUFFER_STATE yy_scan_bytes(char const *mem, uint32_t size)
YY_BUFFER_STATE pBuffer = malloc(sizeof(struct yy_buffer_state)); YY_BUFFER_STATE pBuffer = malloc(sizeof(struct yy_buffer_state));
if (pBuffer == NULL) if (pBuffer == NULL)
fatalerror("%s: Out of memory!", __func__); fatalerror("%s: Out of memory!\n", __func__);
size_t capacity = size + 3; /* space for 2 newlines and terminator */ size_t capacity = size + 3; /* space for 2 newlines and terminator */
pBuffer->pBufferRealStart = malloc(capacity + SAFETYMARGIN); pBuffer->pBufferRealStart = malloc(capacity + SAFETYMARGIN);
if (pBuffer->pBufferRealStart == NULL) if (pBuffer->pBufferRealStart == NULL)
fatalerror("%s: Out of memory for buffer!", __func__); fatalerror("%s: Out of memory for buffer!\n", __func__);
pBuffer->pBufferStart = pBuffer->pBufferRealStart + SAFETYMARGIN; pBuffer->pBufferStart = pBuffer->pBufferRealStart + SAFETYMARGIN;
pBuffer->pBuffer = pBuffer->pBufferRealStart + SAFETYMARGIN; pBuffer->pBuffer = pBuffer->pBufferRealStart + SAFETYMARGIN;
@@ -221,7 +220,7 @@ YY_BUFFER_STATE yy_create_buffer(FILE *f)
YY_BUFFER_STATE pBuffer = malloc(sizeof(struct yy_buffer_state)); YY_BUFFER_STATE pBuffer = malloc(sizeof(struct yy_buffer_state));
if (pBuffer == NULL) if (pBuffer == NULL)
fatalerror("%s: Out of memory!", __func__); fatalerror("%s: Out of memory!\n", __func__);
size_t size = 0, capacity = -1; size_t size = 0, capacity = -1;
char *buf = NULL; char *buf = NULL;
@@ -263,7 +262,7 @@ YY_BUFFER_STATE yy_create_buffer(FILE *f)
buf = realloc(buf, capacity + SAFETYMARGIN + 3); buf = realloc(buf, capacity + SAFETYMARGIN + 3);
if (buf == NULL) if (buf == NULL)
fatalerror("%s: Out of memory for buffer!", fatalerror("%s: Out of memory for buffer!\n",
__func__); __func__);
} }
@@ -271,7 +270,7 @@ YY_BUFFER_STATE yy_create_buffer(FILE *f)
size_t read_count = fread(bufpos, 1, capacity - size, f); size_t read_count = fread(bufpos, 1, capacity - size, f);
if (read_count == 0 && !feof(f)) if (read_count == 0 && !feof(f))
fatalerror("%s: fread error", __func__); fatalerror("%s: fread error\n", __func__);
size += read_count; size += read_count;
} while (!feof(f)); } while (!feof(f));
@@ -320,7 +319,7 @@ YY_BUFFER_STATE yy_create_buffer(FILE *f)
if (mem != pBuffer->pBuffer + size) { if (mem != pBuffer->pBuffer + size) {
nLineNo = lineCount + 1; nLineNo = lineCount + 1;
fatalerror("Found null character"); fatalerror("Found null character\n");
} }
/* Remove comments */ /* Remove comments */
@@ -343,7 +342,8 @@ YY_BUFFER_STATE yy_create_buffer(FILE *f)
*mem++ = ' '; *mem++ = ' ';
/* Comments that start with * at the start of a line */ /* Comments that start with * at the start of a line */
} else if ((mem[0] == '\n') && (mem[1] == '*')) { } else if ((mem[0] == '\n') && (mem[1] == '*')) {
warning(WARNING_OBSOLETE, "'*' is deprecated for comments, please use ';' instead"); warning(WARNING_OBSOLETE,
"'*' is deprecated for comments, please use ';' instead\n");
mem++; mem++;
while (!((*mem == '\n') || (*mem == '\0'))) while (!((*mem == '\n') || (*mem == '\0')))
*mem++ = ' '; *mem++ = ' ';
@@ -372,7 +372,7 @@ uint32_t lex_FloatAlloc(const struct sLexFloat *token)
bool lex_CheckCharacterRange(uint16_t start, uint16_t end) bool lex_CheckCharacterRange(uint16_t start, uint16_t end)
{ {
if (start > end || start < 1 || end > 127) { if (start > end || start < 1 || end > 127) {
yyerror("Invalid character range (start: %" PRIu16 ", end: %" PRIu16 ")", error("Invalid character range (start: %" PRIu16 ", end: %" PRIu16 ")\n",
start, end); start, end);
return false; return false;
} }
@@ -442,7 +442,7 @@ void lex_FloatAddSecondRange(uint32_t id, uint16_t start, uint16_t end)
static struct sLexFloat *lexgetfloat(uint32_t nFloatMask) static struct sLexFloat *lexgetfloat(uint32_t nFloatMask)
{ {
if (nFloatMask == 0) if (nFloatMask == 0)
fatalerror("Internal error in %s", __func__); fatalerror("Internal error in %s\n", __func__);
int32_t i = 0; int32_t i = 0;
@@ -496,11 +496,11 @@ void lex_AddStrings(const struct sLexInitString *lex)
*ppHash = malloc(sizeof(struct sLexString)); *ppHash = malloc(sizeof(struct sLexString));
if (*ppHash == NULL) if (*ppHash == NULL)
fatalerror("Out of memory!"); fatalerror("Out of memory!\n");
(*ppHash)->tzName = (char *)strdup(lex->tzName); (*ppHash)->tzName = (char *)strdup(lex->tzName);
if ((*ppHash)->tzName == NULL) if ((*ppHash)->tzName == NULL)
fatalerror("Out of memory!"); fatalerror("Out of memory!\n");
(*ppHash)->nNameLength = strlen(lex->tzName); (*ppHash)->nNameLength = strlen(lex->tzName);
(*ppHash)->nToken = lex->nToken; (*ppHash)->nToken = lex->nToken;
@@ -595,12 +595,12 @@ size_t CopyMacroArg(char *dest, size_t maxLength, char c)
return 0; return 0;
if (s == NULL) if (s == NULL)
fatalerror("Macro argument '\\%c' not defined", c); fatalerror("Macro argument '\\%c' not defined\n", c);
// TODO: `strncpy`, nay? // TODO: `strncpy`, nay?
for (i = 0; s[i] != 0; i++) { for (i = 0; s[i] != 0; i++) {
if (i >= maxLength) if (i >= maxLength)
fatalerror("Macro argument too long to fit buffer"); fatalerror("Macro argument too long to fit buffer\n");
dest[i] = s[i]; dest[i] = s[i];
} }
@@ -611,7 +611,7 @@ size_t CopyMacroArg(char *dest, size_t maxLength, char c)
static inline void yylex_StringWriteChar(char *s, size_t index, char c) static inline void yylex_StringWriteChar(char *s, size_t index, char c)
{ {
if (index >= MAXSTRLEN) if (index >= MAXSTRLEN)
fatalerror("String too long"); fatalerror("String too long\n");
s[index] = c; s[index] = c;
} }
@@ -619,7 +619,7 @@ static inline void yylex_StringWriteChar(char *s, size_t index, char c)
static inline void yylex_SymbolWriteChar(char *s, size_t index, char c) static inline void yylex_SymbolWriteChar(char *s, size_t index, char c)
{ {
if (index >= MAXSYMLEN) if (index >= MAXSYMLEN)
fatalerror("Symbol too long"); fatalerror("Symbol too long\n");
s[index] = c; s[index] = c;
} }
@@ -657,7 +657,7 @@ size_t yylex_ReadBracketedSymbol(char *dest, size_t index)
if (length != 0) if (length != 0)
i += length; i += length;
else else
fatalerror("Illegal character escape '%c'", ch); fatalerror("Illegal character escape '%c'\n", ch);
} else if (ch == '{') { } else if (ch == '{') {
/* Handle nested symbols */ /* Handle nested symbols */
++pLexBuffer; ++pLexBuffer;
@@ -679,12 +679,11 @@ size_t yylex_ReadBracketedSymbol(char *dest, size_t index)
const char *designatedMode; const char *designatedMode;
if (i != 1) if (i != 1)
fatalerror("Print types are exactly 1 character long"); fatalerror("Print types are exactly 1 character long\n");
designatedMode = strchr(acceptedModes, sym[i - 1]); designatedMode = strchr(acceptedModes, sym[i - 1]);
if (!designatedMode) if (!designatedMode)
fatalerror("Illegal print type '%c'", fatalerror("Illegal print type '%c'\n", sym[i - 1]);
sym[i - 1]);
mode = formatSpecifiers[designatedMode - acceptedModes]; mode = formatSpecifiers[designatedMode - acceptedModes];
/* Begin writing the symbol again */ /* Begin writing the symbol again */
i = 0; i = 0;
@@ -703,7 +702,7 @@ size_t yylex_ReadBracketedSymbol(char *dest, size_t index)
if (*pLexBuffer == '}') if (*pLexBuffer == '}')
pLexBuffer++; pLexBuffer++;
else else
fatalerror("Missing }"); fatalerror("Missing }\n");
return length; return length;
} }
@@ -752,8 +751,7 @@ static void yylex_ReadQuotedString(void)
if (length != 0) if (length != 0)
index += length; index += length;
else else
fatalerror("Illegal character escape '%c'", fatalerror("Illegal character escape '%c'\n", ch);
ch);
ch = 0; ch = 0;
break; break;
@@ -774,7 +772,7 @@ static void yylex_ReadQuotedString(void)
if (*pLexBuffer == '"') if (*pLexBuffer == '"')
pLexBuffer++; pLexBuffer++;
else else
fatalerror("Unterminated string"); fatalerror("Unterminated string\n");
} }
static uint32_t yylex_NORMAL(void) static uint32_t yylex_NORMAL(void)
@@ -818,7 +816,7 @@ scanagain:
nLineNo++; nLineNo++;
goto scanagain; goto scanagain;
} else { } else {
yyerror("Expected a new line after the continuation character."); error("Expected a new line after the continuation character.\n");
pLexBuffer++; pLexBuffer++;
} }
} }
@@ -883,7 +881,7 @@ scanagain:
if (ch != 0 if (ch != 0
&& ch != '\n' && ch != '\n'
&& !(ch >= 0x20 && ch <= 0x7E)) && !(ch >= 0x20 && ch <= 0x7E))
fatalerror("Found garbage character: 0x%02X", ch); fatalerror("Found garbage character: 0x%02X\n", ch);
return ch; return ch;
} }
@@ -973,7 +971,7 @@ static uint32_t yylex_MACROARGS(void)
ch = 0; ch = 0;
break; break;
} else { } else {
yyerror("Expected a new line after the continuation character."); error("Expected a new line after the continuation character.\n");
} }
} }
break; break;
@@ -990,8 +988,7 @@ static uint32_t yylex_MACROARGS(void)
if (length != 0) if (length != 0)
index += length; index += length;
else else
fatalerror("Illegal character escape '%c'", fatalerror("Illegal character escape '%c'\n", ch);
ch);
ch = 0; ch = 0;
break; break;
@@ -1022,7 +1019,7 @@ static uint32_t yylex_MACROARGS(void)
return ','; return ',';
} }
fatalerror("Internal error in %s", __func__); fatalerror("Internal error in %s\n", __func__);
} }
int yylex(void) int yylex(void)
@@ -1037,7 +1034,7 @@ int yylex(void)
returnedChar = yylex_MACROARGS(); returnedChar = yylex_MACROARGS();
break; break;
default: default:
fatalerror("%s: Internal error.", __func__); fatalerror("%s: Internal error.\n", __func__);
} }
/* Check if string expansions were fully read */ /* Check if string expansions were fully read */

View File

@@ -48,7 +48,7 @@ struct MacroArgs *macro_NewArgs(void)
struct MacroArgs *args = malloc(SIZEOF_ARGS(INITIAL_ARG_SIZE)); struct MacroArgs *args = malloc(SIZEOF_ARGS(INITIAL_ARG_SIZE));
if (!args) if (!args)
fatalerror("Unable to register macro arguments: %s", strerror(errno)); fatalerror("Unable to register macro arguments: %s\n", strerror(errno));
args->nbArgs = 0; args->nbArgs = 0;
args->shift = 0; args->shift = 0;
@@ -60,16 +60,16 @@ void macro_AppendArg(struct MacroArgs **argPtr, char *s)
{ {
#define macArgs (*argPtr) #define macArgs (*argPtr)
if (macArgs->nbArgs == MAXMACROARGS) if (macArgs->nbArgs == MAXMACROARGS)
yyerror("A maximum of " EXPAND_AND_STR(MAXMACROARGS) error("A maximum of " EXPAND_AND_STR(MAXMACROARGS)
" arguments is allowed"); " arguments is allowed\n");
if (macArgs->nbArgs >= macArgs->capacity) { if (macArgs->nbArgs >= macArgs->capacity) {
macArgs->capacity *= 2; macArgs->capacity *= 2;
/* Check that overflow didn't roll us back */ /* Check that overflow didn't roll us back */
if (macArgs->capacity <= macArgs->nbArgs) if (macArgs->capacity <= macArgs->nbArgs)
fatalerror("Failed to add new macro argument: possible capacity overflow"); fatalerror("Failed to add new macro argument: possible capacity overflow\n");
macArgs = realloc(macArgs, SIZEOF_ARGS(macArgs->capacity)); macArgs = realloc(macArgs, SIZEOF_ARGS(macArgs->capacity));
if (!macArgs) if (!macArgs)
fatalerror("Error adding new macro argument: %s", strerror(errno)); fatalerror("Error adding new macro argument: %s\n", strerror(errno));
} }
macArgs->args[macArgs->nbArgs++] = s; macArgs->args[macArgs->nbArgs++] = s;
#undef macArgs #undef macArgs

View File

@@ -150,7 +150,7 @@ void opt_Parse(char *s)
newopt.gbgfx[2] = s[3]; newopt.gbgfx[2] = s[3];
newopt.gbgfx[3] = s[4]; newopt.gbgfx[3] = s[4];
} else { } else {
yyerror("Must specify exactly 4 characters for option 'g'"); error("Must specify exactly 4 characters for option 'g'\n");
} }
break; break;
case 'b': case 'b':
@@ -158,11 +158,11 @@ void opt_Parse(char *s)
newopt.binary[0] = s[1]; newopt.binary[0] = s[1];
newopt.binary[1] = s[2]; newopt.binary[1] = s[2];
} else { } else {
yyerror("Must specify exactly 2 characters for option 'b'"); error("Must specify exactly 2 characters for option 'b'\n");
} }
break; break;
case 'z': case 'z':
warning(WARNING_OBSOLETE, "Option 'z' is a deprecated alias for 'p'"); warning(WARNING_OBSOLETE, "Option 'z' is a deprecated alias for 'p'\n");
/* fallthrough */ /* fallthrough */
case 'p': case 'p':
if (strlen(&s[1]) <= 2) { if (strlen(&s[1]) <= 2) {
@@ -171,15 +171,15 @@ void opt_Parse(char *s)
result = sscanf(&s[1], "%x", &fillchar); result = sscanf(&s[1], "%x", &fillchar);
if (result != EOF && result != 1) if (result != EOF && result != 1)
yyerror("Invalid argument for option 'z'"); error("Invalid argument for option 'z'\n");
else else
newopt.fillchar = fillchar; newopt.fillchar = fillchar;
} else { } else {
yyerror("Invalid argument for option 'z'"); error("Invalid argument for option 'z'\n");
} }
break; break;
default: default:
yyerror("Unknown option"); error("Unknown option\n");
break; break;
} }
@@ -193,7 +193,7 @@ void opt_Push(void)
pOpt = malloc(sizeof(struct sOptionStackEntry)); pOpt = malloc(sizeof(struct sOptionStackEntry));
if (pOpt == NULL) if (pOpt == NULL)
fatalerror("No memory for option stack"); fatalerror("No memory for option stack\n");
pOpt->Options = CurrentOptions; pOpt->Options = CurrentOptions;
pOpt->next = pOptionStack; pOpt->next = pOptionStack;
@@ -203,7 +203,7 @@ void opt_Push(void)
void opt_Pop(void) void opt_Pop(void)
{ {
if (pOptionStack == NULL) if (pOptionStack == NULL)
fatalerror("No entries in the option stack"); fatalerror("No entries in the option stack\n");
struct sOptionStackEntry *pOpt; struct sOptionStackEntry *pOpt;
@@ -220,17 +220,17 @@ void opt_AddDefine(char *s)
if (cldefines_index >= cldefines_numindices) { if (cldefines_index >= cldefines_numindices) {
/* Check for overflows */ /* Check for overflows */
if ((cldefines_numindices * 2) < cldefines_numindices) if ((cldefines_numindices * 2) < cldefines_numindices)
fatalerror("No memory for command line defines"); fatalerror("No memory for command line defines\n");
if ((cldefines_bufsize * 2) < cldefines_bufsize) if ((cldefines_bufsize * 2) < cldefines_bufsize)
fatalerror("No memory for command line defines"); fatalerror("No memory for command line defines\n");
cldefines_numindices *= 2; cldefines_numindices *= 2;
cldefines_bufsize *= 2; cldefines_bufsize *= 2;
cldefines = realloc(cldefines, cldefines_bufsize); cldefines = realloc(cldefines, cldefines_bufsize);
if (!cldefines) if (!cldefines)
fatalerror("No memory for command line defines"); fatalerror("No memory for command line defines\n");
} }
equals = strchr(s, '='); equals = strchr(s, '=');
if (equals) { if (equals) {
@@ -344,7 +344,7 @@ int main(int argc, char *argv[])
cldefines_bufsize = cldefines_numindices * cldefine_entrysize; cldefines_bufsize = cldefines_numindices * cldefine_entrysize;
cldefines = malloc(cldefines_bufsize); cldefines = malloc(cldefines_bufsize);
if (!cldefines) if (!cldefines)
fatalerror("No memory for command line defines"); fatalerror("No memory for command line defines\n");
#if defined(YYDEBUG) && YYDEBUG #if defined(YYDEBUG) && YYDEBUG
yydebug = 1; yydebug = 1;

View File

@@ -146,7 +146,7 @@ static uint32_t getsectid(struct Section const *sect)
sec = sec->next; sec = sec->next;
} }
fatalerror("Unknown section '%s'", sect->name); fatalerror("Unknown section '%s'\n", sect->name);
} }
static uint32_t getSectIDIfAny(struct Section const *sect) static uint32_t getSectIDIfAny(struct Section const *sect)
@@ -311,12 +311,11 @@ static struct Patch *allocpatch(uint32_t type, struct Expression const *expr,
uint32_t rpnSize = expr->isKnown ? 5 : expr->nRPNPatchSize; uint32_t rpnSize = expr->isKnown ? 5 : expr->nRPNPatchSize;
if (!patch) if (!patch)
fatalerror("No memory for patch: %s", strerror(errno)); fatalerror("No memory for patch: %s\n", strerror(errno));
patch->pRPN = malloc(sizeof(*patch->pRPN) * rpnSize); patch->pRPN = malloc(sizeof(*patch->pRPN) * rpnSize);
if (!patch->pRPN) if (!patch->pRPN)
fatalerror("No memory for patch's RPN expression: %s", fatalerror("No memory for patch's RPN expression: %s\n", strerror(errno));
strerror(errno));
patch->type = type; patch->type = type;
fstk_DumpToStr(patch->tzFilename, sizeof(patch->tzFilename)); fstk_DumpToStr(patch->tzFilename, sizeof(patch->tzFilename));

View File

@@ -31,7 +31,7 @@
/* If we had `asprintf` this would be great, but alas. */ \ /* If we had `asprintf` this would be great, but alas. */ \
_expr->reason = malloc(128); /* Use an initial reasonable size */ \ _expr->reason = malloc(128); /* Use an initial reasonable size */ \
if (!_expr->reason) \ if (!_expr->reason) \
fatalerror("Can't allocate err string: %s", strerror(errno)); \ fatalerror("Can't allocate err string: %s\n", strerror(errno)); \
int size = snprintf(_expr->reason, 128, __VA_ARGS__); \ int size = snprintf(_expr->reason, 128, __VA_ARGS__); \
if (size >= 128) { /* If this wasn't enough, try again */ \ if (size >= 128) { /* If this wasn't enough, try again */ \
_expr->reason = realloc(_expr->reason, size + 1); \ _expr->reason = realloc(_expr->reason, size + 1); \
@@ -51,8 +51,8 @@ static uint8_t *reserveSpace(struct Expression *expr, uint32_t size)
* To avoid generating humongous object files, cap the * To avoid generating humongous object files, cap the
* size of RPN expressions * size of RPN expressions
*/ */
fatalerror("RPN expression cannot grow larger than %lu bytes", fatalerror("RPN expression cannot grow larger than "
(unsigned long)MAXRPNLEN); EXPAND_AND_STR(MAXRPNLEN) " bytes\n");
else if (expr->nRPNCapacity > MAXRPNLEN / 2) else if (expr->nRPNCapacity > MAXRPNLEN / 2)
expr->nRPNCapacity = MAXRPNLEN; expr->nRPNCapacity = MAXRPNLEN;
else else
@@ -60,8 +60,7 @@ static uint8_t *reserveSpace(struct Expression *expr, uint32_t size)
expr->tRPN = realloc(expr->tRPN, expr->nRPNCapacity); expr->tRPN = realloc(expr->tRPN, expr->nRPNCapacity);
if (!expr->tRPN) if (!expr->tRPN)
fatalerror("Failed to grow RPN expression: %s", fatalerror("Failed to grow RPN expression: %s\n", strerror(errno));
strerror(errno));
} }
uint8_t *ptr = expr->tRPN + expr->nRPNLength; uint8_t *ptr = expr->tRPN + expr->nRPNLength;
@@ -108,17 +107,15 @@ void rpn_Symbol(struct Expression *expr, char *tzSym)
struct Symbol *sym = sym_FindSymbol(tzSym); struct Symbol *sym = sym_FindSymbol(tzSym);
if (sym_IsPC(sym) && !sect_GetSymbolSection()) { if (sym_IsPC(sym) && !sect_GetSymbolSection()) {
yyerror("PC has no value outside a section"); error("PC has no value outside a section\n");
rpn_Number(expr, 0); rpn_Number(expr, 0);
} else if (!sym || !sym_IsConstant(sym)) { } else if (!sym || !sym_IsConstant(sym)) {
rpn_Init(expr); rpn_Init(expr);
expr->isSymbol = true; expr->isSymbol = true;
sym_Ref(tzSym); sym_Ref(tzSym);
makeUnknown(expr, sym_IsPC(sym) makeUnknown(expr, sym_IsPC(sym) ? "PC is not constant at assembly time"
? "PC is not constant at assembly time" : "'%s' is not constant at assembly time", tzSym);
: "'%s' is not constant at assembly time",
tzSym);
expr->nRPNPatchSize += 5; /* 1-byte opcode + 4-byte symbol ID */ expr->nRPNPatchSize += 5; /* 1-byte opcode + 4-byte symbol ID */
size_t nameLen = strlen(tzSym) + 1; /* Don't forget NUL! */ size_t nameLen = strlen(tzSym) + 1; /* Don't forget NUL! */
@@ -145,7 +142,7 @@ void rpn_BankSelf(struct Expression *expr)
rpn_Init(expr); rpn_Init(expr);
if (!pCurrentSection) { if (!pCurrentSection) {
yyerror("PC has no bank outside a section"); error("PC has no bank outside a section\n");
expr->nVal = 1; expr->nVal = 1;
} else if (pCurrentSection->bank == -1) { } else if (pCurrentSection->bank == -1) {
makeUnknown(expr, "Current section's bank is not known"); makeUnknown(expr, "Current section's bank is not known");
@@ -168,7 +165,7 @@ void rpn_BankSymbol(struct Expression *expr, char const *tzSym)
rpn_Init(expr); rpn_Init(expr);
if (sym && !sym_IsLabel(sym)) { if (sym && !sym_IsLabel(sym)) {
yyerror("BANK argument must be a label"); error("BANK argument must be a label\n");
} else { } else {
sym_Ref(tzSym); sym_Ref(tzSym);
if (!sym) if (!sym)
@@ -223,8 +220,7 @@ void rpn_CheckHRAM(struct Expression *expr, const struct Expression *src)
/* That range is valid, but only keep the lower byte */ /* That range is valid, but only keep the lower byte */
expr->nVal &= 0xFF; expr->nVal &= 0xFF;
} else if (expr->nVal < 0 || expr->nVal > 0xFF) { } else if (expr->nVal < 0 || expr->nVal > 0xFF) {
yyerror("Source address $%" PRIx32 " not between $FF00 to $FFFF", error("Source address $%" PRIx32 " not between $FF00 to $FFFF\n", expr->nVal);
expr->nVal);
} }
} }
@@ -235,8 +231,7 @@ void rpn_CheckRST(struct Expression *expr, const struct Expression *src)
if (rpn_isKnown(expr)) { if (rpn_isKnown(expr)) {
/* A valid RST address must be masked with 0x38 */ /* A valid RST address must be masked with 0x38 */
if (expr->nVal & ~0x38) if (expr->nVal & ~0x38)
yyerror("Invalid address $%" PRIx32 " for RST", error("Invalid address $%" PRIx32 " for RST\n", expr->nVal);
expr->nVal);
/* The target is in the "0x38" bits, all other bits are set */ /* The target is in the "0x38" bits, all other bits are set */
expr->nVal |= 0xC7; expr->nVal |= 0xC7;
} else { } else {
@@ -263,7 +258,7 @@ static int32_t shift(int32_t shiftee, int32_t amount)
if (amount >= 0) { if (amount >= 0) {
// Left shift // Left shift
if (amount >= 32) { if (amount >= 32) {
warning(WARNING_SHIFT_AMOUNT, "Shifting left by large amount %" PRId32, warning(WARNING_SHIFT_AMOUNT, "Shifting left by large amount %" PRId32 "\n",
amount); amount);
return 0; return 0;
@@ -279,8 +274,8 @@ static int32_t shift(int32_t shiftee, int32_t amount)
// Right shift // Right shift
amount = -amount; amount = -amount;
if (amount >= 32) { if (amount >= 32) {
warning(WARNING_SHIFT_AMOUNT, "Shifting right by large amount %" PRId32, warning(WARNING_SHIFT_AMOUNT,
amount); "Shifting right by large amount %" PRId32 "\n", amount);
return shiftee < 0 ? -1 : 0; return shiftee < 0 ? -1 : 0;
} else if (shiftee >= 0) { } else if (shiftee >= 0) {
@@ -376,18 +371,20 @@ void rpn_BinaryOp(enum RPNCommand op, struct Expression *expr,
break; break;
case RPN_SHL: case RPN_SHL:
if (src2->nVal < 0) if (src2->nVal < 0)
warning(WARNING_SHIFT_AMOUNT, "Shifting left by negative amount %" PRId32, warning(WARNING_SHIFT_AMOUNT,
"Shifting left by negative amount %" PRId32 "\n",
src2->nVal); src2->nVal);
expr->nVal = shift(src1->nVal, src2->nVal); expr->nVal = shift(src1->nVal, src2->nVal);
break; break;
case RPN_SHR: case RPN_SHR:
if (src1->nVal < 0) if (src1->nVal < 0)
warning(WARNING_SHIFT, "Shifting negative value %" PRId32, warning(WARNING_SHIFT, "Shifting negative value %" PRId32 "\n",
src1->nVal); src1->nVal);
if (src2->nVal < 0) if (src2->nVal < 0)
warning(WARNING_SHIFT_AMOUNT, "Shifting right by negative amount %" PRId32, warning(WARNING_SHIFT_AMOUNT,
"Shifting right by negative amount %" PRId32 "\n",
src2->nVal); src2->nVal);
expr->nVal = shift(src1->nVal, -src2->nVal); expr->nVal = shift(src1->nVal, -src2->nVal);
@@ -397,11 +394,11 @@ void rpn_BinaryOp(enum RPNCommand op, struct Expression *expr,
break; break;
case RPN_DIV: case RPN_DIV:
if (src2->nVal == 0) if (src2->nVal == 0)
fatalerror("Division by zero"); fatalerror("Division by zero\n");
if (src1->nVal == INT32_MIN if (src1->nVal == INT32_MIN && src2->nVal == -1) {
&& src2->nVal == -1) { warning(WARNING_DIV, "Division of %" PRId32 " by -1 yields %"
warning(WARNING_DIV, "Division of min value by -1"); PRId32 "\n", INT32_MIN, INT32_MIN);
expr->nVal = INT32_MIN; expr->nVal = INT32_MIN;
} else { } else {
expr->nVal = src1->nVal / src2->nVal; expr->nVal = src1->nVal / src2->nVal;
@@ -409,7 +406,7 @@ void rpn_BinaryOp(enum RPNCommand op, struct Expression *expr,
break; break;
case RPN_MOD: case RPN_MOD:
if (src2->nVal == 0) if (src2->nVal == 0)
fatalerror("Division by zero"); fatalerror("Division by zero\n");
if (src1->nVal == INT32_MIN && src2->nVal == -1) if (src1->nVal == INT32_MIN && src2->nVal == -1)
expr->nVal = 0; expr->nVal = 0;
@@ -427,7 +424,7 @@ void rpn_BinaryOp(enum RPNCommand op, struct Expression *expr,
case RPN_RST: case RPN_RST:
case RPN_CONST: case RPN_CONST:
case RPN_SYM: case RPN_SYM:
fatalerror("%d is not a binary operator", op); fatalerror("%d is not a binary operator\n", op);
} }
} else if (op == RPN_SUB && isDiffConstant(src1, src2)) { } else if (op == RPN_SUB && isDiffConstant(src1, src2)) {

View File

@@ -40,7 +40,7 @@ struct UnionStackEntry {
static inline void checksection(void) static inline void checksection(void)
{ {
if (pCurrentSection == NULL) if (pCurrentSection == NULL)
fatalerror("Code generation before SECTION directive"); fatalerror("Code generation before SECTION directive\n");
} }
/* /*
@@ -52,7 +52,7 @@ static inline void checkcodesection(void)
checksection(); checksection();
if (!sect_HasData(pCurrentSection->type)) if (!sect_HasData(pCurrentSection->type))
fatalerror("Section '%s' cannot contain code or data (not ROM0 or ROMX)", fatalerror("Section '%s' cannot contain code or data (not ROM0 or ROMX)\n",
pCurrentSection->name); pCurrentSection->name);
} }
@@ -61,8 +61,8 @@ static inline void checkSectionSize(struct Section const *sect, uint32_t size)
uint32_t maxSize = maxsize[sect->type]; uint32_t maxSize = maxsize[sect->type];
if (size > maxSize) if (size > maxSize)
fatalerror("Section '%s' grew too big (max size = 0x%" PRIX32 " bytes, reached 0x%" PRIX32 ").", fatalerror("Section '%s' grew too big (max size = 0x%" PRIX32
sect->name, maxSize, size); " bytes, reached 0x%" PRIX32 ").\n", sect->name, maxSize, size);
} }
/* /*
@@ -110,16 +110,16 @@ static struct Section *getSection(char const *name, enum SectionType type,
if (bank != -1) { if (bank != -1) {
if (type != SECTTYPE_ROMX && type != SECTTYPE_VRAM if (type != SECTTYPE_ROMX && type != SECTTYPE_VRAM
&& type != SECTTYPE_SRAM && type != SECTTYPE_WRAMX) && type != SECTTYPE_SRAM && type != SECTTYPE_WRAMX)
yyerror("BANK only allowed for ROMX, WRAMX, SRAM, or VRAM sections"); error("BANK only allowed for ROMX, WRAMX, SRAM, or VRAM sections\n");
else if (bank < bankranges[type][0] else if (bank < bankranges[type][0]
|| bank > bankranges[type][1]) || bank > bankranges[type][1])
yyerror("%s bank value $%" PRIx32 " out of range ($%" PRIx32 " to $%" PRIx32 ")", error("%s bank value $%" PRIx32 " out of range ($%" PRIx32 " to $%"
typeNames[type], bank, PRIx32 ")\n", typeNames[type], bank,
bankranges[type][0], bankranges[type][1]); bankranges[type][0], bankranges[type][1]);
} }
if (alignOffset >= 1 << alignment) { if (alignOffset >= 1 << alignment) {
yyerror("Alignment offset must not be greater than alignment (%" PRIu16 " < %u)", error("Alignment offset must not be greater than alignment (%" PRIu16 " < %u)\n",
alignOffset, 1U << alignment); alignOffset, 1U << alignment);
alignOffset = 0; alignOffset = 0;
} }
@@ -130,18 +130,19 @@ static struct Section *getSection(char const *name, enum SectionType type,
if (org != -1) { if (org != -1) {
if ((org - alignOffset) & mask) if ((org - alignOffset) & mask)
yyerror("Section \"%s\"'s fixed address doesn't match its alignment", error("Section \"%s\"'s fixed address doesn't match its alignment\n",
name); name);
alignment = 0; /* Ignore it if it's satisfied */ alignment = 0; /* Ignore it if it's satisfied */
} else if (startaddr[type] & mask) { } else if (startaddr[type] & mask) {
yyerror("Section \"%s\"'s alignment cannot be attained in %s", error("Section \"%s\"'s alignment cannot be attained in %s\n",
name, typeNames[type]); name, typeNames[type]);
} }
} }
if (org != -1) { if (org != -1) {
if (org < startaddr[type] || org > endaddr(type)) if (org < startaddr[type] || org > endaddr(type))
yyerror("Section \"%s\"'s fixed address %#" PRIx32 " is outside of range [%#" PRIx16 "; %#" PRIx16 "]", error("Section \"%s\"'s fixed address %#" PRIx32
" is outside of range [%#" PRIx16 "; %#" PRIx16 "]\n",
name, org, startaddr[type], endaddr(type)); name, org, startaddr[type], endaddr(type));
} }
@@ -154,16 +155,16 @@ static struct Section *getSection(char const *name, enum SectionType type,
unsigned int nbSectErrors = 0; unsigned int nbSectErrors = 0;
#define fail(...) \ #define fail(...) \
do { \ do { \
yyerror(__VA_ARGS__); \ error(__VA_ARGS__); \
nbSectErrors++; \ nbSectErrors++; \
} while (0) } while (0)
if (type != sect->type) if (type != sect->type)
fail("Section \"%s\" already exists but with type %s", fail("Section \"%s\" already exists but with type %s\n",
sect->name, typeNames[sect->type]); sect->name, typeNames[sect->type]);
if (sect->modifier != mod) if (sect->modifier != mod)
fail("Section \"%s\" already declared as %s section", fail("Section \"%s\" already declared as %s section\n",
sect->name, sectionModNames[sect->modifier]); sect->name, sectionModNames[sect->modifier]);
/* /*
* Normal sections need to have exactly identical constraints; * Normal sections need to have exactly identical constraints;
@@ -176,18 +177,18 @@ static struct Section *getSection(char const *name, enum SectionType type,
* `EndLoadSection` if modifying the following check! * `EndLoadSection` if modifying the following check!
*/ */
if (sect_HasData(type)) if (sect_HasData(type))
fail("Cannot declare ROM sections as UNION"); fail("Cannot declare ROM sections as UNION\n");
if (org != -1) { if (org != -1) {
/* If both are fixed, they must be the same */ /* If both are fixed, they must be the same */
if (sect->org != -1 && sect->org != org) if (sect->org != -1 && sect->org != org)
fail("Section \"%s\" already declared as fixed at different address $%" PRIx32, fail("Section \"%s\" already declared as fixed at different address $%"
PRIx32 "\n",
sect->name, sect->org); sect->name, sect->org);
else if (sect->align != 0 else if (sect->align != 0
&& (mask(sect->align) && (mask(sect->align)
& (org - sect->alignOfs))) & (org - sect->alignOfs)))
fail("Section \"%s\" already declared as aligned to %u bytes (offset %" PRIu16 ")", fail("Section \"%s\" already declared as aligned to %u bytes (offset %"
sect->name, 1U << sect->align, PRIu16 ")\n", sect->name, 1U << sect->align, sect->alignOfs);
sect->alignOfs);
else else
/* Otherwise, just override */ /* Otherwise, just override */
sect->org = org; sect->org = org;
@@ -196,16 +197,15 @@ static struct Section *getSection(char const *name, enum SectionType type,
if (sect->org != -1) { if (sect->org != -1) {
if ((sect->org - alignOffset) if ((sect->org - alignOffset)
& mask(alignment)) & mask(alignment))
fail("Section \"%s\" already declared as fixed at incompatible address $%" PRIx32, fail("Section \"%s\" already declared as fixed at incompatible address $%"
sect->name, PRIx32 "\n", sect->name, sect->org);
sect->org);
/* Check if alignment offsets are compatible */ /* Check if alignment offsets are compatible */
} else if ((alignOffset & mask(sect->align)) } else if ((alignOffset & mask(sect->align))
!= (sect->alignOfs != (sect->alignOfs
& mask(alignment))) { & mask(alignment))) {
fail("Section \"%s\" already declared with incompatible %" PRIu8 "-byte alignment (offset %" PRIu16 ")", fail("Section \"%s\" already declared with incompatible %"
sect->name, sect->align, PRIu8 "-byte alignment (offset %" PRIu16 ")\n",
sect->alignOfs); sect->name, sect->align, sect->alignOfs);
} else if (alignment > sect->align) { } else if (alignment > sect->align) {
/* /*
* If the section is not fixed, * If the section is not fixed,
@@ -220,42 +220,42 @@ static struct Section *getSection(char const *name, enum SectionType type,
sect->bank = bank; sect->bank = bank;
/* If both specify a bank, it must be the same one */ /* If both specify a bank, it must be the same one */
else if (bank != -1 && sect->bank != bank) else if (bank != -1 && sect->bank != bank)
fail("Section \"%s\" already declared with different bank %" PRIu32, fail("Section \"%s\" already declared with different bank %"
sect->name, sect->bank); PRIu32 "\n", sect->name, sect->bank);
} else { /* Section fragments are handled identically in RGBASM */ } else { /* Section fragments are handled identically in RGBASM */
/* However, concaternating non-fragments will be made an error */ /* However, concaternating non-fragments will be made an error */
if (sect->modifier != SECTION_FRAGMENT || mod != SECTION_FRAGMENT) if (sect->modifier != SECTION_FRAGMENT || mod != SECTION_FRAGMENT)
warning(WARNING_OBSOLETE, "Concatenation of non-fragment sections is deprecated"); warning(WARNING_OBSOLETE,
"Concatenation of non-fragment sections is deprecated\n");
if (org != sect->org) { if (org != sect->org) {
if (sect->org == -1) if (sect->org == -1)
fail("Section \"%s\" already declared as floating", fail("Section \"%s\" already declared as floating\n",
sect->name); sect->name);
else else
fail("Section \"%s\" already declared as fixed at $%" PRIx32, fail("Section \"%s\" already declared as fixed at $%"
sect->name, sect->org); PRIx32 "\n", sect->name, sect->org);
} }
if (bank != sect->bank) { if (bank != sect->bank) {
if (sect->bank == -1) if (sect->bank == -1)
fail("Section \"%s\" already declared as floating bank", fail("Section \"%s\" already declared as floating bank\n",
sect->name); sect->name);
else else
fail("Section \"%s\" already declared as fixed at bank %" PRIu32, fail("Section \"%s\" already declared as fixed at bank %"
sect->name, sect->bank); PRIu32 "\n", sect->name, sect->bank);
} }
if (alignment != sect->align) { if (alignment != sect->align) {
if (sect->align == 0) if (sect->align == 0)
fail("Section \"%s\" already declared as unaligned", fail("Section \"%s\" already declared as unaligned\n",
sect->name); sect->name);
else else
fail("Section \"%s\" already declared as aligned to %u bytes", fail("Section \"%s\" already declared as aligned to %u bytes\n",
sect->name, sect->name, 1U << sect->align);
1U << sect->align);
} }
} }
if (nbSectErrors) if (nbSectErrors)
fatalerror("Cannot create section \"%s\" (%u errors)", fatalerror("Cannot create section \"%s\" (%u errors)\n",
sect->name, nbSectErrors); sect->name, nbSectErrors);
#undef fail #undef fail
return sect; return sect;
@@ -263,11 +263,11 @@ static struct Section *getSection(char const *name, enum SectionType type,
sect = malloc(sizeof(*sect)); sect = malloc(sizeof(*sect));
if (sect == NULL) if (sect == NULL)
fatalerror("Not enough memory for section"); fatalerror("Not enough memory for section: %s\n", strerror(errno));
sect->name = strdup(name); sect->name = strdup(name);
if (sect->name == NULL) if (sect->name == NULL)
fatalerror("Not enough memory for sectionname"); fatalerror("Not enough memory for section name: %s\n", strerror(errno));
sect->type = type; sect->type = type;
sect->modifier = mod; sect->modifier = mod;
@@ -286,7 +286,7 @@ static struct Section *getSection(char const *name, enum SectionType type,
sectsize = maxsize[type]; sectsize = maxsize[type];
sect->data = malloc(sectsize); sect->data = malloc(sectsize);
if (sect->data == NULL) if (sect->data == NULL)
fatalerror("Not enough memory for section"); fatalerror("Not enough memory for section: %s\n", strerror(errno));
} else { } else {
sect->data = NULL; sect->data = NULL;
} }
@@ -307,7 +307,7 @@ static struct Section *getSection(char const *name, enum SectionType type,
static void changeSection(void) static void changeSection(void)
{ {
if (unionStack) if (unionStack)
fatalerror("Cannot change the section within a UNION"); fatalerror("Cannot change the section within a UNION\n");
sym_SetCurrentSymbolScope(NULL); sym_SetCurrentSymbolScope(NULL);
} }
@@ -319,7 +319,7 @@ void out_NewSection(char const *name, uint32_t type, uint32_t org,
struct SectionSpec const *attribs, enum SectionModifier mod) struct SectionSpec const *attribs, enum SectionModifier mod)
{ {
if (currentLoadSection) if (currentLoadSection)
fatalerror("Cannot change the section within a `LOAD` block"); fatalerror("Cannot change the section within a `LOAD` block\n");
struct Section *sect = getSection(name, type, org, attribs, mod); struct Section *sect = getSection(name, type, org, attribs, mod);
@@ -337,7 +337,7 @@ void out_SetLoadSection(char const *name, uint32_t type, uint32_t org,
checkcodesection(); checkcodesection();
if (currentLoadSection) if (currentLoadSection)
fatalerror("`LOAD` blocks cannot be nested"); fatalerror("`LOAD` blocks cannot be nested\n");
struct Section *sect = getSection(name, type, org, attribs, false); struct Section *sect = getSection(name, type, org, attribs, false);
@@ -350,7 +350,7 @@ void out_SetLoadSection(char const *name, uint32_t type, uint32_t org,
void out_EndLoadSection(void) void out_EndLoadSection(void)
{ {
if (!currentLoadSection) if (!currentLoadSection)
yyerror("Found `ENDL` outside of a `LOAD` block"); error("Found `ENDL` outside of a `LOAD` block\n");
currentLoadSection = NULL; currentLoadSection = NULL;
changeSection(); changeSection();
@@ -382,13 +382,13 @@ void sect_AlignPC(uint8_t alignment, uint16_t offset)
if (sect->org != -1) { if (sect->org != -1) {
if ((sym_GetPCValue() - offset) % (1 << alignment)) if ((sym_GetPCValue() - offset) % (1 << alignment))
yyerror("Section's fixed address fails required alignment (PC = $%04" PRIx32 ")", error("Section's fixed address fails required alignment (PC = $%04"
sym_GetPCValue()); PRIx32 ")\n", sym_GetPCValue());
} else if (sect->align != 0) { } else if (sect->align != 0) {
if ((((sect->alignOfs + curOffset) % (1 << sect->align)) if ((((sect->alignOfs + curOffset) % (1 << sect->align))
- offset) % (1 << alignment)) { - offset) % (1 << alignment)) {
yyerror("Section's alignment fails required alignment (offset from section start = $%04" PRIx32 ")", error("Section's alignment fails required alignment (offset from section start = $%04"
curOffset); PRIx32 ")\n", curOffset);
} else if (alignment > sect->align) { } else if (alignment > sect->align) {
sect->align = alignment; sect->align = alignment;
sect->alignOfs = sect->alignOfs =
@@ -438,13 +438,13 @@ static inline void createPatch(enum PatchType type,
void sect_StartUnion(void) void sect_StartUnion(void)
{ {
if (!pCurrentSection) if (!pCurrentSection)
fatalerror("UNIONs must be inside a SECTION"); fatalerror("UNIONs must be inside a SECTION\n");
if (sect_HasData(pCurrentSection->type)) if (sect_HasData(pCurrentSection->type))
fatalerror("Cannot use UNION inside of ROM0 or ROMX sections"); fatalerror("Cannot use UNION inside of ROM0 or ROMX sections\n");
struct UnionStackEntry *entry = malloc(sizeof(*entry)); struct UnionStackEntry *entry = malloc(sizeof(*entry));
if (!entry) if (!entry)
fatalerror("Failed to allocate new union stack entry: %s", strerror(errno)); fatalerror("Failed to allocate new union stack entry: %s\n", strerror(errno));
entry->start = curOffset; entry->start = curOffset;
entry->size = 0; entry->size = 0;
entry->next = unionStack; entry->next = unionStack;
@@ -463,14 +463,14 @@ static void endUnionMember(void)
void sect_NextUnionMember(void) void sect_NextUnionMember(void)
{ {
if (!unionStack) if (!unionStack)
fatalerror("Found NEXTU outside of a UNION construct"); fatalerror("Found NEXTU outside of a UNION construct\n");
endUnionMember(); endUnionMember();
} }
void sect_EndUnion(void) void sect_EndUnion(void)
{ {
if (!unionStack) if (!unionStack)
fatalerror("Found ENDU outside of a UNION construct"); fatalerror("Found ENDU outside of a UNION construct\n");
endUnionMember(); endUnionMember();
curOffset += unionStack->size; curOffset += unionStack->size;
struct UnionStackEntry *next = unionStack->next; struct UnionStackEntry *next = unionStack->next;
@@ -482,7 +482,7 @@ void sect_EndUnion(void)
void sect_CheckUnionClosed(void) void sect_CheckUnionClosed(void)
{ {
if (unionStack) if (unionStack)
fatalerror("Unterminated UNION construct!"); fatalerror("Unterminated UNION construct!\n");
} }
/* /*
@@ -514,7 +514,7 @@ void out_Skip(int32_t skip, bool ds)
reserveSpace(skip); reserveSpace(skip);
if (!ds && sect_HasData(pCurrentSection->type)) if (!ds && sect_HasData(pCurrentSection->type))
warning(WARNING_EMPTY_DATA_DIRECTIVE, "db/dw/dl directive without data in ROM"); warning(WARNING_EMPTY_DATA_DIRECTIVE, "db/dw/dl directive without data in ROM\n");
if (!sect_HasData(pCurrentSection->type)) { if (!sect_HasData(pCurrentSection->type)) {
growSection(skip); growSection(skip);
@@ -636,7 +636,7 @@ void out_PCRelByte(struct Expression *expr)
offset = sym_GetValue(sym) - (sym_GetValue(pc) + 1); offset = sym_GetValue(sym) - (sym_GetValue(pc) + 1);
if (offset < -128 || offset > 127) { if (offset < -128 || offset > 127) {
yyerror("jr target out of reach (expected -129 < %" PRId16 " < 128)", error("jr target out of reach (expected -129 < %" PRId16 " < 128)\n",
offset); offset);
writebyte(0); writebyte(0);
} else { } else {
@@ -652,8 +652,7 @@ void out_PCRelByte(struct Expression *expr)
void out_BinaryFile(char const *s, int32_t startPos) void out_BinaryFile(char const *s, int32_t startPos)
{ {
if (startPos < 0) { if (startPos < 0) {
yyerror("Start position cannot be negative (%" PRId32 ")", error("Start position cannot be negative (%" PRId32 ")\n", startPos);
startPos);
startPos = 0; startPos = 0;
} }
@@ -664,8 +663,7 @@ void out_BinaryFile(char const *s, int32_t startPos)
oFailedOnMissingInclude = true; oFailedOnMissingInclude = true;
return; return;
} }
fatalerror("Error opening INCBIN file '%s': %s", s, fatalerror("Error opening INCBIN file '%s': %s\n", s, strerror(errno));
strerror(errno));
} }
int32_t fsize = -1; int32_t fsize = -1;
@@ -676,7 +674,7 @@ void out_BinaryFile(char const *s, int32_t startPos)
fsize = ftell(f); fsize = ftell(f);
if (startPos >= fsize) { if (startPos >= fsize) {
yyerror("Specified start position is greater than length of file"); error("Specified start position is greater than length of file\n");
return; return;
} }
@@ -684,7 +682,7 @@ void out_BinaryFile(char const *s, int32_t startPos)
reserveSpace(fsize - startPos); reserveSpace(fsize - startPos);
} else { } else {
if (errno != ESPIPE) if (errno != ESPIPE)
yyerror("Error determining size of INCBIN file '%s': %s", error("Error determining size of INCBIN file '%s': %s\n",
s, strerror(errno)); s, strerror(errno));
/* The file isn't seekable, so we'll just skip bytes */ /* The file isn't seekable, so we'll just skip bytes */
while (startPos--) while (startPos--)
@@ -698,8 +696,7 @@ void out_BinaryFile(char const *s, int32_t startPos)
} }
if (ferror(f)) if (ferror(f))
yyerror("Error reading INCBIN file '%s': %s", s, error("Error reading INCBIN file '%s': %s\n", s, strerror(errno));
strerror(errno));
fclose(f); fclose(f);
} }
@@ -707,14 +704,12 @@ void out_BinaryFile(char const *s, int32_t startPos)
void out_BinaryFileSlice(char const *s, int32_t start_pos, int32_t length) void out_BinaryFileSlice(char const *s, int32_t start_pos, int32_t length)
{ {
if (start_pos < 0) { if (start_pos < 0) {
yyerror("Start position cannot be negative (%" PRId32 ")", error("Start position cannot be negative (%" PRId32 ")\n", start_pos);
start_pos);
start_pos = 0; start_pos = 0;
} }
if (length < 0) { if (length < 0) {
yyerror("Number of bytes to read cannot be negative (%" PRId32 ")", error("Number of bytes to read cannot be negative (%" PRId32 ")\n", length);
length);
length = 0; length = 0;
} }
if (length == 0) /* Don't even bother with 0-byte slices */ if (length == 0) /* Don't even bother with 0-byte slices */
@@ -727,8 +722,7 @@ void out_BinaryFileSlice(char const *s, int32_t start_pos, int32_t length)
oFailedOnMissingInclude = true; oFailedOnMissingInclude = true;
return; return;
} }
fatalerror("Error opening INCBIN file '%s': %s", s, fatalerror("Error opening INCBIN file '%s': %s\n", s, strerror(errno));
strerror(errno));
} }
checkcodesection(); checkcodesection();
@@ -740,17 +734,17 @@ void out_BinaryFileSlice(char const *s, int32_t start_pos, int32_t length)
fsize = ftell(f); fsize = ftell(f);
if (start_pos >= fsize) { if (start_pos >= fsize) {
yyerror("Specified start position is greater than length of file"); error("Specified start position is greater than length of file\n");
return; return;
} }
if ((start_pos + length) > fsize) if ((start_pos + length) > fsize)
fatalerror("Specified range in INCBIN is out of bounds"); fatalerror("Specified range in INCBIN is out of bounds\n");
fseek(f, start_pos, SEEK_SET); fseek(f, start_pos, SEEK_SET);
} else { } else {
if (errno != ESPIPE) if (errno != ESPIPE)
yyerror("Error determining size of INCBIN file '%s': %s", error("Error determining size of INCBIN file '%s': %s\n",
s, strerror(errno)); s, strerror(errno));
/* The file isn't seekable, so we'll just skip bytes */ /* The file isn't seekable, so we'll just skip bytes */
while (start_pos--) while (start_pos--)
@@ -765,10 +759,9 @@ void out_BinaryFileSlice(char const *s, int32_t start_pos, int32_t length)
if (byte != EOF) { if (byte != EOF) {
writebyte(byte); writebyte(byte);
} else if (ferror(f)) { } else if (ferror(f)) {
yyerror("Error reading INCBIN file '%s': %s", s, error("Error reading INCBIN file '%s': %s\n", s, strerror(errno));
strerror(errno));
} else { } else {
yyerror("Premature end of file (%" PRId32 " bytes left to read)", error("Premature end of file (%" PRId32 " bytes left to read)\n",
todo + 1); todo + 1);
} }
} }
@@ -785,7 +778,7 @@ void out_PushSection(void)
sect = malloc(sizeof(struct SectionStackEntry)); sect = malloc(sizeof(struct SectionStackEntry));
if (sect == NULL) if (sect == NULL)
fatalerror("No memory for section stack"); fatalerror("No memory for section stack: %s<\n", strerror(errno));
sect->pSection = pCurrentSection; sect->pSection = pCurrentSection;
sect->pScope = sym_GetCurrentSymbolScope(); sect->pScope = sym_GetCurrentSymbolScope();
@@ -798,10 +791,10 @@ void out_PushSection(void)
void out_PopSection(void) void out_PopSection(void)
{ {
if (pSectionStack == NULL) if (pSectionStack == NULL)
fatalerror("No entries in the section stack"); fatalerror("No entries in the section stack\n");
if (currentLoadSection) if (currentLoadSection)
fatalerror("Cannot change the section within a `LOAD` block!"); fatalerror("Cannot change the section within a `LOAD` block!\n");
struct SectionStackEntry *sect; struct SectionStackEntry *sect;

View File

@@ -114,8 +114,7 @@ static void updateSymbolFilename(struct Symbol *sym)
{ {
if (snprintf(sym->fileName, _MAX_PATH + 1, "%s", if (snprintf(sym->fileName, _MAX_PATH + 1, "%s",
tzCurrentFileName) > _MAX_PATH) tzCurrentFileName) > _MAX_PATH)
fatalerror("%s: File name is too long: '%s'", __func__, fatalerror("%s: File name is too long: '%s'\n", __func__, tzCurrentFileName);
tzCurrentFileName);
sym->fileLine = fstk_GetLine(); sym->fileLine = fstk_GetLine();
} }
@@ -127,10 +126,10 @@ static struct Symbol *createsymbol(char const *s)
struct Symbol *symbol = malloc(sizeof(*symbol)); struct Symbol *symbol = malloc(sizeof(*symbol));
if (!symbol) if (!symbol)
fatalerror("Failed to create symbol: %s", strerror(errno)); fatalerror("Failed to create symbol '%s': %s\n", s, strerror(errno));
if (snprintf(symbol->name, MAXSYMLEN + 1, "%s", s) > MAXSYMLEN) if (snprintf(symbol->name, MAXSYMLEN + 1, "%s", s) > MAXSYMLEN)
warning(WARNING_LONG_STR, "Symbol name is too long: '%s'", s); warning(WARNING_LONG_STR, "Symbol name is too long: '%s'\n", s);
symbol->isExported = false; symbol->isExported = false;
symbol->isBuiltin = false; symbol->isBuiltin = false;
@@ -155,8 +154,7 @@ static void fullSymbolName(char *output, size_t outputSize,
int n = snprintf(output, outputSize, "%s%s", parent->name, localName); int n = snprintf(output, outputSize, "%s%s", parent->name, localName);
if (n >= (int)outputSize) if (n >= (int)outputSize)
fatalerror("Symbol name is too long: '%s%s'", parent->name, fatalerror("Symbol name is too long: '%s%s'\n", parent->name, localName);
localName);
} }
/* /*
@@ -174,8 +172,7 @@ static struct Symbol *findsymbol(char const *s, struct Symbol const *scope)
char const *separator = strchr(s, '.'); char const *separator = strchr(s, '.');
if (separator && strchr(separator + 1, '.')) if (separator && strchr(separator + 1, '.'))
fatalerror("'%s' is a nonsensical reference to a nested local symbol", fatalerror("'%s' is a nonsensical reference to a nested local symbol\n", s);
s);
return hash_GetElement(symbols, s); return hash_GetElement(symbols, s);
} }
@@ -202,12 +199,11 @@ void sym_Purge(char const *symName)
struct Symbol *symbol = findsymbol(symName, scope); struct Symbol *symbol = findsymbol(symName, scope);
if (!symbol) { if (!symbol) {
yyerror("'%s' not defined", symName); error("'%s' not defined\n", symName);
} else if (symbol->isBuiltin) { } else if (symbol->isBuiltin) {
yyerror("Built-in symbol '%s' cannot be purged", symName); error("Built-in symbol '%s' cannot be purged\n", symName);
} else if (isReferenced(symbol)) { } else if (isReferenced(symbol)) {
yyerror("Symbol \"%s\" is referenced and thus cannot be purged", error("Symbol \"%s\" is referenced and thus cannot be purged\n", symName);
symName);
} else { } else {
hash_RemoveElement(symbols, symbol->name); hash_RemoveElement(symbols, symbol->name);
if (symbol->type == SYM_MACRO) if (symbol->type == SYM_MACRO)
@@ -221,9 +217,9 @@ uint32_t sym_GetPCValue(void)
struct Section const *sect = sect_GetSymbolSection(); struct Section const *sect = sect_GetSymbolSection();
if (!sect) if (!sect)
yyerror("PC has no value outside a section"); error("PC has no value outside a section\n");
else if (sect->org == -1) else if (sect->org == -1)
yyerror("Expected constant PC but section is not fixed"); error("Expected constant PC but section is not fixed\n");
else else
return CallbackPC(); return CallbackPC();
return 0; return 0;
@@ -237,11 +233,11 @@ uint32_t sym_GetConstantValue(char const *s)
struct Symbol const *sym = sym_FindSymbol(s); struct Symbol const *sym = sym_FindSymbol(s);
if (sym == NULL) if (sym == NULL)
yyerror("'%s' not defined", s); error("'%s' not defined\n", s);
else if (sym == PCSymbol) else if (sym == PCSymbol)
return sym_GetPCValue(); return sym_GetPCValue();
else if (!sym_IsConstant(sym)) else if (!sym_IsConstant(sym))
yyerror("\"%s\" does not have a constant value", s); error("\"%s\" does not have a constant value\n", s);
else else
return sym_GetValue(sym); return sym_GetValue(sym);
@@ -256,9 +252,9 @@ uint32_t sym_GetDefinedValue(char const *s)
struct Symbol const *sym = sym_FindSymbol(s); struct Symbol const *sym = sym_FindSymbol(s);
if (sym == NULL || !sym_IsDefined(sym)) if (sym == NULL || !sym_IsDefined(sym))
yyerror("'%s' not defined", s); error("'%s' not defined\n", s);
else if (!sym_IsNumeric(sym)) else if (!sym_IsNumeric(sym))
yyerror("'%s' is a macro or string symbol", s); error("'%s' is a macro or string symbol\n", s);
else else
return sym_GetValue(sym); return sym_GetValue(sym);
@@ -287,7 +283,7 @@ static struct Symbol *createNonrelocSymbol(char const *symbolName)
if (!symbol) if (!symbol)
symbol = createsymbol(symbolName); symbol = createsymbol(symbolName);
else if (sym_IsDefined(symbol)) else if (sym_IsDefined(symbol))
yyerror("'%s' already defined at %s(%" PRIu32 ")", symbolName, error("'%s' already defined at %s(%" PRIu32 ")\n", symbolName,
symbol->fileName, symbol->fileLine); symbol->fileName, symbol->fileLine);
return symbol; return symbol;
@@ -326,7 +322,7 @@ struct Symbol *sym_AddString(char const *symName, char const *value)
char *string = malloc(len + 1); char *string = malloc(len + 1);
if (string == NULL) if (string == NULL)
fatalerror("No memory for string equate"); fatalerror("No memory for string equate: %s\n", strerror(errno));
strcpy(string, value); strcpy(string, value);
sym->type = SYM_EQUS; sym->type = SYM_EQUS;
@@ -347,7 +343,7 @@ struct Symbol *sym_AddSet(char const *symName, int32_t value)
if (sym == NULL) if (sym == NULL)
sym = createsymbol(symName); sym = createsymbol(symName);
else if (sym_IsDefined(sym) && sym->type != SYM_SET) else if (sym_IsDefined(sym) && sym->type != SYM_SET)
yyerror("'%s' already defined as %s at %s(%" PRIu32 ")", error("'%s' already defined as %s at %s(%" PRIu32 ")\n",
symName, sym->type == SYM_LABEL ? "label" : "constant", symName, sym->type == SYM_LABEL ? "label" : "constant",
sym->fileName, sym->fileLine); sym->fileName, sym->fileLine);
else else
@@ -367,7 +363,7 @@ struct Symbol *sym_AddSet(char const *symName, int32_t value)
struct Symbol *sym_AddLocalReloc(char const *symName) struct Symbol *sym_AddLocalReloc(char const *symName)
{ {
if (!symbolScope) { if (!symbolScope) {
yyerror("Local label '%s' in main scope", symName); error("Local label '%s' in main scope\n", symName);
return NULL; return NULL;
} }
@@ -387,7 +383,7 @@ struct Symbol *sym_AddReloc(char const *symName)
if (localPtr != NULL) { if (localPtr != NULL) {
if (!symbolScope) { if (!symbolScope) {
yyerror("Local label in main scope"); error("Local label in main scope\n");
return NULL; return NULL;
} }
@@ -395,12 +391,11 @@ struct Symbol *sym_AddReloc(char const *symName)
uint32_t parentLen = localPtr - symName; uint32_t parentLen = localPtr - symName;
if (strchr(localPtr + 1, '.') != NULL) if (strchr(localPtr + 1, '.') != NULL)
fatalerror("'%s' is a nonsensical reference to a nested local symbol", fatalerror("'%s' is a nonsensical reference to a nested local symbol\n",
symName); symName);
else if (strlen(scope->name) != parentLen else if (strlen(scope->name) != parentLen
|| strncmp(symName, scope->name, parentLen) != 0) || strncmp(symName, scope->name, parentLen) != 0)
yyerror("Not currently in the scope of '%.*s'", error("Not currently in the scope of '%.*s'\n", parentLen, symName);
parentLen, symName);
} }
struct Symbol *sym = findsymbol(symName, scope); struct Symbol *sym = findsymbol(symName, scope);
@@ -408,8 +403,8 @@ struct Symbol *sym_AddReloc(char const *symName)
if (!sym) if (!sym)
sym = createsymbol(symName); sym = createsymbol(symName);
else if (sym_IsDefined(sym)) else if (sym_IsDefined(sym))
yyerror("'%s' already defined in %s(%" PRIu32 ")", symName, error("'%s' already defined in %s(%" PRIu32 ")\n",
sym->fileName, sym->fileLine); symName, sym->fileName, sym->fileLine);
/* If the symbol already exists as a ref, just "take over" it */ /* If the symbol already exists as a ref, just "take over" it */
sym->type = SYM_LABEL; sym->type = SYM_LABEL;
@@ -423,8 +418,7 @@ struct Symbol *sym_AddReloc(char const *symName)
sym->section = sect_GetSymbolSection(); sym->section = sect_GetSymbolSection();
/* Labels need to be assigned a section, except PC */ /* Labels need to be assigned a section, except PC */
if (!sym->section && strcmp(symName, "@")) if (!sym->section && strcmp(symName, "@"))
yyerror("Label \"%s\" created outside of a SECTION", error("Label \"%s\" created outside of a SECTION\n", symName);
symName);
updateSymbolFilename(sym); updateSymbolFilename(sym);
@@ -481,12 +475,9 @@ struct Symbol *sym_Ref(char const *symName)
if (symName[0] == '.') { if (symName[0] == '.') {
if (!symbolScope) if (!symbolScope)
fatalerror("Local label reference '%s' in main scope", fatalerror("Local label reference '%s' in main scope\n", symName);
symName); scope = symbolScope->scope ? symbolScope->scope : symbolScope;
scope = symbolScope->scope ? symbolScope->scope fullSymbolName(fullname, sizeof(fullname), symName, symbolScope);
: symbolScope;
fullSymbolName(fullname, sizeof(fullname), symName,
symbolScope);
symName = fullname; symName = fullname;
} }

View File

@@ -35,7 +35,7 @@ int32_t readUTF8Char(char *dest, char *src)
for (i = 0, state = 0;; i++) { for (i = 0, state = 0;; i++) {
if (decode(&state, &codep, (uint8_t)src[i]) == 1) if (decode(&state, &codep, (uint8_t)src[i]) == 1)
fatalerror("invalid UTF-8 character"); fatalerror("invalid UTF-8 character\n");
dest[i] = src[i]; dest[i] = src[i];

View File

@@ -201,12 +201,11 @@ void verror(const char *fmt, va_list args, char const *flag)
fstk_Dump(); fstk_Dump();
fprintf(stderr, flag ? ": [-Werror=%s]\n " : ":\n ", flag); fprintf(stderr, flag ? ": [-Werror=%s]\n " : ":\n ", flag);
vfprintf(stderr, fmt, args); vfprintf(stderr, fmt, args);
fputc('\n', stderr);
fstk_DumpStringExpansions(); fstk_DumpStringExpansions();
nbErrors++; nbErrors++;
} }
void yyerror(const char *fmt, ...) void error(const char *fmt, ...)
{ {
va_list args; va_list args;
@@ -254,7 +253,6 @@ void warning(enum WarningID id, char const *fmt, ...)
fstk_Dump(); fstk_Dump();
fprintf(stderr, ": [-W%s]\n ", flag); fprintf(stderr, ": [-W%s]\n ", flag);
vfprintf(stderr, fmt, args); vfprintf(stderr, fmt, args);
fputc('\n', stderr);
fstk_DumpStringExpansions(); fstk_DumpStringExpansions();
va_end(args); va_end(args);

View File

@@ -1,7 +1,7 @@
warning: overflow.asm(24): [-Wdiv] warning: overflow.asm(24): [-Wdiv]
Division of min value by -1 Division of -2147483648 by -1 yields -2147483648
warning: overflow.asm(25): [-Wdiv] warning: overflow.asm(25): [-Wdiv]
Division of min value by -1 Division of -2147483648 by -1 yields -2147483648
warning: overflow.asm(39): [-Wlarge-constant] warning: overflow.asm(39): [-Wlarge-constant]
Integer constant '4294967296' is too large Integer constant '4294967296' is too large
warning: overflow.asm(42): [-Wlarge-constant] warning: overflow.asm(42): [-Wlarge-constant]