summaryrefslogtreecommitdiff
path: root/asm
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2018-06-15 18:20:17 -0700
committerH. Peter Anvin <hpa@zytor.com>2018-06-15 18:20:17 -0700
commitc51369067ce7cfac43d8bc8681a3c916d8d5e503 (patch)
tree185bbd5df654b0e0c61c84aa2da144f18406e5f3 /asm
parentd3b1832c049c533656fd1945440d637f01a0f1a4 (diff)
downloadnasm-c51369067ce7cfac43d8bc8681a3c916d8d5e503.tar.gz
errors: simplify nasm_fatal() and nasm_panic()
Nearly all instances of nasm_fatal() and nasm_panic() take a flags argument of zero. Simplify the code by making nasm_fatal and nasm_panic default to no flags, and add an alternate version if flags really are desired. This also means that every call site doesn't have to initialize a zero argument. Furthermore, ERR_NOFILE is now often not necessary, as the error code will no longer cause a null reference if there is no current file. Therefore, we can remove many instances of ERR_NOFILE which only deprives the user of information. Signed-off-by: H. Peter Anvin <hpa@zytor.com>
Diffstat (limited to 'asm')
-rw-r--r--asm/assemble.c14
-rw-r--r--asm/directiv.c2
-rw-r--r--asm/error.c26
-rw-r--r--asm/eval.c2
-rw-r--r--asm/float.c8
-rw-r--r--asm/nasm.c28
-rw-r--r--asm/parser.c2
-rw-r--r--asm/preproc-nop.c2
-rw-r--r--asm/preproc.c13
9 files changed, 54 insertions, 43 deletions
diff --git a/asm/assemble.c b/asm/assemble.c
index e71e907a..aef9b796 100644
--- a/asm/assemble.c
+++ b/asm/assemble.c
@@ -1317,7 +1317,7 @@ static int64_t calcsize(int32_t segment, int64_t offset, int bits,
break;
default:
- nasm_panic(0, "internal instruction table corrupt"
+ nasm_panic("internal instruction table corrupt"
": instruction code \\%o (0x%02X) given", c, c);
break;
}
@@ -1548,7 +1548,7 @@ static int emit_prefix(struct out_data *data, const int bits, insn *ins)
case P_none:
break;
default:
- nasm_panic(0, "invalid instruction prefix");
+ nasm_panic("invalid instruction prefix");
}
if (c) {
if (data)
@@ -1866,7 +1866,7 @@ static void gencode(struct out_data *data, insn *ins)
case 0340:
if (ins->oprs[0].segment != NO_SEG)
- nasm_panic(0, "non-constant BSS size in pass two");
+ nasm_panic("non-constant BSS size in pass two");
out_reserve(data, ins->oprs[0].offset);
break;
@@ -1976,7 +1976,7 @@ static void gencode(struct out_data *data, insn *ins)
break;
default:
- nasm_panic(0, "internal instruction table corrupt"
+ nasm_panic("internal instruction table corrupt"
": instruction code \\%o (0x%02X) given", c, c);
break;
}
@@ -1986,14 +1986,14 @@ static void gencode(struct out_data *data, insn *ins)
static opflags_t regflag(const operand * o)
{
if (!is_register(o->basereg))
- nasm_panic(0, "invalid operand passed to regflag()");
+ nasm_panic("invalid operand passed to regflag()");
return nasm_reg_flags[o->basereg];
}
static int32_t regval(const operand * o)
{
if (!is_register(o->basereg))
- nasm_panic(0, "invalid operand passed to regval()");
+ nasm_panic("invalid operand passed to regval()");
return nasm_regvals[o->basereg];
}
@@ -2003,7 +2003,7 @@ static int op_rexflags(const operand * o, int mask)
int val;
if (!is_register(o->basereg))
- nasm_panic(0, "invalid operand passed to op_rexflags()");
+ nasm_panic("invalid operand passed to op_rexflags()");
flags = nasm_reg_flags[o->basereg];
val = nasm_regvals[o->basereg];
diff --git a/asm/directiv.c b/asm/directiv.c
index 68a74a12..13ef5eb7 100644
--- a/asm/directiv.c
+++ b/asm/directiv.c
@@ -395,7 +395,7 @@ bool process_directives(char *directive)
} else if (passn == 1)
absolute.offset = 0x100; /* don't go near zero in case of / */
else
- nasm_panic(0, "invalid ABSOLUTE address "
+ nasm_panic("invalid ABSOLUTE address "
"in pass two");
in_absolute = true;
location.segment = NO_SEG;
diff --git a/asm/error.c b/asm/error.c
index 3fdaa027..116e871b 100644
--- a/asm/error.c
+++ b/asm/error.c
@@ -88,7 +88,16 @@ void nasm_error(int severity, const char *fmt, ...)
va_end(ap);
}
-fatal_func nasm_fatal(int flags, const char *fmt, ...)
+fatal_func nasm_fatal(const char *fmt, ...)
+{
+ va_list ap;
+
+ va_start(ap, fmt);
+ nasm_verror(ERR_FATAL, fmt, ap);
+ abort(); /* We should never get here */
+}
+
+fatal_func nasm_fatal_fl(int flags, const char *fmt, ...)
{
va_list ap;
@@ -97,7 +106,16 @@ fatal_func nasm_fatal(int flags, const char *fmt, ...)
abort(); /* We should never get here */
}
-fatal_func nasm_panic(int flags, const char *fmt, ...)
+fatal_func nasm_panic(const char *fmt, ...)
+{
+ va_list ap;
+
+ va_start(ap, fmt);
+ nasm_verror(ERR_PANIC, fmt, ap);
+ abort(); /* We should never get here */
+}
+
+fatal_func nasm_panic_fl(int flags, const char *fmt, ...)
{
va_list ap;
@@ -108,12 +126,12 @@ fatal_func nasm_panic(int flags, const char *fmt, ...)
fatal_func nasm_panic_from_macro(const char *file, int line)
{
- nasm_panic(ERR_NOFILE, "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)
{
- nasm_panic(0, "assertion %s failed at %s:%d", msg, file, line);
+ nasm_panic("assertion %s failed at %s:%d", msg, file, line);
}
/*
diff --git a/asm/eval.c b/asm/eval.c
index 1a6680f2..c4ea4fde 100644
--- a/asm/eval.c
+++ b/asm/eval.c
@@ -752,7 +752,7 @@ static int64_t eval_ifunc(int64_t val, enum ifunc func)
break;
default:
- nasm_panic(0, "invalid IFUNC token %d", func);
+ nasm_panic("invalid IFUNC token %d", func);
rv = 0;
break;
}
diff --git a/asm/float.c b/asm/float.c
index fd66ef38..dcf69fea 100644
--- a/asm/float.c
+++ b/asm/float.c
@@ -732,11 +732,7 @@ static int to_float(const char *str, int s, uint8_t *result,
const int bits = fmt->bytes * 8;
const char *strend;
- if (!str[0]) {
- nasm_panic(0,
- "internal errror: empty string passed to float_const");
- return 0;
- }
+ nasm_assert(str[0]);
strend = strchr(str, '\0');
if (strend[-1] == 'P' || strend[-1] == 'p')
@@ -916,7 +912,7 @@ int float_const(const char *number, int sign, uint8_t *result, int bytes)
case 16:
return to_float(number, sign, result, &ieee_128);
default:
- nasm_panic(0, "strange value %d passed to float_const", bytes);
+ nasm_panic("strange value %d passed to float_const", bytes);
return 0;
}
}
diff --git a/asm/nasm.c b/asm/nasm.c
index 6299831f..3b987727 100644
--- a/asm/nasm.c
+++ b/asm/nasm.c
@@ -463,7 +463,7 @@ int main(int argc, char **argv)
} else {
dfmt = dfmt_find(ofmt, debug_format);
if (!dfmt) {
- nasm_fatal(ERR_NOFILE | ERR_USAGE,
+ nasm_fatal_fl(ERR_NOFILE | ERR_USAGE,
"unrecognized debug format `%s' for"
" output format `%s'",
debug_format, ofmt->shortname);
@@ -505,7 +505,7 @@ int main(int argc, char **argv)
if (outname) {
ofile = nasm_open_write(outname, NF_TEXT);
if (!ofile)
- nasm_fatal(ERR_NOFILE,
+ nasm_fatal_fl(ERR_NOFILE,
"unable to open output file `%s'",
outname);
} else
@@ -550,7 +550,7 @@ int main(int argc, char **argv)
if (operating_mode & OP_NORMAL) {
ofile = nasm_open_write(outname, (ofmt->flags & OFMT_TEXT) ? NF_TEXT : NF_BINARY);
if (!ofile)
- nasm_fatal(ERR_NOFILE,
+ nasm_fatal_fl(ERR_NOFILE,
"unable to open output file `%s'", outname);
/*
@@ -623,7 +623,7 @@ static char *get_param(char *p, char *q, bool *advance)
static void copy_filename(const char **dst, const char *src, const char *what)
{
if (*dst)
- nasm_fatal(0, "more than one %s file specified: %s\n", what, src);
+ nasm_fatal("more than one %s file specified: %s\n", what, src);
*dst = nasm_strdup(src);
}
@@ -854,7 +854,7 @@ static bool process_arg(char *p, char *q, int pass)
if (pass == 1) {
ofmt = ofmt_find(param, &ofmt_alias);
if (!ofmt) {
- nasm_fatal(ERR_NOFILE | ERR_USAGE,
+ nasm_fatal_fl(ERR_NOFILE | ERR_USAGE,
"unrecognised output format `%s' - "
"use -hf for a list", param);
}
@@ -895,8 +895,7 @@ static bool process_arg(char *p, char *q, int pass)
break;
default:
- nasm_fatal(0,
- "unknown optimization option -O%c\n",
+ nasm_fatal("unknown optimization option -O%c\n",
*param);
break;
}
@@ -955,7 +954,7 @@ static bool process_arg(char *p, char *q, int pass)
else if (nasm_stricmp("gnu", param) == 0)
nasm_set_verror(nasm_verror_gnu);
else
- nasm_fatal(ERR_NOFILE | ERR_USAGE,
+ nasm_fatal_fl(ERR_NOFILE | ERR_USAGE,
"unrecognized error reporting format `%s'",
param);
}
@@ -1354,19 +1353,19 @@ static void parse_cmdline(int argc, char **argv, int pass)
return;
if (!inname)
- nasm_fatal(ERR_NOFILE | ERR_USAGE, "no input file specified");
+ nasm_fatal_fl(ERR_NOFILE | ERR_USAGE, "no input file specified");
else if ((errname && !strcmp(inname, errname)) ||
(outname && !strcmp(inname, outname)) ||
(listname && !strcmp(inname, listname)) ||
(depend_file && !strcmp(inname, depend_file)))
- nasm_fatal(ERR_USAGE, "will not overwrite input file");
+ nasm_fatal_fl(ERR_USAGE, "will not overwrite input file");
if (errname) {
error_file = nasm_open_write(errname, NF_TEXT);
if (!error_file) {
error_file = stderr; /* Revert to default! */
- nasm_fatal(ERR_NOFILE | ERR_USAGE,
+ nasm_fatal_fl(ERR_NOFILE | ERR_USAGE,
"cannot open file `%s' for error messages",
errname);
}
@@ -1386,11 +1385,11 @@ static void assemble_file(const char *fname, StrList **depend_ptr)
break;
case 32:
if (!iflag_cpu_level_ok(&cmd_cpu, IF_386))
- nasm_fatal(0, "command line: 32-bit segment size requires a higher cpu");
+ nasm_fatal("command line: 32-bit segment size requires a higher cpu");
break;
case 64:
if (!iflag_cpu_level_ok(&cmd_cpu, IF_X86_64))
- nasm_fatal(0, "command line: 64-bit segment size requires a higher cpu");
+ nasm_fatal("command line: 64-bit segment size requires a higher cpu");
break;
default:
panic();
@@ -1434,8 +1433,7 @@ static void assemble_file(const char *fname, StrList **depend_ptr)
while ((line = preproc->getline())) {
if (++globallineno > nasm_limit[LIMIT_LINES])
- nasm_fatal(0,
- "overall line count exceeds the maximum %"PRId64"\n",
+ nasm_fatal("overall line count exceeds the maximum %"PRId64"\n",
nasm_limit[LIMIT_LINES]);
/*
diff --git a/asm/parser.c b/asm/parser.c
index 40188410..d5a45753 100644
--- a/asm/parser.c
+++ b/asm/parser.c
@@ -98,7 +98,7 @@ static int prefix_slot(int prefix)
case P_VEX2:
return PPS_VEX;
default:
- nasm_panic(0, "Invalid value %d passed to prefix_slot()", prefix);
+ nasm_panic("Invalid value %d passed to prefix_slot()", prefix);
return -1;
}
}
diff --git a/asm/preproc-nop.c b/asm/preproc-nop.c
index 6f7aaf9e..ee690063 100644
--- a/asm/preproc-nop.c
+++ b/asm/preproc-nop.c
@@ -70,7 +70,7 @@ static void nop_reset(const char *file, int pass, StrList **deplist)
nop_fp = nasm_open_read(file, NF_TEXT);
if (!nop_fp)
- nasm_fatal(ERR_NOFILE, "unable to open input file `%s'", file);
+ nasm_fatal_fl(ERR_NOFILE, "unable to open input file `%s'", file);
(void)pass; /* placate compilers */
nasm_add_string_to_strlist(deplist, file);
diff --git a/asm/preproc.c b/asm/preproc.c
index 8e1e6369..fbdfedb7 100644
--- a/asm/preproc.c
+++ b/asm/preproc.c
@@ -1607,7 +1607,7 @@ static FILE *inc_fopen(const char *file,
if (!path) {
if (omode == INC_NEEDED)
- nasm_fatal(0, "unable to open include file `%s'", file);
+ nasm_fatal("unable to open include file `%s'", file);
if (found_path)
*found_path = NULL;
@@ -2821,7 +2821,7 @@ issue_error:
nasm_error(ERR_WARNING|ERR_PASS1|ERR_PP_PRECOND,
"trailing garbage after `%%else' ignored");
if (!istk->conds)
- nasm_fatal(0, "`%%else: no matching `%%if'");
+ nasm_fatal("`%%else: no matching `%%if'");
switch(istk->conds->state) {
case COND_IF_TRUE:
case COND_DONE:
@@ -4986,7 +4986,7 @@ pp_reset(const char *file, int apass, StrList **deplist)
src_set(0, file);
istk->lineinc = 1;
if (!istk->fp)
- nasm_fatal(ERR_NOFILE, "unable to open input file `%s'", file);
+ nasm_fatal_fl(ERR_NOFILE, "unable to open input file `%s'", file);
defining = NULL;
nested_mac_count = 0;
nested_rep_count = 0;
@@ -5094,9 +5094,9 @@ static char *pp_getline(void)
*/
if (defining) {
if (defining->name)
- nasm_panic(0, "defining with name in expansion");
+ nasm_panic("defining with name in expansion");
else if (istk->mstk->name)
- nasm_fatal(0, "`%%rep' without `%%endrep' within"
+ nasm_fatal("`%%rep' without `%%endrep' within"
" expansion of macro `%s'",
istk->mstk->name);
}
@@ -5171,8 +5171,7 @@ static char *pp_getline(void)
fclose(i->fp);
if (i->conds) {
/* nasm_error can't be conditionally suppressed */
- nasm_fatal(0,
- "expected `%%endif' before end of file");
+ nasm_fatal("expected `%%endif' before end of file");
}
/* only set line and file name if there's a next node */
if (i->next)