static int opt_option_handler(char *cmd, /*@null@*/ char *param, int extra);
static int opt_format_handler(char *cmd, /*@null@*/ char *param, int extra);
static int opt_objfile_handler(char *cmd, /*@null@*/ char *param, int extra);
+static int opt_warning_handler(char *cmd, /*@null@*/ char *param, int extra);
/* Fake handlers: remove them */
static int boo_boo_handler(char *cmd, /*@null@*/ char *param, int extra);
static int b_handler(char *cmd, /*@null@*/ char *param, int extra);
{ 'h', "help", 0, opt_option_handler, OPT_SHOW_HELP, "show help text", NULL },
{ 'f', "oformat", 1, opt_format_handler, 0, "select output format", "<format>" },
{ 'o', "objfile", 1, opt_objfile_handler, 0, "name of object-file output", "<filename>" },
+ { 'w', NULL, 0, opt_warning_handler, 1, "inhibits warning messages", NULL },
+ { 'W', NULL, 0, opt_warning_handler, 0, "enables/disables warning", NULL },
/* Fake handlers: remove them */
{ 'b', NULL, 0, b_handler, 0, "says boom!", NULL },
{ 0, "boo-boo", 0, boo_boo_handler, 0, "says boo-boo!", NULL },
return 0;
}
+static int
+opt_warning_handler(char *cmd, /*@unused@*/ char *param, int extra)
+{
+ int enable = 1; /* is it disabling the warning instead of enabling? */
+
+ if (extra == 1) {
+ /* -w, disable warnings */
+ warnings_disabled = 1;
+ return 0;
+ }
+
+ /* skip past 'W' */
+ cmd++;
+
+ /* detect no- prefix to disable the warning */
+ if (cmd[0] == 'n' && cmd[1] == 'o' && cmd[2] == '-') {
+ enable = 0;
+ cmd += 3; /* skip past it to get to the warning name */
+ }
+
+ if (cmd[0] == '\0')
+ /* just -W or -Wno-, so definitely not valid */
+ return 1;
+ else if (strcmp(cmd, "error") == 0) {
+ warning_error = enable;
+ } else if (strcmp(cmd, "unrecognized-char") == 0) {
+ WARN_ENABLE(WARN_UNRECOGNIZED_CHAR, enable);
+ } else
+ return 1;
+
+ return 0;
+}
+
/* Fake handlers: remove them */
static int
boo_boo_handler(/*@unused@*/ char *cmd, /*@unused@*/ char *param,
#include "errwarn.h"
+/* ALL warnings are disabled if this is nonzero. */
+int warnings_disabled = 0;
+
+/* Warnings are treated as errors if this is nonzero.
+ * =2 indicates that warnings are treated as errors, and the message to the
+ * user saying that has been output.
+ */
+int warning_error = 0;
+
+/* Default enabled warnings. See errwarn.h for a list. */
+unsigned long warning_flags =
+ (1<<WARN_UNRECOGNIZED_CHAR);
+
/* Total error count for entire assembler run.
* Assembler should exit with EXIT_FAILURE if this is >= 0 on finish. */
static unsigned int error_count = 0;
va_list ap;
errwarn *we;
+ if (warnings_disabled)
+ return;
+
if (previous_warning_line == line_index)
return;
{
va_list ap;
+ if (warnings_disabled)
+ return;
+
fprintf(stderr, "%s ", _("warning:"));
va_start(ap, fmt);
vfprintf(stderr, fmt, ap);
const char *filename;
unsigned long line;
+ if (warnings_disabled)
+ return;
+
line_lookup(lindex, &filename, &line);
fprintf(stderr, "%s:%lu: %s ", filename?filename:"NULL", line,
_("warning:"));
unsigned long line;
/* If errwarns hasn't been initialized, there are no messages. */
- if (!errwarns)
- return error_count;
+ if (!errwarns) {
+ if (warning_error)
+ return error_count+warning_count;
+ else
+ return error_count;
+ }
+
+ /* If we're treating warnings as errors, tell the user about it. */
+ if (warning_error && warning_error != 2) {
+ fprintf(stderr, "%s\n", _("warnings being treated as errors"));
+ warning_error = 2;
+ }
/* Output error and warning messages. */
STAILQ_FOREACH(we, errwarns, link) {
we = we2;
}
- /* Return the total error count up to this point. */
+ /* Return the total error count up to this point.
+ * If we're treating warnings as errors, add that to the total as well.
+ */
+ if (warning_error)
+ return error_count+warning_count;
return error_count;
}
#ifndef YASM_ERRWARN_H
#define YASM_ERRWARN_H
+/* ALL warnings disabled? */
+extern int warnings_disabled;
+
+/* Warnings treated as errors? */
+extern int warning_error;
+
+/* Warning flags. Currently a maximum of 32 are allowed. This can be
+ * increased by making this an array and modifying the WARN_ macros to use the
+ * proper array index based on the warning number.
+ *
+ * If a bit is 1, it means that particular warning is enabled. The bit numbers
+ * are assigned according to the warn_flag_num enum.
+ *
+ * See errwarn.c for what warnings are enabled by default.
+ */
+extern unsigned long warning_flags;
+typedef enum {
+ WARN_UNRECOGNIZED_CHAR = 0
+} warn_flag_num;
+
+/* Tests the warning flags to see if warning "warn" is enabled */
+#define WARN_ENABLED(warn) (warning_flags & (1<<(warn)))
+/* Sets warning "warn" to be enabled or disabled based on "s" (1=en, 0=dis). */
+#define WARN_ENABLE(warn, s) do { \
+ warning_flags &= ~(1<<(warn)); \
+ warning_flags |= (s)<<(warn); \
+ } while(0)
+
/* Fatal error constants.
* See fatal_msgs in errwarn.c for strings that match up to these constants.
* When adding a constant here, keep errwarn.c in sync! */
return DIRECTIVE_NAME;
}
<DIRECTIVE>. {
- Warning(_("ignoring unrecognized character `%s'"),
- conv_unprint(yytext[0]));
+ if (WARN_ENABLED(WARN_UNRECOGNIZED_CHAR))
+ Warning(_("ignoring unrecognized character `%s'"),
+ conv_unprint(yytext[0]));
}
/* override local labels in directive state */
\n return '\n';
. {
- Warning(_("ignoring unrecognized character `%s'"),
- conv_unprint(yytext[0]));
+ if (WARN_ENABLED(WARN_UNRECOGNIZED_CHAR))
+ Warning(_("ignoring unrecognized character `%s'"),
+ conv_unprint(yytext[0]));
}
#include "errwarn.h"
+/* ALL warnings are disabled if this is nonzero. */
+int warnings_disabled = 0;
+
+/* Warnings are treated as errors if this is nonzero.
+ * =2 indicates that warnings are treated as errors, and the message to the
+ * user saying that has been output.
+ */
+int warning_error = 0;
+
+/* Default enabled warnings. See errwarn.h for a list. */
+unsigned long warning_flags =
+ (1<<WARN_UNRECOGNIZED_CHAR);
+
/* Total error count for entire assembler run.
* Assembler should exit with EXIT_FAILURE if this is >= 0 on finish. */
static unsigned int error_count = 0;
va_list ap;
errwarn *we;
+ if (warnings_disabled)
+ return;
+
if (previous_warning_line == line_index)
return;
{
va_list ap;
+ if (warnings_disabled)
+ return;
+
fprintf(stderr, "%s ", _("warning:"));
va_start(ap, fmt);
vfprintf(stderr, fmt, ap);
const char *filename;
unsigned long line;
+ if (warnings_disabled)
+ return;
+
line_lookup(lindex, &filename, &line);
fprintf(stderr, "%s:%lu: %s ", filename?filename:"NULL", line,
_("warning:"));
unsigned long line;
/* If errwarns hasn't been initialized, there are no messages. */
- if (!errwarns)
- return error_count;
+ if (!errwarns) {
+ if (warning_error)
+ return error_count+warning_count;
+ else
+ return error_count;
+ }
+
+ /* If we're treating warnings as errors, tell the user about it. */
+ if (warning_error && warning_error != 2) {
+ fprintf(stderr, "%s\n", _("warnings being treated as errors"));
+ warning_error = 2;
+ }
/* Output error and warning messages. */
STAILQ_FOREACH(we, errwarns, link) {
we = we2;
}
- /* Return the total error count up to this point. */
+ /* Return the total error count up to this point.
+ * If we're treating warnings as errors, add that to the total as well.
+ */
+ if (warning_error)
+ return error_count+warning_count;
return error_count;
}
#ifndef YASM_ERRWARN_H
#define YASM_ERRWARN_H
+/* ALL warnings disabled? */
+extern int warnings_disabled;
+
+/* Warnings treated as errors? */
+extern int warning_error;
+
+/* Warning flags. Currently a maximum of 32 are allowed. This can be
+ * increased by making this an array and modifying the WARN_ macros to use the
+ * proper array index based on the warning number.
+ *
+ * If a bit is 1, it means that particular warning is enabled. The bit numbers
+ * are assigned according to the warn_flag_num enum.
+ *
+ * See errwarn.c for what warnings are enabled by default.
+ */
+extern unsigned long warning_flags;
+typedef enum {
+ WARN_UNRECOGNIZED_CHAR = 0
+} warn_flag_num;
+
+/* Tests the warning flags to see if warning "warn" is enabled */
+#define WARN_ENABLED(warn) (warning_flags & (1<<(warn)))
+/* Sets warning "warn" to be enabled or disabled based on "s" (1=en, 0=dis). */
+#define WARN_ENABLE(warn, s) do { \
+ warning_flags &= ~(1<<(warn)); \
+ warning_flags |= (s)<<(warn); \
+ } while(0)
+
/* Fatal error constants.
* See fatal_msgs in errwarn.c for strings that match up to these constants.
* When adding a constant here, keep errwarn.c in sync! */
static int opt_option_handler(char *cmd, /*@null@*/ char *param, int extra);
static int opt_format_handler(char *cmd, /*@null@*/ char *param, int extra);
static int opt_objfile_handler(char *cmd, /*@null@*/ char *param, int extra);
+static int opt_warning_handler(char *cmd, /*@null@*/ char *param, int extra);
/* Fake handlers: remove them */
static int boo_boo_handler(char *cmd, /*@null@*/ char *param, int extra);
static int b_handler(char *cmd, /*@null@*/ char *param, int extra);
{ 'h', "help", 0, opt_option_handler, OPT_SHOW_HELP, "show help text", NULL },
{ 'f', "oformat", 1, opt_format_handler, 0, "select output format", "<format>" },
{ 'o', "objfile", 1, opt_objfile_handler, 0, "name of object-file output", "<filename>" },
+ { 'w', NULL, 0, opt_warning_handler, 1, "inhibits warning messages", NULL },
+ { 'W', NULL, 0, opt_warning_handler, 0, "enables/disables warning", NULL },
/* Fake handlers: remove them */
{ 'b', NULL, 0, b_handler, 0, "says boom!", NULL },
{ 0, "boo-boo", 0, boo_boo_handler, 0, "says boo-boo!", NULL },
return 0;
}
+static int
+opt_warning_handler(char *cmd, /*@unused@*/ char *param, int extra)
+{
+ int enable = 1; /* is it disabling the warning instead of enabling? */
+
+ if (extra == 1) {
+ /* -w, disable warnings */
+ warnings_disabled = 1;
+ return 0;
+ }
+
+ /* skip past 'W' */
+ cmd++;
+
+ /* detect no- prefix to disable the warning */
+ if (cmd[0] == 'n' && cmd[1] == 'o' && cmd[2] == '-') {
+ enable = 0;
+ cmd += 3; /* skip past it to get to the warning name */
+ }
+
+ if (cmd[0] == '\0')
+ /* just -W or -Wno-, so definitely not valid */
+ return 1;
+ else if (strcmp(cmd, "error") == 0) {
+ warning_error = enable;
+ } else if (strcmp(cmd, "unrecognized-char") == 0) {
+ WARN_ENABLE(WARN_UNRECOGNIZED_CHAR, enable);
+ } else
+ return 1;
+
+ return 0;
+}
+
/* Fake handlers: remove them */
static int
boo_boo_handler(/*@unused@*/ char *cmd, /*@unused@*/ char *param,
return DIRECTIVE_NAME;
}
<DIRECTIVE>. {
- Warning(_("ignoring unrecognized character `%s'"),
- conv_unprint(yytext[0]));
+ if (WARN_ENABLED(WARN_UNRECOGNIZED_CHAR))
+ Warning(_("ignoring unrecognized character `%s'"),
+ conv_unprint(yytext[0]));
}
/* override local labels in directive state */
\n return '\n';
. {
- Warning(_("ignoring unrecognized character `%s'"),
- conv_unprint(yytext[0]));
+ if (WARN_ENABLED(WARN_UNRECOGNIZED_CHAR))
+ Warning(_("ignoring unrecognized character `%s'"),
+ conv_unprint(yytext[0]));
}