Drop the ofmt and errfunc arguments to label definition functions

We never set ofmt and errfunc to anything but the global values.
Dropping them from the label definition function command line
simplifies the code.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
This commit is contained in:
H. Peter Anvin 2009-07-18 18:31:41 -07:00
parent ab6443969a
commit 605f5155ee
14 changed files with 66 additions and 104 deletions

View file

@ -206,8 +206,7 @@ bool is_extern(char *label)
}
void redefine_label(char *label, int32_t segment, int64_t offset, char *special,
bool is_norm, bool isextrn, struct ofmt *ofmt,
efunc error)
bool is_norm, bool isextrn)
{
union label *lptr;
int exi;
@ -220,19 +219,18 @@ void redefine_label(char *label, int32_t segment, int64_t offset, char *special,
(void)special; /* Don't warn that this parameter is unused */
(void)is_norm; /* Don't warn that this parameter is unused */
(void)isextrn; /* Don't warn that this parameter is unused */
(void)ofmt; /* Don't warn that this parameter is unused */
#ifdef DEBUG
#if DEBUG<3
if (!strncmp(label, "debugdump", 9))
#endif
error(ERR_DEBUG, "redefine_label (%s, %ld, %08lx, %s, %d, %d)",
nasm_error(ERR_DEBUG, "redefine_label (%s, %ld, %08lx, %s, %d, %d)",
label, segment, offset, special, is_norm, isextrn);
#endif
lptr = find_label(label, 1);
if (!lptr)
error(ERR_PANIC, "can't find label `%s' on pass two", label);
nasm_error(ERR_PANIC, "can't find label `%s' on pass two", label);
if (!islocal(label)) {
if (!islocalchar(*label) && lptr->defn.is_norm)
@ -281,7 +279,7 @@ void redefine_label(char *label, int32_t segment, int64_t offset, char *special,
}
void define_label(char *label, int32_t segment, int64_t offset, char *special,
bool is_norm, bool isextrn, struct ofmt *ofmt, efunc error)
bool is_norm, bool isextrn)
{
union label *lptr;
int exi;
@ -290,12 +288,12 @@ void define_label(char *label, int32_t segment, int64_t offset, char *special,
#if DEBUG<3
if (!strncmp(label, "debugdump", 9))
#endif
error(ERR_DEBUG, "define_label (%s, %ld, %08lx, %s, %d, %d)",
nasm_error(ERR_DEBUG, "define_label (%s, %ld, %08lx, %s, %d, %d)",
label, segment, offset, special, is_norm, isextrn);
#endif
lptr = find_label(label, 1);
if (lptr->defn.is_global & DEFINED_BIT) {
error(ERR_NONFATAL, "symbol `%s' redefined", label);
nasm_error(ERR_NONFATAL, "symbol `%s' redefined", label);
return;
}
lptr->defn.is_global |= DEFINED_BIT;
@ -306,7 +304,7 @@ void define_label(char *label, int32_t segment, int64_t offset, char *special,
/* not local, but not special either */
prevlabel = lptr->defn.label;
} else if (islocal(label) && !*prevlabel) {
error(ERR_NONFATAL, "attempt to define a local label before any"
nasm_error(ERR_NONFATAL, "attempt to define a local label before any"
" non-local labels");
}
@ -348,15 +346,14 @@ void define_label(char *label, int32_t segment, int64_t offset, char *special,
} /* if (pass0 == 1) */
}
void define_common(char *label, int32_t segment, int32_t size, char *special,
struct ofmt *ofmt, efunc error)
void define_common(char *label, int32_t segment, int32_t size, char *special)
{
union label *lptr;
lptr = find_label(label, 1);
if ((lptr->defn.is_global & DEFINED_BIT) &&
(passn == 1 || !(lptr->defn.is_global & COMMON_BIT))) {
error(ERR_NONFATAL, "symbol `%s' redefined", label);
nasm_error(ERR_NONFATAL, "symbol `%s' redefined", label);
return;
}
lptr->defn.is_global |= DEFINED_BIT|COMMON_BIT;
@ -364,7 +361,7 @@ void define_common(char *label, int32_t segment, int32_t size, char *special,
if (!islocalchar(label[0])) {
prevlabel = lptr->defn.label;
} else {
error(ERR_NONFATAL, "attempt to define a local label as a "
nasm_error(ERR_NONFATAL, "attempt to define a local label as a "
"common variable");
return;
}
@ -382,12 +379,12 @@ void define_common(char *label, int32_t segment, int32_t size, char *special,
special);
}
void declare_as_global(char *label, char *special, efunc error)
void declare_as_global(char *label, char *special)
{
union label *lptr;
if (islocal(label)) {
error(ERR_NONFATAL, "attempt to declare local symbol `%s' as"
nasm_error(ERR_NONFATAL, "attempt to declare local symbol `%s' as"
" global", label);
return;
}
@ -402,7 +399,7 @@ void declare_as_global(char *label, char *special, efunc error)
break;
case LOCAL_SYMBOL:
if (!(lptr->defn.is_global & EXTERN_BIT)) {
error(ERR_WARNING, "symbol `%s': GLOBAL directive "
nasm_error(ERR_WARNING, "symbol `%s': GLOBAL directive "
"after symbol definition is an experimental feature", label);
lptr->defn.is_global = GLOBAL_SYMBOL;
}

View file

@ -44,14 +44,11 @@ extern char lpostfix[PREFIX_MAX];
bool lookup_label(char *label, int32_t *segment, int64_t *offset);
bool is_extern(char *label);
void define_label(char *label, int32_t segment, int64_t offset, char *special,
bool is_norm, bool isextrn, struct ofmt *ofmt,
efunc error);
bool is_norm, bool isextrn);
void redefine_label(char *label, int32_t segment, int64_t offset, char *special,
bool is_norm, bool isextrn, struct ofmt *ofmt,
efunc error);
void define_common(char *label, int32_t segment, int32_t size, char *special,
struct ofmt *ofmt, efunc error);
void declare_as_global(char *label, char *special, efunc error);
bool is_norm, bool isextrn);
void define_common(char *label, int32_t segment, int32_t size, char *special);
void declare_as_global(char *label, char *special);
int init_labels(void);
void cleanup_labels(void);
char *local_scope(char *label);

24
nasm.c
View file

@ -348,7 +348,7 @@ int main(int argc, char **argv)
if (ofmt->stdmac)
pp_extra_stdmac(ofmt->stdmac);
parser_global_info(ofmt, &location);
parser_global_info(&location);
eval_global_info(ofmt, lookup_label, &location);
/* define some macros dependent of command-line */
@ -1265,10 +1265,9 @@ static void assemble_file(char *fname, StrList **depend_ptr)
if (!is_extern(value)) { /* allow re-EXTERN to be ignored */
int temp = pass0;
pass0 = 1; /* fake pass 1 in labels.c */
declare_as_global(value, special,
nasm_error);
declare_as_global(value, special);
define_label(value, seg_alloc(), 0L, NULL,
false, true, ofmt, nasm_error);
false, true);
pass0 = temp;
}
} /* else pass0 == 1 */
@ -1307,7 +1306,7 @@ static void assemble_file(char *fname, StrList **depend_ptr)
special = q;
} else
special = NULL;
declare_as_global(value, special, nasm_error);
declare_as_global(value, special);
} /* pass == 1 */
break;
case D_COMMON: /* [COMMON symbol size:special] */
@ -1357,8 +1356,7 @@ static void assemble_file(char *fname, StrList **depend_ptr)
}
if (pass0 < 2) {
define_common(value, seg_alloc(), size,
special, ofmt, nasm_error);
define_common(value, seg_alloc(), size, special);
} else if (pass0 == 2) {
if (special)
ofmt->symdef(value, 0L, 0L, 3, special);
@ -1554,8 +1552,7 @@ static void assemble_file(char *fname, StrList **depend_ptr)
def_label(output_ins.label,
output_ins.oprs[0].segment,
output_ins.oprs[0].offset, NULL,
false, isext, ofmt,
nasm_error);
false, isext);
} else if (output_ins.operands == 2
&& (output_ins.oprs[0].type & IMMEDIATE)
&& (output_ins.oprs[0].type & COLON)
@ -1567,8 +1564,7 @@ static void assemble_file(char *fname, StrList **depend_ptr)
def_label(output_ins.label,
output_ins.oprs[0].offset | SEG_ABS,
output_ins.oprs[1].offset,
NULL, false, false, ofmt,
nasm_error);
NULL, false, false);
} else
nasm_error(ERR_NONFATAL,
"bad syntax for EQU");
@ -1586,8 +1582,7 @@ static void assemble_file(char *fname, StrList **depend_ptr)
define_label(output_ins.label,
output_ins.oprs[0].segment,
output_ins.oprs[0].offset,
NULL, false, false, ofmt,
nasm_error);
NULL, false, false);
} else if (output_ins.operands == 2
&& (output_ins.oprs[0].
type & IMMEDIATE)
@ -1602,8 +1597,7 @@ static void assemble_file(char *fname, StrList **depend_ptr)
output_ins.oprs[0].
offset | SEG_ABS,
output_ins.oprs[1].offset,
NULL, false, false, ofmt,
nasm_error);
NULL, false, false);
} else
nasm_error(ERR_NONFATAL,
"bad syntax for EQU");

6
nasm.h
View file

@ -123,11 +123,9 @@ typedef bool (*lfunc) (char *label, int32_t *segment, int64_t *offset);
* an EQU or a segment-base symbol, which shouldn't.
*/
typedef void (*ldfunc)(char *label, int32_t segment, int64_t offset,
char *special, bool is_norm, bool isextrn,
struct ofmt * ofmt, efunc error);
char *special, bool is_norm, bool isextrn);
void define_label(char *label, int32_t segment, int64_t offset,
char *special, bool is_norm, bool isextrn,
struct ofmt * ofmt, efunc error);
char *special, bool is_norm, bool isextrn);
/*
* List-file generators should look like this:

View file

@ -198,20 +198,15 @@ static void aoutb_init(void)
is_pic = 0x00; /* may become 0x40 */
aout_gotpc_sect = seg_alloc();
define_label("..gotpc", aout_gotpc_sect + 1, 0L, NULL, false, false, &of_aoutb,
nasm_error);
define_label("..gotpc", aout_gotpc_sect + 1, 0L, NULL, false, false);
aout_gotoff_sect = seg_alloc();
define_label("..gotoff", aout_gotoff_sect + 1, 0L, NULL, false, false,
&of_aoutb, nasm_error);
define_label("..gotoff", aout_gotoff_sect + 1, 0L, NULL, false, false);
aout_got_sect = seg_alloc();
define_label("..got", aout_got_sect + 1, 0L, NULL, false, false, &of_aoutb,
nasm_error);
define_label("..got", aout_got_sect + 1, 0L, NULL, false, false);
aout_plt_sect = seg_alloc();
define_label("..plt", aout_plt_sect + 1, 0L, NULL, false, false, &of_aoutb,
nasm_error);
define_label("..plt", aout_plt_sect + 1, 0L, NULL, false, false);
aout_sym_sect = seg_alloc();
define_label("..sym", aout_sym_sect + 1, 0L, NULL, false, false, &of_aoutb,
nasm_error);
define_label("..sym", aout_sym_sect + 1, 0L, NULL, false, false);
}
#endif

View file

@ -1205,13 +1205,11 @@ static void bin_define_section_labels(void)
/* section.<name>.start */
strcpy(label_name + base_len, ".start");
define_label(label_name, sec->start_index, 0L,
NULL, 0, 0, ofmt, nasm_error);
define_label(label_name, sec->start_index, 0L, NULL, 0, 0);
/* section.<name>.vstart */
strcpy(label_name + base_len, ".vstart");
define_label(label_name, sec->vstart_index, 0L,
NULL, 0, 0, ofmt, nasm_error);
define_label(label_name, sec->vstart_index, 0L, NULL, 0, 0);
nasm_free(label_name);
}

View file

@ -193,8 +193,7 @@ static void coff_win64_init(void)
win64 = true;
coff_gen_init();
imagebase_sect = seg_alloc()+1;
define_label(WRT_IMAGEBASE, imagebase_sect, 0, NULL, false, false,
ofmt, nasm_error);
define_label(WRT_IMAGEBASE, imagebase_sect, 0, NULL, false, false);
}
static void coff_std_init(void)

View file

@ -253,23 +253,17 @@ static void elf_init(void)
fwds = NULL;
elf_gotpc_sect = seg_alloc();
define_label("..gotpc", elf_gotpc_sect + 1, 0L, NULL, false, false, &of_elf32,
nasm_error);
define_label("..gotpc", elf_gotpc_sect + 1, 0L, NULL, false, false);
elf_gotoff_sect = seg_alloc();
define_label("..gotoff", elf_gotoff_sect + 1, 0L, NULL, false, false, &of_elf32,
nasm_error);
define_label("..gotoff", elf_gotoff_sect + 1, 0L, NULL, false, false);
elf_got_sect = seg_alloc();
define_label("..got", elf_got_sect + 1, 0L, NULL, false, false, &of_elf32,
nasm_error);
define_label("..got", elf_got_sect + 1, 0L, NULL, false, false);
elf_plt_sect = seg_alloc();
define_label("..plt", elf_plt_sect + 1, 0L, NULL, false, false, &of_elf32,
nasm_error);
define_label("..plt", elf_plt_sect + 1, 0L, NULL, false, false);
elf_sym_sect = seg_alloc();
define_label("..sym", elf_sym_sect + 1, 0L, NULL, false, false, &of_elf32,
nasm_error);
define_label("..sym", elf_sym_sect + 1, 0L, NULL, false, false);
elf_tlsie_sect = seg_alloc();
define_label("..tlsie", elf_tlsie_sect + 1, 0L, NULL, false, false, &of_elf32,
nasm_error);
define_label("..tlsie", elf_tlsie_sect + 1, 0L, NULL, false, false);
def_seg = seg_alloc();
}

View file

@ -263,23 +263,17 @@ static void elf_init(void)
fwds = NULL;
elf_gotpc_sect = seg_alloc();
define_label("..gotpc", elf_gotpc_sect + 1, 0L, NULL, false, false, &of_elf64,
nasm_error);
define_label("..gotpc", elf_gotpc_sect + 1, 0L, NULL, false, false);
elf_gotoff_sect = seg_alloc();
define_label("..gotoff", elf_gotoff_sect + 1, 0L, NULL, false, false, &of_elf64,
nasm_error);
define_label("..gotoff", elf_gotoff_sect + 1, 0L, NULL, false, false);
elf_got_sect = seg_alloc();
define_label("..got", elf_got_sect + 1, 0L, NULL, false, false, &of_elf64,
nasm_error);
define_label("..got", elf_got_sect + 1, 0L, NULL, false, false);
elf_plt_sect = seg_alloc();
define_label("..plt", elf_plt_sect + 1, 0L, NULL, false, false, &of_elf64,
nasm_error);
define_label("..plt", elf_plt_sect + 1, 0L, NULL, false, false);
elf_sym_sect = seg_alloc();
define_label("..sym", elf_sym_sect + 1, 0L, NULL, false, false, &of_elf64,
nasm_error);
define_label("..sym", elf_sym_sect + 1, 0L, NULL, false, false);
elf_gottpoff_sect = seg_alloc();
define_label("..gottpoff", elf_gottpoff_sect + 1, 0L, NULL, false, false, &of_elf64,
nasm_error);
define_label("..gottpoff", elf_gottpoff_sect + 1, 0L, NULL, false, false);
def_seg = seg_alloc();

View file

@ -811,10 +811,9 @@ static int32_t ieee_segment(char *name, int pass, int *bits)
ieee_seg_needs_update = seg;
if (seg->align >= SEG_ABS)
define_label(name, NO_SEG, seg->align - SEG_ABS,
NULL, false, false, &of_ieee, nasm_error);
NULL, false, false);
else
define_label(name, seg->index + 1, 0L,
NULL, false, false, &of_ieee, nasm_error);
define_label(name, seg->index + 1, 0L, NULL, false, false);
ieee_seg_needs_update = NULL;
if (seg->use32)

View file

@ -373,11 +373,11 @@ static void macho_init(void)
/* string table starts with a zero byte - don't ask why */
saa_wbytes(strs, &zero, sizeof(char));
strslen = 1;
/* add special symbol for ..gotpcrel */
macho_gotpcrel_sect = seg_alloc();
macho_gotpcrel_sect ++;
define_label("..gotpcrel", macho_gotpcrel_sect, 0L, NULL, false, false, &of_macho64, nasm_error);
/* add special symbol for ..gotpcrel */
macho_gotpcrel_sect = seg_alloc();
macho_gotpcrel_sect++;
define_label("..gotpcrel", macho_gotpcrel_sect, 0L, NULL, false, false);
}
static void sect_write(struct section *sect,
@ -391,9 +391,9 @@ static int32_t add_reloc(struct section *sect, int32_t section,
int pcrel, int bytes, int64_t reloff)
{
struct reloc *r;
struct symbol *sym;
struct symbol *sym;
int32_t fi;
int32_t adjustment = 0;
int32_t adjustment = 0;
/* NeXT as puts relocs in reversed order (address-wise) into the
** files, so we do the same, doesn't seem to make much of a

View file

@ -1478,10 +1478,10 @@ static int32_t obj_segment(char *name, int pass, int *bits)
obj_seg_needs_update = seg;
if (seg->align >= SEG_ABS)
define_label(name, NO_SEG, seg->align - SEG_ABS,
NULL, false, false, &of_obj, nasm_error);
NULL, false, false);
else
define_label(name, seg->index + 1, 0L,
NULL, false, false, &of_obj, nasm_error);
NULL, false, false);
obj_seg_needs_update = NULL;
/*
@ -1495,9 +1495,9 @@ static int32_t obj_segment(char *name, int pass, int *bits)
grp->segs[grp->nindices++].index = seg->obj_index;
if (seg->grp)
nasm_error(ERR_WARNING,
"segment `%s' is already part of"
" a group: first one takes precedence",
seg->name);
"segment `%s' is already part of"
" a group: first one takes precedence",
seg->name);
else
seg->grp = grp;
}
@ -1583,8 +1583,7 @@ static int obj_directive(enum directives directive, char *value, int pass)
grp->name = NULL;
obj_grp_needs_update = grp;
define_label(v, grp->index + 1, 0L,
NULL, false, false, &of_obj, nasm_error);
define_label(v, grp->index + 1, 0L, NULL, false, false);
obj_grp_needs_update = NULL;
while (*q) {

View file

@ -61,12 +61,10 @@ static int is_comma_next(void);
static int i;
static struct tokenval tokval;
static efunc error;
static struct ofmt *outfmt; /* Structure of addresses of output routines */
static struct location *location; /* Pointer to current line's segment,offset */
void parser_global_info(struct ofmt *output, struct location * locp)
void parser_global_info(struct location * locp)
{
outfmt = output;
location = locp;
}
@ -248,7 +246,7 @@ restart_parse:
* am still not certain.
*/
ldef(result->label, in_abs_seg ? abs_seg : location->segment,
location->offset, NULL, true, false, outfmt, errfunc);
location->offset, NULL, true, false);
}
}

View file

@ -39,7 +39,7 @@
#ifndef NASM_PARSER_H
#define NASM_PARSER_H
void parser_global_info(struct ofmt *output, struct location * locp);
void parser_global_info(struct location * locp);
insn *parse_line(int pass, char *buffer, insn * result,
efunc error, evalfunc evaluate, ldfunc ldef);
void cleanup_insn(insn * instruction);