/* */
/* */
/* (C) 2000-2003 Ullrich von Bassewitz */
-/* Wacholderweg 14 */
-/* D-70597 Stuttgart */
-/* EMail: uz@musoftware.de */
+/* Römerstraße 52 */
+/* D-70794 Filderstadt */
+/* EMail: uz@cc65.org */
/* */
/* */
/* This software is provided 'as-is', without any expressed or implied */
/* Check for stack overflow */
if (IfCount >= MAX_IFS) {
- Fatal (FAT_IF_NESTING);
+ Fatal ("Too many nested .IFs");
}
/* Alloc one element */
do {
IfDesc* D = GetCurrentIf();
if (D == 0) {
- Error (ERR_UNEXPECTED, ".ENDIF");
+ Error (" Unexpected .ENDIF");
Done = 1;
} else {
Done = (D->Flags & ifNeedTerm) != 0;
case TOK_ELSE:
D = GetCurrentIf ();
if (D == 0) {
- Error (ERR_UNEXPECTED, ".ELSE");
+ Error ("Unexpected .ELSE");
} else if (GetElse(D)) {
/* We already had a .ELSE ! */
- Error (ERR_DUPLICATE_ELSE);
+ Error ("Duplicate .ELSE");
} else {
/* Allow an .ELSE */
InvertIfCond (D);
case TOK_ELSEIF:
D = GetCurrentIf ();
if (D == 0) {
- Error (ERR_UNEXPECTED, ".ELSEIF");
+ Error ("Unexpected .ELSEIF");
} else if (GetElse(D)) {
/* We already had a .ELSE */
- Error (ERR_DUPLICATE_ELSE);
+ Error ("Duplicate .ELSE");
} else {
/* Handle as if there was an .ELSE first */
InvertIfCond (D);
}
/* Start of .if is in the file we're about to leave */
- PError (&D->Pos, ERR_OPEN_IF);
+ PError (&D->Pos, "Conditional assembly branch was never closed");
FreeIf ();
}
}
/* */
/* */
/* */
-/* (C) 2000-2001 Ullrich von Bassewitz */
-/* Wacholderweg 14 */
-/* D-70597 Stuttgart */
+/* (C) 2000-2003 Ullrich von Bassewitz */
+/* Römerstraße 52 */
+/* D-70794 Filderstadt */
/* EMail: uz@cc65.org */
/* */
/* */
/* Name */
if (Tok != TOK_STRCON) {
- ErrorSkip (ERR_STRCON_EXPECTED);
+ ErrorSkip ("String constant expected");
return;
}
strcpy (Name, SVal);
/* The name of the file follows */
if (Tok != TOK_STRCON) {
- ErrorSkip (ERR_STRCON_EXPECTED);
+ ErrorSkip ("String constant expected");
return;
}
/* Line number */
LineNum = ConstExpression ();
if (LineNum < 0) {
- ErrorSkip (ERR_RANGE);
+ ErrorSkip ("Line number is out of valid range");
return;
}
void DbgInfoSym (void)
/* Parse and handle SYM subcommand of the .dbg pseudo instruction */
{
- ErrorSkip (ERR_NOT_IMPLEMENTED);
+ ErrorSkip ("Not implemented");
}
/* */
/* */
/* (C) 1998-2003 Ullrich von Bassewitz */
-/* Römerstrasse 52 */
+/* Römerstraße 52 */
/* D-70794 Filderstadt */
/* EMail: uz@cc65.org */
/* */
/* [dir] or [dir],y */
NextTok ();
A->Expr = Expression ();
- Consume (TOK_RBRACK, ERR_RBRACK_EXPECTED);
+ Consume (TOK_RBRACK, "']' expected");
if (Tok == TOK_COMMA) {
/* [dir],y */
NextTok ();
- Consume (TOK_Y, ERR_Y_EXPECTED);
+ Consume (TOK_Y, "`Y' expected");
A->AddrModeSet = AM_DIR_IND_LONG_Y;
} else {
/* [dir] */
A->AddrModeSet = AM_STACK_REL_IND_Y;
ConsumeRParen ();
ConsumeComma ();
- Consume (TOK_Y, ERR_Y_EXPECTED);
+ Consume (TOK_Y, "`Y' expected");
} else {
- Error (ERR_SYNTAX);
+ Error ("Syntax error");
}
} else {
if (Tok == TOK_COMMA) {
/* (adr),y */
NextTok ();
- Consume (TOK_Y, ERR_Y_EXPECTED);
+ Consume (TOK_Y, "`Y' expected");
A->AddrModeSet = AM_DIR_IND_Y;
} else {
/* (adr) */
if (Tok == TOK_COMMA) {
/* bank.adr,x */
NextTok ();
- Consume (TOK_X, ERR_X_EXPECTED);
+ Consume (TOK_X, "`X' expected");
A->AddrModeSet = AM_ABS_LONG_X;
} else {
/* bank.adr */
break;
default:
- Error (ERR_SYNTAX);
+ Error ("Syntax error");
}
/* */
/* */
/* (C) 1998-2003 Ullrich von Bassewitz */
-/* Römerstrasse 52 */
+/* Römerstraße 52 */
/* D-70794 Filderstadt */
/* EMail: uz@cc65.org */
/* */
-void WarningMsg (const FilePos* Pos, unsigned WarnNum, va_list ap)
+void WarningMsg (const FilePos* Pos, unsigned Level, const char* Format, va_list ap)
/* Print warning message. */
{
- static const struct {
- unsigned char Level;
- const char* Msg;
- } Warnings [WARN_COUNT-1] = {
- { 2, "Symbol `%s' is defined but never used" },
- { 2, "Symbol `%s' is imported but never used" },
- { 1, "Cannot track processor status byte" },
- { 1, "Suspicious address expression" },
- { 0, "Unnamed .PROCs are deprecated, please use .SCOPE" },
- { 1, "Address size mismatch for symbol `%s'" },
- { 0, "User warning: %s" },
- };
-
- if (Warnings [WarnNum-1].Level <= WarnLevel) {
- fprintf (stderr, "%s(%lu): Warning #%u: ",
- GetFileName (Pos->Name), Pos->Line, WarnNum);
- vfprintf (stderr, Warnings [WarnNum-1].Msg, ap);
+ if (Level <= WarnLevel) {
+ fprintf (stderr, "%s(%lu): Warning: ",
+ GetFileName (Pos->Name), Pos->Line);
+ vfprintf (stderr, Format, ap);
fprintf (stderr, "\n");
++WarningCount;
}
-void Warning (unsigned WarnNum, ...)
+void Warning (unsigned Level, const char* Format, ...)
/* Print warning message. */
{
va_list ap;
- va_start (ap, WarnNum);
- WarningMsg (&CurPos, WarnNum, ap);
+ va_start (ap, Format);
+ WarningMsg (&CurPos, Level, Format, ap);
va_end (ap);
}
-void PWarning (const FilePos* Pos, unsigned WarnNum, ...)
+void PWarning (const FilePos* Pos, unsigned Level, const char* Format, ...)
/* Print warning message giving an explicit file and position. */
{
va_list ap;
- va_start (ap, WarnNum);
- WarningMsg (Pos, WarnNum, ap);
+ va_start (ap, Format);
+ WarningMsg (Pos, Level, Format, ap);
va_end (ap);
}
-void ErrorMsg (const FilePos* Pos, unsigned ErrNum, va_list ap)
+void ErrorMsg (const FilePos* Pos, const char* Format, va_list ap)
/* Print an error message */
{
- static const char* Msgs [ERR_COUNT-1] = {
- "Command/operation not implemented",
- "Cannot open include file `%s': %s",
- "Cannot read from include file `%s': %s",
- "Include nesting too deep",
- "Invalid input character: %02X",
- "Hex digit expected",
- "Digit expected",
- "`0' or `1' expected",
- "Numerical overflow",
- "Control statement expected",
- "Too many characters",
- "`:' expected",
- "`(' expected",
- "`)' expected",
- "`]' expected",
- "`,' expected",
- "Boolean switch value expected (on/off/+/-)",
- "`Y' expected",
- "`X' expected",
- "Integer constant expected",
- "String constant expected",
- "Character constant expected",
- "Constant expression expected",
- "Identifier expected",
- "`.ENDMACRO' expected",
- "Option key expected",
- "`=' expected",
- "Address size specifier expected",
- "Command is only valid in 65816 mode",
- "User error: %s",
- "String constant too long",
- "Newline in string constant",
- "Illegal character constant",
- "Illegal addressing mode",
- "Illegal character to start local symbols",
- "Illegal use of local symbol",
- "Illegal segment name: `%s'",
- "Illegal macro package name",
- "Illegal emulation feature",
- "Illegal scope specifier",
- "Illegal assert action",
- "Syntax error",
- "Symbol `%s' is already defined",
- "Undefined symbol `%s'",
- "Symbol `%s' is already marked as import",
- "Symbol `%s' is already marked as export",
- "Exported symbol `%s' is undefined",
- "Exported values must be constant",
- "Unexpected end of file",
- "Unexpected end of line",
- "Unexpected `%s'",
- "Division by zero",
- "Modulo operation with zero",
- "Range error",
- "Too many macro parameters",
- "Macro parameter expected",
- "Circular reference in symbol definition",
- "Symbol `%s' redeclaration mismatch",
- "Address size mismatch for symbol `%s'",
- "Alignment value must be a power of 2",
- "Duplicate `.ELSE'",
- "Conditional assembly branch was never closed",
- "Lexical level was not terminated correctly",
- "No open lexical level",
- "Segment attribute mismatch",
- "Segment stack overflow",
- "Segment stack is empty",
- "Segment stack is not empty at end of assembly",
- "CPU not supported",
- "Counter underflow",
- "Undefined label",
- "Open `%s'",
- "File name `%s' not found in file table",
- };
-
- fprintf (stderr, "%s(%lu): Error #%u: ",
- GetFileName (Pos->Name), Pos->Line, ErrNum);
- vfprintf (stderr, Msgs [ErrNum-1], ap);
+ fprintf (stderr, "%s(%lu): Error: ",
+ GetFileName (Pos->Name), Pos->Line);
+ vfprintf (stderr, Format, ap);
fprintf (stderr, "\n");
++ErrorCount;
}
-void Error (unsigned ErrNum, ...)
+void Error (const char* Format, ...)
/* Print an error message */
{
va_list ap;
- va_start (ap, ErrNum);
- ErrorMsg (&CurPos, ErrNum, ap);
+ va_start (ap, Format);
+ ErrorMsg (&CurPos, Format, ap);
va_end (ap);
}
-void PError (const FilePos* Pos, unsigned ErrNum, ...)
+void PError (const FilePos* Pos, const char* Format, ...)
/* Print an error message giving an explicit file and position. */
{
va_list ap;
- va_start (ap, ErrNum);
- ErrorMsg (Pos, ErrNum, ap);
+ va_start (ap, Format);
+ ErrorMsg (Pos, Format, ap);
va_end (ap);
}
-void ErrorSkip (unsigned ErrNum, ...)
+void ErrorSkip (const char* Format, ...)
/* Print an error message and skip the rest of the line */
{
va_list ap;
- va_start (ap, ErrNum);
- ErrorMsg (&CurPos, ErrNum, ap);
+ va_start (ap, Format);
+ ErrorMsg (&CurPos, Format, ap);
va_end (ap);
SkipUntilSep ();
-void Fatal (unsigned FatNum, ...)
+void Fatal (const char* Format, ...)
/* Print a message about a fatal error and die */
{
- static const char* Msgs [FAT_COUNT-1] = {
- "Maximum number of input files reached",
- "Out of memory",
- "Too many segments",
- "String too long",
- "Cannot open input file `%s': %s",
- "Cannot stat input file `%s': %s",
- "Cannot open output file `%s': %s",
- "Cannot write to output file `%s': %s",
- "Cannot open listing file: %s",
- "Cannot write to listing file: %s",
- "Cannot read from listing file: %s",
- "Too many nested constructs",
- ".IF nesting too deep",
- "Too many symbols",
- };
va_list ap;
- va_start (ap, FatNum);
- fprintf (stderr, "Fatal #%u: ", FatNum);
- vfprintf (stderr, Msgs [FatNum-1], ap);
+ va_start (ap, Format);
+ fprintf (stderr, "Fatal error: ");
+ vfprintf (stderr, Format, ap);
fprintf (stderr, "\n");
va_end (ap);
/* Print a message about an internal compiler error and die. */
{
va_list ap;
- va_start (ap, Format);
+ va_start (ap, Format);
fprintf (stderr, "Internal assembler error\n");
vfprintf (stderr, Format, ap);
va_end (ap);
-/* Warning numbers */
-enum Warnings {
- WARN_NONE, /* No warning */
- WARN_SYM_NOT_REFERENCED,
- WARN_IMPORT_NOT_REFERENCED,
- WARN_CANNOT_TRACK_STATUS,
- WARN_SUSPICIOUS_ADDREXPR,
- WARN_UNNAMED_PROC,
- WARN_ADDR_SIZE_MISMATCH,
- WARN_USER,
- WARN_COUNT /* Warning count */
-};
-
-/* Error numbers */
-enum Errors {
- ERR_NONE, /* No error */
- ERR_NOT_IMPLEMENTED, /* Command/operation not implemented */
- ERR_CANNOT_OPEN_INCLUDE,
- ERR_CANNOT_READ_INCLUDE,
- ERR_INCLUDE_NESTING,
- ERR_INVALID_CHAR,
- ERR_HEX_DIGIT_EXPECTED,
- ERR_DIGIT_EXPECTED,
- ERR_01_EXPECTED,
- ERR_NUM_OVERFLOW,
- ERR_PSEUDO_EXPECTED,
- ERR_TOO_MANY_CHARS,
- ERR_COLON_EXPECTED,
- ERR_LPAREN_EXPECTED,
- ERR_RPAREN_EXPECTED,
- ERR_RBRACK_EXPECTED,
- ERR_COMMA_EXPECTED,
- ERR_ONOFF_EXPECTED,
- ERR_Y_EXPECTED,
- ERR_X_EXPECTED,
- ERR_INTCON_EXPECTED,
- ERR_STRCON_EXPECTED,
- ERR_CHARCON_EXPECTED,
- ERR_CONSTEXPR_EXPECTED,
- ERR_IDENT_EXPECTED,
- ERR_ENDMACRO_EXPECTED,
- ERR_OPTION_KEY_EXPECTED,
- ERR_EQ_EXPECTED,
- ERR_ADDR_SIZE_EXPECTED,
- ERR_816_MODE_ONLY,
- ERR_USER,
- ERR_STRING_TOO_LONG,
- ERR_NEWLINE_IN_STRING,
- ERR_ILLEGAL_CHARCON,
- ERR_ILLEGAL_ADDR_MODE,
- ERR_ILLEGAL_LOCALSTART,
- ERR_ILLEGAL_LOCAL_USE,
- ERR_ILLEGAL_SEGMENT,
- ERR_ILLEGAL_MACPACK,
- ERR_ILLEGAL_FEATURE,
- ERR_ILLEGAL_SCOPE,
- ERR_ILLEGAL_ASSERT_ACTION,
- ERR_SYNTAX,
- ERR_SYM_ALREADY_DEFINED,
- ERR_SYM_UNDEFINED,
- ERR_SYM_ALREADY_IMPORT,
- ERR_SYM_ALREADY_EXPORT,
- ERR_EXPORT_UNDEFINED,
- ERR_EXPORT_MUST_BE_CONST,
- ERR_UNEXPECTED_EOF,
- ERR_UNEXPECTED_EOL,
- ERR_UNEXPECTED,
- ERR_DIV_BY_ZERO,
- ERR_MOD_BY_ZERO,
- ERR_RANGE,
- ERR_TOO_MANY_PARAMS,
- ERR_MACRO_PARAM_EXPECTED,
- ERR_CIRCULAR_REFERENCE,
- ERR_SYM_REDECL_MISMATCH,
- ERR_ADDR_SIZE_MISMATCH,
- ERR_ALIGN,
- ERR_DUPLICATE_ELSE,
- ERR_OPEN_IF,
- ERR_OPEN_PROC,
- ERR_NO_OPEN_PROC,
- ERR_SEG_ATTR_MISMATCH,
- ERR_SEGSTACK_OVERFLOW,
- ERR_SEGSTACK_EMPTY,
- ERR_SEGSTACK_NOT_EMPTY,
- ERR_CPU_NOT_SUPPORTED,
- ERR_COUNTER_UNDERFLOW,
- ERR_UNDEFINED_LABEL,
- ERR_OPEN_STMT,
- ERR_FILENAME_NOT_FOUND,
- ERR_COUNT /* Error count */
-};
-
-/* Fatal errors */
-enum Fatals {
- FAT_NONE,
- FAT_MAX_INPUT_FILES,
- FAT_OUT_OF_MEMORY,
- FAT_TOO_MANY_SEGMENTS,
- FAT_STRING_TOO_LONG,
- FAT_CANNOT_OPEN_INPUT,
- FAT_CANNOT_STAT_INPUT,
- FAT_CANNOT_OPEN_OUTPUT,
- FAT_CANNOT_WRITE_OUTPUT,
- FAT_CANNOT_OPEN_LISTING,
- FAT_CANNOT_WRITE_LISTING,
- FAT_CANNOT_READ_LISTING,
- FAT_NESTING,
- FAT_IF_NESTING,
- FAT_TOO_MANY_SYMBOLS,
- FAT_COUNT /* Fatal error count */
-};
-
-
-
/* Warning levels */
extern unsigned WarnLevel;
-void Warning (unsigned WarnNum, ...);
+void Warning (unsigned Level, const char* Format, ...) attribute ((format (printf, 2, 3)));
/* Print warning message. */
-void PWarning (const FilePos* Pos, unsigned WarnNum, ...);
+void PWarning (const FilePos* Pos, unsigned Level, const char* Format, ...) attribute ((format (printf, 3, 4)));
/* Print warning message giving an explicit file and position. */
-void Error (unsigned ErrNum, ...);
+void Error (const char* Format, ...) attribute ((format (printf, 1, 2)));
/* Print an error message */
-void PError (const FilePos* Pos, unsigned ErrNum, ...);
+void PError (const FilePos* Pos, const char* Format, ...) attribute ((format (printf, 2, 3)));
/* Print an error message giving an explicit file and position. */
-void ErrorSkip (unsigned ErrNum, ...);
+void ErrorSkip (const char* Format, ...) attribute ((format (printf, 1, 2)));
/* Print an error message and skip the rest of the line */
-void Fatal (unsigned FatNum, ...) attribute ((noreturn));
+void Fatal (const char* Format, ...) attribute((noreturn, format(printf,1,2)));
/* Print a message about a fatal error and die */
void Internal (const char* Format, ...) attribute((noreturn, format(printf,1,2)));
/* We may not end-of-line of end-of-file here */
if (TokIsSep (Tok)) {
- Error (ERR_UNEXPECTED_EOL);
+ Error ("Unexpected end of line");
return 0;
}
/* We may not end-of-line of end-of-file here */
if (TokIsSep (Tok)) {
- Error (ERR_UNEXPECTED_EOL);
+ Error ("Unexpected end of line");
return 0;
}
/* String constant expected */
if (Tok != TOK_STRCON) {
- Error (ERR_STRCON_EXPECTED);
+ Error ("String constant expected");
NextTok ();
return 0;
/* Must be a valid index */
if (Index >= (long) strlen (Str)) {
- Error (ERR_RANGE);
+ Error ("Range error");
return 0;
}
/* String constant expected */
if (Tok != TOK_STRCON) {
- Error (ERR_STRCON_EXPECTED);
+ Error ("String constant expected");
/* Smart error recovery */
if (Tok != TOK_RPAREN) {
NextTok ();
/* Expression must be enclosed in braces */
if (Tok != TOK_LPAREN) {
- Error (ERR_LPAREN_EXPECTED);
+ Error ("'(' expected");
SkipUntilSep ();
return GenLiteralExpr (0);
}
N = GenLiteralExpr (TgtTranslateChar (SVal[0]));
} else {
N = GenLiteralExpr (0); /* Dummy */
- Error (ERR_SYNTAX);
+ Error ("Syntax error");
}
NextTok ();
break;
if (IsConstExpr (Expr)) {
Val = GetExprVal (Expr);
} else {
- Error (ERR_CONSTEXPR_EXPECTED);
+ Error ("Constant expression expected");
Val = 0;
}
if (Verbosity > 0) {
DumpExpr (Root);
}
- PError (GetSymPos (Sym), ERR_CIRCULAR_REFERENCE);
- Const = 0;
+ PError (GetSymPos (Sym), "Circular reference in symbol definition");
+ Const = 0;
} else {
SymMarkUser (Sym);
Const = SymIsConst (Sym);
Left = GetExprVal (Expr->Left);
Right = GetExprVal (Expr->Right);
if (Right == 0) {
- Error (ERR_DIV_BY_ZERO);
+ Error ("Division by zero");
return 0;
}
return Left / Right;
Left = GetExprVal (Expr->Left);
Right = GetExprVal (Expr->Right);
if (Right == 0) {
- Error (ERR_MOD_BY_ZERO);
+ Error ("Modulo operation with zero");
return 0;
}
return Left % Right;
if (Verbosity) {
DumpExpr (Expr);
}
- PError (GetSymPos (Sym), ERR_CIRCULAR_REFERENCE);
+ PError (GetSymPos (Sym), "Circular reference in symbol definition");
return GenLiteralExpr (0); /* Return a dummy value */
}
SymMarkUser (Sym);
/* If we don't have this index, print a diagnostic and use the main file */
if (F == 0) {
- Error (ERR_FILENAME_NOT_FOUND, Name);
- return 0;
+ Error ("File name `%s' not found in file table", Name);
+ return 0;
} else {
return F->Index;
}
/* */
/* */
/* (C) 1998-2003 Ullrich von Bassewitz */
-/* Römerstrasse 52 */
+/* Römerstraße 52 */
/* D-70794 Filderstadt */
/* EMail: uz@cc65.org */
/* */
/* Check if we have any adressing modes left */
if (A->AddrModeSet == 0) {
- Error (ERR_ILLEGAL_ADDR_MODE);
+ Error ("Illegal addressing mode");
return 0;
}
A->AddrMode = BitFind (A->AddrModeSet);
!SymIsZP (Left->V.Sym)) {
/* Output a warning */
- Warning (WARN_SUSPICIOUS_ADDREXPR);
+ Warning (1, "Suspicious address expression");
}
}
/* Check the range for Val. */
if (Val < 0) {
/* We had an error */
- Warning (WARN_CANNOT_TRACK_STATUS);
+ Warning (1, "Cannot track processor status byte");
} else {
if (Val & 0x10) {
/* Index registers to 16 bit */
/* Check the range for Val. */
if (Val < 0) {
/* We had an error */
- Warning (WARN_CANNOT_TRACK_STATUS);
+ Warning (1, "Cannot track processor status byte");
} else {
if (Val & 0x10) {
/* Index registers to 8 bit */
CPU = NewCPU;
InsTab = InsTabs[CPU];
} else {
- Error (ERR_CPU_NOT_SUPPORTED);
+ Error ("CPU not supported");
}
}
/* */
/* */
/* */
-/* (C) 2000 Ullrich von Bassewitz */
-/* Wacholderweg 14 */
-/* D-70597 Stuttgart */
-/* EMail: uz@musoftware.de */
+/* (C) 2000-2003 Ullrich von Bassewitz */
+/* Römerstraße 52 */
+/* D-70794 Filderstadt */
+/* EMail: uz@cc65.org */
/* */
/* */
/* This software is provided 'as-is', without any expressed or implied */
/* common */
#include "check.h"
#include "xmalloc.h"
-
+
/* ca65 */
#include "error.h"
#include "istack.h"
/* Check for a stack overflow */
if (ICount > ISTACK_MAX) {
- Fatal (FAT_NESTING);
- }
+ Fatal ("Maximum input stack nesting exceeded");
+ }
/* Create a new stack element */
E = xmalloc (sizeof (*E));
*/
{
if (IStack) {
- Error (ERR_OPEN_STMT, IStack->Desc);
+ Error ("Open %s", IStack->Desc);
}
}
/* */
/* */
/* (C) 2000-2003 Ullrich von Bassewitz */
-/* Römerstrasse 52 */
+/* Römerstraße 52 */
/* D-70794 Filderstadt */
/* EMail: uz@cc65.org */
/* */
if (Listing) {
if (ListingEnabled == 0) {
/* Cannot switch the listing off once more */
- Error (ERR_COUNTER_UNDERFLOW);
+ Error ("Counter underflow");
} else {
--ListingEnabled;
}
/* Open the real listing file */
F = fopen (ListFile, "w");
if (F == 0) {
- Fatal (FAT_CANNOT_OPEN_LISTING, strerror (errno));
+ Fatal ("Cannot open listing file: %s", strerror (errno));
}
/* Reset variables, print the header for the first page */
/* */
/* */
/* (C) 1998-2003 Ullrich von Bassewitz */
-/* Römerstrasse 52 */
+/* Römerstraße 52 */
/* D-70794 Filderstadt */
/* EMail: uz@cc65.org */
/* */
if (Tok != TOK_EOF) {
SkipUntilSep ();
} else {
- Error (ERR_ENDMACRO_EXPECTED);
+ Error ("`.ENDMACRO' expected");
}
} else {
/* Skip until end of line */
/* We expect a macro name here */
if (Tok != TOK_IDENT) {
- Error (ERR_IDENT_EXPECTED);
+ Error ("Identifier expected");
MacSkipDef (Style);
return;
}
/* Did we already define that macro? */
if (HT_Find (&MacroTab, SVal) != 0) {
/* Macro is already defined */
- Error (ERR_SYM_ALREADY_DEFINED, SVal);
+ Error ("A macro named `%s' is already defined", SVal);
/* Skip tokens until we reach the final .endmacro */
MacSkipDef (Style);
return;
IdDesc* List = M->Params;
while (1) {
if (strcmp (List->Id, SVal) == 0) {
- Error (ERR_SYM_ALREADY_DEFINED, SVal);
- }
+ Error ("Duplicate symbol `%s'", SVal);
+ }
if (List->Next == 0) {
break;
} else {
}
/* May not have end of file in a macro definition */
if (Tok == TOK_EOF) {
- Error (ERR_ENDMACRO_EXPECTED);
+ Error ("`.ENDMACRO' expected");
goto Done;
}
} else {
/* Need an identifer */
if (Tok != TOK_IDENT) {
- Error (ERR_IDENT_EXPECTED);
+ Error ("Identifier expected");
SkipUntilSep ();
break;
}
/* Check for maximum parameter count */
if (E->ParamCount >= M->ParamCount) {
- Error (ERR_TOO_MANY_PARAMS);
- SkipUntilSep ();
+ Error ("Too many macro parameters");
+ SkipUntilSep ();
break;
}
/* Check for end of file */
if (Tok == TOK_EOF) {
- Error (ERR_UNEXPECTED_EOF);
+ Error ("Unexpected end of file");
return;
}
/* Check if there is really a parameter */
if (TokIsSep (Tok) || Tok == TOK_COMMA) {
- Error (ERR_MACRO_PARAM_EXPECTED);
+ Error ("Macro parameter expected");
SkipUntilSep ();
return;
}
if (Tok == TOK_COMMA) {
NextTok ();
} else {
- Error (ERR_COMMA_EXPECTED);
+ Error ("`,' expected");
}
}
}
/* */
/* */
/* (C) 1998-2003 Ullrich von Bassewitz */
-/* Römerstrasse 52 */
+/* Römerstraße 52 */
/* D-70794 Filderstadt */
/* EMail: uz@cc65.org */
/* */
{
long PC = ConstExpression ();
if (PC < 0 || PC > 0xFFFFFF) {
- Error (ERR_RANGE);
+ Error ("Range error");
} else {
SetAbsPC (PC);
}
*/
if (Tok != TOK_COLON) {
if (HadWS || !NoColonLabels) {
- Error (ERR_COLON_EXPECTED);
+ Error ("`:' expected");
}
if (Tok == TOK_NAMESPACE) {
/* Smart :: handling */
} else if (PCAssignment && (Tok == TOK_STAR || Tok == TOK_PC)) {
NextTok ();
if (Tok != TOK_EQ) {
- Error (ERR_EQ_EXPECTED);
+ Error ("`=' expected");
SkipUntilSep ();
} else {
/* Skip the equal sign */
/* */
/* */
/* (C) 2000-2003 Ullrich von Bassewitz */
-/* Wacholderweg 14 */
-/* D-70597 Stuttgart */
-/* EMail: uz@musoftware.de */
+/* Römerstraße 52 */
+/* D-70794 Filderstadt */
+/* EMail: uz@cc65.org */
/* */
/* */
/* This software is provided 'as-is', without any expressed or implied */
/* Check for end of line or end of input */
if (TokIsSep (Tok)) {
- Error (ERR_UNEXPECTED_EOL);
+ Error ("Unexpected end of line");
return List;
}
/* Next token must be a string */
if (Tok != TOK_STRCON) {
- Error (ERR_STRCON_EXPECTED);
+ Error ("String constant expected");
SkipUntilSep ();
return;
}
/* Get the length of the string const and check total length */
L = strlen (SVal);
if (Length + L > MAX_STR_LEN) {
- Error (ERR_STRING_TOO_LONG);
+ Error ("String is too long");
/* Try to recover */
SkipUntilSep ();
return;
* by the string token just created.
*/
if (Tok != TOK_RPAREN) {
- Error (ERR_RPAREN_EXPECTED);
+ Error ("`)' expected");
} else {
Tok = TOK_STRCON;
strcpy (SVal, Buf);
/* Count argument */
Count = ConstExpression ();
if (Count < 0 || Count > 100) {
- Error (ERR_RANGE);
+ Error ("Range error");
Count = 1;
}
ConsumeComma ();
/* Start argument */
Start = ConstExpression ();
if (Start < 0 || Start > 100) {
- Error (ERR_RANGE);
+ Error ("Range error");
Start = 0;
}
ConsumeComma ();
/* Count argument */
Count = ConstExpression ();
if (Count < 0 || Count > 100) {
- Error (ERR_RANGE);
+ Error ("Range error");
Count = 1;
}
ConsumeComma ();
/* Count argument */
Count = ConstExpression ();
if (Count < 0 || Count > 100) {
- Error (ERR_RANGE);
+ Error ("Range error");
Count = 1;
}
ConsumeComma ();
* by the string token just created.
*/
if (Tok != TOK_RPAREN) {
- Error (ERR_RPAREN_EXPECTED);
+ Error ("`)' expected");
} else {
Tok = TOK_STRCON;
strcpy (SVal, Buf);
-void Consume (enum Token Expected, unsigned ErrMsg)
+void Consume (enum Token Expected, const char* ErrMsg)
/* Consume Expected, print an error if we don't find it */
{
if (Tok == Expected) {
/* Accept an EOF as separator */
if (Tok != TOK_EOF) {
if (Tok != TOK_SEP) {
- Error (ERR_TOO_MANY_CHARS);
+ Error ("Too many characters");
SkipUntilSep ();
} else {
NextTok ();
void ConsumeLParen (void)
/* Consume a left paren */
{
- Consume (TOK_LPAREN, ERR_LPAREN_EXPECTED);
+ Consume (TOK_LPAREN, "`(' expected");
}
void ConsumeRParen (void)
/* Consume a right paren */
{
- Consume (TOK_RPAREN, ERR_RPAREN_EXPECTED);
+ Consume (TOK_RPAREN, "`)' expected");
}
void ConsumeComma (void)
/* Consume a comma */
{
- Consume (TOK_COMMA, ERR_COMMA_EXPECTED);
+ Consume (TOK_COMMA, "`,' expected");
}
/* */
/* */
/* */
-/* (C) 2000 Ullrich von Bassewitz */
-/* Wacholderweg 14 */
-/* D-70597 Stuttgart */
-/* EMail: uz@musoftware.de */
+/* (C) 2000-2003 Ullrich von Bassewitz */
+/* Römerstraße 52 */
+/* D-70794 Filderstadt */
+/* EMail: uz@cc65.org */
/* */
/* */
/* This software is provided 'as-is', without any expressed or implied */
void NextTok (void);
/* Get next token and handle token level functions */
-void Consume (enum Token Expected, unsigned ErrMsg);
+void Consume (enum Token Expected, const char* ErrMsg);
/* Consume Token, print an error if we don't find it */
void ConsumeSep (void);
/* */
/* */
/* (C) 1998-2003 Ullrich von Bassewitz */
-/* Römerstrasse 52 */
+/* Römerstraße 52 */
/* D-70794 Filderstadt */
/* EMail: uz@cc65.org */
/* */
long Val = GetExprVal (Expr);
FreeExpr (Expr);
if ((Val & ~0xFF) != 0) {
- Error (ERR_RANGE);
+ Error ("Range error");
}
Emit0 (Val & 0xFF);
} else {
long Val = GetExprVal (Expr);
FreeExpr (Expr);
if ((Val & ~0xFFFF) != 0) {
- Error (ERR_RANGE);
+ Error ("Range error");
}
Emit0 (Val & 0xFF);
Emit0 ((Val >> 8) & 0xFF);
long Val = GetExprVal (Expr);
FreeExpr (Expr);
if ((Val & ~0xFFFFFF) != 0) {
- Error (ERR_RANGE);
+ Error ("Range error");
}
Emit0 (Val & 0xFF);
Emit0 ((Val >> 8) & 0xFF);
/* */
/* */
/* (C) 1998-2003 Ullrich von Bassewitz */
-/* Römerstrasse 52 */
+/* Römerstraße 52 */
/* D-70794 Filderstadt */
/* EMail: uz@cc65.org */
/* */
remove (OutFile);
/* Now abort with a fatal error */
- Fatal (FAT_CANNOT_WRITE_OUTPUT, OutFile, strerror (Error));
+ Fatal ("Cannot write to output file `%s': %s", OutFile, strerror (Error));
}
/* Create the output file */
F = fopen (OutFile, "w+b");
if (F == 0) {
- Fatal (FAT_CANNOT_OPEN_OUTPUT, OutFile, strerror (errno));
+ Fatal ("Cannot open output file `%s': %s", OutFile, strerror (errno));
}
/* Write a dummy header */
} else if (Tok == TOK_IDENT) {
/* Map the keyword to a number */
switch (GetSubKey (Keys, sizeof (Keys) / sizeof (Keys [0]))) {
- case 0: *Flag = 0; NextTok (); break;
- case 1: *Flag = 1; NextTok (); break;
- default: ErrorSkip (ERR_ONOFF_EXPECTED); break;
+ case 0: *Flag = 0; NextTok (); break;
+ case 1: *Flag = 1; NextTok (); break;
+ default: ErrorSkip ("`on' or `off' expected"); break;
}
} else if (TokIsSep (Tok)) {
/* Without anything assume switch on */
*Flag = 1;
} else {
- ErrorSkip (ERR_ONOFF_EXPECTED);
+ ErrorSkip ("`on' or `off' expected");
}
}
/* We need an identifier here */
if (Tok != TOK_IDENT) {
- ErrorSkip (ERR_IDENT_EXPECTED);
+ ErrorSkip ("Identifier expected");
return;
}
} else {
long Val = ConstExpression ();
if (Val < Min || Val > Max) {
- Error (ERR_RANGE);
+ Error ("Range error");
Val = Min;
}
return Val;
Prio = ConstExpression ();
if (Prio < CD_PRIO_MIN || Prio > CD_PRIO_MAX) {
/* Value out of range */
- Error (ERR_RANGE);
+ Error ("Range error");
return;
}
} else {
static void DoA16 (void)
/* Switch the accu to 16 bit mode (assembler only) */
-{
+{
if (GetCPU() != CPU_65816) {
- Error (ERR_816_MODE_ONLY);
+ Error ("Command is only valid in 65816 mode");
} else {
/* Immidiate mode has two extension bytes */
ExtBytes [AMI_IMM_ACCU] = 2;
/* Switch the accu to 8 bit mode (assembler only) */
{
if (GetCPU() != CPU_65816) {
- Error (ERR_816_MODE_ONLY);
+ Error ("Command is only valid in 65816 mode");
} else {
/* Immidiate mode has one extension byte */
ExtBytes [AMI_IMM_ACCU] = 1;
/* Read the alignment value */
Align = ConstExpression ();
if (Align <= 0 || Align > 0x10000) {
- ErrorSkip (ERR_RANGE);
+ ErrorSkip ("Range error");
return;
}
Val = ConstExpression ();
/* We need a byte value here */
if (!IsByteRange (Val)) {
- ErrorSkip (ERR_RANGE);
+ ErrorSkip ("Range error");
return;
}
} else {
/* Check if the alignment is a power of two */
Bit = BitFind (Align);
if (Align != (0x01L << Bit)) {
- Error (ERR_ALIGN);
+ Error ("Alignment value must be a power of 2");
} else {
SegAlign (Bit, (int) Val);
}
while (1) {
/* Must have a string constant */
if (Tok != TOK_STRCON) {
- ErrorSkip (ERR_STRCON_EXPECTED);
+ ErrorSkip ("String constant expected");
return;
}
/* Action follows */
if (Tok != TOK_IDENT) {
- ErrorSkip (ERR_IDENT_EXPECTED);
+ ErrorSkip ("Identifier expected");
return;
}
Action = GetSubKey (ActionTab, sizeof (ActionTab) / sizeof (ActionTab[0]));
break;
default:
- Error (ERR_ILLEGAL_ASSERT_ACTION);
+ Error ("Illegal assert action specifier");
}
NextTok ();
ConsumeComma ();
/* Read the message */
if (Tok != TOK_STRCON) {
- ErrorSkip (ERR_STRCON_EXPECTED);
+ ErrorSkip ("String constant expected");
} else {
AddAssertion (Expr, Action, GetStringId (SVal));
NextTok ();
NextTok ();
/* Do smart handling of dangling comma */
if (Tok == TOK_SEP) {
- Error (ERR_UNEXPECTED_EOL);
+ Error ("Unexpected end of line");
break;
}
}
Index = ConstExpression ();
if (Index < 1 || Index > 255) {
/* Value out of range */
- ErrorSkip (ERR_RANGE);
+ ErrorSkip ("Range error");
return;
}
Code = ConstExpression ();
if (Code < 1 || Code > 255) {
/* Value out of range */
- ErrorSkip (ERR_RANGE);
+ ErrorSkip ("Range error");
return;
}
/* Symbol name follows */
if (Tok != TOK_IDENT) {
- ErrorSkip (ERR_IDENT_EXPECTED);
+ ErrorSkip ("Identifier expected");
return;
}
strcpy (Name, SVal);
/* Check if we got a valid keyword */
if (Type < 0) {
- Error (ERR_SYNTAX);
+ Error ("Syntax error");
SkipUntilSep ();
return;
}
Type = ConstExpression ();
if (Type < CD_TYPE_MIN || Type > CD_TYPE_MAX) {
/* Value out of range */
- Error (ERR_RANGE);
+ Error ("Range error");
return;
}
/* Symbol name follows */
if (Tok != TOK_IDENT) {
- ErrorSkip (ERR_IDENT_EXPECTED);
+ ErrorSkip ("Identifier expected");
return;
}
strcpy (Name, SVal);
/* We expect a subkey */
if (Tok != TOK_IDENT) {
- ErrorSkip (ERR_IDENT_EXPECTED);
+ ErrorSkip ("Identifier expected");
return;
}
case 0: DbgInfoFile (); break;
case 1: DbgInfoLine (); break;
case 2: DbgInfoSym (); break;
- default: ErrorSkip (ERR_SYNTAX); break;
+ default: ErrorSkip ("Syntax error"); break;
}
}
/* Symbol name follows */
if (Tok != TOK_IDENT) {
- ErrorSkip (ERR_IDENT_EXPECTED);
+ ErrorSkip ("Identifier expected");
return;
}
strcpy (Name, SVal);
SymLeaveLevel ();
} else {
/* No local scope */
- ErrorSkip (ERR_NO_OPEN_PROC);
+ ErrorSkip ("No open lexical level");
}
}
/* User error */
{
if (Tok != TOK_STRCON) {
- ErrorSkip (ERR_STRCON_EXPECTED);
+ ErrorSkip ("String constant expected");
} else {
- Error (ERR_USER, SVal);
+ Error ("User error: %s", SVal);
SkipUntilSep ();
}
}
/* We expect an identifier */
if (Tok != TOK_IDENT) {
- ErrorSkip (ERR_IDENT_EXPECTED);
+ ErrorSkip ("Identifier expected");
return;
}
/* Set the feature and check for errors */
if (SetFeature (SVal) == FEAT_UNKNOWN) {
/* Not found */
- ErrorSkip (ERR_ILLEGAL_FEATURE);
+ ErrorSkip ("Invalid feature: `%s'", SVal);
return;
} else {
/* Skip the keyword */
NextTok ();
}
- /* Allow more than one keyword */
+ /* Allow more than one keyword */
if (Tok == TOK_COMMA) {
NextTok ();
} else {
OptNum = GetSubKey (Keys, sizeof (Keys) / sizeof (Keys [0]));
if (OptNum < 0) {
/* Not found */
- ErrorSkip (ERR_OPTION_KEY_EXPECTED);
+ ErrorSkip ("File option keyword expected");
return;
}
/* We accept only string options for now */
if (Tok != TOK_STRCON) {
- ErrorSkip (ERR_STRCON_EXPECTED);
+ ErrorSkip ("String constant expected");
return;
}
/* Option given as number */
OptNum = ConstExpression ();
if (!IsByteRange (OptNum)) {
- ErrorSkip (ERR_RANGE);
+ ErrorSkip ("Range error");
return;
}
/* We accept only string options for now */
if (Tok != TOK_STRCON) {
- ErrorSkip (ERR_STRCON_EXPECTED);
+ ErrorSkip ("String constant expected");
return;
}
/* Switch the index registers to 16 bit mode (assembler only) */
{
if (GetCPU() != CPU_65816) {
- Error (ERR_816_MODE_ONLY);
+ Error ("Command is only valid in 65816 mode");
} else {
/* Immidiate mode has two extension bytes */
ExtBytes [AMI_IMM_INDEX] = 2;
/* Switch the index registers to 16 bit mode (assembler only) */
{
if (GetCPU() != CPU_65816) {
- Error (ERR_816_MODE_ONLY);
+ Error ("Command is only valid in 65816 mode");
} else {
/* Immidiate mode has one extension byte */
ExtBytes [AMI_IMM_INDEX] = 1;
/* Name must follow */
if (Tok != TOK_STRCON) {
- ErrorSkip (ERR_STRCON_EXPECTED);
+ ErrorSkip ("String constant expected");
return;
}
strcpy (Name, SVal);
char* PathName = FindInclude (Name);
if (PathName == 0 || (F = fopen (PathName, "r")) == 0) {
/* Not found or cannot open, print an error and bail out */
- ErrorSkip (ERR_CANNOT_OPEN_INCLUDE, Name, strerror (errno));
+ ErrorSkip ("Cannot open include file `%s': %s", Name, strerror (errno));
}
/* Free the allocated memory */
Count = Size - Start;
if (Count < 0) {
/* Nothing to read - flag this as a range error */
- ErrorSkip (ERR_RANGE);
+ ErrorSkip ("Range error");
goto Done;
}
} else {
/* Count was given, check if it is valid */
if (Start + Count > Size) {
- ErrorSkip (ERR_RANGE);
+ ErrorSkip ("Range error");
goto Done;
}
}
size_t BytesRead = fread (Buf, 1, BytesToRead, F);
if (BytesToRead != BytesRead) {
/* Some sort of error */
- ErrorSkip (ERR_CANNOT_READ_INCLUDE, Name, strerror (errno));
+ ErrorSkip ("Cannot read from include file `%s': %s",
+ Name, strerror (errno));
break;
}
/* Name must follow */
if (Tok != TOK_STRCON) {
- ErrorSkip (ERR_STRCON_EXPECTED);
+ ErrorSkip ("String constant expected");
} else {
strcpy (Name, SVal);
NextTok ();
/* Define the character that starts local labels */
{
if (Tok != TOK_CHARCON) {
- ErrorSkip (ERR_CHARCON_EXPECTED);
+ ErrorSkip ("Character constant expected");
} else {
if (IVal != '@' && IVal != '?') {
- Error (ERR_ILLEGAL_LOCALSTART);
+ Error ("Invalid start character for locals");
} else {
LocalStart = (char) IVal;
}
/* We expect an identifier */
if (Tok != TOK_IDENT) {
- ErrorSkip (ERR_IDENT_EXPECTED);
+ ErrorSkip ("Identifier expected");
return;
}
Package = GetSubKey (Keys, sizeof (Keys) / sizeof (Keys [0]));
if (Package < 0) {
/* Not found */
- ErrorSkip (ERR_ILLEGAL_MACPACK);
+ ErrorSkip ("Invalid macro package");
return;
}
{
long PC = ConstExpression ();
if (PC < 0 || PC > 0xFFFFFF) {
- Error (ERR_RANGE);
+ Error ("Range error");
return;
}
SetAbsPC (PC);
/* Output a string */
{
if (Tok != TOK_STRCON) {
- ErrorSkip (ERR_STRCON_EXPECTED);
+ ErrorSkip ("String constant expected");
} else {
/* Output the string and be sure to flush the output to keep it in
* sync with any error messages if the output is redirected to a file.
/* Must have a segment on the stack */
if (CollCount (&SegStack) == 0) {
- ErrorSkip (ERR_SEGSTACK_EMPTY);
+ ErrorSkip ("Segment stack is empty");
return;
}
/* A .PROC statement without a name */
char Buf[sizeof (SVal)];
SymEnterLevel (AnonName (Buf, sizeof (Buf), "Scope"), ADDR_SIZE_DEFAULT);
- Warning (WARN_UNNAMED_PROC);
+ Warning (1, "Unnamed .PROCs are deprecated, please use .SCOPE");
}
}
{
/* Can only push a limited size of segments */
if (CollCount (&SegStack) >= MAX_PUSHED_SEGMENTS) {
- ErrorSkip (ERR_SEGSTACK_OVERFLOW);
+ ErrorSkip ("Segment stack overflow");
return;
}
Count = ConstExpression ();
if (Count > 0xFFFF || Count < 0) {
- ErrorSkip (ERR_RANGE);
+ ErrorSkip ("Range error");
return;
}
if (Tok == TOK_COMMA) {
Val = ConstExpression ();
/* We need a byte value here */
if (!IsByteRange (Val)) {
- ErrorSkip (ERR_RANGE);
+ ErrorSkip ("Range error");
return;
}
Def.Name = Name;
if (Tok != TOK_STRCON) {
- ErrorSkip (ERR_STRCON_EXPECTED);
+ ErrorSkip ("String constant expected");
} else {
/* Save the name of the segment and skip it */
{
/* We expect an identifier */
if (Tok != TOK_STRCON) {
- ErrorSkip (ERR_STRCON_EXPECTED);
+ ErrorSkip ("String constant expected");
} else {
/* Try to find the CPU, then skip the identifier */
cpu_t CPU = FindCPU (SVal);
static void DoStruct (void)
/* Struct definition */
{
- Error (ERR_NOT_IMPLEMENTED);
+ Error ("Not implemented");
}
static void DoUnion (void)
/* Union definition */
{
- Error (ERR_NOT_IMPLEMENTED);
+ Error ("Not implemented");
}
static void DoUnexpected (void)
/* Got an unexpected keyword */
{
- Error (ERR_UNEXPECTED, Keyword);
+ Error ("Unexpected `%s'", Keyword);
SkipUntilSep ();
}
/* User warning */
{
if (Tok != TOK_STRCON) {
- ErrorSkip (ERR_STRCON_EXPECTED);
+ ErrorSkip ("String constant expected");
} else {
- Warning (WARN_USER, SVal);
+ Warning (0, "User warning: %s", SVal);
SkipUntilSep ();
}
}
/* Check if the segment stack is empty at end of assembly */
{
if (CollCount (&SegStack) != 0) {
- Error (ERR_SEGSTACK_NOT_EMPTY);
+ Error ("Segment stack is not empty");
}
}
/* Check for end of input */
if (Tok == TOK_EOF) {
- Error (ERR_UNEXPECTED_EOF);
+ Error ("Unexpected end of file");
FreeTokList (List);
return 0;
}
/* Repeat count follows */
long RepCount = ConstExpression ();
if (RepCount < 0) {
- Error (ERR_RANGE);
+ Error ("Range error");
RepCount = 0;
}
/* Check for an identifier */
if (Tok != TOK_IDENT) {
- ErrorSkip (ERR_IDENT_EXPECTED);
+ ErrorSkip ("Identifier expected");
} else {
/* Remember the name and skip it */
Name = xstrdup (SVal);
/* */
/* */
/* (C) 1998-2003 Ullrich von Bassewitz */
-/* Römerstrasse 52 */
+/* Römerstraße 52 */
/* D-70794 Filderstadt */
/* EMail: uz@cc65.org */
/* */
/* Error (fatal error if this is the main file) */
if (ICount == 0) {
- Fatal (FAT_CANNOT_OPEN_INPUT, Name, strerror (errno));
+ Fatal ("Cannot open input file `%s': %s", Name, strerror (errno));
}
/* We are on include level. Search for the file in the include
PathName = FindInclude (Name);
if (PathName == 0 || (F = fopen (PathName, "r")) == 0) {
/* Not found or cannot open, print an error and bail out */
- Error (ERR_CANNOT_OPEN_INCLUDE, Name, strerror (errno));
+ Error ("Cannot open include file `%s': %s", Name, strerror (errno));
}
/* Free the allocated memory */
/* Stat the file and remember the values */
struct stat Buf;
if (fstat (fileno (F), &Buf) != 0) {
- Fatal (FAT_CANNOT_STAT_INPUT, Name, strerror (errno));
+ Fatal ("Cannot stat input file `%s': %s", Name, strerror (errno));
}
/* Add the file to the input file table and remember the index */
break;
}
if (C == '\n' || C == EOF) {
- Error (ERR_NEWLINE_IN_STRING);
+ Error ("Newline in string constant");
break;
}
/* Check for string length, print an error message once */
if (I == MAX_STR_LEN) {
- Error (ERR_STRING_TOO_LONG);
+ Error ("Maximum string size exceeded");
} else if (I < MAX_STR_LEN) {
SVal [I] = C;
}
Tok = TOK_PC;
return;
} else {
- Error (ERR_HEX_DIGIT_EXPECTED);
+ Error ("Hexadecimal digit expected");
}
}
IVal = 0;
while (IsXDigit (C)) {
if (IVal & 0xF0000000) {
- Error (ERR_NUM_OVERFLOW);
+ Error ("Overflow in hexadecimal number");
IVal = 0;
}
IVal = (IVal << 4) + DigitVal (C);
/* 0 or 1 must follow */
if (!IsBDigit (C)) {
- Error (ERR_01_EXPECTED);
+ Error ("Binary digit expected");
}
/* Read the number */
IVal = 0;
while (IsBDigit (C)) {
if (IVal & 0x80000000) {
- Error (ERR_NUM_OVERFLOW);
+ Error ("Overflow in binary number");
IVal = 0;
}
IVal = (IVal << 1) + DigitVal (C);
IVal = 0;
while (IsDigit (C)) {
if (IVal > (long) (0xFFFFFFFFUL / 10)) {
- Error (ERR_NUM_OVERFLOW);
+ Error ("Overflow in decimal number");
IVal = 0;
}
IVal = (IVal * 10) + DigitVal (C);
if (C == '.') {
/* Remember and skip the dot */
- SVal[0] = C;
NextChar ();
/* Check if it's just a dot */
} else {
/* Read the remainder of the identifier */
+ SVal[0] = '.';
ReadIdent (1);
/* Dot keyword, search for it */
Tok = TOK_IDENT;
} else {
/* Invalid pseudo instruction */
- Error (ERR_PSEUDO_EXPECTED);
+ Error ("`%s' is not a recognized control command", SVal);
goto Again;
}
}
/* Start character alone is not enough */
if (SVal [1] == '\0') {
- Error (ERR_IDENT_EXPECTED);
+ Error ("Invalid cheap local symbol");
goto Again;
}
/* Always a character constant */
NextChar ();
if (C == '\n' || C == EOF) {
- Error (ERR_ILLEGAL_CHARCON);
+ Error ("Illegal character constant");
goto CharAgain;
}
IVal = C;
Tok = TOK_CHARCON;
NextChar ();
if (C != '\'') {
- Error (ERR_ILLEGAL_CHARCON);
+ Error ("Illegal character constant");
} else {
NextChar ();
}
/* If we go here, we could not identify the current character. Skip it
* and try again.
*/
- Error (ERR_INVALID_CHAR, C & 0xFF);
+ Error ("Invalid input character: 0x%02X", C & 0xFF);
NextChar ();
goto Again;
}
/* Check for an identifier */
if (Tok != TOK_IDENT) {
- Error (ERR_ADDR_SIZE_EXPECTED);
+ Error ("Address size specifier expected");
return ADDR_SIZE_DEFAULT;
}
case 5: return ADDR_SIZE_ABS;
case 6: return ADDR_SIZE_FAR;
default:
- Error (ERR_ADDR_SIZE_EXPECTED);
+ Error ("Address size specifier expected");
return ADDR_SIZE_DEFAULT;
}
}
/* */
/* */
/* (C) 1998-2003 Ullrich von Bassewitz */
-/* Römerstrasse 52 */
+/* Römerstraße 52 */
/* D-70794 Filderstadt */
/* EMail: uz@cc65.org */
/* */
/* Check for too many segments */
if (SegmentCount >= 256) {
- Fatal (FAT_TOO_MANY_SEGMENTS);
+ Fatal ("Too many segments");
}
/* Check the segment name for invalid names */
if (!ValidSegName (Name)) {
- Error (ERR_ILLEGAL_SEGMENT, Name);
+ Error ("Illegal segment name: `%s'", Name);
}
/* Create a new segment */
/* We found this segment. Check if the type is identical */
if (D->AddrSize != ADDR_SIZE_DEFAULT &&
Seg->Def->AddrSize != D->AddrSize) {
- Error (ERR_SEG_ATTR_MISMATCH);
+ Error ("Segment attribute mismatch");
/* Use the new attribute to avoid errors */
Seg->Def->AddrSize = D->AddrSize;
}
if (Abs) {
/* Absolute value */
if (Val > 255) {
- PError (&F->Pos, ERR_RANGE);
+ PError (&F->Pos, "Range error");
}
} else {
/* PC relative value */
if (Val < -128 || Val > 127) {
- PError (&F->Pos, ERR_RANGE);
+ PError (&F->Pos, "Range error");
}
}
} else if (F->Len == 2) {
if (Abs) {
/* Absolute value */
if (Val > 65535) {
- PError (&F->Pos, ERR_RANGE);
+ PError (&F->Pos, "Range error");
}
} else {
/* PC relative value */
if (Val < -32768 || Val > 32767) {
- PError (&F->Pos, ERR_RANGE);
+ PError (&F->Pos, "Range error");
}
}
}
* byte expressions and we will do so.
*/
if (F->Type == FRAG_EXPR && F->Len == 1 && !IsByteExpr (F->V.Expr)) {
- PError (&F->Pos, ERR_RANGE);
+ PError (&F->Pos, "Range error");
}
}
}
/* */
/* */
/* (C) 1998-2003 Ullrich von Bassewitz */
-/* Römerstrasse 52 */
+/* Römerstraße 52 */
/* D-70794 Filderstadt */
/* EMail: uz@cc65.org */
/* */
/* An identifier must follow. Remember and skip it. */
char Name[sizeof (SVal)];
if (Tok != TOK_IDENT) {
- Error (ERR_IDENT_EXPECTED);
+ Error ("Identifier expected");
return 0;
}
strcpy (Name, SVal);
#include "scanner.h"
#include "spool.h"
#include "symentry.h"
+#include "symtab.h"
{
if (S->Flags & SF_IMPORT) {
/* Defined symbol is marked as imported external symbol */
- Error (ERR_SYM_ALREADY_IMPORT, GetSymName (S));
+ Error ("Symbol `%s' is already an import", GetSymName (S));
return;
}
if (S->Flags & SF_DEFINED) {
/* Multiple definition */
- Error (ERR_SYM_ALREADY_DEFINED, GetSymName (S));
+ Error ("Symbol `%s' is already defined", GetSymName (S));
S->Flags |= SF_MULTDEF;
return;
}
/* If the symbol is exported, check the address sizes */
if (S->Flags & SF_EXPORT) {
if (S->AddrSize > S->ExportSize) {
- Warning (WARN_ADDR_SIZE_MISMATCH, GetSymName (S));
+ Warning (1, "Address size mismatch for symbol `%s'", GetSymName (S));
}
}
if (S->AddrSize == ADDR_SIZE_ZP) {
/* Already marked as ZP symbol by some means */
if (!IsByteExpr (Expr)) {
- Error (ERR_RANGE);
+ Error ("Range error");
}
}
{
/* Don't accept local symbols */
if (IsLocalNameId (S->Name)) {
- Error (ERR_ILLEGAL_LOCAL_USE);
+ Error ("Illegal use of a local symbol");
return;
}
if (S->Flags & SF_DEFINED) {
- Error (ERR_SYM_ALREADY_DEFINED, GetSymName (S));
+ Error ("Symbol `%s' is already defined", GetSymName (S));
S->Flags |= SF_MULTDEF;
return;
}
if (S->Flags & SF_EXPORT) {
/* The symbol is already marked as exported symbol */
- Error (ERR_SYM_ALREADY_EXPORT, GetSymName (S));
+ Error ("Cannot import exported symbol `%s'", GetSymName (S));
return;
}
if (S->Flags & (SF_IMPORT | SF_GLOBAL)) {
if ((Flags & SF_FORCED) != (S->Flags & SF_FORCED) ||
AddrSize != S->AddrSize) {
- Error (ERR_SYM_REDECL_MISMATCH, GetSymName (S));
+ Error ("Redeclaration mismatch for symbol `%s'", GetSymName (S));
}
S->Flags &= ~SF_GLOBAL;
}
{
/* Don't accept local symbols */
if (IsLocalNameId (S->Name)) {
- Error (ERR_ILLEGAL_LOCAL_USE);
+ Error ("Illegal use of a local symbol");
return;
}
/* Check if it's ok to export the symbol */
if (S->Flags & SF_IMPORT) {
/* The symbol is already marked as imported external symbol */
- Error (ERR_SYM_ALREADY_IMPORT, GetSymName (S));
+ Error ("Symbol `%s' is already an import", GetSymName (S));
return;
}
*/
if (S->Flags & (SF_EXPORT | SF_GLOBAL)) {
if (S->ExportSize != AddrSize) {
- Error (ERR_ADDR_SIZE_MISMATCH, GetSymName (S));
+ Error ("Address size mismatch for symbol `%s'", GetSymName (S));
}
S->Flags &= ~SF_GLOBAL;
}
*/
if (S->Flags & SF_DEFINED) {
if (S->AddrSize > S->ExportSize) {
- Warning (WARN_ADDR_SIZE_MISMATCH, GetSymName (S));
+ Warning (1, "Address size mismatch for symbol `%s'", GetSymName (S));
}
}
{
/* Don't accept local symbols */
if (IsLocalNameId (S->Name)) {
- Error (ERR_ILLEGAL_LOCAL_USE);
+ Error ("Illegal use of a local symbol");
return;
}
*/
if (S->Flags & SF_IMPORT) {
if (AddrSize != S->AddrSize) {
- Error (ERR_ADDR_SIZE_MISMATCH, GetSymName (S));
+ Error ("Address size mismatch for symbol `%s'", GetSymName (S));
}
return;
}
if (S->Flags & SF_EXPORT) {
if (AddrSize != S->ExportSize) {
- Error (ERR_ADDR_SIZE_MISMATCH, GetSymName (S));
+ Error ("Address size mismatch for symbol `%s'", GetSymName (S));
}
return;
}
if (S->Flags & SF_DEFINED) {
/* The symbol is defined, export it */
if (S->ExportSize != AddrSize) {
- Error (ERR_ADDR_SIZE_MISMATCH, GetSymName (S));
+ Error ("Address size mismatch for symbol `%s'", GetSymName (S));
}
S->Flags |= (SF_EXPORT | Flags);
S->ExportSize = AddrSize;
#include "expr.h"
#include "objfile.h"
#include "scanner.h"
+#include "segment.h"
#include "spool.h"
#include "symtab.h"
-static SymTable* NewSymTable (SymTable* Parent, unsigned AddrSize, const char* Name)
+static SymTable* NewSymTable (SymTable* Parent, const char* Name)
/* Allocate a symbol table on the heap and return it */
{
/* Determine the lexical level and the number of table slots */
S->Left = 0;
S->Right = 0;
S->Childs = 0;
- S->AddrSize = AddrSize;
+ S->Flags = ST_NONE;
+ S->AddrSize = ADDR_SIZE_DEFAULT;
S->Type = 0;
S->Level = Level;
S->TableSlots = Slots;
void SymEnterLevel (const char* ScopeName, unsigned AddrSize)
/* Enter a new lexical level */
{
- /* ### Check existing scope */
-
/* Map a default address size to something real */
- if (AddrSize == ADDR_SIZE_DEFAULT) {
+ if (AddrSize == ADDR_SIZE_DEFAULT) {
/* Use the segment address size */
AddrSize = GetCurrentSegAddrSize ();
}
- /* Create the new table */
- CurrentScope = NewSymTable (CurrentScope, ScopeName);
+ /* Search for an existing table/create a new one */
+ CurrentScope = SymFindScope (CurrentScope, ScopeName, SYM_ALLOC_NEW);
+
+ /* Check if the scope has been defined before */
+ if (CurrentScope->Flags & ST_DEFINED) {
+ Error ("Duplicate scope `%s'", ScopeName);
+ }
+
+ /* Mark the scope as defined */
+ CurrentScope->Flags |= ST_DEFINED;
}
/* Local symbol, get the table */
if (!SymLast) {
/* No last global, so there's no local table */
- Error (ERR_ILLEGAL_LOCAL_USE);
+ Error ("No preceeding global symbol");
if (AllocNew) {
return NewSymEntry (Name);
} else {
/* Don't accept local symbols */
if (IsLocalName (Name)) {
- Error (ERR_ILLEGAL_LOCAL_USE);
+ Error ("Illegal use of a local symbol");
return;
}
S = SymFind (CurrentScope, Name, SYM_ALLOC_NEW);
if (S->Flags & SF_IMPORT) {
/* The symbol is already marked as imported external symbol */
- Error (ERR_SYM_ALREADY_IMPORT, Name);
+ Error ("Symbol `%s' is already an import", Name);
return;
}
/* Check if the symbol was not already defined as ZP symbol */
if (S->AddrSize == ADDR_SIZE_ZP) {
- Error (ERR_SYM_REDECL_MISMATCH, Name);
+ Error ("Redeclaration mismatch for symbol `%s'", Name);
}
/* If the symbol was already declared as a condes, check if the new
*/
if (S->ConDesPrio[Type] != CD_PRIO_NONE) {
if (S->ConDesPrio[Type] != Prio) {
- Error (ERR_SYM_REDECL_MISMATCH, Name);
+ Error ("Redeclaration mismatch for symbol `%s'", Name);
}
}
S->ConDesPrio[Type] = Prio;
if (S->Flags & SF_EXPORT) {
if (Sym->Flags & SF_IMPORT) {
/* The symbol is already marked as imported external symbol */
- PError (&S->Pos, ERR_SYM_ALREADY_IMPORT, GetString (S->Name));
+ PError (&S->Pos, "Symbol `%s' is already an import", GetString (S->Name));
}
Sym->Flags |= S->Flags & (SF_EXPORT | SF_ZP);
}
/* The symbol is definitely undefined */
if (S->Flags & SF_EXPORT) {
/* We will not auto-import an export */
- PError (&S->Pos, ERR_EXPORT_UNDEFINED, GetString (S->Name));
+ PError (&S->Pos, "Exported symbol `%s' was never defined",
+ GetString (S->Name));
} else {
if (AutoImport) {
/* Mark as import, will be indexed later */
S->Flags |= SF_IMPORT;
} else {
/* Error */
- PError (&S->Pos, ERR_SYM_UNDEFINED, GetString (S->Name));
+ PError (&S->Pos, "Symbol `%s' is undefined", GetString (S->Name));
}
}
}
{
SymEntry* S;
- /* Check for open lexical levels */
+ /* Check for open scopes */
if (CurrentScope->Parent != 0) {
- Error (ERR_OPEN_PROC);
+ Error ("Local scope was not closed");
}
/* First pass: Walk through all symbols, checking for undefined's and
(S->Flags & SF_UNDEFMASK) != SF_UNDEFVAL) {
if ((S->Flags & SF_DEFINED) != 0 && (S->Flags & SF_REFERENCED) == 0) {
/* Symbol was defined but never referenced */
- PWarning (&S->Pos, WARN_SYM_NOT_REFERENCED, GetString (S->Name));
+ PWarning (&S->Pos, 2,
+ "Symbol `%s' is defined but never used",
+ GetString (S->Name));
}
if (S->Flags & SF_IMPORT) {
if ((S->Flags & (SF_REFERENCED | SF_FORCED)) == SF_NONE) {
/* Imported symbol is not referenced */
- PWarning (&S->Pos, WARN_IMPORT_NOT_REFERENCED, GetString (S->Name));
+ PWarning (&S->Pos, 2,
+ "Symbol `%s' is imported but never used",
+ GetString (S->Name));
} else {
/* Give the import an index, count imports */
S->Index = ImportCount++;
+/* Symbol table flags */
+#define ST_NONE 0x00 /* No flags */
+#define ST_DEFINED 0x01 /* Scope has been defined */
+
/* A symbol table */
typedef struct SymTable SymTable;
struct SymTable {
SymTable* Right; /* Pointer to greater entry */
SymTable* Parent; /* Link to enclosing scope if any */
SymTable* Childs; /* Pointer to child scopes */
+ unsigned short Flags; /* Symbol table flags */
unsigned char AddrSize; /* Address size */
unsigned char Type; /* Type of the scope */
unsigned Level; /* Lexical level */
/* */
/* */
/* (C) 2000-2003 Ullrich von Bassewitz */
-/* Römerstrasse 52 */
+/* Römerstraße 52 */
/* D-70794 Filderstadt */
/* EMail: uz@cc65.org */
/* */
}
if (L == 0) {
/* Label does not exist */
- Error (ERR_UNDEFINED_LABEL);
+ Error ("Undefined label");
/* We must return something valid */
return GenCurrentPC();
} else {
if (ULabLastDef) {
L = ULabLastDef->Next;
while (L) {
- PError (&L->Pos, ERR_UNDEFINED_LABEL);
+ PError (&L->Pos, "Undefined label");
L = L->Next;
}
}