mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-20 10:12:06 +00:00
Improve error messages.
This commit is contained in:
@@ -19,8 +19,8 @@ extern void opt_Push(void);
|
||||
extern void opt_Pop(void);
|
||||
extern void opt_Parse(char *s);
|
||||
|
||||
void fatalerror(char *s);
|
||||
void yyerror(char *s);
|
||||
void fatalerror(const char *fmt, ...);
|
||||
void yyerror(const char *fmt, ...);
|
||||
|
||||
extern char temptext[1024];
|
||||
|
||||
|
||||
@@ -163,7 +163,7 @@ yywrap(void)
|
||||
/*
|
||||
* RGBAsm - FSTACK.C (FileStack routines)
|
||||
*
|
||||
* Dump the context stack to stdout
|
||||
* Dump the context stack to stderr
|
||||
*
|
||||
*/
|
||||
|
||||
@@ -175,11 +175,12 @@ fstk_Dump(void)
|
||||
pLastFile = pFileStack;
|
||||
|
||||
while (pLastFile) {
|
||||
printf("%s(%ld) -> ", pLastFile->tzFileName, pLastFile->nLine);
|
||||
fprintf(stderr, "%s(%ld) -> ", pLastFile->tzFileName,
|
||||
pLastFile->nLine);
|
||||
pLastFile = pLastFile->pNext;
|
||||
}
|
||||
|
||||
printf("%s(%ld)", tzCurrentFileName, nLineNo);
|
||||
fprintf(stderr, "%s(%ld)", tzCurrentFileName, nLineNo);
|
||||
}
|
||||
/*
|
||||
* RGBAsm - FSTACK.C (FileStack routines)
|
||||
@@ -326,7 +327,7 @@ fstk_RunString(char *s)
|
||||
yy_scan_bytes(pSym->pMacro, strlen(pSym->pMacro));
|
||||
yy_switch_to_buffer(CurrentFlexHandle);
|
||||
} else
|
||||
yyerror("No such string symbol");
|
||||
yyerror("No such string symbol '%s'", s);
|
||||
}
|
||||
/*
|
||||
* RGBAsm - FSTACK.C (FileStack routines)
|
||||
|
||||
@@ -8,7 +8,7 @@ section:
|
||||
if( $6>=0 && $6<0x10000 )
|
||||
out_NewAbsSection($2,$4,$6,-1);
|
||||
else
|
||||
yyerror( "Address must be 16-bit" );
|
||||
yyerror("Address $%x not 16-bit", $6);
|
||||
}
|
||||
| T_POP_SECTION string ',' sectiontype ',' T_OP_BANK '[' const ']'
|
||||
{
|
||||
@@ -16,7 +16,7 @@ section:
|
||||
if( $8>=1 && $8<=0x1ff )
|
||||
out_NewAbsSection($2,$4,-1,$8);
|
||||
else
|
||||
yyerror( "BANK value out of range" );
|
||||
yyerror("ROM bank value $%x out of range (1 to $1ff)", $8);
|
||||
} else
|
||||
yyerror("BANK only allowed for CODE/DATA");
|
||||
}
|
||||
@@ -27,9 +27,9 @@ section:
|
||||
if( $11>=1 && $11<=0x1ff )
|
||||
out_NewAbsSection($2,$4,$6,$11);
|
||||
else
|
||||
yyerror( "BANK value out of range" );
|
||||
yyerror("ROM bank value $%x out of range (1 to $1ff)", 8);
|
||||
} else
|
||||
yyerror( "Address must be 16-bit" );
|
||||
yyerror("Address $%x not 16-bit", $6);
|
||||
} else
|
||||
yyerror("BANK only allowed for CODE/DATA");
|
||||
}
|
||||
@@ -196,7 +196,7 @@ z80_ldio : T_Z80_LDIO T_MODE_A comma op_mem_ind
|
||||
if( (!rpn_isReloc(&$4))
|
||||
&& ($4.nVal<0 || ($4.nVal>0xFF && $4.nVal<0xFF00) || $4.nVal>0xFFFF) )
|
||||
{
|
||||
yyerror( "Source must be in the IO/HRAM area" );
|
||||
yyerror("Source address $%x not in HRAM ($FF00 to $FFFE)", $4.nVal);
|
||||
}
|
||||
|
||||
out_AbsByte(0xF0);
|
||||
@@ -210,7 +210,7 @@ z80_ldio : T_Z80_LDIO T_MODE_A comma op_mem_ind
|
||||
if( (!rpn_isReloc(&$2))
|
||||
&& ($2.nVal<0 || ($2.nVal>0xFF && $2.nVal<0xFF00) || $2.nVal>0xFFFF) )
|
||||
{
|
||||
yyerror( "Destination must be in the IO/HRAM area" );
|
||||
yyerror("Destination address $%x not in HRAM ($FF00 to $FFFE)", $2.nVal);
|
||||
}
|
||||
|
||||
out_AbsByte(0xE0);
|
||||
@@ -271,7 +271,7 @@ z80_ld_r : T_Z80_LD reg_r comma const_8bit
|
||||
{
|
||||
if( ($2==REG_HL_IND) && ($4==REG_HL_IND) )
|
||||
{
|
||||
yyerror( "LD (HL),(HL) not allowed" );
|
||||
yyerror("LD [HL],[HL] not a valid instruction");
|
||||
}
|
||||
else
|
||||
out_AbsByte(0x40|($2<<3)|$4);
|
||||
@@ -394,7 +394,7 @@ z80_rst : T_Z80_RST const_8bit
|
||||
}
|
||||
else if( ($2.nVal&0x38)!=$2.nVal )
|
||||
{
|
||||
yyerror( "Invalid address for RST" );
|
||||
yyerror("Invalid address $%x for RST", $2.nVal);
|
||||
}
|
||||
else
|
||||
out_AbsByte(0xC7|$2.nVal);
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
|
||||
#include <math.h>
|
||||
#include <getopt.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@@ -205,18 +206,26 @@ opt_Pop(void)
|
||||
*/
|
||||
|
||||
void
|
||||
yyerror(char *s)
|
||||
yyerror(const char *fmt, ...)
|
||||
{
|
||||
printf("*ERROR*\t");
|
||||
fprintf(stderr, "ERROR:\t");
|
||||
fstk_Dump();
|
||||
printf(" :\n\t%s\n", s);
|
||||
fprintf(stderr, " :\n\t");
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
vfprintf(stderr, fmt, args);
|
||||
va_end(args);
|
||||
fprintf(stderr, "\n");
|
||||
nErrors += 1;
|
||||
}
|
||||
|
||||
void
|
||||
fatalerror(char *s)
|
||||
fatalerror(const char *fmt, ...)
|
||||
{
|
||||
yyerror(s);
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
yyerror(fmt, args);
|
||||
va_end(args);
|
||||
exit(5);
|
||||
}
|
||||
/*
|
||||
|
||||
@@ -155,8 +155,7 @@ rpn_Bank(struct Expression * expr, char *tzSym)
|
||||
|
||||
psym = sym_FindSymbol(tzSym);
|
||||
if (nPass == 2 && psym == NULL) {
|
||||
sprintf(temptext, "'%s' not defined", tzSym);
|
||||
yyerror(temptext);
|
||||
yyerror("'%s' not defined", tzSym);
|
||||
}
|
||||
expr->isReloc = 1;
|
||||
pushbyte(expr, RPN_BANK);
|
||||
|
||||
@@ -217,8 +217,7 @@ sym_Purge(char *tzName)
|
||||
|
||||
free(pSym);
|
||||
} else {
|
||||
sprintf(temptext, "'%s' not defined", tzName);
|
||||
yyerror(temptext);
|
||||
yyerror("'%s' not defined", tzName);
|
||||
}
|
||||
}
|
||||
/*
|
||||
@@ -245,10 +244,8 @@ sym_isConstDefined(char *tzName)
|
||||
nType & (SYMF_EQU | SYMF_SET | SYMF_MACRO | SYMF_STRING)) {
|
||||
return (1);
|
||||
} else {
|
||||
sprintf(temptext,
|
||||
"'%s' is not allowed as argument to the DEF function",
|
||||
tzName);
|
||||
fatalerror(temptext);
|
||||
fatalerror("'%s' is not allowed as argument to the "
|
||||
"DEF function", tzName);
|
||||
}
|
||||
}
|
||||
return (0);
|
||||
@@ -309,8 +306,7 @@ sym_GetStringValue(char *tzSym)
|
||||
if ((pSym = sym_FindSymbol(tzSym)) != NULL)
|
||||
return (pSym->pMacro);
|
||||
else {
|
||||
sprintf(temptext, "Stringsymbol '%s' not defined", tzSym);
|
||||
yyerror(temptext);
|
||||
yyerror("Stringsymbol '%s' not defined", tzSym);
|
||||
}
|
||||
|
||||
return (NULL);
|
||||
@@ -339,8 +335,7 @@ sym_GetConstantValue(char *s)
|
||||
fatalerror("Expression must have a constant value");
|
||||
}
|
||||
} else {
|
||||
sprintf(temptext, "'%s' not defined", s);
|
||||
yyerror(temptext);
|
||||
yyerror("'%s' not defined", s);
|
||||
}
|
||||
|
||||
return (0);
|
||||
@@ -365,9 +360,7 @@ sym_GetValue(char *s)
|
||||
if ((psym = findsymbol(s, pscope)) != NULL) {
|
||||
if (psym->nType & SYMF_DEFINED) {
|
||||
if (psym->nType & (SYMF_MACRO | SYMF_STRING)) {
|
||||
sprintf(temptext,
|
||||
"'%s' is a macro or string symbol", s);
|
||||
yyerror(temptext);
|
||||
yyerror("'%s' is a macro or string symbol", s);
|
||||
}
|
||||
return (getvaluefield(psym));
|
||||
} else {
|
||||
@@ -375,8 +368,7 @@ sym_GetValue(char *s)
|
||||
/* 0x80 seems like a good default value... */
|
||||
return (0x80);
|
||||
} else {
|
||||
sprintf(temptext, "'%s' not defined", s);
|
||||
yyerror(temptext);
|
||||
yyerror("'%s' not defined", s);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@@ -384,8 +376,7 @@ sym_GetValue(char *s)
|
||||
createsymbol(s);
|
||||
return (0x80);
|
||||
} else {
|
||||
sprintf(temptext, "'%s' not defined", s);
|
||||
yyerror(temptext);
|
||||
yyerror("'%s' not defined", s);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -411,18 +402,14 @@ sym_GetDefinedValue(char *s)
|
||||
if ((psym = findsymbol(s, pscope)) != NULL) {
|
||||
if ((psym->nType & SYMF_DEFINED)) {
|
||||
if (psym->nType & (SYMF_MACRO | SYMF_STRING)) {
|
||||
sprintf(temptext,
|
||||
"'%s' is a macro or string symbol", s);
|
||||
yyerror(temptext);
|
||||
yyerror("'%s' is a macro or string symbol", s);
|
||||
}
|
||||
return (getvaluefield(psym));
|
||||
} else {
|
||||
sprintf(temptext, "'%s' not defined", s);
|
||||
yyerror(temptext);
|
||||
yyerror("'%s' not defined", s);
|
||||
}
|
||||
} else {
|
||||
sprintf(temptext, "'%s' not defined", s);
|
||||
yyerror(temptext);
|
||||
yyerror("'%s' not defined", s);
|
||||
}
|
||||
|
||||
return (0);
|
||||
@@ -558,9 +545,7 @@ sym_AddEqu(char *tzSym, SLONG value)
|
||||
|
||||
if ((nsym = findsymbol(tzSym, NULL)) != NULL) {
|
||||
if (nsym->nType & SYMF_DEFINED) {
|
||||
sprintf(temptext, "'%s' already defined",
|
||||
tzSym);
|
||||
yyerror(temptext);
|
||||
yyerror("'%s' already defined", tzSym);
|
||||
}
|
||||
} else
|
||||
nsym = createsymbol(tzSym);
|
||||
@@ -586,8 +571,7 @@ sym_AddString(char *tzSym, char *tzValue)
|
||||
|
||||
if ((nsym = findsymbol(tzSym, NULL)) != NULL) {
|
||||
if (nsym->nType & SYMF_DEFINED) {
|
||||
sprintf(temptext, "'%s' already defined", tzSym);
|
||||
yyerror(temptext);
|
||||
yyerror("'%s' already defined", tzSym);
|
||||
}
|
||||
} else
|
||||
nsym = createsymbol(tzSym);
|
||||
@@ -661,9 +645,7 @@ sym_AddLocalReloc(char *tzSym)
|
||||
if (pScope) {
|
||||
if ((nsym = findsymbol(tzSym, pScope)) != NULL) {
|
||||
if (nsym->nType & SYMF_DEFINED) {
|
||||
sprintf(temptext,
|
||||
"'%s' already defined", tzSym);
|
||||
yyerror(temptext);
|
||||
yyerror("'%s' already defined", tzSym);
|
||||
}
|
||||
} else
|
||||
nsym = createsymbol(tzSym);
|
||||
@@ -696,9 +678,7 @@ sym_AddReloc(char *tzSym)
|
||||
|
||||
if ((nsym = findsymbol(tzSym, NULL)) != NULL) {
|
||||
if (nsym->nType & SYMF_DEFINED) {
|
||||
sprintf(temptext, "'%s' already defined",
|
||||
tzSym);
|
||||
yyerror(temptext);
|
||||
yyerror("'%s' already defined", tzSym);
|
||||
}
|
||||
} else
|
||||
nsym = createsymbol(tzSym);
|
||||
@@ -739,8 +719,7 @@ sym_Export(char *tzSym)
|
||||
if (nsym->nType & SYMF_DEFINED)
|
||||
return;
|
||||
}
|
||||
sprintf(temptext, "'%s' not defined", tzSym);
|
||||
yyerror(temptext);
|
||||
yyerror("'%s' not defined", tzSym);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -759,8 +738,7 @@ sym_Import(char *tzSym)
|
||||
struct sSymbol *nsym;
|
||||
|
||||
if (findsymbol(tzSym, NULL)) {
|
||||
sprintf(temptext, "'%s' already defined", tzSym);
|
||||
yyerror(temptext);
|
||||
yyerror("'%s' already defined", tzSym);
|
||||
}
|
||||
if ((nsym = createsymbol(tzSym)) != NULL)
|
||||
nsym->nType |= SYMF_IMPORT;
|
||||
@@ -811,9 +789,7 @@ sym_AddMacro(char *tzSym)
|
||||
|
||||
if ((nsym = findsymbol(tzSym, NULL)) != NULL) {
|
||||
if (nsym->nType & SYMF_DEFINED) {
|
||||
sprintf(temptext, "'%s' already defined",
|
||||
tzSym);
|
||||
yyerror(temptext);
|
||||
yyerror("'%s' already defined", tzSym);
|
||||
}
|
||||
} else
|
||||
nsym = createsymbol(tzSym);
|
||||
|
||||
@@ -47,8 +47,7 @@ macro : T_ID
|
||||
|
||||
if( !fstk_RunMacro($1) )
|
||||
{
|
||||
fprintf(stderr, "Macro '%s' not defined", $1);
|
||||
yyerror( "No such macro" );
|
||||
yyerror("Macro '%s' not defined", $1);
|
||||
}
|
||||
}
|
||||
;
|
||||
@@ -138,11 +137,11 @@ pushs : T_POP_PUSHS
|
||||
;
|
||||
|
||||
fail : T_POP_FAIL string
|
||||
{ fatalerror($2); }
|
||||
{ fatalerror("%s", $2); }
|
||||
;
|
||||
|
||||
warn : T_POP_WARN string
|
||||
{ yyerror($2); }
|
||||
{ yyerror("%s", $2); }
|
||||
;
|
||||
|
||||
shift : T_POP_SHIFT
|
||||
@@ -268,8 +267,7 @@ include : T_POP_INCLUDE string
|
||||
{
|
||||
if( !fstk_RunInclude($2) )
|
||||
{
|
||||
fprintf(stderr, "Could not open file '%s' : %s\n", $2, strerror(errno));
|
||||
yyerror( "File not found" );
|
||||
yyerror("Could not open file '%s' : %s\n", $2, strerror(errno));
|
||||
}
|
||||
}
|
||||
;
|
||||
|
||||
Reference in New Issue
Block a user