summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@linux.intel.com>2016-02-17 20:27:41 -0800
committerH. Peter Anvin <hpa@zytor.com>2016-03-03 15:22:03 -0800
commit215186fe82c461bc1ccef7bed5c1a1a0253bfcc9 (patch)
tree2e1e610ccd0fe722e0a67edf9753ba424e67cf29
parent41087068aa3d5ddac8b28cb2bdcacd606f475c08 (diff)
downloadnasm-215186fe82c461bc1ccef7bed5c1a1a0253bfcc9.tar.gz
Get rid of a bunch of unnecessary indirections
We pass around a whole bunch of function pointers in arguments, which then just get stashed in static variables. Clean this mess up and in particular handle the error management in the preprocessor using nasm_set_verror() which already exists. Signed-off-by: H. Peter Anvin <hpa@linux.intel.com> From master branch checkin 130736c0cfcad28ee16cec6c14bb22999d982e5a Resolved Conflicts: nasm.c preproc-nop.c Signed-off-by: H. Peter Anvin <hpa@zytor.com>
-rw-r--r--assemble.c185
-rw-r--r--assemble.h5
-rw-r--r--eval.c78
-rw-r--r--eval.h3
-rw-r--r--float.c38
-rw-r--r--float.h3
-rw-r--r--listing.c17
-rw-r--r--listing.h4
-rw-r--r--nasm.c35
-rw-r--r--nasm.h8
-rw-r--r--nasmlib.c7
-rw-r--r--nasmlib.h26
-rw-r--r--output/outaout.c5
-rw-r--r--output/outbin.c4
-rw-r--r--output/outelf32.c5
-rw-r--r--output/outelf64.c5
-rw-r--r--output/outelfx32.c5
-rw-r--r--output/outform.h1
-rw-r--r--output/outobj.c2
-rw-r--r--parser.c15
-rw-r--r--preproc-nop.c9
-rw-r--r--preproc.c409
22 files changed, 419 insertions, 450 deletions
diff --git a/assemble.c b/assemble.c
index ed8b9f8d..a26f2bf6 100644
--- a/assemble.c
+++ b/assemble.c
@@ -227,9 +227,6 @@ typedef struct {
(((mod) << 6) | (((reg) & 7) << 3) | ((rm) & 7))
static iflag_t cpu; /* cpu level received from nasm.c */
-static efunc errfunc;
-static struct ofmt *outfmt;
-static ListGen *list;
static int64_t calcsize(int32_t, int64_t, int, insn *,
const struct itemplate *);
@@ -257,8 +254,8 @@ static int has_prefix(insn * ins, enum prefix_pos pos, int prefix)
static void assert_no_prefix(insn * ins, enum prefix_pos pos)
{
if (ins->prefixes[pos])
- errfunc(ERR_NONFATAL, "invalid %s prefix",
- prefix_name(ins->prefixes[pos]));
+ nasm_error(ERR_NONFATAL, "invalid %s prefix",
+ prefix_name(ins->prefixes[pos]));
}
static const char *size_name(int size)
@@ -287,7 +284,7 @@ static const char *size_name(int size)
static void warn_overflow(int pass, int size)
{
- errfunc(ERR_WARNING | pass | ERR_WARN_NOV,
+ nasm_error(ERR_WARNING | pass | ERR_WARN_NOV,
"%s data exceeds bounds", size_name(size));
}
@@ -340,7 +337,7 @@ static void out(int64_t offset, int32_t segto, const void *data,
static char *lnfname = NULL;
uint8_t p[8];
int asize = addrsize(type, size); /* Address size in bytes */
- const int amax = outfmt->maxbits >> 3; /* Maximum address size in bytes */
+ const int amax = ofmt->maxbits >> 3; /* Maximum address size in bytes */
if (type == OUT_ADDRESS && segment == NO_SEG && wrt == NO_SEG) {
/*
@@ -350,7 +347,7 @@ static void out(int64_t offset, int32_t segto, const void *data,
uint8_t *q = p;
if (asize > 8) {
- errfunc(ERR_PANIC, "OUT_ADDRESS with size > 8");
+ nasm_error(ERR_PANIC, "OUT_ADDRESS with size > 8");
return;
}
@@ -361,7 +358,7 @@ static void out(int64_t offset, int32_t segto, const void *data,
asize = 0; /* No longer an address */
}
- list->output(offset, data, type, size);
+ nasmlist->output(offset, data, type, size);
/*
* this call to src_get determines when we call the
@@ -373,19 +370,19 @@ static void out(int64_t offset, int32_t segto, const void *data,
*/
if (src_get(&lineno, &lnfname))
- outfmt->current_dfmt->linenum(lnfname, lineno, segto);
+ ofmt->current_dfmt->linenum(lnfname, lineno, segto);
if (asize && asize > amax) {
if (type != OUT_ADDRESS || (int)size < 0) {
- errfunc(ERR_NONFATAL,
+ nasm_error(ERR_NONFATAL,
"%d-bit signed relocation unsupported by output format %s\n",
- asize << 3, outfmt->shortname);
+ asize << 3, ofmt->shortname);
size = asize;
} else {
- errfunc(ERR_WARNING | ERR_WARN_ZEXTRELOC,
+ nasm_error(ERR_WARNING | ERR_WARN_ZEXTRELOC,
"%d-bit unsigned relocation zero-extended from %d bits\n",
- asize << 3, outfmt->maxbits);
- outfmt->output(segto, data, type, amax, segment, wrt);
+ asize << 3, ofmt->maxbits);
+ ofmt->output(segto, data, type, amax, segment, wrt);
size = asize - amax;
}
data = zero_buffer;
@@ -393,7 +390,7 @@ static void out(int64_t offset, int32_t segto, const void *data,
segment = wrt = NO_SEG;
}
- outfmt->output(segto, data, type, size, segment, wrt);
+ ofmt->output(segto, data, type, size, segment, wrt);
}
static void out_imm8(int64_t offset, int32_t segment,
@@ -438,7 +435,7 @@ static bool jmp_match(int32_t segment, int64_t offset, int bits,
if (is_byte && c == 0371 && ins->prefixes[PPS_REP] == P_BND) {
/* jmp short (opcode eb) cannot be used with bnd prefix. */
ins->prefixes[PPS_REP] = P_none;
- errfunc(ERR_WARNING | ERR_WARN_BND | ERR_PASS2 ,
+ nasm_error(ERR_WARNING | ERR_WARN_BND | ERR_PASS2 ,
"jmp short does not init bnd regs - bnd prefix dropped.");
}
@@ -446,8 +443,7 @@ static bool jmp_match(int32_t segment, int64_t offset, int bits,
}
int64_t assemble(int32_t segment, int64_t offset, int bits, iflag_t cp,
- insn * instruction, struct ofmt *output, efunc error,
- ListGen * listgen)
+ insn * instruction)
{
const struct itemplate *temp;
int j;
@@ -457,10 +453,7 @@ int64_t assemble(int32_t segment, int64_t offset, int bits, iflag_t cp,
int64_t start = offset;
int64_t wsize; /* size for DB etc. */
- errfunc = error; /* to pass to other functions */
cpu = cp;
- outfmt = output; /* likewise */
- list = listgen; /* and again */
wsize = idata_bytes(instruction->opcode);
if (wsize == -1)
@@ -470,14 +463,13 @@ int64_t assemble(int32_t segment, int64_t offset, int bits, iflag_t cp,
extop *e;
int32_t t = instruction->times;
if (t < 0)
- errfunc(ERR_PANIC,
- "instruction->times < 0 (%ld) in assemble()", t);
+ nasm_panic(0, "instruction->times < 0 (%"PRId32") in assemble()", t);
while (t--) { /* repeat TIMES times */
list_for_each(e, instruction->eops) {
if (e->type == EOT_DB_NUMBER) {
if (wsize > 8) {
- errfunc(ERR_NONFATAL,
+ nasm_error(ERR_NONFATAL,
"integer supplied to a DT, DO or DY"
" instruction");
} else {
@@ -503,15 +495,15 @@ int64_t assemble(int32_t segment, int64_t offset, int bits, iflag_t cp,
}
if (t > 0 && t == instruction->times - 1) {
/*
- * Dummy call to list->output to give the offset to the
+ * Dummy call to nasmlist->output to give the offset to the
* listing module.
*/
- list->output(offset, NULL, OUT_RAWDATA, 0);
- list->uplevel(LIST_TIMES);
+ nasmlist->output(offset, NULL, OUT_RAWDATA, 0);
+ nasmlist->uplevel(LIST_TIMES);
}
}
if (instruction->times > 1)
- list->downlevel(LIST_TIMES);
+ nasmlist->downlevel(LIST_TIMES);
return offset - start;
}
@@ -521,10 +513,10 @@ int64_t assemble(int32_t segment, int64_t offset, int bits, iflag_t cp,
fp = fopen(fname, "rb");
if (!fp) {
- error(ERR_NONFATAL, "`incbin': unable to open file `%s'",
+ nasm_error(ERR_NONFATAL, "`incbin': unable to open file `%s'",
fname);
} else if (fseek(fp, 0L, SEEK_END) < 0) {
- error(ERR_NONFATAL, "`incbin': unable to seek on file `%s'",
+ nasm_error(ERR_NONFATAL, "`incbin': unable to seek on file `%s'",
fname);
fclose(fp);
} else {
@@ -542,11 +534,11 @@ int64_t assemble(int32_t segment, int64_t offset, int bits, iflag_t cp,
len = (size_t)instruction->eops->next->next->offset;
}
/*
- * Dummy call to list->output to give the offset to the
+ * Dummy call to nasmlist->output to give the offset to the
* listing module.
*/
- list->output(offset, NULL, OUT_RAWDATA, 0);
- list->uplevel(LIST_INCBIN);
+ nasmlist->output(offset, NULL, OUT_RAWDATA, 0);
+ nasmlist->uplevel(LIST_INCBIN);
while (t--) {
size_t l;
@@ -561,7 +553,7 @@ int64_t assemble(int32_t segment, int64_t offset, int bits, iflag_t cp,
* actually changes while we are reading
* it.
*/
- error(ERR_NONFATAL,
+ nasm_error(ERR_NONFATAL,
"`incbin': unexpected EOF while"
" reading file `%s'", fname);
t = 0; /* Try to exit cleanly */
@@ -572,15 +564,15 @@ int64_t assemble(int32_t segment, int64_t offset, int bits, iflag_t cp,
l -= m;
}
}
- list->downlevel(LIST_INCBIN);
+ nasmlist->downlevel(LIST_INCBIN);
if (instruction->times > 1) {
/*
- * Dummy call to list->output to give the offset to the
+ * Dummy call to nasmlist->output to give the offset to the
* listing module.
*/
- list->output(offset, NULL, OUT_RAWDATA, 0);
- list->uplevel(LIST_TIMES);
- list->downlevel(LIST_TIMES);
+ nasmlist->output(offset, NULL, OUT_RAWDATA, 0);
+ nasmlist->uplevel(LIST_TIMES);
+ nasmlist->downlevel(LIST_TIMES);
}
fclose(fp);
return instruction->times * len;
@@ -598,7 +590,7 @@ int64_t assemble(int32_t segment, int64_t offset, int bits, iflag_t cp,
int64_t insn_size = calcsize(segment, offset, bits, instruction, temp);
itimes = instruction->times;
if (insn_size < 0) /* shouldn't be, on pass two */
- error(ERR_PANIC, "errors made it through from pass one");
+ nasm_error(ERR_PANIC, "errors made it through from pass one");
else
while (itimes--) {
for (j = 0; j < MAXPREFIX; j++) {
@@ -624,21 +616,21 @@ int64_t assemble(int32_t segment, int64_t offset, int bits, iflag_t cp,
break;
case R_CS:
if (bits == 64) {
- error(ERR_WARNING | ERR_PASS2,
+ nasm_error(ERR_WARNING | ERR_PASS2,
"cs segment base generated, but will be ignored in 64-bit mode");
}
c = 0x2E;
break;
case R_DS:
if (bits == 64) {
- error(ERR_WARNING | ERR_PASS2,
+ nasm_error(ERR_WARNING | ERR_PASS2,
"ds segment base generated, but will be ignored in 64-bit mode");
}
c = 0x3E;
break;
case R_ES:
if (bits == 64) {
- error(ERR_WARNING | ERR_PASS2,
+ nasm_error(ERR_WARNING | ERR_PASS2,
"es segment base generated, but will be ignored in 64-bit mode");
}
c = 0x26;
@@ -651,19 +643,19 @@ int64_t assemble(int32_t segment, int64_t offset, int bits, iflag_t cp,
break;
case R_SS:
if (bits == 64) {
- error(ERR_WARNING | ERR_PASS2,
+ nasm_error(ERR_WARNING | ERR_PASS2,
"ss segment base generated, but will be ignored in 64-bit mode");
}
c = 0x36;
break;
case R_SEGR6:
case R_SEGR7:
- error(ERR_NONFATAL,
+ nasm_error(ERR_NONFATAL,
"segr6 and segr7 cannot be used as prefixes");
break;
case P_A16:
if (bits == 64) {
- error(ERR_NONFATAL,
+ nasm_error(ERR_NONFATAL,
"16-bit addressing is not supported "
"in 64-bit mode");
} else if (bits != 16)
@@ -675,7 +667,7 @@ int64_t assemble(int32_t segment, int64_t offset, int bits, iflag_t cp,
break;
case P_A64:
if (bits != 64) {
- error(ERR_NONFATAL,
+ nasm_error(ERR_NONFATAL,
"64-bit addressing is only supported "
"in 64-bit mode");
}
@@ -704,7 +696,7 @@ int64_t assemble(int32_t segment, int64_t offset, int bits, iflag_t cp,
case P_none:
break;
default:
- error(ERR_PANIC, "invalid instruction prefix");
+ nasm_error(ERR_PANIC, "invalid instruction prefix");
}
if (c != 0) {
out(offset, segment, &c, OUT_RAWDATA, 1,
@@ -718,49 +710,49 @@ int64_t assemble(int32_t segment, int64_t offset, int bits, iflag_t cp,
offset += insn_size;
if (itimes > 0 && itimes == instruction->times - 1) {
/*
- * Dummy call to list->output to give the offset to the
+ * Dummy call to nasmlist->output to give the offset to the
* listing module.
*/
- list->output(offset, NULL, OUT_RAWDATA, 0);
- list->uplevel(LIST_TIMES);
+ nasmlist->output(offset, NULL, OUT_RAWDATA, 0);
+ nasmlist->uplevel(LIST_TIMES);
}
}
if (instruction->times > 1)
- list->downlevel(LIST_TIMES);
+ nasmlist->downlevel(LIST_TIMES);
return offset - start;
} else {
/* No match */
switch (m) {
case MERR_OPSIZEMISSING:
- error(ERR_NONFATAL, "operation size not specified");
+ nasm_error(ERR_NONFATAL, "operation size not specified");
break;
case MERR_OPSIZEMISMATCH:
- error(ERR_NONFATAL, "mismatch in operand sizes");
+ nasm_error(ERR_NONFATAL, "mismatch in operand sizes");
break;
case MERR_BRNUMMISMATCH:
- error(ERR_NONFATAL,
+ nasm_error(ERR_NONFATAL,
"mismatch in the number of broadcasting elements");
break;
case MERR_BADCPU:
- error(ERR_NONFATAL, "no instruction for this cpu level");
+ nasm_error(ERR_NONFATAL, "no instruction for this cpu level");
break;
case MERR_BADMODE:
- error(ERR_NONFATAL, "instruction not supported in %d-bit mode",
+ nasm_error(ERR_NONFATAL, "instruction not supported in %d-bit mode",
bits);
break;
case MERR_ENCMISMATCH:
- error(ERR_NONFATAL, "specific encoding scheme not available");
+ nasm_error(ERR_NONFATAL, "specific encoding scheme not available");
break;
case MERR_BADBND:
- error(ERR_NONFATAL, "bnd prefix is not allowed");
+ nasm_error(ERR_NONFATAL, "bnd prefix is not allowed");
break;
case MERR_BADREPNE:
- error(ERR_NONFATAL, "%s prefix is not allowed",
+ nasm_error(ERR_NONFATAL, "%s prefix is not allowed",
(has_prefix(instruction, PPS_REP, P_REPNE) ?
"repne" : "repnz"));
break;
default:
- error(ERR_NONFATAL,
+ nasm_error(ERR_NONFATAL,
"invalid combination of opcode and operands");
break;
}
@@ -769,12 +761,11 @@ int64_t assemble(int32_t segment, int64_t offset, int bits, iflag_t cp,
}
int64_t insn_size(int32_t segment, int64_t offset, int bits, iflag_t cp,
- insn * instruction, efunc error)
+ insn * instruction)
{
const struct itemplate *temp;
enum match_result m;
- errfunc = error; /* to pass to other functions */
cpu = cp;
if (instruction->opcode == I_none)
@@ -817,10 +808,10 @@ int64_t insn_size(int32_t segment, int64_t offset, int bits, iflag_t cp,
fp = fopen(fname, "rb");
if (!fp)
- error(ERR_NONFATAL, "`incbin': unable to open file `%s'",
+ nasm_error(ERR_NONFATAL, "`incbin': unable to open file `%s'",
fname);
else if (fseek(fp, 0L, SEEK_END) < 0)
- error(ERR_NONFATAL, "`incbin': unable to seek on file `%s'",
+ nasm_error(ERR_NONFATAL, "`incbin': unable to seek on file `%s'",
fname);
else {
len = ftell(fp);
@@ -912,14 +903,14 @@ static void bad_hle_warn(const insn * ins, uint8_t hleok)
case w_lock:
if (ins->prefixes[PPS_LOCK] != P_LOCK) {
- errfunc(ERR_WARNING | ERR_WARN_HLE | ERR_PASS2,
+ nasm_error(ERR_WARNING | ERR_WARN_HLE | ERR_PASS2,
"%s with this instruction requires lock",
prefix_name(rep_pfx));
}
break;
case w_inval:
- errfunc(ERR_WARNING | ERR_WARN_HLE | ERR_PASS2,
+ nasm_error(ERR_WARNING | ERR_WARN_HLE | ERR_PASS2,
"%s invalid with this instruction",
prefix_name(rep_pfx));
break;
@@ -1117,7 +1108,7 @@ static int64_t calcsize(int32_t segment, int64_t offset, int bits,
if (pfx == P_O16)
break;
if (pfx != P_none)
- errfunc(ERR_WARNING | ERR_PASS2, "invalid operand size prefix");
+ nasm_error(ERR_WARNING | ERR_PASS2, "invalid operand size prefix");
else
ins->prefixes[PPS_OSIZE] = P_O16;
break;
@@ -1129,7 +1120,7 @@ static int64_t calcsize(int32_t segment, int64_t offset, int bits,
if (pfx == P_O32)
break;
if (pfx != P_none)
- errfunc(ERR_WARNING | ERR_PASS2, "invalid operand size prefix");
+ nasm_error(ERR_WARNING | ERR_PASS2, "invalid operand size prefix");
else
ins->prefixes[PPS_OSIZE] = P_O32;
break;
@@ -1184,7 +1175,7 @@ static int64_t calcsize(int32_t segment, int64_t offset, int bits,
case 0340:
if (ins->oprs[0].segment != NO_SEG)
- errfunc(ERR_NONFATAL, "attempt to reserve non-constant"
+ nasm_error(ERR_NONFATAL, "attempt to reserve non-constant"
" quantity of BSS space");
else
length += ins->oprs[0].offset;
@@ -1299,7 +1290,7 @@ static int64_t calcsize(int32_t segment, int64_t offset, int bits,
if (process_ea(opy, &ea_data, bits,
rfield, rflags, ins) != eat) {
- errfunc(ERR_NONFATAL, "invalid effective address");
+ nasm_error(ERR_NONFATAL, "invalid effective address");
return -1;
} else {
ins->rex |= ea_data.rex;
@@ -1309,7 +1300,7 @@ static int64_t calcsize(int32_t segment, int64_t offset, int bits,
break;
default:
- errfunc(ERR_PANIC, "internal instruction table corrupt"
+ nasm_error(ERR_PANIC, "internal instruction table corrupt"
": instruction code \\%o (0x%02X) given", c, c);
break;
}
@@ -1319,7 +1310,7 @@ static int64_t calcsize(int32_t segment, int64_t offset, int bits,
if (ins->rex & REX_NH) {
if (ins->rex & REX_H) {
- errfunc(ERR_NONFATAL, "instruction cannot use high registers");
+ nasm_error(ERR_NONFATAL, "instruction cannot use high registers");
return -1;
}
ins->rex &= ~REX_P; /* Don't force REX prefix due to high reg */
@@ -1343,7 +1334,7 @@ static int64_t calcsize(int32_t segment, int64_t offset, int bits,
int bad32 = REX_R|REX_W|REX_X|REX_B;
if (ins->rex & REX_H) {
- errfunc(ERR_NONFATAL, "cannot use high register in AVX instruction");
+ nasm_error(ERR_NONFATAL, "cannot use high register in AVX instruction");
return -1;
}
switch (ins->vex_wlp & 060) {
@@ -1361,11 +1352,11 @@ static int64_t calcsize(int32_t segment, int64_t offset, int bits,
}
if (bits != 64 && ((ins->rex & bad32) || ins->vexreg > 7)) {
- errfunc(ERR_NONFATAL, "invalid operands in non-64-bit mode");
+ nasm_error(ERR_NONFATAL, "invalid operands in non-64-bit mode");
return -1;
} else if (!(ins->rex & REX_EV) &&
((ins->vexreg > 15) || (ins->evex_p[0] & 0xf0))) {
- errfunc(ERR_NONFATAL, "invalid high-16 register in non-AVX-512");
+ nasm_error(ERR_NONFATAL, "invalid high-16 register in non-AVX-512");
return -1;
}
if (ins->rex & REX_EV)
@@ -1377,7 +1368,7 @@ static int64_t calcsize(int32_t segment, int64_t offset, int bits,
length += 2;
} else if (ins->rex & REX_MASK) {
if (ins->rex & REX_H) {
- errfunc(ERR_NONFATAL, "cannot use high register in rex instruction");
+ nasm_error(ERR_NONFATAL, "cannot use high register in rex instruction");
return -1;
} else if (bits == 64) {
length++;
@@ -1389,14 +1380,14 @@ static int64_t calcsize(int32_t segment, int64_t offset, int bits,
lockcheck = false; /* Already errored, no need for warning */
length++;
} else {
- errfunc(ERR_NONFATAL, "invalid operands in non-64-bit mode");
+ nasm_error(ERR_NONFATAL, "invalid operands in non-64-bit mode");
return -1;
}
}
if (has_prefix(ins, PPS_LOCK, P_LOCK) && lockcheck &&
(!itemp_has(temp,IF_LOCK) || !is_class(MEMORY, ins->oprs[0].type))) {
- errfunc(ERR_WARNING | ERR_WARN_LOCK | ERR_PASS2 ,
+ nasm_error(ERR_WARNING | ERR_WARN_LOCK | ERR_PASS2 ,
"instruction is not lockable");
}
@@ -1482,7 +1473,7 @@ static void gencode(int32_t segment, int64_t offset, int bits,
case4(020):
if (opx->offset < -256 || opx->offset > 255) {
- errfunc(ERR_WARNING | ERR_PASS2 | ERR_WARN_NOV,
+ nasm_error(ERR_WARNING | ERR_PASS2 | ERR_WARN_NOV,
"byte value exceeds bounds");
}
out_imm8(offset, segment, opx, -1);
@@ -1491,7 +1482,7 @@ static void gencode(int32_t segment, int64_t offset, int bits,
case4(024):
if (opx->offset < 0 || opx->offset > 255)
- errfunc(ERR_WARNING | ERR_PASS2 | ERR_WARN_NOV,
+ nasm_error(ERR_WARNING | ERR_PASS2 | ERR_WARN_NOV,
"unsigned byte value exceeds bounds");
out_imm8(offset, segment, opx, 1);
offset += 1;
@@ -1543,7 +1534,7 @@ static void gencode(int32_t segment, int64_t offset, int bits,
} else {
data = opx->offset - insn_end;
if (data > 127 || data < -128)
- errfunc(ERR_NONFATAL, "short jump is out of range");
+ nasm_error(ERR_NONFATAL, "short jump is out of range");
out(offset, segment, &data,
OUT_ADDRESS, 1, NO_SEG, NO_SEG);
}
@@ -1605,11 +1596,11 @@ static void gencode(int32_t segment, int64_t offset, int bits,
case4(074):
if (opx->segment == NO_SEG)
- errfunc(ERR_NONFATAL, "value referenced by FAR is not"
+ nasm_error(ERR_NONFATAL, "value referenced by FAR is not"
" relocatable");
data = 0;
out(offset, segment, &data, OUT_ADDRESS, 2,
- outfmt->segbase(1 + opx->segment),
+ ofmt->segbase(1 + opx->segment),
opx->wrt);
offset += 2;
break;
@@ -1620,12 +1611,12 @@ static void gencode(int32_t segment, int64_t offset, int bits,
bytes[0] = nasm_regvals[opx->basereg] << 4;
opx = &ins->oprs[c & 7];
if (opx->segment != NO_SEG || opx->wrt != NO_SEG) {
- errfunc(ERR_NONFATAL,
+ nasm_error(ERR_NONFATAL,
"non-absolute expression not permitted as argument %d",
c & 7);
} else {
if (opx->offset & ~15) {
- errfunc(ERR_WARNING | ERR_PASS2 | ERR_WARN_NOV,
+ nasm_error(ERR_WARNING | ERR_PASS2 | ERR_WARN_NOV,
"four-bit argument exceeds bounds");
}
bytes[0] |= opx->offset & 15;
@@ -1653,7 +1644,7 @@ static void gencode(int32_t segment, int64_t offset, int bits,
data = opx->offset;
if (opx->wrt == NO_SEG && opx->segment == NO_SEG &&
(int32_t)data != (int64_t)data) {
- errfunc(ERR_WARNING | ERR_PASS2 | ERR_WARN_NOV,
+ nasm_error(ERR_WARNING | ERR_PASS2 | ERR_WARN_NOV,
"signed dword immediate exceeds bounds");
}
out(offset, segment, &data, OUT_ADDRESS, -4,
@@ -1727,7 +1718,7 @@ static void gencode(int32_t segment, int64_t offset, int bits,
/* If this wasn't explicitly byte-sized, warn as though we
* had fallen through to the imm16/32/64 case.
*/
- errfunc(ERR_WARNING | ERR_PASS2 | ERR_WARN_NOV,
+ nasm_error(ERR_WARNING | ERR_PASS2 | ERR_WARN_NOV,
"%s value exceeds bounds",
(opx->type & BITS8) ? "signed byte" :
s == 16 ? "word" :
@@ -1830,7 +1821,7 @@ static void gencode(int32_t segment, int64_t offset, int bits,
case 0340:
if (ins->oprs[0].segment != NO_SEG)
- errfunc(ERR_PANIC, "non-constant BSS size in pass two");
+ nasm_error(ERR_PANIC, "non-constant BSS size in pass two");
else {
int64_t size = ins->oprs[0].offset;
if (size > 0)
@@ -1916,7 +1907,7 @@ static void gencode(int32_t segment, int64_t offset, int bits,
if (process_ea(opy, &ea_data, bits,
rfield, rflags, ins) != eat)
- errfunc(ERR_NONFATAL, "invalid effective address");
+ nasm_error(ERR_NONFATAL, "invalid effective address");
p = bytes;
*p++ = ea_data.modrm;
@@ -1975,7 +1966,7 @@ static void gencode(int32_t segment, int64_t offset, int bits,
break;
default:
- errfunc(ERR_PANIC, "internal instruction table corrupt"
+ nasm_error(ERR_PANIC, "internal instruction table corrupt"
": instruction code \\%o (0x%02X) given", c, c);
break;
}
@@ -1985,14 +1976,14 @@ static void gencode(int32_t segment, int64_t offset, int bits,
static opflags_t regflag(const operand * o)
{
if (!is_register(o->basereg))
- errfunc(ERR_PANIC, "invalid operand passed to regflag()");
+ nasm_error(ERR_PANIC, "invalid operand passed to regflag()");
return nasm_reg_flags[o->basereg];
}
static int32_t regval(const operand * o)
{
if (!is_register(o->basereg))
- errfunc(ERR_PANIC, "invalid operand passed to regval()");
+ nasm_error(ERR_PANIC, "invalid operand passed to regval()");
return nasm_regvals[o->basereg];
}
@@ -2002,7 +1993,7 @@ static int op_rexflags(const operand * o, int mask)
int val;
if (!is_register(o->basereg))
- errfunc(ERR_PANIC, "invalid operand passed to op_rexflags()");
+ nasm_error(ERR_PANIC, "invalid operand passed to op_rexflags()");
flags = nasm_reg_flags[o->basereg];
val = nasm_regvals[o->basereg];
@@ -2159,7 +2150,7 @@ static uint8_t get_broadcast_num(opflags_t opflags, opflags_t brsize)
* this cannot be a simple arithmetic calculation.
*/
if (brsize > BITS64)
- errfunc(ERR_FATAL,
+ nasm_error(ERR_FATAL,
"size of broadcasting element is greater than 64 bits");
switch (opsize) {
@@ -2966,7 +2957,7 @@ static void add_asp(insn *ins, int addrbits)
ins->addr_size = (addrbits == 32) ? 16 : 32;
} else {
/* Impossible... */
- errfunc(ERR_NONFATAL, "impossible combination of address sizes");
+ nasm_error(ERR_NONFATAL, "impossible combination of address sizes");
ins->addr_size = addrbits; /* Error recovery */
}
diff --git a/assemble.h b/assemble.h
index 381e3ab5..f85037ad 100644
--- a/assemble.h
+++ b/assemble.h
@@ -41,8 +41,7 @@
#include "iflag.h"
int64_t insn_size(int32_t segment, int64_t offset, int bits, iflag_t cp,
- insn * instruction, efunc error);
+ insn * instruction);
int64_t assemble(int32_t segment, int64_t offset, int bits, iflag_t cp,
- insn * instruction, struct ofmt *output, efunc error,
- ListGen * listgen);
+ insn * instruction);
#endif
diff --git a/eval.c b/eval.c
index 403a793e..a8e463f2 100644
--- a/eval.c
+++ b/eval.c
@@ -54,7 +54,6 @@
#define TEMPEXPR_DELTA 8
static scanner scan; /* Address of scanner routine */
-static efunc error; /* Address of error reporting routine */
static lfunc labelfunc; /* Address of label routine */
static struct ofmt *outfmt; /* Structure of addresses of output routines */
@@ -227,18 +226,18 @@ static expr *segment_part(expr * e)
return unknown_expr();
if (!is_reloc(e)) {
- error(ERR_NONFATAL, "cannot apply SEG to a non-relocatable value");
+ nasm_error(ERR_NONFATAL, "cannot apply SEG to a non-relocatable value");
return NULL;
}
seg = reloc_seg(e);
if (seg == NO_SEG) {
- error(ERR_NONFATAL, "cannot apply SEG to a non-relocatable value");
+ nasm_error(ERR_NONFATAL, "cannot apply SEG to a non-relocatable value");
return NULL;
} else if (seg & SEG_ABS) {
return scalarvect(seg & ~SEG_ABS);
} else if (seg & 1) {
- error(ERR_NONFATAL, "SEG applied to something which"
+ nasm_error(ERR_NONFATAL, "SEG applied to something which"
" is already a segment base");
return NULL;
} else {
@@ -306,7 +305,7 @@ static expr *rexp0(int critical)
return NULL;
if (!(is_simple(e) || is_just_unknown(e)) ||
!(is_simple(f) || is_just_unknown(f))) {
- error(ERR_NONFATAL, "`|' operator may only be applied to"
+ nasm_error(ERR_NONFATAL, "`|' operator may only be applied to"
" scalar values");
}
@@ -333,7 +332,7 @@ static expr *rexp1(int critical)
return NULL;
if (!(is_simple(e) || is_just_unknown(e)) ||
!(is_simple(f) || is_just_unknown(f))) {
- error(ERR_NONFATAL, "`^' operator may only be applied to"
+ nasm_error(ERR_NONFATAL, "`^' operator may only be applied to"
" scalar values");
}
@@ -359,7 +358,7 @@ static expr *rexp2(int critical)
return NULL;
if (!(is_simple(e) || is_just_unknown(e)) ||
!(is_simple(f) || is_just_unknown(f))) {
- error(ERR_NONFATAL, "`&' operator may only be applied to"
+ nasm_error(ERR_NONFATAL, "`&' operator may only be applied to"
" scalar values");
}
if (is_just_unknown(e) || is_just_unknown(f))
@@ -403,7 +402,7 @@ static expr *rexp3(int critical)
if (is_unknown(e))
v = -1; /* means unknown */
else if (!is_really_simple(e)) {
- error(ERR_NONFATAL,
+ nasm_error(ERR_NONFATAL,
"`%s': operands differ by a non-scalar",
(j == TOKEN_LE ? "<=" : j == TOKEN_LT ? "<" : j ==
TOKEN_GE ? ">=" : ">"));
@@ -443,7 +442,7 @@ static expr *expr0(int critical)
return NULL;
if (!(is_simple(e) || is_just_unknown(e)) ||
!(is_simple(f) || is_just_unknown(f))) {
- error(ERR_NONFATAL, "`|' operator may only be applied to"
+ nasm_error(ERR_NONFATAL, "`|' operator may only be applied to"
" scalar values");
}
if (is_just_unknown(e) || is_just_unknown(f))
@@ -469,7 +468,7 @@ static expr *expr1(int critical)
return NULL;
if (!(is_simple(e) || is_just_unknown(e)) ||
!(is_simple(f) || is_just_unknown(f))) {
- error(ERR_NONFATAL, "`^' operator may only be applied to"
+ nasm_error(ERR_NONFATAL, "`^' operator may only be applied to"
" scalar values");
}
if (is_just_unknown(e) || is_just_unknown(f))
@@ -495,7 +494,7 @@ static expr *expr2(int critical)
return NULL;
if (!(is_simple(e) || is_just_unknown(e)) ||
!(is_simple(f) || is_just_unknown(f))) {
- error(ERR_NONFATAL, "`&' operator may only be applied to"
+ nasm_error(ERR_NONFATAL, "`&' operator may only be applied to"
" scalar values");
}
if (is_just_unknown(e) || is_just_unknown(f))
@@ -522,7 +521,7 @@ static expr *expr3(int critical)
return NULL;
if (!(is_simple(e) || is_just_unknown(e)) ||
!(is_simple(f) || is_just_unknown(f))) {
- error(ERR_NONFATAL, "shift operator may only be applied to"
+ nasm_error(ERR_NONFATAL, "shift operator may only be applied to"
" scalar values");
} else if (is_just_unknown(e) || is_just_unknown(f)) {
e = unknown_expr();
@@ -581,12 +580,12 @@ static expr *expr5(int critical)
return NULL;
if (j != '*' && (!(is_simple(e) || is_just_unknown(e)) ||
!(is_simple(f) || is_just_unknown(f)))) {
- error(ERR_NONFATAL, "division operator may only be applied to"
+ nasm_error(ERR_NONFATAL, "division operator may only be applied to"
" scalar values");
return NULL;
}
if (j != '*' && !is_unknown(f) && reloc_value(f) == 0) {
- error(ERR_NONFATAL, "division by zero");
+ nasm_error(ERR_NONFATAL, "division by zero");
return NULL;
}
switch (j) {
@@ -598,7 +597,7 @@ static expr *expr5(int critical)
else if (is_just_unknown(e) && is_just_unknown(f))
e = unknown_expr();
else {
- error(ERR_NONFATAL, "unable to multiply two "
+ nasm_error(ERR_NONFATAL, "unable to multiply two "
"non-scalar objects");
return NULL;
}
@@ -657,7 +656,7 @@ static expr *eval_floatize(enum floatize type)
i = scan(scpriv, tokval);
if (i != '(') {
- error(ERR_NONFATAL, "expecting `('");
+ nasm_error(ERR_NONFATAL, "expecting `('");
return NULL;
}
i = scan(scpriv, tokval);
@@ -666,15 +665,14 @@ static expr *eval_floatize(enum floatize type)
i = scan(scpriv, tokval);
}
if (i != TOKEN_FLOAT) {
- error(ERR_NONFATAL, "expecting floating-point number");
+ nasm_error(ERR_NONFATAL, "expecting floating-point number");
return NULL;
}
- if (!float_const(tokval->t_charptr, sign, result,
- formats[type].bytes, error))
+ if (!float_const(tokval->t_charptr, sign, result, formats[type].bytes))
return NULL;
i = scan(scpriv, tokval);
if (i != ')') {
- error(ERR_NONFATAL, "expecting `)'");
+ nasm_error(ERR_NONFATAL, "expecting `)'");
return NULL;
}
@@ -706,13 +704,13 @@ static expr *eval_strfunc(enum strfunc type)
i = scan(scpriv, tokval);
}
if (i != TOKEN_STR) {
- error(ERR_NONFATAL, "expecting string");
+ nasm_error(ERR_NONFATAL, "expecting string");
return NULL;
}
string_len = string_transform(tokval->t_charptr, tokval->t_inttwo,
&string, type);
if (string_len == (size_t)-1) {
- error(ERR_NONFATAL, "invalid string for transform");
+ nasm_error(ERR_NONFATAL, "invalid string for transform");
return NULL;
}
@@ -720,13 +718,13 @@ static expr *eval_strfunc(enum strfunc type)
if (parens) {
i = scan(scpriv, tokval);
if (i != ')') {
- error(ERR_NONFATAL, "expecting `)'");
+ nasm_error(ERR_NONFATAL, "expecting `)'");
return NULL;
}
}
if (rn_warn)
- error(ERR_WARNING|ERR_PASS1, "character constant too long");
+ nasm_error(ERR_WARNING|ERR_PASS1, "character constant too long");
begintemp();
addtotemp(EXPR_SIMPLE, val);
@@ -747,7 +745,7 @@ static int64_t eval_ifunc(int64_t val, enum ifunc func)
errtype = (func == IFUNC_ILOG2E) ? ERR_NONFATAL : ERR_WARNING;
if (!is_power2(uval))
- error(errtype, "ilog2 argument is not a power of two");
+ nasm_error(errtype, "ilog2 argument is not a power of two");
/* fall through */
case IFUNC_ILOG2F:
rv = ilog2_64(uval);
@@ -758,7 +756,7 @@ static int64_t eval_ifunc(int64_t val, enum ifunc func)
break;
default:
- error(ERR_PANIC, "invalid IFUNC token %d", func);
+ nasm_error(ERR_PANIC, "invalid IFUNC token %d", func);
rv = 0;
break;
}
@@ -796,7 +794,7 @@ static expr *expr6(int critical)
if (is_just_unknown(e))
return unknown_expr();
else if (!is_simple(e)) {
- error(ERR_NONFATAL, "`~' operator may only be applied to"
+ nasm_error(ERR_NONFATAL, "`~' operator may only be applied to"
" scalar values");
return NULL;
}
@@ -810,7 +808,7 @@ static expr *expr6(int critical)
if (is_just_unknown(e))
return unknown_expr();
else if (!is_simple(e)) {
- error(ERR_NONFATAL, "`!' operator may only be applied to"
+ nasm_error(ERR_NONFATAL, "`!' operator may only be applied to"
" scalar values");
return NULL;
}
@@ -826,7 +824,7 @@ static expr *expr6(int critical)
if (is_just_unknown(e))
return unknown_expr();
else if (!is_simple(e)) {
- error(ERR_NONFATAL, "function may only be applied to"
+ nasm_error(ERR_NONFATAL, "function may only be applied to"
" scalar values");
return NULL;
}
@@ -842,7 +840,7 @@ static expr *expr6(int critical)
if (!e)
return NULL;
if (is_unknown(e) && critical) {
- error(ERR_NONFATAL, "unable to determine segment base");
+ nasm_error(ERR_NONFATAL, "unable to determine segment base");
return NULL;
}
return e;
@@ -859,7 +857,7 @@ static expr *expr6(int critical)
if (!e)
return NULL;
if (i != ')') {
- error(ERR_NONFATAL, "expecting `)'");
+ nasm_error(ERR_NONFATAL, "expecting `)'");
return NULL;
}
i = scan(scpriv, tokval);
@@ -881,7 +879,7 @@ static expr *expr6(int critical)
case TOKEN_STR:
tmpval = readstrnum(tokval->t_charptr, tokval->t_inttwo, &rn_warn);
if (rn_warn)
- error(ERR_WARNING|ERR_PASS1, "character constant too long");
+ nasm_error(ERR_WARNING|ERR_PASS1, "character constant too long");
addtotemp(EXPR_SIMPLE, tmpval);
break;
case TOKEN_REG:
@@ -899,7 +897,7 @@ static expr *expr6(int critical)
* are in preprocess-only mode.
*/
if (!location->known) {
- error(ERR_NONFATAL,
+ nasm_error(ERR_NONFATAL,
"%s not supported in preprocess-only mode",
(i == TOKEN_HERE ? "`$'" :
i == TOKEN_BASE ? "`$$'" :
@@ -919,11 +917,11 @@ static expr *expr6(int critical)
if (!labelfunc(tokval->t_charptr, &label_seg, &label_ofs)) {
scope = local_scope(tokval->t_charptr);
if (critical == 2) {
- error(ERR_NONFATAL, "symbol `%s%s' undefined",
+ nasm_error(ERR_NONFATAL, "symbol `%s%s' undefined",
scope,tokval->t_charptr);
return NULL;
} else if (critical == 1) {
- error(ERR_NONFATAL,
+ nasm_error(ERR_NONFATAL,
"symbol `%s%s' not defined before use",
scope,tokval->t_charptr);
return NULL;
@@ -950,7 +948,7 @@ static expr *expr6(int critical)
return finishtemp();
default:
- error(ERR_NONFATAL, "expression syntax error");
+ nasm_error(ERR_NONFATAL, "expression syntax error");
return NULL;
}
}
@@ -964,8 +962,7 @@ void eval_global_info(struct ofmt *output, lfunc lookup_label,
}
expr *evaluate(scanner sc, void *scprivate, struct tokenval *tv,
- int *fwref, int critical, efunc report_error,
- struct eval_hints *hints)
+ int *fwref, int critical, struct eval_hints *hints)
{
expr *e;
expr *f = NULL;
@@ -983,7 +980,6 @@ expr *evaluate(scanner sc, void *scprivate, struct tokenval *tv,
scan = sc;
scpriv = scprivate;
tokval = tv;
- error = report_error;
opflags = fwref;
if (tokval->t_type == TOKEN_INVALID)
@@ -1013,14 +1009,14 @@ expr *evaluate(scanner sc, void *scprivate, struct tokenval *tv,
int64_t value;
begintemp();
if (!is_reloc(f)) {
- error(ERR_NONFATAL, "invalid right-hand operand to WRT");
+ nasm_error(ERR_NONFATAL, "invalid right-hand operand to WRT");
return NULL;
}
value = reloc_seg(f);
if (value == NO_SEG)
value = reloc_value(f) | SEG_ABS;
else if (!(value & SEG_ABS) && !(value % 2) && critical) {
- error(ERR_NONFATAL, "invalid right-hand operand to WRT");
+ nasm_error(ERR_NONFATAL, "invalid right-hand operand to WRT");
return NULL;
}
addtotemp(EXPR_WRT, value);
diff --git a/eval.h b/eval.h
index 0ea59d17..76ea14b5 100644
--- a/eval.h
+++ b/eval.h
@@ -50,8 +50,7 @@ void eval_global_info(struct ofmt *output, lfunc lookup_label,
* The evaluator itself.
*/
expr *evaluate(scanner sc, void *scprivate, struct tokenval *tv,
- int *fwref, int critical, efunc report_error,
- struct eval_hints *hints);
+ int *fwref, int critical, struct eval_hints *hints);
void eval_cleanup(void);
diff --git a/float.c b/float.c
index 7a4f8cbe..adf18c5b 100644
--- a/float.c
+++ b/float.c
@@ -51,7 +51,6 @@
* local variables
* -----------------
*/
-static efunc error;
static bool daz = false; /* denormals as zero */
static enum float_round rc = FLOAT_RC_NEAR; /* rounding control */
@@ -183,7 +182,7 @@ static int32_t read_exponent(const char *string, int32_t max)
} else if (*string == '_') {
/* do nothing */
} else {
- error(ERR_NONFATAL|ERR_PASS1,
+ nasm_error(ERR_NONFATAL|ERR_PASS1,
"invalid character in floating-point constant %s: '%c'",
"exponent", *string);
return INT32_MAX;
@@ -220,7 +219,7 @@ static bool ieee_flconvert(const char *string, fp_limb *mant,
if (!seendot) {
seendot = true;
} else {
- error(ERR_NONFATAL|ERR_PASS1,
+ nasm_error(ERR_NONFATAL|ERR_PASS1,
"too many periods in floating-point constant");
return false;
}
@@ -235,7 +234,7 @@ static bool ieee_flconvert(const char *string, fp_limb *mant,
*p++ = *string - '0';
} else {
if (!warned) {
- error(ERR_WARNING|ERR_WARN_FL_TOOLONG|ERR_PASS1,
+ nasm_error(ERR_WARNING|ERR_WARN_FL_TOOLONG|ERR_PASS1,
"floating-point constant significand contains "
"more than %i digits", MANT_DIGITS);
warned = true;
@@ -248,7 +247,7 @@ static bool ieee_flconvert(const char *string, fp_limb *mant,
} else if (*string == '_') {
/* do nothing */
} else {
- error(ERR_NONFATAL|ERR_PASS1,
+ nasm_error(ERR_NONFATAL|ERR_PASS1,
"invalid character in floating-point constant %s: '%c'",
"significand", *string);
return false;
@@ -534,7 +533,7 @@ static bool ieee_flconvert_bin(const char *string, int bits,
if (!seendot)
seendot = true;
else {
- error(ERR_NONFATAL|ERR_PASS1,
+ nasm_error(ERR_NONFATAL|ERR_PASS1,
"too many periods in floating-point constant");
return false;
}
@@ -576,7 +575,7 @@ static bool ieee_flconvert_bin(const char *string, int bits,
} else if (c == '_') {
/* ignore */
} else {
- error(ERR_NONFATAL|ERR_PASS1,
+ nasm_error(ERR_NONFATAL|ERR_PASS1,
"floating-point constant: `%c' is invalid character", c);
return false;
}
@@ -674,7 +673,7 @@ static int to_packed_bcd(const char *str, const char *p,
int tv = -1;
if (fmt != &ieee_80) {
- error(ERR_NONFATAL|ERR_PASS1,
+ nasm_error(ERR_NONFATAL|ERR_PASS1,
"packed BCD requires an 80-bit format");
return 0;
}
@@ -684,7 +683,7 @@ static int to_packed_bcd(const char *str, const char *p,
if (c >= '0' && c <= '9') {
if (tv < 0) {
if (n == 9) {
- error(ERR_WARNING|ERR_PASS1,
+ nasm_error(ERR_WARNING|ERR_PASS1,
"packed BCD truncated to 18 digits");
}
tv = c-'0';
@@ -697,7 +696,7 @@ static int to_packed_bcd(const char *str, const char *p,
} else if (c == '_') {
/* do nothing */
} else {
- error(ERR_NONFATAL|ERR_PASS1,
+ nasm_error(ERR_NONFATAL|ERR_PASS1,
"invalid character `%c' in packed BCD constant", c);
return 0;
}
@@ -734,7 +733,7 @@ static int to_float(const char *str, int s, uint8_t *result,
const char *strend;
if (!str[0]) {
- error(ERR_PANIC,
+ nasm_error(ERR_PANIC,
"internal errror: empty string passed to float_const");
return 0;
}
@@ -762,7 +761,7 @@ static int to_float(const char *str, int s, uint8_t *result,
type = FL_INFINITY;
break;
default:
- error(ERR_NONFATAL|ERR_PASS1,
+ nasm_error(ERR_NONFATAL|ERR_PASS1,
"internal error: unknown FP constant token `%s'\n", str);
type = FL_QNAN;
break;
@@ -810,7 +809,7 @@ static int to_float(const char *str, int s, uint8_t *result,
type = FL_NORMAL;
} else if (exponent > 0) {
if (pass0 == 1)
- error(ERR_WARNING|ERR_WARN_FL_OVERFLOW|ERR_PASS1,
+ nasm_error(ERR_WARNING|ERR_WARN_FL_OVERFLOW|ERR_PASS1,
"overflow in floating-point constant");
type = FL_INFINITY;
} else {
@@ -845,11 +844,11 @@ static int to_float(const char *str, int s, uint8_t *result,
} else {
if (daz || is_zero(mant)) {
/* Flush denormals to zero */
- error(ERR_WARNING|ERR_WARN_FL_UNDERFLOW|ERR_PASS1,
+ nasm_error(ERR_WARNING|ERR_WARN_FL_UNDERFLOW|ERR_PASS1,
"underflow in floating-point constant");
goto zero;
} else {
- error(ERR_WARNING|ERR_WARN_FL_DENORM|ERR_PASS1,
+ nasm_error(ERR_WARNING|ERR_WARN_FL_DENORM|ERR_PASS1,
"denormal floating-point constant");
}
}
@@ -865,7 +864,7 @@ static int to_float(const char *str, int s, uint8_t *result,
ieee_shr(mant, 1);
exponent++;
if (exponent >= (expmax << 1)-1) {
- error(ERR_WARNING|ERR_WARN_FL_OVERFLOW|ERR_PASS1,
+ nasm_error(ERR_WARNING|ERR_WARN_FL_OVERFLOW|ERR_PASS1,
"overflow in floating-point constant");
type = FL_INFINITY;
goto overflow;
@@ -901,11 +900,8 @@ static int to_float(const char *str, int s, uint8_t *result,
return 1; /* success */
}
-int float_const(const char *number, int sign, uint8_t *result,
- int bytes, efunc err)
+int float_const(const char *number, int sign, uint8_t *result, int bytes)
{
- error = err;
-
switch (bytes) {
case 1:
return to_float(number, sign, result, &ieee_8);
@@ -920,7 +916,7 @@ int float_const(const char *number, int sign, uint8_t *result,
case 16:
return to_float(number, sign, result, &ieee_128);
default:
- error(ERR_PANIC, "strange value %d passed to float_const", bytes);
+ nasm_error(ERR_PANIC, "strange value %d passed to float_const", bytes);
return 0;
}
}
diff --git a/float.h b/float.h
index 6823cd4c..b07e542a 100644
--- a/float.h
+++ b/float.h
@@ -48,8 +48,7 @@ enum float_round {
FLOAT_RC_UP
};
-int float_const(const char *string, int sign, uint8_t *result, int bytes,
- efunc error);
+int float_const(const char *string, int sign, uint8_t *result, int bytes);
int float_option(const char *option);
#endif
diff --git a/listing.c b/listing.c
index 8da58eb5..fa850448 100644
--- a/listing.c
+++ b/listing.c
@@ -126,12 +126,17 @@ static void list_emit(void)
}
}
-static void list_init(char *fname, efunc error)
+static void list_init(const char *fname)
{
+ if (!fname) {
+ listfp = NULL;
+ return;
+ }
+
listfp = fopen(fname, "w");
if (!listfp) {
- error(ERR_NONFATAL, "unable to open listing file `%s'",
- fname);
+ nasm_error(ERR_NONFATAL, "unable to open listing file `%s'",
+ fname);
return;
}
@@ -197,7 +202,7 @@ static void list_output(int32_t offset, const void *data,
{
char q[20];
- if (!listp || suppress || user_nolist) /* fbk - 9/2/00 */
+ if (!listp || suppress || user_nolist)
return;
switch (type) {
@@ -321,7 +326,7 @@ static void list_error(int severity, const char *pfx, const char *msg)
}
-ListGen nasmlist = {
+static const ListGen nasm_list = {
list_init,
list_cleanup,
list_output,
@@ -330,3 +335,5 @@ ListGen nasmlist = {
list_downlevel,
list_error
};
+
+const ListGen *nasmlist = &nasm_list;
diff --git a/listing.h b/listing.h
index da2e849f..8e178b0b 100644
--- a/listing.h
+++ b/listing.h
@@ -38,7 +38,7 @@
#ifndef NASM_LISTING_H
#define NASM_LISTING_H
-extern ListGen nasmlist;
-extern int user_nolist; /* fbk - 9/1/00 */
+extern const ListGen *nasmlist;
+extern bool user_nolist;
#endif
diff --git a/nasm.c b/nasm.c
index ba42aa88..42f1e894 100644
--- a/nasm.c
+++ b/nasm.c
@@ -78,10 +78,10 @@ static int get_bits(char *value);
static iflag_t get_cpu(char *cpu_str);
static void parse_cmdline(int, char **);
static void assemble_file(char *, StrList **);
+static bool is_suppressed_warning(int severity);
static void nasm_verror_gnu(int severity, const char *fmt, va_list args);
static void nasm_verror_vc(int severity, const char *fmt, va_list args);
static void nasm_verror_common(int severity, const char *fmt, va_list args);
-static bool is_suppressed_warning(int severity);
static void usage(void);
static int using_debug_info, opt_verbose_info;
@@ -172,7 +172,7 @@ static const struct warning {
static bool want_usage;
static bool terminate_after_phase;
-int user_nolist = 0; /* fbk 9/2/00 */
+bool user_nolist = false;
static char *quote_for_make(const char *str);
@@ -377,7 +377,7 @@ int main(int argc, char **argv)
if (depend_missing_ok)
preproc->include_path(NULL); /* "assume generated" */
- preproc->reset(inname, 0, &nasmlist, depend_ptr);
+ preproc->reset(inname, 0, depend_ptr);
if (outname[0] == '\0')
ofmt->filename(inname, outname);
ofile = NULL;
@@ -402,8 +402,9 @@ int main(int argc, char **argv)
location.known = false;
/* pass = 1; */
- preproc->reset(inname, 3, &nasmlist, depend_ptr);
- memcpy(warning_on, warning_on_global, (ERR_WARN_MAX+1) * sizeof(bool));
+ preproc->reset(inname, 3, depend_ptr);
+ memcpy(warning_on, warning_on_global,
+ (ERR_WARN_MAX+1) * sizeof(bool));
while ((line = preproc->getline())) {
/*
@@ -1200,8 +1201,7 @@ static void assemble_file(char *fname, StrList **depend_ptr)
int pass_max;
if (cmd_sb == 32 && iflag_ffs(&cmd_cpu) < IF_386)
- nasm_fatal(0, "command line: "
- "32-bit segment size requires a higher cpu");
+ nasm_fatal(0, "command line: 32-bit segment size requires a higher cpu");
pass_max = prev_offset_changed = (INT_MAX >> 1) + 2; /* Almost unlimited */
for (passn = 1; pass0 <= 2; passn++) {
@@ -1217,8 +1217,7 @@ static void assemble_file(char *fname, StrList **depend_ptr)
globalbits = sb = cmd_sb; /* set 'bits' to command line default */
cpu = cmd_cpu;
if (pass0 == 2) {
- if (*listname)
- nasmlist.init(listname, nasm_error);
+ nasmlist->init(listname);
}
in_abs_seg = false;
global_offset_changed = 0; /* set by redefine_label */
@@ -1230,8 +1229,7 @@ static void assemble_file(char *fname, StrList **depend_ptr)
raa_free(offsets);
offsets = raa_init();
}
- preproc->reset(fname, pass1, &nasmlist,
- pass1 == 2 ? depend_ptr : NULL);
+ preproc->reset(fname, pass1, pass1 == 2 ? depend_ptr : NULL);
memcpy(warning_on, warning_on_global, (ERR_WARN_MAX+1) * sizeof(bool));
globallineno = 0;
@@ -1270,7 +1268,7 @@ static void assemble_file(char *fname, StrList **depend_ptr)
stdscan_reset();
stdscan_set(value);
tokval.t_type = TOKEN_INVALID;
- e = evaluate(stdscan, NULL, &tokval, NULL, pass2, nasm_error, NULL);
+ e = evaluate(stdscan, NULL, &tokval, NULL, pass2, NULL);
if (e) {
unsigned int align = (unsigned int)e->value;
if ((uint64_t)e->value > 0x7fffffff) {
@@ -1428,8 +1426,7 @@ static void assemble_file(char *fname, StrList **depend_ptr)
stdscan_reset();
stdscan_set(value);
tokval.t_type = TOKEN_INVALID;
- e = evaluate(stdscan, NULL, &tokval, NULL, pass2,
- nasm_error, NULL);
+ e = evaluate(stdscan, NULL, &tokval, NULL, pass2, NULL);
if (e) {
if (!is_reloc(e))
nasm_error(pass0 ==
@@ -1676,7 +1673,7 @@ static void assemble_file(char *fname, StrList **depend_ptr)
if (pass1 == 1) {
int64_t l = insn_size(location.segment, offs, sb, cpu,
- &output_ins, nasm_error);
+ &output_ins);
/* if (using_debug_info) && output_ins.opcode != -1) */
if (using_debug_info)
@@ -1755,8 +1752,7 @@ static void assemble_file(char *fname, StrList **depend_ptr)
} else {
offs += assemble(location.segment, offs, sb, cpu,
- &output_ins, ofmt, nasm_error,
- &nasmlist);
+ &output_ins);
set_curr_offs(offs);
}
@@ -1801,7 +1797,7 @@ static void assemble_file(char *fname, StrList **depend_ptr)
}
preproc->cleanup(0);
- nasmlist.cleanup();
+ nasmlist->cleanup();
if (!terminate_after_phase && opt_verbose_info) {
/* -On and -Ov switches */
fprintf(stdout, "info: assembly required 1+%d+1 passes\n", passn-3);
@@ -1985,8 +1981,7 @@ static void nasm_verror_common(int severity, const char *fmt, va_list args)
fprintf(error_file, "%s%s\n", pfx, msg);
- if (*listname)
- nasmlist.error(severity, pfx, msg);
+ nasmlist->error(severity, pfx, msg);
if (severity & ERR_USAGE)
want_usage = true;
diff --git a/nasm.h b/nasm.h
index 48284f6d..ff2acfe7 100644
--- a/nasm.h
+++ b/nasm.h
@@ -136,7 +136,7 @@ typedef struct {
* called. The `char *' parameter is the file name to write the
* listing to.
*/
- void (*init)(char *fname, efunc error);
+ void (*init)(const char *fname);
/*
* Called to clear stuff up and close the listing file.
@@ -190,6 +190,8 @@ typedef struct {
void (*error)(int severity, const char *pfx, const char *msg);
} ListGen;
+extern const ListGen *nasmlist;
+
/*
* Token types returned by the scanner, in addition to ordinary
* ASCII character values, and zero for end-of-string.
@@ -351,7 +353,7 @@ struct eval_hints {
#define CRITICAL 0x100
typedef expr *(*evalfunc)(scanner sc, void *scprivate,
struct tokenval *tv, int *fwref, int critical,
- efunc error, struct eval_hints *hints);
+ struct eval_hints *hints);
/*
* Special values for expr->type.
@@ -382,7 +384,7 @@ struct preproc_ops {
* of the pass, an error reporting function, an evaluator
* function, and a listing generator to talk to.
*/
- void (*reset)(char *file, int pass, ListGen *listgen, StrList **deplist);
+ void (*reset)(char *file, int pass, StrList **deplist);
/*
* Called to fetch a line of preprocessed source. The line
diff --git a/nasmlib.c b/nasmlib.c
index 265091c7..a1a3191f 100644
--- a/nasmlib.c
+++ b/nasmlib.c
@@ -49,7 +49,7 @@
#include "insns.h"
int globalbits = 0; /* defined in nasm.h, works better here for ASM+DISASM */
-static vefunc nasm_verror; /* Global error handling function */
+vefunc nasm_verror; /* Global error handling function */
/* Uninitialized -> all zero by C spec */
const uint8_t zero_buffer[ZERO_BUF_SIZE];
@@ -69,11 +69,6 @@ void tolower_init(void)
nasm_tolower_tab[i] = tolower(i);
}
-void nasm_set_verror(vefunc ve)
-{
- nasm_verror = ve;
-}
-
void nasm_error(int severity, const char *fmt, ...)
{
va_list ap;
diff --git a/nasmlib.h b/nasmlib.h
index 2e2e807f..96c488a4 100644
--- a/nasmlib.h
+++ b/nasmlib.h
@@ -73,32 +73,40 @@ extern unsigned char nasm_tolower_tab[256];
/*
* An error reporting function should look like this.
*/
-typedef void (*efunc) (int severity, const char *fmt, ...);
-typedef void (*vefunc) (int severity, const char *fmt, va_list ap);
void printf_func(2, 3) nasm_error(int severity, const char *fmt, ...);
-void nasm_set_verror(vefunc);
no_return printf_func(2, 3) nasm_fatal(int flags, const char *fmt, ...);
no_return printf_func(2, 3) nasm_panic(int flags, const char *fmt, ...);
no_return nasm_panic_from_macro(const char *file, int line);
#define panic() nasm_panic_from_macro(__FILE__, __LINE__);
+typedef void (*vefunc) (int severity, const char *fmt, va_list ap);
+extern vefunc nasm_verror;
+static inline vefunc nasm_set_verror(vefunc ve)
+{
+ vefunc old_verror = nasm_verror;
+ nasm_verror = ve;
+ return old_verror;
+}
+
/*
* These are the error severity codes which get passed as the first
* argument to an efunc.
*/
-#define ERR_DEBUG 0x00000008 /* put out debugging message */
-#define ERR_WARNING 0x00000000 /* warn only: no further action */
-#define ERR_NONFATAL 0x00000001 /* terminate assembly after phase */
-#define ERR_FATAL 0x00000002 /* instantly fatal: exit with error */
-#define ERR_PANIC 0x00000003 /* internal error: panic instantly
+#define ERR_DEBUG 0x00000000 /* put out debugging message */
+#define ERR_WARNING 0x00000001 /* warn only: no further action */
+#define ERR_NONFATAL 0x00000002 /* terminate assembly after phase */
+#define ERR_FATAL 0x00000006 /* instantly fatal: exit with error */
+#define ERR_PANIC 0x00000007 /* internal error: panic instantly
* and dump core for reference */
-#define ERR_MASK 0x0000000F /* 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_USAGE 0x00000020 /* print a usage message */
#define ERR_PASS1 0x00000040 /* only print this error on pass one */
#define ERR_PASS2 0x00000080
+
#define ERR_NO_SEVERITY 0x00000100 /* suppress printing severity */
+#define ERR_PP_PRECOND 0x00000200 /* for preprocessor use */
/*
* These codes define specific types of suppressible warning.
diff --git a/output/outaout.c b/output/outaout.c
index fe49feb4..66045519 100644
--- a/output/outaout.c
+++ b/output/outaout.c
@@ -298,7 +298,7 @@ static void aout_deflabel(char *name, int32_t segment, int64_t offset,
stdscan_reset();
stdscan_set(p);
tokval.t_type = TOKEN_INVALID;
- e = evaluate(stdscan, NULL, &tokval, NULL, 1, nasm_error, NULL);
+ e = evaluate(stdscan, NULL, &tokval, NULL, 1, NULL);
if (e) {
if (!is_simple(e))
nasm_error(ERR_NONFATAL, "cannot use relocatable"
@@ -392,8 +392,7 @@ static void aout_deflabel(char *name, int32_t segment, int64_t offset,
stdscan_reset();
stdscan_set(special + n);
tokval.t_type = TOKEN_INVALID;
- e = evaluate(stdscan, NULL, &tokval, &fwd, 0, nasm_error,
- NULL);
+ e = evaluate(stdscan, NULL, &tokval, &fwd, 0, NULL);
if (fwd) {
sym->nextfwd = fwds;
fwds = sym;
diff --git a/output/outbin.c b/output/outbin.c
index 47fbb471..915dc45f 100644
--- a/output/outbin.c
+++ b/output/outbin.c
@@ -990,7 +990,7 @@ static int bin_read_attribute(char **line, int *attribute,
stdscan_reset();
stdscan_set(exp);
tokval.t_type = TOKEN_INVALID;
- e = evaluate(stdscan, NULL, &tokval, NULL, 1, nasm_error, NULL);
+ e = evaluate(stdscan, NULL, &tokval, NULL, 1, NULL);
if (e) {
if (!is_really_simple(e)) {
nasm_error(ERR_NONFATAL, "section attribute value must be"
@@ -1299,7 +1299,7 @@ static int bin_directive(enum directives directive, char *args, int pass)
stdscan_reset();
stdscan_set(args);
tokval.t_type = TOKEN_INVALID;
- e = evaluate(stdscan, NULL, &tokval, NULL, 1, nasm_error, NULL);
+ e = evaluate(stdscan, NULL, &tokval, NULL, 1, NULL);
if (e) {
if (!is_really_simple(e))
nasm_error(ERR_NONFATAL, "org value must be a critical"
diff --git a/output/outelf32.c b/output/outelf32.c
index 9c83a579..0af2420b 100644
--- a/output/outelf32.c
+++ b/output/outelf32.c
@@ -383,7 +383,7 @@ static void elf_deflabel(char *name, int32_t segment, int64_t offset,
stdscan_reset();
stdscan_set(p);
tokval.t_type = TOKEN_INVALID;
- e = evaluate(stdscan, NULL, &tokval, NULL, 1, nasm_error, NULL);
+ e = evaluate(stdscan, NULL, &tokval, NULL, 1, NULL);
if (e) {
if (!is_simple(e))
nasm_error(ERR_NONFATAL, "cannot use relocatable"
@@ -525,8 +525,7 @@ static void elf_deflabel(char *name, int32_t segment, int64_t offset,
stdscan_reset();
stdscan_set(special + n);
tokval.t_type = TOKEN_INVALID;
- e = evaluate(stdscan, NULL, &tokval, &fwd, 0, nasm_error,
- NULL);
+ e = evaluate(stdscan, NULL, &tokval, &fwd, 0, NULL);
if (fwd) {
sym->nextfwd = fwds;
fwds = sym;
diff --git a/output/outelf64.c b/output/outelf64.c
index ef0b9377..5b4eee86 100644
--- a/output/outelf64.c
+++ b/output/outelf64.c
@@ -388,7 +388,7 @@ static void elf_deflabel(char *name, int32_t segment, int64_t offset,
stdscan_reset();
stdscan_set(p);
tokval.t_type = TOKEN_INVALID;
- e = evaluate(stdscan, NULL, &tokval, NULL, 1, nasm_error, NULL);
+ e = evaluate(stdscan, NULL, &tokval, NULL, 1, NULL);
if (e) {
if (!is_simple(e))
nasm_error(ERR_NONFATAL, "cannot use relocatable"
@@ -530,8 +530,7 @@ static void elf_deflabel(char *name, int32_t segment, int64_t offset,
stdscan_reset();
stdscan_set(special + n);
tokval.t_type = TOKEN_INVALID;
- e = evaluate(stdscan, NULL, &tokval, &fwd, 0, nasm_error,
- NULL);
+ e = evaluate(stdscan, NULL, &tokval, &fwd, 0, NULL);
if (fwd) {
sym->nextfwd = fwds;
fwds = sym;
diff --git a/output/outelfx32.c b/output/outelfx32.c
index 18f3724c..49ed945e 100644
--- a/output/outelfx32.c
+++ b/output/outelfx32.c
@@ -387,7 +387,7 @@ static void elf_deflabel(char *name, int32_t segment, int64_t offset,
stdscan_reset();
stdscan_set(p);
tokval.t_type = TOKEN_INVALID;
- e = evaluate(stdscan, NULL, &tokval, NULL, 1, nasm_error, NULL);
+ e = evaluate(stdscan, NULL, &tokval, NULL, 1, NULL);
if (e) {
if (!is_simple(e))
nasm_error(ERR_NONFATAL, "cannot use relocatable"
@@ -529,8 +529,7 @@ static void elf_deflabel(char *name, int32_t segment, int64_t offset,
stdscan_reset();
stdscan_set(special + n);
tokval.t_type = TOKEN_INVALID;
- e = evaluate(stdscan, NULL, &tokval, &fwd, 0, nasm_error,
- NULL);
+ e = evaluate(stdscan, NULL, &tokval, &fwd, 0, NULL);
if (fwd) {
sym->nextfwd = fwds;
fwds = sym;
diff --git a/output/outform.h b/output/outform.h
index d37a61b4..f52a112a 100644
--- a/output/outform.h
+++ b/output/outform.h
@@ -374,7 +374,6 @@ struct ofmt *ofmt_find(char *name, struct ofmt_alias **ofmt_alias);
struct dfmt *dfmt_find(struct ofmt *, char *);
void ofmt_list(struct ofmt *, FILE *);
void dfmt_list(struct ofmt *ofmt, FILE * fp);
-struct ofmt *ofmt_register(efunc error);
extern struct dfmt null_debug_form;
#endif /* NASM_OUTFORM_H */
diff --git a/output/outobj.c b/output/outobj.c
index a39610be..74f43ced 100644
--- a/output/outobj.c
+++ b/output/outobj.c
@@ -969,7 +969,7 @@ static void obj_deflabel(char *name, int32_t segment,
stdscan_reset();
stdscan_set(special);
tokval.t_type = TOKEN_INVALID;
- e = evaluate(stdscan, NULL, &tokval, NULL, 1, nasm_error, NULL);
+ e = evaluate(stdscan, NULL, &tokval, NULL, 1, NULL);
if (e) {
if (!is_simple(e))
nasm_error(ERR_NONFATAL, "cannot use relocatable"
diff --git a/parser.c b/parser.c
index 50bfdf64..5107860e 100644
--- a/parser.c
+++ b/parser.c
@@ -461,7 +461,7 @@ restart_parse:
expr *value;
i = stdscan(NULL, &tokval);
- value = evaluate(stdscan, NULL, &tokval, NULL, pass0, nasm_error, NULL);
+ value = evaluate(stdscan, NULL, &tokval, NULL, pass0, NULL);
i = tokval.t_type;
if (!value) /* Error in evaluator */
goto fail;
@@ -646,8 +646,7 @@ is_float:
eop->stringval = (char *)eop + sizeof(extop);
if (!eop->stringlen ||
!float_const(tokval.t_charptr, sign,
- (uint8_t *)eop->stringval,
- eop->stringlen, nasm_error))
+ (uint8_t *)eop->stringval, eop->stringlen))
eop->type = EOT_NOTHING;
i = stdscan(NULL, &tokval); /* eat the comma */
} else {
@@ -656,7 +655,7 @@ is_float:
is_expression:
value = evaluate(stdscan, NULL, &tokval, NULL,
- critical, nasm_error, NULL);
+ critical, NULL);
i = tokval.t_type;
if (!value) /* Error in evaluator */
goto fail;
@@ -845,8 +844,7 @@ is_expression:
}
value = evaluate(stdscan, NULL, &tokval,
- &op->opflags,
- critical, nasm_error, &hints);
+ &op->opflags, critical, &hints);
i = tokval.t_type;
if (op->opflags & OPFLAG_FORWARD) {
result->forw_ref = true;
@@ -876,8 +874,7 @@ is_expression:
i = stdscan(NULL, &tokval);
}
value = evaluate(stdscan, NULL, &tokval,
- &op->opflags,
- critical, nasm_error, &hints);
+ &op->opflags, critical, &hints);
i = tokval.t_type;
if (op->opflags & OPFLAG_FORWARD) {
result->forw_ref = true;
@@ -898,7 +895,7 @@ is_expression:
i = stdscan(NULL, &tokval); /* Eat comma */
value = evaluate(stdscan, NULL, &tokval, &op->opflags,
- critical, nasm_error, &hints);
+ critical, &hints);
i = tokval.t_type;
if (!value)
goto fail;
diff --git a/preproc-nop.c b/preproc-nop.c
index 4d04af5d..353e269b 100644
--- a/preproc-nop.c
+++ b/preproc-nop.c
@@ -55,10 +55,9 @@
#define BUF_DELTA 512
static FILE *nop_fp;
-static ListGen *nop_list;
static int32_t nop_lineinc;
-static void nop_reset(char *file, int pass, ListGen *listgen, StrList **deplist)
+static void nop_reset(char *file, int pass, StrList **deplist)
{
src_set_fname(nasm_strdup(file));
src_set_linnum(0);
@@ -66,9 +65,7 @@ static void nop_reset(char *file, int pass, ListGen *listgen, StrList **deplist)
nop_fp = fopen(file, "r");
if (!nop_fp)
- nasm_fatal(ERR_NOFILE,
- "unable to open input file `%s'", file);
- nop_list = listgen;
+ nasm_fatal(ERR_NOFILE, "unable to open input file `%s'", file);
(void)pass; /* placate compilers */
if (deplist) {
@@ -133,7 +130,7 @@ static char *nop_getline(void)
break;
}
- nop_list->line(LIST_READ, buffer);
+ nasmlist->line(LIST_READ, buffer);
return buffer;
}
diff --git a/preproc.c b/preproc.c
index 054cc209..b43cd617 100644
--- a/preproc.c
+++ b/preproc.c
@@ -1,6 +1,6 @@
/* ----------------------------------------------------------------------- *
*
- * Copyright 1996-2014 The NASM Authors - All Rights Reserved
+ * Copyright 1996-2016 The NASM Authors - All Rights Reserved
* See the file AUTHORS included with the NASM distribution for
* the specific copyright holders.
*
@@ -402,8 +402,6 @@ static uint64_t unique; /* unique identifier numbers */
static Line *predef = NULL;
static bool do_predef;
-static ListGen *list;
-
/*
* The current set of multi-line macros we have defined.
*/
@@ -461,8 +459,8 @@ static Token *expand_smacro(Token * tline);
static Token *expand_id(Token * tline);
static Context *get_ctx(const char *name, const char **namep);
static void make_tok_num(Token * tok, int64_t val);
-static void error(int severity, const char *fmt, ...);
-static void error_precond(int severity, const char *fmt, ...);
+static void pp_verror(int severity, const char *fmt, va_list ap);
+static vefunc real_verror;
static void *new_Block(size_t size);
static void delete_Blocks(void);
static Token *new_Token(Token * next, enum pp_token_type type,
@@ -488,7 +486,7 @@ static size_t nasm_unquote_cstr(char *qstr, enum preproc_token directive)
size_t clen = strlen(qstr);
if (len != clen)
- error(ERR_NONFATAL, "NUL character in `%s' directive",
+ nasm_error(ERR_NONFATAL, "NUL character in `%s' directive",
pp_directives[directive]);
return clen;
@@ -880,7 +878,7 @@ static char *read_line(void)
*/
buffer[strcspn(buffer, "\032")] = '\0';
- list->line(LIST_READ, buffer);
+ nasmlist->line(LIST_READ, buffer);
return buffer;
}
@@ -920,7 +918,8 @@ static Token *tokenize(char *line)
p++;
}
if (*p != '}')
- error(ERR_WARNING | ERR_PASS1, "unterminated %{ construct");
+ nasm_error(ERR_WARNING | ERR_PASS1,
+ "unterminated %%{ construct");
p[-1] = '\0';
if (*p)
p++;
@@ -951,7 +950,8 @@ static Token *tokenize(char *line)
if (*p)
*p++ = '\0';
if (lvl)
- error(ERR_NONFATAL, "unterminated %[ construct");
+ nasm_error(ERR_NONFATAL|ERR_PASS1,
+ "unterminated %%[ construct");
type = TOK_INDIRECT;
} else if (*p == '?') {
type = TOK_PREPROC_Q; /* %? */
@@ -973,7 +973,8 @@ static Token *tokenize(char *line)
if (*p)
p++;
else
- error(ERR_NONFATAL|ERR_PASS1, "unterminated %! string");
+ nasm_error(ERR_NONFATAL|ERR_PASS1,
+ "unterminated %%! string");
} else {
/* %! without string or identifier */
type = TOK_OTHER; /* Legacy behavior... */
@@ -1006,7 +1007,7 @@ static Token *tokenize(char *line)
if (*p) {
p++;
} else {
- error(ERR_WARNING|ERR_PASS1, "unterminated string");
+ nasm_error(ERR_WARNING|ERR_PASS1, "unterminated string");
/* Handling unterminated strings by UNV */
/* type = -1; */
}
@@ -1253,8 +1254,8 @@ static char *detoken(Token * tlist, bool expand_locals)
size_t clen = strlen(v);
if (len != clen) {
- error(ERR_NONFATAL | ERR_PASS1,
- "NUL character in %! string");
+ nasm_error(ERR_NONFATAL | ERR_PASS1,
+ "NUL character in %%! string");
v = NULL;
}
}
@@ -1262,7 +1263,7 @@ static char *detoken(Token * tlist, bool expand_locals)
if (v) {
char *p = getenv(v);
if (!p) {
- error(ERR_NONFATAL | ERR_PASS1,
+ nasm_error(ERR_NONFATAL | ERR_PASS1,
"nonexistent environment variable `%s'", v);
p = "";
}
@@ -1458,7 +1459,7 @@ static Context *get_ctx(const char *name, const char **namep)
return NULL;
if (!cstk) {
- error(ERR_NONFATAL, "`%s': context stack is empty", name);
+ nasm_error(ERR_NONFATAL, "`%s': context stack is empty", name);
return NULL;
}
@@ -1471,7 +1472,7 @@ static Context *get_ctx(const char *name, const char **namep)
ctx = ctx->next;
}
if (!ctx) {
- error(ERR_NONFATAL, "`%s': context stack is only"
+ nasm_error(ERR_NONFATAL, "`%s': context stack is only"
" %d level%s deep", name, i, (i == 1 ? "" : "s"));
return NULL;
}
@@ -1549,7 +1550,7 @@ static FILE *inc_fopen(const char *file, StrList **dhead, StrList ***dtail,
}
}
- error(ERR_FATAL, "unable to open include file `%s'", file);
+ nasm_error(ERR_FATAL, "unable to open include file `%s'", file);
return NULL;
}
@@ -1650,7 +1651,7 @@ static void count_mmac_params(Token * t, int *nparam, Token *** params)
t = t->next;
skip_white_(t);
if (tok_isnt_(t, ",")) {
- error(ERR_NONFATAL,
+ nasm_error(ERR_NONFATAL,
"braces do not enclose all of macro parameter");
while (tok_isnt_(t, ","))
t = t->next;
@@ -1692,7 +1693,7 @@ static bool if_condition(Token * tline, enum preproc_token ct)
if (!tline)
break;
if (tline->type != TOK_ID) {
- error(ERR_NONFATAL,
+ nasm_error(ERR_NONFATAL,
"`%s' expects context identifiers", pp_directives[ct]);
free_tlist(origline);
return -1;
@@ -1710,7 +1711,7 @@ static bool if_condition(Token * tline, enum preproc_token ct)
if (!tline || (tline->type != TOK_ID &&
(tline->type != TOK_PREPROC_ID ||
tline->text[1] != '$'))) {
- error(ERR_NONFATAL,
+ nasm_error(ERR_NONFATAL,
"`%s' expects macro identifiers", pp_directives[ct]);
goto fail;
}
@@ -1729,7 +1730,7 @@ static bool if_condition(Token * tline, enum preproc_token ct)
tline->type != TOK_STRING &&
(tline->type != TOK_PREPROC_ID ||
tline->text[1] != '!'))) {
- error(ERR_NONFATAL,
+ nasm_error(ERR_NONFATAL,
"`%s' expects environment variable names",
pp_directives[ct]);
goto fail;
@@ -1752,7 +1753,7 @@ static bool if_condition(Token * tline, enum preproc_token ct)
while (tok_isnt_(tt, ","))
tt = tt->next;
if (!tt) {
- error(ERR_NONFATAL,
+ nasm_error(ERR_NONFATAL,
"`%s' expects two comma-separated arguments",
pp_directives[ct]);
goto fail;
@@ -1761,7 +1762,7 @@ static bool if_condition(Token * tline, enum preproc_token ct)
j = true; /* assume equality unless proved not */
while ((t->type != TOK_OTHER || strcmp(t->text, ",")) && tt) {
if (tt->type == TOK_OTHER && !strcmp(tt->text, ",")) {
- error(ERR_NONFATAL, "`%s': more than one comma on line",
+ nasm_error(ERR_NONFATAL, "`%s': more than one comma on line",
pp_directives[ct]);
goto fail;
}
@@ -1810,7 +1811,7 @@ static bool if_condition(Token * tline, enum preproc_token ct)
skip_white_(tline);
tline = expand_id(tline);
if (!tok_type_(tline, TOK_ID)) {
- error(ERR_NONFATAL,
+ nasm_error(ERR_NONFATAL,
"`%s' expects a macro name", pp_directives[ct]);
goto fail;
}
@@ -1827,14 +1828,14 @@ static bool if_condition(Token * tline, enum preproc_token ct)
skip_white_(tline);
if (!tline) {
} else if (!tok_type_(tline, TOK_NUMBER)) {
- error(ERR_NONFATAL,
+ nasm_error(ERR_NONFATAL,
"`%s' expects a parameter count or nothing",
pp_directives[ct]);
} else {
searching.nparam_min = searching.nparam_max =
readnum(tline->text, &j);
if (j)
- error(ERR_NONFATAL,
+ nasm_error(ERR_NONFATAL,
"unable to parse parameter count `%s'",
tline->text);
}
@@ -1843,17 +1844,17 @@ static bool if_condition(Token * tline, enum preproc_token ct)
if (tok_is_(tline, "*"))
searching.nparam_max = INT_MAX;
else if (!tok_type_(tline, TOK_NUMBER))
- error(ERR_NONFATAL,
+ nasm_error(ERR_NONFATAL,
"`%s' expects a parameter count after `-'",
pp_directives[ct]);
else {
searching.nparam_max = readnum(tline->text, &j);
if (j)
- error(ERR_NONFATAL,
+ nasm_error(ERR_NONFATAL,
"unable to parse parameter count `%s'",
tline->text);
if (searching.nparam_min > searching.nparam_max)
- error(ERR_NONFATAL,
+ nasm_error(ERR_NONFATAL,
"minimum parameter count exceeds maximum");
}
}
@@ -1874,7 +1875,7 @@ static bool if_condition(Token * tline, enum preproc_token ct)
mmac = mmac->next;
}
if (tline && tline->next)
- error(ERR_WARNING|ERR_PASS1,
+ nasm_error(ERR_WARNING|ERR_PASS1,
"trailing garbage after %%ifmacro ignored");
nasm_free(searching.name);
j = found;
@@ -1931,14 +1932,14 @@ iftype:
tptr = &t;
tokval.t_type = TOKEN_INVALID;
evalresult = evaluate(ppscan, tptr, &tokval,
- NULL, pass | CRITICAL, error, NULL);
+ NULL, pass | CRITICAL, NULL);
if (!evalresult)
return -1;
if (tokval.t_type)
- error(ERR_WARNING|ERR_PASS1,
+ nasm_error(ERR_WARNING|ERR_PASS1,
"trailing garbage after expression ignored");
if (!is_simple(evalresult)) {
- error(ERR_NONFATAL,
+ nasm_error(ERR_NONFATAL,
"non-constant value given to `%s'", pp_directives[ct]);
goto fail;
}
@@ -1946,7 +1947,7 @@ iftype:
break;
default:
- error(ERR_FATAL,
+ nasm_error(ERR_FATAL,
"preprocessor directive `%s' not yet implemented",
pp_directives[ct]);
goto fail;
@@ -1971,7 +1972,7 @@ static bool define_smacro(Context *ctx, const char *mname, bool casesense,
if (smacro_defined(ctx, mname, nparam, &smac, casesense)) {
if (!smac) {
- error(ERR_WARNING|ERR_PASS1,
+ nasm_error(ERR_WARNING|ERR_PASS1,
"single-line macro `%s' defined both with and"
" without parameters", mname);
/*
@@ -2044,7 +2045,7 @@ static bool parse_mmacro_spec(Token *tline, MMacro *def, const char *directive)
skip_white_(tline);
tline = expand_id(tline);
if (!tok_type_(tline, TOK_ID)) {
- error(ERR_NONFATAL, "`%s' expects a macro name", directive);
+ nasm_error(ERR_NONFATAL, "`%s' expects a macro name", directive);
return false;
}
@@ -2060,12 +2061,12 @@ static bool parse_mmacro_spec(Token *tline, MMacro *def, const char *directive)
tline = expand_smacro(tline->next);
skip_white_(tline);
if (!tok_type_(tline, TOK_NUMBER)) {
- error(ERR_NONFATAL, "`%s' expects a parameter count", directive);
+ nasm_error(ERR_NONFATAL, "`%s' expects a parameter count", directive);
} else {
def->nparam_min = def->nparam_max =
readnum(tline->text, &err);
if (err)
- error(ERR_NONFATAL,
+ nasm_error(ERR_NONFATAL,
"unable to parse parameter count `%s'", tline->text);
}
if (tline && tok_is_(tline->next, "-")) {
@@ -2073,16 +2074,16 @@ static bool parse_mmacro_spec(Token *tline, MMacro *def, const char *directive)
if (tok_is_(tline, "*")) {
def->nparam_max = INT_MAX;
} else if (!tok_type_(tline, TOK_NUMBER)) {
- error(ERR_NONFATAL,
+ nasm_error(ERR_NONFATAL,
"`%s' expects a parameter count after `-'", directive);
} else {
def->nparam_max = readnum(tline->text, &err);
if (err) {
- error(ERR_NONFATAL, "unable to parse parameter count `%s'",
+ nasm_error(ERR_NONFATAL, "unable to parse parameter count `%s'",
tline->text);
}
if (def->nparam_min > def->nparam_max) {
- error(ERR_NONFATAL, "minimum parameter count exceeds maximum");
+ nasm_error(ERR_NONFATAL, "minimum parameter count exceeds maximum");
}
}
}
@@ -2111,7 +2112,7 @@ static bool parse_mmacro_spec(Token *tline, MMacro *def, const char *directive)
if (def->defaults && def->ndefs > def->nparam_max - def->nparam_min &&
!def->plus)
- error(ERR_WARNING|ERR_PASS1|ERR_WARN_MDP,
+ nasm_error(ERR_WARNING|ERR_PASS1|ERR_WARN_MDP,
"too many default macro parameters");
return true;
@@ -2183,7 +2184,7 @@ static int do_directive(Token * tline)
* in future release (2.09-2.10)
*/
if (i == PP_RMACRO || i == PP_IRMACRO || i == PP_EXITMACRO) {
- error(ERR_NONFATAL, "unknown preprocessor directive `%s'",
+ nasm_error(ERR_NONFATAL, "unknown preprocessor directive `%s'",
tline->text);
return NO_DIRECTIVE_FOUND;
}
@@ -2238,7 +2239,7 @@ static int do_directive(Token * tline)
switch (i) {
case PP_INVALID:
- error(ERR_NONFATAL, "unknown preprocessor directive `%s'",
+ nasm_error(ERR_NONFATAL, "unknown preprocessor directive `%s'",
tline->text);
return NO_DIRECTIVE_FOUND; /* didn't get it */
@@ -2251,7 +2252,7 @@ static int do_directive(Token * tline)
if (tline && tline->type == TOK_WHITESPACE)
tline = tline->next;
if (!tline || tline->type != TOK_ID) {
- error(ERR_NONFATAL, "`%%stacksize' missing size parameter");
+ nasm_error(ERR_NONFATAL, "`%%stacksize' missing size parameter");
free_tlist(origline);
return DIRECTIVE_FOUND;
}
@@ -2284,7 +2285,7 @@ static int do_directive(Token * tline)
ArgOffset = 6;
LocalOffset = 0;
} else {
- error(ERR_NONFATAL, "`%%stacksize' invalid size type");
+ nasm_error(ERR_NONFATAL, "`%%stacksize' invalid size type");
free_tlist(origline);
return DIRECTIVE_FOUND;
}
@@ -2307,7 +2308,7 @@ static int do_directive(Token * tline)
if (tline && tline->type == TOK_WHITESPACE)
tline = tline->next;
if (!tline || tline->type != TOK_ID) {
- error(ERR_NONFATAL, "`%%arg' missing argument parameter");
+ nasm_error(ERR_NONFATAL, "`%%arg' missing argument parameter");
free_tlist(origline);
return DIRECTIVE_FOUND;
}
@@ -2317,14 +2318,14 @@ static int do_directive(Token * tline)
tline = tline->next;
if (!tline || tline->type != TOK_OTHER
|| tline->text[0] != ':') {
- error(ERR_NONFATAL,
+ nasm_error(ERR_NONFATAL,
"Syntax error processing `%%arg' directive");
free_tlist(origline);
return DIRECTIVE_FOUND;
}
tline = tline->next;
if (!tline || tline->type != TOK_ID) {
- error(ERR_NONFATAL, "`%%arg' missing size type parameter");
+ nasm_error(ERR_NONFATAL, "`%%arg' missing size type parameter");
free_tlist(origline);
return DIRECTIVE_FOUND;
}
@@ -2334,7 +2335,7 @@ static int do_directive(Token * tline)
tt = expand_smacro(tt);
size = parse_size(tt->text);
if (!size) {
- error(ERR_NONFATAL,
+ nasm_error(ERR_NONFATAL,
"Invalid size type for `%%arg' missing directive");
free_tlist(tt);
free_tlist(origline);
@@ -2380,7 +2381,7 @@ static int do_directive(Token * tline)
if (tline && tline->type == TOK_WHITESPACE)
tline = tline->next;
if (!tline || tline->type != TOK_ID) {
- error(ERR_NONFATAL,
+ nasm_error(ERR_NONFATAL,
"`%%local' missing argument parameter");
free_tlist(origline);
return DIRECTIVE_FOUND;
@@ -2391,14 +2392,14 @@ static int do_directive(Token * tline)
tline = tline->next;
if (!tline || tline->type != TOK_OTHER
|| tline->text[0] != ':') {
- error(ERR_NONFATAL,
+ nasm_error(ERR_NONFATAL,
"Syntax error processing `%%local' directive");
free_tlist(origline);
return DIRECTIVE_FOUND;
}
tline = tline->next;
if (!tline || tline->type != TOK_ID) {
- error(ERR_NONFATAL,
+ nasm_error(ERR_NONFATAL,
"`%%local' missing size type parameter");
free_tlist(origline);
return DIRECTIVE_FOUND;
@@ -2409,7 +2410,7 @@ static int do_directive(Token * tline)
tt = expand_smacro(tt);
size = parse_size(tt->text);
if (!size) {
- error(ERR_NONFATAL,
+ nasm_error(ERR_NONFATAL,
"Invalid size type for `%%local' missing directive");
free_tlist(tt);
free_tlist(origline);
@@ -2443,7 +2444,7 @@ static int do_directive(Token * tline)
case PP_CLEAR:
if (tline->next)
- error(ERR_WARNING|ERR_PASS1,
+ nasm_error(ERR_WARNING|ERR_PASS1,
"trailing garbage after `%%clear' ignored");
free_macros();
init_macros();
@@ -2455,12 +2456,12 @@ static int do_directive(Token * tline)
skip_white_(t);
if (!t || (t->type != TOK_STRING &&
t->type != TOK_INTERNAL_STRING)) {
- error(ERR_NONFATAL, "`%%depend' expects a file name");
+ nasm_error(ERR_NONFATAL, "`%%depend' expects a file name");
free_tlist(origline);
return DIRECTIVE_FOUND; /* but we did _something_ */
}
if (t->next)
- error(ERR_WARNING|ERR_PASS1,
+ nasm_error(ERR_WARNING|ERR_PASS1,
"trailing garbage after `%%depend' ignored");
p = t->text;
if (t->type != TOK_INTERNAL_STRING)
@@ -2481,12 +2482,12 @@ static int do_directive(Token * tline)
if (!t || (t->type != TOK_STRING &&
t->type != TOK_INTERNAL_STRING)) {
- error(ERR_NONFATAL, "`%%include' expects a file name");
+ nasm_error(ERR_NONFATAL, "`%%include' expects a file name");
free_tlist(origline);
return DIRECTIVE_FOUND; /* but we did _something_ */
}
if (t->next)
- error(ERR_WARNING|ERR_PASS1,
+ nasm_error(ERR_WARNING|ERR_PASS1,
"trailing garbage after `%%include' ignored");
p = t->text;
if (t->type != TOK_INTERNAL_STRING)
@@ -2505,7 +2506,7 @@ static int do_directive(Token * tline)
inc->expansion = NULL;
inc->mstk = NULL;
istk = inc;
- list->uplevel(LIST_INCLUDE);
+ nasmlist->uplevel(LIST_INCLUDE);
}
free_tlist(origline);
return DIRECTIVE_FOUND;
@@ -2522,18 +2523,18 @@ static int do_directive(Token * tline)
if (!tline || (tline->type != TOK_STRING &&
tline->type != TOK_INTERNAL_STRING &&
tline->type != TOK_ID)) {
- error(ERR_NONFATAL, "`%%use' expects a package name");
+ nasm_error(ERR_NONFATAL, "`%%use' expects a package name");
free_tlist(origline);
return DIRECTIVE_FOUND; /* but we did _something_ */
}
if (tline->next)
- error(ERR_WARNING|ERR_PASS1,
+ nasm_error(ERR_WARNING|ERR_PASS1,
"trailing garbage after `%%use' ignored");
if (tline->type == TOK_STRING)
nasm_unquote_cstr(tline->text, i);
use_pkg = nasm_stdmac_find_package(tline->text);
if (!use_pkg)
- error(ERR_NONFATAL, "unknown `%%use' package: %s", tline->text);
+ nasm_error(ERR_NONFATAL, "unknown `%%use' package: %s", tline->text);
else
pkg_macro = (char *)use_pkg + 1; /* The first string will be <%define>__USE_*__ */
if (use_pkg && ! smacro_defined(NULL, pkg_macro, 0, NULL, true)) {
@@ -2551,13 +2552,13 @@ static int do_directive(Token * tline)
tline = expand_id(tline);
if (tline) {
if (!tok_type_(tline, TOK_ID)) {
- error(ERR_NONFATAL, "`%s' expects a context identifier",
+ nasm_error(ERR_NONFATAL, "`%s' expects a context identifier",
pp_directives[i]);
free_tlist(origline);
return DIRECTIVE_FOUND; /* but we did _something_ */
}
if (tline->next)
- error(ERR_WARNING|ERR_PASS1,
+ nasm_error(ERR_WARNING|ERR_PASS1,
"trailing garbage after `%s' ignored",
pp_directives[i]);
p = nasm_strdup(tline->text);
@@ -2575,11 +2576,11 @@ static int do_directive(Token * tline)
} else {
/* %pop or %repl */
if (!cstk) {
- error(ERR_NONFATAL, "`%s': context stack is empty",
+ nasm_error(ERR_NONFATAL, "`%s': context stack is empty",
pp_directives[i]);
} else if (i == PP_POP) {
if (p && (!cstk->name || nasm_stricmp(p, cstk->name)))
- error(ERR_NONFATAL, "`%%pop' in wrong context: %s, "
+ nasm_error(ERR_NONFATAL, "`%%pop' in wrong context: %s, "
"expected %s",
cstk->name ? cstk->name : "anonymous", p);
else
@@ -2619,11 +2620,11 @@ issue_error:
/* The line contains only a quoted string */
p = tline->text;
nasm_unquote(p, NULL); /* Ignore NUL character truncation */
- error(severity, "%s", p);
+ nasm_error(severity, "%s", p);
} else {
/* Not a quoted string, or more than a quoted string */
p = detoken(tline, false);
- error(severity, "%s", p);
+ nasm_error(severity, "%s", p);
nasm_free(p);
}
free_tlist(origline);
@@ -2649,7 +2650,7 @@ issue_error:
CASE_PP_ELIF:
if (!istk->conds)
- error(ERR_FATAL, "`%s': no matching `%%if'", pp_directives[i]);
+ nasm_error(ERR_FATAL, "`%s': no matching `%%if'", pp_directives[i]);
switch(istk->conds->state) {
case COND_IF_TRUE:
istk->conds->state = COND_DONE;
@@ -2661,8 +2662,8 @@ issue_error:
case COND_ELSE_TRUE:
case COND_ELSE_FALSE:
- error_precond(ERR_WARNING|ERR_PASS1,
- "`%%elif' after `%%else' ignored");
+ nasm_error(ERR_WARNING|ERR_PASS1|ERR_PP_PRECOND,
+ "`%%elif' after `%%else' ignored");
istk->conds->state = COND_NEVER;
break;
@@ -2686,10 +2687,10 @@ issue_error:
case PP_ELSE:
if (tline->next)
- error_precond(ERR_WARNING|ERR_PASS1,
- "trailing garbage after `%%else' ignored");
+ nasm_error(ERR_WARNING|ERR_PASS1|ERR_PP_PRECOND,
+ "trailing garbage after `%%else' ignored");
if (!istk->conds)
- error(ERR_FATAL, "`%%else': no matching `%%if'");
+ nasm_fatal(0, "`%%else: no matching `%%if'");
switch(istk->conds->state) {
case COND_IF_TRUE:
case COND_DONE:
@@ -2705,7 +2706,7 @@ issue_error:
case COND_ELSE_TRUE:
case COND_ELSE_FALSE:
- error_precond(ERR_WARNING|ERR_PASS1,
+ nasm_error(ERR_WARNING|ERR_PASS1|ERR_PP_PRECOND,
"`%%else' after `%%else' ignored.");
istk->conds->state = COND_NEVER;
break;
@@ -2715,10 +2716,10 @@ issue_error:
case PP_ENDIF:
if (tline->next)
- error_precond(ERR_WARNING|ERR_PASS1,
- "trailing garbage after `%%endif' ignored");
+ nasm_error(ERR_WARNING|ERR_PASS1|ERR_PP_PRECOND,
+ "trailing garbage after `%%endif' ignored");
if (!istk->conds)
- error(ERR_FATAL, "`%%endif': no matching `%%if'");
+ nasm_error(ERR_FATAL, "`%%endif': no matching `%%if'");
cond = istk->conds;
istk->conds = cond->next;
nasm_free(cond);
@@ -2732,7 +2733,7 @@ issue_error:
case PP_MACRO:
case PP_IMACRO:
if (defining) {
- error(ERR_FATAL, "`%s': already defining a macro",
+ nasm_error(ERR_FATAL, "`%s': already defining a macro",
pp_directives[i]);
return DIRECTIVE_FOUND;
}
@@ -2753,7 +2754,7 @@ issue_error:
|| defining->plus)
&& (defining->nparam_min <= mmac->nparam_max
|| mmac->plus)) {
- error(ERR_WARNING|ERR_PASS1,
+ nasm_error(ERR_WARNING|ERR_PASS1,
"redefining multi-line macro `%s'", defining->name);
return DIRECTIVE_FOUND;
}
@@ -2765,7 +2766,7 @@ issue_error:
case PP_ENDM:
case PP_ENDMACRO:
if (! (defining && defining->name)) {
- error(ERR_NONFATAL, "`%s': not defining a macro", tline->text);
+ nasm_error(ERR_NONFATAL, "`%s': not defining a macro", tline->text);
return DIRECTIVE_FOUND;
}
mmhead = (MMacro **) hash_findi_add(&mmacros, defining->name);
@@ -2797,7 +2798,7 @@ issue_error:
}
istk->expansion = l;
} else {
- error(ERR_NONFATAL, "`%%exitmacro' not within `%%macro' block");
+ nasm_error(ERR_NONFATAL, "`%%exitmacro' not within `%%macro' block");
}
free_tlist(origline);
return DIRECTIVE_FOUND;
@@ -2836,7 +2837,7 @@ issue_error:
tline = tline->next;
if (!tline->next) {
free_tlist(origline);
- error(ERR_NONFATAL, "`%%rotate' missing rotate count");
+ nasm_error(ERR_NONFATAL, "`%%rotate' missing rotate count");
return DIRECTIVE_FOUND;
}
t = expand_smacro(tline->next);
@@ -2846,24 +2847,24 @@ issue_error:
tptr = &t;
tokval.t_type = TOKEN_INVALID;
evalresult =
- evaluate(ppscan, tptr, &tokval, NULL, pass, error, NULL);
+ evaluate(ppscan, tptr, &tokval, NULL, pass, NULL);
free_tlist(tline);
if (!evalresult)
return DIRECTIVE_FOUND;
if (tokval.t_type)
- error(ERR_WARNING|ERR_PASS1,
+ nasm_error(ERR_WARNING|ERR_PASS1,
"trailing garbage after expression ignored");
if (!is_simple(evalresult)) {
- error(ERR_NONFATAL, "non-constant value given to `%%rotate'");
+ nasm_error(ERR_NONFATAL, "non-constant value given to `%%rotate'");
return DIRECTIVE_FOUND;
}
mmac = istk->mstk;
while (mmac && !mmac->name) /* avoid mistaking %reps for macros */
mmac = mmac->next_active;
if (!mmac) {
- error(ERR_NONFATAL, "`%%rotate' invoked outside a macro call");
+ nasm_error(ERR_NONFATAL, "`%%rotate' invoked outside a macro call");
} else if (mmac->nparam == 0) {
- error(ERR_NONFATAL,
+ nasm_error(ERR_NONFATAL,
"`%%rotate' invoked within macro without parameters");
} else {
int rotate = mmac->rotate + reloc_value(evalresult);
@@ -2895,26 +2896,26 @@ issue_error:
tptr = &t;
tokval.t_type = TOKEN_INVALID;
evalresult =
- evaluate(ppscan, tptr, &tokval, NULL, pass, error, NULL);
+ evaluate(ppscan, tptr, &tokval, NULL, pass, NULL);
if (!evalresult) {
free_tlist(origline);
return DIRECTIVE_FOUND;
}
if (tokval.t_type)
- error(ERR_WARNING|ERR_PASS1,
+ nasm_error(ERR_WARNING|ERR_PASS1,
"trailing garbage after expression ignored");
if (!is_simple(evalresult)) {
- error(ERR_NONFATAL, "non-constant value given to `%%rep'");
+ nasm_error(ERR_NONFATAL, "non-constant value given to `%%rep'");
return DIRECTIVE_FOUND;
}
count = reloc_value(evalresult);
if (count >= REP_LIMIT) {
- error(ERR_NONFATAL, "`%%rep' value exceeds limit");
+ nasm_error(ERR_NONFATAL, "`%%rep' value exceeds limit");
count = 0;
} else
count++;
} else {
- error(ERR_NONFATAL, "`%%rep' expects a repeat count");
+ nasm_error(ERR_NONFATAL, "`%%rep' expects a repeat count");
count = 0;
}
free_tlist(origline);
@@ -2938,7 +2939,7 @@ issue_error:
case PP_ENDREP:
if (!defining || defining->name) {
- error(ERR_NONFATAL, "`%%endrep': no matching `%%rep'");
+ nasm_error(ERR_NONFATAL, "`%%endrep': no matching `%%rep'");
return DIRECTIVE_FOUND;
}
@@ -2961,7 +2962,7 @@ issue_error:
istk->mstk = defining;
- list->uplevel(defining->nolist ? LIST_MACRO_NOLIST : LIST_MACRO);
+ nasmlist->uplevel(defining->nolist ? LIST_MACRO_NOLIST : LIST_MACRO);
tmp_defining = defining;
defining = defining->rep_nest;
free_tlist(origline);
@@ -2980,7 +2981,7 @@ issue_error:
if (l)
l->finishes->in_progress = 1;
else
- error(ERR_NONFATAL, "`%%exitrep' not within `%%rep' block");
+ nasm_error(ERR_NONFATAL, "`%%exitrep' not within `%%rep' block");
free_tlist(origline);
return DIRECTIVE_FOUND;
@@ -2996,7 +2997,7 @@ issue_error:
if (!tline || (tline->type != TOK_ID &&
(tline->type != TOK_PREPROC_ID ||
tline->text[1] != '$'))) {
- error(ERR_NONFATAL, "`%s' expects a macro identifier",
+ nasm_error(ERR_NONFATAL, "`%s' expects a macro identifier",
pp_directives[i]);
free_tlist(origline);
return DIRECTIVE_FOUND;
@@ -3020,12 +3021,12 @@ issue_error:
while (1) {
skip_white_(tline);
if (!tline) {
- error(ERR_NONFATAL, "parameter identifier expected");
+ nasm_error(ERR_NONFATAL, "parameter identifier expected");
free_tlist(origline);
return DIRECTIVE_FOUND;
}
if (tline->type != TOK_ID) {
- error(ERR_NONFATAL,
+ nasm_error(ERR_NONFATAL,
"`%s': parameter identifier expected",
tline->text);
free_tlist(origline);
@@ -3038,7 +3039,7 @@ issue_error:
tline = tline->next;
} else {
if (!tok_is_(tline, ")")) {
- error(ERR_NONFATAL,
+ nasm_error(ERR_NONFATAL,
"`)' expected to terminate macro template");
free_tlist(origline);
return DIRECTIVE_FOUND;
@@ -3085,12 +3086,12 @@ issue_error:
if (!tline || (tline->type != TOK_ID &&
(tline->type != TOK_PREPROC_ID ||
tline->text[1] != '$'))) {
- error(ERR_NONFATAL, "`%%undef' expects a macro identifier");
+ nasm_error(ERR_NONFATAL, "`%%undef' expects a macro identifier");
free_tlist(origline);
return DIRECTIVE_FOUND;
}
if (tline->next) {
- error(ERR_WARNING|ERR_PASS1,
+ nasm_error(ERR_WARNING|ERR_PASS1,
"trailing garbage after macro name ignored");
}
@@ -3110,7 +3111,7 @@ issue_error:
if (!tline || (tline->type != TOK_ID &&
(tline->type != TOK_PREPROC_ID ||
tline->text[1] != '$'))) {
- error(ERR_NONFATAL, "`%s' expects a macro identifier",
+ nasm_error(ERR_NONFATAL, "`%s' expects a macro identifier",
pp_directives[i]);
free_tlist(origline);
return DIRECTIVE_FOUND;
@@ -3151,7 +3152,7 @@ issue_error:
if (!tline || (tline->type != TOK_ID &&
(tline->type != TOK_PREPROC_ID ||
tline->text[1] != '$'))) {
- error(ERR_NONFATAL,
+ nasm_error(ERR_NONFATAL,
"`%s' expects a macro identifier as first parameter",
pp_directives[i]);
free_tlist(origline);
@@ -3167,7 +3168,7 @@ issue_error:
t = t->next;
/* t should now point to the string */
if (!tok_type_(t, TOK_STRING)) {
- error(ERR_NONFATAL,
+ nasm_error(ERR_NONFATAL,
"`%s` requires string as second parameter",
pp_directives[i]);
free_tlist(tline);
@@ -3207,7 +3208,7 @@ issue_error:
if (!tline || (tline->type != TOK_ID &&
(tline->type != TOK_PREPROC_ID ||
tline->text[1] != '$'))) {
- error(ERR_NONFATAL,
+ nasm_error(ERR_NONFATAL,
"`%%pathsearch' expects a macro identifier as first parameter");
free_tlist(origline);
return DIRECTIVE_FOUND;
@@ -3223,13 +3224,13 @@ issue_error:
if (!t || (t->type != TOK_STRING &&
t->type != TOK_INTERNAL_STRING)) {
- error(ERR_NONFATAL, "`%%pathsearch' expects a file name");
+ nasm_error(ERR_NONFATAL, "`%%pathsearch' expects a file name");
free_tlist(tline);
free_tlist(origline);
return DIRECTIVE_FOUND; /* but we did _something_ */
}
if (t->next)
- error(ERR_WARNING|ERR_PASS1,
+ nasm_error(ERR_WARNING|ERR_PASS1,
"trailing garbage after `%%pathsearch' ignored");
p = t->text;
if (t->type != TOK_INTERNAL_STRING)
@@ -3268,7 +3269,7 @@ issue_error:
if (!tline || (tline->type != TOK_ID &&
(tline->type != TOK_PREPROC_ID ||
tline->text[1] != '$'))) {
- error(ERR_NONFATAL,
+ nasm_error(ERR_NONFATAL,
"`%%strlen' expects a macro identifier as first parameter");
free_tlist(origline);
return DIRECTIVE_FOUND;
@@ -3283,7 +3284,7 @@ issue_error:
t = t->next;
/* t should now point to the string */
if (!tok_type_(t, TOK_STRING)) {
- error(ERR_NONFATAL,
+ nasm_error(ERR_NONFATAL,
"`%%strlen` requires string as second parameter");
free_tlist(tline);
free_tlist(origline);
@@ -3314,7 +3315,7 @@ issue_error:
if (!tline || (tline->type != TOK_ID &&
(tline->type != TOK_PREPROC_ID ||
tline->text[1] != '$'))) {
- error(ERR_NONFATAL,
+ nasm_error(ERR_NONFATAL,
"`%%strcat' expects a macro identifier as first parameter");
free_tlist(origline);
return DIRECTIVE_FOUND;
@@ -3337,7 +3338,7 @@ issue_error:
break;
/* else fall through */
default:
- error(ERR_NONFATAL,
+ nasm_error(ERR_NONFATAL,
"non-string passed to `%%strcat' (%d)", t->type);
free_tlist(tline);
free_tlist(origline);
@@ -3379,7 +3380,7 @@ issue_error:
if (!tline || (tline->type != TOK_ID &&
(tline->type != TOK_PREPROC_ID ||
tline->text[1] != '$'))) {
- error(ERR_NONFATAL,
+ nasm_error(ERR_NONFATAL,
"`%%substr' expects a macro identifier as first parameter");
free_tlist(origline);
return DIRECTIVE_FOUND;
@@ -3396,7 +3397,7 @@ issue_error:
/* t should now point to the string */
if (!tok_type_(t, TOK_STRING)) {
- error(ERR_NONFATAL,
+ nasm_error(ERR_NONFATAL,
"`%%substr` requires string as second parameter");
free_tlist(tline);
free_tlist(origline);
@@ -3406,14 +3407,13 @@ issue_error:
tt = t->next;
tptr = &tt;
tokval.t_type = TOKEN_INVALID;
- evalresult = evaluate(ppscan, tptr, &tokval, NULL,
- pass, error, NULL);
+ evalresult = evaluate(ppscan, tptr, &tokval, NULL, pass, NULL);
if (!evalresult) {
free_tlist(tline);
free_tlist(origline);
return DIRECTIVE_FOUND;
} else if (!is_simple(evalresult)) {
- error(ERR_NONFATAL, "non-constant value given to `%%substr`");
+ nasm_error(ERR_NONFATAL, "non-constant value given to `%%substr`");
free_tlist(tline);
free_tlist(origline);
return DIRECTIVE_FOUND;
@@ -3426,14 +3426,13 @@ issue_error:
count = 1; /* Backwards compatibility: one character */
} else {
tokval.t_type = TOKEN_INVALID;
- evalresult = evaluate(ppscan, tptr, &tokval, NULL,
- pass, error, NULL);
+ evalresult = evaluate(ppscan, tptr, &tokval, NULL, pass, NULL);
if (!evalresult) {
free_tlist(tline);
free_tlist(origline);
return DIRECTIVE_FOUND;
} else if (!is_simple(evalresult)) {
- error(ERR_NONFATAL, "non-constant value given to `%%substr`");
+ nasm_error(ERR_NONFATAL, "non-constant value given to `%%substr`");
free_tlist(tline);
free_tlist(origline);
return DIRECTIVE_FOUND;
@@ -3480,7 +3479,7 @@ issue_error:
if (!tline || (tline->type != TOK_ID &&
(tline->type != TOK_PREPROC_ID ||
tline->text[1] != '$'))) {
- error(ERR_NONFATAL,
+ nasm_error(ERR_NONFATAL,
"`%%%sassign' expects a macro identifier",
(i == PP_IASSIGN ? "i" : ""));
free_tlist(origline);
@@ -3494,8 +3493,7 @@ issue_error:
t = tline;
tptr = &t;
tokval.t_type = TOKEN_INVALID;
- evalresult =
- evaluate(ppscan, tptr, &tokval, NULL, pass, error, NULL);
+ evalresult = evaluate(ppscan, tptr, &tokval, NULL, pass, NULL);
free_tlist(tline);
if (!evalresult) {
free_tlist(origline);
@@ -3503,11 +3501,11 @@ issue_error:
}
if (tokval.t_type)
- error(ERR_WARNING|ERR_PASS1,
+ nasm_error(ERR_WARNING|ERR_PASS1,
"trailing garbage after expression ignored");
if (!is_simple(evalresult)) {
- error(ERR_NONFATAL,
+ nasm_error(ERR_NONFATAL,
"non-constant value given to `%%%sassign'",
(i == PP_IASSIGN ? "i" : ""));
free_tlist(origline);
@@ -3535,7 +3533,7 @@ issue_error:
tline = tline->next;
skip_white_(tline);
if (!tok_type_(tline, TOK_NUMBER)) {
- error(ERR_NONFATAL, "`%%line' expects line number");
+ nasm_error(ERR_NONFATAL, "`%%line' expects line number");
free_tlist(origline);
return DIRECTIVE_FOUND;
}
@@ -3545,7 +3543,7 @@ issue_error:
if (tok_is_(tline, "+")) {
tline = tline->next;
if (!tok_type_(tline, TOK_NUMBER)) {
- error(ERR_NONFATAL, "`%%line' expects line increment");
+ nasm_error(ERR_NONFATAL, "`%%line' expects line increment");
free_tlist(origline);
return DIRECTIVE_FOUND;
}
@@ -3562,7 +3560,7 @@ issue_error:
return DIRECTIVE_FOUND;
default:
- error(ERR_FATAL,
+ nasm_error(ERR_FATAL,
"preprocessor directive `%s' not yet implemented",
pp_directives[i]);
return DIRECTIVE_FOUND;
@@ -3649,7 +3647,7 @@ static bool paste_tokens(Token **head, const struct tokseq_match *m,
/* Left pasting token is start of line */
if (!prev_nonspace)
- error(ERR_FATAL, "No lvalue found on pasting");
+ nasm_error(ERR_FATAL, "No lvalue found on pasting");
/*
* No ending token, this might happen in two
@@ -3841,7 +3839,7 @@ static Token *expand_mmac_params_range(MMacro *mac, Token *tline, Token ***last)
return head;
err:
- error(ERR_NONFATAL, "`%%{%s}': macro parameters out of range",
+ nasm_error(ERR_NONFATAL, "`%%{%s}': macro parameters out of range",
&tline->text[1]);
return tline;
}
@@ -3879,7 +3877,7 @@ static Token *expand_mmac_params(Token * tline)
while (mac && !mac->name) /* avoid mistaking %reps for macros */
mac = mac->next_active;
if (!mac) {
- error(ERR_NONFATAL, "`%s': not in a macro call", t->text);
+ nasm_error(ERR_NONFATAL, "`%s': not in a macro call", t->text);
} else {
pos = strchr(t->text, ':');
if (!pos) {
@@ -3910,14 +3908,14 @@ static Token *expand_mmac_params(Token * tline)
}
cc = find_cc(tt);
if (cc == -1) {
- error(ERR_NONFATAL,
+ nasm_error(ERR_NONFATAL,
"macro parameter %d is not a condition code",
n + 1);
text = NULL;
} else {
type = TOK_ID;
if (inverse_ccs[cc] == -1) {
- error(ERR_NONFATAL,
+ nasm_error(ERR_NONFATAL,
"condition code `%s' is not invertible",
conditions[cc]);
text = NULL;
@@ -3936,7 +3934,7 @@ static Token *expand_mmac_params(Token * tline)
}
cc = find_cc(tt);
if (cc == -1) {
- error(ERR_NONFATAL,
+ nasm_error(ERR_NONFATAL,
"macro parameter %d is not a condition code",
n + 1);
text = NULL;
@@ -4078,7 +4076,7 @@ again:
while (tline) { /* main token loop */
if (!--deadman) {
- error(ERR_NONFATAL, "interminable macro recursion");
+ nasm_error(ERR_NONFATAL, "interminable macro recursion");
goto err;
}
@@ -4185,7 +4183,7 @@ again:
tline = t;
if (!tline) {
- error(ERR_NONFATAL,
+ nasm_error(ERR_NONFATAL,
"macro call expects terminating `)'");
break;
}
@@ -4235,7 +4233,7 @@ again:
}
if (brackets < 0) {
brackets = 0;
- error(ERR_NONFATAL, "braces do not "
+ nasm_error(ERR_NONFATAL, "braces do not "
"enclose all of macro parameter");
}
paramsize[nparam] += white + 1;
@@ -4247,7 +4245,7 @@ again:
m->casesense)))
m = m->next;
if (!m)
- error(ERR_WARNING|ERR_PASS1|ERR_WARN_MNP,
+ nasm_error(ERR_WARNING|ERR_PASS1|ERR_WARN_MNP,
"macro `%s' exists, "
"but not taking %d parameters",
mstart->text, nparam);
@@ -4485,7 +4483,7 @@ static MMacro *is_mmacro(Token * tline, Token *** params_array)
*/
if (m->in_progress > m->max_depth) {
if (m->max_depth > 0) {
- error(ERR_WARNING,
+ nasm_error(ERR_WARNING,
"reached maximum recursion depth of %i",
m->max_depth);
}
@@ -4537,7 +4535,7 @@ static MMacro *is_mmacro(Token * tline, Token *** params_array)
* After all that, we didn't find one with the right number of
* parameters. Issue a warning, and fail to expand the macro.
*/
- error(ERR_WARNING|ERR_PASS1|ERR_WARN_MNP,
+ nasm_error(ERR_WARNING|ERR_PASS1|ERR_WARN_MNP,
"macro `%s' exists, but not taking %d parameters",
tline->text, nparam);
nasm_free(params);
@@ -4673,7 +4671,7 @@ static int expand_mmacro(Token * tline)
paramlen[i]++;
}
if (brace)
- error(ERR_NONFATAL, "macro params should be enclosed in braces");
+ nasm_error(ERR_NONFATAL, "macro params should be enclosed in braces");
}
/*
@@ -4771,73 +4769,57 @@ static int expand_mmacro(Token * tline)
}
}
- list->uplevel(m->nolist ? LIST_MACRO_NOLIST : LIST_MACRO);
+ nasmlist->uplevel(m->nolist ? LIST_MACRO_NOLIST : LIST_MACRO);
return 1;
}
-/* The function that actually does the error reporting */
-static void verror(int severity, const char *fmt, va_list arg)
+/*
+ * This function adds macro names to error messages, and suppresses
+ * them if necessary.
+ */
+static void pp_verror(int severity, const char *fmt, va_list arg)
{
- char buff[1024];
+ char buff[BUFSIZ];
MMacro *mmac = NULL;
int delta = 0;
- vsnprintf(buff, sizeof(buff), fmt, arg);
+ /*
+ * If we're in a dead branch of IF or something like it, ignore the error.
+ * However, because %else etc are evaluated in the state context
+ * of the previous branch, errors might get lost:
+ * %if 0 ... %else trailing garbage ... %endif
+ * So %else etc should set the ERR_PP_PRECOND flag.
+ */
+ if ((severity & ERR_MASK) < ERR_FATAL &&
+ istk && istk->conds &&
+ ((severity & ERR_PP_PRECOND) ?
+ istk->conds->state == COND_NEVER :
+ emitting(istk->conds->state)))
+ return;
/* get %macro name */
- if (istk && istk->mstk) {
+ if (!(severity & ERR_NOFILE) && istk && istk->mstk) {
mmac = istk->mstk;
/* but %rep blocks should be skipped */
while (mmac && !mmac->name)
mmac = mmac->next_active, delta++;
}
- if (mmac)
- nasm_error(severity, "(%s:%d) %s",
- mmac->name, mmac->lineno - delta, buff);
- else
- nasm_error(severity, "%s", buff);
-}
-
-/*
- * Since preprocessor always operate only on the line that didn't
- * arrived yet, we should always use ERR_OFFBY1.
- */
-static void error(int severity, const char *fmt, ...)
-{
- va_list arg;
-
- /* If we're in a dead branch of IF or something like it, ignore the error */
- if (istk && istk->conds && !emitting(istk->conds->state))
- return;
-
- va_start(arg, fmt);
- verror(severity, fmt, arg);
- va_end(arg);
-}
+ if (mmac) {
+ vsnprintf(buff, sizeof(buff), fmt, arg);
-/*
- * Because %else etc are evaluated in the state context
- * of the previous branch, errors might get lost with error():
- * %if 0 ... %else trailing garbage ... %endif
- * So %else etc should report errors with this function.
- */
-static void error_precond(int severity, const char *fmt, ...)
-{
- va_list arg;
-
- /* Only ignore the error if it's really in a dead branch */
- if (istk && istk->conds && istk->conds->state == COND_NEVER)
- return;
-
- va_start(arg, fmt);
- verror(severity, fmt, arg);
- va_end(arg);
+ nasm_set_verror(real_verror);
+ nasm_error(severity, "(%s:%d) %s",
+ mmac->name, mmac->lineno - delta, buff);
+ nasm_set_verror(pp_verror);
+ } else {
+ real_verror(severity, fmt, arg);
+ }
}
static void
-pp_reset(char *file, int apass, ListGen * listgen, StrList **deplist)
+pp_reset(char *file, int apass, StrList **deplist)
{
Token *t;
@@ -4853,8 +4835,7 @@ pp_reset(char *file, int apass, ListGen * listgen, StrList **deplist)
src_set_linnum(0);
istk->lineinc = 1;
if (!istk->fp)
- error(ERR_FATAL|ERR_NOFILE, "unable to open input file `%s'",
- file);
+ nasm_fatal(ERR_NOFILE, "unable to open input file `%s'", file);
defining = NULL;
nested_mac_count = 0;
nested_rep_count = 0;
@@ -4867,7 +4848,6 @@ pp_reset(char *file, int apass, ListGen * listgen, StrList **deplist)
}
any_extrastdmac = extrastdmac && *extrastdmac;
do_predef = true;
- list = listgen;
/*
* 0 for dependencies, 1 for preparatory passes, 2 for final pass.
@@ -4902,6 +4882,8 @@ static char *pp_getline(void)
char *line;
Token *tline;
+ real_verror = nasm_set_verror(pp_verror);
+
while (1) {
/*
* Fetch a tokenized line, either from the macro-expansion
@@ -4955,13 +4937,11 @@ static char *pp_getline(void)
*/
if (defining) {
if (defining->name)
- error(ERR_PANIC,
- "defining with name in expansion");
+ nasm_panic(0, "defining with name in expansion");
else if (istk->mstk->name)
- error(ERR_FATAL,
- "`%%rep' without `%%endrep' within"
- " expansion of macro `%s'",
- istk->mstk->name);
+ nasm_fatal(0, "`%%rep' without `%%endrep' within"
+ " expansion of macro `%s'",
+ istk->mstk->name);
}
/*
@@ -4991,7 +4971,7 @@ static char *pp_getline(void)
}
istk->expansion = l->next;
nasm_free(l);
- list->downlevel(LIST_MACRO);
+ nasmlist->downlevel(LIST_MACRO);
}
}
while (1) { /* until we get a line we can use */
@@ -5005,7 +4985,7 @@ static char *pp_getline(void)
istk->expansion = l->next;
nasm_free(l);
p = detoken(tline, false);
- list->line(LIST_MACRO, p);
+ nasmlist->line(LIST_MACRO, p);
nasm_free(p);
break;
}
@@ -5033,10 +5013,12 @@ static char *pp_getline(void)
nasm_free(src_set_fname(nasm_strdup(i->fname)));
}
istk = i->next;
- list->downlevel(LIST_INCLUDE);
+ nasmlist->downlevel(LIST_INCLUDE);
nasm_free(i);
- if (!istk)
- return NULL;
+ if (!istk) {
+ line = NULL;
+ goto done;
+ }
if (istk->expansion && istk->expansion->finishes)
break;
}
@@ -5109,23 +5091,30 @@ static char *pp_getline(void)
}
}
+done:
+ nasm_set_verror(real_verror);
return line;
}
static void pp_cleanup(int pass)
{
+ real_verror = nasm_set_verror(pp_verror);
+
if (defining) {
if (defining->name) {
- error(ERR_NONFATAL,
- "end of file while still defining macro `%s'",
- defining->name);
+ nasm_error(ERR_NONFATAL,
+ "end of file while still defining macro `%s'",
+ defining->name);
} else {
- error(ERR_NONFATAL, "end of file while still in %%rep");
+ nasm_error(ERR_NONFATAL, "end of file while still in %%rep");
}
free_mmacro(defining);
defining = NULL;
}
+
+ nasm_set_verror(real_verror);
+
while (cstk)
ctx_pop();
free_macros();
@@ -5194,6 +5183,8 @@ static void pp_pre_define(char *definition)
Line *l;
char *equals;
+ real_verror = nasm_set_verror(pp_verror);
+
equals = strchr(definition, '=');
space = new_Token(NULL, TOK_WHITESPACE, NULL, 0);
def = new_Token(space, TOK_PREPROC_ID, "%define", 0);
@@ -5205,13 +5196,15 @@ static void pp_pre_define(char *definition)
if (space->next->type != TOK_PREPROC_ID &&
space->next->type != TOK_ID)
- error(ERR_WARNING, "pre-defining non ID `%s\'\n", definition);
+ nasm_error(ERR_WARNING, "pre-defining non ID `%s\'\n", definition);
l = nasm_malloc(sizeof(Line));
l->next = predef;
l->first = def;
l->finishes = NULL;
predef = l;
+
+ nasm_set_verror(real_verror);
}
static void pp_pre_undefine(char *definition)