[cfe-commits] r89917 - in /cfe/trunk: include/clang/Driver/CC1Options.td lib/Driver/CC1Options.cpp lib/Frontend/CompilerInvocation.cpp

Daniel Dunbar daniel at zuster.org
Wed Nov 25 18:14:07 PST 2009


Author: ddunbar
Date: Wed Nov 25 20:14:07 2009
New Revision: 89917

URL: http://llvm.org/viewvc/llvm-project?rev=89917&view=rev
Log:
Add clang -cc1 parsing for preprocessor options.

Modified:
    cfe/trunk/include/clang/Driver/CC1Options.td
    cfe/trunk/lib/Driver/CC1Options.cpp
    cfe/trunk/lib/Frontend/CompilerInvocation.cpp

Modified: cfe/trunk/include/clang/Driver/CC1Options.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/CC1Options.td?rev=89917&r1=89916&r2=89917&view=diff

==============================================================================
--- cfe/trunk/include/clang/Driver/CC1Options.td (original)
+++ cfe/trunk/include/clang/Driver/CC1Options.td Wed Nov 25 20:14:07 2009
@@ -333,9 +333,9 @@
   HelpText<"Disable standard #include directories">;
 def nobuiltininc : Flag<"-nobuiltininc">,
   HelpText<"Disable builtin #include directories">;
-def F : Separate<"-F">, MetaVarName<"directory">,
+def F : JoinedOrSeparate<"-F">, MetaVarName<"directory">,
   HelpText<"Add directory to framework include search path">;
-def I : Separate<"-I">, MetaVarName<"directory">,
+def I : JoinedOrSeparate<"-I">, MetaVarName<"directory">,
   HelpText<"Add directory to include search path">;
 def idirafter : Separate<"-idirafter">, MetaVarName<"directory">,
   HelpText<"Add directory to AFTER include search path">;
@@ -357,7 +357,7 @@
 // Preprocessor Options
 //===----------------------------------------------------------------------===//
 
-def D : Separate<"-D">, MetaVarName<"macro">,
+def D : JoinedOrSeparate<"-D">, MetaVarName<"macro">,
   HelpText<"Predefine the specified macro">;
 def include_ : Separate<"-include">, MetaVarName<"file">, EnumName<"include">,
   HelpText<"Include file before parsing">;
@@ -369,7 +369,7 @@
   HelpText<"Include file before parsing">;
 def token_cache : Separate<"-token-cache">, MetaVarName<"path">,
   HelpText<"Use specified token cache file">;
-def U : Separate<"-U">, MetaVarName<"macro">,
+def U : JoinedOrSeparate<"-U">, MetaVarName<"macro">,
   HelpText<"Undefine the specified macro">;
 def undef : Flag<"-undef">, MetaVarName<"macro">,
   HelpText<"undef all system defines">;

Modified: cfe/trunk/lib/Driver/CC1Options.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/CC1Options.cpp?rev=89917&r1=89916&r2=89917&view=diff

==============================================================================
--- cfe/trunk/lib/Driver/CC1Options.cpp (original)
+++ cfe/trunk/lib/Driver/CC1Options.cpp Wed Nov 25 20:14:07 2009
@@ -13,6 +13,7 @@
 #include "clang/Driver/OptTable.h"
 #include "clang/Driver/Option.h"
 #include "clang/Frontend/CompilerInvocation.h"
+#include "clang/Frontend/PCHReader.h"
 #include "llvm/ADT/OwningPtr.h"
 #include "llvm/ADT/StringSwitch.h"
 #include "llvm/ADT/SmallVector.h"
@@ -356,7 +357,7 @@
 
 static void ParseHeaderSearchArgs(HeaderSearchOptions &Opts, ArgList &Args) {
   using namespace cc1options;
-  Opts.Sysroot = getLastArgValue(Args, OPT_isysroot);
+  Opts.Sysroot = getLastArgValue(Args, OPT_isysroot, "/");
   Opts.Verbose = Args.hasArg(OPT_v);
   Opts.UseStandardIncludes = !Args.hasArg(OPT_nostdinc);
   Opts.BuiltinIncludePath = "";
@@ -401,6 +402,43 @@
 }
 
 static void ParsePreprocessorArgs(PreprocessorOptions &Opts, ArgList &Args) {
+  using namespace cc1options;
+  Opts.ImplicitPCHInclude = getLastArgValue(Args, OPT_include_pch);
+  Opts.ImplicitPTHInclude = getLastArgValue(Args, OPT_include_pth);
+  Opts.TokenCache = getLastArgValue(Args, OPT_token_cache);
+  Opts.UsePredefines = !Args.hasArg(OPT_undef);
+
+  // Add macros from the command line.
+  for (arg_iterator it = Args.filtered_begin(OPT_D, OPT_U),
+         ie = Args.filtered_end(); it != ie; ++it) {
+    if (it->getOption().matches(OPT_D))
+      Opts.addMacroDef(it->getValue(Args));
+    else
+      Opts.addMacroUndef(it->getValue(Args));
+  }
+
+  Opts.MacroIncludes = getAllArgValues(Args, OPT_imacros);
+
+  // Add the ordered list of -includes.
+  for (arg_iterator it = Args.filtered_begin(OPT_include, OPT_include_pch,
+                                             OPT_include_pth),
+         ie = Args.filtered_end(); it != ie; ++it) {
+    // PCH is handled specially, we need to extra the original include path.
+    if (it->getOption().matches(OPT_include_pch)) {
+      // FIXME: Disabled for now, I don't want to incur the cost of linking in
+      // Sema and all until we are actually going to use it. Alternatively this
+      // could be factored out somehow.
+      //        PCHReader::getOriginalSourceFile(it->getValue(Args));
+      std::string OriginalFile = "FIXME";
+
+      // FIXME: Don't fail like this.
+      if (OriginalFile.empty())
+        exit(1);
+
+      Opts.Includes.push_back(OriginalFile);
+    } else
+      Opts.Includes.push_back(it->getValue(Args));
+  }
 }
 
 static void ParsePreprocessorOutputArgs(PreprocessorOutputOptions &Opts,

Modified: cfe/trunk/lib/Frontend/CompilerInvocation.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInvocation.cpp?rev=89917&r1=89916&r2=89917&view=diff

==============================================================================
--- cfe/trunk/lib/Frontend/CompilerInvocation.cpp (original)
+++ cfe/trunk/lib/Frontend/CompilerInvocation.cpp Wed Nov 25 20:14:07 2009
@@ -470,28 +470,34 @@
 static void PreprocessorOptsToArgs(const PreprocessorOptions &Opts,
                                    std::vector<std::string> &Res) {
   for (unsigned i = 0, e = Opts.Macros.size(); i != e; ++i)
-    Res.push_back((Opts.Macros[i].second ? "-U" : "-D") + Opts.Macros[i].first);
+    Res.push_back(std::string(Opts.Macros[i].second ? "-U" : "-D") +
+                  Opts.Macros[i].first);
   for (unsigned i = 0, e = Opts.Includes.size(); i != e; ++i) {
+    // FIXME: We need to avoid reincluding the implicit PCH and PTH includes.
     Res.push_back("-include");
     Res.push_back(Opts.Includes[i]);
   }
   for (unsigned i = 0, e = Opts.MacroIncludes.size(); i != e; ++i) {
     Res.push_back("-imacros");
-    Res.push_back(Opts.Includes[i]);
+    Res.push_back(Opts.MacroIncludes[i]);
   }
   if (!Opts.UsePredefines)
     Res.push_back("-undef");
   if (!Opts.ImplicitPCHInclude.empty()) {
-    Res.push_back("-implicit-pch-include");
+    Res.push_back("-include-pch");
     Res.push_back(Opts.ImplicitPCHInclude);
   }
   if (!Opts.ImplicitPTHInclude.empty()) {
-    Res.push_back("-implicit-pth-include");
+    Res.push_back("-include-pth");
     Res.push_back(Opts.ImplicitPTHInclude);
   }
   if (!Opts.TokenCache.empty()) {
-    Res.push_back("-token-cache");
-    Res.push_back(Opts.TokenCache);
+    if (Opts.ImplicitPTHInclude.empty()) {
+      Res.push_back("-token-cache");
+      Res.push_back(Opts.TokenCache);
+    } else
+      assert(Opts.ImplicitPTHInclude == Opts.TokenCache &&
+             "Unsupported option combination!");
   }
 }
 





More information about the cfe-commits mailing list