-Os Inline some known functions
-T Include source as comment
-V Print the compiler version number
- -W Suppress warnings
+ -W name[,name] Enable or disable warnings
-d Debug mode
-g Add debug info to object file
-h Help (this text)
Tells the compiler to generate code that checks for stack overflows. See
<tt><ref id="pragma-checkstack" name="#pragma checkstack"></tt> for an
explanation of this feature.
-
+
<tag><tt>--code-name seg</tt></tag>
<label id="option-W">
- <tag><tt>-W</tt></tag>
-
- This option will suppress any warnings generated by the compiler. Since
- any source file may be written in a manner that it will not produce
- compiler warnings, using this option is usually not a good idea.
+ <tag><tt>-W name[,name]</tt></tag>
+
+ This option allows to control warnings generated by the compiler. It is
+ followed by a comma separated list of warnings that should be enabled or
+ disabled. To disable a warning, its name is prefixed by a minus sign. If
+ no such prefix exists, or the name is prefixed by a plus sign, the warning
+ is enabled.
+
+ The following warning names are currently recognized:
+ <descrip>
+ <tag><tt/error/</tag>
+ Treat all warnings as errors.
+ <tag><tt/unknown-pragma/</tag>
+ Warn about known #pragmas.
+ <tag><tt/unused-label/</tag>
+ Warn about unused labels.
+ <tag><tt/unused-param/</tag>
+ Warn about unused function parameters.
+ <tag><tt/unused-var/</tag>
+ Warn about unused variables.
+ </descrip>
</descrip><p>
the same base name, but with the extension replaced by ".s". The output
file contains assembler code suitable for the use with the ca65 macro
assembler.
-
+
Include files in single quotes are searched in the following places:
<enum>
<item>The current directory.
<item>A compiled in directory which is often <tt>/usr/lib/cc65/include</tt> on
Linux systems.
<item>The value of the environment variable <tt/CC65_INC/ if it is defined.
-<item>A subdirectory named <tt/include/ of the directory defined in the
+<item>A subdirectory named <tt/include/ of the directory defined in the
environment variable <tt/CC65_HOME/, if it is defined.
<item>Any directory added with the <tt/-I/ option on the command line.
</enum>
unsigned ErrorCount = 0;
unsigned WarningCount = 0;
+/* Warning and error options */
+IntStack WarnEnable = INTSTACK(1); /* Enable warnings */
+IntStack WarningsAreErrors = INTSTACK(0); /* Treat warnings as errors */
+IntStack WarnUnusedLabel = INTSTACK(1); /* Warn about unused labels */
+IntStack WarnUnusedParam = INTSTACK(1); /* Warn about unused parameters */
+IntStack WarnUnusedVar = INTSTACK(1); /* Warn about unused variables */
+IntStack WarnUnknownPragma = INTSTACK(1); /* Warn about unknown #pragmas */
+
+/* Map the name of a warning to the intstack that holds its state */
+typedef struct WarnMapEntry WarnMapEntry;
+struct WarnMapEntry {
+ IntStack* Stack;
+ const char* Name;
+};
+static WarnMapEntry WarnMap[] = {
+ /* Keep sorted, even if this isn't used for now */
+ { &WarningsAreErrors, "error" },
+ { &WarnUnknownPragma, "unknown-pragma" },
+ { &WarnUnusedLabel, "unused-label" },
+ { &WarnUnusedParam, "unused-param" },
+ { &WarnUnusedVar, "unused-var" },
+};
+
/*****************************************************************************/
-/* Code */
+/* Handling of fatal errors */
/*****************************************************************************/
-static void IntWarning (const char* Filename, unsigned LineNo, const char* Msg, va_list ap)
-/* Print warning message - internal function. */
+void Fatal (const char* Format, ...)
+/* Print a message about a fatal error and die */
{
- if (!IS_Get (&WarnDisable)) {
- fprintf (stderr, "%s(%u): Warning: ", Filename, LineNo);
- vfprintf (stderr, Msg, ap);
- fprintf (stderr, "\n");
+ va_list ap;
- if (Line) {
- Print (stderr, 1, "Input: %.*s\n", (int) SB_GetLen (Line), SB_GetConstBuf (Line));
- }
- ++WarningCount;
+ const char* FileName;
+ unsigned LineNum;
+ if (CurTok.LI) {
+ FileName = GetInputName (CurTok.LI);
+ LineNum = GetInputLine (CurTok.LI);
+ } else {
+ FileName = GetCurrentFile ();
+ LineNum = GetCurrentLine ();
}
-}
-
+ fprintf (stderr, "%s(%u): Fatal: ", FileName, LineNum);
-void Warning (const char* Format, ...)
-/* Print warning message. */
-{
- va_list ap;
va_start (ap, Format);
- IntWarning (GetInputName (CurTok.LI), GetInputLine (CurTok.LI), Format, ap);
+ vfprintf (stderr, Format, ap);
va_end (ap);
+ fprintf (stderr, "\n");
+
+ if (Line) {
+ Print (stderr, 1, "Input: %.*s\n", (int) SB_GetLen (Line), SB_GetConstBuf (Line));
+ }
+ exit (EXIT_FAILURE);
}
-void LIWarning (const LineInfo* LI, const char* Format, ...)
-/* Print a warning message with the line info given explicitly */
+void Internal (const char* Format, ...)
+/* Print a message about an internal compiler error and die. */
{
va_list ap;
- va_start (ap, Format);
- IntWarning (GetInputName (LI), GetInputLine (LI), Format, ap);
- va_end (ap);
-}
+ const char* FileName;
+ unsigned LineNum;
+ if (CurTok.LI) {
+ FileName = GetInputName (CurTok.LI);
+ LineNum = GetInputLine (CurTok.LI);
+ } else {
+ FileName = GetCurrentFile ();
+ LineNum = GetCurrentLine ();
+ }
+ fprintf (stderr, "%s(%u): Internal compiler error:\n",
+ FileName, LineNum);
-void PPWarning (const char* Format, ...)
-/* Print warning message. For use within the preprocessor. */
-{
- va_list ap;
va_start (ap, Format);
- IntWarning (GetCurrentFile(), GetCurrentLine(), Format, ap);
+ vfprintf (stderr, Format, ap);
va_end (ap);
+ fprintf (stderr, "\n");
+
+ if (Line) {
+ fprintf (stderr, "\nInput: %.*s\n", (int) SB_GetLen (Line), SB_GetConstBuf (Line));
+ }
+
+ /* Use abort to create a core dump */
+ abort ();
}
+/*****************************************************************************/
+/* Handling of errors */
+/*****************************************************************************/
+
+
+
static void IntError (const char* Filename, unsigned LineNo, const char* Msg, va_list ap)
/* Print an error message - internal function*/
{
-void Fatal (const char* Format, ...)
-/* Print a message about a fatal error and die */
+/*****************************************************************************/
+/* Handling of warnings */
+/*****************************************************************************/
+
+
+
+static void IntWarning (const char* Filename, unsigned LineNo, const char* Msg, va_list ap)
+/* Print warning message - internal function. */
{
- va_list ap;
+ if (IS_Get (&WarningsAreErrors)) {
+
+ /* Treat the warning as an error */
+ IntError (Filename, LineNo, Msg, ap);
+
+ } else if (IS_Get (&WarnEnable)) {
+
+ fprintf (stderr, "%s(%u): Warning: ", Filename, LineNo);
+ vfprintf (stderr, Msg, ap);
+ fprintf (stderr, "\n");
+
+ if (Line) {
+ Print (stderr, 1, "Input: %.*s\n", (int) SB_GetLen (Line), SB_GetConstBuf (Line));
+ }
+ ++WarningCount;
- const char* FileName;
- unsigned LineNum;
- if (CurTok.LI) {
- FileName = GetInputName (CurTok.LI);
- LineNum = GetInputLine (CurTok.LI);
- } else {
- FileName = GetCurrentFile ();
- LineNum = GetCurrentLine ();
}
+}
- fprintf (stderr, "%s(%u): Fatal: ", FileName, LineNum);
+
+void Warning (const char* Format, ...)
+/* Print warning message. */
+{
+ va_list ap;
va_start (ap, Format);
- vfprintf (stderr, Format, ap);
+ IntWarning (GetInputName (CurTok.LI), GetInputLine (CurTok.LI), Format, ap);
va_end (ap);
- fprintf (stderr, "\n");
-
- if (Line) {
- Print (stderr, 1, "Input: %.*s\n", (int) SB_GetLen (Line), SB_GetConstBuf (Line));
- }
- exit (EXIT_FAILURE);
}
-void Internal (const char* Format, ...)
-/* Print a message about an internal compiler error and die. */
+void LIWarning (const LineInfo* LI, const char* Format, ...)
+/* Print a warning message with the line info given explicitly */
{
va_list ap;
+ va_start (ap, Format);
+ IntWarning (GetInputName (LI), GetInputLine (LI), Format, ap);
+ va_end (ap);
+}
- const char* FileName;
- unsigned LineNum;
- if (CurTok.LI) {
- FileName = GetInputName (CurTok.LI);
- LineNum = GetInputLine (CurTok.LI);
- } else {
- FileName = GetCurrentFile ();
- LineNum = GetCurrentLine ();
- }
- fprintf (stderr, "%s(%u): Internal compiler error:\n",
- FileName, LineNum);
+void PPWarning (const char* Format, ...)
+/* Print warning message. For use within the preprocessor. */
+{
+ va_list ap;
va_start (ap, Format);
- vfprintf (stderr, Format, ap);
+ IntWarning (GetCurrentFile(), GetCurrentLine(), Format, ap);
va_end (ap);
- fprintf (stderr, "\n");
+}
- if (Line) {
- fprintf (stderr, "\nInput: %.*s\n", (int) SB_GetLen (Line), SB_GetConstBuf (Line));
- }
- /* Use abort to create a core dump */
- abort ();
+
+IntStack* FindWarning (const char* Name)
+/* Search for a warning in the WarnMap table and return a pointer to the
+ * intstack that holds its state. Return NULL if there is no such warning.
+ */
+{
+ unsigned I;
+
+ /* For now, do a linear search */
+ for (I = 0; I < sizeof(WarnMap) / sizeof (WarnMap[0]); ++I) {
+ if (strcmp (WarnMap[I].Name, Name) == 0) {
+ return WarnMap[I].Stack;
+ }
+ }
+ return 0;
}
+/*****************************************************************************/
+/* Code */
+/*****************************************************************************/
+
+
+
void ErrorReport (void)
/* Report errors (called at end of compile) */
{
/* */
/* */
/* */
-/* (C) 1998-2000 Ullrich von Bassewitz */
-/* Wacholderweg 14 */
-/* D-70597 Stuttgart */
-/* EMail: uz@musoftware.de */
+/* (C) 1998-2009, Ullrich von Bassewitz */
+/* Roemerstrasse 52 */
+/* D-70794 Filderstadt */
+/* EMail: uz@cc65.org */
/* */
/* */
/* This software is provided 'as-is', without any expressed or implied */
/* common */
#include "attrib.h"
+#include "intstack.h"
/* cc65 */
#include "lineinfo.h"
extern unsigned ErrorCount;
extern unsigned WarningCount;
+/* Warning and error options */
+extern IntStack WarnEnable; /* Enable warnings */
+extern IntStack WarningsAreErrors; /* Treat warnings as errors */
+extern IntStack WarnUnusedLabel; /* Warn about unused labels */
+extern IntStack WarnUnusedParam; /* Warn about unused parameters */
+extern IntStack WarnUnusedVar; /* Warn about unused variables */
+extern IntStack WarnUnknownPragma; /* Warn about unknown #pragmas */
+
/*****************************************************************************/
-void Warning (const char* Format, ...) attribute ((format (printf, 1, 2)));
-/* Print warning message. */
-
-void LIWarning (const LineInfo* LI, const char* Format, ...) attribute ((format (printf, 2, 3)));
-/* Print a warning message with the line info given explicitly */
+void Fatal (const char* Format, ...) attribute ((noreturn, format (printf, 1, 2)));
+/* Print a message about a fatal error and die */
-void PPWarning (const char* Format, ...) attribute ((format (printf, 1, 2)));
-/* Print warning message. For use within the preprocessor. */
+void Internal (const char* Format, ...) attribute ((noreturn, format (printf, 1, 2)));
+/* Print a message about an internal compiler error and die. */
void Error (const char* Format, ...) attribute ((format (printf, 1, 2)));
/* Print an error message */
void PPError (const char* Format, ...) attribute ((format (printf, 1, 2)));
/* Print an error message. For use within the preprocessor. */
-void Fatal (const char* Format, ...) attribute ((noreturn, format (printf, 1, 2)));
-/* Print a message about a fatal error and die */
+void Warning (const char* Format, ...) attribute ((format (printf, 1, 2)));
+/* Print warning message. */
-void Internal (const char* Format, ...) attribute ((noreturn, format (printf, 1, 2)));
-/* Print a message about an internal compiler error and die. */
+void LIWarning (const LineInfo* LI, const char* Format, ...) attribute ((format (printf, 2, 3)));
+/* Print a warning message with the line info given explicitly */
+
+void PPWarning (const char* Format, ...) attribute ((format (printf, 1, 2)));
+/* Print warning message. For use within the preprocessor. */
+
+IntStack* FindWarning (const char* Name);
+/* Search for a warning in the WarnMap table and return a pointer to the
+ * intstack that holds its state. Return NULL if there is no such warning.
+ */
void ErrorReport (void);
/* Report errors (called at end of compile) */
/* */
/* */
/* */
-/* (C) 1998-2004 Ullrich von Bassewitz */
-/* Römerstraße 52 */
-/* D-70794 Filderstadt */
-/* EMail: uz@cc65.org */
+/* (C) 1998-2009, Ullrich von Bassewitz */
+/* Roemerstrasse 52 */
+/* D-70794 Filderstadt */
+/* EMail: uz@cc65.org */
/* */
/* */
/* This software is provided 'as-is', without any expressed or implied */
unsigned RegisterSpace = 6; /* Space available for register vars */
/* Stackable options */
-IntStack WarnDisable = INTSTACK(0); /* Suppress warnings */
IntStack WritableStrings = INTSTACK(0); /* Literal strings are r/w */
IntStack InlineStdFuncs = INTSTACK(0); /* Inline some known functions */
IntStack EnableRegVars = INTSTACK(0); /* Enable register variables */
/* */
/* */
/* */
-/* (C) 1998-2004 Ullrich von Bassewitz */
-/* Römerstraße 52 */
-/* D-70794 Filderstadt */
-/* EMail: uz@cc65.org */
+/* (C) 1998-2009, Ullrich von Bassewitz */
+/* Roemerstrasse 52 */
+/* D-70794 Filderstadt */
+/* EMail: uz@cc65.org */
/* */
/* */
/* This software is provided 'as-is', without any expressed or implied */
extern unsigned RegisterSpace; /* Space available for register vars */
/* Stackable options */
-extern IntStack WarnDisable; /* Suppress warnings */
extern IntStack WritableStrings; /* Literal strings are r/w */
extern IntStack InlineStdFuncs; /* Inline some known functions */
extern IntStack EnableRegVars; /* Enable register variables */
#include "mmodel.h"
#include "print.h"
#include "segnames.h"
+#include "strbuf.h"
#include "target.h"
#include "tgttrans.h"
#include "version.h"
/* Numeric argument expected */
if (sscanf (Arg, "%u%c", &Factor, &BoundsCheck) != 1 ||
Factor < 10 || Factor > 1000) {
- InvArg (Opt, Arg);
+ AbEnd ("Argument for %s is invalid", Opt);
}
IS_Set (&CodeSizeFactor, Factor);
}
CPU = FindCPU (Arg);
if (CPU != CPU_6502 && CPU != CPU_6502X && CPU != CPU_65SC02 &&
CPU != CPU_65C02 && CPU != CPU_65816 && CPU != CPU_HUC6280) {
- InvArg (Opt, Arg);
+ AbEnd ("Invalid argument for %s: `%s'", Opt, Arg);
}
}
{
/* Numeric argument expected */
if (sscanf (Arg, "%u", &RegisterSpace) != 1 || RegisterSpace > 256) {
- InvArg (Opt, Arg);
+ AbEnd ("Argument for option %s is invalid", Opt);
}
}
/* Find the standard from the given name */
standard_t Std = FindStandard (Arg);
if (Std == STD_UNKNOWN) {
- InvArg (Opt, Arg);
+ AbEnd ("Invalid argument for %s: `%s'", Opt, Arg);
} else if (IS_Get (&Standard) != STD_UNKNOWN) {
AbEnd ("Option %s given more than once", Opt);
} else {
+static void OptWarning (const char* Opt attribute ((unused)), const char* Arg)
+/* Handle the -W option */
+{
+ StrBuf W = AUTO_STRBUF_INITIALIZER;
+
+ /* Arg is a list of suboptions, separated by commas */
+ while (Arg) {
+
+ const char* Pos;
+ int Enabled = 1;
+ IntStack* S;
+
+ /* The suboption may be prefixed with '-' or '+' */
+ if (*Arg == '-') {
+ Enabled = 0;
+ ++Arg;
+ } else if (*Arg == '+') {
+ /* This is the default */
+ ++Arg;
+ }
+
+ /* Get the next suboption */
+ Pos = strchr (Arg, ',');
+ if (Pos) {
+ SB_CopyBuf (&W, Arg, Pos - Arg);
+ Arg = Pos + 1;
+ } else {
+ SB_CopyStr (&W, Arg);
+ Arg = 0;
+ }
+ SB_Terminate (&W);
+
+ /* Search for the warning */
+ S = FindWarning (SB_GetConstBuf (&W));
+ if (S == 0) {
+ InvArg (Opt, SB_GetConstBuf (&W));
+ }
+ IS_Set (S, Enabled);
+ }
+
+ /* Free allocated memory */
+ SB_Done (&W);
+}
+
+
+
static void OptWritableStrings (const char* Opt attribute ((unused)),
const char* Arg attribute ((unused)))
/* Make string literals writable */
const char* Arg = ArgVec[I];
/* Check for an option */
- if (Arg [0] == '-') {
+ if (Arg[0] == '-') {
- switch (Arg [1]) {
+ switch (Arg[1]) {
case '-':
LongOption (&I, OptTab, sizeof(OptTab)/sizeof(OptTab[0]));
default:
UnknownOption (Arg);
break;
- }
+ }
}
break;
break;
case 'W':
- IS_Set (&WarnDisable, 1);
+ OptWarning (Arg, GetArg (&I, 2));
break;
default:
/* */
/* */
/* */
-/* (C) 1998-2008 Ullrich von Bassewitz */
-/* Roemerstrasse 52 */
-/* D-70794 Filderstadt */
-/* EMail: uz@cc65.org */
+/* (C) 1998-2009, Ullrich von Bassewitz */
+/* Roemerstrasse 52 */
+/* D-70794 Filderstadt */
+/* EMail: uz@cc65.org */
/* */
/* */
/* This software is provided 'as-is', without any expressed or implied */
break;
case PR_WARN:
- FlagPragma (&B, &WarnDisable);
+ FlagPragma (&B, &WarnEnable);
break;
case PR_ZPSYM:
if (((Flags & SC_AUTO) || (Flags & SC_STATIC)) && (Flags & SC_EXTERN) == 0) {
if (SymIsDef (Entry) && !SymIsRef (Entry)) {
if (Flags & SC_PARAM) {
- Warning ("Parameter `%s' is never used", Entry->Name);
+ if (IS_Get (&WarnUnusedParam)) {
+ Warning ("Parameter `%s' is never used", Entry->Name);
+ }
} else {
- Warning ("`%s' is defined but never used", Entry->Name);
+ if (IS_Get (&WarnUnusedVar)) {
+ Warning ("`%s' is defined but never used", Entry->Name);
+ }
}
}
}
/* Undefined label */
Error ("Undefined label: `%s'", Entry->Name);
} else if (!SymIsRef (Entry)) {
- /* Defined but not used */
- Warning ("`%s' is defined but never used", Entry->Name);
+ /* Defined but not used */
+ if (IS_Get (&WarnUnusedLabel)) {
+ Warning ("`%s' is defined but never used", Entry->Name);
+ }
}
}