]> granicus.if.org Git - clang/commitdiff
Move MainFileName option variable into CodeGenOptions instead of LangOptions.
authorDaniel Dunbar <daniel@zuster.org>
Sun, 29 Nov 2009 02:38:34 +0000 (02:38 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Sun, 29 Nov 2009 02:38:34 +0000 (02:38 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@90051 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/LangOptions.h
include/clang/CodeGen/CodeGenOptions.h
lib/CodeGen/CGDebugInfo.cpp
lib/Driver/CC1Options.cpp
lib/Frontend/CompilerInvocation.cpp
tools/clang-cc/Options.cpp

index 99c100d55e7edc1a3b9f9222a96e5eff43614b00..513fefdb57a6444cb6dbf840bbf5aa5d79dce6eb 100644 (file)
@@ -101,11 +101,6 @@ private:
                                   // on making enums signed.  Set/Query this
                                   // value using accessors.
 
-  /// The user provided name for the "main file", if non-null. This is
-  /// useful in situations where the input file name does not match
-  /// the original input file, for example with -save-temps.
-  const char *MainFileName;
-
 public:
   unsigned InstantiationDepth;    // Maximum template instantiation depth.
 
@@ -164,8 +159,6 @@ public:
 
     CharIsSigned = 1;
     ShortWChar = 0;
-
-    MainFileName = 0;
   }
 
   GCMode getGCMode() const { return (GCMode) GC; }
@@ -178,9 +171,6 @@ public:
     StackProtector = static_cast<unsigned>(m);
   }
 
-  const char *getMainFileName() const { return MainFileName; }
-  void setMainFileName(const char *Name) { MainFileName = Name; }
-
   VisibilityMode getVisibilityMode() const {
     return (VisibilityMode) SymbolVisibility;
   }
index 02679cd998950b8ad17e69f46a3acad6b49cc96f..4fd80dd4d2b42b21ccfdab06e9d54997c84c2534 100644 (file)
@@ -52,6 +52,11 @@ public:
   /// Inlining - The kind of inlining to perform.
   InliningMethod Inlining;
 
+  /// The user provided name for the "main file", if non-empty. This is useful
+  /// in situations where the input file name does not match the original input
+  /// file, for example with -save-temps.
+  std::string MainFileName;
+
 public:
   CodeGenOptions() {
     OptimizationLevel = 0;
index 558bb5bc96412ae722f41330adef1f7cac464d9f..317da7e46a751d5e4af7c6564175554c1512bfb1 100644 (file)
@@ -95,10 +95,10 @@ llvm::DICompileUnit CGDebugInfo::getOrCreateCompileUnit(SourceLocation Loc) {
   // file at a time.
   bool isMain = false;
   const LangOptions &LO = M->getLangOptions();
-  const char *MainFileName = LO.getMainFileName();
+  const CodeGenOptions &CGO = M->getCodeGenOpts();
   if (isMainCompileUnitCreated == false) {
-    if (MainFileName) {
-      if (!strcmp(AbsFileName.getLast().c_str(), MainFileName))
+    if (!CGO.MainFileName.empty()) {
+      if (AbsFileName.getLast() == CGO.MainFileName)
         isMain = true;
     } else {
       if (Loc.isValid() && SM.isFromMainFile(Loc))
index e65d3dc37b3079e7ad04be724b660c343e641537..1b07578e956333e022bb2b62e6a078539d76ae5e 100644 (file)
@@ -172,6 +172,8 @@ static void ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args) {
   Opts.SimplifyLibCalls = 1;
   Opts.UnrollLoops = (Opts.OptimizationLevel > 1 && !Opts.OptimizeSize);
 
+  Opts.MainFileName = getLastArgValue(Args, OPT_main_file_name);
+
   // FIXME: Implement!
   // FIXME: Eliminate this dependency?
 //   if (Lang.NoBuiltin)
index be9bab16be1166af8b9252125db6c56bd4ff4b51..3925ff06482d48595305ab407eab9bfb5fab1165 100644 (file)
@@ -111,6 +111,10 @@ static void CodeGenOptsToArgs(const CodeGenOptions &Opts,
     Res.push_back("-Os");
   } else if (Opts.OptimizationLevel != 0)
     Res.push_back("-O" + llvm::utostr(Opts.OptimizationLevel));
+  if (!Opts.MainFileName.empty()) {
+    Res.push_back("-main-file-name");
+    Res.push_back(Opts.MainFileName);
+  }
   // SimplifyLibCalls is only derived.
   // TimePasses is only derived.
   // UnitAtATime is unused.
@@ -453,10 +457,6 @@ static void LangOptsToArgs(const LangOptions &Opts,
     Res.push_back("-stack-protector");
     Res.push_back(llvm::utostr(Opts.getStackProtectorMode()));
   }
-  if (Opts.getMainFileName()) {
-    Res.push_back("-main-file-name");
-    Res.push_back(Opts.getMainFileName());
-  }
   if (Opts.InstantiationDepth != DefaultLangOpts.InstantiationDepth) {
     Res.push_back("-ftemplate-depth");
     Res.push_back(llvm::utostr(Opts.InstantiationDepth));
index ac555ab9a7784962ebbf32cfec7a1c51136d0076..548454835913ce1641f8cfd17cf72ac6f6bd006d 100644 (file)
@@ -141,6 +141,10 @@ static llvm::cl::opt<bool>
 GenerateDebugInfo("g",
                   llvm::cl::desc("Generate source level debug information"));
 
+static llvm::cl::opt<std::string>
+MainFileName("main-file-name",
+             llvm::cl::desc("Main file name to use for debug info"));
+
 static llvm::cl::opt<bool>
 NoCommon("fno-common",
          llvm::cl::desc("Compile common globals like normal definitions"),
@@ -497,10 +501,6 @@ MSExtensions("fms-extensions",
              llvm::cl::desc("Accept some non-standard constructs used in "
                             "Microsoft header files "));
 
-static llvm::cl::opt<std::string>
-MainFileName("main-file-name",
-             llvm::cl::desc("Main file name to use for debug info"));
-
 static llvm::cl::opt<bool>
 NoMathErrno("fno-math-errno",
           llvm::cl::desc("Don't require math functions to respect errno"));
@@ -797,6 +797,9 @@ void clang::InitializeCodeGenOptions(CodeGenOptions &Opts,
 #ifdef NDEBUG
   Opts.VerifyModule = 0;
 #endif
+
+  if (MainFileName.getPosition())
+    Opts.MainFileName = MainFileName;
 }
 
 void clang::InitializeDependencyOutputOptions(DependencyOutputOptions &Opts) {
@@ -1051,23 +1054,6 @@ void clang::InitializeLangOptions(LangOptions &Options,
     Options.LaxVectorConversions = 1;
   }
 
-  if (ObjCExclusiveGC)
-    Options.setGCMode(LangOptions::GCOnly);
-  else if (ObjCEnableGC)
-    Options.setGCMode(LangOptions::HybridGC);
-
-  if (ObjCEnableGCBitmapPrint)
-    Options.ObjCGCBitmapPrint = 1;
-
-  if (AltiVec)
-    Options.AltiVec = 1;
-
-  if (PThread)
-    Options.POSIXThreads = 1;
-
-  Options.setVisibilityMode(SymbolVisibility);
-  Options.OverflowChecking = OverflowChecking;
-
   if (LangStd == LangStandard::lang_unspecified) {
     // Based on the base language, pick one.
     switch (IK) {
@@ -1106,6 +1092,23 @@ void clang::InitializeLangOptions(LangOptions &Options,
   if (Options.CPlusPlus)
     Options.CXXOperatorNames = !NoOperatorNames;
 
+  if (ObjCExclusiveGC)
+    Options.setGCMode(LangOptions::GCOnly);
+  else if (ObjCEnableGC)
+    Options.setGCMode(LangOptions::HybridGC);
+
+  if (ObjCEnableGCBitmapPrint)
+    Options.ObjCGCBitmapPrint = 1;
+
+  if (AltiVec)
+    Options.AltiVec = 1;
+
+  if (PThread)
+    Options.POSIXThreads = 1;
+
+  Options.setVisibilityMode(SymbolVisibility);
+  Options.OverflowChecking = OverflowChecking;
+
   // Mimicing gcc's behavior, trigraphs are only enabled if -trigraphs
   // is specified, or -std is set to a conforming mode.
   Options.Trigraphs = !Options.GNUMode;
@@ -1204,9 +1207,6 @@ void clang::InitializeLangOptions(LangOptions &Options,
     case 2: Options.setStackProtectorMode(LangOptions::SSPReq); break;
     }
   }
-
-  if (MainFileName.getPosition())
-    Options.setMainFileName(MainFileName.c_str());
 }
 
 void