summaryrefslogtreecommitdiff
path: root/output
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2009-07-12 12:53:49 -0700
committerH. Peter Anvin <hpa@zytor.com>2009-07-12 12:55:24 -0700
commitafa06137fa3d6de926134b4061c3ff4a74d212cf (patch)
treeddfb5182b1e0d06cfc731563cfdda2814b658cc5 /output
parentd0fbb7f0ab355fd4e73d1aab215a2aa387b615c3 (diff)
downloadnasm-afa06137fa3d6de926134b4061c3ff4a74d212cf.tar.gz
nasm-afa06137fa3d6de926134b4061c3ff4a74d212cf.tar.bz2
nasm-afa06137fa3d6de926134b4061c3ff4a74d212cf.zip
Hash even backend-specific directives, unify null functions
Hash all directives, even the ones that are backend-specific, and instead pass the backend an already-parsed directive number. Furthermore, unify null functions across various backends. Signed-off-by: H. Peter Anvin <hpa@zytor.com>
Diffstat (limited to 'output')
-rw-r--r--output/nullout.c51
-rw-r--r--output/outaout.c22
-rw-r--r--output/outas86.c27
-rw-r--r--output/outbin.c19
-rw-r--r--output/outcoff.c18
-rw-r--r--output/outdbg.c4
-rw-r--r--output/outelf32.c10
-rw-r--r--output/outelf64.c10
-rw-r--r--output/outieee.c10
-rw-r--r--output/outlib.h4
-rw-r--r--output/outmacho32.c23
-rw-r--r--output/outmacho64.c19
-rw-r--r--output/outobj.c24
-rw-r--r--output/outrdf2.c34
14 files changed, 147 insertions, 128 deletions
diff --git a/output/nullout.c b/output/nullout.c
new file mode 100644
index 0000000..228fa16
--- /dev/null
+++ b/output/nullout.c
@@ -0,0 +1,51 @@
+/* ----------------------------------------------------------------------- *
+ *
+ * Copyright 1996-2009 The NASM Authors - All Rights Reserved
+ * See the file AUTHORS included with the NASM distribution for
+ * the specific copyright holders.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following
+ * conditions are met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+ * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+ * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * ----------------------------------------------------------------------- */
+
+#include "nasm.h"
+#include "nasmlib.h"
+#include "output/outlib.h"
+
+int null_setinfo(enum geninfo type, char **string)
+{
+ (void)type;
+ (void)string;
+ return 0;
+}
+
+int null_directive(enum directives directive, char *value, int pass)
+{
+ (void)directive;
+ (void)value;
+ (void)pass;
+ return 0;
+}
diff --git a/output/outaout.c b/output/outaout.c
index 8d8966b..c39eedd 100644
--- a/output/outaout.c
+++ b/output/outaout.c
@@ -917,14 +917,6 @@ static int32_t aout_segbase(int32_t segment)
return segment;
}
-static int aout_directive(char *directive, char *value, int pass)
-{
- (void)directive;
- (void)value;
- (void)pass;
- return 0;
-}
-
static void aout_filename(char *inname, char *outname, efunc error)
{
standard_extension(inname, outname, ".o", error);
@@ -932,12 +924,6 @@ static void aout_filename(char *inname, char *outname, efunc error)
extern macros_t aout_stdmac[];
-static int aout_set_info(enum geninfo type, char **val)
-{
- (void)type;
- (void)val;
- return 0;
-}
#endif /* OF_AOUT || OF_AOUTB */
#ifdef OF_AOUT
@@ -950,12 +936,12 @@ struct ofmt of_aout = {
&null_debug_form,
aout_stdmac,
aout_init,
- aout_set_info,
+ null_setinfo,
aout_out,
aout_deflabel,
aout_section_names,
aout_segbase,
- aout_directive,
+ null_directive,
aout_filename,
aout_cleanup
};
@@ -972,12 +958,12 @@ struct ofmt of_aoutb = {
&null_debug_form,
aout_stdmac,
aoutb_init,
- aout_set_info,
+ null_setinfo,
aout_out,
aout_deflabel,
aout_section_names,
aout_segbase,
- aout_directive,
+ null_directive,
aout_filename,
aout_cleanup
};
diff --git a/output/outas86.c b/output/outas86.c
index f21bd2e..efef143 100644
--- a/output/outas86.c
+++ b/output/outas86.c
@@ -617,14 +617,6 @@ static int32_t as86_segbase(int32_t segment)
return segment;
}
-static int as86_directive(char *directive, char *value, int pass)
-{
- (void)directive;
- (void)value;
- (void)pass;
- return 0;
-}
-
static void as86_filename(char *inname, char *outname, efunc error)
{
char *p;
@@ -640,21 +632,6 @@ static void as86_filename(char *inname, char *outname, efunc error)
extern macros_t as86_stdmac[];
-static int as86_set_info(enum geninfo type, char **val)
-{
- (void)type;
- (void)val;
- return 0;
-}
-void as86_linenumber(char *name, int32_t segment, int32_t offset, int is_main,
- int lineno)
-{
- (void)name;
- (void)segment;
- (void)offset;
- (void)is_main;
- (void)lineno;
-}
struct ofmt of_as86 = {
"Linux as86 (bin86 version 0.3) object files",
"as86",
@@ -663,12 +640,12 @@ struct ofmt of_as86 = {
&null_debug_form,
as86_stdmac,
as86_init,
- as86_set_info,
+ null_setinfo,
as86_out,
as86_deflabel,
as86_section_names,
as86_segbase,
- as86_directive,
+ null_directive,
as86_filename,
as86_cleanup
};
diff --git a/output/outbin.c b/output/outbin.c
index 5dc8e97..216397b 100644
--- a/output/outbin.c
+++ b/output/outbin.c
@@ -1286,10 +1286,11 @@ static int32_t bin_secname(char *name, int pass, int *bits)
return current_section;
}
-static int bin_directive(char *directive, char *args, int pass)
+static int bin_directive(enum directives directive, char *args, int pass)
{
- /* Handle ORG directive */
- if (!nasm_stricmp(directive, "org")) {
+ switch (directive) {
+ case D_ORG:
+ {
struct tokenval tokval;
uint64_t value;
expr *e;
@@ -1317,12 +1318,12 @@ static int bin_directive(char *directive, char *args, int pass)
" in ORG directive.");
return 1;
}
-
+ case D_MAP:
+ {
/* The 'map' directive allows the user to generate section
* and symbol information to stdout, stderr, or to a file. */
- else if (format_mode && !nasm_stricmp(directive, "map")) {
- char *p;
-
+ char *p;
+
if (pass != 1)
return 1;
args += strspn(args, " \t");
@@ -1365,7 +1366,9 @@ static int bin_directive(char *directive, char *args, int pass)
rf = stdout;
return 1;
}
- return 0;
+ default:
+ return 0;
+ }
}
static void bin_filename(char *inname, char *outname, efunc error)
diff --git a/output/outcoff.c b/output/outcoff.c
index 4c1213d..e7bd350 100644
--- a/output/outcoff.c
+++ b/output/outcoff.c
@@ -716,9 +716,11 @@ void BuildExportTable(void)
Exports = NULL;
}
-static int coff_directives(char *directive, char *value, int pass)
+static int coff_directives(enum directives directive, char *value, int pass)
{
- if (!strcmp(directive, "export")) {
+ switch (directive) {
+ case D_EXPORT:
+ {
char *q, *name;
if (pass == 2)
@@ -742,9 +744,15 @@ static int coff_directives(char *directive, char *value, int pass)
}
AddExport(name);
return 1;
- } else if (win32 && !strcmp(directive,"safeseh")) {
+ }
+ case D_SAFESEH:
+ {
static int sxseg=-1;
int i;
+
+ if (!win32) /* Only applicable for -f win32 */
+ return 0;
+
if (sxseg==-1)
{ for (i = 0; i < nsects; i++)
if (!strcmp(".sxdata",sects[i]->name))
@@ -793,7 +801,9 @@ static int coff_directives(char *directive, char *value, int pass)
}
return 1;
}
- return 0;
+ default:
+ return 0;
+ }
}
static void coff_write(void)
diff --git a/output/outdbg.c b/output/outdbg.c
index 497a48e..96c110b 100644
--- a/output/outdbg.c
+++ b/output/outdbg.c
@@ -179,10 +179,10 @@ static int32_t dbg_segbase(int32_t segment)
return segment;
}
-static int dbg_directive(char *directive, char *value, int pass)
+static int dbg_directive(enum directives directive, char *value, int pass)
{
fprintf(dbgf, "directive [%s] value [%s] (pass %d)\n",
- directive, value, pass);
+ directives[directive], value, pass);
return 1;
}
diff --git a/output/outelf32.c b/output/outelf32.c
index 99e53ef..a3a8c7a 100644
--- a/output/outelf32.c
+++ b/output/outelf32.c
@@ -1392,13 +1392,14 @@ static int32_t elf_segbase(int32_t segment)
return segment;
}
-static int elf_directive(char *directive, char *value, int pass)
+static int elf_directive(enum directives directive, char *value, int pass)
{
bool err;
int64_t n;
char *p;
- if (!strcmp(directive, "osabi")) {
+ switch (directive) {
+ case D_OSABI:
if (pass == 2)
return 1; /* ignore in pass 2 */
@@ -1425,9 +1426,10 @@ static int elf_directive(char *directive, char *value, int pass)
elf_abiver = n;
return 1;
+
+ default:
+ return 0;
}
-
- return 0;
}
static void elf_filename(char *inname, char *outname, efunc error)
diff --git a/output/outelf64.c b/output/outelf64.c
index b797eb8..cf6e378 100644
--- a/output/outelf64.c
+++ b/output/outelf64.c
@@ -1483,13 +1483,14 @@ static int32_t elf_segbase(int32_t segment)
return segment;
}
-static int elf_directive(char *directive, char *value, int pass)
+static int elf_directive(enum directives directive, char *value, int pass)
{
bool err;
int64_t n;
char *p;
- if (!strcmp(directive, "osabi")) {
+ switch (directive) {
+ case D_OSABI:
if (pass == 2)
return 1; /* ignore in pass 2 */
@@ -1516,9 +1517,10 @@ static int elf_directive(char *directive, char *value, int pass)
elf_abiver = n;
return 1;
+
+ default:
+ return 0;
}
-
- return 0;
}
static void elf_filename(char *inname, char *outname, efunc error)
diff --git a/output/outieee.c b/output/outieee.c
index 003e4d0..534e561 100644
--- a/output/outieee.c
+++ b/output/outieee.c
@@ -835,16 +835,20 @@ static int32_t ieee_segment(char *name, int pass, int *bits)
/*
* directives supported
*/
-static int ieee_directive(char *directive, char *value, int pass)
+static int ieee_directive(enum directives directive, char *value, int pass)
{
(void)value;
(void)pass;
- if (!strcmp(directive, "uppercase")) {
+
+ switch (directive) {
+ case D_UPPERCASE:
ieee_uppercase = true;
return 1;
+
+ default:
+ return 0;
}
- return 0;
}
/*
diff --git a/output/outlib.h b/output/outlib.h
index 964da5c..4089a6a 100644
--- a/output/outlib.h
+++ b/output/outlib.h
@@ -38,6 +38,10 @@
uint64_t realsize(enum out_type type, uint64_t size);
+/* Do-nothing versions of some output routines */
+int null_setinfo(enum geninfo type, char **string);
+int null_directive(enum directives directive, char *value, int pass);
+
/* Do-nothing versions of all the debug routines */
struct ofmt;
void null_debug_init(struct ofmt *of, void *id, FILE * fp, efunc error);
diff --git a/output/outmacho32.c b/output/outmacho32.c
index 0203f0d..3a2e59c 100644
--- a/output/outmacho32.c
+++ b/output/outmacho32.c
@@ -357,13 +357,6 @@ static void macho_init(FILE * fp, efunc errfunc, ldfunc ldef,
strslen = 1;
}
-static int macho_setinfo(enum geninfo type, char **val)
-{
- (void)type;
- (void)val;
- return 0;
-}
-
static void sect_write(struct section *sect,
const uint8_t *data, uint32_t len)
{
@@ -720,14 +713,6 @@ static int32_t macho_segbase(int32_t section)
return section;
}
-static int macho_directive(char *directive, char *value, int pass)
-{
- (void)directive;
- (void)value;
- (void)pass;
- return 0;
-}
-
static void macho_filename(char *inname, char *outname, efunc error)
{
standard_extension(inname, outname, ".o", error);
@@ -1340,12 +1325,12 @@ struct ofmt of_macho32 = {
&null_debug_form,
macho_stdmac,
macho_init,
- macho_setinfo,
+ null_setinfo,
macho_output,
macho_symdef,
macho_section,
macho_segbase,
- macho_directive,
+ null_directive,
macho_filename,
macho_cleanup
};
@@ -1358,12 +1343,12 @@ struct ofmt of_macho = {
&null_debug_form,
macho_stdmac,
macho_init,
- macho_setinfo,
+ null_setinfo,
macho_output,
macho_symdef,
macho_section,
macho_segbase,
- macho_directive,
+ null_directive,
macho_filename,
macho_cleanup
};
diff --git a/output/outmacho64.c b/output/outmacho64.c
index 659cbc4..d3f5a8e 100644
--- a/output/outmacho64.c
+++ b/output/outmacho64.c
@@ -390,13 +390,6 @@ static void macho_init(FILE * fp, efunc errfunc, ldfunc ldef,
ldef("..gotpcrel", macho_gotpcrel_sect, 0L, NULL, false, false, &of_macho64, error);
}
-static int macho_setinfo(enum geninfo type, char **val)
-{
- (void)type;
- (void)val;
- return 0;
-}
-
static void sect_write(struct section *sect,
const uint8_t *data, uint32_t len)
{
@@ -867,14 +860,6 @@ static int32_t macho_segbase(int32_t section)
return section;
}
-static int macho_directive(char *directive, char *value, int pass)
-{
- (void)directive;
- (void)value;
- (void)pass;
- return 0;
-}
-
static void macho_filename(char *inname, char *outname, efunc error)
{
standard_extension(inname, outname, ".o", error);
@@ -1509,12 +1494,12 @@ struct ofmt of_macho64 = {
&null_debug_form,
macho_stdmac,
macho_init,
- macho_setinfo,
+ null_setinfo,
macho_output,
macho_symdef,
macho_section,
macho_segbase,
- macho_directive,
+ null_directive,
macho_filename,
macho_cleanup
};
diff --git a/output/outobj.c b/output/outobj.c
index 73bec3c..80b5492 100644
--- a/output/outobj.c
+++ b/output/outobj.c
@@ -633,7 +633,7 @@ static struct Segment *current_seg;
static int32_t obj_segment(char *, int, int *);
static void obj_write_file(int debuginfo);
-static int obj_directive(char *, char *, int);
+static int obj_directive(enum directives, char *, int);
static void obj_init(FILE * fp, efunc errfunc, ldfunc ldef, evalfunc eval)
{
@@ -1417,7 +1417,7 @@ static int32_t obj_segment(char *name, int pass, int *bits)
if (!strcmp(grp->name, "FLAT"))
break;
if (!grp) {
- obj_directive("group", "FLAT", 1);
+ obj_directive(D_GROUP, "FLAT", 1);
for (grp = grphead; grp; grp = grp->next)
if (!strcmp(grp->name, "FLAT"))
break;
@@ -1538,9 +1538,11 @@ static int32_t obj_segment(char *name, int pass, int *bits)
}
}
-static int obj_directive(char *directive, char *value, int pass)
+static int obj_directive(enum directives directive, char *value, int pass)
{
- if (!strcmp(directive, "group")) {
+ switch (directive) {
+ case D_GROUP:
+ {
char *p, *q, *v;
if (pass == 1) {
struct Group *grp;
@@ -1650,11 +1652,12 @@ static int obj_directive(char *directive, char *value, int pass)
}
return 1;
}
- if (!strcmp(directive, "uppercase")) {
+ case D_UPPERCASE:
obj_uppercase = true;
return 1;
- }
- if (!strcmp(directive, "import")) {
+
+ case D_IMPORT:
+ {
char *q, *extname, *libname, *impname;
if (pass == 2)
@@ -1700,7 +1703,8 @@ static int obj_directive(char *directive, char *value, int pass)
return 1;
}
- if (!strcmp(directive, "export")) {
+ case D_EXPORT:
+ {
char *q, *extname, *intname, *v;
struct ExpDef *export;
int flags = 0;
@@ -1777,7 +1781,9 @@ static int obj_directive(char *directive, char *value, int pass)
return 1;
}
- return 0;
+ default:
+ return 0;
+ }
}
static int32_t obj_segbase(int32_t segment)
diff --git a/output/outrdf2.c b/output/outrdf2.c
index 84a565d..dd80438 100644
--- a/output/outrdf2.c
+++ b/output/outrdf2.c
@@ -733,17 +733,17 @@ static int32_t rdf2_segbase(int32_t segment)
/*
* Handle RDOFF2 specific directives
*/
-static int rdf2_directive(char *directive, char *value, int pass)
+static int rdf2_directive(enum directives directive, char *value, int pass)
{
- int n;
-
- /* Check if the name length is OK */
- if ((n = strlen(value)) >= MODLIB_NAME_MAX) {
- error(ERR_NONFATAL, "name size exceeds %d bytes", MODLIB_NAME_MAX);
- return 0;
- }
-
- if (!strcmp(directive, "library")) {
+ size_t n;
+
+ switch (directive) {
+ case D_LIBRARY:
+ n = strlen(value);
+ if (n >= MODLIB_NAME_MAX) {
+ error(ERR_NONFATAL, "name size exceeds %d bytes", MODLIB_NAME_MAX);
+ return 1;
+ }
if (pass == 1) {
struct DLLRec r;
r.type = RDFREC_DLL;
@@ -752,9 +752,12 @@ static int rdf2_directive(char *directive, char *value, int pass)
write_dll_rec(&r);
}
return 1;
- }
-
- if (!strcmp(directive, "module")) {
+
+ case D_MODULE:
+ if ((n = strlen(value)) >= MODLIB_NAME_MAX) {
+ error(ERR_NONFATAL, "name size exceeds %d bytes", MODLIB_NAME_MAX);
+ return 1;
+ }
if (pass == 1) {
struct ModRec r;
r.type = RDFREC_MODNAME;
@@ -763,9 +766,10 @@ static int rdf2_directive(char *directive, char *value, int pass)
write_modname_rec(&r);
}
return 1;
- }
- return 0;
+ default:
+ return 0;
+ }
}
static void rdf2_filename(char *inname, char *outname, efunc error)