0
0
mirror of https://github.com/netwide-assembler/nasm.git synced 2025-09-22 10:43:39 -04:00

error: Style liftup

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
This commit is contained in:
Cyrill Gorcunov
2018-11-24 18:58:11 +03:00
parent 85261a2b57
commit 3351072306
2 changed files with 166 additions and 163 deletions

View File

@@ -47,92 +47,94 @@
* the [warning] directive. * the [warning] directive.
*/ */
const struct warning warnings[ERR_WARN_ALL+1] = { const struct warning warnings[ERR_WARN_ALL+1] = {
{"other", "any warning not specifially mentioned below", true}, { "other", "any warning not specifially mentioned below", true },
{"macro-params", "macro calls with wrong parameter count", true}, { "macro-params", "macro calls with wrong parameter count", true },
{"macro-selfref", "cyclic macro references", false}, { "macro-selfref", "cyclic macro references", false },
{"macro-defaults", "macros with more default than optional parameters", true}, { "macro-defaults", "macros with more default than optional parameters", true },
{"orphan-labels", "labels alone on lines without trailing `:'", true}, { "orphan-labels", "labels alone on lines without trailing `:'", true },
{"number-overflow", "numeric constant does not fit", true}, { "number-overflow", "numeric constant does not fit", true },
{"gnu-elf-extensions", "using 8- or 16-bit relocation in ELF32, a GNU extension", false}, { "gnu-elf-extensions", "using 8- or 16-bit relocation in ELF32, a GNU extension", false },
{"float-overflow", "floating point overflow", true}, { "float-overflow", "floating point overflow", true },
{"float-denorm", "floating point denormal", false}, { "float-denorm", "floating point denormal", false },
{"float-underflow", "floating point underflow", false}, { "float-underflow", "floating point underflow", false },
{"float-toolong", "too many digits in floating-point number", true}, { "float-toolong", "too many digits in floating-point number", true },
{"user", "%warning directives", true}, { "user", "%warning directives", true },
{"lock", "lock prefix on unlockable instructions", true}, { "lock", "lock prefix on unlockable instructions", true },
{"hle", "invalid hle prefixes", true}, { "hle", "invalid hle prefixes", true },
{"bnd", "invalid bnd prefixes", true}, { "bnd", "invalid bnd prefixes", true },
{"zext-reloc", "relocation zero-extended to match output format", true}, { "zext-reloc", "relocation zero-extended to match output format", true },
{"ptr", "non-NASM keyword used in other assemblers", true}, { "ptr", "non-NASM keyword used in other assemblers", true },
{"bad-pragma", "empty or malformed %pragma", false}, { "bad-pragma", "empty or malformed %pragma", false },
{"unknown-pragma", "unknown %pragma facility or directive", false}, { "unknown-pragma", "unknown %pragma facility or directive", false },
{"not-my-pragma", "%pragma not applicable to this compilation", false}, { "not-my-pragma", "%pragma not applicable to this compilation", false },
{"unknown-warning", "unknown warning in -W/-w or warning directive", false}, { "unknown-warning", "unknown warning in -W/-w or warning directive", false },
{"negative-rep", "regative %rep count", true}, { "negative-rep", "regative %rep count", true },
{"phase", "phase error during stabilization", false}, { "phase", "phase error during stabilization", false },
/* THIS ENTRY MUST COME LAST */ /* THIS ENTRY MUST COME LAST */
{"all", "all possible warnings", false} { "all", "all possible warnings", false }
}; };
uint8_t warning_state[ERR_WARN_ALL];/* Current state */ /* Current state and command-line state, for reset */
uint8_t warning_state_init[ERR_WARN_ALL]; /* Command-line state, for reset */ uint8_t warning_state[ERR_WARN_ALL];
uint8_t warning_state_init[ERR_WARN_ALL];
vefunc nasm_verror; /* Global error handling function */ /* Global error handling function */
vefunc nasm_verror;
void nasm_error(int severity, const char *fmt, ...) void nasm_error(int severity, const char *fmt, ...)
{ {
va_list ap; va_list ap;
va_start(ap, fmt); va_start(ap, fmt);
nasm_verror(severity, fmt, ap); nasm_verror(severity, fmt, ap);
va_end(ap); va_end(ap);
} }
fatal_func nasm_fatal(const char *fmt, ...) fatal_func nasm_fatal(const char *fmt, ...)
{ {
va_list ap; va_list ap;
va_start(ap, fmt); va_start(ap, fmt);
nasm_verror(ERR_FATAL, fmt, ap); nasm_verror(ERR_FATAL, fmt, ap);
abort(); /* We should never get here */ abort();
} }
fatal_func nasm_fatal_fl(int flags, const char *fmt, ...) fatal_func nasm_fatal_fl(int flags, const char *fmt, ...)
{ {
va_list ap; va_list ap;
va_start(ap, fmt); va_start(ap, fmt);
nasm_verror(flags | ERR_FATAL, fmt, ap); nasm_verror(flags | ERR_FATAL, fmt, ap);
abort(); /* We should never get here */ abort();
} }
fatal_func nasm_panic(const char *fmt, ...) fatal_func nasm_panic(const char *fmt, ...)
{ {
va_list ap; va_list ap;
va_start(ap, fmt); va_start(ap, fmt);
nasm_verror(ERR_PANIC, fmt, ap); nasm_verror(ERR_PANIC, fmt, ap);
abort(); /* We should never get here */ abort();
} }
fatal_func nasm_panic_fl(int flags, const char *fmt, ...) fatal_func nasm_panic_fl(int flags, const char *fmt, ...)
{ {
va_list ap; va_list ap;
va_start(ap, fmt); va_start(ap, fmt);
nasm_verror(flags | ERR_PANIC, fmt, ap); nasm_verror(flags | ERR_PANIC, fmt, ap);
abort(); /* We should never get here */ abort();
} }
fatal_func nasm_panic_from_macro(const char *file, int line) fatal_func nasm_panic_from_macro(const char *file, int line)
{ {
nasm_panic("internal error at %s:%d\n", file, line); nasm_panic("internal error at %s:%d\n", file, line);
} }
fatal_func nasm_assert_failed(const char *file, int line, const char *msg) fatal_func nasm_assert_failed(const char *file, int line, const char *msg)
{ {
nasm_panic("assertion %s failed at %s:%d", msg, file, line); nasm_panic("assertion %s failed at %s:%d", msg, file, line);
} }
/* /*
@@ -141,82 +143,82 @@ fatal_func nasm_assert_failed(const char *file, int line, const char *msg)
*/ */
bool set_warning_status(const char *value) bool set_warning_status(const char *value)
{ {
enum warn_action { WID_OFF, WID_ON, WID_RESET }; enum warn_action { WID_OFF, WID_ON, WID_RESET };
enum warn_action action; enum warn_action action;
uint8_t mask; bool ok = false;
int i; uint8_t mask;
bool ok = false; int i;
value = nasm_skip_spaces(value); value = nasm_skip_spaces(value);
switch (*value) { switch (*value) {
case '-': case '-':
action = WID_OFF; action = WID_OFF;
value++; value++;
break; break;
case '+': case '+':
action = WID_ON; action = WID_ON;
value++; value++;
break; break;
case '*': case '*':
action = WID_RESET; action = WID_RESET;
value++; value++;
break; break;
case 'N': case 'N':
case 'n': case 'n':
if (!nasm_strnicmp(value, "no-", 3)) { if (!nasm_strnicmp(value, "no-", 3)) {
action = WID_OFF; action = WID_OFF;
value += 3; value += 3;
break; break;
} else if (!nasm_stricmp(value, "none")) { } else if (!nasm_stricmp(value, "none")) {
action = WID_OFF; action = WID_OFF;
value = NULL; value = NULL;
break; break;
} }
/* else fall through */ /* else fall through */
default: default:
action = WID_ON; action = WID_ON;
break; break;
} }
mask = WARN_ST_ENABLED; mask = WARN_ST_ENABLED;
if (value && !nasm_strnicmp(value, "error", 5)) { if (value && !nasm_strnicmp(value, "error", 5)) {
switch (value[5]) { switch (value[5]) {
case '=': case '=':
mask = WARN_ST_ERROR; mask = WARN_ST_ERROR;
value += 6; value += 6;
break; break;
case '\0': case '\0':
mask = WARN_ST_ERROR; mask = WARN_ST_ERROR;
value = NULL; value = NULL;
break; break;
default: default:
/* Just an accidental prefix? */ /* Just an accidental prefix? */
break; break;
} }
} }
if (value && !nasm_stricmp(value, "all")) if (value && !nasm_stricmp(value, "all"))
value = NULL; value = NULL;
/* This is inefficient, but it shouldn't matter... */ /* This is inefficient, but it shouldn't matter... */
for (i = 0; i < ERR_WARN_ALL; i++) { for (i = 0; i < ERR_WARN_ALL; i++) {
if (!value || !nasm_stricmp(value, warnings[i].name)) { if (!value || !nasm_stricmp(value, warnings[i].name)) {
ok = true; /* At least one action taken */ ok = true; /* At least one action taken */
switch (action) { switch (action) {
case WID_OFF: case WID_OFF:
warning_state[i] &= ~mask; warning_state[i] &= ~mask;
break; break;
case WID_ON: case WID_ON:
warning_state[i] |= mask; warning_state[i] |= mask;
break; break;
case WID_RESET: case WID_RESET:
warning_state[i] &= ~mask; warning_state[i] &= ~mask;
warning_state[i] |= warning_state_init[i] & mask; warning_state[i] |= warning_state_init[i] & mask;
break; break;
} }
} }
} }
return ok; return ok;
} }

View File

@@ -53,11 +53,12 @@ fatal_func nasm_panic_from_macro(const char *file, int line);
typedef void (*vefunc) (int severity, const char *fmt, va_list ap); typedef void (*vefunc) (int severity, const char *fmt, va_list ap);
extern vefunc nasm_verror; extern vefunc nasm_verror;
static inline vefunc nasm_set_verror(vefunc ve) static inline vefunc nasm_set_verror(vefunc ve)
{ {
vefunc old_verror = nasm_verror; vefunc old_verror = nasm_verror;
nasm_verror = ve; nasm_verror = ve;
return old_verror; return old_verror;
} }
/* /*
@@ -65,46 +66,46 @@ static inline vefunc nasm_set_verror(vefunc ve)
* argument to an efunc. * argument to an efunc.
*/ */
#define ERR_DEBUG 0x00000000 /* put out debugging message */ #define ERR_DEBUG 0x00000000 /* put out debugging message */
#define ERR_WARNING 0x00000001 /* warn only: no further action */ #define ERR_WARNING 0x00000001 /* warn only: no further action */
#define ERR_NONFATAL 0x00000002 /* terminate assembly after phase */ #define ERR_NONFATAL 0x00000002 /* terminate assembly after phase */
#define ERR_FATAL 0x00000006 /* instantly fatal: exit with error */ #define ERR_FATAL 0x00000006 /* instantly fatal: exit with error */
#define ERR_PANIC 0x00000007 /* internal error: panic instantly #define ERR_PANIC 0x00000007 /* internal error: panic instantly
* and dump core for reference */ * and dump core for reference */
#define ERR_MASK 0x00000007 /* mask off the above codes */ #define ERR_MASK 0x00000007 /* mask off the above codes */
#define ERR_NOFILE 0x00000010 /* don't give source file name/line */ #define ERR_NOFILE 0x00000010 /* don't give source file name/line */
#define ERR_TOPFILE 0x00000020 /* give the top input file name only */ #define ERR_TOPFILE 0x00000020 /* give the top input file name only */
#define ERR_USAGE 0x00000040 /* print a usage message */ #define ERR_USAGE 0x00000040 /* print a usage message */
#define ERR_PASS1 0x00000080 /* only print this error on pass one */ #define ERR_PASS1 0x00000080 /* only print this error on pass one */
#define ERR_PASS2 0x00000100 /* only print this error on pass one */ #define ERR_PASS2 0x00000100 /* only print this error on pass one */
#define ERR_NO_SEVERITY 0x00000200 /* suppress printing severity */ #define ERR_NO_SEVERITY 0x00000200 /* suppress printing severity */
#define ERR_PP_PRECOND 0x00000400 /* for preprocessor use */ #define ERR_PP_PRECOND 0x00000400 /* for preprocessor use */
#define ERR_PP_LISTMACRO 0x00000800 /* from preproc->error_list_macros() */ #define ERR_PP_LISTMACRO 0x00000800 /* from preproc->error_list_macros() */
/* /*
* These codes define specific types of suppressible warning. * These codes define specific types of suppressible warning.
*/ */
#define ERR_WARN_MASK 0xFFFFF000 /* the mask for this feature */ #define ERR_WARN_MASK 0xFFFFF000 /* the mask for this feature */
#define ERR_WARN_SHR 12 /* how far to shift right */ #define ERR_WARN_SHR 12 /* how far to shift right */
#define WARN(x) ((x) << ERR_WARN_SHR) #define WARN(x) ((x) << ERR_WARN_SHR)
#define WARN_IDX(x) (((x) & ERR_WARN_MASK) >> ERR_WARN_SHR) #define WARN_IDX(x) (((x) & ERR_WARN_MASK) >> ERR_WARN_SHR)
#define ERR_WARN_OTHER WARN( 0) /* any noncategorized warning */ #define ERR_WARN_OTHER WARN( 0) /* any noncategorized warning */
#define ERR_WARN_MNP WARN( 1) /* macro-num-parameters warning */ #define ERR_WARN_MNP WARN( 1) /* macro-num-parameters warning */
#define ERR_WARN_MSR WARN( 2) /* macro self-reference */ #define ERR_WARN_MSR WARN( 2) /* macro self-reference */
#define ERR_WARN_MDP WARN( 3) /* macro default parameters check */ #define ERR_WARN_MDP WARN( 3) /* macro default parameters check */
#define ERR_WARN_OL WARN( 4) /* orphan label (no colon, and #define ERR_WARN_OL WARN( 4) /* orphan label (no colon, and
* alone on line) */ * alone on line) */
#define ERR_WARN_NOV WARN( 5) /* numeric overflow */ #define ERR_WARN_NOV WARN( 5) /* numeric overflow */
#define ERR_WARN_GNUELF WARN( 6) /* using GNU ELF extensions */ #define ERR_WARN_GNUELF WARN( 6) /* using GNU ELF extensions */
#define ERR_WARN_FL_OVERFLOW WARN( 7) /* FP overflow */ #define ERR_WARN_FL_OVERFLOW WARN( 7) /* FP overflow */
#define ERR_WARN_FL_DENORM WARN( 8) /* FP denormal */ #define ERR_WARN_FL_DENORM WARN( 8) /* FP denormal */
#define ERR_WARN_FL_UNDERFLOW WARN( 9) /* FP underflow */ #define ERR_WARN_FL_UNDERFLOW WARN( 9) /* FP underflow */
#define ERR_WARN_FL_TOOLONG WARN(10) /* FP too many digits */ #define ERR_WARN_FL_TOOLONG WARN(10) /* FP too many digits */
#define ERR_WARN_USER WARN(11) /* %warning directives */ #define ERR_WARN_USER WARN(11) /* %warning directives */
#define ERR_WARN_LOCK WARN(12) /* bad LOCK prefixes */ #define ERR_WARN_LOCK WARN(12) /* bad LOCK prefixes */
#define ERR_WARN_HLE WARN(13) /* bad HLE prefixes */ #define ERR_WARN_HLE WARN(13) /* bad HLE prefixes */
#define ERR_WARN_BND WARN(14) /* bad BND prefixes */ #define ERR_WARN_BND WARN(14) /* bad BND prefixes */
@@ -118,23 +119,23 @@ static inline vefunc nasm_set_verror(vefunc ve)
#define ERR_WARN_PHASE WARN(22) /* phase error in pass 1 */ #define ERR_WARN_PHASE WARN(22) /* phase error in pass 1 */
/* The "all" warning acts as a global switch, it must come last */ /* The "all" warning acts as a global switch, it must come last */
#define ERR_WARN_ALL 23 /* Do not use WARN() here */ #define ERR_WARN_ALL 23 /* Do not use WARN() here */
struct warning { struct warning {
const char *name; const char *name;
const char *help; const char *help;
bool enabled; bool enabled;
}; };
extern const struct warning warnings[ERR_WARN_ALL+1]; extern const struct warning warnings[ERR_WARN_ALL+1];
/* This is a bitmask */ /* This is a bitmask */
#define WARN_ST_ENABLED 1 /* Warning is currently enabled */ #define WARN_ST_ENABLED 1 /* Warning is currently enabled */
#define WARN_ST_ERROR 2 /* Treat this warning as an error */ #define WARN_ST_ERROR 2 /* Treat this warning as an error */
extern uint8_t warning_state[ERR_WARN_ALL]; extern uint8_t warning_state[ERR_WARN_ALL];
extern uint8_t warning_state_init[ERR_WARN_ALL]; extern uint8_t warning_state_init[ERR_WARN_ALL];
/* Process a warning option or directive */ /* Process a warning option or directive */
bool set_warning_status(const char *); bool set_warning_status(const char *value);
#endif /* NASM_ERROR_H */ #endif /* NASM_ERROR_H */