From: Daniel Dunbar Date: Sun, 29 Nov 2009 02:38:34 +0000 (+0000) Subject: Move MainFileName option variable into CodeGenOptions instead of LangOptions. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=7d065d0f21b35f445cee13730398bc2bec6edff2;p=clang Move MainFileName option variable into CodeGenOptions instead of LangOptions. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@90051 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Basic/LangOptions.h b/include/clang/Basic/LangOptions.h index 99c100d55e..513fefdb57 100644 --- a/include/clang/Basic/LangOptions.h +++ b/include/clang/Basic/LangOptions.h @@ -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(m); } - const char *getMainFileName() const { return MainFileName; } - void setMainFileName(const char *Name) { MainFileName = Name; } - VisibilityMode getVisibilityMode() const { return (VisibilityMode) SymbolVisibility; } diff --git a/include/clang/CodeGen/CodeGenOptions.h b/include/clang/CodeGen/CodeGenOptions.h index 02679cd998..4fd80dd4d2 100644 --- a/include/clang/CodeGen/CodeGenOptions.h +++ b/include/clang/CodeGen/CodeGenOptions.h @@ -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; diff --git a/lib/CodeGen/CGDebugInfo.cpp b/lib/CodeGen/CGDebugInfo.cpp index 558bb5bc96..317da7e46a 100644 --- a/lib/CodeGen/CGDebugInfo.cpp +++ b/lib/CodeGen/CGDebugInfo.cpp @@ -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)) diff --git a/lib/Driver/CC1Options.cpp b/lib/Driver/CC1Options.cpp index e65d3dc37b..1b07578e95 100644 --- a/lib/Driver/CC1Options.cpp +++ b/lib/Driver/CC1Options.cpp @@ -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) diff --git a/lib/Frontend/CompilerInvocation.cpp b/lib/Frontend/CompilerInvocation.cpp index be9bab16be..3925ff0648 100644 --- a/lib/Frontend/CompilerInvocation.cpp +++ b/lib/Frontend/CompilerInvocation.cpp @@ -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)); diff --git a/tools/clang-cc/Options.cpp b/tools/clang-cc/Options.cpp index ac555ab9a7..5484548359 100644 --- a/tools/clang-cc/Options.cpp +++ b/tools/clang-cc/Options.cpp @@ -141,6 +141,10 @@ static llvm::cl::opt GenerateDebugInfo("g", llvm::cl::desc("Generate source level debug information")); +static llvm::cl::opt +MainFileName("main-file-name", + llvm::cl::desc("Main file name to use for debug info")); + static llvm::cl::opt 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 -MainFileName("main-file-name", - llvm::cl::desc("Main file name to use for debug info")); - static llvm::cl::opt 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