]> granicus.if.org Git - clang/commitdiff
Add a -cc1-level option -fmodule-name=<name>, which will be used when
authorDouglas Gregor <dgregor@apple.com>
Tue, 15 Nov 2011 19:35:01 +0000 (19:35 +0000)
committerDouglas Gregor <dgregor@apple.com>
Tue, 15 Nov 2011 19:35:01 +0000 (19:35 +0000)
building modules.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@144680 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/LangOptions.h
include/clang/Driver/CC1Options.td
lib/Basic/LangOptions.cpp
lib/Frontend/CompilerInstance.cpp
lib/Frontend/CompilerInvocation.cpp
lib/Serialization/ASTReader.cpp
lib/Serialization/ASTWriter.cpp

index 688047ff5bdf9b060f116d5b147be548ecec3946..35c0ade7ec940ec4a9c8b73c719faff05cee55e2 100644 (file)
@@ -54,6 +54,9 @@ public:
   /// If none is specified, abort (GCC-compatible behaviour).
   std::string OverflowHandler;
 
+  /// \brief The name of the current module.
+  std::string CurrentModule;
+  
   LangOptions();
 
   // Define accessors/mutators for language options of enumeration type.
index 882805bc2fc0eac9dd7977122403cc0d940bb27d..2177aa5a72e04e5d4d88dd5dd7496c80efc827e4 100644 (file)
@@ -626,6 +626,9 @@ def nobuiltininc : Flag<"-nobuiltininc">,
 def fmodule_cache_path : Separate<"-fmodule-cache-path">, 
   MetaVarName<"<directory>">,
   HelpText<"Specify the module cache path">;           
+def fmodule_name : Joined<"-fmodule-name=">, 
+  MetaVarName<"<name>">,
+  HelpText<"Specify the name of the module to build">;           
 def fdisable_module_hash : Flag<"-fdisable-module-hash">,
   HelpText<"Disable the module hash">;
 def fauto_module_import : Flag<"-fauto-module-import">,
index 5f479dbb771cfeec4f422d61d383eb1313513aea..991992a477e487f6eb2be55f38b763120f8f66e8 100644 (file)
@@ -26,5 +26,7 @@ void LangOptions::resetNonModularOptions() {
 #define BENIGN_ENUM_LANGOPT(Name, Type, Bits, Default, Description) \
   Name = Default;
 #include "clang/Basic/LangOptions.def"
+  
+  CurrentModule.clear();
 }
 
index 0e3b25168f062c7b696062f30e7afa0d5740ff45..ea2c3bd6c6b86b65e25125f9010f297ab01300d1 100644 (file)
@@ -278,9 +278,7 @@ void CompilerInstance::createPreprocessor() {
     llvm::sys::path::append(SpecificModuleCache,
                             getInvocation().getModuleHash());
   PP->getHeaderSearchInfo().configureModules(SpecificModuleCache,
-    getPreprocessorOpts().ModuleBuildPath.empty()
-      ? std::string()
-      : getPreprocessorOpts().ModuleBuildPath.back());
+                                             getLangOpts().CurrentModule);
 
   // Handle generating dependencies, if requested.
   const DependencyOutputOptions &DepOpts = getDependencyOutputOpts();
@@ -992,6 +990,9 @@ static void compileModule(CompilerInstance &ImportingInstance,
   Invocation->getLangOpts().resetNonModularOptions();
   Invocation->getPreprocessorOpts().resetNonModularOptions();
 
+  // Note the name of the module we're building.
+  Invocation->getLangOpts().CurrentModule = ModuleName;
+
   // Note that this module is part of the module build path, so that we
   // can detect cycles in the module graph.
   Invocation->getPreprocessorOpts().ModuleBuildPath.push_back(ModuleName);
index c247e217376793b0e2aa0c4aea18143b716fe635..015288c85315bab05f37e71fd24e8e294e4b7494 100644 (file)
@@ -788,6 +788,8 @@ static void LangOptsToArgs(const LangOptions &Opts,
     Res.push_back("-fdeprecated-macro");
   if (Opts.ApplePragmaPack)
     Res.push_back("-fapple-pragma-pack");
+  if (!Opts.CurrentModule.empty())
+    Res.push_back("-fmodule-name=" + Opts.CurrentModule);
 }
 
 static void PreprocessorOptsToArgs(const PreprocessorOptions &Opts,
@@ -1785,6 +1787,7 @@ static void ParseLangArgs(LangOptions &Opts, ArgList &Args, InputKind IK,
   Opts.ParseUnknownAnytype = Args.hasArg(OPT_funknown_anytype);
   Opts.DebuggerSupport = Args.hasArg(OPT_fdebugger_support);
   Opts.ApplePragmaPack = Args.hasArg(OPT_fapple_pragma_pack);
+  Opts.CurrentModule = Args.getLastArgValue(OPT_fmodule_name);
 
   // Record whether the __DEPRECATED define was requested.
   Opts.Deprecated = Args.hasFlag(OPT_fdeprecated_macro,
index 6192fb77517c6e9a1225bc37ff96b1faf8147501..8961974856b67d5a02f41e75b2829eee3df53b13 100644 (file)
@@ -2789,6 +2789,10 @@ bool ASTReader::ParseLanguageOptions(
   LangOpts.set##Name(static_cast<LangOptions::Type>(Record[Idx++]));
 #include "clang/Basic/LangOptions.def"
     
+    unsigned Length = Record[Idx++];
+    LangOpts.CurrentModule.assign(Record.begin() + Idx, 
+                                  Record.begin() + Idx + Length);
+    Idx += Length;
     return Listener->ReadLanguageOptions(LangOpts);
   }
 
index 4fa3cf87564e2b06ba2a01804494de87c8298ec5..6893dbd9f578d8fd034d165b75b61a7a66db5940 100644 (file)
@@ -1063,6 +1063,9 @@ void ASTWriter::WriteLanguageOptions(const LangOptions &LangOpts) {
 #define ENUM_LANGOPT(Name, Type, Bits, Default, Description) \
   Record.push_back(static_cast<unsigned>(LangOpts.get##Name()));
 #include "clang/Basic/LangOptions.def"  
+  
+  Record.push_back(LangOpts.CurrentModule.size());
+  Record.append(LangOpts.CurrentModule.begin(), LangOpts.CurrentModule.end());
   Stream.EmitRecord(LANGUAGE_OPTIONS, Record);
 }