From 4a2623caaba77a42e83998f511804ba230c042ae Mon Sep 17 00:00:00 2001 From: Nathan Sidwell Date: Thu, 21 Jun 2018 20:04:36 +0000 Subject: [PATCH] c.opt: Add -fmodule-header. gcc/c-family/ * c.opt: Add -fmodule-header. gcc/cp/ * lang-specs.h: Add legacy import options. * module.c (module_header_name): New. (init_module_processing): Default it. (handle_module_option): Set it. From-SVN: r261862 --- ChangeLog.modules | 8 ++++++++ gcc/c-family/c.opt | 8 ++++++++ gcc/cp/lang-specs.h | 47 ++++++++++++++++++++++++--------------------- gcc/cp/module.c | 40 +++++++++++++++++++++++++++++++++++--- gcc/doc/invoke.texi | 4 ++-- 5 files changed, 80 insertions(+), 27 deletions(-) diff --git a/ChangeLog.modules b/ChangeLog.modules index d35e2b25fef5..d1136455b8c0 100644 --- a/ChangeLog.modules +++ b/ChangeLog.modules @@ -1,5 +1,13 @@ 2018-06-21 Nathan Sidwell + gcc/c-family/ + * c.opt: Add -fmodule-header. + gcc/cp/ + * lang-specs.h: Add legacy import options. + * module.c (module_header_name): New. + (init_module_processing): Default it. + (handle_module_option): Set it. + Use getaddrinfo, not gethostbyname2 gcc/ * configure.ac (HAVE_AF_INET6): Test for getaddrinfo. diff --git a/gcc/c-family/c.opt b/gcc/c-family/c.opt index b75627a6e828..2bba082a32b1 100644 --- a/gcc/c-family/c.opt +++ b/gcc/c-family/c.opt @@ -1532,6 +1532,14 @@ fno-modules C++ ObjC++ Driver Undocumented RejectNegative Var(flag_modules,0) Integer ;; undocumented +fmodule-header +C++ ObjC Driver Undocumented RejectNegative +;; undocumented + +fmodule-header= +C++ ObjC++ Driver Joined RejectNegative MissingArgError(missing header name) +ATOM legacy import name + fmodule-mapper= C++ ObjC++ Driver Joined RejectNegative MissingArgError(missing mapper) Mapper for module to BMI files diff --git a/gcc/cp/lang-specs.h b/gcc/cp/lang-specs.h index 9d47101f211f..50abbfbbf746 100644 --- a/gcc/cp/lang-specs.h +++ b/gcc/cp/lang-specs.h @@ -40,29 +40,32 @@ along with GCC; see the file COPYING3. If not see {".tcc", "@c++-header", 0, 0, 0}, {".hh", "@c++-header", 0, 0, 0}, {"@c++-header", - "%{E|M|MM:cc1plus -E %(cpp_options) %2 %(cpp_debug_options)}\ - %{!E:%{!M:%{!MM:\ - %{save-temps*|no-integrated-cpp:cc1plus -E\ - %(cpp_options) %2 -o %{save-temps*:%b.ii} %{!save-temps*:%g.ii} \n}\ - cc1plus %{save-temps*|no-integrated-cpp:-fpreprocessed %{save-temps*:%b.ii} %{!save-temps*:%g.ii}}\ - %{!save-temps*:%{!no-integrated-cpp:%(cpp_unique_options)}}\ - %(cc1_options) %2\ - %{!fsyntax-only:%{!S:-o %g.s} \ - %{!fdump-ada-spec*:%{!o*:--output-pch=%i.gch}\ - %W{o*:--output-pch=%*}}%V}}}}", + "%{E|M|MM:cc1plus -E %(cpp_options) %2 %(cpp_debug_options)}" + "%{!E:%{!M:%{!MM:" + " %{save-temps*|no-integrated-cpp:cc1plus -E" + " %(cpp_options) %2 -o %{save-temps*:%b.ii} %{!save-temps*:%g.ii} \n}" + " cc1plus %{save-temps*|no-integrated-cpp:-fpreprocessed" + " %{save-temps*:%b.ii} %{!save-temps*:%g.ii}}" + " %{!save-temps*:%{!no-integrated-cpp:%(cpp_unique_options)}}" + " %(cc1_options) %2" + " %{fmodules-atom:%{fmodule-header*:-fmodule-header}}" + " %{!fsyntax-only:%{!S:-o %g.s}" + " %{!fdump-ada-spec*:%{!fmodules-atom:" + " %{!o*:--output-pch=%i.gch}%W{o*:--output-pch=%*}}%V}}}}}", CPLUSPLUS_CPP_SPEC, 0, 0}, {"@c++", - "%{E|M|MM:cc1plus -E %{fmodule-prefix*} %(cpp_options) %2 %(cpp_debug_options)}\ - %{!E:%{!M:%{!MM:\ - %{save-temps*|no-integrated-cpp:cc1plus -E\ - %(cpp_options) %2 -o %{save-temps*:%b.ii} %{!save-temps*:%g.ii} \n}\ - cc1plus %{save-temps*|no-integrated-cpp:-fpreprocessed %{save-temps*:%b.ii} %{!save-temps*:%g.ii}}\ - %{!save-temps*:%{!no-integrated-cpp:%(cpp_unique_options)}}\ - %(cc1_options) %2\ - %{!fsyntax-only:%(invoke_as)}}}}", - CPLUSPLUS_CPP_SPEC, 0, 0}, + "%{E|M|MM:cc1plus -E %(cpp_options) %2 %(cpp_debug_options)}" + "%{!E:%{!M:%{!MM:" + " %{save-temps*|no-integrated-cpp:cc1plus -E" + " %(cpp_options) %2 -o %{save-temps*:%b.ii} %{!save-temps*:%g.ii} \n}" + " cc1plus %{save-temps*|no-integrated-cpp:-fpreprocessed" + " %{save-temps*:%b.ii} %{!save-temps*:%g.ii}}" + " %{!save-temps*:%{!no-integrated-cpp:%(cpp_unique_options)}}" + " %(cc1_options) %2" + " %{!fsyntax-only:%(invoke_as)}}}}", + CPLUSPLUS_CPP_SPEC, 0, 0}, {".ii", "@c++-cpp-output", 0, 0, 0}, {"@c++-cpp-output", - "%{!M:%{!MM:%{!E:\ - cc1plus -fpreprocessed %i %(cc1_options) %2\ - %{!fsyntax-only:%(invoke_as)}}}}", 0, 0, 0}, + "%{!E:%{!M:%{!MM:" + " cc1plus -fpreprocessed %i %(cc1_options) %2" + " %{!fsyntax-only:%(invoke_as)}}}}", 0, 0, 0}, diff --git a/gcc/cp/module.c b/gcc/cp/module.c index b24fe55a100c..597627dcefae 100644 --- a/gcc/cp/module.c +++ b/gcc/cp/module.c @@ -2827,6 +2827,9 @@ bool module_state_hash::equal (const value_type existing, /* Mapper name. */ static const char *module_mapper_name; +/* Legacy header mode. */ +static const char *module_header_name; + /* BMI repository path and workspace. */ static char *bmi_repo; static size_t bmi_repo_length; @@ -10736,8 +10739,28 @@ atom_module_preamble (location_t loc, line_maps *lmaps) void init_module_processing () { - if (pch_file) - error ("modules and PCH are incompatible"); + gcc_assert (pch_file); + + if (module_header_name && !module_header_name[0]) + { + /* Set the module header name from the main_input_filename. */ + const char *main = main_input_filename; + size_t len = strlen (main); + for (; len >= 2; len--) + if (IS_DIR_SEPARATOR (main[len-1])) + { + /* Is this '//' or '/./'? */ + size_t peek = len - 2; + if (peek && main[peek] == '.') + peek--; + if (IS_DIR_SEPARATOR (main[peek])) + break; + } + if (len < 2) + len = 0; + module_header_name = main + len; + else + } module_state::init (); } @@ -10844,7 +10867,9 @@ maybe_repeat_preamble (location_t loc, int count ATTRIBUTE_UNUSED, cpp_reader *) } /* If CODE is a module option, handle it & return true. Otherwise - return false. */ + return false. For unknown reasons I cannot get the option + generation machinery to set fmodule-mapper pr -fmodule-header to + make a string type option variable. */ bool handle_module_option (unsigned code, const char *str, int num) @@ -10861,6 +10886,15 @@ handle_module_option (unsigned code, const char *str, int num) flag_module_preamble = num; return true; + case OPT_fmodule_header: + str=""; + /* FALLTHROUGH. */ + case OPT_fmodule_header_: + module_header_name = str; + /* Force atom. */ + flag_modules = -1; + return true; + default: return false; } diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index 4656336b6e3b..2fd1b9f487c5 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -488,7 +488,7 @@ Objective-C and Objective-C++ Dialects}. -dD -dI -dM -dN -dU @gol -fdebug-cpp -fdirectives-only -fdollars-in-identifiers @gol -fexec-charset=@var{charset} -fextended-identifiers @gol --finput-charset=@var{charset} -fmodule-prefix @gol +-finput-charset=@var{charset} -fmodule-preamble @gol -fmacro-prefix-map=@var{old}=@var{new} @gol -fno-canonical-system-headers @gol -fpch-deps -fpch-preprocess @gol -fpreprocessed -ftabstop=@var{width} -ftrack-macro-expansion @gol @@ -29471,7 +29471,7 @@ Usually importing a module will load minimal information, defering the bulk of the loading to the point at which name-lookup inspects a particular namespace-scope name. -The @option{-fmodule-prefix} option may be added when preprocessing with +The @option{-fmodule-preamble} option may be added when preprocessing with @option{-E}. This causes preprocessing to terminate once the Atom preamble is processed. Build systems may need to determine the set of imports a compilation needed, and this allows that without the expense