[nasm:master] preproc: drop preproc_ops

nasm-bot for H. Peter Anvin (Intel) hpa at zytor.com
Fri Jul 10 19:30:04 PDT 2020


Commit-ID:  10c9aa37a40b9e33a0129f9ba964f62835929506
Gitweb:     http://repo.or.cz/w/nasm.git?a=commitdiff;h=10c9aa37a40b9e33a0129f9ba964f62835929506
Author:     H. Peter Anvin (Intel) <hpa at zytor.com>
AuthorDate: Fri, 10 Jul 2020 19:23:22 -0700
Committer:  H. Peter Anvin (Intel) <hpa at zytor.com>
CommitDate: Fri, 10 Jul 2020 19:26:44 -0700

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 at zytor.com>


---
 asm/nasm.c      | 72 ++++++++++++++++++++++++-------------------------
 asm/preproc.c   | 45 ++++++++++---------------------
 include/error.h |  2 +-
 include/nasm.h  | 84 +++++++++++++++++++++++++++------------------------------
 4 files changed, 90 insertions(+), 113 deletions(-)

diff --git a/asm/nasm.c b/asm/nasm.c
index 78cd120b..e9cb5c83 100644
--- a/asm/nasm.c
+++ b/asm/nasm.c
@@ -143,7 +143,6 @@ static struct RAA *offsets;
 static struct SAA *forwrefs;    /* keep track of forward references */
 static const struct forwrefinfo *forwref;
 
-#define preproc (&preproc_nasm) /* Hack */
 static struct strlist *include_path;
 static enum preproc_opt ppopt;
 
@@ -304,29 +303,29 @@ static void define_macros(void)
 
     if (oct->have_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);
-        preproc->pre_define(temp);
+        pp_pre_define(temp);
         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);
-        preproc->pre_define(temp);
+        pp_pre_define(temp);
     }
 
     if (oct->have_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);
-        preproc->pre_define(temp);
+        pp_pre_define(temp);
         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);
-        preproc->pre_define(temp);
+        pp_pre_define(temp);
     }
 
     if (oct->have_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",
              ofmt_alias ? ofmt_alias->shortname : ofmt->shortname);
-    preproc->pre_define(temp);
+    pp_pre_define(temp);
 
     /*
      * Output-format specific macros.
      */
     if (ofmt->stdmac)
-        preproc->extra_stdmac(ofmt->stdmac);
+        pp_extra_stdmac(ofmt->stdmac);
 
     /*
      * Debug format, if any
      */
     if (dfmt != &null_debug_form) {
         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)
 {
-    preproc->init(ppopt);
+    pp_init(ppopt);
     define_macros();
-    preproc->include_path(ipath);
+    pp_include_path(ipath);
 }
 
 static void emit_dependencies(struct strlist *list)
@@ -620,13 +619,13 @@ int main(int argc, char **argv)
             char *line;
 
             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;
-            while ((line = preproc->getline()))
+            while ((line = pp_getline()))
                 nasm_free(line);
-            preproc->cleanup_pass();
+            pp_cleanup_pass();
             reset_warnings();
     } else if (operating_mode & OP_PREPROCESS) {
             char *line;
@@ -649,9 +648,9 @@ int main(int argc, char **argv)
             location.known = false;
 
             _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
                  */
@@ -696,7 +695,7 @@ int main(int argc, char **argv)
 
             nasm_free(quoted_file_name);
 
-            preproc->cleanup_pass();
+            pp_cleanup_pass();
             reset_warnings();
             if (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)
         emit_dependencies(depend_list);
@@ -1066,19 +1065,19 @@ static bool process_arg(char *p, char *q, int pass)
         case 'p':       /* pre-include */
         case 'P':
             if (pass == 2)
-                preproc->pre_include(param);
+                pp_pre_include(param);
             break;
 
         case 'd':       /* pre-define */
         case 'D':
             if (pass == 2)
-                preproc->pre_define(param);
+                pp_pre_define(param);
             break;
 
         case 'u':       /* un-define */
         case 'U':
             if (pass == 2)
-                preproc->pre_undefine(param);
+                pp_pre_undefine(param);
             break;
 
         case 'i':       /* include search path */
@@ -1309,15 +1308,15 @@ static bool process_arg(char *p, char *q, int pass)
                     break;
                 case OPT_INCLUDE:
                     if (pass == 2)
-                        preproc->pre_include(q);
+                        pp_pre_include(q);
                     break;
                 case OPT_PRAGMA:
                     if (pass == 2)
-                        preproc->pre_command("pragma", param);
+                        pp_pre_command("pragma", param);
                     break;
                 case OPT_BEFORE:
                     if (pass == 2)
-                        preproc->pre_command(NULL, param);
+                        pp_pre_command(NULL, param);
                     break;
                 case OPT_LIMIT:
                     if (pass == 1)
@@ -1711,11 +1710,11 @@ static void assemble_file(const char *fname, struct strlist *depend_list)
             location.known = true;
         ofmt->reset();
         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;
 
-        while ((line = preproc->getline())) {
+        while ((line = pp_getline())) {
             if (++globallineno > nasm_limit[LIMIT_LINES])
                 nasm_fatal("overall line count exceeds the maximum %"PRId64"\n",
                            nasm_limit[LIMIT_LINES]);
@@ -1735,9 +1734,9 @@ static void assemble_file(const char *fname, struct strlist *depend_list)
 
         end_of_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... */
         nasm_assert(!errhold_stack);
@@ -1870,8 +1869,8 @@ static bool is_suppressed(errflags severity)
     if (!(warning_state[warn_index(severity)] & WARN_ST_ENABLED))
         return true;
 
-    if (preproc && !(severity & ERR_PP_LISTMACRO))
-        return preproc->suppress_error(severity);
+    if (!(severity & ERR_PP_LISTMACRO))
+        return pp_suppress_error(severity);
 
     return false;
 }
@@ -2104,8 +2103,7 @@ void nasm_verror(errflags severity, const char *fmt, va_list args)
         return;
 
     if (!(severity & (ERR_HERE|ERR_PP_LISTMACRO)))
-        if (preproc)
-            preproc->error_list_macros(severity);
+        pp_error_list_macros(severity);
 }
 
 /*
diff --git a/asm/preproc.c b/asm/preproc.c
index b2dea76d..fc1b0df1 100644
--- a/asm/preproc.c
+++ b/asm/preproc.c
@@ -6564,7 +6564,7 @@ static int expand_mmacro(Token * tline)
  * It will never be called with a severity level of ERR_FATAL or
  * 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.
@@ -6726,8 +6726,8 @@ static void pp_reset_stdmac(enum preproc_mode mode)
     define_smacro("__?PASS?__", true, make_tok_num(NULL, apass), NULL);
 }
 
-static void pp_reset(const char *file, enum preproc_mode mode,
-                     struct strlist *dep_list)
+void pp_reset(const char *file, enum preproc_mode mode,
+              struct strlist *dep_list)
 {
     cstk = NULL;
     defining = NULL;
@@ -6771,7 +6771,7 @@ static void pp_reset(const char *file, enum preproc_mode mode,
         pp_reset_stdmac(mode);
 }
 
-static void pp_init(enum preproc_opt opt)
+void pp_init(enum preproc_opt opt)
 {
     ppopt = opt;
     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;
     Token *tline;
@@ -7071,7 +7071,7 @@ static char *pp_getline(void)
     return line;
 }
 
-static void pp_cleanup_pass(void)
+void pp_cleanup_pass(void)
 {
     if (defining) {
         if (defining->name) {
@@ -7102,7 +7102,7 @@ static void pp_cleanup_pass(void)
         debug_macro_output();
 }
 
-static void pp_cleanup_session(void)
+void pp_cleanup_session(void)
 {
     nasm_free(use_loaded);
     free_llist(predef);
@@ -7111,12 +7111,12 @@ static void pp_cleanup_session(void)
     ipath_list = NULL;
 }
 
-static void pp_include_path(struct strlist *list)
+void pp_include_path(struct strlist *list)
 {
     ipath_list = list;
 }
 
-static void pp_pre_include(char *fname)
+void pp_pre_include(char *fname)
 {
     Token *inc, *space, *name;
     Line *l;
@@ -7132,7 +7132,7 @@ static void pp_pre_include(char *fname)
     predef = l;
 }
 
-static void pp_pre_define(char *definition)
+void pp_pre_define(char *definition)
 {
     Token *def, *space;
     Line *l;
@@ -7159,7 +7159,7 @@ static void pp_pre_define(char *definition)
     predef = l;
 }
 
-static void pp_pre_undefine(char *definition)
+void pp_pre_undefine(char *definition)
 {
     Token *def, *space;
     Line *l;
@@ -7176,7 +7176,7 @@ static void pp_pre_undefine(char *definition)
 }
 
 /* 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;
     Token *def, *space;
@@ -7212,7 +7212,7 @@ static void pp_add_stdmac(macros_t *macros)
     *mp = macros;
 }
 
-static void pp_extra_stdmac(macros_t *macros)
+void pp_extra_stdmac(macros_t *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
  * encountering an error message.
  */
-static void pp_error_list_macros(errflags severity)
+void pp_error_list_macros(errflags severity)
 {
     const MMacro *m;
 
@@ -7271,20 +7271,3 @@ static void pp_error_list_macros(errflags severity)
 
     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
-};
diff --git a/include/error.h b/include/error.h
index 52f5d1d6..5d86a856 100644
--- a/include/error.h
+++ b/include/error.h
@@ -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_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 */
 
 /*
diff --git a/include/nasm.h b/include/nasm.h
index df1593e4..3bcd3cda 100644
--- a/include/nasm.h
+++ b/include/nasm.h
@@ -350,61 +350,57 @@ enum preproc_opt {
     PP_TASM     = 4             /* TASM compatibility hacks */
 };
 
-struct preproc_ops {
-    /*
-     * Called once at the very start of assembly.
-     */
-    void (*init)(enum preproc_opt opt);
-
-    /*
-     * Called at the start of a pass; given a file name, the number
-     * of the pass, an error reporting function, an evaluator
-     * function, and a listing generator to talk to.
-     */
-    void (*reset)(const char *file, enum preproc_mode mode,
-                  struct strlist *deplist);
+/*
+ * Called once at the very start of assembly.
+ */
+void pp_init(enum preproc_opt opt);
 
-    /*
-     * Called to fetch a line of preprocessed source. The line
-     * returned has been malloc'ed, and so should be freed after
-     * use.
-     */
-    char *(*getline)(void);
+/*
+ * Called at the start of a pass; given a file name, the number
+ * of the pass, an error reporting function, an evaluator
+ * function, and a listing generator to talk to.
+ */
+void pp_reset(const char *file, enum preproc_mode mode,
+              struct strlist *deplist);
 
-    /* Called at the end of each pass. */
-    void (*cleanup_pass)(void);
+/*
+ * Called to fetch a line of preprocessed source. The line
+ * returned has been malloc'ed, and so should be freed after
+ * use.
+ */
+char *pp_getline(void);
 
-    /*
-     * Called at the end of the assembly session,
-     * after cleanup_pass() has been called for the
-     * last pass.
-     */
-    void (*cleanup_session)(void);
+/* Called at the end of each pass. */
+void pp_cleanup_pass(void);
 
-    /* Additional macros specific to output format */
-    void (*extra_stdmac)(macros_t *macros);
+/*
+ * Called at the end of the assembly session,
+ * after cleanup_pass() has been called for the
+ * last pass.
+ */
+void pp_cleanup_session(void);
 
-    /* Early definitions and undefinitions for macros */
-    void (*pre_define)(char *definition);
-    void (*pre_undefine)(char *definition);
+/* Additional macros specific to output format */
+void pp_extra_stdmac(macros_t *macros);
 
-    /* Include file from command line */
-    void (*pre_include)(char *fname);
+/* Early definitions and undefinitions for macros */
+void pp_pre_define(char *definition);
+void pp_pre_undefine(char *definition);
 
-    /* Add a command from the command line */
-    void (*pre_command)(const char *what, char *str);
+/* Include file from command line */
+void pp_pre_include(char *fname);
 
-    /* Include path from command line */
-    void (*include_path)(struct strlist *ipath);
+/* Add a command from the command line */
+void pp_pre_command(const char *what, char *str);
 
-    /* Unwind the macro stack when printing an error message */
-    void (*error_list_macros)(errflags severity);
+/* Include path from command line */
+void pp_include_path(struct strlist *ipath);
 
-    /* Return true if an error message should be suppressed */
-    bool (*suppress_error)(errflags severity);
-};
+/* Unwind the macro stack when printing an error message */
+void pp_error_list_macros(errflags severity);
 
-extern const struct preproc_ops preproc_nasm;
+/* Return true if an error message should be suppressed */
+bool pp_suppress_error(errflags severity);
 
 /* List of dependency files */
 extern struct strlist *depend_list;


More information about the Nasm-commits mailing list