Daniel Dunbar | 0498cfc | 2009-11-10 19:51:53 +0000 | [diff] [blame] | 1 | //===--- Options.cpp - clang-cc Option Handling ---------------------------===// |
| 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 | // This file contains "pure" option handling, it is only responsible for turning |
| 11 | // the options into internal *Option classes, but shouldn't have any other |
| 12 | // logic. |
| 13 | |
| 14 | #include "Options.h" |
Daniel Dunbar | 339c134 | 2009-11-11 08:13:55 +0000 | [diff] [blame] | 15 | #include "clang/Basic/LangOptions.h" |
| 16 | #include "clang/Basic/TargetInfo.h" |
Daniel Dunbar | d58c03f | 2009-11-15 06:48:46 +0000 | [diff] [blame] | 17 | #include "clang/Basic/TargetOptions.h" |
Daniel Dunbar | 339c134 | 2009-11-11 08:13:55 +0000 | [diff] [blame] | 18 | #include "clang/Frontend/AnalysisConsumer.h" |
Chandler Carruth | 2811ccf | 2009-11-12 17:24:48 +0000 | [diff] [blame] | 19 | #include "clang/CodeGen/CodeGenOptions.h" |
Daniel Dunbar | 0e0bae8 | 2009-11-11 21:43:12 +0000 | [diff] [blame] | 20 | #include "clang/Frontend/DependencyOutputOptions.h" |
Daniel Dunbar | 0db4b76 | 2009-11-11 08:13:40 +0000 | [diff] [blame] | 21 | #include "clang/Frontend/DiagnosticOptions.h" |
Daniel Dunbar | 2626688 | 2009-11-12 23:52:32 +0000 | [diff] [blame] | 22 | #include "clang/Frontend/FrontendOptions.h" |
Daniel Dunbar | f797329 | 2009-11-11 08:13:32 +0000 | [diff] [blame] | 23 | #include "clang/Frontend/HeaderSearchOptions.h" |
Daniel Dunbar | b52d243 | 2009-11-11 06:10:03 +0000 | [diff] [blame] | 24 | #include "clang/Frontend/PCHReader.h" |
| 25 | #include "clang/Frontend/PreprocessorOptions.h" |
Daniel Dunbar | 29cf746 | 2009-11-11 10:07:44 +0000 | [diff] [blame] | 26 | #include "clang/Frontend/PreprocessorOutputOptions.h" |
Daniel Dunbar | b52d243 | 2009-11-11 06:10:03 +0000 | [diff] [blame] | 27 | #include "llvm/ADT/STLExtras.h" |
Daniel Dunbar | 0498cfc | 2009-11-10 19:51:53 +0000 | [diff] [blame] | 28 | #include "llvm/ADT/StringMap.h" |
| 29 | #include "llvm/Support/CommandLine.h" |
Daniel Dunbar | d10c5b8 | 2009-11-15 00:12:04 +0000 | [diff] [blame] | 30 | #include "llvm/Support/RegistryParser.h" |
Daniel Dunbar | d58c03f | 2009-11-15 06:48:46 +0000 | [diff] [blame] | 31 | #include "llvm/System/Host.h" |
Dan Gohman | 0063e98 | 2009-11-10 21:21:27 +0000 | [diff] [blame] | 32 | #include <stdio.h> |
Daniel Dunbar | 0498cfc | 2009-11-10 19:51:53 +0000 | [diff] [blame] | 33 | |
| 34 | using namespace clang; |
| 35 | |
| 36 | //===----------------------------------------------------------------------===// |
Daniel Dunbar | 339c134 | 2009-11-11 08:13:55 +0000 | [diff] [blame] | 37 | // Analyzer Options |
| 38 | //===----------------------------------------------------------------------===// |
| 39 | |
| 40 | namespace analyzeroptions { |
| 41 | |
| 42 | static llvm::cl::list<Analyses> |
| 43 | AnalysisList(llvm::cl::desc("Source Code Analysis - Checks and Analyses"), |
| 44 | llvm::cl::values( |
| 45 | #define ANALYSIS(NAME, CMDFLAG, DESC, SCOPE)\ |
| 46 | clEnumValN(NAME, CMDFLAG, DESC), |
| 47 | #include "clang/Frontend/Analyses.def" |
| 48 | clEnumValEnd)); |
| 49 | |
| 50 | static llvm::cl::opt<AnalysisStores> |
| 51 | AnalysisStoreOpt("analyzer-store", |
| 52 | llvm::cl::desc("Source Code Analysis - Abstract Memory Store Models"), |
| 53 | llvm::cl::init(BasicStoreModel), |
| 54 | llvm::cl::values( |
| 55 | #define ANALYSIS_STORE(NAME, CMDFLAG, DESC, CREATFN)\ |
| 56 | clEnumValN(NAME##Model, CMDFLAG, DESC), |
| 57 | #include "clang/Frontend/Analyses.def" |
| 58 | clEnumValEnd)); |
| 59 | |
| 60 | static llvm::cl::opt<AnalysisConstraints> |
| 61 | AnalysisConstraintsOpt("analyzer-constraints", |
| 62 | llvm::cl::desc("Source Code Analysis - Symbolic Constraint Engines"), |
| 63 | llvm::cl::init(RangeConstraintsModel), |
| 64 | llvm::cl::values( |
| 65 | #define ANALYSIS_CONSTRAINTS(NAME, CMDFLAG, DESC, CREATFN)\ |
| 66 | clEnumValN(NAME##Model, CMDFLAG, DESC), |
| 67 | #include "clang/Frontend/Analyses.def" |
| 68 | clEnumValEnd)); |
| 69 | |
| 70 | static llvm::cl::opt<AnalysisDiagClients> |
| 71 | AnalysisDiagOpt("analyzer-output", |
| 72 | llvm::cl::desc("Source Code Analysis - Output Options"), |
| 73 | llvm::cl::init(PD_HTML), |
| 74 | llvm::cl::values( |
| 75 | #define ANALYSIS_DIAGNOSTICS(NAME, CMDFLAG, DESC, CREATFN, AUTOCREATE)\ |
| 76 | clEnumValN(PD_##NAME, CMDFLAG, DESC), |
| 77 | #include "clang/Frontend/Analyses.def" |
| 78 | clEnumValEnd)); |
| 79 | |
| 80 | static llvm::cl::opt<bool> |
| 81 | AnalyzeAll("analyzer-opt-analyze-headers", |
| 82 | llvm::cl::desc("Force the static analyzer to analyze " |
| 83 | "functions defined in header files")); |
Ted Kremenek | eb94113 | 2009-11-13 01:15:47 +0000 | [diff] [blame] | 84 | |
Daniel Dunbar | 339c134 | 2009-11-11 08:13:55 +0000 | [diff] [blame] | 85 | static llvm::cl::opt<bool> |
| 86 | AnalyzerDisplayProgress("analyzer-display-progress", |
Ted Kremenek | eb94113 | 2009-11-13 01:15:47 +0000 | [diff] [blame] | 87 | llvm::cl::desc("Emit verbose output about the analyzer's progress")); |
Daniel Dunbar | 339c134 | 2009-11-11 08:13:55 +0000 | [diff] [blame] | 88 | |
Ted Kremenek | eb94113 | 2009-11-13 01:15:47 +0000 | [diff] [blame] | 89 | static llvm::cl::opt<bool> |
| 90 | AnalyzerExperimentalChecks("analyzer-experimental-checks", |
| 91 | llvm::cl::desc("Use experimental path-sensitive checks")); |
Ted Kremenek | 8382cf5 | 2009-11-13 18:46:29 +0000 | [diff] [blame] | 92 | |
| 93 | static llvm::cl::opt<bool> |
| 94 | AnalyzerExperimentalInternalChecks("analyzer-experimental-internal-checks", |
| 95 | llvm::cl::desc("Use new default path-sensitive checks currently in testing")); |
Ted Kremenek | eb94113 | 2009-11-13 01:15:47 +0000 | [diff] [blame] | 96 | |
Daniel Dunbar | 339c134 | 2009-11-11 08:13:55 +0000 | [diff] [blame] | 97 | static llvm::cl::opt<std::string> |
| 98 | AnalyzeSpecificFunction("analyze-function", |
| 99 | llvm::cl::desc("Run analysis on specific function")); |
| 100 | |
| 101 | static llvm::cl::opt<bool> |
| 102 | EagerlyAssume("analyzer-eagerly-assume", |
| 103 | llvm::cl::init(false), |
| 104 | llvm::cl::desc("Eagerly assume the truth/falseness of some " |
Ted Kremenek | eb94113 | 2009-11-13 01:15:47 +0000 | [diff] [blame] | 105 | "symbolic constraints")); |
Daniel Dunbar | 339c134 | 2009-11-11 08:13:55 +0000 | [diff] [blame] | 106 | |
| 107 | static llvm::cl::opt<bool> |
| 108 | PurgeDead("analyzer-purge-dead", |
| 109 | llvm::cl::init(true), |
| 110 | llvm::cl::desc("Remove dead symbols, bindings, and constraints before" |
Ted Kremenek | eb94113 | 2009-11-13 01:15:47 +0000 | [diff] [blame] | 111 | " processing a statement")); |
Daniel Dunbar | 339c134 | 2009-11-11 08:13:55 +0000 | [diff] [blame] | 112 | |
| 113 | static llvm::cl::opt<bool> |
| 114 | TrimGraph("trim-egraph", |
| 115 | llvm::cl::desc("Only show error-related paths in the analysis graph")); |
| 116 | |
| 117 | static llvm::cl::opt<bool> |
| 118 | VisualizeEGDot("analyzer-viz-egraph-graphviz", |
| 119 | llvm::cl::desc("Display exploded graph using GraphViz")); |
| 120 | |
| 121 | static llvm::cl::opt<bool> |
| 122 | VisualizeEGUbi("analyzer-viz-egraph-ubigraph", |
| 123 | llvm::cl::desc("Display exploded graph using Ubigraph")); |
| 124 | |
| 125 | } |
| 126 | |
Daniel Dunbar | 339c134 | 2009-11-11 08:13:55 +0000 | [diff] [blame] | 127 | //===----------------------------------------------------------------------===// |
Daniel Dunbar | 0498cfc | 2009-11-10 19:51:53 +0000 | [diff] [blame] | 128 | // Code Generation Options |
| 129 | //===----------------------------------------------------------------------===// |
| 130 | |
| 131 | namespace codegenoptions { |
| 132 | |
| 133 | static llvm::cl::opt<bool> |
| 134 | DisableLLVMOptimizations("disable-llvm-optzns", |
| 135 | llvm::cl::desc("Don't run LLVM optimization passes")); |
| 136 | |
| 137 | static llvm::cl::opt<bool> |
| 138 | DisableRedZone("disable-red-zone", |
| 139 | llvm::cl::desc("Do not emit code that uses the red zone."), |
| 140 | llvm::cl::init(false)); |
| 141 | |
| 142 | static llvm::cl::opt<bool> |
| 143 | GenerateDebugInfo("g", |
| 144 | llvm::cl::desc("Generate source level debug information")); |
| 145 | |
| 146 | static llvm::cl::opt<bool> |
| 147 | NoCommon("fno-common", |
| 148 | llvm::cl::desc("Compile common globals like normal definitions"), |
| 149 | llvm::cl::ValueDisallowed); |
| 150 | |
| 151 | static llvm::cl::opt<bool> |
| 152 | NoImplicitFloat("no-implicit-float", |
| 153 | llvm::cl::desc("Don't generate implicit floating point instructions (x86-only)"), |
| 154 | llvm::cl::init(false)); |
| 155 | |
| 156 | static llvm::cl::opt<bool> |
| 157 | NoMergeConstants("fno-merge-all-constants", |
| 158 | llvm::cl::desc("Disallow merging of constants.")); |
| 159 | |
| 160 | // It might be nice to add bounds to the CommandLine library directly. |
| 161 | struct OptLevelParser : public llvm::cl::parser<unsigned> { |
| 162 | bool parse(llvm::cl::Option &O, llvm::StringRef ArgName, |
| 163 | llvm::StringRef Arg, unsigned &Val) { |
| 164 | if (llvm::cl::parser<unsigned>::parse(O, ArgName, Arg, Val)) |
| 165 | return true; |
| 166 | if (Val > 3) |
| 167 | return O.error("'" + Arg + "' invalid optimization level!"); |
| 168 | return false; |
| 169 | } |
| 170 | }; |
| 171 | static llvm::cl::opt<unsigned, false, OptLevelParser> |
| 172 | OptLevel("O", llvm::cl::Prefix, |
| 173 | llvm::cl::desc("Optimization level"), |
| 174 | llvm::cl::init(0)); |
| 175 | |
| 176 | static llvm::cl::opt<bool> |
| 177 | OptSize("Os", llvm::cl::desc("Optimize for size")); |
| 178 | |
Daniel Dunbar | 0498cfc | 2009-11-10 19:51:53 +0000 | [diff] [blame] | 179 | } |
| 180 | |
| 181 | //===----------------------------------------------------------------------===// |
Daniel Dunbar | 0e0bae8 | 2009-11-11 21:43:12 +0000 | [diff] [blame] | 182 | // Dependency Output Options |
| 183 | //===----------------------------------------------------------------------===// |
| 184 | |
| 185 | namespace dependencyoutputoptions { |
| 186 | |
| 187 | static llvm::cl::opt<std::string> |
| 188 | DependencyFile("dependency-file", |
| 189 | llvm::cl::desc("Filename (or -) to write dependency output to")); |
| 190 | |
| 191 | static llvm::cl::opt<bool> |
| 192 | DependenciesIncludeSystemHeaders("sys-header-deps", |
| 193 | llvm::cl::desc("Include system headers in dependency output")); |
| 194 | |
| 195 | static llvm::cl::list<std::string> |
| 196 | DependencyTargets("MT", |
| 197 | llvm::cl::desc("Specify target for dependency")); |
| 198 | |
| 199 | static llvm::cl::opt<bool> |
| 200 | PhonyDependencyTarget("MP", |
| 201 | llvm::cl::desc("Create phony target for each dependency " |
| 202 | "(other than main file)")); |
| 203 | |
| 204 | } |
| 205 | |
| 206 | //===----------------------------------------------------------------------===// |
Daniel Dunbar | 0db4b76 | 2009-11-11 08:13:40 +0000 | [diff] [blame] | 207 | // Diagnostic Options |
| 208 | //===----------------------------------------------------------------------===// |
| 209 | |
| 210 | namespace diagnosticoptions { |
| 211 | |
Daniel Dunbar | 11e729d | 2009-11-12 07:28:21 +0000 | [diff] [blame] | 212 | static llvm::cl::opt<std::string> |
| 213 | DumpBuildInformation("dump-build-information", |
| 214 | llvm::cl::value_desc("filename"), |
| 215 | llvm::cl::desc("output a dump of some build information to a file")); |
| 216 | |
Daniel Dunbar | 0db4b76 | 2009-11-11 08:13:40 +0000 | [diff] [blame] | 217 | static llvm::cl::opt<bool> |
| 218 | NoShowColumn("fno-show-column", |
| 219 | llvm::cl::desc("Do not include column number on diagnostics")); |
| 220 | |
| 221 | static llvm::cl::opt<bool> |
| 222 | NoShowLocation("fno-show-source-location", |
| 223 | llvm::cl::desc("Do not include source location information with" |
| 224 | " diagnostics")); |
| 225 | |
| 226 | static llvm::cl::opt<bool> |
| 227 | NoCaretDiagnostics("fno-caret-diagnostics", |
| 228 | llvm::cl::desc("Do not include source line and caret with" |
| 229 | " diagnostics")); |
| 230 | |
| 231 | static llvm::cl::opt<bool> |
| 232 | NoDiagnosticsFixIt("fno-diagnostics-fixit-info", |
| 233 | llvm::cl::desc("Do not include fixit information in" |
| 234 | " diagnostics")); |
| 235 | |
Daniel Dunbar | 6907943 | 2009-11-12 07:28:44 +0000 | [diff] [blame] | 236 | static llvm::cl::opt<bool> OptNoWarnings("w"); |
| 237 | |
| 238 | static llvm::cl::opt<bool> OptPedantic("pedantic"); |
| 239 | |
| 240 | static llvm::cl::opt<bool> OptPedanticErrors("pedantic-errors"); |
| 241 | |
| 242 | // This gets all -W options, including -Werror, -W[no-]system-headers, etc. The |
| 243 | // driver has stripped off -Wa,foo etc. The driver has also translated -W to |
| 244 | // -Wextra, so we don't need to worry about it. |
| 245 | static llvm::cl::list<std::string> |
| 246 | OptWarnings("W", llvm::cl::Prefix, llvm::cl::ValueOptional); |
| 247 | |
Daniel Dunbar | 0db4b76 | 2009-11-11 08:13:40 +0000 | [diff] [blame] | 248 | static llvm::cl::opt<bool> |
| 249 | PrintSourceRangeInfo("fdiagnostics-print-source-range-info", |
| 250 | llvm::cl::desc("Print source range spans in numeric form")); |
| 251 | |
| 252 | static llvm::cl::opt<bool> |
| 253 | PrintDiagnosticOption("fdiagnostics-show-option", |
| 254 | llvm::cl::desc("Print diagnostic name with mappable diagnostics")); |
| 255 | |
| 256 | static llvm::cl::opt<unsigned> |
| 257 | MessageLength("fmessage-length", |
| 258 | llvm::cl::desc("Format message diagnostics so that they fit " |
| 259 | "within N columns or fewer, when possible."), |
| 260 | llvm::cl::value_desc("N")); |
| 261 | |
| 262 | static llvm::cl::opt<bool> |
| 263 | PrintColorDiagnostic("fcolor-diagnostics", |
| 264 | llvm::cl::desc("Use colors in diagnostics")); |
| 265 | |
Daniel Dunbar | 6907943 | 2009-11-12 07:28:44 +0000 | [diff] [blame] | 266 | static llvm::cl::opt<bool> |
| 267 | SilenceRewriteMacroWarning("Wno-rewrite-macros", llvm::cl::init(false), |
| 268 | llvm::cl::desc("Silence ObjC rewriting warnings")); |
| 269 | |
Daniel Dunbar | 2626688 | 2009-11-12 23:52:32 +0000 | [diff] [blame] | 270 | static llvm::cl::opt<bool> |
| 271 | VerifyDiagnostics("verify", |
| 272 | llvm::cl::desc("Verify emitted diagnostics and warnings")); |
| 273 | |
| 274 | } |
| 275 | |
Daniel Dunbar | 2626688 | 2009-11-12 23:52:32 +0000 | [diff] [blame] | 276 | //===----------------------------------------------------------------------===// |
| 277 | // Frontend Options |
| 278 | //===----------------------------------------------------------------------===// |
| 279 | |
| 280 | namespace frontendoptions { |
| 281 | |
Daniel Dunbar | 9a8a83b | 2009-11-14 22:32:38 +0000 | [diff] [blame] | 282 | using namespace clang::frontend; |
| 283 | |
Daniel Dunbar | 914474c | 2009-11-13 01:02:10 +0000 | [diff] [blame] | 284 | static llvm::cl::opt<ParsedSourceLocation> |
| 285 | CodeCompletionAt("code-completion-at", |
| 286 | llvm::cl::value_desc("file:line:column"), |
| 287 | llvm::cl::desc("Dump code-completion information at a location")); |
| 288 | |
| 289 | static llvm::cl::opt<bool> |
| 290 | CodeCompletionDebugPrinter("code-completion-debug-printer", |
| 291 | llvm::cl::desc("Use the \"debug\" code-completion print"), |
| 292 | llvm::cl::init(true)); |
| 293 | |
| 294 | static llvm::cl::opt<bool> |
| 295 | CodeCompletionWantsMacros("code-completion-macros", |
| 296 | llvm::cl::desc("Include macros in code-completion results")); |
| 297 | |
Daniel Dunbar | 2626688 | 2009-11-12 23:52:32 +0000 | [diff] [blame] | 298 | static llvm::cl::opt<bool> |
| 299 | DisableFree("disable-free", |
| 300 | llvm::cl::desc("Disable freeing of memory on exit"), |
| 301 | llvm::cl::init(false)); |
| 302 | |
| 303 | static llvm::cl::opt<bool> |
| 304 | EmptyInputOnly("empty-input-only", |
| 305 | llvm::cl::desc("Force running on an empty input file")); |
| 306 | |
Daniel Dunbar | fbe2faf | 2009-11-13 02:06:12 +0000 | [diff] [blame] | 307 | static llvm::cl::opt<FrontendOptions::InputKind> |
| 308 | InputType("x", llvm::cl::desc("Input language type"), |
| 309 | llvm::cl::init(FrontendOptions::IK_None), |
| 310 | llvm::cl::values(clEnumValN(FrontendOptions::IK_C, "c", "C"), |
| 311 | clEnumValN(FrontendOptions::IK_OpenCL, "cl", "OpenCL C"), |
| 312 | clEnumValN(FrontendOptions::IK_CXX, "c++", "C++"), |
| 313 | clEnumValN(FrontendOptions::IK_ObjC, "objective-c", |
| 314 | "Objective C"), |
| 315 | clEnumValN(FrontendOptions::IK_ObjCXX, "objective-c++", |
| 316 | "Objective C++"), |
| 317 | clEnumValN(FrontendOptions::IK_PreprocessedC, |
| 318 | "cpp-output", |
| 319 | "Preprocessed C"), |
| 320 | clEnumValN(FrontendOptions::IK_Asm, |
| 321 | "assembler-with-cpp", |
| 322 | "Assembly Source Codde"), |
| 323 | clEnumValN(FrontendOptions::IK_PreprocessedCXX, |
| 324 | "c++-cpp-output", |
| 325 | "Preprocessed C++"), |
| 326 | clEnumValN(FrontendOptions::IK_PreprocessedObjC, |
| 327 | "objective-c-cpp-output", |
| 328 | "Preprocessed Objective C"), |
| 329 | clEnumValN(FrontendOptions::IK_PreprocessedObjCXX, |
| 330 | "objective-c++-cpp-output", |
| 331 | "Preprocessed Objective C++"), |
| 332 | clEnumValN(FrontendOptions::IK_C, "c-header", |
| 333 | "C header"), |
| 334 | clEnumValN(FrontendOptions::IK_ObjC, "objective-c-header", |
| 335 | "Objective-C header"), |
| 336 | clEnumValN(FrontendOptions::IK_CXX, "c++-header", |
| 337 | "C++ header"), |
| 338 | clEnumValN(FrontendOptions::IK_ObjCXX, |
| 339 | "objective-c++-header", |
| 340 | "Objective-C++ header"), |
| 341 | clEnumValN(FrontendOptions::IK_AST, "ast", |
| 342 | "Clang AST"), |
| 343 | clEnumValEnd)); |
| 344 | |
Daniel Dunbar | 2626688 | 2009-11-12 23:52:32 +0000 | [diff] [blame] | 345 | static llvm::cl::list<std::string> |
| 346 | InputFilenames(llvm::cl::Positional, llvm::cl::desc("<input files>")); |
| 347 | |
| 348 | static llvm::cl::opt<std::string> |
| 349 | InheritanceViewCls("cxx-inheritance-view", |
| 350 | llvm::cl::value_desc("class name"), |
| 351 | llvm::cl::desc("View C++ inheritance for a specified class")); |
| 352 | |
Daniel Dunbar | c86804b | 2009-11-12 23:52:56 +0000 | [diff] [blame] | 353 | static llvm::cl::list<ParsedSourceLocation> |
| 354 | FixItAtLocations("fixit-at", llvm::cl::value_desc("source-location"), |
| 355 | llvm::cl::desc("Perform Fix-It modifications at the given source location")); |
| 356 | |
Daniel Dunbar | 2626688 | 2009-11-12 23:52:32 +0000 | [diff] [blame] | 357 | static llvm::cl::opt<std::string> |
| 358 | OutputFile("o", |
| 359 | llvm::cl::value_desc("path"), |
| 360 | llvm::cl::desc("Specify output file")); |
| 361 | |
Daniel Dunbar | d10c5b8 | 2009-11-15 00:12:04 +0000 | [diff] [blame] | 362 | static llvm::cl::opt<std::string> |
| 363 | PluginActionName("plugin", |
| 364 | llvm::cl::desc("Use the named plugin action " |
| 365 | "(use \"help\" to list available options)")); |
| 366 | |
Daniel Dunbar | 9a8a83b | 2009-11-14 22:32:38 +0000 | [diff] [blame] | 367 | static llvm::cl::opt<ActionKind> |
| 368 | ProgAction(llvm::cl::desc("Choose output type:"), llvm::cl::ZeroOrMore, |
| 369 | llvm::cl::init(ParseSyntaxOnly), |
| 370 | llvm::cl::values( |
| 371 | clEnumValN(RunPreprocessorOnly, "Eonly", |
| 372 | "Just run preprocessor, no output (for timings)"), |
| 373 | clEnumValN(PrintPreprocessedInput, "E", |
| 374 | "Run preprocessor, emit preprocessed file"), |
| 375 | clEnumValN(DumpRawTokens, "dump-raw-tokens", |
| 376 | "Lex file in raw mode and dump raw tokens"), |
| 377 | clEnumValN(RunAnalysis, "analyze", |
| 378 | "Run static analysis engine"), |
| 379 | clEnumValN(DumpTokens, "dump-tokens", |
| 380 | "Run preprocessor, dump internal rep of tokens"), |
| 381 | clEnumValN(ParseNoop, "parse-noop", |
| 382 | "Run parser with noop callbacks (for timings)"), |
| 383 | clEnumValN(ParseSyntaxOnly, "fsyntax-only", |
| 384 | "Run parser and perform semantic analysis"), |
| 385 | clEnumValN(FixIt, "fixit", |
| 386 | "Apply fix-it advice to the input source"), |
| 387 | clEnumValN(ParsePrintCallbacks, "parse-print-callbacks", |
| 388 | "Run parser and print each callback invoked"), |
| 389 | clEnumValN(EmitHTML, "emit-html", |
| 390 | "Output input source as HTML"), |
| 391 | clEnumValN(ASTPrint, "ast-print", |
| 392 | "Build ASTs and then pretty-print them"), |
| 393 | clEnumValN(ASTPrintXML, "ast-print-xml", |
| 394 | "Build ASTs and then print them in XML format"), |
| 395 | clEnumValN(ASTDump, "ast-dump", |
| 396 | "Build ASTs and then debug dump them"), |
| 397 | clEnumValN(ASTView, "ast-view", |
| 398 | "Build ASTs and view them with GraphViz"), |
| 399 | clEnumValN(PrintDeclContext, "print-decl-contexts", |
| 400 | "Print DeclContexts and their Decls"), |
| 401 | clEnumValN(DumpRecordLayouts, "dump-record-layouts", |
| 402 | "Dump record layout information"), |
| 403 | clEnumValN(GeneratePTH, "emit-pth", |
| 404 | "Generate pre-tokenized header file"), |
| 405 | clEnumValN(GeneratePCH, "emit-pch", |
| 406 | "Generate pre-compiled header file"), |
| 407 | clEnumValN(EmitAssembly, "S", |
| 408 | "Emit native assembly code"), |
| 409 | clEnumValN(EmitLLVM, "emit-llvm", |
| 410 | "Build ASTs then convert to LLVM, emit .ll file"), |
| 411 | clEnumValN(EmitBC, "emit-llvm-bc", |
| 412 | "Build ASTs then convert to LLVM, emit .bc file"), |
| 413 | clEnumValN(EmitLLVMOnly, "emit-llvm-only", |
| 414 | "Build ASTs and convert to LLVM, discarding output"), |
| 415 | clEnumValN(RewriteTest, "rewrite-test", |
| 416 | "Rewriter playground"), |
| 417 | clEnumValN(RewriteObjC, "rewrite-objc", |
| 418 | "Rewrite ObjC into C (code rewriter example)"), |
| 419 | clEnumValN(RewriteMacros, "rewrite-macros", |
| 420 | "Expand macros without full preprocessing"), |
| 421 | clEnumValN(RewriteBlocks, "rewrite-blocks", |
| 422 | "Rewrite Blocks to C"), |
| 423 | clEnumValEnd)); |
| 424 | |
Daniel Dunbar | 2626688 | 2009-11-12 23:52:32 +0000 | [diff] [blame] | 425 | static llvm::cl::opt<bool> |
| 426 | RelocatablePCH("relocatable-pch", |
| 427 | llvm::cl::desc("Whether to build a relocatable precompiled " |
| 428 | "header")); |
| 429 | static llvm::cl::opt<bool> |
| 430 | Stats("print-stats", |
| 431 | llvm::cl::desc("Print performance metrics and statistics")); |
| 432 | |
| 433 | static llvm::cl::opt<bool> |
| 434 | TimeReport("ftime-report", |
| 435 | llvm::cl::desc("Print the amount of time each " |
| 436 | "phase of compilation takes")); |
| 437 | |
Daniel Dunbar | 0db4b76 | 2009-11-11 08:13:40 +0000 | [diff] [blame] | 438 | } |
| 439 | |
| 440 | //===----------------------------------------------------------------------===// |
Daniel Dunbar | 5674908 | 2009-11-11 07:26:12 +0000 | [diff] [blame] | 441 | // Language Options |
| 442 | //===----------------------------------------------------------------------===// |
| 443 | |
| 444 | namespace langoptions { |
| 445 | |
| 446 | static llvm::cl::opt<bool> |
| 447 | AllowBuiltins("fbuiltin", llvm::cl::init(true), |
| 448 | llvm::cl::desc("Disable implicit builtin knowledge of functions")); |
| 449 | |
| 450 | static llvm::cl::opt<bool> |
| 451 | AltiVec("faltivec", llvm::cl::desc("Enable AltiVec vector initializer syntax"), |
| 452 | llvm::cl::init(false)); |
| 453 | |
| 454 | static llvm::cl::opt<bool> |
| 455 | AccessControl("faccess-control", |
| 456 | llvm::cl::desc("Enable C++ access control")); |
| 457 | |
| 458 | static llvm::cl::opt<bool> |
| 459 | CharIsSigned("fsigned-char", |
| 460 | llvm::cl::desc("Force char to be a signed/unsigned type")); |
| 461 | |
| 462 | static llvm::cl::opt<bool> |
| 463 | DollarsInIdents("fdollars-in-identifiers", |
| 464 | llvm::cl::desc("Allow '$' in identifiers")); |
| 465 | |
| 466 | static llvm::cl::opt<bool> |
| 467 | EmitAllDecls("femit-all-decls", |
| 468 | llvm::cl::desc("Emit all declarations, even if unused")); |
| 469 | |
| 470 | static llvm::cl::opt<bool> |
| 471 | EnableBlocks("fblocks", llvm::cl::desc("enable the 'blocks' language feature")); |
| 472 | |
| 473 | static llvm::cl::opt<bool> |
| 474 | EnableHeinousExtensions("fheinous-gnu-extensions", |
| 475 | llvm::cl::desc("enable GNU extensions that you really really shouldn't use"), |
| 476 | llvm::cl::ValueDisallowed, llvm::cl::Hidden); |
| 477 | |
| 478 | static llvm::cl::opt<bool> |
| 479 | Exceptions("fexceptions", |
| 480 | llvm::cl::desc("Enable support for exception handling")); |
| 481 | |
| 482 | static llvm::cl::opt<bool> |
| 483 | Freestanding("ffreestanding", |
| 484 | llvm::cl::desc("Assert that the compilation takes place in a " |
| 485 | "freestanding environment")); |
| 486 | |
| 487 | static llvm::cl::opt<bool> |
| 488 | GNURuntime("fgnu-runtime", |
| 489 | llvm::cl::desc("Generate output compatible with the standard GNU " |
| 490 | "Objective-C runtime")); |
| 491 | |
| 492 | /// LangStds - Language standards we support. |
| 493 | enum LangStds { |
| 494 | lang_unspecified, |
| 495 | lang_c89, lang_c94, lang_c99, |
| 496 | lang_gnu89, lang_gnu99, |
| 497 | lang_cxx98, lang_gnucxx98, |
| 498 | lang_cxx0x, lang_gnucxx0x |
| 499 | }; |
| 500 | static llvm::cl::opt<LangStds> |
| 501 | LangStd("std", llvm::cl::desc("Language standard to compile for"), |
| 502 | llvm::cl::init(lang_unspecified), |
| 503 | llvm::cl::values(clEnumValN(lang_c89, "c89", "ISO C 1990"), |
| 504 | clEnumValN(lang_c89, "c90", "ISO C 1990"), |
| 505 | clEnumValN(lang_c89, "iso9899:1990", "ISO C 1990"), |
| 506 | clEnumValN(lang_c94, "iso9899:199409", |
| 507 | "ISO C 1990 with amendment 1"), |
| 508 | clEnumValN(lang_c99, "c99", "ISO C 1999"), |
| 509 | clEnumValN(lang_c99, "c9x", "ISO C 1999"), |
| 510 | clEnumValN(lang_c99, "iso9899:1999", "ISO C 1999"), |
| 511 | clEnumValN(lang_c99, "iso9899:199x", "ISO C 1999"), |
| 512 | clEnumValN(lang_gnu89, "gnu89", |
| 513 | "ISO C 1990 with GNU extensions"), |
| 514 | clEnumValN(lang_gnu99, "gnu99", |
| 515 | "ISO C 1999 with GNU extensions (default for C)"), |
| 516 | clEnumValN(lang_gnu99, "gnu9x", |
| 517 | "ISO C 1999 with GNU extensions"), |
| 518 | clEnumValN(lang_cxx98, "c++98", |
| 519 | "ISO C++ 1998 with amendments"), |
| 520 | clEnumValN(lang_gnucxx98, "gnu++98", |
| 521 | "ISO C++ 1998 with amendments and GNU " |
| 522 | "extensions (default for C++)"), |
| 523 | clEnumValN(lang_cxx0x, "c++0x", |
| 524 | "Upcoming ISO C++ 200x with amendments"), |
| 525 | clEnumValN(lang_gnucxx0x, "gnu++0x", |
| 526 | "Upcoming ISO C++ 200x with amendments and GNU " |
| 527 | "extensions"), |
| 528 | clEnumValEnd)); |
| 529 | |
| 530 | static llvm::cl::opt<bool> |
| 531 | MSExtensions("fms-extensions", |
| 532 | llvm::cl::desc("Accept some non-standard constructs used in " |
| 533 | "Microsoft header files ")); |
| 534 | |
| 535 | static llvm::cl::opt<std::string> |
| 536 | MainFileName("main-file-name", |
| 537 | llvm::cl::desc("Main file name to use for debug info")); |
| 538 | |
| 539 | static llvm::cl::opt<bool> |
| 540 | MathErrno("fmath-errno", llvm::cl::init(true), |
| 541 | llvm::cl::desc("Require math functions to respect errno")); |
| 542 | |
| 543 | static llvm::cl::opt<bool> |
Daniel Dunbar | 5674908 | 2009-11-11 07:26:12 +0000 | [diff] [blame] | 544 | NoElideConstructors("fno-elide-constructors", |
| 545 | llvm::cl::desc("Disable C++ copy constructor elision")); |
| 546 | |
| 547 | static llvm::cl::opt<bool> |
| 548 | NoLaxVectorConversions("fno-lax-vector-conversions", |
| 549 | llvm::cl::desc("Disallow implicit conversions between " |
| 550 | "vectors with a different number of " |
| 551 | "elements or different element types")); |
| 552 | |
| 553 | |
| 554 | static llvm::cl::opt<bool> |
| 555 | NoOperatorNames("fno-operator-names", |
| 556 | llvm::cl::desc("Do not treat C++ operator name keywords as " |
| 557 | "synonyms for operators")); |
| 558 | |
| 559 | static llvm::cl::opt<std::string> |
| 560 | ObjCConstantStringClass("fconstant-string-class", |
| 561 | llvm::cl::value_desc("class name"), |
| 562 | llvm::cl::desc("Specify the class to use for constant " |
| 563 | "Objective-C string objects.")); |
| 564 | |
| 565 | static llvm::cl::opt<bool> |
| 566 | ObjCEnableGC("fobjc-gc", |
| 567 | llvm::cl::desc("Enable Objective-C garbage collection")); |
| 568 | |
| 569 | static llvm::cl::opt<bool> |
| 570 | ObjCExclusiveGC("fobjc-gc-only", |
| 571 | llvm::cl::desc("Use GC exclusively for Objective-C related " |
| 572 | "memory management")); |
| 573 | |
| 574 | static llvm::cl::opt<bool> |
| 575 | ObjCEnableGCBitmapPrint("print-ivar-layout", |
| 576 | llvm::cl::desc("Enable Objective-C Ivar layout bitmap print trace")); |
| 577 | |
| 578 | static llvm::cl::opt<bool> |
| 579 | ObjCNonFragileABI("fobjc-nonfragile-abi", |
| 580 | llvm::cl::desc("enable objective-c's nonfragile abi")); |
| 581 | |
| 582 | static llvm::cl::opt<bool> |
| 583 | OverflowChecking("ftrapv", |
| 584 | llvm::cl::desc("Trap on integer overflow"), |
| 585 | llvm::cl::init(false)); |
| 586 | |
| 587 | static llvm::cl::opt<unsigned> |
| 588 | PICLevel("pic-level", llvm::cl::desc("Value for __PIC__")); |
| 589 | |
| 590 | static llvm::cl::opt<bool> |
| 591 | PThread("pthread", llvm::cl::desc("Support POSIX threads in generated code"), |
| 592 | llvm::cl::init(false)); |
| 593 | |
| 594 | static llvm::cl::opt<bool> |
| 595 | PascalStrings("fpascal-strings", |
| 596 | llvm::cl::desc("Recognize and construct Pascal-style " |
| 597 | "string literals")); |
| 598 | |
Daniel Dunbar | 5674908 | 2009-11-11 07:26:12 +0000 | [diff] [blame] | 599 | static llvm::cl::opt<bool> |
| 600 | Rtti("frtti", llvm::cl::init(true), |
| 601 | llvm::cl::desc("Enable generation of rtti information")); |
| 602 | |
| 603 | static llvm::cl::opt<bool> |
| 604 | ShortWChar("fshort-wchar", |
| 605 | llvm::cl::desc("Force wchar_t to be a short unsigned int")); |
| 606 | |
| 607 | static llvm::cl::opt<bool> |
| 608 | StaticDefine("static-define", llvm::cl::desc("Should __STATIC__ be defined")); |
| 609 | |
| 610 | static llvm::cl::opt<int> |
| 611 | StackProtector("stack-protector", |
| 612 | llvm::cl::desc("Enable stack protectors"), |
| 613 | llvm::cl::init(-1)); |
| 614 | |
| 615 | static llvm::cl::opt<LangOptions::VisibilityMode> |
| 616 | SymbolVisibility("fvisibility", |
| 617 | llvm::cl::desc("Set the default symbol visibility:"), |
| 618 | llvm::cl::init(LangOptions::Default), |
| 619 | llvm::cl::values(clEnumValN(LangOptions::Default, "default", |
| 620 | "Use default symbol visibility"), |
| 621 | clEnumValN(LangOptions::Hidden, "hidden", |
| 622 | "Use hidden symbol visibility"), |
| 623 | clEnumValN(LangOptions::Protected,"protected", |
| 624 | "Use protected symbol visibility"), |
| 625 | clEnumValEnd)); |
| 626 | |
| 627 | static llvm::cl::opt<unsigned> |
| 628 | TemplateDepth("ftemplate-depth", llvm::cl::init(99), |
| 629 | llvm::cl::desc("Maximum depth of recursive template " |
| 630 | "instantiation")); |
| 631 | |
| 632 | static llvm::cl::opt<bool> |
| 633 | Trigraphs("trigraphs", llvm::cl::desc("Process trigraph sequences")); |
| 634 | |
| 635 | static llvm::cl::opt<bool> |
| 636 | WritableStrings("fwritable-strings", |
| 637 | llvm::cl::desc("Store string literals as writable data")); |
| 638 | |
| 639 | } |
| 640 | |
| 641 | //===----------------------------------------------------------------------===// |
Daniel Dunbar | b52d243 | 2009-11-11 06:10:03 +0000 | [diff] [blame] | 642 | // General Preprocessor Options |
| 643 | //===----------------------------------------------------------------------===// |
| 644 | |
| 645 | namespace preprocessoroptions { |
| 646 | |
| 647 | static llvm::cl::list<std::string> |
| 648 | D_macros("D", llvm::cl::value_desc("macro"), llvm::cl::Prefix, |
| 649 | llvm::cl::desc("Predefine the specified macro")); |
| 650 | |
| 651 | static llvm::cl::list<std::string> |
| 652 | ImplicitIncludes("include", llvm::cl::value_desc("file"), |
| 653 | llvm::cl::desc("Include file before parsing")); |
| 654 | static llvm::cl::list<std::string> |
| 655 | ImplicitMacroIncludes("imacros", llvm::cl::value_desc("file"), |
| 656 | llvm::cl::desc("Include macros from file before parsing")); |
| 657 | |
| 658 | static llvm::cl::opt<std::string> |
| 659 | ImplicitIncludePCH("include-pch", llvm::cl::value_desc("file"), |
| 660 | llvm::cl::desc("Include precompiled header file")); |
| 661 | |
| 662 | static llvm::cl::opt<std::string> |
| 663 | ImplicitIncludePTH("include-pth", llvm::cl::value_desc("file"), |
| 664 | llvm::cl::desc("Include file before parsing")); |
| 665 | |
Daniel Dunbar | b3cb98e | 2009-11-12 02:53:59 +0000 | [diff] [blame] | 666 | static llvm::cl::opt<std::string> |
| 667 | TokenCache("token-cache", llvm::cl::value_desc("path"), |
| 668 | llvm::cl::desc("Use specified token cache file")); |
| 669 | |
Daniel Dunbar | b52d243 | 2009-11-11 06:10:03 +0000 | [diff] [blame] | 670 | static llvm::cl::list<std::string> |
| 671 | U_macros("U", llvm::cl::value_desc("macro"), llvm::cl::Prefix, |
| 672 | llvm::cl::desc("Undefine the specified macro")); |
| 673 | |
| 674 | static llvm::cl::opt<bool> |
| 675 | UndefMacros("undef", llvm::cl::value_desc("macro"), |
| 676 | llvm::cl::desc("undef all system defines")); |
| 677 | |
| 678 | } |
| 679 | |
| 680 | //===----------------------------------------------------------------------===// |
Daniel Dunbar | f797329 | 2009-11-11 08:13:32 +0000 | [diff] [blame] | 681 | // Header Search Options |
| 682 | //===----------------------------------------------------------------------===// |
| 683 | |
| 684 | namespace headersearchoptions { |
| 685 | |
| 686 | static llvm::cl::opt<bool> |
| 687 | nostdinc("nostdinc", llvm::cl::desc("Disable standard #include directories")); |
| 688 | |
| 689 | static llvm::cl::opt<bool> |
| 690 | nobuiltininc("nobuiltininc", |
| 691 | llvm::cl::desc("Disable builtin #include directories")); |
| 692 | |
| 693 | // Various command line options. These four add directories to each chain. |
| 694 | static llvm::cl::list<std::string> |
| 695 | F_dirs("F", llvm::cl::value_desc("directory"), llvm::cl::Prefix, |
| 696 | llvm::cl::desc("Add directory to framework include search path")); |
| 697 | |
| 698 | static llvm::cl::list<std::string> |
| 699 | I_dirs("I", llvm::cl::value_desc("directory"), llvm::cl::Prefix, |
| 700 | llvm::cl::desc("Add directory to include search path")); |
| 701 | |
| 702 | static llvm::cl::list<std::string> |
| 703 | idirafter_dirs("idirafter", llvm::cl::value_desc("directory"), llvm::cl::Prefix, |
| 704 | llvm::cl::desc("Add directory to AFTER include search path")); |
| 705 | |
| 706 | static llvm::cl::list<std::string> |
| 707 | iquote_dirs("iquote", llvm::cl::value_desc("directory"), llvm::cl::Prefix, |
| 708 | llvm::cl::desc("Add directory to QUOTE include search path")); |
| 709 | |
| 710 | static llvm::cl::list<std::string> |
| 711 | isystem_dirs("isystem", llvm::cl::value_desc("directory"), llvm::cl::Prefix, |
| 712 | llvm::cl::desc("Add directory to SYSTEM include search path")); |
| 713 | |
| 714 | // These handle -iprefix/-iwithprefix/-iwithprefixbefore. |
| 715 | static llvm::cl::list<std::string> |
| 716 | iprefix_vals("iprefix", llvm::cl::value_desc("prefix"), llvm::cl::Prefix, |
| 717 | llvm::cl::desc("Set the -iwithprefix/-iwithprefixbefore prefix")); |
| 718 | static llvm::cl::list<std::string> |
| 719 | iwithprefix_vals("iwithprefix", llvm::cl::value_desc("dir"), llvm::cl::Prefix, |
| 720 | llvm::cl::desc("Set directory to SYSTEM include search path with prefix")); |
| 721 | static llvm::cl::list<std::string> |
| 722 | iwithprefixbefore_vals("iwithprefixbefore", llvm::cl::value_desc("dir"), |
| 723 | llvm::cl::Prefix, |
| 724 | llvm::cl::desc("Set directory to include search path with prefix")); |
| 725 | |
| 726 | static llvm::cl::opt<std::string> |
| 727 | isysroot("isysroot", llvm::cl::value_desc("dir"), llvm::cl::init("/"), |
| 728 | llvm::cl::desc("Set the system root directory (usually /)")); |
| 729 | |
Daniel Dunbar | 1417c74 | 2009-11-12 23:52:46 +0000 | [diff] [blame] | 730 | static llvm::cl::opt<bool> |
| 731 | Verbose("v", llvm::cl::desc("Enable verbose output")); |
| 732 | |
Daniel Dunbar | f797329 | 2009-11-11 08:13:32 +0000 | [diff] [blame] | 733 | } |
| 734 | |
| 735 | //===----------------------------------------------------------------------===// |
Daniel Dunbar | 29cf746 | 2009-11-11 10:07:44 +0000 | [diff] [blame] | 736 | // Preprocessed Output Options |
| 737 | //===----------------------------------------------------------------------===// |
| 738 | |
| 739 | namespace preprocessoroutputoptions { |
| 740 | |
| 741 | static llvm::cl::opt<bool> |
| 742 | DisableLineMarkers("P", llvm::cl::desc("Disable linemarker output in -E mode")); |
| 743 | |
| 744 | static llvm::cl::opt<bool> |
| 745 | EnableCommentOutput("C", llvm::cl::desc("Enable comment output in -E mode")); |
| 746 | |
| 747 | static llvm::cl::opt<bool> |
| 748 | EnableMacroCommentOutput("CC", |
| 749 | llvm::cl::desc("Enable comment output in -E mode, " |
| 750 | "even from macro expansions")); |
| 751 | static llvm::cl::opt<bool> |
| 752 | DumpMacros("dM", llvm::cl::desc("Print macro definitions in -E mode instead of" |
| 753 | " normal output")); |
| 754 | static llvm::cl::opt<bool> |
| 755 | DumpDefines("dD", llvm::cl::desc("Print macro definitions in -E mode in " |
| 756 | "addition to normal output")); |
| 757 | |
| 758 | } |
Daniel Dunbar | d58c03f | 2009-11-15 06:48:46 +0000 | [diff] [blame] | 759 | //===----------------------------------------------------------------------===// |
| 760 | // Target Options |
| 761 | //===----------------------------------------------------------------------===// |
| 762 | |
| 763 | namespace targetoptions { |
| 764 | |
| 765 | static llvm::cl::opt<std::string> |
| 766 | TargetABI("target-abi", |
| 767 | llvm::cl::desc("Target a particular ABI type")); |
| 768 | |
| 769 | static llvm::cl::opt<std::string> |
| 770 | TargetCPU("mcpu", |
| 771 | llvm::cl::desc("Target a specific cpu type (-mcpu=help for details)")); |
| 772 | |
| 773 | static llvm::cl::list<std::string> |
| 774 | TargetFeatures("target-feature", llvm::cl::desc("Target specific attributes")); |
| 775 | |
| 776 | static llvm::cl::opt<std::string> |
| 777 | TargetTriple("triple", |
| 778 | llvm::cl::desc("Specify target triple (e.g. i686-apple-darwin9)")); |
| 779 | |
| 780 | } |
Daniel Dunbar | 29cf746 | 2009-11-11 10:07:44 +0000 | [diff] [blame] | 781 | |
| 782 | //===----------------------------------------------------------------------===// |
Daniel Dunbar | 0498cfc | 2009-11-10 19:51:53 +0000 | [diff] [blame] | 783 | // Option Object Construction |
| 784 | //===----------------------------------------------------------------------===// |
| 785 | |
Daniel Dunbar | 223ebe3 | 2009-11-17 05:05:08 +0000 | [diff] [blame] | 786 | void clang::InitializeAnalyzerOptions(AnalyzerOptions &Opts) { |
| 787 | using namespace analyzeroptions; |
| 788 | Opts.AnalysisList = AnalysisList; |
| 789 | Opts.AnalysisStoreOpt = AnalysisStoreOpt; |
| 790 | Opts.AnalysisConstraintsOpt = AnalysisConstraintsOpt; |
| 791 | Opts.AnalysisDiagOpt = AnalysisDiagOpt; |
| 792 | Opts.VisualizeEGDot = VisualizeEGDot; |
| 793 | Opts.VisualizeEGUbi = VisualizeEGUbi; |
| 794 | Opts.AnalyzeAll = AnalyzeAll; |
| 795 | Opts.AnalyzerDisplayProgress = AnalyzerDisplayProgress; |
| 796 | Opts.PurgeDead = PurgeDead; |
| 797 | Opts.EagerlyAssume = EagerlyAssume; |
| 798 | Opts.AnalyzeSpecificFunction = AnalyzeSpecificFunction; |
| 799 | Opts.EnableExperimentalChecks = AnalyzerExperimentalChecks; |
| 800 | Opts.EnableExperimentalInternalChecks = AnalyzerExperimentalInternalChecks; |
| 801 | Opts.TrimGraph = TrimGraph; |
| 802 | } |
| 803 | |
Daniel Dunbar | 6143ea2 | 2009-11-16 22:38:14 +0000 | [diff] [blame] | 804 | void clang::InitializeCodeGenOptions(CodeGenOptions &Opts, |
| 805 | const LangOptions &Lang, |
| 806 | bool TimePasses) { |
Daniel Dunbar | 0498cfc | 2009-11-10 19:51:53 +0000 | [diff] [blame] | 807 | using namespace codegenoptions; |
Daniel Dunbar | 0498cfc | 2009-11-10 19:51:53 +0000 | [diff] [blame] | 808 | |
Daniel Dunbar | 0498cfc | 2009-11-10 19:51:53 +0000 | [diff] [blame] | 809 | // -Os implies -O2 |
| 810 | Opts.OptimizationLevel = OptSize ? 2 : OptLevel; |
| 811 | |
| 812 | // We must always run at least the always inlining pass. |
Chandler Carruth | 2811ccf | 2009-11-12 17:24:48 +0000 | [diff] [blame] | 813 | Opts.Inlining = (Opts.OptimizationLevel > 1) ? CodeGenOptions::NormalInlining |
| 814 | : CodeGenOptions::OnlyAlwaysInlining; |
Daniel Dunbar | 0498cfc | 2009-11-10 19:51:53 +0000 | [diff] [blame] | 815 | |
Daniel Dunbar | 29a790b | 2009-11-11 09:38:56 +0000 | [diff] [blame] | 816 | Opts.DebugInfo = GenerateDebugInfo; |
| 817 | Opts.DisableLLVMOpts = DisableLLVMOptimizations; |
| 818 | Opts.DisableRedZone = DisableRedZone; |
| 819 | Opts.MergeAllConstants = !NoMergeConstants; |
| 820 | Opts.NoCommon = NoCommon; |
| 821 | Opts.NoImplicitFloat = NoImplicitFloat; |
| 822 | Opts.OptimizeSize = OptSize; |
Daniel Dunbar | 0498cfc | 2009-11-10 19:51:53 +0000 | [diff] [blame] | 823 | Opts.SimplifyLibCalls = 1; |
Daniel Dunbar | 29a790b | 2009-11-11 09:38:56 +0000 | [diff] [blame] | 824 | Opts.UnrollLoops = (Opts.OptimizationLevel > 1 && !OptSize); |
Daniel Dunbar | 0498cfc | 2009-11-10 19:51:53 +0000 | [diff] [blame] | 825 | |
Daniel Dunbar | 6143ea2 | 2009-11-16 22:38:14 +0000 | [diff] [blame] | 826 | // FIXME: Eliminate this dependency? |
| 827 | if (Lang.NoBuiltin) |
| 828 | Opts.SimplifyLibCalls = 0; |
| 829 | if (Lang.CPlusPlus) |
| 830 | Opts.NoCommon = 1; |
| 831 | Opts.TimePasses = TimePasses; |
| 832 | |
Daniel Dunbar | 0498cfc | 2009-11-10 19:51:53 +0000 | [diff] [blame] | 833 | #ifdef NDEBUG |
| 834 | Opts.VerifyModule = 0; |
| 835 | #endif |
Daniel Dunbar | 0498cfc | 2009-11-10 19:51:53 +0000 | [diff] [blame] | 836 | } |
Daniel Dunbar | b52d243 | 2009-11-11 06:10:03 +0000 | [diff] [blame] | 837 | |
Daniel Dunbar | 0e0bae8 | 2009-11-11 21:43:12 +0000 | [diff] [blame] | 838 | void clang::InitializeDependencyOutputOptions(DependencyOutputOptions &Opts) { |
| 839 | using namespace dependencyoutputoptions; |
| 840 | |
| 841 | Opts.OutputFile = DependencyFile; |
Daniel Dunbar | 2626688 | 2009-11-12 23:52:32 +0000 | [diff] [blame] | 842 | Opts.Targets = DependencyTargets; |
Daniel Dunbar | 0e0bae8 | 2009-11-11 21:43:12 +0000 | [diff] [blame] | 843 | Opts.IncludeSystemHeaders = DependenciesIncludeSystemHeaders; |
| 844 | Opts.UsePhonyTargets = PhonyDependencyTarget; |
| 845 | } |
| 846 | |
Daniel Dunbar | 0db4b76 | 2009-11-11 08:13:40 +0000 | [diff] [blame] | 847 | void clang::InitializeDiagnosticOptions(DiagnosticOptions &Opts) { |
| 848 | using namespace diagnosticoptions; |
| 849 | |
Daniel Dunbar | 2626688 | 2009-11-12 23:52:32 +0000 | [diff] [blame] | 850 | Opts.Warnings = OptWarnings; |
Daniel Dunbar | 11e729d | 2009-11-12 07:28:21 +0000 | [diff] [blame] | 851 | Opts.DumpBuildInformation = DumpBuildInformation; |
Daniel Dunbar | 6907943 | 2009-11-12 07:28:44 +0000 | [diff] [blame] | 852 | Opts.IgnoreWarnings = OptNoWarnings; |
Daniel Dunbar | 0db4b76 | 2009-11-11 08:13:40 +0000 | [diff] [blame] | 853 | Opts.MessageLength = MessageLength; |
Daniel Dunbar | 6907943 | 2009-11-12 07:28:44 +0000 | [diff] [blame] | 854 | Opts.NoRewriteMacros = SilenceRewriteMacroWarning; |
| 855 | Opts.Pedantic = OptPedantic; |
| 856 | Opts.PedanticErrors = OptPedanticErrors; |
Daniel Dunbar | 11e729d | 2009-11-12 07:28:21 +0000 | [diff] [blame] | 857 | Opts.ShowCarets = !NoCaretDiagnostics; |
| 858 | Opts.ShowColors = PrintColorDiagnostic; |
| 859 | Opts.ShowColumn = !NoShowColumn; |
| 860 | Opts.ShowFixits = !NoDiagnosticsFixIt; |
| 861 | Opts.ShowLocation = !NoShowLocation; |
| 862 | Opts.ShowOptionNames = PrintDiagnosticOption; |
| 863 | Opts.ShowSourceRanges = PrintSourceRangeInfo; |
Daniel Dunbar | 2626688 | 2009-11-12 23:52:32 +0000 | [diff] [blame] | 864 | Opts.VerifyDiagnostics = VerifyDiagnostics; |
| 865 | } |
| 866 | |
| 867 | void clang::InitializeFrontendOptions(FrontendOptions &Opts) { |
| 868 | using namespace frontendoptions; |
| 869 | |
Daniel Dunbar | d10c5b8 | 2009-11-15 00:12:04 +0000 | [diff] [blame] | 870 | // Select program action. |
| 871 | Opts.ProgramAction = ProgAction; |
| 872 | if (PluginActionName.getPosition()) { |
| 873 | Opts.ProgramAction = frontend::PluginAction; |
| 874 | Opts.ActionName = PluginActionName; |
| 875 | } |
| 876 | |
Daniel Dunbar | 914474c | 2009-11-13 01:02:10 +0000 | [diff] [blame] | 877 | Opts.CodeCompletionAt = CodeCompletionAt; |
| 878 | Opts.DebugCodeCompletionPrinter = CodeCompletionDebugPrinter; |
Daniel Dunbar | 2626688 | 2009-11-12 23:52:32 +0000 | [diff] [blame] | 879 | Opts.DisableFree = DisableFree; |
| 880 | Opts.EmptyInputOnly = EmptyInputOnly; |
Daniel Dunbar | c86804b | 2009-11-12 23:52:56 +0000 | [diff] [blame] | 881 | Opts.FixItLocations = FixItAtLocations; |
Daniel Dunbar | 2626688 | 2009-11-12 23:52:32 +0000 | [diff] [blame] | 882 | Opts.OutputFile = OutputFile; |
Daniel Dunbar | 914474c | 2009-11-13 01:02:10 +0000 | [diff] [blame] | 883 | Opts.RelocatablePCH = RelocatablePCH; |
| 884 | Opts.ShowMacrosInCodeCompletion = CodeCompletionWantsMacros; |
| 885 | Opts.ShowStats = Stats; |
| 886 | Opts.ShowTimers = TimeReport; |
Daniel Dunbar | 2626688 | 2009-11-12 23:52:32 +0000 | [diff] [blame] | 887 | Opts.ViewClassInheritance = InheritanceViewCls; |
| 888 | |
| 889 | // '-' is the default input if none is given. |
Daniel Dunbar | fbe2faf | 2009-11-13 02:06:12 +0000 | [diff] [blame] | 890 | if (InputFilenames.empty()) { |
| 891 | FrontendOptions::InputKind IK = InputType; |
| 892 | if (IK == FrontendOptions::IK_None) IK = FrontendOptions::IK_C; |
| 893 | Opts.Inputs.push_back(std::make_pair(IK, "-")); |
| 894 | } else { |
| 895 | for (unsigned i = 0, e = InputFilenames.size(); i != e; ++i) { |
| 896 | FrontendOptions::InputKind IK = InputType; |
| 897 | llvm::StringRef Ext = |
| 898 | llvm::StringRef(InputFilenames[i]).rsplit('.').second; |
| 899 | if (IK == FrontendOptions::IK_None) |
| 900 | IK = FrontendOptions::getInputKindForExtension(Ext); |
| 901 | Opts.Inputs.push_back(std::make_pair(IK, InputFilenames[i])); |
Daniel Dunbar | fbe2faf | 2009-11-13 02:06:12 +0000 | [diff] [blame] | 902 | } |
| 903 | } |
Daniel Dunbar | 0db4b76 | 2009-11-11 08:13:40 +0000 | [diff] [blame] | 904 | } |
| 905 | |
Daniel Dunbar | f797329 | 2009-11-11 08:13:32 +0000 | [diff] [blame] | 906 | void clang::InitializeHeaderSearchOptions(HeaderSearchOptions &Opts, |
Daniel Dunbar | c363cb1 | 2009-11-16 22:38:40 +0000 | [diff] [blame] | 907 | llvm::StringRef BuiltinIncludePath) { |
Daniel Dunbar | f797329 | 2009-11-11 08:13:32 +0000 | [diff] [blame] | 908 | using namespace headersearchoptions; |
| 909 | |
| 910 | Opts.Sysroot = isysroot; |
| 911 | Opts.Verbose = Verbose; |
| 912 | |
| 913 | // Handle -I... and -F... options, walking the lists in parallel. |
| 914 | unsigned Iidx = 0, Fidx = 0; |
| 915 | while (Iidx < I_dirs.size() && Fidx < F_dirs.size()) { |
| 916 | if (I_dirs.getPosition(Iidx) < F_dirs.getPosition(Fidx)) { |
Daniel Dunbar | 1b483e7 | 2009-11-17 05:04:15 +0000 | [diff] [blame] | 917 | Opts.AddPath(I_dirs[Iidx], frontend::Angled, true, false); |
Daniel Dunbar | f797329 | 2009-11-11 08:13:32 +0000 | [diff] [blame] | 918 | ++Iidx; |
| 919 | } else { |
Daniel Dunbar | 1b483e7 | 2009-11-17 05:04:15 +0000 | [diff] [blame] | 920 | Opts.AddPath(F_dirs[Fidx], frontend::Angled, true, true); |
Daniel Dunbar | f797329 | 2009-11-11 08:13:32 +0000 | [diff] [blame] | 921 | ++Fidx; |
| 922 | } |
| 923 | } |
| 924 | |
| 925 | // Consume what's left from whatever list was longer. |
| 926 | for (; Iidx != I_dirs.size(); ++Iidx) |
Daniel Dunbar | 1b483e7 | 2009-11-17 05:04:15 +0000 | [diff] [blame] | 927 | Opts.AddPath(I_dirs[Iidx], frontend::Angled, true, false); |
Daniel Dunbar | f797329 | 2009-11-11 08:13:32 +0000 | [diff] [blame] | 928 | for (; Fidx != F_dirs.size(); ++Fidx) |
Daniel Dunbar | 1b483e7 | 2009-11-17 05:04:15 +0000 | [diff] [blame] | 929 | Opts.AddPath(F_dirs[Fidx], frontend::Angled, true, true); |
Daniel Dunbar | f797329 | 2009-11-11 08:13:32 +0000 | [diff] [blame] | 930 | |
| 931 | // Handle -idirafter... options. |
| 932 | for (unsigned i = 0, e = idirafter_dirs.size(); i != e; ++i) |
Daniel Dunbar | 1b483e7 | 2009-11-17 05:04:15 +0000 | [diff] [blame] | 933 | Opts.AddPath(idirafter_dirs[i], frontend::After, true, false); |
Daniel Dunbar | f797329 | 2009-11-11 08:13:32 +0000 | [diff] [blame] | 934 | |
| 935 | // Handle -iquote... options. |
| 936 | for (unsigned i = 0, e = iquote_dirs.size(); i != e; ++i) |
Daniel Dunbar | 1b483e7 | 2009-11-17 05:04:15 +0000 | [diff] [blame] | 937 | Opts.AddPath(iquote_dirs[i], frontend::Quoted, true, false); |
Daniel Dunbar | f797329 | 2009-11-11 08:13:32 +0000 | [diff] [blame] | 938 | |
| 939 | // Handle -isystem... options. |
| 940 | for (unsigned i = 0, e = isystem_dirs.size(); i != e; ++i) |
Daniel Dunbar | 1b483e7 | 2009-11-17 05:04:15 +0000 | [diff] [blame] | 941 | Opts.AddPath(isystem_dirs[i], frontend::System, true, false); |
Daniel Dunbar | f797329 | 2009-11-11 08:13:32 +0000 | [diff] [blame] | 942 | |
| 943 | // Walk the -iprefix/-iwithprefix/-iwithprefixbefore argument lists in |
| 944 | // parallel, processing the values in order of occurance to get the right |
| 945 | // prefixes. |
| 946 | { |
| 947 | std::string Prefix = ""; // FIXME: this isn't the correct default prefix. |
| 948 | unsigned iprefix_idx = 0; |
| 949 | unsigned iwithprefix_idx = 0; |
| 950 | unsigned iwithprefixbefore_idx = 0; |
| 951 | bool iprefix_done = iprefix_vals.empty(); |
| 952 | bool iwithprefix_done = iwithprefix_vals.empty(); |
| 953 | bool iwithprefixbefore_done = iwithprefixbefore_vals.empty(); |
| 954 | while (!iprefix_done || !iwithprefix_done || !iwithprefixbefore_done) { |
| 955 | if (!iprefix_done && |
| 956 | (iwithprefix_done || |
| 957 | iprefix_vals.getPosition(iprefix_idx) < |
| 958 | iwithprefix_vals.getPosition(iwithprefix_idx)) && |
| 959 | (iwithprefixbefore_done || |
| 960 | iprefix_vals.getPosition(iprefix_idx) < |
| 961 | iwithprefixbefore_vals.getPosition(iwithprefixbefore_idx))) { |
| 962 | Prefix = iprefix_vals[iprefix_idx]; |
| 963 | ++iprefix_idx; |
| 964 | iprefix_done = iprefix_idx == iprefix_vals.size(); |
| 965 | } else if (!iwithprefix_done && |
| 966 | (iwithprefixbefore_done || |
| 967 | iwithprefix_vals.getPosition(iwithprefix_idx) < |
| 968 | iwithprefixbefore_vals.getPosition(iwithprefixbefore_idx))) { |
| 969 | Opts.AddPath(Prefix+iwithprefix_vals[iwithprefix_idx], |
Daniel Dunbar | 1b483e7 | 2009-11-17 05:04:15 +0000 | [diff] [blame] | 970 | frontend::System, false, false); |
Daniel Dunbar | f797329 | 2009-11-11 08:13:32 +0000 | [diff] [blame] | 971 | ++iwithprefix_idx; |
| 972 | iwithprefix_done = iwithprefix_idx == iwithprefix_vals.size(); |
| 973 | } else { |
| 974 | Opts.AddPath(Prefix+iwithprefixbefore_vals[iwithprefixbefore_idx], |
Daniel Dunbar | 1b483e7 | 2009-11-17 05:04:15 +0000 | [diff] [blame] | 975 | frontend::Angled, false, false); |
Daniel Dunbar | f797329 | 2009-11-11 08:13:32 +0000 | [diff] [blame] | 976 | ++iwithprefixbefore_idx; |
| 977 | iwithprefixbefore_done = |
| 978 | iwithprefixbefore_idx == iwithprefixbefore_vals.size(); |
| 979 | } |
| 980 | } |
| 981 | } |
| 982 | |
| 983 | // Add CPATH environment paths. |
| 984 | if (const char *Env = getenv("CPATH")) |
| 985 | Opts.EnvIncPath = Env; |
| 986 | |
| 987 | // Add language specific environment paths. |
Daniel Dunbar | c363cb1 | 2009-11-16 22:38:40 +0000 | [diff] [blame] | 988 | if (const char *Env = getenv("OBJCPLUS_INCLUDE_PATH")) |
| 989 | Opts.ObjCXXEnvIncPath = Env; |
| 990 | if (const char *Env = getenv("CPLUS_INCLUDE_PATH")) |
| 991 | Opts.CXXEnvIncPath = Env; |
| 992 | if (const char *Env = getenv("OBJC_INCLUDE_PATH")) |
| 993 | Opts.CEnvIncPath = Env; |
| 994 | if (const char *Env = getenv("C_INCLUDE_PATH")) |
| 995 | Opts.CEnvIncPath = Env; |
Daniel Dunbar | f797329 | 2009-11-11 08:13:32 +0000 | [diff] [blame] | 996 | |
| 997 | if (!nobuiltininc) |
| 998 | Opts.BuiltinIncludePath = BuiltinIncludePath; |
| 999 | |
| 1000 | Opts.UseStandardIncludes = !nostdinc; |
| 1001 | } |
| 1002 | |
Daniel Dunbar | b52d243 | 2009-11-11 06:10:03 +0000 | [diff] [blame] | 1003 | void clang::InitializePreprocessorOptions(PreprocessorOptions &Opts) { |
| 1004 | using namespace preprocessoroptions; |
| 1005 | |
Daniel Dunbar | 049d3a0 | 2009-11-17 05:52:41 +0000 | [diff] [blame] | 1006 | Opts.ImplicitPCHInclude = ImplicitIncludePCH; |
| 1007 | Opts.ImplicitPTHInclude = ImplicitIncludePTH; |
Daniel Dunbar | b52d243 | 2009-11-11 06:10:03 +0000 | [diff] [blame] | 1008 | |
Daniel Dunbar | b3cb98e | 2009-11-12 02:53:59 +0000 | [diff] [blame] | 1009 | // Select the token cache file, we don't support more than one currently so we |
| 1010 | // can't have both an implicit-pth and a token cache file. |
| 1011 | if (TokenCache.getPosition() && ImplicitIncludePTH.getPosition()) { |
| 1012 | // FIXME: Don't fail like this. |
| 1013 | fprintf(stderr, "error: cannot use both -token-cache and -include-pth " |
| 1014 | "options\n"); |
| 1015 | exit(1); |
| 1016 | } |
| 1017 | if (TokenCache.getPosition()) |
Daniel Dunbar | 049d3a0 | 2009-11-17 05:52:41 +0000 | [diff] [blame] | 1018 | Opts.TokenCache = TokenCache; |
Daniel Dunbar | b3cb98e | 2009-11-12 02:53:59 +0000 | [diff] [blame] | 1019 | else |
Daniel Dunbar | 049d3a0 | 2009-11-17 05:52:41 +0000 | [diff] [blame] | 1020 | Opts.TokenCache = ImplicitIncludePTH; |
Daniel Dunbar | b3cb98e | 2009-11-12 02:53:59 +0000 | [diff] [blame] | 1021 | |
Daniel Dunbar | b52d243 | 2009-11-11 06:10:03 +0000 | [diff] [blame] | 1022 | // Use predefines? |
Daniel Dunbar | 049d3a0 | 2009-11-17 05:52:41 +0000 | [diff] [blame] | 1023 | Opts.UsePredefines = !UndefMacros; |
Daniel Dunbar | b52d243 | 2009-11-11 06:10:03 +0000 | [diff] [blame] | 1024 | |
| 1025 | // Add macros from the command line. |
| 1026 | unsigned d = 0, D = D_macros.size(); |
| 1027 | unsigned u = 0, U = U_macros.size(); |
| 1028 | while (d < D || u < U) { |
| 1029 | if (u == U || (d < D && D_macros.getPosition(d) < U_macros.getPosition(u))) |
| 1030 | Opts.addMacroDef(D_macros[d++]); |
| 1031 | else |
| 1032 | Opts.addMacroUndef(U_macros[u++]); |
| 1033 | } |
| 1034 | |
| 1035 | // If -imacros are specified, include them now. These are processed before |
| 1036 | // any -include directives. |
| 1037 | for (unsigned i = 0, e = ImplicitMacroIncludes.size(); i != e; ++i) |
Daniel Dunbar | 049d3a0 | 2009-11-17 05:52:41 +0000 | [diff] [blame] | 1038 | Opts.MacroIncludes.push_back(ImplicitMacroIncludes[i]); |
Daniel Dunbar | b52d243 | 2009-11-11 06:10:03 +0000 | [diff] [blame] | 1039 | |
| 1040 | // Add the ordered list of -includes, sorting in the implicit include options |
| 1041 | // at the appropriate location. |
| 1042 | llvm::SmallVector<std::pair<unsigned, std::string*>, 8> OrderedPaths; |
| 1043 | std::string OriginalFile; |
| 1044 | |
| 1045 | if (!ImplicitIncludePTH.empty()) |
| 1046 | OrderedPaths.push_back(std::make_pair(ImplicitIncludePTH.getPosition(), |
| 1047 | &ImplicitIncludePTH)); |
| 1048 | if (!ImplicitIncludePCH.empty()) { |
| 1049 | OriginalFile = PCHReader::getOriginalSourceFile(ImplicitIncludePCH); |
| 1050 | // FIXME: Don't fail like this. |
| 1051 | if (OriginalFile.empty()) |
| 1052 | exit(1); |
| 1053 | OrderedPaths.push_back(std::make_pair(ImplicitIncludePCH.getPosition(), |
| 1054 | &OriginalFile)); |
| 1055 | } |
| 1056 | for (unsigned i = 0, e = ImplicitIncludes.size(); i != e; ++i) |
| 1057 | OrderedPaths.push_back(std::make_pair(ImplicitIncludes.getPosition(i), |
| 1058 | &ImplicitIncludes[i])); |
| 1059 | llvm::array_pod_sort(OrderedPaths.begin(), OrderedPaths.end()); |
| 1060 | |
| 1061 | for (unsigned i = 0, e = OrderedPaths.size(); i != e; ++i) |
Daniel Dunbar | 049d3a0 | 2009-11-17 05:52:41 +0000 | [diff] [blame] | 1062 | Opts.Includes.push_back(*OrderedPaths[i].second); |
Daniel Dunbar | b52d243 | 2009-11-11 06:10:03 +0000 | [diff] [blame] | 1063 | } |
Daniel Dunbar | 5674908 | 2009-11-11 07:26:12 +0000 | [diff] [blame] | 1064 | |
Daniel Dunbar | fbe2faf | 2009-11-13 02:06:12 +0000 | [diff] [blame] | 1065 | void clang::InitializeLangOptions(LangOptions &Options, |
| 1066 | FrontendOptions::InputKind IK, |
Daniel Dunbar | 6143ea2 | 2009-11-16 22:38:14 +0000 | [diff] [blame] | 1067 | TargetInfo &Target) { |
Daniel Dunbar | 5674908 | 2009-11-11 07:26:12 +0000 | [diff] [blame] | 1068 | using namespace langoptions; |
| 1069 | |
Daniel Dunbar | 5674908 | 2009-11-11 07:26:12 +0000 | [diff] [blame] | 1070 | |
Daniel Dunbar | fbe2faf | 2009-11-13 02:06:12 +0000 | [diff] [blame] | 1071 | switch (IK) { |
| 1072 | case FrontendOptions::IK_None: |
| 1073 | case FrontendOptions::IK_AST: |
| 1074 | assert(0 && "Invalid input kind!"); |
| 1075 | case FrontendOptions::IK_Asm: |
Daniel Dunbar | 5674908 | 2009-11-11 07:26:12 +0000 | [diff] [blame] | 1076 | Options.AsmPreprocessor = 1; |
| 1077 | // FALLTHROUGH |
Daniel Dunbar | fbe2faf | 2009-11-13 02:06:12 +0000 | [diff] [blame] | 1078 | case FrontendOptions::IK_PreprocessedC: |
Daniel Dunbar | 5674908 | 2009-11-11 07:26:12 +0000 | [diff] [blame] | 1079 | // FALLTHROUGH |
Daniel Dunbar | fbe2faf | 2009-11-13 02:06:12 +0000 | [diff] [blame] | 1080 | case FrontendOptions::IK_C: |
Daniel Dunbar | 5674908 | 2009-11-11 07:26:12 +0000 | [diff] [blame] | 1081 | // Do nothing. |
| 1082 | break; |
Daniel Dunbar | fbe2faf | 2009-11-13 02:06:12 +0000 | [diff] [blame] | 1083 | case FrontendOptions::IK_PreprocessedCXX: |
Daniel Dunbar | 5674908 | 2009-11-11 07:26:12 +0000 | [diff] [blame] | 1084 | // FALLTHROUGH |
Daniel Dunbar | fbe2faf | 2009-11-13 02:06:12 +0000 | [diff] [blame] | 1085 | case FrontendOptions::IK_CXX: |
Daniel Dunbar | 5674908 | 2009-11-11 07:26:12 +0000 | [diff] [blame] | 1086 | Options.CPlusPlus = 1; |
| 1087 | break; |
Daniel Dunbar | fbe2faf | 2009-11-13 02:06:12 +0000 | [diff] [blame] | 1088 | case FrontendOptions::IK_PreprocessedObjC: |
Daniel Dunbar | 5674908 | 2009-11-11 07:26:12 +0000 | [diff] [blame] | 1089 | // FALLTHROUGH |
Daniel Dunbar | fbe2faf | 2009-11-13 02:06:12 +0000 | [diff] [blame] | 1090 | case FrontendOptions::IK_ObjC: |
Daniel Dunbar | 5674908 | 2009-11-11 07:26:12 +0000 | [diff] [blame] | 1091 | Options.ObjC1 = Options.ObjC2 = 1; |
| 1092 | break; |
Daniel Dunbar | fbe2faf | 2009-11-13 02:06:12 +0000 | [diff] [blame] | 1093 | case FrontendOptions::IK_PreprocessedObjCXX: |
Daniel Dunbar | 5674908 | 2009-11-11 07:26:12 +0000 | [diff] [blame] | 1094 | // FALLTHROUGH |
Daniel Dunbar | fbe2faf | 2009-11-13 02:06:12 +0000 | [diff] [blame] | 1095 | case FrontendOptions::IK_ObjCXX: |
Daniel Dunbar | 5674908 | 2009-11-11 07:26:12 +0000 | [diff] [blame] | 1096 | Options.ObjC1 = Options.ObjC2 = 1; |
| 1097 | Options.CPlusPlus = 1; |
| 1098 | break; |
Daniel Dunbar | fbe2faf | 2009-11-13 02:06:12 +0000 | [diff] [blame] | 1099 | case FrontendOptions::IK_OpenCL: |
Daniel Dunbar | 5674908 | 2009-11-11 07:26:12 +0000 | [diff] [blame] | 1100 | Options.OpenCL = 1; |
| 1101 | Options.AltiVec = 1; |
| 1102 | Options.CXXOperatorNames = 1; |
| 1103 | Options.LaxVectorConversions = 1; |
| 1104 | break; |
| 1105 | } |
| 1106 | |
| 1107 | if (ObjCExclusiveGC) |
| 1108 | Options.setGCMode(LangOptions::GCOnly); |
| 1109 | else if (ObjCEnableGC) |
| 1110 | Options.setGCMode(LangOptions::HybridGC); |
| 1111 | |
| 1112 | if (ObjCEnableGCBitmapPrint) |
| 1113 | Options.ObjCGCBitmapPrint = 1; |
| 1114 | |
| 1115 | if (AltiVec) |
| 1116 | Options.AltiVec = 1; |
| 1117 | |
| 1118 | if (PThread) |
| 1119 | Options.POSIXThreads = 1; |
| 1120 | |
| 1121 | Options.setVisibilityMode(SymbolVisibility); |
| 1122 | Options.OverflowChecking = OverflowChecking; |
| 1123 | |
Daniel Dunbar | 5674908 | 2009-11-11 07:26:12 +0000 | [diff] [blame] | 1124 | if (LangStd == lang_unspecified) { |
| 1125 | // Based on the base language, pick one. |
Daniel Dunbar | fbe2faf | 2009-11-13 02:06:12 +0000 | [diff] [blame] | 1126 | switch (IK) { |
| 1127 | case FrontendOptions::IK_None: |
| 1128 | case FrontendOptions::IK_AST: |
| 1129 | assert(0 && "Invalid input kind!"); |
| 1130 | case FrontendOptions::IK_OpenCL: |
Daniel Dunbar | 5674908 | 2009-11-11 07:26:12 +0000 | [diff] [blame] | 1131 | LangStd = lang_c99; |
| 1132 | break; |
Daniel Dunbar | fbe2faf | 2009-11-13 02:06:12 +0000 | [diff] [blame] | 1133 | case FrontendOptions::IK_Asm: |
| 1134 | case FrontendOptions::IK_C: |
| 1135 | case FrontendOptions::IK_PreprocessedC: |
| 1136 | case FrontendOptions::IK_ObjC: |
| 1137 | case FrontendOptions::IK_PreprocessedObjC: |
Daniel Dunbar | 5674908 | 2009-11-11 07:26:12 +0000 | [diff] [blame] | 1138 | LangStd = lang_gnu99; |
| 1139 | break; |
Daniel Dunbar | fbe2faf | 2009-11-13 02:06:12 +0000 | [diff] [blame] | 1140 | case FrontendOptions::IK_CXX: |
| 1141 | case FrontendOptions::IK_PreprocessedCXX: |
| 1142 | case FrontendOptions::IK_ObjCXX: |
| 1143 | case FrontendOptions::IK_PreprocessedObjCXX: |
Daniel Dunbar | 5674908 | 2009-11-11 07:26:12 +0000 | [diff] [blame] | 1144 | LangStd = lang_gnucxx98; |
| 1145 | break; |
| 1146 | } |
| 1147 | } |
| 1148 | |
| 1149 | switch (LangStd) { |
| 1150 | default: assert(0 && "Unknown language standard!"); |
| 1151 | |
| 1152 | // Fall through from newer standards to older ones. This isn't really right. |
| 1153 | // FIXME: Enable specifically the right features based on the language stds. |
| 1154 | case lang_gnucxx0x: |
| 1155 | case lang_cxx0x: |
| 1156 | Options.CPlusPlus0x = 1; |
| 1157 | // FALL THROUGH |
| 1158 | case lang_gnucxx98: |
| 1159 | case lang_cxx98: |
| 1160 | Options.CPlusPlus = 1; |
| 1161 | Options.CXXOperatorNames = !NoOperatorNames; |
| 1162 | // FALL THROUGH. |
| 1163 | case lang_gnu99: |
| 1164 | case lang_c99: |
| 1165 | Options.C99 = 1; |
| 1166 | Options.HexFloats = 1; |
| 1167 | // FALL THROUGH. |
| 1168 | case lang_gnu89: |
| 1169 | Options.BCPLComment = 1; // Only for C99/C++. |
| 1170 | // FALL THROUGH. |
| 1171 | case lang_c94: |
| 1172 | Options.Digraphs = 1; // C94, C99, C++. |
| 1173 | // FALL THROUGH. |
| 1174 | case lang_c89: |
| 1175 | break; |
| 1176 | } |
| 1177 | |
| 1178 | // GNUMode - Set if we're in gnu99, gnu89, gnucxx98, etc. |
| 1179 | switch (LangStd) { |
| 1180 | default: assert(0 && "Unknown language standard!"); |
| 1181 | case lang_gnucxx0x: |
| 1182 | case lang_gnucxx98: |
| 1183 | case lang_gnu99: |
| 1184 | case lang_gnu89: |
| 1185 | Options.GNUMode = 1; |
| 1186 | break; |
| 1187 | case lang_cxx0x: |
| 1188 | case lang_cxx98: |
| 1189 | case lang_c99: |
| 1190 | case lang_c94: |
| 1191 | case lang_c89: |
| 1192 | Options.GNUMode = 0; |
| 1193 | break; |
| 1194 | } |
| 1195 | |
| 1196 | if (Options.CPlusPlus) { |
| 1197 | Options.C99 = 0; |
| 1198 | Options.HexFloats = 0; |
| 1199 | } |
| 1200 | |
| 1201 | if (LangStd == lang_c89 || LangStd == lang_c94 || LangStd == lang_gnu89) |
| 1202 | Options.ImplicitInt = 1; |
| 1203 | else |
| 1204 | Options.ImplicitInt = 0; |
| 1205 | |
| 1206 | // Mimicing gcc's behavior, trigraphs are only enabled if -trigraphs |
| 1207 | // is specified, or -std is set to a conforming mode. |
| 1208 | Options.Trigraphs = !Options.GNUMode; |
| 1209 | if (Trigraphs.getPosition()) |
| 1210 | Options.Trigraphs = Trigraphs; // Command line option wins if specified. |
| 1211 | |
| 1212 | // If in a conformant language mode (e.g. -std=c99) Blocks defaults to off |
| 1213 | // even if they are normally on for the target. In GNU modes (e.g. |
| 1214 | // -std=gnu99) the default for blocks depends on the target settings. |
| 1215 | // However, blocks are not turned off when compiling Obj-C or Obj-C++ code. |
| 1216 | if (!Options.ObjC1 && !Options.GNUMode) |
| 1217 | Options.Blocks = 0; |
| 1218 | |
| 1219 | // Default to not accepting '$' in identifiers when preprocessing assembler, |
| 1220 | // but do accept when preprocessing C. FIXME: these defaults are right for |
| 1221 | // darwin, are they right everywhere? |
Daniel Dunbar | fbe2faf | 2009-11-13 02:06:12 +0000 | [diff] [blame] | 1222 | Options.DollarIdents = IK != FrontendOptions::IK_Asm; |
Daniel Dunbar | 5674908 | 2009-11-11 07:26:12 +0000 | [diff] [blame] | 1223 | if (DollarsInIdents.getPosition()) // Explicit setting overrides default. |
| 1224 | Options.DollarIdents = DollarsInIdents; |
| 1225 | |
| 1226 | if (PascalStrings.getPosition()) |
| 1227 | Options.PascalStrings = PascalStrings; |
| 1228 | if (MSExtensions.getPosition()) |
| 1229 | Options.Microsoft = MSExtensions; |
| 1230 | Options.WritableStrings = WritableStrings; |
| 1231 | if (NoLaxVectorConversions.getPosition()) |
| 1232 | Options.LaxVectorConversions = 0; |
| 1233 | Options.Exceptions = Exceptions; |
| 1234 | Options.Rtti = Rtti; |
| 1235 | if (EnableBlocks.getPosition()) |
| 1236 | Options.Blocks = EnableBlocks; |
| 1237 | if (CharIsSigned.getPosition()) |
| 1238 | Options.CharIsSigned = CharIsSigned; |
| 1239 | if (ShortWChar.getPosition()) |
| 1240 | Options.ShortWChar = ShortWChar; |
| 1241 | |
| 1242 | if (!AllowBuiltins) |
| 1243 | Options.NoBuiltin = 1; |
| 1244 | if (Freestanding) |
| 1245 | Options.Freestanding = Options.NoBuiltin = 1; |
| 1246 | |
| 1247 | if (EnableHeinousExtensions) |
| 1248 | Options.HeinousExtensions = 1; |
| 1249 | |
| 1250 | if (AccessControl) |
| 1251 | Options.AccessControl = 1; |
| 1252 | |
| 1253 | Options.ElideConstructors = !NoElideConstructors; |
| 1254 | |
| 1255 | // OpenCL and C++ both have bool, true, false keywords. |
| 1256 | Options.Bool = Options.OpenCL | Options.CPlusPlus; |
| 1257 | |
| 1258 | Options.MathErrno = MathErrno; |
| 1259 | |
| 1260 | Options.InstantiationDepth = TemplateDepth; |
| 1261 | |
| 1262 | // Override the default runtime if the user requested it. |
Daniel Dunbar | c5a97ec | 2009-11-17 07:07:28 +0000 | [diff] [blame] | 1263 | if (GNURuntime) |
Daniel Dunbar | 5674908 | 2009-11-11 07:26:12 +0000 | [diff] [blame] | 1264 | Options.NeXTRuntime = 0; |
| 1265 | |
| 1266 | if (!ObjCConstantStringClass.empty()) |
| 1267 | Options.ObjCConstantStringClass = ObjCConstantStringClass.c_str(); |
| 1268 | |
| 1269 | if (ObjCNonFragileABI) |
| 1270 | Options.ObjCNonFragileABI = 1; |
| 1271 | |
| 1272 | if (EmitAllDecls) |
| 1273 | Options.EmitAllDecls = 1; |
| 1274 | |
| 1275 | // The __OPTIMIZE_SIZE__ define is tied to -Oz, which we don't support. |
| 1276 | Options.OptimizeSize = 0; |
Daniel Dunbar | 6143ea2 | 2009-11-16 22:38:14 +0000 | [diff] [blame] | 1277 | Options.Optimize = codegenoptions::OptSize || codegenoptions::OptLevel; |
Daniel Dunbar | 5674908 | 2009-11-11 07:26:12 +0000 | [diff] [blame] | 1278 | |
| 1279 | assert(PICLevel <= 2 && "Invalid value for -pic-level"); |
| 1280 | Options.PICLevel = PICLevel; |
| 1281 | |
| 1282 | Options.GNUInline = !Options.C99; |
Daniel Dunbar | 5674908 | 2009-11-11 07:26:12 +0000 | [diff] [blame] | 1283 | |
| 1284 | // This is the __NO_INLINE__ define, which just depends on things like the |
| 1285 | // optimization level and -fno-inline, not actually whether the backend has |
| 1286 | // inlining enabled. |
Daniel Dunbar | 6143ea2 | 2009-11-16 22:38:14 +0000 | [diff] [blame] | 1287 | // |
| 1288 | // FIXME: This is affected by other options (-fno-inline). |
| 1289 | Options.NoInline = !codegenoptions::OptLevel; |
Daniel Dunbar | 5674908 | 2009-11-11 07:26:12 +0000 | [diff] [blame] | 1290 | |
| 1291 | Options.Static = StaticDefine; |
| 1292 | |
| 1293 | switch (StackProtector) { |
| 1294 | default: |
| 1295 | assert(StackProtector <= 2 && "Invalid value for -stack-protector"); |
| 1296 | case -1: break; |
| 1297 | case 0: Options.setStackProtectorMode(LangOptions::SSPOff); break; |
| 1298 | case 1: Options.setStackProtectorMode(LangOptions::SSPOn); break; |
| 1299 | case 2: Options.setStackProtectorMode(LangOptions::SSPReq); break; |
| 1300 | } |
| 1301 | |
| 1302 | if (MainFileName.getPosition()) |
| 1303 | Options.setMainFileName(MainFileName.c_str()); |
| 1304 | |
| 1305 | Target.setForcedLangOptions(Options); |
| 1306 | } |
Daniel Dunbar | 29cf746 | 2009-11-11 10:07:44 +0000 | [diff] [blame] | 1307 | |
| 1308 | void |
| 1309 | clang::InitializePreprocessorOutputOptions(PreprocessorOutputOptions &Opts) { |
| 1310 | using namespace preprocessoroutputoptions; |
| 1311 | |
| 1312 | Opts.ShowCPP = !DumpMacros; |
| 1313 | Opts.ShowMacros = DumpMacros || DumpDefines; |
| 1314 | Opts.ShowLineMarkers = !DisableLineMarkers; |
| 1315 | Opts.ShowComments = EnableCommentOutput; |
| 1316 | Opts.ShowMacroComments = EnableMacroCommentOutput; |
| 1317 | } |
Daniel Dunbar | d58c03f | 2009-11-15 06:48:46 +0000 | [diff] [blame] | 1318 | |
| 1319 | void clang::InitializeTargetOptions(TargetOptions &Opts) { |
| 1320 | using namespace targetoptions; |
| 1321 | |
| 1322 | Opts.ABI = TargetABI; |
| 1323 | Opts.CPU = TargetCPU; |
| 1324 | Opts.Triple = TargetTriple; |
| 1325 | Opts.Features = TargetFeatures; |
| 1326 | |
| 1327 | // Use the host triple if unspecified. |
| 1328 | if (Opts.Triple.empty()) |
| 1329 | Opts.Triple = llvm::sys::getHostTriple(); |
| 1330 | } |