backend: move wrapper for legacy output functions to a library routine

Move the wrapper for legacy output into a library routine so the
backends can be ported one at a time.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
This commit is contained in:
H. Peter Anvin 2016-09-24 09:46:47 -07:00
parent 04445364fc
commit fa803abc61
19 changed files with 168 additions and 69 deletions

View File

@ -99,8 +99,8 @@ NASM = asm/nasm.$(O) \
\
macros/macros.$(O) \
\
output/outform.$(O) output/outlib.$(O) output/nulldbg.$(O) \
output/nullout.$(O) \
output/outform.$(O) output/outlib.$(O) output/legacy.$(O) \
output/nulldbg.$(O) output/nullout.$(O) \
output/outbin.$(O) output/outaout.$(O) output/outcoff.$(O) \
output/outelf.$(O) \
output/outobj.$(O) output/outas86.$(O) output/outrdf2.$(O) \
@ -511,6 +511,10 @@ output/codeview.$(O): output/codeview.c asm/directiv.h asm/pptok.h \
include/nasm.h include/nasmint.h include/nasmlib.h include/opflags.h \
include/saa.h include/tables.h output/outlib.h output/pecoff.h version.h \
x86/insnsi.h x86/regs.h
output/legacy.$(O): output/legacy.c asm/directiv.h asm/pptok.h asm/preproc.h \
config.h include/compiler.h include/nasm.h include/nasmint.h \
include/nasmlib.h include/opflags.h include/tables.h x86/insnsi.h \
x86/regs.h
output/nulldbg.$(O): output/nulldbg.c asm/directiv.h asm/pptok.h \
asm/preproc.h config.h include/compiler.h include/nasm.h include/nasmint.h \
include/nasmlib.h include/opflags.h include/tables.h output/outlib.h \
@ -541,7 +545,7 @@ output/outcoff.$(O): output/outcoff.c asm/directiv.h asm/eval.h asm/pptok.h \
output/outdbg.$(O): output/outdbg.c asm/directiv.h asm/pptok.h asm/preproc.h \
config.h include/compiler.h include/nasm.h include/nasmint.h \
include/nasmlib.h include/opflags.h include/tables.h output/outform.h \
x86/insnsi.h x86/regs.h
output/outlib.h x86/insnsi.h x86/regs.h
output/outelf.$(O): output/outelf.c asm/directiv.h asm/eval.h asm/pptok.h \
asm/preproc.h asm/stdscan.h config.h include/compiler.h include/nasm.h \
include/nasmint.h include/nasmlib.h include/opflags.h include/raa.h \

View File

@ -63,8 +63,8 @@ NASM = asm/nasm.$(O) \
\
macros/macros.$(O) \
\
output/outform.$(O) output/outlib.$(O) output/nulldbg.$(O) \
output/nullout.$(O) \
output/outform.$(O) output/outlib.$(O) output/legacy.$(O) \
output/nulldbg.$(O) output/nullout.$(O) \
output/outbin.$(O) output/outaout.$(O) output/outcoff.$(O) \
output/outelf.$(O) \
output/outobj.$(O) output/outas86.$(O) output/outrdf2.$(O) \
@ -395,6 +395,9 @@ output/codeview.$(O): output/codeview.c asm/directiv.h asm/pptok.h \
include/nasm.h include/nasmint.h include/nasmlib.h include/opflags.h \
include/saa.h include/tables.h output/outlib.h output/pecoff.h version.h \
x86/insnsi.h x86/regs.h
output/legacy.$(O): output/legacy.c asm/directiv.h asm/pptok.h asm/preproc.h \
include/compiler.h include/nasm.h include/nasmint.h include/nasmlib.h \
include/opflags.h include/tables.h x86/insnsi.h x86/regs.h
output/nulldbg.$(O): output/nulldbg.c asm/directiv.h asm/pptok.h \
asm/preproc.h include/compiler.h include/nasm.h include/nasmint.h \
include/nasmlib.h include/opflags.h include/tables.h output/outlib.h \
@ -424,7 +427,8 @@ output/outcoff.$(O): output/outcoff.c asm/directiv.h asm/eval.h asm/pptok.h \
x86/insnsi.h x86/regs.h
output/outdbg.$(O): output/outdbg.c asm/directiv.h asm/pptok.h asm/preproc.h \
include/compiler.h include/nasm.h include/nasmint.h include/nasmlib.h \
include/opflags.h include/tables.h output/outform.h x86/insnsi.h x86/regs.h
include/opflags.h include/tables.h output/outform.h output/outlib.h \
x86/insnsi.h x86/regs.h
output/outelf.$(O): output/outelf.c asm/directiv.h asm/eval.h asm/pptok.h \
asm/preproc.h asm/stdscan.h include/compiler.h include/nasm.h \
include/nasmint.h include/nasmlib.h include/opflags.h include/raa.h \

View File

@ -44,8 +44,8 @@ NASM = nasm.o \
\
macros.o \
\
outform.o outlib.o nulldbg.o \
nullout.o \
outform.o outlib.o legacy.o \
nulldbg.o nullout.o \
outbin.o outaout.o outcoff.o \
outelf.o \
outobj.o outas86.o outrdf2.o \
@ -226,6 +226,8 @@ zerobuf.o: zerobuf.c config.h compiler.h nasmint.h nasmlib.h
codeview.o: codeview.c directiv.h pptok.h preproc.h config.h compiler.h \
hashtbl.h md5.h nasm.h nasmint.h nasmlib.h opflags.h saa.h tables.h \
outlib.h pecoff.h version.h insnsi.h regs.h
legacy.o: legacy.c directiv.h pptok.h preproc.h config.h compiler.h nasm.h \
nasmint.h nasmlib.h opflags.h tables.h insnsi.h regs.h
nulldbg.o: nulldbg.c directiv.h pptok.h preproc.h config.h compiler.h nasm.h \
nasmint.h nasmlib.h opflags.h tables.h outlib.h insnsi.h regs.h
nullout.o: nullout.c directiv.h pptok.h preproc.h config.h compiler.h nasm.h \
@ -243,7 +245,7 @@ outcoff.o: outcoff.c directiv.h eval.h pptok.h preproc.h config.h compiler.h \
nasm.h nasmint.h nasmlib.h opflags.h raa.h saa.h tables.h outform.h \
outlib.h pecoff.h insnsi.h regs.h
outdbg.o: outdbg.c directiv.h pptok.h preproc.h config.h compiler.h nasm.h \
nasmint.h nasmlib.h opflags.h tables.h outform.h insnsi.h regs.h
nasmint.h nasmlib.h opflags.h tables.h outform.h outlib.h insnsi.h regs.h
outelf.o: outelf.c directiv.h eval.h pptok.h preproc.h stdscan.h config.h \
compiler.h nasm.h nasmint.h nasmlib.h opflags.h raa.h rbtree.h saa.h \
tables.h ver.h dwarf.h elf.h outelf.h outform.h outlib.h stabs.h insnsi.h \

View File

@ -60,8 +60,8 @@ NASM = asm/nasm.$(O) &
&
macros/macros.$(O) &
&
output/outform.$(O) output/outlib.$(O) output/nulldbg.$(O) &
output/nullout.$(O) &
output/outform.$(O) output/outlib.$(O) output/legacy.$(O) &
output/nulldbg.$(O) output/nullout.$(O) &
output/outbin.$(O) output/outaout.$(O) output/outcoff.$(O) &
output/outelf.$(O) &
output/outobj.$(O) output/outas86.$(O) output/outrdf2.$(O) &
@ -422,6 +422,10 @@ output/codeview.$(O): output/codeview.c asm/directiv.h asm/pptok.h &
include/nasm.h include/nasmint.h include/nasmlib.h include/opflags.h &
include/saa.h include/tables.h output/outlib.h output/pecoff.h version.h &
x86/insnsi.h x86/regs.h
output/legacy.$(O): output/legacy.c asm/directiv.h asm/pptok.h asm/preproc.h &
config.h include/compiler.h include/nasm.h include/nasmint.h &
include/nasmlib.h include/opflags.h include/tables.h x86/insnsi.h &
x86/regs.h
output/nulldbg.$(O): output/nulldbg.c asm/directiv.h asm/pptok.h &
asm/preproc.h config.h include/compiler.h include/nasm.h include/nasmint.h &
include/nasmlib.h include/opflags.h include/tables.h output/outlib.h &
@ -452,7 +456,7 @@ output/outcoff.$(O): output/outcoff.c asm/directiv.h asm/eval.h asm/pptok.h &
output/outdbg.$(O): output/outdbg.c asm/directiv.h asm/pptok.h asm/preproc.h &
config.h include/compiler.h include/nasm.h include/nasmint.h &
include/nasmlib.h include/opflags.h include/tables.h output/outform.h &
x86/insnsi.h x86/regs.h
output/outlib.h x86/insnsi.h x86/regs.h
output/outelf.$(O): output/outelf.c asm/directiv.h asm/eval.h asm/pptok.h &
asm/preproc.h asm/stdscan.h config.h include/compiler.h include/nasm.h &
include/nasmint.h include/nasmlib.h include/opflags.h include/raa.h &

View File

@ -71,8 +71,8 @@ NASM = asm/nasm.$(O) \
\
macros/macros.$(O) \
\
output/outform.$(O) output/outlib.$(O) output/nulldbg.$(O) \
output/nullout.$(O) \
output/outform.$(O) output/outlib.$(O) output/legacy.$(O) \
output/nulldbg.$(O) output/nullout.$(O) \
output/outbin.$(O) output/outaout.$(O) output/outcoff.$(O) \
output/outelf.$(O) \
output/outobj.$(O) output/outas86.$(O) output/outrdf2.$(O) \
@ -387,6 +387,9 @@ output/codeview.$(O): output/codeview.c asm/directiv.h asm/pptok.h \
include/nasm.h include/nasmint.h include/nasmlib.h include/opflags.h \
include/saa.h include/tables.h output/outlib.h output/pecoff.h version.h \
x86/insnsi.h x86/regs.h
output/legacy.$(O): output/legacy.c asm/directiv.h asm/pptok.h asm/preproc.h \
include/compiler.h include/nasm.h include/nasmint.h include/nasmlib.h \
include/opflags.h include/tables.h x86/insnsi.h x86/regs.h
output/nulldbg.$(O): output/nulldbg.c asm/directiv.h asm/pptok.h \
asm/preproc.h include/compiler.h include/nasm.h include/nasmint.h \
include/nasmlib.h include/opflags.h include/tables.h output/outlib.h \
@ -416,7 +419,8 @@ output/outcoff.$(O): output/outcoff.c asm/directiv.h asm/eval.h asm/pptok.h \
x86/insnsi.h x86/regs.h
output/outdbg.$(O): output/outdbg.c asm/directiv.h asm/pptok.h asm/preproc.h \
include/compiler.h include/nasm.h include/nasmint.h include/nasmlib.h \
include/opflags.h include/tables.h output/outform.h x86/insnsi.h x86/regs.h
include/opflags.h include/tables.h output/outform.h output/outlib.h \
x86/insnsi.h x86/regs.h
output/outelf.$(O): output/outelf.c asm/directiv.h asm/eval.h asm/pptok.h \
asm/preproc.h asm/stdscan.h include/compiler.h include/nasm.h \
include/nasmint.h include/nasmlib.h include/opflags.h include/raa.h \

View File

@ -386,8 +386,7 @@ static void out(struct out_data *data)
"%d-bit unsigned relocation zero-extended from %d bits\n",
asize << 3, ofmt->maxbits);
data->size = amax;
ofmt->output(data->segment, data->data, data->type,
data->size, data->tsegment, data->twrt);
ofmt->output(data);
data->insoffs += amax;
data->offset += amax;
data->size = size = asize - amax;
@ -396,54 +395,7 @@ static void out(struct out_data *data)
data->type = OUT_RAWDATA;
}
/* Hack until backend change */
switch (data->type) {
case OUT_RELADDR:
switch (data->size) {
case 1:
data->type = OUT_REL1ADR;
break;
case 2:
data->type = OUT_REL2ADR;
break;
case 4:
data->type = OUT_REL4ADR;
break;
case 8:
data->type = OUT_REL8ADR;
break;
default:
panic();
break;
}
xdata.q = data->toffset;
data->data = xdata.b;
data->size = data->inslen - data->insoffs;
break;
case OUT_SEGMENT:
data->type = OUT_ADDRESS;
/* fall through */
case OUT_ADDRESS:
xdata.q = data->toffset;
data->data = xdata.b;
data->size = (data->sign == OUT_SIGNED) ? -data->size : data->size;
break;
case OUT_RAWDATA:
case OUT_RESERVE:
data->tsegment = data->twrt = NO_SEG;
break;
default:
panic();
break;
}
ofmt->output(data->segment, data->data, data->type,
data->size, data->tsegment, data->twrt);
ofmt->output(data);
data->offset += size;
data->insoffs += size;
}

View File

@ -748,6 +748,13 @@ struct ofmt {
*/
int (*setinfo)(enum geninfo type, char **string);
/*
* This is the modern output function, which gets passed
* a struct out_data with much more information. See the
* definition of struct out_data.
*/
void (*output)(const struct out_data *data);
/*
* This procedure is called by assemble() to write actual
* generated code or data to the object file. Typically it
@ -756,10 +763,15 @@ struct ofmt {
*
* The `type' argument specifies the type of output data, and
* usually the size as well: its contents are described below.
*
* This is used for backends which have not yet been ported to
* the new interface, and should be NULL on ported backends.
* To use this entry point, set the output pointer to
* nasm_do_legacy_output.
*/
void (*output)(int32_t segto, const void *data,
enum out_type type, uint64_t size,
int32_t segment, int32_t wrt);
void (*legacy_output)(int32_t segto, const void *data,
enum out_type type, uint64_t size,
int32_t segment, int32_t wrt);
/*
* This procedure is called once for every symbol defined in

95
output/legacy.c Normal file
View File

@ -0,0 +1,95 @@
/* ----------------------------------------------------------------------- *
*
* Copyright 2016 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.
*
* ----------------------------------------------------------------------- */
/*
* output/legacy.c
*
* Mangle a struct out_data to match the rather bizarre legacy
* backend interface.
*/
#include "nasm.h"
void nasm_do_legacy_output(const struct out_data *data)
{
const void *dptr = data->data;
enum out_type type = data->type;
int32_t tsegment = data->tsegment;
int32_t twrt = data->twrt;
uint64_t size = data->size;
switch (data->type) {
case OUT_RELADDR:
switch (data->size) {
case 1:
type = OUT_REL1ADR;
break;
case 2:
type = OUT_REL2ADR;
break;
case 4:
type = OUT_REL4ADR;
break;
case 8:
type = OUT_REL8ADR;
break;
default:
panic();
break;
}
dptr = &data->toffset;
size = data->inslen - data->insoffs;
break;
case OUT_SEGMENT:
type = OUT_ADDRESS;
/* fall through */
case OUT_ADDRESS:
dptr = &data->toffset;
size = (data->sign == OUT_SIGNED) ? -data->size : data->size;
break;
case OUT_RAWDATA:
case OUT_RESERVE:
tsegment = twrt = NO_SEG;
break;
default:
panic();
break;
}
ofmt->legacy_output(data->segment, dptr, type, size, tsegment, twrt);
}

View File

@ -915,6 +915,7 @@ const struct ofmt of_aout = {
aout_stdmac,
aout_init,
null_setinfo,
nasm_do_legacy_output,
aout_out,
aout_deflabel,
aout_section_names,
@ -939,6 +940,7 @@ const struct ofmt of_aoutb = {
aout_stdmac,
aoutb_init,
null_setinfo,
nasm_do_legacy_output,
aout_out,
aout_deflabel,
aout_section_names,

View File

@ -636,6 +636,7 @@ const struct ofmt of_as86 = {
as86_stdmac,
as86_init,
null_setinfo,
nasm_do_legacy_output,
as86_out,
as86_deflabel,
as86_section_names,

View File

@ -1662,6 +1662,7 @@ const struct ofmt of_bin = {
bin_stdmac,
bin_init,
bin_set_info,
nasm_do_legacy_output,
bin_out,
bin_deflabel,
bin_secname,
@ -1682,6 +1683,7 @@ const struct ofmt of_ith = {
bin_stdmac,
ith_init,
bin_set_info,
nasm_do_legacy_output,
bin_out,
bin_deflabel,
bin_secname,
@ -1702,6 +1704,7 @@ const struct ofmt of_srec = {
bin_stdmac,
srec_init,
bin_set_info,
nasm_do_legacy_output,
bin_out,
bin_deflabel,
bin_secname,

View File

@ -1176,6 +1176,7 @@ const struct ofmt of_coff = {
coff_stdmac,
coff_std_init,
coff_set_info,
nasm_do_legacy_output,
coff_out,
coff_deflabel,
coff_section_names,
@ -1204,6 +1205,7 @@ const struct ofmt of_win32 = {
coff_stdmac,
coff_win32_init,
coff_set_info,
nasm_do_legacy_output,
coff_out,
coff_deflabel,
coff_section_names,
@ -1230,6 +1232,7 @@ const struct ofmt of_win64 = {
coff_stdmac,
coff_win64_init,
coff_set_info,
nasm_do_legacy_output,
coff_out,
coff_deflabel,
coff_section_names,

View File

@ -46,6 +46,7 @@
#include "nasm.h"
#include "nasmlib.h"
#include "outform.h"
#include "outlib.h"
#ifdef OF_DBG
@ -268,6 +269,7 @@ const struct ofmt of_dbg = {
NULL,
dbg_init,
dbg_set_info,
nasm_do_legacy_output,
dbg_out,
dbg_deflabel,
dbg_section_names,

View File

@ -2262,6 +2262,7 @@ const struct ofmt of_elf32 = {
elf_stdmac,
elf_init,
elf_set_info,
nasm_do_legacy_output,
elf32_out,
elf_deflabel,
elf_section_names,
@ -2309,6 +2310,7 @@ const struct ofmt of_elf64 = {
elf_stdmac,
elf_init,
elf_set_info,
nasm_do_legacy_output,
elf64_out,
elf_deflabel,
elf_section_names,
@ -2356,6 +2358,7 @@ const struct ofmt of_elfx32 = {
elf_stdmac,
elf_init,
elf_set_info,
nasm_do_legacy_output,
elfx32_out,
elf_deflabel,
elf_section_names,

View File

@ -1522,6 +1522,7 @@ const struct ofmt of_ieee = {
NULL,
ieee_init,
ieee_set_info,
nasm_do_legacy_output,
ieee_out,
ieee_deflabel,
ieee_segment,

View File

@ -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.
*
@ -55,5 +55,8 @@ void null_debug_output(int type, void *param);
void null_debug_cleanup(void);
extern const struct dfmt * const null_debug_arr[2];
/* Wrapper for unported backends */
void nasm_do_legacy_output(const struct out_data *data);
#endif /* NASM_OUTLIB_H */

View File

@ -1627,6 +1627,7 @@ const struct ofmt of_macho32 = {
macho_stdmac,
macho32_init,
null_setinfo,
nasm_do_legacy_output,
macho_output,
macho_symdef,
macho_section,
@ -1674,6 +1675,7 @@ const struct ofmt of_macho64 = {
macho_stdmac,
macho64_init,
null_setinfo,
nasm_do_legacy_output,
macho_output,
macho_symdef,
macho_section,

View File

@ -2667,6 +2667,7 @@ const struct ofmt of_obj = {
obj_stdmac,
obj_init,
obj_set_info,
nasm_do_legacy_output,
obj_out,
obj_deflabel,
obj_segment,

View File

@ -782,6 +782,7 @@ const struct ofmt of_rdf2 = {
rdf2_stdmac,
rdf2_init,
rdf2_set_info,
nasm_do_legacy_output,
rdf2_out,
rdf2_deflabel,
rdf2_section_names,