]> granicus.if.org Git - yasm/commitdiff
Implemented -I and -P command line options frontend, nasm and raw preprocs.
authorMichael Urman <mu@tortall.net>
Tue, 1 Apr 2003 04:06:47 +0000 (04:06 -0000)
committerMichael Urman <mu@tortall.net>
Tue, 1 Apr 2003 04:06:47 +0000 (04:06 -0000)
svn path=/trunk/yasm/; revision=906

frontends/yasm/yasm.c
libyasm/preproc.h
modules/preprocs/nasm/nasm-preproc.c
modules/preprocs/raw/raw-preproc.c

index b68d1086967516f162a9b2d21c67cf036087da0b..164d74a52a02776ea69f80326fcca43ac3a6581e 100644 (file)
@@ -70,6 +70,10 @@ static int opt_dbgfmt_handler(char *cmd, /*@null@*/ char *param, int extra);
 static int opt_objfile_handler(char *cmd, /*@null@*/ char *param, int extra);
 static int opt_warning_handler(char *cmd, /*@null@*/ char *param, int extra);
 static int preproc_only_handler(char *cmd, /*@null@*/ char *param, int extra);
+static int opt_preproc_include_path(char *cmd, /*@null@*/ char *param,
+                                   int extra);
+static int opt_preproc_include_file(char *cmd, /*@null@*/ char *param,
+                                   int extra);
 
 static /*@only@*/ char *replace_extension(const char *orig, /*@null@*/
                                          const char *ext, const char *def);
@@ -85,6 +89,8 @@ static void print_yasm_error(const char *filename, unsigned long line,
 static void print_yasm_warning(const char *filename, unsigned long line,
                               const char *msg);
 
+static void apply_preproc_saved_options(void);
+
 /* values for special_options */
 #define SPECIAL_SHOW_HELP 0x01
 #define SPECIAL_SHOW_VERSION 0x02
@@ -112,6 +118,10 @@ static opt_option options[] =
       N_("enables/disables warning"), NULL },
     { 'e', "preproc-only", 0, preproc_only_handler, 0,
       N_("preprocess only (writes output to stdout by default)"), NULL },
+    { 'I', NULL, 1, opt_preproc_include_path, 0,
+      N_("add include path"), N_("path") },
+    { 'P', NULL, 1, opt_preproc_include_file, 0,
+      N_("pre-include file"), N_("filename") },
 };
 
 /* version message */
@@ -141,6 +151,17 @@ static opt_option options[] =
     "\n"
     "Report bugs to bug-yasm@tortall.net\n");
 
+/* parsed command line storage until appropriate modules have been loaded */
+typedef STAILQ_HEAD(constcharparam_head, constcharparam) constcharparam_head;
+
+typedef struct constcharparam {
+    STAILQ_ENTRY(constcharparam) link;
+    const char *param;
+} constcharparam;
+
+static constcharparam_head includepaths;
+static constcharparam_head includefiles;
+
 /* main function */
 /*@-globstate -unrecog@*/
 int
@@ -195,6 +216,10 @@ main(int argc, char *argv[])
     }
 #endif
 
+    /* Initialize parameter storage */
+    STAILQ_INIT(&includepaths);
+    STAILQ_INIT(&includefiles);
+
     if (parse_cmdline(argc, argv, options, NELEMS(options), print_error))
        return EXIT_FAILURE;
 
@@ -270,6 +295,8 @@ main(int argc, char *argv[])
            return EXIT_FAILURE;
        }
 
+       apply_preproc_saved_options();
+
        /* Pre-process until done */
        cur_preproc->initialize(in, in_filename, &yasm_std_linemgr);
        while ((got = cur_preproc->input(preproc_buf, PREPROC_BUF_SIZE)) != 0)
@@ -400,6 +427,7 @@ main(int argc, char *argv[])
            return EXIT_FAILURE;
        }
     }
+    apply_preproc_saved_options();
 
     /* Get initial x86 BITS setting from object format */
     if (strcmp(cur_arch->keyword, "x86") == 0) {
@@ -664,6 +692,63 @@ preproc_only_handler(/*@unused@*/ char *cmd, /*@unused@*/ char *param,
     return 0;
 }
 
+static int
+opt_preproc_include_path(/*@unused@*/ char *cmd, char *param,
+                        /*@unused@*/ int extra)
+{
+    constcharparam *cp;
+    cp = yasm_xmalloc(sizeof(constcharparam));
+    cp->param = param;
+    STAILQ_INSERT_TAIL(&includepaths, cp, link);
+    return 0;
+}
+
+static void
+apply_preproc_saved_options()
+{
+    constcharparam *cp;
+    constcharparam *cpnext;
+
+    if (cur_preproc->add_include_path != NULL) {
+       STAILQ_FOREACH(cp, &includepaths, link) {
+           cur_preproc->add_include_path(cp->param);
+       }
+    }
+
+    cp = STAILQ_FIRST(&includepaths);
+    while (cp != NULL) {
+       cpnext = STAILQ_NEXT(cp, link);
+       yasm_xfree(cp);
+       cp = cpnext;
+    }
+    STAILQ_INIT(&includepaths);
+
+    if (cur_preproc->add_include_file != NULL) {
+       STAILQ_FOREACH(cp, &includefiles, link) {
+           cur_preproc->add_include_file(cp->param);
+       }
+    }
+
+    cp = STAILQ_FIRST(&includepaths);
+    while (cp != NULL) {
+       cpnext = STAILQ_NEXT(cp, link);
+       yasm_xfree(cp);
+       cp = cpnext;
+    }
+    STAILQ_INIT(&includepaths);
+}
+
+static int
+opt_preproc_include_file(/*@unused@*/ char *cmd, char *param,
+                        /*@unused@*/ int extra)
+{
+    constcharparam *cp;
+    cp = yasm_xmalloc(sizeof(constcharparam));
+    cp->param = param;
+    STAILQ_INSERT_TAIL(&includefiles, cp, link);
+    return 0;
+}
+
 /* Replace extension on a filename (or append one if none is present).
  * If output filename would be identical to input (same extension out as in),
  * returns (copy of) def.
index 67d970c9ce7adb3d0d13fc501c968f961b1469c8..8226f9aa2063444b128bf6973f353ab2e30f8b1e 100644 (file)
@@ -51,6 +51,12 @@ struct yasm_preproc {
     /* Gets more preprocessed source code (up to max_size bytes) into buf.
      * Note that more than a single line may be returned in buf. */
     size_t (*input) (/*@out@*/ char *buf, size_t max_size);
+
+    /* Add a directory to the %include search path */
+    void (*add_include_path) (const char *path);
+
+    /* Pre-include a file */
+    void (*add_include_file) (const char *filename);
 };
 
 #endif
index 81f7fe887d2b337669f0183a7573cd5887f6623f..eda59b21974ca01dc172c24a29bac7d96b79156d 100644 (file)
@@ -174,6 +174,22 @@ nasm_preproc_input(char *buf, size_t max_size)
     return tot;
 }
 
+static void
+nasm_preproc_add_include_path (const char *path)
+{
+    char *p = yasm__xstrdup(path);
+    pp_include_path(p);
+    yasm_xfree(p);
+}
+
+static void
+nasm_preproc_add_include_file (const char *filename)
+{
+    char *f = yasm__xstrdup(filename);
+    pp_pre_include(f);
+    yasm_xfree(f);
+}
+
 
 /* Define preproc structure -- see preproc.h for details */
 yasm_preproc yasm_nasm_LTX_preproc = {
@@ -181,5 +197,7 @@ yasm_preproc yasm_nasm_LTX_preproc = {
     "nasm",
     nasm_preproc_initialize,
     nasm_preproc_cleanup,
-    nasm_preproc_input
+    nasm_preproc_input,
+    nasm_preproc_add_include_path,
+    nasm_preproc_add_include_file
 };
index ecf363192bca5b104c0da301f11ac765cb3b87d2..e971b5f26238412b9e79d9b8916fcc5cdd6485f9 100644 (file)
@@ -76,5 +76,7 @@ yasm_preproc yasm_raw_LTX_preproc = {
     "raw",
     raw_preproc_initialize,
     raw_preproc_cleanup,
-    raw_preproc_input
+    raw_preproc_input,
+    /* no include paths */ NULL,
+    /* no pre-include files */ NULL
 };