Drop the ofmt and errfunc arguments to label definition functions
authorH. Peter Anvin <hpa@zytor.com>
Sun, 19 Jul 2009 01:31:41 +0000 (18:31 -0700)
committerH. Peter Anvin <hpa@zytor.com>
Sun, 19 Jul 2009 01:43:58 +0000 (18:43 -0700)
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>
14 files changed:
labels.c
labels.h
nasm.c
nasm.h
output/outaout.c
output/outbin.c
output/outcoff.c
output/outelf32.c
output/outelf64.c
output/outieee.c
output/outmacho64.c
output/outobj.c
parser.c
parser.h

index 7e7b7f315098b89f50ae119561fdc4df33db73dd..8c850c3085268fbb2dd64c794e077c5a51f99394 100644 (file)
--- a/labels.c
+++ b/labels.c
@@ -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;
         }
index 59e83ba0123bb0a4a1aa0b6815764bbe86dd048c..865a557105f340543865216ae9b1c7fbb08486a2 100644 (file)
--- a/labels.h
+++ b/labels.h
@@ -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);
diff --git a/nasm.c b/nasm.c
index 7bcdc5af38aeeeed34bf30cc6f96bdfdb83f61f6..d6db557c336263e4220933ed17beff7cdbd0ccb6 100644 (file)
--- a/nasm.c
+++ b/nasm.c
@@ -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");
diff --git a/nasm.h b/nasm.h
index 341983ad334719edc11b13844919c59487dcc1ce..a94cb0a279f9e9ddfc7df96a0f12ad34b873e996 100644 (file)
--- a/nasm.h
+++ b/nasm.h
@@ -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:
index 0b3c7ca3416e9e27a4abccc181123ddab3af000f..8bff63e80d94c9b13b909e8a87ad558a77dd8eff 100644 (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
index 79f5d20ce5ef12ee286ee00ed6ec0a174673b520..6f08e87e37f88f6a43a1e1d2f937033778f6bc4e 100644 (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);
     }
index f147ea98ed8813888ba764ba26bd1c8d8079cb75..4277744224018222fd8f7bde442d10ab6787c1ab 100644 (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)
index cec3feb67e1ca1467ef6974f4882bf1c78f6f17c..7dce1658b2d1e591012c8dbb3606dd945ce3022c 100644 (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();
 }
index 1e73fccd9b07d3ef63db965dc44ea282ba75b1c3..5ccdf51cd41a60213c6d531e87c788ff6a163450 100644 (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();
 
index 0fc3c409cea630a463836f93fc0aea5ca8bb0d89..900d1e3e811bf91913a1308990e11299bcc286d1 100644 (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)
index 3c38ddb691b2b0074ecb3c0c9d4a1c988f607e3f..a0da1340bfc32c83cfaf0f468abd393161eb4e5b 100644 (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
index 2011a879af5040e22973979bba3cc8f79b5888de..89156b22804889c4fdf67a0998814baad1e959b9 100644 (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) {
index 79da372931b92de28a8efe30e31d6744a1ab694b..9b9e89ac0c5b351c8cf69966ed90adad21c18b61 100644 (file)
--- a/parser.c
+++ b/parser.c
@@ -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);
         }
     }
 
index 7e5a9f9d76a460fb05e3366ec0d19dd49bab75b5..eb882edbc79bb989681dac3013349a73016165c9 100644 (file)
--- a/parser.h
+++ b/parser.h
@@ -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);