From: nasm-bot f. H. P. A. <hp...@li...> - 2016-02-18 04:33:50
|
Commit-ID: 130736c0cfcad28ee16cec6c14bb22999d982e5a Gitweb: http://repo.or.cz/w/nasm.git?a=commitdiff;h=130736c0cfcad28ee16cec6c14bb22999d982e5a Author: H. Peter Anvin <hp...@li...> AuthorDate: Wed, 17 Feb 2016 20:27:41 -0800 Committer: H. Peter Anvin <hp...@li...> CommitDate: Wed, 17 Feb 2016 20:27:41 -0800 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 <hp...@li...> --- assemble.c | 185 ++++++++++++------------ assemble.h | 5 +- eval.c | 78 +++++----- eval.h | 3 +- float.c | 38 +++-- float.h | 3 +- listing.c | 20 ++- listing.h | 4 +- nasm.c | 35 ++--- nasm.h | 8 +- nasmlib.c | 7 +- nasmlib.h | 26 ++-- output/outaout.c | 5 +- output/outbin.c | 4 +- output/outelf32.c | 5 +- output/outelf64.c | 5 +- output/outelfx32.c | 5 +- output/outform.h | 1 - output/outobj.c | 2 +- parser.c | 15 +- preproc-nop.c | 9 +- preproc.c | 409 ++++++++++++++++++++++++++--------------------------- 22 files changed, 421 insertions(+), 451 deletions(-) diff --git a/assemble.c b/assemble.c index ed8b9f8..a26f2bf 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 381e3ab..f85037a 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 403a793..a8e463f 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 0ea59d1..76ea14b 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 7a4f8cb..adf18c5 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 6f94cc6..a00a043 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 49f5e15..3b395bc 100644 --- a/listing.c +++ b/listing.c @@ -1,6 +1,6 @@ /* ----------------------------------------------------------------------- * * - * Copyright 1996-2009 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. * @@ -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,6 @@ ListGen nasmlist = { list_downlevel, list_error }; + +const ListGen *nasmlist = &nasm_list; + diff --git a/listing.h b/listing.h index da2e849..8e178b0 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 a176f25..140a6e1 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())) { /* @@ -1203,8 +1204,7 @@ static void assemble_file(char *fname, StrList **depend_ptr) int pass_max; if (cmd_sb == 32 && iflag_ffs(&cmd_cpu) < IF_386) - nasm_error(ERR_FATAL, "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++) { @@ -1220,8 +1220,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 */ @@ -1233,8 +1232,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; @@ -1273,7 +1271,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) { @@ -1431,8 +1429,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 == @@ -1679,7 +1676,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) @@ -1758,8 +1755,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); } @@ -1804,7 +1800,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); @@ -1988,8 +1984,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 f0cc346..d0fb8bd 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, - ... [truncated message content] |