diff options
Diffstat (limited to 'gcc/m2/gm2spec.cc')
-rw-r--r-- | gcc/m2/gm2spec.cc | 64 |
1 files changed, 63 insertions, 1 deletions
diff --git a/gcc/m2/gm2spec.cc b/gcc/m2/gm2spec.cc index 0645be9..a118a88 100644 --- a/gcc/m2/gm2spec.cc +++ b/gcc/m2/gm2spec.cc @@ -31,6 +31,8 @@ along with GNU Modula-2; see the file COPYING3. If not see #include "gcc.h" #include "opts.h" #include "vec.h" +#include <vector> +#include <string> #include "m2/gm2config.h" @@ -149,7 +151,40 @@ static void append_arg (const struct cl_decoded_option *); static unsigned int gm2_newargc; static struct cl_decoded_option *gm2_new_decoded_options; static const char *libraries = NULL; /* Abbreviated libraries. */ +static const char *m2_path_name = ""; +typedef struct named_path_s { + std::vector<const char*>path; + const char *name; +} named_path; + +static std::vector<named_path>Ipaths; + + +static void +push_back_Ipath (const char *arg) +{ + if (Ipaths.empty ()) + { + named_path np; + np.path.push_back (arg); + np.name = m2_path_name; + Ipaths.push_back (np); + } + else + { + if (strcmp (Ipaths.back ().name, + m2_path_name) == 0) + Ipaths.back ().path.push_back (arg); + else + { + named_path np; + np.path.push_back (arg); + np.name = m2_path_name; + Ipaths.push_back (np); + } + } +} /* Return whether strings S1 and S2 are both NULL or both the same string. */ @@ -342,6 +377,24 @@ convert_abbreviations (const char *libraries) return full_libraries; } +/* add_m2_I_path appends -fm2-pathname and -fm2-pathnameI options to + the command line which are contructed in the saved Ipaths. */ + +static void +add_m2_I_path (void) +{ + for (auto np : Ipaths) + { + if (strcmp (np.name, "") == 0) + append_option (OPT_fm2_pathname_, safe_strdup ("-"), 1); + else + append_option (OPT_fm2_pathname_, safe_strdup (np.name), 1); + for (auto *s : np.path) + append_option (OPT_fm2_pathnameI, safe_strdup (s), 1); + } + Ipaths.clear(); +} + void lang_specific_driver (struct cl_decoded_option **in_decoded_options, @@ -429,6 +482,7 @@ lang_specific_driver (struct cl_decoded_option **in_decoded_options, fprintf (stderr, "\n"); #endif + // add_spec_function ("m2I", add_m2_I_path); gm2_xargc = argc; gm2_x_decoded_options = decoded_options; gm2_newargc = 0; @@ -514,7 +568,14 @@ lang_specific_driver (struct cl_decoded_option **in_decoded_options, seen_uselist = true; uselist = decoded_options[i].value; break; - + case OPT_fm2_pathname_: + args[i] |= SKIPOPT; /* We will add the option if it is needed. */ + m2_path_name = decoded_options[i].arg; + break; + case OPT_I: + args[i] |= SKIPOPT; /* We will add the option if it is needed. */ + push_back_Ipath (decoded_options[i].arg); + break; case OPT_nostdlib: case OPT_nostdlib__: case OPT_nodefaultlibs: @@ -670,6 +731,7 @@ lang_specific_driver (struct cl_decoded_option **in_decoded_options, #endif } + add_m2_I_path (); /* We now add in extra arguments to facilitate a successful link. Note that the libraries are added to the end of the link here and also placed earlier into the link by lang-specs.h. Possibly |