Change nasmlist/ListGen to lfmt/struct lfmt

For consistency with ofmt/dfmt, change the listing structure
to "struct lfmt" and "lfmt" and move it to listing.h.

From master branch commit 8ac25aa02000889df94c3ea96bdda6375ddfa661

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
This commit is contained in:
H. Peter Anvin 2016-02-18 01:16:18 -08:00 committed by H. Peter Anvin
parent 335c4857ce
commit 172b840aa3
12 changed files with 126 additions and 125 deletions

View File

@ -316,8 +316,8 @@ alldeps: perlreq
# @path-separator: "/"
#-- Everything below is generated by mkdep.pl - do not edit --#
assemble.$(O): assemble.c assemble.h compiler.h config.h directiv.h disp8.h \
iflag.h iflaggen.h insns.h insnsi.h nasm.h nasmlib.h opflags.h pptok.h \
preproc.h regs.h tables.h tokens.h
iflag.h iflaggen.h insns.h insnsi.h listing.h nasm.h nasmlib.h opflags.h \
pptok.h preproc.h regs.h tables.h tokens.h
crc64.$(O): crc64.c compiler.h config.h hashtbl.h nasmlib.h
directiv.$(O): directiv.c compiler.h config.h directiv.h hashtbl.h insnsi.h \
nasm.h nasmlib.h opflags.h pptok.h preproc.h regs.h tables.h
@ -430,10 +430,10 @@ parser.$(O): parser.c compiler.h config.h directiv.h eval.h float.h iflag.h \
pptok.$(O): pptok.c compiler.h config.h hashtbl.h nasmlib.h pptok.h \
preproc.h
preproc-nop.$(O): preproc-nop.c compiler.h config.h directiv.h insnsi.h \
nasm.h nasmlib.h opflags.h pptok.h preproc.h regs.h tables.h
listing.h nasm.h nasmlib.h opflags.h pptok.h preproc.h regs.h tables.h
preproc.$(O): preproc.c compiler.h config.h directiv.h eval.h hashtbl.h \
insnsi.h nasm.h nasmlib.h opflags.h pptok.h preproc.h quote.h regs.h \
stdscan.h tables.h tokens.h
insnsi.h listing.h nasm.h nasmlib.h opflags.h pptok.h preproc.h quote.h \
regs.h stdscan.h tables.h tokens.h
quote.$(O): quote.c compiler.h config.h nasmlib.h quote.h
raa.$(O): raa.c compiler.h config.h nasmlib.h raa.h
rbtree.$(O): rbtree.c compiler.h config.h rbtree.h

View File

@ -226,8 +226,8 @@ everything: all doc rdf
# @exclude: "config.h"
#-- Everything below is generated by mkdep.pl - do not edit --#
assemble.$(O): assemble.c assemble.h compiler.h directiv.h disp8.h iflag.h \
iflaggen.h insns.h insnsi.h nasm.h nasmlib.h opflags.h pptok.h preproc.h \
regs.h tables.h tokens.h
iflaggen.h insns.h insnsi.h listing.h nasm.h nasmlib.h opflags.h pptok.h \
preproc.h regs.h tables.h tokens.h
crc64.$(O): crc64.c compiler.h hashtbl.h nasmlib.h
directiv.$(O): directiv.c compiler.h directiv.h hashtbl.h insnsi.h nasm.h \
nasmlib.h opflags.h pptok.h preproc.h regs.h tables.h
@ -332,11 +332,11 @@ parser.$(O): parser.c compiler.h directiv.h eval.h float.h iflag.h \
iflaggen.h insns.h insnsi.h nasm.h nasmlib.h opflags.h parser.h pptok.h \
preproc.h regs.h stdscan.h tables.h tokens.h
pptok.$(O): pptok.c compiler.h hashtbl.h nasmlib.h pptok.h preproc.h
preproc-nop.$(O): preproc-nop.c compiler.h directiv.h insnsi.h nasm.h \
nasmlib.h opflags.h pptok.h preproc.h regs.h tables.h
preproc-nop.$(O): preproc-nop.c compiler.h directiv.h insnsi.h listing.h \
nasm.h nasmlib.h opflags.h pptok.h preproc.h regs.h tables.h
preproc.$(O): preproc.c compiler.h directiv.h eval.h hashtbl.h insnsi.h \
nasm.h nasmlib.h opflags.h pptok.h preproc.h quote.h regs.h stdscan.h \
tables.h tokens.h
listing.h nasm.h nasmlib.h opflags.h pptok.h preproc.h quote.h regs.h \
stdscan.h tables.h tokens.h
quote.$(O): quote.c compiler.h nasmlib.h quote.h
raa.$(O): raa.c compiler.h nasmlib.h raa.h
rbtree.$(O): rbtree.c compiler.h rbtree.h

View File

@ -134,8 +134,8 @@ $(OBJDIR)/version.mak: $(PROOT)/version $(PROOT)/version.pl $(OBJDIR)
# @continuation: "\"
#-- Everything below is generated by mkdep.pl - do not edit --#
assemble.o: assemble.c assemble.h compiler.h config.h directiv.h disp8.h \
iflag.h iflaggen.h insns.h insnsi.h nasm.h nasmlib.h opflags.h pptok.h \
preproc.h regs.h tables.h tokens.h
iflag.h iflaggen.h insns.h insnsi.h listing.h nasm.h nasmlib.h opflags.h \
pptok.h preproc.h regs.h tables.h tokens.h
crc64.o: crc64.c compiler.h config.h hashtbl.h nasmlib.h
directiv.o: directiv.c compiler.h config.h directiv.h hashtbl.h insnsi.h \
nasm.h nasmlib.h opflags.h pptok.h preproc.h regs.h tables.h
@ -236,11 +236,11 @@ parser.o: parser.c compiler.h config.h directiv.h eval.h float.h iflag.h \
iflaggen.h insns.h insnsi.h nasm.h nasmlib.h opflags.h parser.h pptok.h \
preproc.h regs.h stdscan.h tables.h tokens.h
pptok.o: pptok.c compiler.h config.h hashtbl.h nasmlib.h pptok.h preproc.h
preproc-nop.o: preproc-nop.c compiler.h config.h directiv.h insnsi.h nasm.h \
nasmlib.h opflags.h pptok.h preproc.h regs.h tables.h
preproc-nop.o: preproc-nop.c compiler.h config.h directiv.h insnsi.h \
listing.h nasm.h nasmlib.h opflags.h pptok.h preproc.h regs.h tables.h
preproc.o: preproc.c compiler.h config.h directiv.h eval.h hashtbl.h \
insnsi.h nasm.h nasmlib.h opflags.h pptok.h preproc.h quote.h regs.h \
stdscan.h tables.h tokens.h
insnsi.h listing.h nasm.h nasmlib.h opflags.h pptok.h preproc.h quote.h \
regs.h stdscan.h tables.h tokens.h
quote.o: quote.c compiler.h config.h nasmlib.h quote.h
raa.o: raa.c compiler.h config.h nasmlib.h raa.h
rbtree.o: rbtree.c compiler.h config.h rbtree.h

View File

@ -271,8 +271,8 @@ alldeps: perlreq .SYMBOLIC
# @continuation: "&"
#-- Everything below is generated by mkdep.pl - do not edit --#
assemble.$(O): assemble.c assemble.h compiler.h config.h directiv.h disp8.h &
iflag.h iflaggen.h insns.h insnsi.h nasm.h nasmlib.h opflags.h pptok.h &
preproc.h regs.h tables.h tokens.h
iflag.h iflaggen.h insns.h insnsi.h listing.h nasm.h nasmlib.h opflags.h &
pptok.h preproc.h regs.h tables.h tokens.h
crc64.$(O): crc64.c compiler.h config.h hashtbl.h nasmlib.h
directiv.$(O): directiv.c compiler.h config.h directiv.h hashtbl.h insnsi.h &
nasm.h nasmlib.h opflags.h pptok.h preproc.h regs.h tables.h
@ -385,10 +385,10 @@ parser.$(O): parser.c compiler.h config.h directiv.h eval.h float.h iflag.h &
pptok.$(O): pptok.c compiler.h config.h hashtbl.h nasmlib.h pptok.h &
preproc.h
preproc-nop.$(O): preproc-nop.c compiler.h config.h directiv.h insnsi.h &
nasm.h nasmlib.h opflags.h pptok.h preproc.h regs.h tables.h
listing.h nasm.h nasmlib.h opflags.h pptok.h preproc.h regs.h tables.h
preproc.$(O): preproc.c compiler.h config.h directiv.h eval.h hashtbl.h &
insnsi.h nasm.h nasmlib.h opflags.h pptok.h preproc.h quote.h regs.h &
stdscan.h tables.h tokens.h
insnsi.h listing.h nasm.h nasmlib.h opflags.h pptok.h preproc.h quote.h &
regs.h stdscan.h tables.h tokens.h
quote.$(O): quote.c compiler.h config.h nasmlib.h quote.h
raa.$(O): raa.c compiler.h config.h nasmlib.h raa.h
rbtree.$(O): rbtree.c compiler.h config.h rbtree.h

View File

@ -240,8 +240,8 @@ everything: all doc rdf
# @continuation: "\"
#-- Everything below is generated by mkdep.pl - do not edit --#
assemble.$(O): assemble.c assemble.h compiler.h directiv.h disp8.h iflag.h \
iflaggen.h insns.h insnsi.h nasm.h nasmlib.h opflags.h pptok.h preproc.h \
regs.h tables.h tokens.h
iflaggen.h insns.h insnsi.h listing.h nasm.h nasmlib.h opflags.h pptok.h \
preproc.h regs.h tables.h tokens.h
crc64.$(O): crc64.c compiler.h hashtbl.h nasmlib.h
directiv.$(O): directiv.c compiler.h directiv.h hashtbl.h insnsi.h nasm.h \
nasmlib.h opflags.h pptok.h preproc.h regs.h tables.h
@ -346,11 +346,11 @@ parser.$(O): parser.c compiler.h directiv.h eval.h float.h iflag.h \
iflaggen.h insns.h insnsi.h nasm.h nasmlib.h opflags.h parser.h pptok.h \
preproc.h regs.h stdscan.h tables.h tokens.h
pptok.$(O): pptok.c compiler.h hashtbl.h nasmlib.h pptok.h preproc.h
preproc-nop.$(O): preproc-nop.c compiler.h directiv.h insnsi.h nasm.h \
nasmlib.h opflags.h pptok.h preproc.h regs.h tables.h
preproc-nop.$(O): preproc-nop.c compiler.h directiv.h insnsi.h listing.h \
nasm.h nasmlib.h opflags.h pptok.h preproc.h regs.h tables.h
preproc.$(O): preproc.c compiler.h directiv.h eval.h hashtbl.h insnsi.h \
nasm.h nasmlib.h opflags.h pptok.h preproc.h quote.h regs.h stdscan.h \
tables.h tokens.h
listing.h nasm.h nasmlib.h opflags.h pptok.h preproc.h quote.h regs.h \
stdscan.h tables.h tokens.h
quote.$(O): quote.c compiler.h nasmlib.h quote.h
raa.$(O): raa.c compiler.h nasmlib.h raa.h
rbtree.$(O): rbtree.c compiler.h rbtree.h

View File

@ -188,6 +188,7 @@
#include "insns.h"
#include "tables.h"
#include "disp8.h"
#include "listing.h"
enum match_result {
/*
@ -358,7 +359,7 @@ static void out(int64_t offset, int32_t segto, const void *data,
asize = 0; /* No longer an address */
}
nasmlist->output(offset, data, type, size);
lfmt->output(offset, data, type, size);
/*
* this call to src_get determines when we call the
@ -495,15 +496,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 nasmlist->output to give the offset to the
* Dummy call to lfmt->output to give the offset to the
* listing module.
*/
nasmlist->output(offset, NULL, OUT_RAWDATA, 0);
nasmlist->uplevel(LIST_TIMES);
lfmt->output(offset, NULL, OUT_RAWDATA, 0);
lfmt->uplevel(LIST_TIMES);
}
}
if (instruction->times > 1)
nasmlist->downlevel(LIST_TIMES);
lfmt->downlevel(LIST_TIMES);
return offset - start;
}
@ -534,11 +535,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 nasmlist->output to give the offset to the
* Dummy call to lfmt->output to give the offset to the
* listing module.
*/
nasmlist->output(offset, NULL, OUT_RAWDATA, 0);
nasmlist->uplevel(LIST_INCBIN);
lfmt->output(offset, NULL, OUT_RAWDATA, 0);
lfmt->uplevel(LIST_INCBIN);
while (t--) {
size_t l;
@ -564,15 +565,15 @@ int64_t assemble(int32_t segment, int64_t offset, int bits, iflag_t cp,
l -= m;
}
}
nasmlist->downlevel(LIST_INCBIN);
lfmt->downlevel(LIST_INCBIN);
if (instruction->times > 1) {
/*
* Dummy call to nasmlist->output to give the offset to the
* Dummy call to lfmt->output to give the offset to the
* listing module.
*/
nasmlist->output(offset, NULL, OUT_RAWDATA, 0);
nasmlist->uplevel(LIST_TIMES);
nasmlist->downlevel(LIST_TIMES);
lfmt->output(offset, NULL, OUT_RAWDATA, 0);
lfmt->uplevel(LIST_TIMES);
lfmt->downlevel(LIST_TIMES);
}
fclose(fp);
return instruction->times * len;
@ -710,15 +711,15 @@ 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 nasmlist->output to give the offset to the
* Dummy call to lfmt->output to give the offset to the
* listing module.
*/
nasmlist->output(offset, NULL, OUT_RAWDATA, 0);
nasmlist->uplevel(LIST_TIMES);
lfmt->output(offset, NULL, OUT_RAWDATA, 0);
lfmt->uplevel(LIST_TIMES);
}
}
if (instruction->times > 1)
nasmlist->downlevel(LIST_TIMES);
lfmt->downlevel(LIST_TIMES);
return offset - start;
} else {
/* No match */

View File

@ -326,7 +326,7 @@ static void list_error(int severity, const char *pfx, const char *msg)
}
static const ListGen nasm_list = {
static const struct lfmt nasm_list = {
list_init,
list_cleanup,
list_output,
@ -336,4 +336,4 @@ static const ListGen nasm_list = {
list_error
};
const ListGen *nasmlist = &nasm_list;
const struct lfmt *lfmt = &nasm_list;

View File

@ -38,7 +38,71 @@
#ifndef NASM_LISTING_H
#define NASM_LISTING_H
extern const ListGen *nasmlist;
/*
* List-file generators should look like this:
*/
struct lfmt {
/*
* Called to initialize the listing file generator. Before this
* is called, the other routines will silently do nothing when
* called. The `char *' parameter is the file name to write the
* listing to.
*/
void (*init)(const char *fname);
/*
* Called to clear stuff up and close the listing file.
*/
void (*cleanup)(void);
/*
* Called to output binary data. Parameters are: the offset;
* the data; the data type. Data types are similar to the
* output-format interface, only OUT_ADDRESS will _always_ be
* displayed as if it's relocatable, so ensure that any non-
* relocatable address has been converted to OUT_RAWDATA by
* then. Note that OUT_RAWDATA,0 is a valid data type, and is a
* dummy call used to give the listing generator an offset to
* work with when doing things like uplevel(LIST_TIMES) or
* uplevel(LIST_INCBIN).
*/
void (*output)(int32_t offset, const void *data, enum out_type type, uint64_t size);
/*
* Called to send a text line to the listing generator. The
* `int' parameter is LIST_READ or LIST_MACRO depending on
* whether the line came directly from an input file or is the
* result of a multi-line macro expansion.
*/
void (*line)(int type, char *line);
/*
* Called to change one of the various levelled mechanisms in
* the listing generator. LIST_INCLUDE and LIST_MACRO can be
* used to increase the nesting level of include files and
* macro expansions; LIST_TIMES and LIST_INCBIN switch on the
* two binary-output-suppression mechanisms for large-scale
* pseudo-instructions.
*
* LIST_MACRO_NOLIST is synonymous with LIST_MACRO except that
* it indicates the beginning of the expansion of a `nolist'
* macro, so anything under that level won't be expanded unless
* it includes another file.
*/
void (*uplevel)(int type);
/*
* Reverse the effects of uplevel.
*/
void (*downlevel)(int type);
/*
* Called on a warning or error, with the error message.
*/
void (*error)(int severity, const char *pfx, const char *msg);
};
extern const struct lfmt *lfmt;
extern bool user_nolist;
#endif

6
nasm.c
View File

@ -1220,7 +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) {
nasmlist->init(listname);
lfmt->init(listname);
}
in_abs_seg = false;
global_offset_changed = 0; /* set by redefine_label */
@ -1800,7 +1800,7 @@ static void assemble_file(char *fname, StrList **depend_ptr)
}
preproc->cleanup(0);
nasmlist->cleanup();
lfmt->cleanup();
if (!terminate_after_phase && opt_verbose_info) {
/* -On and -Ov switches */
fprintf(stdout, "info: assembly required 1+%d+1 passes\n", passn-3);
@ -2002,7 +2002,7 @@ static void nasm_verror_common(int severity, const char *fmt, va_list args)
* preprocessor warnings in the list file
*/
if ((severity & ERR_MASK) >= ERR_WARNING)
nasmlist->error(severity, pfx, msg);
lfmt->error(severity, pfx, msg);
if (severity & ERR_USAGE)
want_usage = true;

66
nasm.h
View File

@ -126,72 +126,6 @@ typedef void (*ldfunc)(char *label, int32_t segment, int64_t offset,
void define_label(char *label, int32_t segment, int64_t offset,
char *special, bool is_norm, bool isextrn);
/*
* List-file generators should look like this:
*/
typedef struct {
/*
* Called to initialize the listing file generator. Before this
* is called, the other routines will silently do nothing when
* called. The `char *' parameter is the file name to write the
* listing to.
*/
void (*init)(const char *fname);
/*
* Called to clear stuff up and close the listing file.
*/
void (*cleanup)(void);
/*
* Called to output binary data. Parameters are: the offset;
* the data; the data type. Data types are similar to the
* output-format interface, only OUT_ADDRESS will _always_ be
* displayed as if it's relocatable, so ensure that any non-
* relocatable address has been converted to OUT_RAWDATA by
* then. Note that OUT_RAWDATA,0 is a valid data type, and is a
* dummy call used to give the listing generator an offset to
* work with when doing things like uplevel(LIST_TIMES) or
* uplevel(LIST_INCBIN).
*/
void (*output)(int32_t offset, const void *data, enum out_type type, uint64_t size);
/*
* Called to send a text line to the listing generator. The
* `int' parameter is LIST_READ or LIST_MACRO depending on
* whether the line came directly from an input file or is the
* result of a multi-line macro expansion.
*/
void (*line)(int type, char *line);
/*
* Called to change one of the various levelled mechanisms in
* the listing generator. LIST_INCLUDE and LIST_MACRO can be
* used to increase the nesting level of include files and
* macro expansions; LIST_TIMES and LIST_INCBIN switch on the
* two binary-output-suppression mechanisms for large-scale
* pseudo-instructions.
*
* LIST_MACRO_NOLIST is synonymous with LIST_MACRO except that
* it indicates the beginning of the expansion of a `nolist'
* macro, so anything under that level won't be expanded unless
* it includes another file.
*/
void (*uplevel)(int type);
/*
* Reverse the effects of uplevel.
*/
void (*downlevel)(int type);
/*
* Called on a warning or error, with the error message.
*/
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.

View File

@ -51,6 +51,7 @@
#include "nasm.h"
#include "nasmlib.h"
#include "preproc.h"
#include "listing.h"
#define BUF_DELTA 512
@ -130,7 +131,7 @@ static char *nop_getline(void)
break;
}
nasmlist->line(LIST_READ, buffer);
lfmt->line(LIST_READ, buffer);
return buffer;
}

View File

@ -80,6 +80,7 @@
#include "eval.h"
#include "tokens.h"
#include "tables.h"
#include "listing.h"
typedef struct SMacro SMacro;
typedef struct MMacro MMacro;
@ -878,7 +879,7 @@ static char *read_line(void)
*/
buffer[strcspn(buffer, "\032")] = '\0';
nasmlist->line(LIST_READ, buffer);
lfmt->line(LIST_READ, buffer);
return buffer;
}
@ -2506,7 +2507,7 @@ static int do_directive(Token * tline)
inc->expansion = NULL;
inc->mstk = NULL;
istk = inc;
nasmlist->uplevel(LIST_INCLUDE);
lfmt->uplevel(LIST_INCLUDE);
}
free_tlist(origline);
return DIRECTIVE_FOUND;
@ -2962,7 +2963,7 @@ issue_error:
istk->mstk = defining;
nasmlist->uplevel(defining->nolist ? LIST_MACRO_NOLIST : LIST_MACRO);
lfmt->uplevel(defining->nolist ? LIST_MACRO_NOLIST : LIST_MACRO);
tmp_defining = defining;
defining = defining->rep_nest;
free_tlist(origline);
@ -4769,7 +4770,7 @@ static int expand_mmacro(Token * tline)
}
}
nasmlist->uplevel(m->nolist ? LIST_MACRO_NOLIST : LIST_MACRO);
lfmt->uplevel(m->nolist ? LIST_MACRO_NOLIST : LIST_MACRO);
return 1;
}
@ -4971,7 +4972,7 @@ static char *pp_getline(void)
}
istk->expansion = l->next;
nasm_free(l);
nasmlist->downlevel(LIST_MACRO);
lfmt->downlevel(LIST_MACRO);
}
}
while (1) { /* until we get a line we can use */
@ -4985,7 +4986,7 @@ static char *pp_getline(void)
istk->expansion = l->next;
nasm_free(l);
p = detoken(tline, false);
nasmlist->line(LIST_MACRO, p);
lfmt->line(LIST_MACRO, p);
nasm_free(p);
break;
}
@ -5013,7 +5014,7 @@ static char *pp_getline(void)
nasm_free(src_set_fname(nasm_strdup(i->fname)));
}
istk = i->next;
nasmlist->downlevel(LIST_INCLUDE);
lfmt->downlevel(LIST_INCLUDE);
nasm_free(i);
if (!istk) {
line = NULL;