0
0
mirror of https://github.com/netwide-assembler/nasm.git synced 2025-07-24 10:25:42 -04:00

preproc: drop preproc_ops

There is only one preprocessor now, so drop the indirection through
preproc_ops.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
This commit is contained in:
H. Peter Anvin (Intel) 2020-07-10 19:23:22 -07:00
parent 84cf342e38
commit 10c9aa37a4
4 changed files with 90 additions and 113 deletions

View File

@ -143,7 +143,6 @@ static struct RAA *offsets;
static struct SAA *forwrefs; /* keep track of forward references */ static struct SAA *forwrefs; /* keep track of forward references */
static const struct forwrefinfo *forwref; static const struct forwrefinfo *forwref;
#define preproc (&preproc_nasm) /* Hack */
static struct strlist *include_path; static struct strlist *include_path;
static enum preproc_opt ppopt; static enum preproc_opt ppopt;
@ -304,29 +303,29 @@ static void define_macros(void)
if (oct->have_local) { if (oct->have_local) {
strftime(temp, sizeof temp, "__?DATE?__=\"%Y-%m-%d\"", &oct->local); strftime(temp, sizeof temp, "__?DATE?__=\"%Y-%m-%d\"", &oct->local);
preproc->pre_define(temp); pp_pre_define(temp);
strftime(temp, sizeof temp, "__?DATE_NUM?__=%Y%m%d", &oct->local); strftime(temp, sizeof temp, "__?DATE_NUM?__=%Y%m%d", &oct->local);
preproc->pre_define(temp); pp_pre_define(temp);
strftime(temp, sizeof temp, "__?TIME?__=\"%H:%M:%S\"", &oct->local); strftime(temp, sizeof temp, "__?TIME?__=\"%H:%M:%S\"", &oct->local);
preproc->pre_define(temp); pp_pre_define(temp);
strftime(temp, sizeof temp, "__?TIME_NUM?__=%H%M%S", &oct->local); strftime(temp, sizeof temp, "__?TIME_NUM?__=%H%M%S", &oct->local);
preproc->pre_define(temp); pp_pre_define(temp);
} }
if (oct->have_gm) { if (oct->have_gm) {
strftime(temp, sizeof temp, "__?UTC_DATE?__=\"%Y-%m-%d\"", &oct->gm); strftime(temp, sizeof temp, "__?UTC_DATE?__=\"%Y-%m-%d\"", &oct->gm);
preproc->pre_define(temp); pp_pre_define(temp);
strftime(temp, sizeof temp, "__?UTC_DATE_NUM?__=%Y%m%d", &oct->gm); strftime(temp, sizeof temp, "__?UTC_DATE_NUM?__=%Y%m%d", &oct->gm);
preproc->pre_define(temp); pp_pre_define(temp);
strftime(temp, sizeof temp, "__?UTC_TIME?__=\"%H:%M:%S\"", &oct->gm); strftime(temp, sizeof temp, "__?UTC_TIME?__=\"%H:%M:%S\"", &oct->gm);
preproc->pre_define(temp); pp_pre_define(temp);
strftime(temp, sizeof temp, "__?UTC_TIME_NUM?__=%H%M%S", &oct->gm); strftime(temp, sizeof temp, "__?UTC_TIME_NUM?__=%H%M%S", &oct->gm);
preproc->pre_define(temp); pp_pre_define(temp);
} }
if (oct->have_posix) { if (oct->have_posix) {
snprintf(temp, sizeof temp, "__?POSIX_TIME?__=%"PRId64, oct->posix); snprintf(temp, sizeof temp, "__?POSIX_TIME?__=%"PRId64, oct->posix);
preproc->pre_define(temp); pp_pre_define(temp);
} }
/* /*
@ -336,20 +335,20 @@ static void define_macros(void)
*/ */
snprintf(temp, sizeof(temp), "__?OUTPUT_FORMAT?__=%s", snprintf(temp, sizeof(temp), "__?OUTPUT_FORMAT?__=%s",
ofmt_alias ? ofmt_alias->shortname : ofmt->shortname); ofmt_alias ? ofmt_alias->shortname : ofmt->shortname);
preproc->pre_define(temp); pp_pre_define(temp);
/* /*
* Output-format specific macros. * Output-format specific macros.
*/ */
if (ofmt->stdmac) if (ofmt->stdmac)
preproc->extra_stdmac(ofmt->stdmac); pp_extra_stdmac(ofmt->stdmac);
/* /*
* Debug format, if any * Debug format, if any
*/ */
if (dfmt != &null_debug_form) { if (dfmt != &null_debug_form) {
snprintf(temp, sizeof(temp), "__?DEBUG_FORMAT?__=%s", dfmt->shortname); snprintf(temp, sizeof(temp), "__?DEBUG_FORMAT?__=%s", dfmt->shortname);
preproc->pre_define(temp); pp_pre_define(temp);
} }
} }
@ -364,9 +363,9 @@ static void define_macros(void)
*/ */
static void preproc_init(struct strlist *ipath) static void preproc_init(struct strlist *ipath)
{ {
preproc->init(ppopt); pp_init(ppopt);
define_macros(); define_macros();
preproc->include_path(ipath); pp_include_path(ipath);
} }
static void emit_dependencies(struct strlist *list) static void emit_dependencies(struct strlist *list)
@ -620,13 +619,13 @@ int main(int argc, char **argv)
char *line; char *line;
if (depend_missing_ok) if (depend_missing_ok)
preproc->include_path(NULL); /* "assume generated" */ pp_include_path(NULL); /* "assume generated" */
preproc->reset(inname, PP_DEPS, depend_list); pp_reset(inname, PP_DEPS, depend_list);
ofile = NULL; ofile = NULL;
while ((line = preproc->getline())) while ((line = pp_getline()))
nasm_free(line); nasm_free(line);
preproc->cleanup_pass(); pp_cleanup_pass();
reset_warnings(); reset_warnings();
} else if (operating_mode & OP_PREPROCESS) { } else if (operating_mode & OP_PREPROCESS) {
char *line; char *line;
@ -649,9 +648,9 @@ int main(int argc, char **argv)
location.known = false; location.known = false;
_pass_type = PASS_PREPROC; _pass_type = PASS_PREPROC;
preproc->reset(inname, PP_PREPROC, depend_list); pp_reset(inname, PP_PREPROC, depend_list);
while ((line = preproc->getline())) { while ((line = pp_getline())) {
/* /*
* We generate %line directives if needed for later programs * We generate %line directives if needed for later programs
*/ */
@ -696,7 +695,7 @@ int main(int argc, char **argv)
nasm_free(quoted_file_name); nasm_free(quoted_file_name);
preproc->cleanup_pass(); pp_cleanup_pass();
reset_warnings(); reset_warnings();
if (ofile) if (ofile)
fclose(ofile); fclose(ofile);
@ -731,7 +730,7 @@ int main(int argc, char **argv)
} }
} }
preproc->cleanup_session(); pp_cleanup_session();
if (depend_list && !terminate_after_phase) if (depend_list && !terminate_after_phase)
emit_dependencies(depend_list); emit_dependencies(depend_list);
@ -1066,19 +1065,19 @@ static bool process_arg(char *p, char *q, int pass)
case 'p': /* pre-include */ case 'p': /* pre-include */
case 'P': case 'P':
if (pass == 2) if (pass == 2)
preproc->pre_include(param); pp_pre_include(param);
break; break;
case 'd': /* pre-define */ case 'd': /* pre-define */
case 'D': case 'D':
if (pass == 2) if (pass == 2)
preproc->pre_define(param); pp_pre_define(param);
break; break;
case 'u': /* un-define */ case 'u': /* un-define */
case 'U': case 'U':
if (pass == 2) if (pass == 2)
preproc->pre_undefine(param); pp_pre_undefine(param);
break; break;
case 'i': /* include search path */ case 'i': /* include search path */
@ -1309,15 +1308,15 @@ static bool process_arg(char *p, char *q, int pass)
break; break;
case OPT_INCLUDE: case OPT_INCLUDE:
if (pass == 2) if (pass == 2)
preproc->pre_include(q); pp_pre_include(q);
break; break;
case OPT_PRAGMA: case OPT_PRAGMA:
if (pass == 2) if (pass == 2)
preproc->pre_command("pragma", param); pp_pre_command("pragma", param);
break; break;
case OPT_BEFORE: case OPT_BEFORE:
if (pass == 2) if (pass == 2)
preproc->pre_command(NULL, param); pp_pre_command(NULL, param);
break; break;
case OPT_LIMIT: case OPT_LIMIT:
if (pass == 1) if (pass == 1)
@ -1711,11 +1710,11 @@ static void assemble_file(const char *fname, struct strlist *depend_list)
location.known = true; location.known = true;
ofmt->reset(); ofmt->reset();
switch_segment(ofmt->section(NULL, &globalbits)); switch_segment(ofmt->section(NULL, &globalbits));
preproc->reset(fname, PP_NORMAL, pass_final() ? depend_list : NULL); pp_reset(fname, PP_NORMAL, pass_final() ? depend_list : NULL);
globallineno = 0; globallineno = 0;
while ((line = preproc->getline())) { while ((line = pp_getline())) {
if (++globallineno > nasm_limit[LIMIT_LINES]) if (++globallineno > nasm_limit[LIMIT_LINES])
nasm_fatal("overall line count exceeds the maximum %"PRId64"\n", nasm_fatal("overall line count exceeds the maximum %"PRId64"\n",
nasm_limit[LIMIT_LINES]); nasm_limit[LIMIT_LINES]);
@ -1735,9 +1734,9 @@ static void assemble_file(const char *fname, struct strlist *depend_list)
end_of_line: end_of_line:
nasm_free(line); nasm_free(line);
} /* end while (line = preproc->getline... */ } /* end while (line = pp_getline... */
preproc->cleanup_pass(); pp_cleanup_pass();
/* We better not be having an error hold still... */ /* We better not be having an error hold still... */
nasm_assert(!errhold_stack); nasm_assert(!errhold_stack);
@ -1870,8 +1869,8 @@ static bool is_suppressed(errflags severity)
if (!(warning_state[warn_index(severity)] & WARN_ST_ENABLED)) if (!(warning_state[warn_index(severity)] & WARN_ST_ENABLED))
return true; return true;
if (preproc && !(severity & ERR_PP_LISTMACRO)) if (!(severity & ERR_PP_LISTMACRO))
return preproc->suppress_error(severity); return pp_suppress_error(severity);
return false; return false;
} }
@ -2104,8 +2103,7 @@ void nasm_verror(errflags severity, const char *fmt, va_list args)
return; return;
if (!(severity & (ERR_HERE|ERR_PP_LISTMACRO))) if (!(severity & (ERR_HERE|ERR_PP_LISTMACRO)))
if (preproc) pp_error_list_macros(severity);
preproc->error_list_macros(severity);
} }
/* /*

View File

@ -6564,7 +6564,7 @@ static int expand_mmacro(Token * tline)
* It will never be called with a severity level of ERR_FATAL or * It will never be called with a severity level of ERR_FATAL or
* higher. * higher.
*/ */
static bool pp_suppress_error(errflags severity) bool pp_suppress_error(errflags severity)
{ {
/* /*
* If we're in a dead branch of IF or something like it, ignore the error. * If we're in a dead branch of IF or something like it, ignore the error.
@ -6726,8 +6726,8 @@ static void pp_reset_stdmac(enum preproc_mode mode)
define_smacro("__?PASS?__", true, make_tok_num(NULL, apass), NULL); define_smacro("__?PASS?__", true, make_tok_num(NULL, apass), NULL);
} }
static void pp_reset(const char *file, enum preproc_mode mode, void pp_reset(const char *file, enum preproc_mode mode,
struct strlist *dep_list) struct strlist *dep_list)
{ {
cstk = NULL; cstk = NULL;
defining = NULL; defining = NULL;
@ -6771,7 +6771,7 @@ static void pp_reset(const char *file, enum preproc_mode mode,
pp_reset_stdmac(mode); pp_reset_stdmac(mode);
} }
static void pp_init(enum preproc_opt opt) void pp_init(enum preproc_opt opt)
{ {
ppopt = opt; ppopt = opt;
nasm_newn(use_loaded, use_package_count); nasm_newn(use_loaded, use_package_count);
@ -7038,7 +7038,7 @@ static Token *pp_tokline(void)
} }
} }
static char *pp_getline(void) char *pp_getline(void)
{ {
char *line = NULL; char *line = NULL;
Token *tline; Token *tline;
@ -7071,7 +7071,7 @@ static char *pp_getline(void)
return line; return line;
} }
static void pp_cleanup_pass(void) void pp_cleanup_pass(void)
{ {
if (defining) { if (defining) {
if (defining->name) { if (defining->name) {
@ -7102,7 +7102,7 @@ static void pp_cleanup_pass(void)
debug_macro_output(); debug_macro_output();
} }
static void pp_cleanup_session(void) void pp_cleanup_session(void)
{ {
nasm_free(use_loaded); nasm_free(use_loaded);
free_llist(predef); free_llist(predef);
@ -7111,12 +7111,12 @@ static void pp_cleanup_session(void)
ipath_list = NULL; ipath_list = NULL;
} }
static void pp_include_path(struct strlist *list) void pp_include_path(struct strlist *list)
{ {
ipath_list = list; ipath_list = list;
} }
static void pp_pre_include(char *fname) void pp_pre_include(char *fname)
{ {
Token *inc, *space, *name; Token *inc, *space, *name;
Line *l; Line *l;
@ -7132,7 +7132,7 @@ static void pp_pre_include(char *fname)
predef = l; predef = l;
} }
static void pp_pre_define(char *definition) void pp_pre_define(char *definition)
{ {
Token *def, *space; Token *def, *space;
Line *l; Line *l;
@ -7159,7 +7159,7 @@ static void pp_pre_define(char *definition)
predef = l; predef = l;
} }
static void pp_pre_undefine(char *definition) void pp_pre_undefine(char *definition)
{ {
Token *def, *space; Token *def, *space;
Line *l; Line *l;
@ -7176,7 +7176,7 @@ static void pp_pre_undefine(char *definition)
} }
/* Insert an early preprocessor command that doesn't need special handling */ /* Insert an early preprocessor command that doesn't need special handling */
static void pp_pre_command(const char *what, char *string) void pp_pre_command(const char *what, char *string)
{ {
char *cmd; char *cmd;
Token *def, *space; Token *def, *space;
@ -7212,7 +7212,7 @@ static void pp_add_stdmac(macros_t *macros)
*mp = macros; *mp = macros;
} }
static void pp_extra_stdmac(macros_t *macros) void pp_extra_stdmac(macros_t *macros)
{ {
extrastdmac = macros; extrastdmac = macros;
} }
@ -7259,7 +7259,7 @@ static Token *make_tok_char(Token *next, char op)
* Descent the macro hierarchy and display the expansion after * Descent the macro hierarchy and display the expansion after
* encountering an error message. * encountering an error message.
*/ */
static void pp_error_list_macros(errflags severity) void pp_error_list_macros(errflags severity)
{ {
const MMacro *m; const MMacro *m;
@ -7271,20 +7271,3 @@ static void pp_error_list_macros(errflags severity)
src_error_reset(); src_error_reset();
} }
/* The normal NASM preprocessor */
const struct preproc_ops preproc_nasm = {
pp_init,
pp_reset,
pp_getline,
pp_cleanup_pass,
pp_cleanup_session,
pp_extra_stdmac,
pp_pre_define,
pp_pre_undefine,
pp_pre_include,
pp_pre_command,
pp_include_path,
pp_error_list_macros,
pp_suppress_error
};

View File

@ -97,7 +97,7 @@ fatal_func nasm_verror_critical(errflags severity, const char *fmt, va_list ap);
#define ERR_NO_SEVERITY 0x00000200 /* suppress printing severity */ #define ERR_NO_SEVERITY 0x00000200 /* suppress printing severity */
#define ERR_PP_PRECOND 0x00000400 /* for preprocessor use */ #define ERR_PP_PRECOND 0x00000400 /* for preprocessor use */
#define ERR_PP_LISTMACRO 0x00000800 /* from preproc->error_list_macros() */ #define ERR_PP_LISTMACRO 0x00000800 /* from pp_error_list_macros() */
#define ERR_HOLD 0x00001000 /* this error/warning can be held */ #define ERR_HOLD 0x00001000 /* this error/warning can be held */
/* /*

View File

@ -350,61 +350,57 @@ enum preproc_opt {
PP_TASM = 4 /* TASM compatibility hacks */ PP_TASM = 4 /* TASM compatibility hacks */
}; };
struct preproc_ops { /*
/* * Called once at the very start of assembly.
* Called once at the very start of assembly. */
*/ void pp_init(enum preproc_opt opt);
void (*init)(enum preproc_opt opt);
/* /*
* Called at the start of a pass; given a file name, the number * Called at the start of a pass; given a file name, the number
* of the pass, an error reporting function, an evaluator * of the pass, an error reporting function, an evaluator
* function, and a listing generator to talk to. * function, and a listing generator to talk to.
*/ */
void (*reset)(const char *file, enum preproc_mode mode, void pp_reset(const char *file, enum preproc_mode mode,
struct strlist *deplist); struct strlist *deplist);
/* /*
* Called to fetch a line of preprocessed source. The line * Called to fetch a line of preprocessed source. The line
* returned has been malloc'ed, and so should be freed after * returned has been malloc'ed, and so should be freed after
* use. * use.
*/ */
char *(*getline)(void); char *pp_getline(void);
/* Called at the end of each pass. */ /* Called at the end of each pass. */
void (*cleanup_pass)(void); void pp_cleanup_pass(void);
/* /*
* Called at the end of the assembly session, * Called at the end of the assembly session,
* after cleanup_pass() has been called for the * after cleanup_pass() has been called for the
* last pass. * last pass.
*/ */
void (*cleanup_session)(void); void pp_cleanup_session(void);
/* Additional macros specific to output format */ /* Additional macros specific to output format */
void (*extra_stdmac)(macros_t *macros); void pp_extra_stdmac(macros_t *macros);
/* Early definitions and undefinitions for macros */ /* Early definitions and undefinitions for macros */
void (*pre_define)(char *definition); void pp_pre_define(char *definition);
void (*pre_undefine)(char *definition); void pp_pre_undefine(char *definition);
/* Include file from command line */ /* Include file from command line */
void (*pre_include)(char *fname); void pp_pre_include(char *fname);
/* Add a command from the command line */ /* Add a command from the command line */
void (*pre_command)(const char *what, char *str); void pp_pre_command(const char *what, char *str);
/* Include path from command line */ /* Include path from command line */
void (*include_path)(struct strlist *ipath); void pp_include_path(struct strlist *ipath);
/* Unwind the macro stack when printing an error message */ /* Unwind the macro stack when printing an error message */
void (*error_list_macros)(errflags severity); void pp_error_list_macros(errflags severity);
/* Return true if an error message should be suppressed */ /* Return true if an error message should be suppressed */
bool (*suppress_error)(errflags severity); bool pp_suppress_error(errflags severity);
};
extern const struct preproc_ops preproc_nasm;
/* List of dependency files */ /* List of dependency files */
extern struct strlist *depend_list; extern struct strlist *depend_list;