Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 1 | //===--- CompilerInvocation.cpp -------------------------------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #include "clang/Frontend/CompilerInvocation.h" |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 11 | #include "clang/Basic/Diagnostic.h" |
| 12 | #include "clang/Basic/Version.h" |
Argyrios Kyrtzidis | 389db16 | 2010-11-03 22:45:23 +0000 | [diff] [blame] | 13 | #include "clang/Basic/FileManager.h" |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 14 | #include "clang/Driver/Arg.h" |
| 15 | #include "clang/Driver/ArgList.h" |
| 16 | #include "clang/Driver/CC1Options.h" |
| 17 | #include "clang/Driver/DriverDiagnostic.h" |
| 18 | #include "clang/Driver/OptTable.h" |
| 19 | #include "clang/Driver/Option.h" |
| 20 | #include "clang/Frontend/CompilerInvocation.h" |
| 21 | #include "clang/Frontend/LangStandard.h" |
Sebastian Redl | 6ab7cd8 | 2010-08-18 23:57:17 +0000 | [diff] [blame] | 22 | #include "clang/Serialization/ASTReader.h" |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 23 | #include "llvm/ADT/OwningPtr.h" |
| 24 | #include "llvm/ADT/SmallVector.h" |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 25 | #include "llvm/ADT/StringExtras.h" |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 26 | #include "llvm/ADT/StringSwitch.h" |
Duncan Sands | 2dc1453 | 2010-08-30 09:42:39 +0000 | [diff] [blame] | 27 | #include "llvm/ADT/Triple.h" |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 28 | #include "llvm/Support/ErrorHandling.h" |
Michael J. Spencer | 03013fa | 2010-11-29 18:12:39 +0000 | [diff] [blame] | 29 | #include "llvm/Support/Host.h" |
| 30 | #include "llvm/Support/Path.h" |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 31 | using namespace clang; |
| 32 | |
Ted Kremenek | d3b74d9 | 2011-11-17 23:01:24 +0000 | [diff] [blame] | 33 | //===----------------------------------------------------------------------===// |
| 34 | // Initialization. |
| 35 | //===----------------------------------------------------------------------===// |
| 36 | |
Ted Kremenek | 8a0c5c2 | 2011-11-18 04:32:13 +0000 | [diff] [blame] | 37 | CompilerInvocationBase::CompilerInvocationBase() |
Ted Kremenek | d3b74d9 | 2011-11-17 23:01:24 +0000 | [diff] [blame] | 38 | : LangOpts(new LangOptions()) {} |
| 39 | |
Ted Kremenek | 8a0c5c2 | 2011-11-18 04:32:13 +0000 | [diff] [blame] | 40 | CompilerInvocationBase::CompilerInvocationBase(const CompilerInvocationBase &X) |
Benjamin Kramer | 85224ae | 2011-11-29 11:31:35 +0000 | [diff] [blame] | 41 | : llvm::RefCountedBase<CompilerInvocation>(), |
| 42 | LangOpts(new LangOptions(*X.getLangOpts())) {} |
Ted Kremenek | d3b74d9 | 2011-11-17 23:01:24 +0000 | [diff] [blame] | 43 | |
| 44 | //===----------------------------------------------------------------------===// |
| 45 | // Utility functions. |
| 46 | //===----------------------------------------------------------------------===// |
| 47 | |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 48 | static const char *getAnalysisStoreName(AnalysisStores Kind) { |
| 49 | switch (Kind) { |
| 50 | default: |
Jeffrey Yasskin | 9f61aa9 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 51 | llvm_unreachable("Unknown analysis store!"); |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 52 | #define ANALYSIS_STORE(NAME, CMDFLAG, DESC, CREATFN) \ |
| 53 | case NAME##Model: return CMDFLAG; |
| 54 | #include "clang/Frontend/Analyses.def" |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | static const char *getAnalysisConstraintName(AnalysisConstraints Kind) { |
| 59 | switch (Kind) { |
| 60 | default: |
Jeffrey Yasskin | 9f61aa9 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 61 | llvm_unreachable("Unknown analysis constraints!"); |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 62 | #define ANALYSIS_CONSTRAINTS(NAME, CMDFLAG, DESC, CREATFN) \ |
| 63 | case NAME##Model: return CMDFLAG; |
| 64 | #include "clang/Frontend/Analyses.def" |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | static const char *getAnalysisDiagClientName(AnalysisDiagClients Kind) { |
| 69 | switch (Kind) { |
| 70 | default: |
Jeffrey Yasskin | 9f61aa9 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 71 | llvm_unreachable("Unknown analysis client!"); |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 72 | #define ANALYSIS_DIAGNOSTICS(NAME, CMDFLAG, DESC, CREATFN, AUTOCREATE) \ |
| 73 | case PD_##NAME: return CMDFLAG; |
| 74 | #include "clang/Frontend/Analyses.def" |
| 75 | } |
| 76 | } |
| 77 | |
Anna Zaks | d309528 | 2011-09-30 02:03:00 +0000 | [diff] [blame] | 78 | static const char *getAnalysisPurgeModeName(AnalysisPurgeMode Kind) { |
| 79 | switch (Kind) { |
| 80 | default: |
| 81 | llvm_unreachable("Unknown analysis client!"); |
| 82 | #define ANALYSIS_PURGE(NAME, CMDFLAG, DESC) \ |
| 83 | case NAME: return CMDFLAG; |
| 84 | #include "clang/Frontend/Analyses.def" |
| 85 | } |
| 86 | } |
| 87 | |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 88 | //===----------------------------------------------------------------------===// |
| 89 | // Serialization (to args) |
| 90 | //===----------------------------------------------------------------------===// |
| 91 | |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 92 | static void AnalyzerOptsToArgs(const AnalyzerOptions &Opts, |
| 93 | std::vector<std::string> &Res) { |
Argyrios Kyrtzidis | 116f364 | 2011-02-25 00:09:51 +0000 | [diff] [blame] | 94 | if (Opts.ShowCheckerHelp) |
| 95 | Res.push_back("-analyzer-checker-help"); |
Ted Kremenek | a4c7a43 | 2011-07-28 23:08:16 +0000 | [diff] [blame] | 96 | if (Opts.AnalysisStoreOpt != RegionStoreModel) { |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 97 | Res.push_back("-analyzer-store"); |
| 98 | Res.push_back(getAnalysisStoreName(Opts.AnalysisStoreOpt)); |
| 99 | } |
| 100 | if (Opts.AnalysisConstraintsOpt != RangeConstraintsModel) { |
| 101 | Res.push_back("-analyzer-constraints"); |
| 102 | Res.push_back(getAnalysisConstraintName(Opts.AnalysisConstraintsOpt)); |
| 103 | } |
| 104 | if (Opts.AnalysisDiagOpt != PD_HTML) { |
| 105 | Res.push_back("-analyzer-output"); |
| 106 | Res.push_back(getAnalysisDiagClientName(Opts.AnalysisDiagOpt)); |
| 107 | } |
Anna Zaks | d309528 | 2011-09-30 02:03:00 +0000 | [diff] [blame] | 108 | if (Opts.AnalysisPurgeOpt != PurgeStmt) { |
| 109 | Res.push_back("-analyzer-purge"); |
| 110 | Res.push_back(getAnalysisPurgeModeName(Opts.AnalysisPurgeOpt)); |
| 111 | } |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 112 | if (!Opts.AnalyzeSpecificFunction.empty()) { |
| 113 | Res.push_back("-analyze-function"); |
| 114 | Res.push_back(Opts.AnalyzeSpecificFunction); |
| 115 | } |
| 116 | if (Opts.AnalyzeAll) |
| 117 | Res.push_back("-analyzer-opt-analyze-headers"); |
| 118 | if (Opts.AnalyzerDisplayProgress) |
| 119 | Res.push_back("-analyzer-display-progress"); |
Ted Kremenek | fc57651 | 2009-12-07 22:06:12 +0000 | [diff] [blame] | 120 | if (Opts.AnalyzeNestedBlocks) |
| 121 | Res.push_back("-analyzer-opt-analyze-nested-blocks"); |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 122 | if (Opts.EagerlyAssume) |
| 123 | Res.push_back("-analyzer-eagerly-assume"); |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 124 | if (Opts.TrimGraph) |
| 125 | Res.push_back("-trim-egraph"); |
| 126 | if (Opts.VisualizeEGDot) |
| 127 | Res.push_back("-analyzer-viz-egraph-graphviz"); |
Sandeep Patel | 1040c22 | 2011-03-16 19:14:34 +0000 | [diff] [blame] | 128 | if (Opts.VisualizeEGUbi) |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 129 | Res.push_back("-analyzer-viz-egraph-ubigraph"); |
Argyrios Kyrtzidis | 43dee22 | 2011-02-14 18:13:31 +0000 | [diff] [blame] | 130 | |
| 131 | for (unsigned i = 0, e = Opts.CheckersControlList.size(); i != e; ++i) { |
| 132 | const std::pair<std::string, bool> &opt = Opts.CheckersControlList[i]; |
| 133 | if (opt.second) |
| 134 | Res.push_back("-analyzer-disable-checker"); |
| 135 | else |
| 136 | Res.push_back("-analyzer-checker"); |
| 137 | Res.push_back(opt.first); |
| 138 | } |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 139 | } |
| 140 | |
| 141 | static void CodeGenOptsToArgs(const CodeGenOptions &Opts, |
| 142 | std::vector<std::string> &Res) { |
| 143 | if (Opts.DebugInfo) |
| 144 | Res.push_back("-g"); |
| 145 | if (Opts.DisableLLVMOpts) |
| 146 | Res.push_back("-disable-llvm-optzns"); |
| 147 | if (Opts.DisableRedZone) |
| 148 | Res.push_back("-disable-red-zone"); |
Nick Lewycky | 7c4fd91 | 2011-10-21 02:32:14 +0000 | [diff] [blame] | 149 | if (!Opts.DebugCompilationDir.empty()) { |
| 150 | Res.push_back("-fdebug-compilation-dir"); |
| 151 | Res.push_back(Opts.DebugCompilationDir); |
| 152 | } |
Daniel Dunbar | f2d8b9f | 2009-12-18 02:43:17 +0000 | [diff] [blame] | 153 | if (!Opts.DwarfDebugFlags.empty()) { |
| 154 | Res.push_back("-dwarf-debug-flags"); |
| 155 | Res.push_back(Opts.DwarfDebugFlags); |
| 156 | } |
John McCall | 9f084a3 | 2011-07-06 00:26:06 +0000 | [diff] [blame] | 157 | if (Opts.ObjCRuntimeHasARC) |
| 158 | Res.push_back("-fobjc-runtime-has-arc"); |
John McCall | 256a76e | 2011-07-06 01:22:26 +0000 | [diff] [blame] | 159 | if (Opts.ObjCRuntimeHasTerminate) |
| 160 | Res.push_back("-fobjc-runtime-has-terminate"); |
Nick Lewycky | e8ba8d7 | 2011-04-21 23:44:07 +0000 | [diff] [blame] | 161 | if (Opts.EmitGcovArcs) |
| 162 | Res.push_back("-femit-coverage-data"); |
| 163 | if (Opts.EmitGcovNotes) |
| 164 | Res.push_back("-femit-coverage-notes"); |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 165 | if (!Opts.MergeAllConstants) |
| 166 | Res.push_back("-fno-merge-all-constants"); |
Daniel Dunbar | 50a4487 | 2009-11-20 17:23:30 +0000 | [diff] [blame] | 167 | if (Opts.NoCommon) |
| 168 | Res.push_back("-fno-common"); |
John McCall | 3209669 | 2011-03-18 02:56:14 +0000 | [diff] [blame] | 169 | if (Opts.ForbidGuardVariables) |
| 170 | Res.push_back("-fforbid-guard-variables"); |
Daniel Dunbar | e26bdb9 | 2011-06-21 18:54:46 +0000 | [diff] [blame] | 171 | if (Opts.UseRegisterSizedBitfieldAccess) |
| 172 | Res.push_back("-fuse-register-sized-bitfield-access"); |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 173 | if (Opts.NoImplicitFloat) |
| 174 | Res.push_back("-no-implicit-float"); |
Daniel Dunbar | 1ad6648 | 2010-07-01 01:31:45 +0000 | [diff] [blame] | 175 | if (Opts.OmitLeafFramePointer) |
| 176 | Res.push_back("-momit-leaf-frame-pointer"); |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 177 | if (Opts.OptimizeSize) { |
| 178 | assert(Opts.OptimizationLevel == 2 && "Invalid options!"); |
Bob Wilson | a0fa203 | 2011-04-29 22:49:50 +0000 | [diff] [blame] | 179 | Opts.OptimizeSize == 1 ? Res.push_back("-Os") : Res.push_back("-Oz"); |
Daniel Dunbar | 1be3b3b | 2009-11-19 20:54:59 +0000 | [diff] [blame] | 180 | } else if (Opts.OptimizationLevel != 0) |
| 181 | Res.push_back("-O" + llvm::utostr(Opts.OptimizationLevel)); |
Daniel Dunbar | 7d065d0 | 2009-11-29 02:38:34 +0000 | [diff] [blame] | 182 | if (!Opts.MainFileName.empty()) { |
| 183 | Res.push_back("-main-file-name"); |
| 184 | Res.push_back(Opts.MainFileName); |
| 185 | } |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 186 | // SimplifyLibCalls is only derived. |
| 187 | // TimePasses is only derived. |
| 188 | // UnitAtATime is unused. |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 189 | // Inlining is only derived. |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 190 | |
Eric Christopher | f84d409 | 2010-08-07 23:08:14 +0000 | [diff] [blame] | 191 | // UnrollLoops is derived, but also accepts an option, no |
| 192 | // harm in pushing it back here. |
| 193 | if (Opts.UnrollLoops) |
| 194 | Res.push_back("-funroll-loops"); |
Chris Lattner | bbea716 | 2010-04-13 00:38:24 +0000 | [diff] [blame] | 195 | if (Opts.DataSections) |
| 196 | Res.push_back("-fdata-sections"); |
| 197 | if (Opts.FunctionSections) |
| 198 | Res.push_back("-ffunction-sections"); |
Daniel Dunbar | f219e7c | 2009-11-29 07:18:39 +0000 | [diff] [blame] | 199 | if (Opts.AsmVerbose) |
| 200 | Res.push_back("-masm-verbose"); |
| 201 | if (!Opts.CodeModel.empty()) { |
| 202 | Res.push_back("-mcode-model"); |
| 203 | Res.push_back(Opts.CodeModel); |
| 204 | } |
Peter Collingbourne | d51e43a | 2011-10-06 18:29:46 +0000 | [diff] [blame] | 205 | if (Opts.CUDAIsDevice) |
| 206 | Res.push_back("-fcuda-is-device"); |
Daniel Dunbar | efb0fa9 | 2010-03-20 04:15:41 +0000 | [diff] [blame] | 207 | if (!Opts.CXAAtExit) |
| 208 | Res.push_back("-fno-use-cxa-atexit"); |
| 209 | if (Opts.CXXCtorDtorAliases) |
| 210 | Res.push_back("-mconstructor-aliases"); |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 211 | if (Opts.ObjCAutoRefCountExceptions) |
| 212 | Res.push_back("-fobjc-arc-eh"); |
Daniel Dunbar | f219e7c | 2009-11-29 07:18:39 +0000 | [diff] [blame] | 213 | if (!Opts.DebugPass.empty()) { |
| 214 | Res.push_back("-mdebug-pass"); |
| 215 | Res.push_back(Opts.DebugPass); |
| 216 | } |
| 217 | if (Opts.DisableFPElim) |
| 218 | Res.push_back("-mdisable-fp-elim"); |
Daniel Dunbar | 3b31526 | 2009-11-30 08:42:00 +0000 | [diff] [blame] | 219 | if (!Opts.FloatABI.empty()) { |
| 220 | Res.push_back("-mfloat-abi"); |
| 221 | Res.push_back(Opts.FloatABI); |
| 222 | } |
Daniel Dunbar | f219e7c | 2009-11-29 07:18:39 +0000 | [diff] [blame] | 223 | if (!Opts.LimitFloatPrecision.empty()) { |
| 224 | Res.push_back("-mlimit-float-precision"); |
| 225 | Res.push_back(Opts.LimitFloatPrecision); |
| 226 | } |
| 227 | if (Opts.NoZeroInitializedInBSS) |
| 228 | Res.push_back("-mno-zero-initialized-bss"); |
Daniel Dunbar | f643b9b | 2010-04-24 17:56:46 +0000 | [diff] [blame] | 229 | switch (Opts.getObjCDispatchMethod()) { |
| 230 | case CodeGenOptions::Legacy: |
| 231 | break; |
| 232 | case CodeGenOptions::Mixed: |
| 233 | Res.push_back("-fobjc-dispatch-method=mixed"); |
| 234 | break; |
| 235 | case CodeGenOptions::NonLegacy: |
| 236 | Res.push_back("-fobjc-dispatch-method=non-legacy"); |
| 237 | break; |
| 238 | } |
Daniel Dunbar | 17d3fea | 2011-02-09 17:54:19 +0000 | [diff] [blame] | 239 | if (Opts.NumRegisterParameters) { |
| 240 | Res.push_back("-mregparm"); |
| 241 | Res.push_back(llvm::utostr(Opts.NumRegisterParameters)); |
| 242 | } |
Chad Rosier | 1b90605 | 2011-08-26 00:26:29 +0000 | [diff] [blame] | 243 | if (Opts.NoGlobalMerge) |
| 244 | Res.push_back("-mno-global-merge"); |
Nick Lewycky | c3b9014 | 2011-06-21 00:14:18 +0000 | [diff] [blame] | 245 | if (Opts.NoExecStack) |
| 246 | Res.push_back("-mnoexecstack"); |
Daniel Dunbar | 4ecc9b7 | 2010-05-27 05:39:39 +0000 | [diff] [blame] | 247 | if (Opts.RelaxAll) |
| 248 | Res.push_back("-mrelax-all"); |
Daniel Dunbar | 9693232 | 2011-03-28 22:49:28 +0000 | [diff] [blame] | 249 | if (Opts.SaveTempLabels) |
| 250 | Res.push_back("-msave-temp-labels"); |
Rafael Espindola | f24a151 | 2011-04-30 18:35:43 +0000 | [diff] [blame] | 251 | if (Opts.NoDwarf2CFIAsm) |
| 252 | Res.push_back("-fno-dwarf2-cfi-asm"); |
Nick Lewycky | ea523d7 | 2011-10-17 23:05:52 +0000 | [diff] [blame] | 253 | if (Opts.NoDwarfDirectoryAsm) |
| 254 | Res.push_back("-fno-dwarf-directory-asm"); |
Daniel Dunbar | 3b31526 | 2009-11-30 08:42:00 +0000 | [diff] [blame] | 255 | if (Opts.SoftFloat) |
| 256 | Res.push_back("-msoft-float"); |
Daniel Dunbar | f219e7c | 2009-11-29 07:18:39 +0000 | [diff] [blame] | 257 | if (Opts.UnwindTables) |
| 258 | Res.push_back("-munwind-tables"); |
| 259 | if (Opts.RelocationModel != "pic") { |
| 260 | Res.push_back("-mrelocation-model"); |
| 261 | Res.push_back(Opts.RelocationModel); |
| 262 | } |
John McCall | b689afb | 2010-02-13 03:50:24 +0000 | [diff] [blame] | 263 | if (!Opts.VerifyModule) |
| 264 | Res.push_back("-disable-llvm-verifier"); |
Daniel Dunbar | 3c66d30 | 2011-03-22 16:48:17 +0000 | [diff] [blame] | 265 | for (unsigned i = 0, e = Opts.BackendOptions.size(); i != e; ++i) { |
| 266 | Res.push_back("-backend-option"); |
| 267 | Res.push_back(Opts.BackendOptions[i]); |
| 268 | } |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 269 | } |
| 270 | |
| 271 | static void DependencyOutputOptsToArgs(const DependencyOutputOptions &Opts, |
| 272 | std::vector<std::string> &Res) { |
| 273 | if (Opts.IncludeSystemHeaders) |
| 274 | Res.push_back("-sys-header-deps"); |
Daniel Dunbar | eef63e0 | 2011-02-02 15:41:17 +0000 | [diff] [blame] | 275 | if (Opts.ShowHeaderIncludes) |
| 276 | Res.push_back("-H"); |
Daniel Dunbar | b34d69b | 2011-02-02 21:11:31 +0000 | [diff] [blame] | 277 | if (!Opts.HeaderIncludeOutputFile.empty()) { |
| 278 | Res.push_back("-header-include-file"); |
| 279 | Res.push_back(Opts.HeaderIncludeOutputFile); |
| 280 | } |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 281 | if (Opts.UsePhonyTargets) |
| 282 | Res.push_back("-MP"); |
| 283 | if (!Opts.OutputFile.empty()) { |
| 284 | Res.push_back("-dependency-file"); |
| 285 | Res.push_back(Opts.OutputFile); |
| 286 | } |
| 287 | for (unsigned i = 0, e = Opts.Targets.size(); i != e; ++i) { |
| 288 | Res.push_back("-MT"); |
| 289 | Res.push_back(Opts.Targets[i]); |
| 290 | } |
| 291 | } |
| 292 | |
| 293 | static void DiagnosticOptsToArgs(const DiagnosticOptions &Opts, |
| 294 | std::vector<std::string> &Res) { |
| 295 | if (Opts.IgnoreWarnings) |
| 296 | Res.push_back("-w"); |
| 297 | if (Opts.NoRewriteMacros) |
| 298 | Res.push_back("-Wno-rewrite-macros"); |
| 299 | if (Opts.Pedantic) |
| 300 | Res.push_back("-pedantic"); |
| 301 | if (Opts.PedanticErrors) |
| 302 | Res.push_back("-pedantic-errors"); |
| 303 | if (!Opts.ShowColumn) |
| 304 | Res.push_back("-fno-show-column"); |
| 305 | if (!Opts.ShowLocation) |
| 306 | Res.push_back("-fno-show-source-location"); |
| 307 | if (!Opts.ShowCarets) |
| 308 | Res.push_back("-fno-caret-diagnostics"); |
| 309 | if (!Opts.ShowFixits) |
| 310 | Res.push_back("-fno-diagnostics-fixit-info"); |
| 311 | if (Opts.ShowSourceRanges) |
| 312 | Res.push_back("-fdiagnostics-print-source-range-info"); |
Douglas Gregor | 4786c15 | 2010-08-19 20:24:43 +0000 | [diff] [blame] | 313 | if (Opts.ShowParseableFixits) |
| 314 | Res.push_back("-fdiagnostics-parseable-fixits"); |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 315 | if (Opts.ShowColors) |
| 316 | Res.push_back("-fcolor-diagnostics"); |
| 317 | if (Opts.VerifyDiagnostics) |
| 318 | Res.push_back("-verify"); |
Douglas Gregor | 7d2b8c1 | 2011-04-15 22:04:17 +0000 | [diff] [blame] | 319 | if (Opts.ShowNames) |
| 320 | Res.push_back("-fdiagnostics-show-name"); |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 321 | if (Opts.ShowOptionNames) |
| 322 | Res.push_back("-fdiagnostics-show-option"); |
Chris Lattner | 6fbe839 | 2010-05-04 21:55:25 +0000 | [diff] [blame] | 323 | if (Opts.ShowCategories == 1) |
| 324 | Res.push_back("-fdiagnostics-show-category=id"); |
| 325 | else if (Opts.ShowCategories == 2) |
| 326 | Res.push_back("-fdiagnostics-show-category=name"); |
Douglas Gregor | c9471b0 | 2011-05-21 17:07:29 +0000 | [diff] [blame] | 327 | switch (Opts.Format) { |
| 328 | case DiagnosticOptions::Clang: |
| 329 | Res.push_back("-fdiagnostics-format=clang"); break; |
| 330 | case DiagnosticOptions::Msvc: |
| 331 | Res.push_back("-fdiagnostics-format=msvc"); break; |
| 332 | case DiagnosticOptions::Vi: |
| 333 | Res.push_back("-fdiagnostics-format=vi"); break; |
| 334 | } |
Chris Lattner | c100214 | 2010-04-07 20:37:06 +0000 | [diff] [blame] | 335 | if (Opts.ErrorLimit) { |
| 336 | Res.push_back("-ferror-limit"); |
| 337 | Res.push_back(llvm::utostr(Opts.ErrorLimit)); |
| 338 | } |
Daniel Dunbar | 08c6695 | 2011-04-07 18:11:14 +0000 | [diff] [blame] | 339 | if (!Opts.DiagnosticLogFile.empty()) { |
| 340 | Res.push_back("-diagnostic-log-file"); |
| 341 | Res.push_back(Opts.DiagnosticLogFile); |
| 342 | } |
Douglas Gregor | 6c1cb99 | 2010-05-04 17:13:42 +0000 | [diff] [blame] | 343 | if (Opts.MacroBacktraceLimit |
| 344 | != DiagnosticOptions::DefaultMacroBacktraceLimit) { |
| 345 | Res.push_back("-fmacro-backtrace-limit"); |
| 346 | Res.push_back(llvm::utostr(Opts.MacroBacktraceLimit)); |
| 347 | } |
| 348 | if (Opts.TemplateBacktraceLimit |
| 349 | != DiagnosticOptions::DefaultTemplateBacktraceLimit) { |
Douglas Gregor | 575cf37 | 2010-04-20 07:18:24 +0000 | [diff] [blame] | 350 | Res.push_back("-ftemplate-backtrace-limit"); |
| 351 | Res.push_back(llvm::utostr(Opts.TemplateBacktraceLimit)); |
| 352 | } |
| 353 | |
Chris Lattner | 52388f9 | 2010-01-13 03:06:50 +0000 | [diff] [blame] | 354 | if (Opts.TabStop != DiagnosticOptions::DefaultTabStop) { |
Chris Lattner | 124fca5 | 2010-01-09 21:54:33 +0000 | [diff] [blame] | 355 | Res.push_back("-ftabstop"); |
| 356 | Res.push_back(llvm::utostr(Opts.TabStop)); |
| 357 | } |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 358 | if (Opts.MessageLength) { |
| 359 | Res.push_back("-fmessage-length"); |
| 360 | Res.push_back(llvm::utostr(Opts.MessageLength)); |
| 361 | } |
| 362 | if (!Opts.DumpBuildInformation.empty()) { |
| 363 | Res.push_back("-dump-build-information"); |
| 364 | Res.push_back(Opts.DumpBuildInformation); |
| 365 | } |
| 366 | for (unsigned i = 0, e = Opts.Warnings.size(); i != e; ++i) |
| 367 | Res.push_back("-W" + Opts.Warnings[i]); |
| 368 | } |
| 369 | |
Daniel Dunbar | c34ce3f | 2010-06-07 23:22:09 +0000 | [diff] [blame] | 370 | static const char *getInputKindName(InputKind Kind) { |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 371 | switch (Kind) { |
Daniel Dunbar | c34ce3f | 2010-06-07 23:22:09 +0000 | [diff] [blame] | 372 | case IK_None: break; |
| 373 | case IK_AST: return "ast"; |
| 374 | case IK_Asm: return "assembler-with-cpp"; |
| 375 | case IK_C: return "c"; |
| 376 | case IK_CXX: return "c++"; |
Daniel Dunbar | faddc3e | 2010-06-07 23:26:47 +0000 | [diff] [blame] | 377 | case IK_LLVM_IR: return "ir"; |
Daniel Dunbar | c34ce3f | 2010-06-07 23:22:09 +0000 | [diff] [blame] | 378 | case IK_ObjC: return "objective-c"; |
| 379 | case IK_ObjCXX: return "objective-c++"; |
| 380 | case IK_OpenCL: return "cl"; |
Peter Collingbourne | 895fcca | 2010-12-01 03:15:20 +0000 | [diff] [blame] | 381 | case IK_CUDA: return "cuda"; |
Daniel Dunbar | c34ce3f | 2010-06-07 23:22:09 +0000 | [diff] [blame] | 382 | case IK_PreprocessedC: return "cpp-output"; |
| 383 | case IK_PreprocessedCXX: return "c++-cpp-output"; |
| 384 | case IK_PreprocessedObjC: return "objective-c-cpp-output"; |
| 385 | case IK_PreprocessedObjCXX:return "objective-c++-cpp-output"; |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 386 | } |
| 387 | |
Jeffrey Yasskin | 9f61aa9 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 388 | llvm_unreachable("Unexpected language kind!"); |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 389 | return 0; |
| 390 | } |
| 391 | |
| 392 | static const char *getActionName(frontend::ActionKind Kind) { |
| 393 | switch (Kind) { |
| 394 | case frontend::PluginAction: |
Jeffrey Yasskin | 9f61aa9 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 395 | llvm_unreachable("Invalid kind!"); |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 396 | |
| 397 | case frontend::ASTDump: return "-ast-dump"; |
John McCall | f351424 | 2010-11-24 11:21:45 +0000 | [diff] [blame] | 398 | case frontend::ASTDumpXML: return "-ast-dump-xml"; |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 399 | case frontend::ASTPrint: return "-ast-print"; |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 400 | case frontend::ASTView: return "-ast-view"; |
| 401 | case frontend::DumpRawTokens: return "-dump-raw-tokens"; |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 402 | case frontend::DumpTokens: return "-dump-tokens"; |
| 403 | case frontend::EmitAssembly: return "-S"; |
| 404 | case frontend::EmitBC: return "-emit-llvm-bc"; |
| 405 | case frontend::EmitHTML: return "-emit-html"; |
| 406 | case frontend::EmitLLVM: return "-emit-llvm"; |
| 407 | case frontend::EmitLLVMOnly: return "-emit-llvm-only"; |
Daniel Dunbar | 32148ce | 2010-05-25 18:41:01 +0000 | [diff] [blame] | 408 | case frontend::EmitCodeGenOnly: return "-emit-codegen-only"; |
Daniel Dunbar | da1573f | 2010-02-03 01:18:43 +0000 | [diff] [blame] | 409 | case frontend::EmitObj: return "-emit-obj"; |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 410 | case frontend::FixIt: return "-fixit"; |
Douglas Gregor | 467dc88 | 2011-08-25 22:30:56 +0000 | [diff] [blame] | 411 | case frontend::GenerateModule: return "-emit-module"; |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 412 | case frontend::GeneratePCH: return "-emit-pch"; |
| 413 | case frontend::GeneratePTH: return "-emit-pth"; |
Daniel Dunbar | 2758595 | 2010-03-19 19:44:04 +0000 | [diff] [blame] | 414 | case frontend::InitOnly: return "-init-only"; |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 415 | case frontend::ParseSyntaxOnly: return "-fsyntax-only"; |
| 416 | case frontend::PrintDeclContext: return "-print-decl-contexts"; |
Douglas Gregor | f033f1d | 2010-07-20 20:18:03 +0000 | [diff] [blame] | 417 | case frontend::PrintPreamble: return "-print-preamble"; |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 418 | case frontend::PrintPreprocessedInput: return "-E"; |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 419 | case frontend::RewriteMacros: return "-rewrite-macros"; |
| 420 | case frontend::RewriteObjC: return "-rewrite-objc"; |
| 421 | case frontend::RewriteTest: return "-rewrite-test"; |
| 422 | case frontend::RunAnalysis: return "-analyze"; |
| 423 | case frontend::RunPreprocessorOnly: return "-Eonly"; |
| 424 | } |
| 425 | |
Jeffrey Yasskin | 9f61aa9 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 426 | llvm_unreachable("Unexpected language kind!"); |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 427 | return 0; |
| 428 | } |
| 429 | |
Argyrios Kyrtzidis | 389db16 | 2010-11-03 22:45:23 +0000 | [diff] [blame] | 430 | static void FileSystemOptsToArgs(const FileSystemOptions &Opts, |
| 431 | std::vector<std::string> &Res) { |
| 432 | if (!Opts.WorkingDir.empty()) { |
| 433 | Res.push_back("-working-directory"); |
| 434 | Res.push_back(Opts.WorkingDir); |
| 435 | } |
| 436 | } |
| 437 | |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 438 | static void FrontendOptsToArgs(const FrontendOptions &Opts, |
| 439 | std::vector<std::string> &Res) { |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 440 | if (Opts.DisableFree) |
| 441 | Res.push_back("-disable-free"); |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 442 | if (Opts.RelocatablePCH) |
| 443 | Res.push_back("-relocatable-pch"); |
Daniel Dunbar | 9b5e9ae | 2009-12-03 07:01:58 +0000 | [diff] [blame] | 444 | if (Opts.ShowHelp) |
| 445 | Res.push_back("-help"); |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 446 | if (Opts.ShowMacrosInCodeCompletion) |
| 447 | Res.push_back("-code-completion-macros"); |
Douglas Gregor | d8e8a58 | 2010-05-25 21:41:55 +0000 | [diff] [blame] | 448 | if (Opts.ShowCodePatternsInCodeCompletion) |
| 449 | Res.push_back("-code-completion-patterns"); |
Douglas Gregor | 8071e42 | 2010-08-15 06:18:01 +0000 | [diff] [blame] | 450 | if (!Opts.ShowGlobalSymbolsInCodeCompletion) |
| 451 | Res.push_back("-no-code-completion-globals"); |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 452 | if (Opts.ShowStats) |
Daniel Dunbar | eb01ac8 | 2009-11-25 10:14:52 +0000 | [diff] [blame] | 453 | Res.push_back("-print-stats"); |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 454 | if (Opts.ShowTimers) |
| 455 | Res.push_back("-ftime-report"); |
Daniel Dunbar | 9b5e9ae | 2009-12-03 07:01:58 +0000 | [diff] [blame] | 456 | if (Opts.ShowVersion) |
| 457 | Res.push_back("-version"); |
Nick Lewycky | 1450f26 | 2010-08-13 17:31:00 +0000 | [diff] [blame] | 458 | if (Opts.FixWhatYouCan) |
| 459 | Res.push_back("-fix-what-you-can"); |
John McCall | 8f0e8d2 | 2011-06-15 23:25:17 +0000 | [diff] [blame] | 460 | switch (Opts.ARCMTAction) { |
| 461 | case FrontendOptions::ARCMT_None: |
| 462 | break; |
| 463 | case FrontendOptions::ARCMT_Check: |
| 464 | Res.push_back("-arcmt-check"); |
| 465 | break; |
| 466 | case FrontendOptions::ARCMT_Modify: |
| 467 | Res.push_back("-arcmt-modify"); |
| 468 | break; |
Argyrios Kyrtzidis | 69325d5 | 2011-07-09 20:00:58 +0000 | [diff] [blame] | 469 | case FrontendOptions::ARCMT_Migrate: |
| 470 | Res.push_back("-arcmt-migrate"); |
| 471 | break; |
| 472 | } |
| 473 | if (!Opts.ARCMTMigrateDir.empty()) { |
| 474 | Res.push_back("-arcmt-migrate-directory"); |
| 475 | Res.push_back(Opts.ARCMTMigrateDir); |
John McCall | 8f0e8d2 | 2011-06-15 23:25:17 +0000 | [diff] [blame] | 476 | } |
Argyrios Kyrtzidis | 7ee2049 | 2011-07-19 17:20:03 +0000 | [diff] [blame] | 477 | if (!Opts.ARCMTMigrateReportOut.empty()) { |
| 478 | Res.push_back("-arcmt-migrate-report-output"); |
| 479 | Res.push_back(Opts.ARCMTMigrateReportOut); |
| 480 | } |
| 481 | if (Opts.ARCMTMigrateEmitARCErrors) |
| 482 | Res.push_back("-arcmt-migrate-emit-errors"); |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 483 | |
| 484 | bool NeedLang = false; |
| 485 | for (unsigned i = 0, e = Opts.Inputs.size(); i != e; ++i) |
| 486 | if (FrontendOptions::getInputKindForExtension(Opts.Inputs[i].second) != |
| 487 | Opts.Inputs[i].first) |
| 488 | NeedLang = true; |
| 489 | if (NeedLang) { |
| 490 | Res.push_back("-x"); |
| 491 | Res.push_back(getInputKindName(Opts.Inputs[0].first)); |
| 492 | } |
| 493 | for (unsigned i = 0, e = Opts.Inputs.size(); i != e; ++i) { |
| 494 | assert((!NeedLang || Opts.Inputs[i].first == Opts.Inputs[0].first) && |
| 495 | "Unable to represent this input vector!"); |
| 496 | Res.push_back(Opts.Inputs[i].second); |
| 497 | } |
| 498 | |
| 499 | if (!Opts.OutputFile.empty()) { |
| 500 | Res.push_back("-o"); |
| 501 | Res.push_back(Opts.OutputFile); |
| 502 | } |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 503 | if (!Opts.CodeCompletionAt.FileName.empty()) { |
| 504 | Res.push_back("-code-completion-at"); |
| 505 | Res.push_back(Opts.CodeCompletionAt.FileName + ":" + |
| 506 | llvm::utostr(Opts.CodeCompletionAt.Line) + ":" + |
| 507 | llvm::utostr(Opts.CodeCompletionAt.Column)); |
| 508 | } |
Douglas Gregor | 91a230a | 2011-02-17 19:04:40 +0000 | [diff] [blame] | 509 | if (Opts.ProgramAction != frontend::PluginAction) |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 510 | Res.push_back(getActionName(Opts.ProgramAction)); |
| 511 | if (!Opts.ActionName.empty()) { |
| 512 | Res.push_back("-plugin"); |
| 513 | Res.push_back(Opts.ActionName); |
Daniel Dunbar | 3177aae | 2010-06-16 16:59:23 +0000 | [diff] [blame] | 514 | for(unsigned i = 0, e = Opts.PluginArgs.size(); i != e; ++i) { |
| 515 | Res.push_back("-plugin-arg-" + Opts.ActionName); |
| 516 | Res.push_back(Opts.PluginArgs[i]); |
| 517 | } |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 518 | } |
Daniel Dunbar | efba227 | 2009-12-03 05:11:05 +0000 | [diff] [blame] | 519 | for (unsigned i = 0, e = Opts.Plugins.size(); i != e; ++i) { |
| 520 | Res.push_back("-load"); |
| 521 | Res.push_back(Opts.Plugins[i]); |
| 522 | } |
Nico Weber | 5aa74af | 2011-01-25 20:34:14 +0000 | [diff] [blame] | 523 | for (unsigned i = 0, e = Opts.AddPluginActions.size(); i != e; ++i) { |
| 524 | Res.push_back("-add-plugin"); |
| 525 | Res.push_back(Opts.AddPluginActions[i]); |
Nico Weber | f25649c | 2011-01-29 21:21:49 +0000 | [diff] [blame] | 526 | for(unsigned ai = 0, ae = Opts.AddPluginArgs.size(); ai != ae; ++ai) { |
| 527 | Res.push_back("-plugin-arg-" + Opts.AddPluginActions[i]); |
| 528 | Res.push_back(Opts.AddPluginArgs[i][ai]); |
| 529 | } |
Nico Weber | 5aa74af | 2011-01-25 20:34:14 +0000 | [diff] [blame] | 530 | } |
Douglas Gregor | 9bed879 | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 531 | for (unsigned i = 0, e = Opts.ASTMergeFiles.size(); i != e; ++i) { |
| 532 | Res.push_back("-ast-merge"); |
| 533 | Res.push_back(Opts.ASTMergeFiles[i]); |
| 534 | } |
Daniel Dunbar | 3f87fb0 | 2010-04-15 06:09:03 +0000 | [diff] [blame] | 535 | for (unsigned i = 0, e = Opts.LLVMArgs.size(); i != e; ++i) { |
| 536 | Res.push_back("-mllvm"); |
| 537 | Res.push_back(Opts.LLVMArgs[i]); |
| 538 | } |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 539 | } |
| 540 | |
| 541 | static void HeaderSearchOptsToArgs(const HeaderSearchOptions &Opts, |
| 542 | std::vector<std::string> &Res) { |
Daniel Dunbar | c59dc92 | 2009-11-19 05:32:21 +0000 | [diff] [blame] | 543 | if (Opts.Sysroot != "/") { |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 544 | Res.push_back("-isysroot"); |
| 545 | Res.push_back(Opts.Sysroot); |
| 546 | } |
| 547 | |
| 548 | /// User specified include entries. |
| 549 | for (unsigned i = 0, e = Opts.UserEntries.size(); i != e; ++i) { |
| 550 | const HeaderSearchOptions::Entry &E = Opts.UserEntries[i]; |
Daniel Dunbar | d8c7806 | 2009-11-26 02:13:54 +0000 | [diff] [blame] | 551 | if (E.IsFramework && (E.Group != frontend::Angled || !E.IsUserSupplied)) |
Chris Lattner | 83e7a78 | 2010-04-07 22:58:06 +0000 | [diff] [blame] | 552 | llvm::report_fatal_error("Invalid option set!"); |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 553 | if (E.IsUserSupplied) { |
Douglas Gregor | 65e02fa | 2011-07-28 04:45:53 +0000 | [diff] [blame] | 554 | switch (E.Group) { |
| 555 | case frontend::After: |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 556 | Res.push_back("-idirafter"); |
Douglas Gregor | 65e02fa | 2011-07-28 04:45:53 +0000 | [diff] [blame] | 557 | break; |
| 558 | |
| 559 | case frontend::Quoted: |
Daniel Dunbar | d8c7806 | 2009-11-26 02:13:54 +0000 | [diff] [blame] | 560 | Res.push_back("-iquote"); |
Douglas Gregor | 65e02fa | 2011-07-28 04:45:53 +0000 | [diff] [blame] | 561 | break; |
| 562 | |
| 563 | case frontend::System: |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 564 | Res.push_back("-isystem"); |
Douglas Gregor | 65e02fa | 2011-07-28 04:45:53 +0000 | [diff] [blame] | 565 | break; |
| 566 | |
| 567 | case frontend::IndexHeaderMap: |
| 568 | Res.push_back("-index-header-map"); |
| 569 | Res.push_back(E.IsFramework? "-F" : "-I"); |
| 570 | break; |
| 571 | |
Benjamin Kramer | 47adebe | 2011-09-22 21:41:16 +0000 | [diff] [blame] | 572 | case frontend::CSystem: |
| 573 | Res.push_back("-c-isystem"); |
| 574 | break; |
| 575 | |
Douglas Gregor | 65e02fa | 2011-07-28 04:45:53 +0000 | [diff] [blame] | 576 | case frontend::CXXSystem: |
Joerg Sonnenberger | 2df6647 | 2011-02-22 00:40:56 +0000 | [diff] [blame] | 577 | Res.push_back("-cxx-isystem"); |
Douglas Gregor | 65e02fa | 2011-07-28 04:45:53 +0000 | [diff] [blame] | 578 | break; |
Benjamin Kramer | 47adebe | 2011-09-22 21:41:16 +0000 | [diff] [blame] | 579 | |
| 580 | case frontend::ObjCSystem: |
| 581 | Res.push_back("-objc-isystem"); |
| 582 | break; |
| 583 | |
| 584 | case frontend::ObjCXXSystem: |
| 585 | Res.push_back("-objcxx-isystem"); |
| 586 | break; |
Douglas Gregor | 65e02fa | 2011-07-28 04:45:53 +0000 | [diff] [blame] | 587 | |
| 588 | case frontend::Angled: |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 589 | Res.push_back(E.IsFramework ? "-F" : "-I"); |
Douglas Gregor | 65e02fa | 2011-07-28 04:45:53 +0000 | [diff] [blame] | 590 | break; |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 591 | } |
| 592 | } else { |
Chandler Carruth | ac2bc4d | 2011-11-05 08:30:29 +0000 | [diff] [blame] | 593 | if (E.IsInternal) { |
| 594 | assert(E.Group == frontend::System && "Unexpected header search group"); |
Chandler Carruth | 0764308 | 2011-11-07 09:17:31 +0000 | [diff] [blame] | 595 | if (E.ImplicitExternC) |
Chandler Carruth | 103accc | 2011-11-05 09:24:44 +0000 | [diff] [blame] | 596 | Res.push_back("-internal-externc-isystem"); |
| 597 | else |
| 598 | Res.push_back("-internal-isystem"); |
Chandler Carruth | ac2bc4d | 2011-11-05 08:30:29 +0000 | [diff] [blame] | 599 | } else { |
| 600 | if (E.Group != frontend::Angled && E.Group != frontend::System) |
| 601 | llvm::report_fatal_error("Invalid option set!"); |
| 602 | Res.push_back(E.Group == frontend::Angled ? "-iwithprefixbefore" : |
| 603 | "-iwithprefix"); |
| 604 | } |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 605 | } |
| 606 | Res.push_back(E.Path); |
| 607 | } |
| 608 | |
Daniel Dunbar | 8b9adfe | 2009-12-15 00:06:45 +0000 | [diff] [blame] | 609 | if (!Opts.ResourceDir.empty()) { |
| 610 | Res.push_back("-resource-dir"); |
| 611 | Res.push_back(Opts.ResourceDir); |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 612 | } |
Douglas Gregor | 9a6da69 | 2011-09-12 20:41:59 +0000 | [diff] [blame] | 613 | if (!Opts.ModuleCachePath.empty()) { |
| 614 | Res.push_back("-fmodule-cache-path"); |
| 615 | Res.push_back(Opts.ModuleCachePath); |
| 616 | } |
Daniel Dunbar | a268fc0 | 2011-10-11 18:20:10 +0000 | [diff] [blame] | 617 | if (!Opts.UseStandardSystemIncludes) |
| 618 | Res.push_back("-nostdsysteminc"); |
Douglas Gregor | 4c2bcad | 2010-03-24 20:13:48 +0000 | [diff] [blame] | 619 | if (!Opts.UseStandardCXXIncludes) |
| 620 | Res.push_back("-nostdinc++"); |
Bob Wilson | 13c4f21 | 2011-06-21 21:12:29 +0000 | [diff] [blame] | 621 | if (Opts.UseLibcxx) |
| 622 | Res.push_back("-stdlib=libc++"); |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 623 | if (Opts.Verbose) |
| 624 | Res.push_back("-v"); |
| 625 | } |
| 626 | |
| 627 | static void LangOptsToArgs(const LangOptions &Opts, |
| 628 | std::vector<std::string> &Res) { |
| 629 | LangOptions DefaultLangOpts; |
| 630 | |
| 631 | // FIXME: Need to set -std to get all the implicit options. |
| 632 | |
| 633 | // FIXME: We want to only pass options relative to the defaults, which |
| 634 | // requires constructing a target. :( |
| 635 | // |
| 636 | // It would be better to push the all target specific choices into the driver, |
| 637 | // so that everything below that was more uniform. |
| 638 | |
| 639 | if (Opts.Trigraphs) |
| 640 | Res.push_back("-trigraphs"); |
| 641 | // Implicit based on the input kind: |
| 642 | // AsmPreprocessor, CPlusPlus, ObjC1, ObjC2, OpenCL |
| 643 | // Implicit based on the input language standard: |
| 644 | // BCPLComment, C99, CPlusPlus0x, Digraphs, GNUInline, ImplicitInt, GNUMode |
| 645 | if (Opts.DollarIdents) |
| 646 | Res.push_back("-fdollars-in-identifiers"); |
Chandler Carruth | eb5d7b7 | 2010-04-17 20:17:31 +0000 | [diff] [blame] | 647 | if (Opts.GNUMode && !Opts.GNUKeywords) |
| 648 | Res.push_back("-fno-gnu-keywords"); |
| 649 | if (!Opts.GNUMode && Opts.GNUKeywords) |
| 650 | Res.push_back("-fgnu-keywords"); |
Francois Pichet | 62ec1f2 | 2011-09-17 17:15:52 +0000 | [diff] [blame] | 651 | if (Opts.MicrosoftExt) |
Daniel Dunbar | 8663b18 | 2009-12-16 20:10:18 +0000 | [diff] [blame] | 652 | Res.push_back("-fms-extensions"); |
Douglas Gregor | 0bb935c | 2011-10-24 15:27:23 +0000 | [diff] [blame] | 653 | if (Opts.MicrosoftMode) |
| 654 | Res.push_back("-fms-compatibility"); |
Michael J. Spencer | dae4ac4 | 2010-10-21 05:21:48 +0000 | [diff] [blame] | 655 | if (Opts.MSCVersion != 0) |
| 656 | Res.push_back("-fmsc-version=" + llvm::utostr(Opts.MSCVersion)); |
Dawn Perchik | 400b607 | 2010-09-02 23:59:25 +0000 | [diff] [blame] | 657 | if (Opts.Borland) |
| 658 | Res.push_back("-fborland-extensions"); |
John McCall | d1e40d5 | 2011-10-02 01:16:38 +0000 | [diff] [blame] | 659 | if (!Opts.ObjCNonFragileABI) |
| 660 | Res.push_back("-fobjc-fragile-abi"); |
Ted Kremenek | c32647d | 2010-12-23 21:35:43 +0000 | [diff] [blame] | 661 | if (Opts.ObjCDefaultSynthProperties) |
| 662 | Res.push_back("-fobjc-default-synthesize-properties"); |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 663 | // NoInline is implicit. |
| 664 | if (!Opts.CXXOperatorNames) |
| 665 | Res.push_back("-fno-operator-names"); |
| 666 | if (Opts.PascalStrings) |
| 667 | Res.push_back("-fpascal-strings"); |
Mike Stump | 9c276ae | 2009-12-12 01:27:46 +0000 | [diff] [blame] | 668 | if (Opts.CatchUndefined) |
| 669 | Res.push_back("-fcatch-undefined-behavior"); |
Kostya Serebryany | b619688 | 2011-11-22 01:28:36 +0000 | [diff] [blame] | 670 | if (Opts.AddressSanitizer) |
| 671 | Res.push_back("-faddress-sanitizer"); |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 672 | if (Opts.WritableStrings) |
| 673 | Res.push_back("-fwritable-strings"); |
John McCall | 4b7a834 | 2010-03-15 10:54:44 +0000 | [diff] [blame] | 674 | if (Opts.ConstStrings) |
Chandler Carruth | 50465d1 | 2011-04-23 06:30:43 +0000 | [diff] [blame] | 675 | Res.push_back("-fconst-strings"); |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 676 | if (!Opts.LaxVectorConversions) |
| 677 | Res.push_back("-fno-lax-vector-conversions"); |
| 678 | if (Opts.AltiVec) |
| 679 | Res.push_back("-faltivec"); |
Daniel Dunbar | 1be3b3b | 2009-11-19 20:54:59 +0000 | [diff] [blame] | 680 | if (Opts.Exceptions) |
| 681 | Res.push_back("-fexceptions"); |
Anders Carlsson | 0761e44 | 2011-02-23 03:16:42 +0000 | [diff] [blame] | 682 | if (Opts.ObjCExceptions) |
| 683 | Res.push_back("-fobjc-exceptions"); |
| 684 | if (Opts.CXXExceptions) |
| 685 | Res.push_back("-fcxx-exceptions"); |
Daniel Dunbar | 7348288 | 2010-02-10 18:48:44 +0000 | [diff] [blame] | 686 | if (Opts.SjLjExceptions) |
| 687 | Res.push_back("-fsjlj-exceptions"); |
Daniel Dunbar | 2ed4228 | 2011-03-18 21:23:38 +0000 | [diff] [blame] | 688 | if (Opts.TraditionalCPP) |
| 689 | Res.push_back("-traditional-cpp"); |
Mike Stump | de05057 | 2009-12-02 18:57:08 +0000 | [diff] [blame] | 690 | if (!Opts.RTTI) |
Daniel Dunbar | 4db166b | 2009-11-19 05:32:09 +0000 | [diff] [blame] | 691 | Res.push_back("-fno-rtti"); |
Douglas Gregor | 6f75550 | 2011-02-01 15:15:22 +0000 | [diff] [blame] | 692 | if (Opts.MSBitfields) |
| 693 | Res.push_back("-mms-bitfields"); |
Daniel Dunbar | c5a97ec | 2009-11-17 07:07:28 +0000 | [diff] [blame] | 694 | if (!Opts.NeXTRuntime) |
| 695 | Res.push_back("-fgnu-runtime"); |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 696 | if (Opts.Freestanding) |
| 697 | Res.push_back("-ffreestanding"); |
| 698 | if (Opts.NoBuiltin) |
| 699 | Res.push_back("-fno-builtin"); |
Nuno Lopes | fc28448 | 2009-12-16 16:59:22 +0000 | [diff] [blame] | 700 | if (!Opts.AssumeSaneOperatorNew) |
| 701 | Res.push_back("-fno-assume-sane-operator-new"); |
Anders Carlsson | a508b7d | 2010-02-06 23:23:06 +0000 | [diff] [blame] | 702 | if (!Opts.ThreadsafeStatics) |
| 703 | Res.push_back("-fno-threadsafe-statics"); |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 704 | if (Opts.POSIXThreads) |
| 705 | Res.push_back("-pthread"); |
Daniel Dunbar | a51ca52 | 2009-11-17 09:15:57 +0000 | [diff] [blame] | 706 | if (Opts.Blocks) |
Daniel Dunbar | e50c167 | 2009-11-29 05:52:21 +0000 | [diff] [blame] | 707 | Res.push_back("-fblocks"); |
John McCall | 13db5cf | 2011-09-09 20:41:01 +0000 | [diff] [blame] | 708 | if (Opts.BlocksRuntimeOptional) |
| 709 | Res.push_back("-fblocks-runtime-optional"); |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 710 | if (Opts.EmitAllDecls) |
| 711 | Res.push_back("-femit-all-decls"); |
Dan Gohman | c31176d | 2010-01-08 02:20:44 +0000 | [diff] [blame] | 712 | if (Opts.MathErrno) |
| 713 | Res.push_back("-fmath-errno"); |
Chris Lattner | a4d7145 | 2010-06-26 21:25:03 +0000 | [diff] [blame] | 714 | switch (Opts.getSignedOverflowBehavior()) { |
| 715 | case LangOptions::SOB_Undefined: break; |
| 716 | case LangOptions::SOB_Defined: Res.push_back("-fwrapv"); break; |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 717 | case LangOptions::SOB_Trapping: |
Douglas Gregor | 21a2516 | 2011-11-02 20:52:01 +0000 | [diff] [blame] | 718 | Res.push_back("-ftrapv"); |
David Chisnall | 7f18e67 | 2010-09-17 18:29:54 +0000 | [diff] [blame] | 719 | if (!Opts.OverflowHandler.empty()) { |
| 720 | Res.push_back("-ftrapv-handler"); |
| 721 | Res.push_back(Opts.OverflowHandler); |
| 722 | } |
Douglas Gregor | 21a2516 | 2011-11-02 20:52:01 +0000 | [diff] [blame] | 723 | break; |
Chris Lattner | a4d7145 | 2010-06-26 21:25:03 +0000 | [diff] [blame] | 724 | } |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 725 | if (Opts.HeinousExtensions) |
| 726 | Res.push_back("-fheinous-gnu-extensions"); |
| 727 | // Optimize is implicit. |
| 728 | // OptimizeSize is implicit. |
| 729 | if (Opts.Static) |
| 730 | Res.push_back("-static-define"); |
Daniel Dunbar | fb937b8 | 2010-04-15 15:06:22 +0000 | [diff] [blame] | 731 | if (Opts.DumpRecordLayouts) |
| 732 | Res.push_back("-fdump-record-layouts"); |
Anders Carlsson | 046c294 | 2010-04-17 20:15:18 +0000 | [diff] [blame] | 733 | if (Opts.DumpVTableLayouts) |
Daniel Dunbar | fb937b8 | 2010-04-15 15:06:22 +0000 | [diff] [blame] | 734 | Res.push_back("-fdump-vtable-layouts"); |
| 735 | if (Opts.NoBitFieldTypeAlign) |
| 736 | Res.push_back("-fno-bitfield-type-alignment"); |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 737 | if (Opts.PICLevel) { |
| 738 | Res.push_back("-pic-level"); |
| 739 | Res.push_back(llvm::utostr(Opts.PICLevel)); |
| 740 | } |
| 741 | if (Opts.ObjCGCBitmapPrint) |
| 742 | Res.push_back("-print-ivar-layout"); |
Fariborz Jahanian | 33e982b | 2010-04-22 20:26:39 +0000 | [diff] [blame] | 743 | if (Opts.NoConstantCFStrings) |
| 744 | Res.push_back("-fno-constant-cfstrings"); |
John McCall | 7002f4c | 2010-04-09 19:03:51 +0000 | [diff] [blame] | 745 | if (!Opts.AccessControl) |
| 746 | Res.push_back("-fno-access-control"); |
Daniel Dunbar | 1be3b3b | 2009-11-19 20:54:59 +0000 | [diff] [blame] | 747 | if (!Opts.CharIsSigned) |
Daniel Dunbar | e50c167 | 2009-11-29 05:52:21 +0000 | [diff] [blame] | 748 | Res.push_back("-fno-signed-char"); |
Daniel Dunbar | 1be3b3b | 2009-11-19 20:54:59 +0000 | [diff] [blame] | 749 | if (Opts.ShortWChar) |
| 750 | Res.push_back("-fshort-wchar"); |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 751 | if (!Opts.ElideConstructors) |
| 752 | Res.push_back("-fno-elide-constructors"); |
Douglas Gregor | e289d81 | 2011-09-13 17:21:33 +0000 | [diff] [blame] | 753 | if (Opts.getGC() != LangOptions::NonGC) { |
| 754 | if (Opts.getGC() == LangOptions::HybridGC) { |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 755 | Res.push_back("-fobjc-gc"); |
| 756 | } else { |
Douglas Gregor | e289d81 | 2011-09-13 17:21:33 +0000 | [diff] [blame] | 757 | assert(Opts.getGC() == LangOptions::GCOnly && "Invalid GC mode!"); |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 758 | Res.push_back("-fobjc-gc-only"); |
| 759 | } |
| 760 | } |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 761 | if (Opts.ObjCAutoRefCount) |
| 762 | Res.push_back("-fobjc-arc"); |
John McCall | 9f084a3 | 2011-07-06 00:26:06 +0000 | [diff] [blame] | 763 | if (Opts.ObjCRuntimeHasWeak) |
| 764 | Res.push_back("-fobjc-runtime-has-weak"); |
Douglas Gregor | 74da19f | 2011-06-14 23:20:43 +0000 | [diff] [blame] | 765 | if (!Opts.ObjCInferRelatedResultType) |
| 766 | Res.push_back("-fno-objc-infer-related-result-type"); |
| 767 | |
Fariborz Jahanian | b466d01 | 2011-01-07 01:05:02 +0000 | [diff] [blame] | 768 | if (Opts.AppleKext) |
| 769 | Res.push_back("-fapple-kext"); |
| 770 | |
John McCall | 1fb0caa | 2010-10-22 21:05:15 +0000 | [diff] [blame] | 771 | if (Opts.getVisibilityMode() != DefaultVisibility) { |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 772 | Res.push_back("-fvisibility"); |
John McCall | 1fb0caa | 2010-10-22 21:05:15 +0000 | [diff] [blame] | 773 | if (Opts.getVisibilityMode() == HiddenVisibility) { |
Daniel Dunbar | 1be3b3b | 2009-11-19 20:54:59 +0000 | [diff] [blame] | 774 | Res.push_back("hidden"); |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 775 | } else { |
John McCall | 1fb0caa | 2010-10-22 21:05:15 +0000 | [diff] [blame] | 776 | assert(Opts.getVisibilityMode() == ProtectedVisibility && |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 777 | "Invalid visibility!"); |
| 778 | Res.push_back("protected"); |
| 779 | } |
| 780 | } |
Douglas Gregor | 7cf84d6 | 2010-06-15 17:05:35 +0000 | [diff] [blame] | 781 | if (Opts.InlineVisibilityHidden) |
| 782 | Res.push_back("-fvisibility-inlines-hidden"); |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 783 | |
Douglas Gregor | e289d81 | 2011-09-13 17:21:33 +0000 | [diff] [blame] | 784 | if (Opts.getStackProtector() != 0) { |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 785 | Res.push_back("-stack-protector"); |
Douglas Gregor | e289d81 | 2011-09-13 17:21:33 +0000 | [diff] [blame] | 786 | Res.push_back(llvm::utostr(Opts.getStackProtector())); |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 787 | } |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 788 | if (Opts.InstantiationDepth != DefaultLangOpts.InstantiationDepth) { |
| 789 | Res.push_back("-ftemplate-depth"); |
| 790 | Res.push_back(llvm::utostr(Opts.InstantiationDepth)); |
| 791 | } |
Richard Smith | c18c423 | 2011-11-21 19:36:32 +0000 | [diff] [blame] | 792 | if (Opts.ConstexprCallDepth != DefaultLangOpts.ConstexprCallDepth) { |
| 793 | Res.push_back("-fconstexpr-depth"); |
| 794 | Res.push_back(llvm::utostr(Opts.ConstexprCallDepth)); |
| 795 | } |
Daniel Dunbar | 1b09695 | 2009-11-29 02:38:47 +0000 | [diff] [blame] | 796 | if (!Opts.ObjCConstantStringClass.empty()) { |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 797 | Res.push_back("-fconstant-string-class"); |
| 798 | Res.push_back(Opts.ObjCConstantStringClass); |
| 799 | } |
Peter Collingbourne | 207f4d8 | 2011-03-18 22:38:29 +0000 | [diff] [blame] | 800 | if (Opts.FakeAddressSpaceMap) |
| 801 | Res.push_back("-ffake-address-space-map"); |
John McCall | a5fc472 | 2011-04-09 22:50:59 +0000 | [diff] [blame] | 802 | if (Opts.ParseUnknownAnytype) |
| 803 | Res.push_back("-funknown-anytype"); |
John McCall | 48218c6 | 2011-07-13 17:56:40 +0000 | [diff] [blame] | 804 | if (Opts.DebuggerSupport) |
| 805 | Res.push_back("-fdebugger-support"); |
Francois Pichet | 8387e2a | 2011-04-22 22:18:13 +0000 | [diff] [blame] | 806 | if (Opts.DelayedTemplateParsing) |
| 807 | Res.push_back("-fdelayed-template-parsing"); |
Chandler Carruth | f8c247d | 2011-04-23 19:48:40 +0000 | [diff] [blame] | 808 | if (Opts.Deprecated) |
| 809 | Res.push_back("-fdeprecated-macro"); |
Eli Friedman | 19bda3a | 2011-11-02 01:53:16 +0000 | [diff] [blame] | 810 | if (Opts.ApplePragmaPack) |
| 811 | Res.push_back("-fapple-pragma-pack"); |
Douglas Gregor | b86b8dc | 2011-11-15 19:35:01 +0000 | [diff] [blame] | 812 | if (!Opts.CurrentModule.empty()) |
| 813 | Res.push_back("-fmodule-name=" + Opts.CurrentModule); |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 814 | } |
| 815 | |
| 816 | static void PreprocessorOptsToArgs(const PreprocessorOptions &Opts, |
| 817 | std::vector<std::string> &Res) { |
| 818 | for (unsigned i = 0, e = Opts.Macros.size(); i != e; ++i) |
Daniel Dunbar | 0ff679f | 2009-11-26 02:14:07 +0000 | [diff] [blame] | 819 | Res.push_back(std::string(Opts.Macros[i].second ? "-U" : "-D") + |
| 820 | Opts.Macros[i].first); |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 821 | for (unsigned i = 0, e = Opts.Includes.size(); i != e; ++i) { |
Daniel Dunbar | 0ff679f | 2009-11-26 02:14:07 +0000 | [diff] [blame] | 822 | // FIXME: We need to avoid reincluding the implicit PCH and PTH includes. |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 823 | Res.push_back("-include"); |
| 824 | Res.push_back(Opts.Includes[i]); |
| 825 | } |
| 826 | for (unsigned i = 0, e = Opts.MacroIncludes.size(); i != e; ++i) { |
| 827 | Res.push_back("-imacros"); |
Daniel Dunbar | 0ff679f | 2009-11-26 02:14:07 +0000 | [diff] [blame] | 828 | Res.push_back(Opts.MacroIncludes[i]); |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 829 | } |
| 830 | if (!Opts.UsePredefines) |
| 831 | Res.push_back("-undef"); |
Douglas Gregor | 94dc8f6 | 2010-03-19 16:15:56 +0000 | [diff] [blame] | 832 | if (Opts.DetailedRecord) |
| 833 | Res.push_back("-detailed-preprocessing-record"); |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 834 | if (!Opts.ImplicitPCHInclude.empty()) { |
Daniel Dunbar | 0ff679f | 2009-11-26 02:14:07 +0000 | [diff] [blame] | 835 | Res.push_back("-include-pch"); |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 836 | Res.push_back(Opts.ImplicitPCHInclude); |
| 837 | } |
| 838 | if (!Opts.ImplicitPTHInclude.empty()) { |
Daniel Dunbar | 0ff679f | 2009-11-26 02:14:07 +0000 | [diff] [blame] | 839 | Res.push_back("-include-pth"); |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 840 | Res.push_back(Opts.ImplicitPTHInclude); |
| 841 | } |
| 842 | if (!Opts.TokenCache.empty()) { |
Daniel Dunbar | 0ff679f | 2009-11-26 02:14:07 +0000 | [diff] [blame] | 843 | if (Opts.ImplicitPTHInclude.empty()) { |
| 844 | Res.push_back("-token-cache"); |
| 845 | Res.push_back(Opts.TokenCache); |
| 846 | } else |
| 847 | assert(Opts.ImplicitPTHInclude == Opts.TokenCache && |
| 848 | "Unsupported option combination!"); |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 849 | } |
Argyrios Kyrtzidis | b0f4b9a | 2011-03-09 17:21:42 +0000 | [diff] [blame] | 850 | for (unsigned i = 0, e = Opts.ChainedIncludes.size(); i != e; ++i) { |
| 851 | Res.push_back("-chain-include"); |
| 852 | Res.push_back(Opts.ChainedIncludes[i]); |
| 853 | } |
Daniel Dunbar | e14b5f5 | 2009-12-03 05:11:16 +0000 | [diff] [blame] | 854 | for (unsigned i = 0, e = Opts.RemappedFiles.size(); i != e; ++i) { |
| 855 | Res.push_back("-remap-file"); |
| 856 | Res.push_back(Opts.RemappedFiles[i].first + ";" + |
| 857 | Opts.RemappedFiles[i].second); |
| 858 | } |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 859 | } |
| 860 | |
| 861 | static void PreprocessorOutputOptsToArgs(const PreprocessorOutputOptions &Opts, |
| 862 | std::vector<std::string> &Res) { |
| 863 | if (!Opts.ShowCPP && !Opts.ShowMacros) |
Chris Lattner | 83e7a78 | 2010-04-07 22:58:06 +0000 | [diff] [blame] | 864 | llvm::report_fatal_error("Invalid option combination!"); |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 865 | |
| 866 | if (Opts.ShowCPP && Opts.ShowMacros) |
| 867 | Res.push_back("-dD"); |
| 868 | else if (!Opts.ShowCPP && Opts.ShowMacros) |
| 869 | Res.push_back("-dM"); |
| 870 | |
| 871 | if (!Opts.ShowLineMarkers) |
| 872 | Res.push_back("-P"); |
| 873 | if (Opts.ShowComments) |
| 874 | Res.push_back("-C"); |
| 875 | if (Opts.ShowMacroComments) |
| 876 | Res.push_back("-CC"); |
| 877 | } |
| 878 | |
| 879 | static void TargetOptsToArgs(const TargetOptions &Opts, |
| 880 | std::vector<std::string> &Res) { |
| 881 | Res.push_back("-triple"); |
| 882 | Res.push_back(Opts.Triple); |
| 883 | if (!Opts.CPU.empty()) { |
Daniel Dunbar | 38b48af | 2009-12-18 06:30:12 +0000 | [diff] [blame] | 884 | Res.push_back("-target-cpu"); |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 885 | Res.push_back(Opts.CPU); |
| 886 | } |
| 887 | if (!Opts.ABI.empty()) { |
| 888 | Res.push_back("-target-abi"); |
| 889 | Res.push_back(Opts.ABI); |
| 890 | } |
Daniel Dunbar | 39065a5 | 2010-08-11 23:07:42 +0000 | [diff] [blame] | 891 | if (!Opts.LinkerVersion.empty()) { |
| 892 | Res.push_back("-target-linker-version"); |
| 893 | Res.push_back(Opts.LinkerVersion); |
| 894 | } |
John McCall | 875ab10 | 2010-08-22 06:43:33 +0000 | [diff] [blame] | 895 | if (!Opts.CXXABI.empty()) { |
| 896 | Res.push_back("-cxx-abi"); |
| 897 | Res.push_back(Opts.CXXABI); |
| 898 | } |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 899 | for (unsigned i = 0, e = Opts.Features.size(); i != e; ++i) { |
| 900 | Res.push_back("-target-feature"); |
| 901 | Res.push_back(Opts.Features[i]); |
| 902 | } |
| 903 | } |
| 904 | |
| 905 | void CompilerInvocation::toArgs(std::vector<std::string> &Res) { |
| 906 | AnalyzerOptsToArgs(getAnalyzerOpts(), Res); |
| 907 | CodeGenOptsToArgs(getCodeGenOpts(), Res); |
| 908 | DependencyOutputOptsToArgs(getDependencyOutputOpts(), Res); |
| 909 | DiagnosticOptsToArgs(getDiagnosticOpts(), Res); |
Argyrios Kyrtzidis | 389db16 | 2010-11-03 22:45:23 +0000 | [diff] [blame] | 910 | FileSystemOptsToArgs(getFileSystemOpts(), Res); |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 911 | FrontendOptsToArgs(getFrontendOpts(), Res); |
| 912 | HeaderSearchOptsToArgs(getHeaderSearchOpts(), Res); |
Ted Kremenek | d3b74d9 | 2011-11-17 23:01:24 +0000 | [diff] [blame] | 913 | LangOptsToArgs(*getLangOpts(), Res); |
Daniel Dunbar | b3375cb | 2009-11-17 06:02:29 +0000 | [diff] [blame] | 914 | PreprocessorOptsToArgs(getPreprocessorOpts(), Res); |
| 915 | PreprocessorOutputOptsToArgs(getPreprocessorOutputOpts(), Res); |
| 916 | TargetOptsToArgs(getTargetOpts(), Res); |
| 917 | } |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 918 | |
| 919 | //===----------------------------------------------------------------------===// |
| 920 | // Deserialization (to args) |
| 921 | //===----------------------------------------------------------------------===// |
| 922 | |
| 923 | using namespace clang::driver; |
| 924 | using namespace clang::driver::cc1options; |
| 925 | |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 926 | // |
| 927 | |
Peter Collingbourne | 0a3c03c | 2010-12-04 01:50:36 +0000 | [diff] [blame] | 928 | static unsigned getOptimizationLevel(ArgList &Args, InputKind IK, |
David Blaikie | d6471f7 | 2011-09-25 23:23:43 +0000 | [diff] [blame] | 929 | DiagnosticsEngine &Diags) { |
Peter Collingbourne | 61e0786 | 2010-12-04 01:50:45 +0000 | [diff] [blame] | 930 | unsigned DefaultOpt = 0; |
| 931 | if (IK == IK_OpenCL && !Args.hasArg(OPT_cl_opt_disable)) |
| 932 | DefaultOpt = 2; |
Bob Wilson | a0fa203 | 2011-04-29 22:49:50 +0000 | [diff] [blame] | 933 | // -Os/-Oz implies -O2 |
| 934 | return (Args.hasArg(OPT_Os) || Args.hasArg (OPT_Oz)) ? 2 : |
Peter Collingbourne | 61e0786 | 2010-12-04 01:50:45 +0000 | [diff] [blame] | 935 | Args.getLastArgIntValue(OPT_O, DefaultOpt, Diags); |
Peter Collingbourne | 0a3c03c | 2010-12-04 01:50:36 +0000 | [diff] [blame] | 936 | } |
| 937 | |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 938 | static void ParseAnalyzerArgs(AnalyzerOptions &Opts, ArgList &Args, |
David Blaikie | d6471f7 | 2011-09-25 23:23:43 +0000 | [diff] [blame] | 939 | DiagnosticsEngine &Diags) { |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 940 | using namespace cc1options; |
| 941 | |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 942 | if (Arg *A = Args.getLastArg(OPT_analyzer_store)) { |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 943 | StringRef Name = A->getValue(Args); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 944 | AnalysisStores Value = llvm::StringSwitch<AnalysisStores>(Name) |
| 945 | #define ANALYSIS_STORE(NAME, CMDFLAG, DESC, CREATFN) \ |
| 946 | .Case(CMDFLAG, NAME##Model) |
| 947 | #include "clang/Frontend/Analyses.def" |
| 948 | .Default(NumStores); |
| 949 | // FIXME: Error handling. |
| 950 | if (Value == NumStores) |
| 951 | Diags.Report(diag::err_drv_invalid_value) |
Daniel Dunbar | bfbb39d | 2010-06-09 22:30:54 +0000 | [diff] [blame] | 952 | << A->getAsString(Args) << Name; |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 953 | else |
| 954 | Opts.AnalysisStoreOpt = Value; |
| 955 | } |
| 956 | |
| 957 | if (Arg *A = Args.getLastArg(OPT_analyzer_constraints)) { |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 958 | StringRef Name = A->getValue(Args); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 959 | AnalysisConstraints Value = llvm::StringSwitch<AnalysisConstraints>(Name) |
| 960 | #define ANALYSIS_CONSTRAINTS(NAME, CMDFLAG, DESC, CREATFN) \ |
| 961 | .Case(CMDFLAG, NAME##Model) |
| 962 | #include "clang/Frontend/Analyses.def" |
| 963 | .Default(NumConstraints); |
| 964 | // FIXME: Error handling. |
| 965 | if (Value == NumConstraints) |
| 966 | Diags.Report(diag::err_drv_invalid_value) |
Daniel Dunbar | bfbb39d | 2010-06-09 22:30:54 +0000 | [diff] [blame] | 967 | << A->getAsString(Args) << Name; |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 968 | else |
| 969 | Opts.AnalysisConstraintsOpt = Value; |
| 970 | } |
| 971 | |
| 972 | if (Arg *A = Args.getLastArg(OPT_analyzer_output)) { |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 973 | StringRef Name = A->getValue(Args); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 974 | AnalysisDiagClients Value = llvm::StringSwitch<AnalysisDiagClients>(Name) |
| 975 | #define ANALYSIS_DIAGNOSTICS(NAME, CMDFLAG, DESC, CREATFN, AUTOCREAT) \ |
| 976 | .Case(CMDFLAG, PD_##NAME) |
| 977 | #include "clang/Frontend/Analyses.def" |
| 978 | .Default(NUM_ANALYSIS_DIAG_CLIENTS); |
| 979 | // FIXME: Error handling. |
| 980 | if (Value == NUM_ANALYSIS_DIAG_CLIENTS) |
| 981 | Diags.Report(diag::err_drv_invalid_value) |
Daniel Dunbar | bfbb39d | 2010-06-09 22:30:54 +0000 | [diff] [blame] | 982 | << A->getAsString(Args) << Name; |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 983 | else |
| 984 | Opts.AnalysisDiagOpt = Value; |
| 985 | } |
| 986 | |
Anna Zaks | d309528 | 2011-09-30 02:03:00 +0000 | [diff] [blame] | 987 | if (Arg *A = Args.getLastArg(OPT_analyzer_purge)) { |
| 988 | StringRef Name = A->getValue(Args); |
| 989 | AnalysisPurgeMode Value = llvm::StringSwitch<AnalysisPurgeMode>(Name) |
| 990 | #define ANALYSIS_PURGE(NAME, CMDFLAG, DESC) \ |
| 991 | .Case(CMDFLAG, NAME) |
| 992 | #include "clang/Frontend/Analyses.def" |
| 993 | .Default(NumPurgeModes); |
| 994 | // FIXME: Error handling. |
| 995 | if (Value == NumPurgeModes) |
| 996 | Diags.Report(diag::err_drv_invalid_value) |
| 997 | << A->getAsString(Args) << Name; |
| 998 | else |
| 999 | Opts.AnalysisPurgeOpt = Value; |
| 1000 | } |
| 1001 | |
Argyrios Kyrtzidis | 116f364 | 2011-02-25 00:09:51 +0000 | [diff] [blame] | 1002 | Opts.ShowCheckerHelp = Args.hasArg(OPT_analyzer_checker_help); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1003 | Opts.VisualizeEGDot = Args.hasArg(OPT_analyzer_viz_egraph_graphviz); |
| 1004 | Opts.VisualizeEGUbi = Args.hasArg(OPT_analyzer_viz_egraph_ubigraph); |
| 1005 | Opts.AnalyzeAll = Args.hasArg(OPT_analyzer_opt_analyze_headers); |
| 1006 | Opts.AnalyzerDisplayProgress = Args.hasArg(OPT_analyzer_display_progress); |
Ted Kremenek | fc57651 | 2009-12-07 22:06:12 +0000 | [diff] [blame] | 1007 | Opts.AnalyzeNestedBlocks = |
| 1008 | Args.hasArg(OPT_analyzer_opt_analyze_nested_blocks); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1009 | Opts.EagerlyAssume = Args.hasArg(OPT_analyzer_eagerly_assume); |
Daniel Dunbar | 03e8ab2 | 2010-05-20 16:54:55 +0000 | [diff] [blame] | 1010 | Opts.AnalyzeSpecificFunction = Args.getLastArgValue(OPT_analyze_function); |
Ted Kremenek | 9b823e8 | 2010-08-03 00:09:51 +0000 | [diff] [blame] | 1011 | Opts.UnoptimizedCFG = Args.hasArg(OPT_analysis_UnoptimizedCFG); |
Marcin Swiderski | 9121ba2 | 2010-09-30 07:41:24 +0000 | [diff] [blame] | 1012 | Opts.CFGAddImplicitDtors = Args.hasArg(OPT_analysis_CFGAddImplicitDtors); |
| 1013 | Opts.CFGAddInitializers = Args.hasArg(OPT_analysis_CFGAddInitializers); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1014 | Opts.TrimGraph = Args.hasArg(OPT_trim_egraph); |
Daniel Dunbar | 03e8ab2 | 2010-05-20 16:54:55 +0000 | [diff] [blame] | 1015 | Opts.MaxNodes = Args.getLastArgIntValue(OPT_analyzer_max_nodes, 150000,Diags); |
Ted Kremenek | 6648e5d | 2010-10-18 23:36:05 +0000 | [diff] [blame] | 1016 | Opts.MaxLoop = Args.getLastArgIntValue(OPT_analyzer_max_loop, 4, Diags); |
Ted Kremenek | d767d81 | 2011-02-09 01:27:33 +0000 | [diff] [blame] | 1017 | Opts.EagerlyTrimEGraph = !Args.hasArg(OPT_analyzer_no_eagerly_trim_egraph); |
Zhongxing Xu | 7b99d12 | 2010-05-06 02:59:29 +0000 | [diff] [blame] | 1018 | Opts.InlineCall = Args.hasArg(OPT_analyzer_inline_call); |
Argyrios Kyrtzidis | 43dee22 | 2011-02-14 18:13:31 +0000 | [diff] [blame] | 1019 | |
| 1020 | Opts.CheckersControlList.clear(); |
| 1021 | for (arg_iterator it = Args.filtered_begin(OPT_analyzer_checker, |
| 1022 | OPT_analyzer_disable_checker), |
| 1023 | ie = Args.filtered_end(); it != ie; ++it) { |
| 1024 | const Arg *A = *it; |
| 1025 | A->claim(); |
| 1026 | bool enable = (A->getOption().getID() == OPT_analyzer_checker); |
Argyrios Kyrtzidis | 38c8fe7 | 2011-02-24 08:42:20 +0000 | [diff] [blame] | 1027 | // We can have a list of comma separated checker names, e.g: |
| 1028 | // '-analyzer-checker=cocoa,unix' |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1029 | StringRef checkerList = A->getValue(Args); |
| 1030 | SmallVector<StringRef, 4> checkers; |
Argyrios Kyrtzidis | 38c8fe7 | 2011-02-24 08:42:20 +0000 | [diff] [blame] | 1031 | checkerList.split(checkers, ","); |
| 1032 | for (unsigned i = 0, e = checkers.size(); i != e; ++i) |
| 1033 | Opts.CheckersControlList.push_back(std::make_pair(checkers[i], enable)); |
Argyrios Kyrtzidis | 43dee22 | 2011-02-14 18:13:31 +0000 | [diff] [blame] | 1034 | } |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1035 | } |
| 1036 | |
Peter Collingbourne | 0a3c03c | 2010-12-04 01:50:36 +0000 | [diff] [blame] | 1037 | static void ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args, InputKind IK, |
David Blaikie | d6471f7 | 2011-09-25 23:23:43 +0000 | [diff] [blame] | 1038 | DiagnosticsEngine &Diags) { |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1039 | using namespace cc1options; |
Peter Collingbourne | 0a3c03c | 2010-12-04 01:50:36 +0000 | [diff] [blame] | 1040 | |
| 1041 | Opts.OptimizationLevel = getOptimizationLevel(Args, IK, Diags); |
| 1042 | if (Opts.OptimizationLevel > 3) { |
| 1043 | Diags.Report(diag::err_drv_invalid_value) |
| 1044 | << Args.getLastArg(OPT_O)->getAsString(Args) << Opts.OptimizationLevel; |
| 1045 | Opts.OptimizationLevel = 3; |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1046 | } |
| 1047 | |
| 1048 | // We must always run at least the always inlining pass. |
| 1049 | Opts.Inlining = (Opts.OptimizationLevel > 1) ? CodeGenOptions::NormalInlining |
| 1050 | : CodeGenOptions::OnlyAlwaysInlining; |
| 1051 | |
| 1052 | Opts.DebugInfo = Args.hasArg(OPT_g); |
Devang Patel | 033be8b | 2011-11-04 20:05:58 +0000 | [diff] [blame] | 1053 | Opts.LimitDebugInfo = !Args.hasArg(OPT_fno_limit_debug_info) |
| 1054 | || Args.hasArg(OPT_flimit_debug_info); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1055 | Opts.DisableLLVMOpts = Args.hasArg(OPT_disable_llvm_optzns); |
| 1056 | Opts.DisableRedZone = Args.hasArg(OPT_disable_red_zone); |
John McCall | 3209669 | 2011-03-18 02:56:14 +0000 | [diff] [blame] | 1057 | Opts.ForbidGuardVariables = Args.hasArg(OPT_fforbid_guard_variables); |
Daniel Dunbar | e26bdb9 | 2011-06-21 18:54:46 +0000 | [diff] [blame] | 1058 | Opts.UseRegisterSizedBitfieldAccess = Args.hasArg( |
| 1059 | OPT_fuse_register_sized_bitfield_access); |
Dan Gohman | 4d5625e | 2010-10-14 22:36:56 +0000 | [diff] [blame] | 1060 | Opts.RelaxedAliasing = Args.hasArg(OPT_relaxed_aliasing); |
Daniel Dunbar | 03e8ab2 | 2010-05-20 16:54:55 +0000 | [diff] [blame] | 1061 | Opts.DwarfDebugFlags = Args.getLastArgValue(OPT_dwarf_debug_flags); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1062 | Opts.MergeAllConstants = !Args.hasArg(OPT_fno_merge_all_constants); |
| 1063 | Opts.NoCommon = Args.hasArg(OPT_fno_common); |
| 1064 | Opts.NoImplicitFloat = Args.hasArg(OPT_no_implicit_float); |
| 1065 | Opts.OptimizeSize = Args.hasArg(OPT_Os); |
Bob Wilson | a0fa203 | 2011-04-29 22:49:50 +0000 | [diff] [blame] | 1066 | Opts.OptimizeSize = Args.hasArg(OPT_Oz) ? 2 : Opts.OptimizeSize; |
Daniel Dunbar | 6b0cf67 | 2010-06-07 23:19:17 +0000 | [diff] [blame] | 1067 | Opts.SimplifyLibCalls = !(Args.hasArg(OPT_fno_builtin) || |
| 1068 | Args.hasArg(OPT_ffreestanding)); |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1069 | Opts.UnrollLoops = Args.hasArg(OPT_funroll_loops) || |
Eric Christopher | f84d409 | 2010-08-07 23:08:14 +0000 | [diff] [blame] | 1070 | (Opts.OptimizationLevel > 1 && !Opts.OptimizeSize); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1071 | |
| 1072 | Opts.AsmVerbose = Args.hasArg(OPT_masm_verbose); |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 1073 | Opts.ObjCAutoRefCountExceptions = Args.hasArg(OPT_fobjc_arc_exceptions); |
John McCall | 9f084a3 | 2011-07-06 00:26:06 +0000 | [diff] [blame] | 1074 | Opts.ObjCRuntimeHasARC = Args.hasArg(OPT_fobjc_runtime_has_arc); |
John McCall | 256a76e | 2011-07-06 01:22:26 +0000 | [diff] [blame] | 1075 | Opts.ObjCRuntimeHasTerminate = Args.hasArg(OPT_fobjc_runtime_has_terminate); |
Peter Collingbourne | d51e43a | 2011-10-06 18:29:46 +0000 | [diff] [blame] | 1076 | Opts.CUDAIsDevice = Args.hasArg(OPT_fcuda_is_device); |
Daniel Dunbar | efb0fa9 | 2010-03-20 04:15:41 +0000 | [diff] [blame] | 1077 | Opts.CXAAtExit = !Args.hasArg(OPT_fno_use_cxa_atexit); |
| 1078 | Opts.CXXCtorDtorAliases = Args.hasArg(OPT_mconstructor_aliases); |
Daniel Dunbar | 03e8ab2 | 2010-05-20 16:54:55 +0000 | [diff] [blame] | 1079 | Opts.CodeModel = Args.getLastArgValue(OPT_mcode_model); |
| 1080 | Opts.DebugPass = Args.getLastArgValue(OPT_mdebug_pass); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1081 | Opts.DisableFPElim = Args.hasArg(OPT_mdisable_fp_elim); |
Daniel Dunbar | 03e8ab2 | 2010-05-20 16:54:55 +0000 | [diff] [blame] | 1082 | Opts.FloatABI = Args.getLastArgValue(OPT_mfloat_abi); |
John McCall | 279b5eb | 2010-08-12 23:36:15 +0000 | [diff] [blame] | 1083 | Opts.HiddenWeakVTables = Args.hasArg(OPT_fhidden_weak_vtables); |
Peter Collingbourne | 4400cb8 | 2010-12-04 01:51:33 +0000 | [diff] [blame] | 1084 | Opts.LessPreciseFPMAD = Args.hasArg(OPT_cl_mad_enable); |
Daniel Dunbar | 03e8ab2 | 2010-05-20 16:54:55 +0000 | [diff] [blame] | 1085 | Opts.LimitFloatPrecision = Args.getLastArgValue(OPT_mlimit_float_precision); |
Peter Collingbourne | f084082 | 2010-12-04 01:51:23 +0000 | [diff] [blame] | 1086 | Opts.NoInfsFPMath = Opts.NoNaNsFPMath = Args.hasArg(OPT_cl_finite_math_only)|| |
| 1087 | Args.hasArg(OPT_cl_fast_relaxed_math); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1088 | Opts.NoZeroInitializedInBSS = Args.hasArg(OPT_mno_zero_initialized_in_bss); |
Daniel Dunbar | 3c66d30 | 2011-03-22 16:48:17 +0000 | [diff] [blame] | 1089 | Opts.BackendOptions = Args.getAllArgValues(OPT_backend_option); |
Daniel Dunbar | 17d3fea | 2011-02-09 17:54:19 +0000 | [diff] [blame] | 1090 | Opts.NumRegisterParameters = Args.getLastArgIntValue(OPT_mregparm, 0, Diags); |
Chad Rosier | 1b90605 | 2011-08-26 00:26:29 +0000 | [diff] [blame] | 1091 | Opts.NoGlobalMerge = Args.hasArg(OPT_mno_global_merge); |
Nick Lewycky | c3b9014 | 2011-06-21 00:14:18 +0000 | [diff] [blame] | 1092 | Opts.NoExecStack = Args.hasArg(OPT_mno_exec_stack); |
Daniel Dunbar | 4ecc9b7 | 2010-05-27 05:39:39 +0000 | [diff] [blame] | 1093 | Opts.RelaxAll = Args.hasArg(OPT_mrelax_all); |
Daniel Dunbar | 1ad6648 | 2010-07-01 01:31:45 +0000 | [diff] [blame] | 1094 | Opts.OmitLeafFramePointer = Args.hasArg(OPT_momit_leaf_frame_pointer); |
Daniel Dunbar | 9693232 | 2011-03-28 22:49:28 +0000 | [diff] [blame] | 1095 | Opts.SaveTempLabels = Args.hasArg(OPT_msave_temp_labels); |
Rafael Espindola | f24a151 | 2011-04-30 18:35:43 +0000 | [diff] [blame] | 1096 | Opts.NoDwarf2CFIAsm = Args.hasArg(OPT_fno_dwarf2_cfi_asm); |
Nick Lewycky | ea523d7 | 2011-10-17 23:05:52 +0000 | [diff] [blame] | 1097 | Opts.NoDwarfDirectoryAsm = Args.hasArg(OPT_fno_dwarf_directory_asm); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1098 | Opts.SoftFloat = Args.hasArg(OPT_msoft_float); |
Peter Collingbourne | f084082 | 2010-12-04 01:51:23 +0000 | [diff] [blame] | 1099 | Opts.UnsafeFPMath = Args.hasArg(OPT_cl_unsafe_math_optimizations) || |
| 1100 | Args.hasArg(OPT_cl_fast_relaxed_math); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1101 | Opts.UnwindTables = Args.hasArg(OPT_munwind_tables); |
Daniel Dunbar | 03e8ab2 | 2010-05-20 16:54:55 +0000 | [diff] [blame] | 1102 | Opts.RelocationModel = Args.getLastArgValue(OPT_mrelocation_model, "pic"); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1103 | |
Chris Lattner | bbea716 | 2010-04-13 00:38:24 +0000 | [diff] [blame] | 1104 | Opts.FunctionSections = Args.hasArg(OPT_ffunction_sections); |
| 1105 | Opts.DataSections = Args.hasArg(OPT_fdata_sections); |
| 1106 | |
Daniel Dunbar | 03e8ab2 | 2010-05-20 16:54:55 +0000 | [diff] [blame] | 1107 | Opts.MainFileName = Args.getLastArgValue(OPT_main_file_name); |
John McCall | 824e19e | 2010-02-12 23:47:27 +0000 | [diff] [blame] | 1108 | Opts.VerifyModule = !Args.hasArg(OPT_disable_llvm_verifier); |
Daniel Dunbar | f643b9b | 2010-04-24 17:56:46 +0000 | [diff] [blame] | 1109 | |
Chris Lattner | 7255a2d | 2010-06-22 00:03:40 +0000 | [diff] [blame] | 1110 | Opts.InstrumentFunctions = Args.hasArg(OPT_finstrument_functions); |
Roman Divacky | be4c870 | 2011-02-10 16:52:03 +0000 | [diff] [blame] | 1111 | Opts.InstrumentForProfiling = Args.hasArg(OPT_pg); |
Nick Lewycky | e8ba8d7 | 2011-04-21 23:44:07 +0000 | [diff] [blame] | 1112 | Opts.EmitGcovArcs = Args.hasArg(OPT_femit_coverage_data); |
| 1113 | Opts.EmitGcovNotes = Args.hasArg(OPT_femit_coverage_notes); |
Nick Lewycky | 3dc0541 | 2011-05-05 00:08:20 +0000 | [diff] [blame] | 1114 | Opts.CoverageFile = Args.getLastArgValue(OPT_coverage_file); |
Nick Lewycky | 7c4fd91 | 2011-10-21 02:32:14 +0000 | [diff] [blame] | 1115 | Opts.DebugCompilationDir = Args.getLastArgValue(OPT_fdebug_compilation_dir); |
Peter Collingbourne | 22a7dfe | 2011-10-30 17:30:44 +0000 | [diff] [blame] | 1116 | Opts.LinkBitcodeFile = Args.getLastArgValue(OPT_mlink_bitcode_file); |
Chris Lattner | 7255a2d | 2010-06-22 00:03:40 +0000 | [diff] [blame] | 1117 | |
Daniel Dunbar | f643b9b | 2010-04-24 17:56:46 +0000 | [diff] [blame] | 1118 | if (Arg *A = Args.getLastArg(OPT_fobjc_dispatch_method_EQ)) { |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1119 | StringRef Name = A->getValue(Args); |
Daniel Dunbar | f643b9b | 2010-04-24 17:56:46 +0000 | [diff] [blame] | 1120 | unsigned Method = llvm::StringSwitch<unsigned>(Name) |
| 1121 | .Case("legacy", CodeGenOptions::Legacy) |
| 1122 | .Case("non-legacy", CodeGenOptions::NonLegacy) |
| 1123 | .Case("mixed", CodeGenOptions::Mixed) |
| 1124 | .Default(~0U); |
| 1125 | if (Method == ~0U) |
| 1126 | Diags.Report(diag::err_drv_invalid_value) << A->getAsString(Args) << Name; |
| 1127 | else |
| 1128 | Opts.ObjCDispatchMethod = Method; |
| 1129 | } |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1130 | } |
| 1131 | |
| 1132 | static void ParseDependencyOutputArgs(DependencyOutputOptions &Opts, |
| 1133 | ArgList &Args) { |
| 1134 | using namespace cc1options; |
Daniel Dunbar | 03e8ab2 | 2010-05-20 16:54:55 +0000 | [diff] [blame] | 1135 | Opts.OutputFile = Args.getLastArgValue(OPT_dependency_file); |
| 1136 | Opts.Targets = Args.getAllArgValues(OPT_MT); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1137 | Opts.IncludeSystemHeaders = Args.hasArg(OPT_sys_header_deps); |
| 1138 | Opts.UsePhonyTargets = Args.hasArg(OPT_MP); |
Daniel Dunbar | eef63e0 | 2011-02-02 15:41:17 +0000 | [diff] [blame] | 1139 | Opts.ShowHeaderIncludes = Args.hasArg(OPT_H); |
Daniel Dunbar | b34d69b | 2011-02-02 21:11:31 +0000 | [diff] [blame] | 1140 | Opts.HeaderIncludeOutputFile = Args.getLastArgValue(OPT_header_include_file); |
Peter Collingbourne | bb52786 | 2011-07-12 19:35:15 +0000 | [diff] [blame] | 1141 | Opts.AddMissingHeaderDeps = Args.hasArg(OPT_MG); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1142 | } |
| 1143 | |
| 1144 | static void ParseDiagnosticArgs(DiagnosticOptions &Opts, ArgList &Args, |
David Blaikie | d6471f7 | 2011-09-25 23:23:43 +0000 | [diff] [blame] | 1145 | DiagnosticsEngine &Diags) { |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1146 | using namespace cc1options; |
Daniel Dunbar | 08c6695 | 2011-04-07 18:11:14 +0000 | [diff] [blame] | 1147 | Opts.DiagnosticLogFile = Args.getLastArgValue(OPT_diagnostic_log_file); |
Ted Kremenek | 7800212 | 2011-10-29 00:12:39 +0000 | [diff] [blame] | 1148 | Opts.DiagnosticSerializationFile = |
| 1149 | Args.getLastArgValue(OPT_diagnostic_serialized_file); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1150 | Opts.IgnoreWarnings = Args.hasArg(OPT_w); |
| 1151 | Opts.NoRewriteMacros = Args.hasArg(OPT_Wno_rewrite_macros); |
| 1152 | Opts.Pedantic = Args.hasArg(OPT_pedantic); |
| 1153 | Opts.PedanticErrors = Args.hasArg(OPT_pedantic_errors); |
| 1154 | Opts.ShowCarets = !Args.hasArg(OPT_fno_caret_diagnostics); |
| 1155 | Opts.ShowColors = Args.hasArg(OPT_fcolor_diagnostics); |
Douglas Gregor | c9471b0 | 2011-05-21 17:07:29 +0000 | [diff] [blame] | 1156 | Opts.ShowColumn = Args.hasFlag(OPT_fshow_column, |
| 1157 | OPT_fno_show_column, |
| 1158 | /*Default=*/true); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1159 | Opts.ShowFixits = !Args.hasArg(OPT_fno_diagnostics_fixit_info); |
| 1160 | Opts.ShowLocation = !Args.hasArg(OPT_fno_show_source_location); |
Douglas Gregor | 7d2b8c1 | 2011-04-15 22:04:17 +0000 | [diff] [blame] | 1161 | Opts.ShowNames = Args.hasArg(OPT_fdiagnostics_show_name); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1162 | Opts.ShowOptionNames = Args.hasArg(OPT_fdiagnostics_show_option); |
Jeffrey Yasskin | 5edbdcc | 2010-06-11 05:57:47 +0000 | [diff] [blame] | 1163 | |
Chandler Carruth | 34b8e68 | 2011-03-27 20:00:08 +0000 | [diff] [blame] | 1164 | // Default behavior is to not to show note include stacks. |
| 1165 | Opts.ShowNoteIncludeStack = false; |
Chandler Carruth | abaca7a | 2011-03-27 01:50:55 +0000 | [diff] [blame] | 1166 | if (Arg *A = Args.getLastArg(OPT_fdiagnostics_show_note_include_stack, |
| 1167 | OPT_fno_diagnostics_show_note_include_stack)) |
Chandler Carruth | 34b8e68 | 2011-03-27 20:00:08 +0000 | [diff] [blame] | 1168 | if (A->getOption().matches(OPT_fdiagnostics_show_note_include_stack)) |
| 1169 | Opts.ShowNoteIncludeStack = true; |
Chandler Carruth | abaca7a | 2011-03-27 01:50:55 +0000 | [diff] [blame] | 1170 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1171 | StringRef ShowOverloads = |
Jeffrey Yasskin | 5edbdcc | 2010-06-11 05:57:47 +0000 | [diff] [blame] | 1172 | Args.getLastArgValue(OPT_fshow_overloads_EQ, "all"); |
| 1173 | if (ShowOverloads == "best") |
David Blaikie | d6471f7 | 2011-09-25 23:23:43 +0000 | [diff] [blame] | 1174 | Opts.ShowOverloads = DiagnosticsEngine::Ovl_Best; |
Jeffrey Yasskin | 5edbdcc | 2010-06-11 05:57:47 +0000 | [diff] [blame] | 1175 | else if (ShowOverloads == "all") |
David Blaikie | d6471f7 | 2011-09-25 23:23:43 +0000 | [diff] [blame] | 1176 | Opts.ShowOverloads = DiagnosticsEngine::Ovl_All; |
Jeffrey Yasskin | 5edbdcc | 2010-06-11 05:57:47 +0000 | [diff] [blame] | 1177 | else |
| 1178 | Diags.Report(diag::err_drv_invalid_value) |
| 1179 | << Args.getLastArg(OPT_fshow_overloads_EQ)->getAsString(Args) |
| 1180 | << ShowOverloads; |
| 1181 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1182 | StringRef ShowCategory = |
Daniel Dunbar | 03e8ab2 | 2010-05-20 16:54:55 +0000 | [diff] [blame] | 1183 | Args.getLastArgValue(OPT_fdiagnostics_show_category, "none"); |
Chris Lattner | 6fbe839 | 2010-05-04 21:55:25 +0000 | [diff] [blame] | 1184 | if (ShowCategory == "none") |
| 1185 | Opts.ShowCategories = 0; |
| 1186 | else if (ShowCategory == "id") |
| 1187 | Opts.ShowCategories = 1; |
| 1188 | else if (ShowCategory == "name") |
| 1189 | Opts.ShowCategories = 2; |
| 1190 | else |
| 1191 | Diags.Report(diag::err_drv_invalid_value) |
| 1192 | << Args.getLastArg(OPT_fdiagnostics_show_category)->getAsString(Args) |
| 1193 | << ShowCategory; |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1194 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1195 | StringRef Format = |
Douglas Gregor | c9471b0 | 2011-05-21 17:07:29 +0000 | [diff] [blame] | 1196 | Args.getLastArgValue(OPT_fdiagnostics_format, "clang"); |
| 1197 | if (Format == "clang") |
| 1198 | Opts.Format = DiagnosticOptions::Clang; |
| 1199 | else if (Format == "msvc") |
| 1200 | Opts.Format = DiagnosticOptions::Msvc; |
| 1201 | else if (Format == "vi") |
| 1202 | Opts.Format = DiagnosticOptions::Vi; |
| 1203 | else |
| 1204 | Diags.Report(diag::err_drv_invalid_value) |
| 1205 | << Args.getLastArg(OPT_fdiagnostics_format)->getAsString(Args) |
| 1206 | << Format; |
| 1207 | |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1208 | Opts.ShowSourceRanges = Args.hasArg(OPT_fdiagnostics_print_source_range_info); |
Douglas Gregor | 4786c15 | 2010-08-19 20:24:43 +0000 | [diff] [blame] | 1209 | Opts.ShowParseableFixits = Args.hasArg(OPT_fdiagnostics_parseable_fixits); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1210 | Opts.VerifyDiagnostics = Args.hasArg(OPT_verify); |
Daniel Dunbar | 03e8ab2 | 2010-05-20 16:54:55 +0000 | [diff] [blame] | 1211 | Opts.ErrorLimit = Args.getLastArgIntValue(OPT_ferror_limit, 0, Diags); |
Douglas Gregor | 6c1cb99 | 2010-05-04 17:13:42 +0000 | [diff] [blame] | 1212 | Opts.MacroBacktraceLimit |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1213 | = Args.getLastArgIntValue(OPT_fmacro_backtrace_limit, |
Douglas Gregor | 6c1cb99 | 2010-05-04 17:13:42 +0000 | [diff] [blame] | 1214 | DiagnosticOptions::DefaultMacroBacktraceLimit, Diags); |
Douglas Gregor | 575cf37 | 2010-04-20 07:18:24 +0000 | [diff] [blame] | 1215 | Opts.TemplateBacktraceLimit |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1216 | = Args.getLastArgIntValue(OPT_ftemplate_backtrace_limit, |
| 1217 | DiagnosticOptions::DefaultTemplateBacktraceLimit, |
Douglas Gregor | 6c1cb99 | 2010-05-04 17:13:42 +0000 | [diff] [blame] | 1218 | Diags); |
Daniel Dunbar | 03e8ab2 | 2010-05-20 16:54:55 +0000 | [diff] [blame] | 1219 | Opts.TabStop = Args.getLastArgIntValue(OPT_ftabstop, |
Chris Lattner | 52388f9 | 2010-01-13 03:06:50 +0000 | [diff] [blame] | 1220 | DiagnosticOptions::DefaultTabStop, Diags); |
| 1221 | if (Opts.TabStop == 0 || Opts.TabStop > DiagnosticOptions::MaxTabStop) { |
| 1222 | Diags.Report(diag::warn_ignoring_ftabstop_value) |
| 1223 | << Opts.TabStop << DiagnosticOptions::DefaultTabStop; |
| 1224 | Opts.TabStop = DiagnosticOptions::DefaultTabStop; |
| 1225 | } |
Daniel Dunbar | 03e8ab2 | 2010-05-20 16:54:55 +0000 | [diff] [blame] | 1226 | Opts.MessageLength = Args.getLastArgIntValue(OPT_fmessage_length, 0, Diags); |
| 1227 | Opts.DumpBuildInformation = Args.getLastArgValue(OPT_dump_build_information); |
| 1228 | Opts.Warnings = Args.getAllArgValues(OPT_W); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1229 | } |
| 1230 | |
Argyrios Kyrtzidis | 389db16 | 2010-11-03 22:45:23 +0000 | [diff] [blame] | 1231 | static void ParseFileSystemArgs(FileSystemOptions &Opts, ArgList &Args) { |
| 1232 | Opts.WorkingDir = Args.getLastArgValue(OPT_working_directory); |
| 1233 | } |
| 1234 | |
Daniel Dunbar | c34ce3f | 2010-06-07 23:22:09 +0000 | [diff] [blame] | 1235 | static InputKind ParseFrontendArgs(FrontendOptions &Opts, ArgList &Args, |
David Blaikie | d6471f7 | 2011-09-25 23:23:43 +0000 | [diff] [blame] | 1236 | DiagnosticsEngine &Diags) { |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1237 | using namespace cc1options; |
| 1238 | Opts.ProgramAction = frontend::ParseSyntaxOnly; |
| 1239 | if (const Arg *A = Args.getLastArg(OPT_Action_Group)) { |
| 1240 | switch (A->getOption().getID()) { |
| 1241 | default: |
David Blaikie | b219cfc | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 1242 | llvm_unreachable("Invalid option in group!"); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1243 | case OPT_ast_dump: |
| 1244 | Opts.ProgramAction = frontend::ASTDump; break; |
John McCall | f351424 | 2010-11-24 11:21:45 +0000 | [diff] [blame] | 1245 | case OPT_ast_dump_xml: |
| 1246 | Opts.ProgramAction = frontend::ASTDumpXML; break; |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1247 | case OPT_ast_print: |
| 1248 | Opts.ProgramAction = frontend::ASTPrint; break; |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1249 | case OPT_ast_view: |
| 1250 | Opts.ProgramAction = frontend::ASTView; break; |
| 1251 | case OPT_dump_raw_tokens: |
| 1252 | Opts.ProgramAction = frontend::DumpRawTokens; break; |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1253 | case OPT_dump_tokens: |
| 1254 | Opts.ProgramAction = frontend::DumpTokens; break; |
| 1255 | case OPT_S: |
| 1256 | Opts.ProgramAction = frontend::EmitAssembly; break; |
| 1257 | case OPT_emit_llvm_bc: |
| 1258 | Opts.ProgramAction = frontend::EmitBC; break; |
| 1259 | case OPT_emit_html: |
| 1260 | Opts.ProgramAction = frontend::EmitHTML; break; |
| 1261 | case OPT_emit_llvm: |
| 1262 | Opts.ProgramAction = frontend::EmitLLVM; break; |
| 1263 | case OPT_emit_llvm_only: |
| 1264 | Opts.ProgramAction = frontend::EmitLLVMOnly; break; |
Daniel Dunbar | 32148ce | 2010-05-25 18:41:01 +0000 | [diff] [blame] | 1265 | case OPT_emit_codegen_only: |
| 1266 | Opts.ProgramAction = frontend::EmitCodeGenOnly; break; |
Daniel Dunbar | da1573f | 2010-02-03 01:18:43 +0000 | [diff] [blame] | 1267 | case OPT_emit_obj: |
| 1268 | Opts.ProgramAction = frontend::EmitObj; break; |
Nick Lewycky | ba5f6ec | 2010-04-24 01:30:46 +0000 | [diff] [blame] | 1269 | case OPT_fixit_EQ: |
| 1270 | Opts.FixItSuffix = A->getValue(Args); |
| 1271 | // fall-through! |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1272 | case OPT_fixit: |
| 1273 | Opts.ProgramAction = frontend::FixIt; break; |
Douglas Gregor | 467dc88 | 2011-08-25 22:30:56 +0000 | [diff] [blame] | 1274 | case OPT_emit_module: |
| 1275 | Opts.ProgramAction = frontend::GenerateModule; break; |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1276 | case OPT_emit_pch: |
| 1277 | Opts.ProgramAction = frontend::GeneratePCH; break; |
| 1278 | case OPT_emit_pth: |
| 1279 | Opts.ProgramAction = frontend::GeneratePTH; break; |
Daniel Dunbar | 2758595 | 2010-03-19 19:44:04 +0000 | [diff] [blame] | 1280 | case OPT_init_only: |
| 1281 | Opts.ProgramAction = frontend::InitOnly; break; |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1282 | case OPT_fsyntax_only: |
| 1283 | Opts.ProgramAction = frontend::ParseSyntaxOnly; break; |
| 1284 | case OPT_print_decl_contexts: |
| 1285 | Opts.ProgramAction = frontend::PrintDeclContext; break; |
Douglas Gregor | f033f1d | 2010-07-20 20:18:03 +0000 | [diff] [blame] | 1286 | case OPT_print_preamble: |
| 1287 | Opts.ProgramAction = frontend::PrintPreamble; break; |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1288 | case OPT_E: |
| 1289 | Opts.ProgramAction = frontend::PrintPreprocessedInput; break; |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1290 | case OPT_rewrite_macros: |
| 1291 | Opts.ProgramAction = frontend::RewriteMacros; break; |
| 1292 | case OPT_rewrite_objc: |
| 1293 | Opts.ProgramAction = frontend::RewriteObjC; break; |
| 1294 | case OPT_rewrite_test: |
| 1295 | Opts.ProgramAction = frontend::RewriteTest; break; |
| 1296 | case OPT_analyze: |
| 1297 | Opts.ProgramAction = frontend::RunAnalysis; break; |
| 1298 | case OPT_Eonly: |
| 1299 | Opts.ProgramAction = frontend::RunPreprocessorOnly; break; |
| 1300 | } |
| 1301 | } |
Daniel Dunbar | 3177aae | 2010-06-16 16:59:23 +0000 | [diff] [blame] | 1302 | |
| 1303 | if (const Arg* A = Args.getLastArg(OPT_plugin)) { |
| 1304 | Opts.Plugins.push_back(A->getValue(Args,0)); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1305 | Opts.ProgramAction = frontend::PluginAction; |
| 1306 | Opts.ActionName = A->getValue(Args); |
Daniel Dunbar | 3177aae | 2010-06-16 16:59:23 +0000 | [diff] [blame] | 1307 | |
| 1308 | for (arg_iterator it = Args.filtered_begin(OPT_plugin_arg), |
| 1309 | end = Args.filtered_end(); it != end; ++it) { |
| 1310 | if ((*it)->getValue(Args, 0) == Opts.ActionName) |
| 1311 | Opts.PluginArgs.push_back((*it)->getValue(Args, 1)); |
| 1312 | } |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1313 | } |
| 1314 | |
Nico Weber | 5aa74af | 2011-01-25 20:34:14 +0000 | [diff] [blame] | 1315 | Opts.AddPluginActions = Args.getAllArgValues(OPT_add_plugin); |
Nico Weber | f25649c | 2011-01-29 21:21:49 +0000 | [diff] [blame] | 1316 | Opts.AddPluginArgs.resize(Opts.AddPluginActions.size()); |
| 1317 | for (int i = 0, e = Opts.AddPluginActions.size(); i != e; ++i) { |
| 1318 | for (arg_iterator it = Args.filtered_begin(OPT_plugin_arg), |
| 1319 | end = Args.filtered_end(); it != end; ++it) { |
| 1320 | if ((*it)->getValue(Args, 0) == Opts.AddPluginActions[i]) |
| 1321 | Opts.AddPluginArgs[i].push_back((*it)->getValue(Args, 1)); |
| 1322 | } |
| 1323 | } |
Nico Weber | 5aa74af | 2011-01-25 20:34:14 +0000 | [diff] [blame] | 1324 | |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1325 | if (const Arg *A = Args.getLastArg(OPT_code_completion_at)) { |
| 1326 | Opts.CodeCompletionAt = |
| 1327 | ParsedSourceLocation::FromString(A->getValue(Args)); |
| 1328 | if (Opts.CodeCompletionAt.FileName.empty()) |
| 1329 | Diags.Report(diag::err_drv_invalid_value) |
| 1330 | << A->getAsString(Args) << A->getValue(Args); |
| 1331 | } |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1332 | Opts.DisableFree = Args.hasArg(OPT_disable_free); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1333 | |
Daniel Dunbar | 03e8ab2 | 2010-05-20 16:54:55 +0000 | [diff] [blame] | 1334 | Opts.OutputFile = Args.getLastArgValue(OPT_o); |
| 1335 | Opts.Plugins = Args.getAllArgValues(OPT_load); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1336 | Opts.RelocatablePCH = Args.hasArg(OPT_relocatable_pch); |
Daniel Dunbar | 9b5e9ae | 2009-12-03 07:01:58 +0000 | [diff] [blame] | 1337 | Opts.ShowHelp = Args.hasArg(OPT_help); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1338 | Opts.ShowMacrosInCodeCompletion = Args.hasArg(OPT_code_completion_macros); |
Douglas Gregor | d8e8a58 | 2010-05-25 21:41:55 +0000 | [diff] [blame] | 1339 | Opts.ShowCodePatternsInCodeCompletion |
| 1340 | = Args.hasArg(OPT_code_completion_patterns); |
Douglas Gregor | 8071e42 | 2010-08-15 06:18:01 +0000 | [diff] [blame] | 1341 | Opts.ShowGlobalSymbolsInCodeCompletion |
| 1342 | = !Args.hasArg(OPT_no_code_completion_globals); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1343 | Opts.ShowStats = Args.hasArg(OPT_print_stats); |
| 1344 | Opts.ShowTimers = Args.hasArg(OPT_ftime_report); |
Daniel Dunbar | 9b5e9ae | 2009-12-03 07:01:58 +0000 | [diff] [blame] | 1345 | Opts.ShowVersion = Args.hasArg(OPT_version); |
Daniel Dunbar | 03e8ab2 | 2010-05-20 16:54:55 +0000 | [diff] [blame] | 1346 | Opts.ASTMergeFiles = Args.getAllArgValues(OPT_ast_merge); |
| 1347 | Opts.LLVMArgs = Args.getAllArgValues(OPT_mllvm); |
Nick Lewycky | 1450f26 | 2010-08-13 17:31:00 +0000 | [diff] [blame] | 1348 | Opts.FixWhatYouCan = Args.hasArg(OPT_fix_what_you_can); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1349 | |
John McCall | 8f0e8d2 | 2011-06-15 23:25:17 +0000 | [diff] [blame] | 1350 | Opts.ARCMTAction = FrontendOptions::ARCMT_None; |
| 1351 | if (const Arg *A = Args.getLastArg(OPT_arcmt_check, |
Argyrios Kyrtzidis | 69325d5 | 2011-07-09 20:00:58 +0000 | [diff] [blame] | 1352 | OPT_arcmt_modify, |
| 1353 | OPT_arcmt_migrate)) { |
John McCall | 8f0e8d2 | 2011-06-15 23:25:17 +0000 | [diff] [blame] | 1354 | switch (A->getOption().getID()) { |
| 1355 | default: |
| 1356 | llvm_unreachable("missed a case"); |
| 1357 | case OPT_arcmt_check: |
| 1358 | Opts.ARCMTAction = FrontendOptions::ARCMT_Check; |
| 1359 | break; |
| 1360 | case OPT_arcmt_modify: |
| 1361 | Opts.ARCMTAction = FrontendOptions::ARCMT_Modify; |
| 1362 | break; |
Argyrios Kyrtzidis | 69325d5 | 2011-07-09 20:00:58 +0000 | [diff] [blame] | 1363 | case OPT_arcmt_migrate: |
| 1364 | Opts.ARCMTAction = FrontendOptions::ARCMT_Migrate; |
| 1365 | break; |
John McCall | 8f0e8d2 | 2011-06-15 23:25:17 +0000 | [diff] [blame] | 1366 | } |
| 1367 | } |
Argyrios Kyrtzidis | 69325d5 | 2011-07-09 20:00:58 +0000 | [diff] [blame] | 1368 | Opts.ARCMTMigrateDir = Args.getLastArgValue(OPT_arcmt_migrate_directory); |
Argyrios Kyrtzidis | 7ee2049 | 2011-07-19 17:20:03 +0000 | [diff] [blame] | 1369 | Opts.ARCMTMigrateReportOut |
| 1370 | = Args.getLastArgValue(OPT_arcmt_migrate_report_output); |
| 1371 | Opts.ARCMTMigrateEmitARCErrors |
| 1372 | = Args.hasArg(OPT_arcmt_migrate_emit_arc_errors); |
John McCall | 8f0e8d2 | 2011-06-15 23:25:17 +0000 | [diff] [blame] | 1373 | |
Daniel Dunbar | c34ce3f | 2010-06-07 23:22:09 +0000 | [diff] [blame] | 1374 | InputKind DashX = IK_None; |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1375 | if (const Arg *A = Args.getLastArg(OPT_x)) { |
Daniel Dunbar | c34ce3f | 2010-06-07 23:22:09 +0000 | [diff] [blame] | 1376 | DashX = llvm::StringSwitch<InputKind>(A->getValue(Args)) |
| 1377 | .Case("c", IK_C) |
| 1378 | .Case("cl", IK_OpenCL) |
Peter Collingbourne | 895fcca | 2010-12-01 03:15:20 +0000 | [diff] [blame] | 1379 | .Case("cuda", IK_CUDA) |
Daniel Dunbar | c34ce3f | 2010-06-07 23:22:09 +0000 | [diff] [blame] | 1380 | .Case("c++", IK_CXX) |
| 1381 | .Case("objective-c", IK_ObjC) |
| 1382 | .Case("objective-c++", IK_ObjCXX) |
| 1383 | .Case("cpp-output", IK_PreprocessedC) |
| 1384 | .Case("assembler-with-cpp", IK_Asm) |
| 1385 | .Case("c++-cpp-output", IK_PreprocessedCXX) |
| 1386 | .Case("objective-c-cpp-output", IK_PreprocessedObjC) |
Chris Lattner | 919f2ca | 2011-04-09 07:09:31 +0000 | [diff] [blame] | 1387 | .Case("objc-cpp-output", IK_PreprocessedObjC) |
Daniel Dunbar | c34ce3f | 2010-06-07 23:22:09 +0000 | [diff] [blame] | 1388 | .Case("objective-c++-cpp-output", IK_PreprocessedObjCXX) |
Nico Weber | 1f7957d | 2011-08-13 19:03:50 +0000 | [diff] [blame] | 1389 | .Case("objc++-cpp-output", IK_PreprocessedObjCXX) |
Daniel Dunbar | c34ce3f | 2010-06-07 23:22:09 +0000 | [diff] [blame] | 1390 | .Case("c-header", IK_C) |
Peter Collingbourne | ae57ead | 2011-10-09 22:03:19 +0000 | [diff] [blame] | 1391 | .Case("cl-header", IK_OpenCL) |
Daniel Dunbar | c34ce3f | 2010-06-07 23:22:09 +0000 | [diff] [blame] | 1392 | .Case("objective-c-header", IK_ObjC) |
| 1393 | .Case("c++-header", IK_CXX) |
| 1394 | .Case("objective-c++-header", IK_ObjCXX) |
| 1395 | .Case("ast", IK_AST) |
Daniel Dunbar | faddc3e | 2010-06-07 23:26:47 +0000 | [diff] [blame] | 1396 | .Case("ir", IK_LLVM_IR) |
Daniel Dunbar | c34ce3f | 2010-06-07 23:22:09 +0000 | [diff] [blame] | 1397 | .Default(IK_None); |
| 1398 | if (DashX == IK_None) |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1399 | Diags.Report(diag::err_drv_invalid_value) |
| 1400 | << A->getAsString(Args) << A->getValue(Args); |
| 1401 | } |
| 1402 | |
| 1403 | // '-' is the default input if none is given. |
Daniel Dunbar | 03e8ab2 | 2010-05-20 16:54:55 +0000 | [diff] [blame] | 1404 | std::vector<std::string> Inputs = Args.getAllArgValues(OPT_INPUT); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1405 | Opts.Inputs.clear(); |
| 1406 | if (Inputs.empty()) |
| 1407 | Inputs.push_back("-"); |
| 1408 | for (unsigned i = 0, e = Inputs.size(); i != e; ++i) { |
Daniel Dunbar | c34ce3f | 2010-06-07 23:22:09 +0000 | [diff] [blame] | 1409 | InputKind IK = DashX; |
| 1410 | if (IK == IK_None) { |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1411 | IK = FrontendOptions::getInputKindForExtension( |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1412 | StringRef(Inputs[i]).rsplit('.').second); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1413 | // FIXME: Remove this hack. |
| 1414 | if (i == 0) |
| 1415 | DashX = IK; |
| 1416 | } |
| 1417 | Opts.Inputs.push_back(std::make_pair(IK, Inputs[i])); |
| 1418 | } |
| 1419 | |
| 1420 | return DashX; |
| 1421 | } |
| 1422 | |
Daniel Dunbar | 8b9adfe | 2009-12-15 00:06:45 +0000 | [diff] [blame] | 1423 | std::string CompilerInvocation::GetResourcesPath(const char *Argv0, |
| 1424 | void *MainAddr) { |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1425 | llvm::sys::Path P = llvm::sys::Path::GetMainExecutable(Argv0, MainAddr); |
| 1426 | |
| 1427 | if (!P.isEmpty()) { |
| 1428 | P.eraseComponent(); // Remove /clang from foo/bin/clang |
| 1429 | P.eraseComponent(); // Remove /bin from foo/bin |
| 1430 | |
| 1431 | // Get foo/lib/clang/<version>/include |
| 1432 | P.appendComponent("lib"); |
| 1433 | P.appendComponent("clang"); |
| 1434 | P.appendComponent(CLANG_VERSION_STRING); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1435 | } |
| 1436 | |
| 1437 | return P.str(); |
| 1438 | } |
| 1439 | |
Daniel Dunbar | 1e69fe3 | 2009-12-13 03:45:58 +0000 | [diff] [blame] | 1440 | static void ParseHeaderSearchArgs(HeaderSearchOptions &Opts, ArgList &Args) { |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1441 | using namespace cc1options; |
Daniel Dunbar | 03e8ab2 | 2010-05-20 16:54:55 +0000 | [diff] [blame] | 1442 | Opts.Sysroot = Args.getLastArgValue(OPT_isysroot, "/"); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1443 | Opts.Verbose = Args.hasArg(OPT_v); |
Francois Pichet | c91562c | 2011-10-10 20:34:10 +0000 | [diff] [blame] | 1444 | Opts.UseBuiltinIncludes = !Args.hasArg(OPT_nobuiltininc); |
Daniel Dunbar | a268fc0 | 2011-10-11 18:20:10 +0000 | [diff] [blame] | 1445 | Opts.UseStandardSystemIncludes = !Args.hasArg(OPT_nostdsysteminc); |
Douglas Gregor | 4c2bcad | 2010-03-24 20:13:48 +0000 | [diff] [blame] | 1446 | Opts.UseStandardCXXIncludes = !Args.hasArg(OPT_nostdincxx); |
Bob Wilson | 13c4f21 | 2011-06-21 21:12:29 +0000 | [diff] [blame] | 1447 | if (const Arg *A = Args.getLastArg(OPT_stdlib_EQ)) |
| 1448 | Opts.UseLibcxx = (strcmp(A->getValue(Args), "libc++") == 0); |
Daniel Dunbar | 03e8ab2 | 2010-05-20 16:54:55 +0000 | [diff] [blame] | 1449 | Opts.ResourceDir = Args.getLastArgValue(OPT_resource_dir); |
Douglas Gregor | 9a6da69 | 2011-09-12 20:41:59 +0000 | [diff] [blame] | 1450 | Opts.ModuleCachePath = Args.getLastArgValue(OPT_fmodule_cache_path); |
Douglas Gregor | 6e975c4 | 2011-09-13 23:15:45 +0000 | [diff] [blame] | 1451 | Opts.DisableModuleHash = Args.hasArg(OPT_fdisable_module_hash); |
Douglas Gregor | 9a6da69 | 2011-09-12 20:41:59 +0000 | [diff] [blame] | 1452 | |
Douglas Gregor | 65e02fa | 2011-07-28 04:45:53 +0000 | [diff] [blame] | 1453 | // Add -I..., -F..., and -index-header-map options in order. |
| 1454 | bool IsIndexHeaderMap = false; |
| 1455 | for (arg_iterator it = Args.filtered_begin(OPT_I, OPT_F, |
| 1456 | OPT_index_header_map), |
| 1457 | ie = Args.filtered_end(); it != ie; ++it) { |
| 1458 | if ((*it)->getOption().matches(OPT_index_header_map)) { |
| 1459 | // -index-header-map applies to the next -I or -F. |
| 1460 | IsIndexHeaderMap = true; |
| 1461 | continue; |
| 1462 | } |
| 1463 | |
| 1464 | frontend::IncludeDirGroup Group |
| 1465 | = IsIndexHeaderMap? frontend::IndexHeaderMap : frontend::Angled; |
| 1466 | |
| 1467 | Opts.AddPath((*it)->getValue(Args), Group, true, |
Bob Wilson | 5dd45f1 | 2011-06-21 21:53:08 +0000 | [diff] [blame] | 1468 | /*IsFramework=*/ (*it)->getOption().matches(OPT_F), false); |
Douglas Gregor | 65e02fa | 2011-07-28 04:45:53 +0000 | [diff] [blame] | 1469 | IsIndexHeaderMap = false; |
| 1470 | } |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1471 | |
| 1472 | // Add -iprefix/-iwith-prefix/-iwithprefixbefore options. |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1473 | StringRef Prefix = ""; // FIXME: This isn't the correct default prefix. |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1474 | for (arg_iterator it = Args.filtered_begin(OPT_iprefix, OPT_iwithprefix, |
| 1475 | OPT_iwithprefixbefore), |
| 1476 | ie = Args.filtered_end(); it != ie; ++it) { |
Daniel Dunbar | 7e4953e | 2010-06-11 22:00:13 +0000 | [diff] [blame] | 1477 | const Arg *A = *it; |
| 1478 | if (A->getOption().matches(OPT_iprefix)) |
| 1479 | Prefix = A->getValue(Args); |
| 1480 | else if (A->getOption().matches(OPT_iwithprefix)) |
| 1481 | Opts.AddPath(Prefix.str() + A->getValue(Args), |
Bob Wilson | 5dd45f1 | 2011-06-21 21:53:08 +0000 | [diff] [blame] | 1482 | frontend::System, false, false, false); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1483 | else |
Daniel Dunbar | 7e4953e | 2010-06-11 22:00:13 +0000 | [diff] [blame] | 1484 | Opts.AddPath(Prefix.str() + A->getValue(Args), |
Bob Wilson | 5dd45f1 | 2011-06-21 21:53:08 +0000 | [diff] [blame] | 1485 | frontend::Angled, false, false, false); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1486 | } |
| 1487 | |
| 1488 | for (arg_iterator it = Args.filtered_begin(OPT_idirafter), |
| 1489 | ie = Args.filtered_end(); it != ie; ++it) |
Bob Wilson | 5dd45f1 | 2011-06-21 21:53:08 +0000 | [diff] [blame] | 1490 | Opts.AddPath((*it)->getValue(Args), frontend::After, true, false, false); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1491 | for (arg_iterator it = Args.filtered_begin(OPT_iquote), |
| 1492 | ie = Args.filtered_end(); it != ie; ++it) |
Bob Wilson | 5dd45f1 | 2011-06-21 21:53:08 +0000 | [diff] [blame] | 1493 | Opts.AddPath((*it)->getValue(Args), frontend::Quoted, true, false, false); |
Benjamin Kramer | 47adebe | 2011-09-22 21:41:16 +0000 | [diff] [blame] | 1494 | for (arg_iterator it = Args.filtered_begin(OPT_isystem, |
Joerg Sonnenberger | 2df6647 | 2011-02-22 00:40:56 +0000 | [diff] [blame] | 1495 | OPT_iwithsysroot), ie = Args.filtered_end(); it != ie; ++it) |
Benjamin Kramer | 47adebe | 2011-09-22 21:41:16 +0000 | [diff] [blame] | 1496 | Opts.AddPath((*it)->getValue(Args), frontend::System, true, false, |
| 1497 | !(*it)->getOption().matches(OPT_iwithsysroot)); |
Daniel Dunbar | 024f4be | 2011-10-18 20:40:38 +0000 | [diff] [blame] | 1498 | for (arg_iterator it = Args.filtered_begin(OPT_iframework), |
| 1499 | ie = Args.filtered_end(); it != ie; ++it) |
| 1500 | Opts.AddPath((*it)->getValue(Args), frontend::System, true, true, |
| 1501 | true); |
Benjamin Kramer | 47adebe | 2011-09-22 21:41:16 +0000 | [diff] [blame] | 1502 | |
| 1503 | // Add the paths for the various language specific isystem flags. |
| 1504 | for (arg_iterator it = Args.filtered_begin(OPT_c_isystem), |
| 1505 | ie = Args.filtered_end(); it != ie; ++it) |
| 1506 | Opts.AddPath((*it)->getValue(Args), frontend::CSystem, true, false, true); |
| 1507 | for (arg_iterator it = Args.filtered_begin(OPT_cxx_isystem), |
| 1508 | ie = Args.filtered_end(); it != ie; ++it) |
| 1509 | Opts.AddPath((*it)->getValue(Args), frontend::CXXSystem, true, false, true); |
| 1510 | for (arg_iterator it = Args.filtered_begin(OPT_objc_isystem), |
| 1511 | ie = Args.filtered_end(); it != ie; ++it) |
| 1512 | Opts.AddPath((*it)->getValue(Args), frontend::ObjCSystem, true, false,true); |
| 1513 | for (arg_iterator it = Args.filtered_begin(OPT_objcxx_isystem), |
| 1514 | ie = Args.filtered_end(); it != ie; ++it) |
| 1515 | Opts.AddPath((*it)->getValue(Args), frontend::ObjCXXSystem, true, false, |
| 1516 | true); |
Chandler Carruth | ac2bc4d | 2011-11-05 08:30:29 +0000 | [diff] [blame] | 1517 | |
| 1518 | // Add the internal paths from a driver that detects standard include paths. |
| 1519 | for (arg_iterator I = Args.filtered_begin(OPT_internal_isystem, |
Chandler Carruth | 0764308 | 2011-11-07 09:17:31 +0000 | [diff] [blame] | 1520 | OPT_internal_externc_isystem), |
Chandler Carruth | ac2bc4d | 2011-11-05 08:30:29 +0000 | [diff] [blame] | 1521 | E = Args.filtered_end(); |
| 1522 | I != E; ++I) |
| 1523 | Opts.AddPath((*I)->getValue(Args), frontend::System, |
Chandler Carruth | 0764308 | 2011-11-07 09:17:31 +0000 | [diff] [blame] | 1524 | false, false, /*IgnoreSysRoot=*/true, /*IsInternal=*/true, |
Chandler Carruth | ac2bc4d | 2011-11-05 08:30:29 +0000 | [diff] [blame] | 1525 | (*I)->getOption().matches(OPT_internal_externc_isystem)); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1526 | } |
| 1527 | |
Peter Collingbourne | 53c92be | 2010-12-04 01:50:27 +0000 | [diff] [blame] | 1528 | void CompilerInvocation::setLangDefaults(LangOptions &Opts, InputKind IK, |
| 1529 | LangStandard::Kind LangStd) { |
Chris Lattner | fc8f0e1 | 2011-04-15 05:22:18 +0000 | [diff] [blame] | 1530 | // Set some properties which depend solely on the input kind; it would be nice |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1531 | // to move these to the language standard, and have the driver resolve the |
| 1532 | // input kind + language standard. |
Daniel Dunbar | c34ce3f | 2010-06-07 23:22:09 +0000 | [diff] [blame] | 1533 | if (IK == IK_Asm) { |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1534 | Opts.AsmPreprocessor = 1; |
Daniel Dunbar | c34ce3f | 2010-06-07 23:22:09 +0000 | [diff] [blame] | 1535 | } else if (IK == IK_ObjC || |
| 1536 | IK == IK_ObjCXX || |
| 1537 | IK == IK_PreprocessedObjC || |
| 1538 | IK == IK_PreprocessedObjCXX) { |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1539 | Opts.ObjC1 = Opts.ObjC2 = 1; |
| 1540 | } |
| 1541 | |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1542 | if (LangStd == LangStandard::lang_unspecified) { |
| 1543 | // Based on the base language, pick one. |
| 1544 | switch (IK) { |
Daniel Dunbar | c34ce3f | 2010-06-07 23:22:09 +0000 | [diff] [blame] | 1545 | case IK_None: |
| 1546 | case IK_AST: |
Daniel Dunbar | faddc3e | 2010-06-07 23:26:47 +0000 | [diff] [blame] | 1547 | case IK_LLVM_IR: |
David Blaikie | b219cfc | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 1548 | llvm_unreachable("Invalid input kind!"); |
Daniel Dunbar | c34ce3f | 2010-06-07 23:22:09 +0000 | [diff] [blame] | 1549 | case IK_OpenCL: |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1550 | LangStd = LangStandard::lang_opencl; |
| 1551 | break; |
Peter Collingbourne | 895fcca | 2010-12-01 03:15:20 +0000 | [diff] [blame] | 1552 | case IK_CUDA: |
| 1553 | LangStd = LangStandard::lang_cuda; |
| 1554 | break; |
Daniel Dunbar | c34ce3f | 2010-06-07 23:22:09 +0000 | [diff] [blame] | 1555 | case IK_Asm: |
| 1556 | case IK_C: |
| 1557 | case IK_PreprocessedC: |
| 1558 | case IK_ObjC: |
| 1559 | case IK_PreprocessedObjC: |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1560 | LangStd = LangStandard::lang_gnu99; |
| 1561 | break; |
Daniel Dunbar | c34ce3f | 2010-06-07 23:22:09 +0000 | [diff] [blame] | 1562 | case IK_CXX: |
| 1563 | case IK_PreprocessedCXX: |
| 1564 | case IK_ObjCXX: |
| 1565 | case IK_PreprocessedObjCXX: |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1566 | LangStd = LangStandard::lang_gnucxx98; |
| 1567 | break; |
| 1568 | } |
| 1569 | } |
| 1570 | |
| 1571 | const LangStandard &Std = LangStandard::getLangStandardForKind(LangStd); |
| 1572 | Opts.BCPLComment = Std.hasBCPLComments(); |
| 1573 | Opts.C99 = Std.isC99(); |
Peter Collingbourne | 7e7fbd0 | 2011-04-15 00:35:23 +0000 | [diff] [blame] | 1574 | Opts.C1X = Std.isC1X(); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1575 | Opts.CPlusPlus = Std.isCPlusPlus(); |
| 1576 | Opts.CPlusPlus0x = Std.isCPlusPlus0x(); |
| 1577 | Opts.Digraphs = Std.hasDigraphs(); |
| 1578 | Opts.GNUMode = Std.isGNUMode(); |
| 1579 | Opts.GNUInline = !Std.isC99(); |
| 1580 | Opts.HexFloats = Std.hasHexFloats(); |
| 1581 | Opts.ImplicitInt = Std.hasImplicitInt(); |
| 1582 | |
| 1583 | // OpenCL has some additional defaults. |
| 1584 | if (LangStd == LangStandard::lang_opencl) { |
| 1585 | Opts.OpenCL = 1; |
Tobias Grosser | 37c31c2 | 2011-09-21 18:28:29 +0000 | [diff] [blame] | 1586 | Opts.AltiVec = 0; |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1587 | Opts.CXXOperatorNames = 1; |
Tobias Grosser | 37c31c2 | 2011-09-21 18:28:29 +0000 | [diff] [blame] | 1588 | Opts.LaxVectorConversions = 0; |
Peter Collingbourne | f315fa8 | 2011-02-14 01:42:53 +0000 | [diff] [blame] | 1589 | Opts.DefaultFPContract = 1; |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1590 | } |
| 1591 | |
Peter Collingbourne | 895fcca | 2010-12-01 03:15:20 +0000 | [diff] [blame] | 1592 | if (LangStd == LangStandard::lang_cuda) |
| 1593 | Opts.CUDA = 1; |
| 1594 | |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1595 | // OpenCL and C++ both have bool, true, false keywords. |
| 1596 | Opts.Bool = Opts.OpenCL || Opts.CPlusPlus; |
| 1597 | |
Peter Collingbourne | 53c92be | 2010-12-04 01:50:27 +0000 | [diff] [blame] | 1598 | Opts.GNUKeywords = Opts.GNUMode; |
| 1599 | Opts.CXXOperatorNames = Opts.CPlusPlus; |
| 1600 | |
| 1601 | // Mimicing gcc's behavior, trigraphs are only enabled if -trigraphs |
| 1602 | // is specified, or -std is set to a conforming mode. |
| 1603 | Opts.Trigraphs = !Opts.GNUMode; |
| 1604 | |
| 1605 | Opts.DollarIdents = !Opts.AsmPreprocessor; |
| 1606 | } |
| 1607 | |
| 1608 | static void ParseLangArgs(LangOptions &Opts, ArgList &Args, InputKind IK, |
David Blaikie | d6471f7 | 2011-09-25 23:23:43 +0000 | [diff] [blame] | 1609 | DiagnosticsEngine &Diags) { |
Peter Collingbourne | 53c92be | 2010-12-04 01:50:27 +0000 | [diff] [blame] | 1610 | // FIXME: Cleanup per-file based stuff. |
| 1611 | LangStandard::Kind LangStd = LangStandard::lang_unspecified; |
| 1612 | if (const Arg *A = Args.getLastArg(OPT_std_EQ)) { |
| 1613 | LangStd = llvm::StringSwitch<LangStandard::Kind>(A->getValue(Args)) |
| 1614 | #define LANGSTANDARD(id, name, desc, features) \ |
| 1615 | .Case(name, LangStandard::lang_##id) |
| 1616 | #include "clang/Frontend/LangStandards.def" |
| 1617 | .Default(LangStandard::lang_unspecified); |
| 1618 | if (LangStd == LangStandard::lang_unspecified) |
| 1619 | Diags.Report(diag::err_drv_invalid_value) |
| 1620 | << A->getAsString(Args) << A->getValue(Args); |
Chad Rosier | b2dba4b | 2011-05-02 19:24:53 +0000 | [diff] [blame] | 1621 | else { |
| 1622 | // Valid standard, check to make sure language and standard are compatable. |
| 1623 | const LangStandard &Std = LangStandard::getLangStandardForKind(LangStd); |
| 1624 | switch (IK) { |
| 1625 | case IK_C: |
| 1626 | case IK_ObjC: |
| 1627 | case IK_PreprocessedC: |
| 1628 | case IK_PreprocessedObjC: |
| 1629 | if (!(Std.isC89() || Std.isC99())) |
| 1630 | Diags.Report(diag::err_drv_argument_not_allowed_with) |
| 1631 | << A->getAsString(Args) << "C/ObjC"; |
| 1632 | break; |
| 1633 | case IK_CXX: |
| 1634 | case IK_ObjCXX: |
| 1635 | case IK_PreprocessedCXX: |
| 1636 | case IK_PreprocessedObjCXX: |
| 1637 | if (!Std.isCPlusPlus()) |
| 1638 | Diags.Report(diag::err_drv_argument_not_allowed_with) |
| 1639 | << A->getAsString(Args) << "C++/ObjC++"; |
| 1640 | break; |
| 1641 | case IK_OpenCL: |
| 1642 | if (!Std.isC99()) |
| 1643 | Diags.Report(diag::err_drv_argument_not_allowed_with) |
| 1644 | << A->getAsString(Args) << "OpenCL"; |
| 1645 | break; |
| 1646 | case IK_CUDA: |
| 1647 | if (!Std.isCPlusPlus()) |
| 1648 | Diags.Report(diag::err_drv_argument_not_allowed_with) |
| 1649 | << A->getAsString(Args) << "CUDA"; |
| 1650 | break; |
| 1651 | default: |
| 1652 | break; |
| 1653 | } |
| 1654 | } |
Peter Collingbourne | 53c92be | 2010-12-04 01:50:27 +0000 | [diff] [blame] | 1655 | } |
| 1656 | |
Peter Collingbourne | 91252d1 | 2010-12-04 01:51:40 +0000 | [diff] [blame] | 1657 | if (const Arg *A = Args.getLastArg(OPT_cl_std_EQ)) { |
| 1658 | if (strcmp(A->getValue(Args), "CL1.1") != 0) { |
| 1659 | Diags.Report(diag::err_drv_invalid_value) |
| 1660 | << A->getAsString(Args) << A->getValue(Args); |
| 1661 | } |
| 1662 | } |
| 1663 | |
Peter Collingbourne | 53c92be | 2010-12-04 01:50:27 +0000 | [diff] [blame] | 1664 | CompilerInvocation::setLangDefaults(Opts, IK, LangStd); |
| 1665 | |
Chandler Carruth | eb5d7b7 | 2010-04-17 20:17:31 +0000 | [diff] [blame] | 1666 | // We abuse '-f[no-]gnu-keywords' to force overriding all GNU-extension |
| 1667 | // keywords. This behavior is provided by GCC's poorly named '-fasm' flag, |
| 1668 | // while a subset (the non-C++ GNU keywords) is provided by GCC's |
| 1669 | // '-fgnu-keywords'. Clang conflates the two for simplicity under the single |
| 1670 | // name, as it doesn't seem a useful distinction. |
| 1671 | Opts.GNUKeywords = Args.hasFlag(OPT_fgnu_keywords, OPT_fno_gnu_keywords, |
Peter Collingbourne | 53c92be | 2010-12-04 01:50:27 +0000 | [diff] [blame] | 1672 | Opts.GNUKeywords); |
Chandler Carruth | eb5d7b7 | 2010-04-17 20:17:31 +0000 | [diff] [blame] | 1673 | |
Peter Collingbourne | 53c92be | 2010-12-04 01:50:27 +0000 | [diff] [blame] | 1674 | if (Args.hasArg(OPT_fno_operator_names)) |
| 1675 | Opts.CXXOperatorNames = 0; |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1676 | |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 1677 | if (Opts.ObjC1) { |
| 1678 | if (Args.hasArg(OPT_fobjc_gc_only)) |
Douglas Gregor | e289d81 | 2011-09-13 17:21:33 +0000 | [diff] [blame] | 1679 | Opts.setGC(LangOptions::GCOnly); |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 1680 | else if (Args.hasArg(OPT_fobjc_gc)) |
Douglas Gregor | e289d81 | 2011-09-13 17:21:33 +0000 | [diff] [blame] | 1681 | Opts.setGC(LangOptions::HybridGC); |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 1682 | else if (Args.hasArg(OPT_fobjc_arc)) { |
| 1683 | Opts.ObjCAutoRefCount = 1; |
John McCall | d1e40d5 | 2011-10-02 01:16:38 +0000 | [diff] [blame] | 1684 | if (Args.hasArg(OPT_fobjc_fragile_abi)) |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 1685 | Diags.Report(diag::err_arc_nonfragile_abi); |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 1686 | } |
| 1687 | |
John McCall | 9f084a3 | 2011-07-06 00:26:06 +0000 | [diff] [blame] | 1688 | if (Args.hasArg(OPT_fobjc_runtime_has_weak)) |
| 1689 | Opts.ObjCRuntimeHasWeak = 1; |
| 1690 | |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 1691 | if (Args.hasArg(OPT_fno_objc_infer_related_result_type)) |
| 1692 | Opts.ObjCInferRelatedResultType = 0; |
| 1693 | } |
| 1694 | |
Rafael Espindola | fb3f4aa | 2011-06-02 16:13:27 +0000 | [diff] [blame] | 1695 | if (Args.hasArg(OPT_fgnu89_inline)) |
| 1696 | Opts.GNUInline = 1; |
| 1697 | |
Fariborz Jahanian | 142f9e9 | 2011-02-04 00:01:24 +0000 | [diff] [blame] | 1698 | if (Args.hasArg(OPT_fapple_kext)) { |
| 1699 | if (!Opts.CPlusPlus) |
| 1700 | Diags.Report(diag::warn_c_kext); |
| 1701 | else |
| 1702 | Opts.AppleKext = 1; |
| 1703 | } |
| 1704 | |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1705 | if (Args.hasArg(OPT_print_ivar_layout)) |
| 1706 | Opts.ObjCGCBitmapPrint = 1; |
Fariborz Jahanian | 33e982b | 2010-04-22 20:26:39 +0000 | [diff] [blame] | 1707 | if (Args.hasArg(OPT_fno_constant_cfstrings)) |
| 1708 | Opts.NoConstantCFStrings = 1; |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1709 | |
| 1710 | if (Args.hasArg(OPT_faltivec)) |
| 1711 | Opts.AltiVec = 1; |
| 1712 | |
| 1713 | if (Args.hasArg(OPT_pthread)) |
| 1714 | Opts.POSIXThreads = 1; |
| 1715 | |
Francois Pichet | 8387e2a | 2011-04-22 22:18:13 +0000 | [diff] [blame] | 1716 | if (Args.hasArg(OPT_fdelayed_template_parsing)) |
| 1717 | Opts.DelayedTemplateParsing = 1; |
| 1718 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1719 | StringRef Vis = Args.getLastArgValue(OPT_fvisibility, "default"); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1720 | if (Vis == "default") |
John McCall | 1fb0caa | 2010-10-22 21:05:15 +0000 | [diff] [blame] | 1721 | Opts.setVisibilityMode(DefaultVisibility); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1722 | else if (Vis == "hidden") |
John McCall | 1fb0caa | 2010-10-22 21:05:15 +0000 | [diff] [blame] | 1723 | Opts.setVisibilityMode(HiddenVisibility); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1724 | else if (Vis == "protected") |
John McCall | 1fb0caa | 2010-10-22 21:05:15 +0000 | [diff] [blame] | 1725 | Opts.setVisibilityMode(ProtectedVisibility); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1726 | else |
| 1727 | Diags.Report(diag::err_drv_invalid_value) |
| 1728 | << Args.getLastArg(OPT_fvisibility)->getAsString(Args) << Vis; |
| 1729 | |
Douglas Gregor | 7cf84d6 | 2010-06-15 17:05:35 +0000 | [diff] [blame] | 1730 | if (Args.hasArg(OPT_fvisibility_inlines_hidden)) |
| 1731 | Opts.InlineVisibilityHidden = 1; |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1732 | |
David Chisnall | 7f18e67 | 2010-09-17 18:29:54 +0000 | [diff] [blame] | 1733 | if (Args.hasArg(OPT_ftrapv)) { |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1734 | Opts.setSignedOverflowBehavior(LangOptions::SOB_Trapping); |
David Chisnall | 7f18e67 | 2010-09-17 18:29:54 +0000 | [diff] [blame] | 1735 | // Set the handler, if one is specified. |
| 1736 | Opts.OverflowHandler = |
| 1737 | Args.getLastArgValue(OPT_ftrapv_handler); |
| 1738 | } |
Chris Lattner | a4d7145 | 2010-06-26 21:25:03 +0000 | [diff] [blame] | 1739 | else if (Args.hasArg(OPT_fwrapv)) |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1740 | Opts.setSignedOverflowBehavior(LangOptions::SOB_Defined); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1741 | |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1742 | if (Args.hasArg(OPT_trigraphs)) |
| 1743 | Opts.Trigraphs = 1; |
| 1744 | |
Daniel Dunbar | 8663b18 | 2009-12-16 20:10:18 +0000 | [diff] [blame] | 1745 | Opts.DollarIdents = Args.hasFlag(OPT_fdollars_in_identifiers, |
| 1746 | OPT_fno_dollars_in_identifiers, |
Peter Collingbourne | 53c92be | 2010-12-04 01:50:27 +0000 | [diff] [blame] | 1747 | Opts.DollarIdents); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1748 | Opts.PascalStrings = Args.hasArg(OPT_fpascal_strings); |
Douglas Gregor | 0bb935c | 2011-10-24 15:27:23 +0000 | [diff] [blame] | 1749 | Opts.MicrosoftExt |
| 1750 | = Args.hasArg(OPT_fms_extensions) || Args.hasArg(OPT_fms_compatibility); |
Francois Pichet | ae55608 | 2011-09-17 04:32:15 +0000 | [diff] [blame] | 1751 | Opts.MicrosoftMode = Args.hasArg(OPT_fms_compatibility); |
Michael J. Spencer | dae4ac4 | 2010-10-21 05:21:48 +0000 | [diff] [blame] | 1752 | Opts.MSCVersion = Args.getLastArgIntValue(OPT_fmsc_version, 0, Diags); |
Dawn Perchik | 400b607 | 2010-09-02 23:59:25 +0000 | [diff] [blame] | 1753 | Opts.Borland = Args.hasArg(OPT_fborland_extensions); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1754 | Opts.WritableStrings = Args.hasArg(OPT_fwritable_strings); |
Chandler Carruth | 50465d1 | 2011-04-23 06:30:43 +0000 | [diff] [blame] | 1755 | Opts.ConstStrings = Args.hasFlag(OPT_fconst_strings, OPT_fno_const_strings, |
| 1756 | Opts.ConstStrings); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1757 | if (Args.hasArg(OPT_fno_lax_vector_conversions)) |
Anders Carlsson | a508b7d | 2010-02-06 23:23:06 +0000 | [diff] [blame] | 1758 | Opts.LaxVectorConversions = 0; |
| 1759 | if (Args.hasArg(OPT_fno_threadsafe_statics)) |
Anders Carlsson | 824d7ea | 2010-02-11 08:02:13 +0000 | [diff] [blame] | 1760 | Opts.ThreadsafeStatics = 0; |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1761 | Opts.Exceptions = Args.hasArg(OPT_fexceptions); |
Anders Carlsson | e9b801f | 2011-02-22 01:52:06 +0000 | [diff] [blame] | 1762 | Opts.ObjCExceptions = Args.hasArg(OPT_fobjc_exceptions); |
Anders Carlsson | 0761e44 | 2011-02-23 03:16:42 +0000 | [diff] [blame] | 1763 | Opts.CXXExceptions = Args.hasArg(OPT_fcxx_exceptions); |
| 1764 | Opts.SjLjExceptions = Args.hasArg(OPT_fsjlj_exceptions); |
Daniel Dunbar | 2ed4228 | 2011-03-18 21:23:38 +0000 | [diff] [blame] | 1765 | Opts.TraditionalCPP = Args.hasArg(OPT_traditional_cpp); |
Anders Carlsson | 0761e44 | 2011-02-23 03:16:42 +0000 | [diff] [blame] | 1766 | |
Mike Stump | de05057 | 2009-12-02 18:57:08 +0000 | [diff] [blame] | 1767 | Opts.RTTI = !Args.hasArg(OPT_fno_rtti); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1768 | Opts.Blocks = Args.hasArg(OPT_fblocks); |
John McCall | 13db5cf | 2011-09-09 20:41:01 +0000 | [diff] [blame] | 1769 | Opts.BlocksRuntimeOptional = Args.hasArg(OPT_fblocks_runtime_optional); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1770 | Opts.CharIsSigned = !Args.hasArg(OPT_fno_signed_char); |
| 1771 | Opts.ShortWChar = Args.hasArg(OPT_fshort_wchar); |
Argyrios Kyrtzidis | 9a2b9d7 | 2010-10-08 00:25:19 +0000 | [diff] [blame] | 1772 | Opts.ShortEnums = Args.hasArg(OPT_fshort_enums); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1773 | Opts.Freestanding = Args.hasArg(OPT_ffreestanding); |
| 1774 | Opts.NoBuiltin = Args.hasArg(OPT_fno_builtin) || Opts.Freestanding; |
Nuno Lopes | fc28448 | 2009-12-16 16:59:22 +0000 | [diff] [blame] | 1775 | Opts.AssumeSaneOperatorNew = !Args.hasArg(OPT_fno_assume_sane_operator_new); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1776 | Opts.HeinousExtensions = Args.hasArg(OPT_fheinous_gnu_extensions); |
John McCall | 7002f4c | 2010-04-09 19:03:51 +0000 | [diff] [blame] | 1777 | Opts.AccessControl = !Args.hasArg(OPT_fno_access_control); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1778 | Opts.ElideConstructors = !Args.hasArg(OPT_fno_elide_constructors); |
Dan Gohman | c31176d | 2010-01-08 02:20:44 +0000 | [diff] [blame] | 1779 | Opts.MathErrno = Args.hasArg(OPT_fmath_errno); |
Daniel Dunbar | 03e8ab2 | 2010-05-20 16:54:55 +0000 | [diff] [blame] | 1780 | Opts.InstantiationDepth = Args.getLastArgIntValue(OPT_ftemplate_depth, 1024, |
Richard Smith | c18c423 | 2011-11-21 19:36:32 +0000 | [diff] [blame] | 1781 | Diags); |
| 1782 | Opts.ConstexprCallDepth = Args.getLastArgIntValue(OPT_fconstexpr_depth, 512, |
| 1783 | Diags); |
Francois Pichet | 8387e2a | 2011-04-22 22:18:13 +0000 | [diff] [blame] | 1784 | Opts.DelayedTemplateParsing = Args.hasArg(OPT_fdelayed_template_parsing); |
Argyrios Kyrtzidis | 1380a14 | 2010-11-18 00:20:36 +0000 | [diff] [blame] | 1785 | Opts.NumLargeByValueCopy = Args.getLastArgIntValue(OPT_Wlarge_by_value_copy, |
Argyrios Kyrtzidis | 3532fdd | 2010-11-17 23:11:54 +0000 | [diff] [blame] | 1786 | 0, Diags); |
Douglas Gregor | 6f75550 | 2011-02-01 15:15:22 +0000 | [diff] [blame] | 1787 | Opts.MSBitfields = Args.hasArg(OPT_mms_bitfields); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1788 | Opts.NeXTRuntime = !Args.hasArg(OPT_fgnu_runtime); |
Daniel Dunbar | 03e8ab2 | 2010-05-20 16:54:55 +0000 | [diff] [blame] | 1789 | Opts.ObjCConstantStringClass = |
| 1790 | Args.getLastArgValue(OPT_fconstant_string_class); |
John McCall | d1e40d5 | 2011-10-02 01:16:38 +0000 | [diff] [blame] | 1791 | Opts.ObjCNonFragileABI = !Args.hasArg(OPT_fobjc_fragile_abi); |
Fariborz Jahanian | 112c330 | 2011-01-04 20:05:20 +0000 | [diff] [blame] | 1792 | if (Opts.ObjCNonFragileABI) |
| 1793 | Opts.ObjCNonFragileABI2 = true; |
Ted Kremenek | c32647d | 2010-12-23 21:35:43 +0000 | [diff] [blame] | 1794 | Opts.ObjCDefaultSynthProperties = |
| 1795 | Args.hasArg(OPT_fobjc_default_synthesize_properties); |
Mike Stump | 9c276ae | 2009-12-12 01:27:46 +0000 | [diff] [blame] | 1796 | Opts.CatchUndefined = Args.hasArg(OPT_fcatch_undefined_behavior); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1797 | Opts.EmitAllDecls = Args.hasArg(OPT_femit_all_decls); |
Daniel Dunbar | 88934e8 | 2011-10-05 21:04:55 +0000 | [diff] [blame] | 1798 | Opts.PackStruct = Args.getLastArgIntValue(OPT_fpack_struct, 0, Diags); |
Daniel Dunbar | 03e8ab2 | 2010-05-20 16:54:55 +0000 | [diff] [blame] | 1799 | Opts.PICLevel = Args.getLastArgIntValue(OPT_pic_level, 0, Diags); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1800 | Opts.Static = Args.hasArg(OPT_static_define); |
Anders Carlsson | 46116ce | 2010-04-10 19:09:13 +0000 | [diff] [blame] | 1801 | Opts.DumpRecordLayouts = Args.hasArg(OPT_fdump_record_layouts); |
Anders Carlsson | 046c294 | 2010-04-17 20:15:18 +0000 | [diff] [blame] | 1802 | Opts.DumpVTableLayouts = Args.hasArg(OPT_fdump_vtable_layouts); |
Douglas Gregor | a0068fc | 2010-07-09 17:35:33 +0000 | [diff] [blame] | 1803 | Opts.SpellChecking = !Args.hasArg(OPT_fno_spell_checking); |
Daniel Dunbar | fb937b8 | 2010-04-15 15:06:22 +0000 | [diff] [blame] | 1804 | Opts.NoBitFieldTypeAlign = Args.hasArg(OPT_fno_bitfield_type_align); |
Peter Collingbourne | 0982136 | 2010-12-04 01:50:56 +0000 | [diff] [blame] | 1805 | Opts.SinglePrecisionConstants = Args.hasArg(OPT_cl_single_precision_constant); |
Peter Collingbourne | f084082 | 2010-12-04 01:51:23 +0000 | [diff] [blame] | 1806 | Opts.FastRelaxedMath = Args.hasArg(OPT_cl_fast_relaxed_math); |
Roman Divacky | cfe9af2 | 2011-03-01 17:40:53 +0000 | [diff] [blame] | 1807 | Opts.MRTD = Args.hasArg(OPT_mrtd); |
Peter Collingbourne | 207f4d8 | 2011-03-18 22:38:29 +0000 | [diff] [blame] | 1808 | Opts.FakeAddressSpaceMap = Args.hasArg(OPT_ffake_address_space_map); |
John McCall | a5fc472 | 2011-04-09 22:50:59 +0000 | [diff] [blame] | 1809 | Opts.ParseUnknownAnytype = Args.hasArg(OPT_funknown_anytype); |
John McCall | 48218c6 | 2011-07-13 17:56:40 +0000 | [diff] [blame] | 1810 | Opts.DebuggerSupport = Args.hasArg(OPT_fdebugger_support); |
Kostya Serebryany | b619688 | 2011-11-22 01:28:36 +0000 | [diff] [blame] | 1811 | Opts.AddressSanitizer = Args.hasArg(OPT_faddress_sanitizer); |
Eli Friedman | 19bda3a | 2011-11-02 01:53:16 +0000 | [diff] [blame] | 1812 | Opts.ApplePragmaPack = Args.hasArg(OPT_fapple_pragma_pack); |
Douglas Gregor | b86b8dc | 2011-11-15 19:35:01 +0000 | [diff] [blame] | 1813 | Opts.CurrentModule = Args.getLastArgValue(OPT_fmodule_name); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1814 | |
Chandler Carruth | 1cfe3c3 | 2011-04-23 09:27:53 +0000 | [diff] [blame] | 1815 | // Record whether the __DEPRECATED define was requested. |
| 1816 | Opts.Deprecated = Args.hasFlag(OPT_fdeprecated_macro, |
| 1817 | OPT_fno_deprecated_macro, |
| 1818 | Opts.Deprecated); |
| 1819 | |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1820 | // FIXME: Eliminate this dependency. |
Peter Collingbourne | 0a3c03c | 2010-12-04 01:50:36 +0000 | [diff] [blame] | 1821 | unsigned Opt = getOptimizationLevel(Args, IK, Diags); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1822 | Opts.Optimize = Opt != 0; |
Rafael Espindola | 4c7ce36 | 2011-11-26 06:21:20 +0000 | [diff] [blame] | 1823 | Opts.OptimizeSize = Args.hasArg(OPT_Os) || Args.hasArg(OPT_Oz); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1824 | |
| 1825 | // This is the __NO_INLINE__ define, which just depends on things like the |
| 1826 | // optimization level and -fno-inline, not actually whether the backend has |
| 1827 | // inlining enabled. |
| 1828 | // |
| 1829 | // FIXME: This is affected by other options (-fno-inline). |
| 1830 | Opts.NoInline = !Opt; |
| 1831 | |
Daniel Dunbar | 03e8ab2 | 2010-05-20 16:54:55 +0000 | [diff] [blame] | 1832 | unsigned SSP = Args.getLastArgIntValue(OPT_stack_protector, 0, Diags); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1833 | switch (SSP) { |
| 1834 | default: |
| 1835 | Diags.Report(diag::err_drv_invalid_value) |
| 1836 | << Args.getLastArg(OPT_stack_protector)->getAsString(Args) << SSP; |
| 1837 | break; |
Douglas Gregor | e289d81 | 2011-09-13 17:21:33 +0000 | [diff] [blame] | 1838 | case 0: Opts.setStackProtector(LangOptions::SSPOff); break; |
| 1839 | case 1: Opts.setStackProtector(LangOptions::SSPOn); break; |
| 1840 | case 2: Opts.setStackProtector(LangOptions::SSPReq); break; |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1841 | } |
| 1842 | } |
| 1843 | |
Daniel Dunbar | e14b5f5 | 2009-12-03 05:11:16 +0000 | [diff] [blame] | 1844 | static void ParsePreprocessorArgs(PreprocessorOptions &Opts, ArgList &Args, |
Argyrios Kyrtzidis | 389db16 | 2010-11-03 22:45:23 +0000 | [diff] [blame] | 1845 | FileManager &FileMgr, |
David Blaikie | d6471f7 | 2011-09-25 23:23:43 +0000 | [diff] [blame] | 1846 | DiagnosticsEngine &Diags) { |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1847 | using namespace cc1options; |
Daniel Dunbar | 03e8ab2 | 2010-05-20 16:54:55 +0000 | [diff] [blame] | 1848 | Opts.ImplicitPCHInclude = Args.getLastArgValue(OPT_include_pch); |
| 1849 | Opts.ImplicitPTHInclude = Args.getLastArgValue(OPT_include_pth); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1850 | if (const Arg *A = Args.getLastArg(OPT_token_cache)) |
| 1851 | Opts.TokenCache = A->getValue(Args); |
| 1852 | else |
| 1853 | Opts.TokenCache = Opts.ImplicitPTHInclude; |
| 1854 | Opts.UsePredefines = !Args.hasArg(OPT_undef); |
Douglas Gregor | 94dc8f6 | 2010-03-19 16:15:56 +0000 | [diff] [blame] | 1855 | Opts.DetailedRecord = Args.hasArg(OPT_detailed_preprocessing_record); |
Douglas Gregor | fba18aa | 2011-09-15 22:00:41 +0000 | [diff] [blame] | 1856 | Opts.AutoModuleImport = Args.hasArg(OPT_fauto_module_import); |
Douglas Gregor | fae3b2f | 2010-07-27 00:27:13 +0000 | [diff] [blame] | 1857 | Opts.DisablePCHValidation = Args.hasArg(OPT_fno_validate_pch); |
Argyrios Kyrtzidis | 3e78593 | 2010-10-14 20:14:25 +0000 | [diff] [blame] | 1858 | |
Argyrios Kyrtzidis | b972858 | 2010-10-14 20:14:18 +0000 | [diff] [blame] | 1859 | Opts.DumpDeserializedPCHDecls = Args.hasArg(OPT_dump_deserialized_pch_decls); |
Argyrios Kyrtzidis | 3e78593 | 2010-10-14 20:14:25 +0000 | [diff] [blame] | 1860 | for (arg_iterator it = Args.filtered_begin(OPT_error_on_deserialized_pch_decl), |
| 1861 | ie = Args.filtered_end(); it != ie; ++it) { |
| 1862 | const Arg *A = *it; |
| 1863 | Opts.DeserializedPCHDeclsToErrorOn.insert(A->getValue(Args)); |
| 1864 | } |
Douglas Gregor | fae3b2f | 2010-07-27 00:27:13 +0000 | [diff] [blame] | 1865 | |
Douglas Gregor | f4f6c9d | 2010-07-26 21:36:20 +0000 | [diff] [blame] | 1866 | if (const Arg *A = Args.getLastArg(OPT_preamble_bytes_EQ)) { |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1867 | StringRef Value(A->getValue(Args)); |
Douglas Gregor | f4f6c9d | 2010-07-26 21:36:20 +0000 | [diff] [blame] | 1868 | size_t Comma = Value.find(','); |
| 1869 | unsigned Bytes = 0; |
| 1870 | unsigned EndOfLine = 0; |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1871 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1872 | if (Comma == StringRef::npos || |
Douglas Gregor | f4f6c9d | 2010-07-26 21:36:20 +0000 | [diff] [blame] | 1873 | Value.substr(0, Comma).getAsInteger(10, Bytes) || |
| 1874 | Value.substr(Comma + 1).getAsInteger(10, EndOfLine)) |
| 1875 | Diags.Report(diag::err_drv_preamble_format); |
| 1876 | else { |
| 1877 | Opts.PrecompiledPreambleBytes.first = Bytes; |
| 1878 | Opts.PrecompiledPreambleBytes.second = (EndOfLine != 0); |
| 1879 | } |
| 1880 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1881 | |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1882 | // Add macros from the command line. |
| 1883 | for (arg_iterator it = Args.filtered_begin(OPT_D, OPT_U), |
| 1884 | ie = Args.filtered_end(); it != ie; ++it) { |
Daniel Dunbar | 7e4953e | 2010-06-11 22:00:13 +0000 | [diff] [blame] | 1885 | if ((*it)->getOption().matches(OPT_D)) |
| 1886 | Opts.addMacroDef((*it)->getValue(Args)); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1887 | else |
Daniel Dunbar | 7e4953e | 2010-06-11 22:00:13 +0000 | [diff] [blame] | 1888 | Opts.addMacroUndef((*it)->getValue(Args)); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1889 | } |
| 1890 | |
Daniel Dunbar | 03e8ab2 | 2010-05-20 16:54:55 +0000 | [diff] [blame] | 1891 | Opts.MacroIncludes = Args.getAllArgValues(OPT_imacros); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1892 | |
| 1893 | // Add the ordered list of -includes. |
| 1894 | for (arg_iterator it = Args.filtered_begin(OPT_include, OPT_include_pch, |
| 1895 | OPT_include_pth), |
| 1896 | ie = Args.filtered_end(); it != ie; ++it) { |
Daniel Dunbar | 7e4953e | 2010-06-11 22:00:13 +0000 | [diff] [blame] | 1897 | const Arg *A = *it; |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1898 | // PCH is handled specially, we need to extra the original include path. |
Daniel Dunbar | 7e4953e | 2010-06-11 22:00:13 +0000 | [diff] [blame] | 1899 | if (A->getOption().matches(OPT_include_pch)) { |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1900 | std::string OriginalFile = |
Chris Lattner | 39b49bc | 2010-11-23 08:35:12 +0000 | [diff] [blame] | 1901 | ASTReader::getOriginalSourceFile(A->getValue(Args), FileMgr, Diags); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1902 | if (OriginalFile.empty()) |
Daniel Dunbar | 93ebb1b | 2009-12-03 09:13:06 +0000 | [diff] [blame] | 1903 | continue; |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1904 | |
| 1905 | Opts.Includes.push_back(OriginalFile); |
| 1906 | } else |
Daniel Dunbar | 7e4953e | 2010-06-11 22:00:13 +0000 | [diff] [blame] | 1907 | Opts.Includes.push_back(A->getValue(Args)); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1908 | } |
Daniel Dunbar | e14b5f5 | 2009-12-03 05:11:16 +0000 | [diff] [blame] | 1909 | |
Argyrios Kyrtzidis | b0f4b9a | 2011-03-09 17:21:42 +0000 | [diff] [blame] | 1910 | for (arg_iterator it = Args.filtered_begin(OPT_chain_include), |
| 1911 | ie = Args.filtered_end(); it != ie; ++it) { |
| 1912 | const Arg *A = *it; |
| 1913 | Opts.ChainedIncludes.push_back(A->getValue(Args)); |
| 1914 | } |
| 1915 | |
Chris Lattner | dd17394 | 2010-04-14 03:54:58 +0000 | [diff] [blame] | 1916 | // Include 'altivec.h' if -faltivec option present |
| 1917 | if (Args.hasArg(OPT_faltivec)) |
| 1918 | Opts.Includes.push_back("altivec.h"); |
| 1919 | |
Daniel Dunbar | e14b5f5 | 2009-12-03 05:11:16 +0000 | [diff] [blame] | 1920 | for (arg_iterator it = Args.filtered_begin(OPT_remap_file), |
| 1921 | ie = Args.filtered_end(); it != ie; ++it) { |
Daniel Dunbar | 7e4953e | 2010-06-11 22:00:13 +0000 | [diff] [blame] | 1922 | const Arg *A = *it; |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1923 | std::pair<StringRef,StringRef> Split = |
| 1924 | StringRef(A->getValue(Args)).split(';'); |
Daniel Dunbar | e14b5f5 | 2009-12-03 05:11:16 +0000 | [diff] [blame] | 1925 | |
| 1926 | if (Split.second.empty()) { |
Daniel Dunbar | 7e4953e | 2010-06-11 22:00:13 +0000 | [diff] [blame] | 1927 | Diags.Report(diag::err_drv_invalid_remap_file) << A->getAsString(Args); |
Daniel Dunbar | e14b5f5 | 2009-12-03 05:11:16 +0000 | [diff] [blame] | 1928 | continue; |
| 1929 | } |
| 1930 | |
| 1931 | Opts.addRemappedFile(Split.first, Split.second); |
| 1932 | } |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 1933 | |
| 1934 | if (Arg *A = Args.getLastArg(OPT_fobjc_arc_cxxlib_EQ)) { |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1935 | StringRef Name = A->getValue(Args); |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 1936 | unsigned Library = llvm::StringSwitch<unsigned>(Name) |
| 1937 | .Case("libc++", ARCXX_libcxx) |
| 1938 | .Case("libstdc++", ARCXX_libstdcxx) |
| 1939 | .Case("none", ARCXX_nolib) |
| 1940 | .Default(~0U); |
| 1941 | if (Library == ~0U) |
| 1942 | Diags.Report(diag::err_drv_invalid_value) << A->getAsString(Args) << Name; |
| 1943 | else |
| 1944 | Opts.ObjCXXARCStandardLibrary = (ObjCXXARCStandardLibraryKind)Library; |
| 1945 | } |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1946 | } |
| 1947 | |
| 1948 | static void ParsePreprocessorOutputArgs(PreprocessorOutputOptions &Opts, |
| 1949 | ArgList &Args) { |
| 1950 | using namespace cc1options; |
| 1951 | Opts.ShowCPP = !Args.hasArg(OPT_dM); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1952 | Opts.ShowComments = Args.hasArg(OPT_C); |
Daniel Dunbar | f7c16d9 | 2010-08-24 22:44:13 +0000 | [diff] [blame] | 1953 | Opts.ShowLineMarkers = !Args.hasArg(OPT_P); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1954 | Opts.ShowMacroComments = Args.hasArg(OPT_CC); |
Daniel Dunbar | f7c16d9 | 2010-08-24 22:44:13 +0000 | [diff] [blame] | 1955 | Opts.ShowMacros = Args.hasArg(OPT_dM) || Args.hasArg(OPT_dD); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1956 | } |
| 1957 | |
| 1958 | static void ParseTargetArgs(TargetOptions &Opts, ArgList &Args) { |
| 1959 | using namespace cc1options; |
Daniel Dunbar | 03e8ab2 | 2010-05-20 16:54:55 +0000 | [diff] [blame] | 1960 | Opts.ABI = Args.getLastArgValue(OPT_target_abi); |
Charles Davis | 98b7c5c | 2010-06-11 01:06:47 +0000 | [diff] [blame] | 1961 | Opts.CXXABI = Args.getLastArgValue(OPT_cxx_abi); |
Daniel Dunbar | 03e8ab2 | 2010-05-20 16:54:55 +0000 | [diff] [blame] | 1962 | Opts.CPU = Args.getLastArgValue(OPT_target_cpu); |
Daniel Dunbar | 03e8ab2 | 2010-05-20 16:54:55 +0000 | [diff] [blame] | 1963 | Opts.Features = Args.getAllArgValues(OPT_target_feature); |
Daniel Dunbar | 39065a5 | 2010-08-11 23:07:42 +0000 | [diff] [blame] | 1964 | Opts.LinkerVersion = Args.getLastArgValue(OPT_target_linker_version); |
Duncan Sands | 2dc1453 | 2010-08-30 09:42:39 +0000 | [diff] [blame] | 1965 | Opts.Triple = llvm::Triple::normalize(Args.getLastArgValue(OPT_triple)); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1966 | |
Sebastian Pop | 5d8b954 | 2011-11-01 21:33:06 +0000 | [diff] [blame] | 1967 | // Use the default target triple if unspecified. |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1968 | if (Opts.Triple.empty()) |
Sebastian Pop | 5d8b954 | 2011-11-01 21:33:06 +0000 | [diff] [blame] | 1969 | Opts.Triple = llvm::sys::getDefaultTargetTriple(); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1970 | } |
| 1971 | |
| 1972 | // |
| 1973 | |
| 1974 | void CompilerInvocation::CreateFromArgs(CompilerInvocation &Res, |
Chris Lattner | 39b49bc | 2010-11-23 08:35:12 +0000 | [diff] [blame] | 1975 | const char *const *ArgBegin, |
| 1976 | const char *const *ArgEnd, |
David Blaikie | d6471f7 | 2011-09-25 23:23:43 +0000 | [diff] [blame] | 1977 | DiagnosticsEngine &Diags) { |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1978 | // Parse the arguments. |
| 1979 | llvm::OwningPtr<OptTable> Opts(createCC1OptTable()); |
| 1980 | unsigned MissingArgIndex, MissingArgCount; |
| 1981 | llvm::OwningPtr<InputArgList> Args( |
| 1982 | Opts->ParseArgs(ArgBegin, ArgEnd,MissingArgIndex, MissingArgCount)); |
| 1983 | |
| 1984 | // Check for missing argument error. |
| 1985 | if (MissingArgCount) |
| 1986 | Diags.Report(diag::err_drv_missing_argument) |
| 1987 | << Args->getArgString(MissingArgIndex) << MissingArgCount; |
| 1988 | |
| 1989 | // Issue errors on unknown arguments. |
| 1990 | for (arg_iterator it = Args->filtered_begin(OPT_UNKNOWN), |
| 1991 | ie = Args->filtered_end(); it != ie; ++it) |
Daniel Dunbar | 7e4953e | 2010-06-11 22:00:13 +0000 | [diff] [blame] | 1992 | Diags.Report(diag::err_drv_unknown_argument) << (*it)->getAsString(*Args); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1993 | |
| 1994 | ParseAnalyzerArgs(Res.getAnalyzerOpts(), *Args, Diags); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 1995 | ParseDependencyOutputArgs(Res.getDependencyOutputOpts(), *Args); |
| 1996 | ParseDiagnosticArgs(Res.getDiagnosticOpts(), *Args, Diags); |
Argyrios Kyrtzidis | 389db16 | 2010-11-03 22:45:23 +0000 | [diff] [blame] | 1997 | ParseFileSystemArgs(Res.getFileSystemOpts(), *Args); |
Peter Collingbourne | 0a3c03c | 2010-12-04 01:50:36 +0000 | [diff] [blame] | 1998 | // FIXME: We shouldn't have to pass the DashX option around here |
Daniel Dunbar | c34ce3f | 2010-06-07 23:22:09 +0000 | [diff] [blame] | 1999 | InputKind DashX = ParseFrontendArgs(Res.getFrontendOpts(), *Args, Diags); |
Peter Collingbourne | 0a3c03c | 2010-12-04 01:50:36 +0000 | [diff] [blame] | 2000 | ParseCodeGenArgs(Res.getCodeGenOpts(), *Args, DashX, Diags); |
Daniel Dunbar | 1e69fe3 | 2009-12-13 03:45:58 +0000 | [diff] [blame] | 2001 | ParseHeaderSearchArgs(Res.getHeaderSearchOpts(), *Args); |
Fariborz Jahanian | e293d30 | 2011-02-25 17:24:55 +0000 | [diff] [blame] | 2002 | if (DashX != IK_AST && DashX != IK_LLVM_IR) { |
Ted Kremenek | d3b74d9 | 2011-11-17 23:01:24 +0000 | [diff] [blame] | 2003 | ParseLangArgs(*Res.getLangOpts(), *Args, DashX, Diags); |
Fariborz Jahanian | e293d30 | 2011-02-25 17:24:55 +0000 | [diff] [blame] | 2004 | if (Res.getFrontendOpts().ProgramAction == frontend::RewriteObjC) |
Ted Kremenek | d3b74d9 | 2011-11-17 23:01:24 +0000 | [diff] [blame] | 2005 | Res.getLangOpts()->ObjCExceptions = 1; |
Fariborz Jahanian | e293d30 | 2011-02-25 17:24:55 +0000 | [diff] [blame] | 2006 | } |
Argyrios Kyrtzidis | 389db16 | 2010-11-03 22:45:23 +0000 | [diff] [blame] | 2007 | // FIXME: ParsePreprocessorArgs uses the FileManager to read the contents of |
| 2008 | // PCH file and find the original header name. Remove the need to do that in |
Chris Lattner | 39b49bc | 2010-11-23 08:35:12 +0000 | [diff] [blame] | 2009 | // ParsePreprocessorArgs and remove the FileManager |
Argyrios Kyrtzidis | 389db16 | 2010-11-03 22:45:23 +0000 | [diff] [blame] | 2010 | // parameters from the function and the "FileManager.h" #include. |
Chris Lattner | 7ad97ff | 2010-11-23 07:51:02 +0000 | [diff] [blame] | 2011 | FileManager FileMgr(Res.getFileSystemOpts()); |
Chris Lattner | 39b49bc | 2010-11-23 08:35:12 +0000 | [diff] [blame] | 2012 | ParsePreprocessorArgs(Res.getPreprocessorOpts(), *Args, FileMgr, Diags); |
Daniel Dunbar | 56ac85c | 2009-12-01 03:16:53 +0000 | [diff] [blame] | 2013 | ParsePreprocessorOutputArgs(Res.getPreprocessorOutputOpts(), *Args); |
| 2014 | ParseTargetArgs(Res.getTargetOpts(), *Args); |
| 2015 | } |
Douglas Gregor | 6e975c4 | 2011-09-13 23:15:45 +0000 | [diff] [blame] | 2016 | |
| 2017 | namespace { |
| 2018 | |
| 2019 | class ModuleSignature { |
| 2020 | llvm::SmallVector<uint64_t, 16> Data; |
| 2021 | unsigned CurBit; |
| 2022 | uint64_t CurValue; |
| 2023 | |
| 2024 | public: |
| 2025 | ModuleSignature() : CurBit(0), CurValue(0) { } |
| 2026 | |
| 2027 | void add(uint64_t Value, unsigned Bits); |
| 2028 | void add(StringRef Value); |
| 2029 | void flush(); |
| 2030 | |
| 2031 | llvm::APInt getAsInteger() const; |
| 2032 | }; |
| 2033 | } |
| 2034 | |
| 2035 | void ModuleSignature::add(uint64_t Value, unsigned int NumBits) { |
| 2036 | CurValue |= Value << CurBit; |
| 2037 | if (CurBit + NumBits < 64) { |
| 2038 | CurBit += NumBits; |
| 2039 | return; |
| 2040 | } |
| 2041 | |
| 2042 | // Add the current word. |
| 2043 | Data.push_back(CurValue); |
| 2044 | |
| 2045 | if (CurBit) |
| 2046 | CurValue = Value >> (64-CurBit); |
| 2047 | else |
| 2048 | CurValue = 0; |
| 2049 | CurBit = (CurBit+NumBits) & 63; |
| 2050 | } |
| 2051 | |
| 2052 | void ModuleSignature::flush() { |
| 2053 | if (CurBit == 0) |
| 2054 | return; |
| 2055 | |
| 2056 | Data.push_back(CurValue); |
| 2057 | CurBit = 0; |
| 2058 | CurValue = 0; |
| 2059 | } |
| 2060 | |
| 2061 | void ModuleSignature::add(StringRef Value) { |
| 2062 | for (StringRef::iterator I = Value.begin(), IEnd = Value.end(); I != IEnd;++I) |
| 2063 | add(*I, 8); |
| 2064 | } |
| 2065 | |
| 2066 | llvm::APInt ModuleSignature::getAsInteger() const { |
| 2067 | return llvm::APInt(Data.size() * 64, Data); |
| 2068 | } |
| 2069 | |
| 2070 | std::string CompilerInvocation::getModuleHash() const { |
| 2071 | ModuleSignature Signature; |
| 2072 | |
| 2073 | // Start the signature with the compiler version. |
| 2074 | Signature.add(getClangFullRepositoryVersion()); |
| 2075 | |
| 2076 | // Extend the signature with the language options |
| 2077 | #define LANGOPT(Name, Bits, Default, Description) \ |
Ted Kremenek | d3b74d9 | 2011-11-17 23:01:24 +0000 | [diff] [blame] | 2078 | Signature.add(LangOpts->Name, Bits); |
Douglas Gregor | 6e975c4 | 2011-09-13 23:15:45 +0000 | [diff] [blame] | 2079 | #define ENUM_LANGOPT(Name, Type, Bits, Default, Description) \ |
Ted Kremenek | d3b74d9 | 2011-11-17 23:01:24 +0000 | [diff] [blame] | 2080 | Signature.add(static_cast<unsigned>(LangOpts->get##Name()), Bits); |
Douglas Gregor | 6e975c4 | 2011-09-13 23:15:45 +0000 | [diff] [blame] | 2081 | #define BENIGN_LANGOPT(Name, Bits, Default, Description) |
| 2082 | #define BENIGN_ENUM_LANGOPT(Name, Type, Bits, Default, Description) |
| 2083 | #include "clang/Basic/LangOptions.def" |
| 2084 | |
| 2085 | // Extend the signature with the target triple |
| 2086 | llvm::Triple T(TargetOpts.Triple); |
| 2087 | Signature.add((unsigned)T.getArch(), 5); |
| 2088 | Signature.add((unsigned)T.getVendor(), 4); |
| 2089 | Signature.add((unsigned)T.getOS(), 5); |
| 2090 | Signature.add((unsigned)T.getEnvironment(), 4); |
| 2091 | |
Douglas Gregor | 815759c | 2011-09-14 15:55:12 +0000 | [diff] [blame] | 2092 | // Extend the signature with preprocessor options. |
| 2093 | Signature.add(getPreprocessorOpts().UsePredefines, 1); |
| 2094 | Signature.add(getPreprocessorOpts().DetailedRecord, 1); |
| 2095 | |
Douglas Gregor | 05edf66 | 2011-10-17 14:55:37 +0000 | [diff] [blame] | 2096 | // Hash the preprocessor defines. |
| 2097 | // FIXME: This is terrible. Use an MD5 sum of the preprocessor defines. |
| 2098 | std::vector<StringRef> MacroDefs; |
| 2099 | for (std::vector<std::pair<std::string, bool/*isUndef*/> >::const_iterator |
| 2100 | I = getPreprocessorOpts().Macros.begin(), |
| 2101 | IEnd = getPreprocessorOpts().Macros.end(); |
| 2102 | I != IEnd; ++I) { |
| 2103 | if (!I->second) |
| 2104 | MacroDefs.push_back(I->first); |
| 2105 | } |
| 2106 | llvm::array_pod_sort(MacroDefs.begin(), MacroDefs.end()); |
| 2107 | |
| 2108 | unsigned PPHashResult = 0; |
| 2109 | for (unsigned I = 0, N = MacroDefs.size(); I != N; ++I) |
| 2110 | PPHashResult = llvm::HashString(MacroDefs[I], PPHashResult); |
| 2111 | Signature.add(PPHashResult, 32); |
| 2112 | |
Douglas Gregor | 6e975c4 | 2011-09-13 23:15:45 +0000 | [diff] [blame] | 2113 | // We've generated the signature. Treat it as one large APInt that we'll |
Douglas Gregor | 815759c | 2011-09-14 15:55:12 +0000 | [diff] [blame] | 2114 | // encode in base-36 and return. |
Douglas Gregor | 6e975c4 | 2011-09-13 23:15:45 +0000 | [diff] [blame] | 2115 | Signature.flush(); |
Douglas Gregor | 815759c | 2011-09-14 15:55:12 +0000 | [diff] [blame] | 2116 | return Signature.getAsInteger().toString(36, /*Signed=*/false); |
Douglas Gregor | 6e975c4 | 2011-09-13 23:15:45 +0000 | [diff] [blame] | 2117 | } |