Daniel Dunbar | f89a32a | 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 | d2cfa01 | 2009-11-11 08:13:55 +0000 | [diff] [blame] | 15 | #include "clang/Basic/LangOptions.h" |
| 16 | #include "clang/Basic/TargetInfo.h" |
| 17 | #include "clang/Frontend/AnalysisConsumer.h" |
Daniel Dunbar | f89a32a | 2009-11-10 19:51:53 +0000 | [diff] [blame] | 18 | #include "clang/Frontend/CompileOptions.h" |
Daniel Dunbar | dcd40fb | 2009-11-11 08:13:40 +0000 | [diff] [blame] | 19 | #include "clang/Frontend/DiagnosticOptions.h" |
Daniel Dunbar | f527a12 | 2009-11-11 08:13:32 +0000 | [diff] [blame] | 20 | #include "clang/Frontend/HeaderSearchOptions.h" |
Daniel Dunbar | 999215c | 2009-11-11 06:10:03 +0000 | [diff] [blame] | 21 | #include "clang/Frontend/PCHReader.h" |
| 22 | #include "clang/Frontend/PreprocessorOptions.h" |
Daniel Dunbar | 999215c | 2009-11-11 06:10:03 +0000 | [diff] [blame] | 23 | #include "llvm/ADT/STLExtras.h" |
Daniel Dunbar | f89a32a | 2009-11-10 19:51:53 +0000 | [diff] [blame] | 24 | #include "llvm/ADT/StringMap.h" |
| 25 | #include "llvm/Support/CommandLine.h" |
Dan Gohman | ad5ef3d | 2009-11-10 21:21:27 +0000 | [diff] [blame] | 26 | #include <stdio.h> |
Daniel Dunbar | f89a32a | 2009-11-10 19:51:53 +0000 | [diff] [blame] | 27 | |
| 28 | using namespace clang; |
| 29 | |
| 30 | //===----------------------------------------------------------------------===// |
Daniel Dunbar | d2cfa01 | 2009-11-11 08:13:55 +0000 | [diff] [blame] | 31 | // Analyzer Options |
| 32 | //===----------------------------------------------------------------------===// |
| 33 | |
| 34 | namespace analyzeroptions { |
| 35 | |
| 36 | static llvm::cl::list<Analyses> |
| 37 | AnalysisList(llvm::cl::desc("Source Code Analysis - Checks and Analyses"), |
| 38 | llvm::cl::values( |
| 39 | #define ANALYSIS(NAME, CMDFLAG, DESC, SCOPE)\ |
| 40 | clEnumValN(NAME, CMDFLAG, DESC), |
| 41 | #include "clang/Frontend/Analyses.def" |
| 42 | clEnumValEnd)); |
| 43 | |
| 44 | static llvm::cl::opt<AnalysisStores> |
| 45 | AnalysisStoreOpt("analyzer-store", |
| 46 | llvm::cl::desc("Source Code Analysis - Abstract Memory Store Models"), |
| 47 | llvm::cl::init(BasicStoreModel), |
| 48 | llvm::cl::values( |
| 49 | #define ANALYSIS_STORE(NAME, CMDFLAG, DESC, CREATFN)\ |
| 50 | clEnumValN(NAME##Model, CMDFLAG, DESC), |
| 51 | #include "clang/Frontend/Analyses.def" |
| 52 | clEnumValEnd)); |
| 53 | |
| 54 | static llvm::cl::opt<AnalysisConstraints> |
| 55 | AnalysisConstraintsOpt("analyzer-constraints", |
| 56 | llvm::cl::desc("Source Code Analysis - Symbolic Constraint Engines"), |
| 57 | llvm::cl::init(RangeConstraintsModel), |
| 58 | llvm::cl::values( |
| 59 | #define ANALYSIS_CONSTRAINTS(NAME, CMDFLAG, DESC, CREATFN)\ |
| 60 | clEnumValN(NAME##Model, CMDFLAG, DESC), |
| 61 | #include "clang/Frontend/Analyses.def" |
| 62 | clEnumValEnd)); |
| 63 | |
| 64 | static llvm::cl::opt<AnalysisDiagClients> |
| 65 | AnalysisDiagOpt("analyzer-output", |
| 66 | llvm::cl::desc("Source Code Analysis - Output Options"), |
| 67 | llvm::cl::init(PD_HTML), |
| 68 | llvm::cl::values( |
| 69 | #define ANALYSIS_DIAGNOSTICS(NAME, CMDFLAG, DESC, CREATFN, AUTOCREATE)\ |
| 70 | clEnumValN(PD_##NAME, CMDFLAG, DESC), |
| 71 | #include "clang/Frontend/Analyses.def" |
| 72 | clEnumValEnd)); |
| 73 | |
| 74 | static llvm::cl::opt<bool> |
| 75 | AnalyzeAll("analyzer-opt-analyze-headers", |
| 76 | llvm::cl::desc("Force the static analyzer to analyze " |
| 77 | "functions defined in header files")); |
| 78 | |
| 79 | static llvm::cl::opt<bool> |
| 80 | AnalyzerDisplayProgress("analyzer-display-progress", |
| 81 | llvm::cl::desc("Emit verbose output about the analyzer's progress.")); |
| 82 | |
| 83 | static llvm::cl::opt<std::string> |
| 84 | AnalyzeSpecificFunction("analyze-function", |
| 85 | llvm::cl::desc("Run analysis on specific function")); |
| 86 | |
| 87 | static llvm::cl::opt<bool> |
| 88 | EagerlyAssume("analyzer-eagerly-assume", |
| 89 | llvm::cl::init(false), |
| 90 | llvm::cl::desc("Eagerly assume the truth/falseness of some " |
| 91 | "symbolic constraints.")); |
| 92 | |
| 93 | static llvm::cl::opt<bool> |
| 94 | PurgeDead("analyzer-purge-dead", |
| 95 | llvm::cl::init(true), |
| 96 | llvm::cl::desc("Remove dead symbols, bindings, and constraints before" |
| 97 | " processing a statement.")); |
| 98 | |
| 99 | static llvm::cl::opt<bool> |
| 100 | TrimGraph("trim-egraph", |
| 101 | llvm::cl::desc("Only show error-related paths in the analysis graph")); |
| 102 | |
| 103 | static llvm::cl::opt<bool> |
| 104 | VisualizeEGDot("analyzer-viz-egraph-graphviz", |
| 105 | llvm::cl::desc("Display exploded graph using GraphViz")); |
| 106 | |
| 107 | static llvm::cl::opt<bool> |
| 108 | VisualizeEGUbi("analyzer-viz-egraph-ubigraph", |
| 109 | llvm::cl::desc("Display exploded graph using Ubigraph")); |
| 110 | |
| 111 | } |
| 112 | |
| 113 | void clang::InitializeAnalyzerOptions(AnalyzerOptions &Opts) { |
| 114 | using namespace analyzeroptions; |
| 115 | Opts.AnalysisList = AnalysisList; |
| 116 | Opts.AnalysisStoreOpt = AnalysisStoreOpt; |
| 117 | Opts.AnalysisConstraintsOpt = AnalysisConstraintsOpt; |
| 118 | Opts.AnalysisDiagOpt = AnalysisDiagOpt; |
| 119 | Opts.VisualizeEGDot = VisualizeEGDot; |
| 120 | Opts.VisualizeEGUbi = VisualizeEGUbi; |
| 121 | Opts.AnalyzeAll = AnalyzeAll; |
| 122 | Opts.AnalyzerDisplayProgress = AnalyzerDisplayProgress; |
| 123 | Opts.PurgeDead = PurgeDead; |
| 124 | Opts.EagerlyAssume = EagerlyAssume; |
| 125 | Opts.AnalyzeSpecificFunction = AnalyzeSpecificFunction; |
| 126 | Opts.TrimGraph = TrimGraph; |
| 127 | } |
| 128 | |
| 129 | |
| 130 | //===----------------------------------------------------------------------===// |
Daniel Dunbar | f89a32a | 2009-11-10 19:51:53 +0000 | [diff] [blame] | 131 | // Code Generation Options |
| 132 | //===----------------------------------------------------------------------===// |
| 133 | |
| 134 | namespace codegenoptions { |
| 135 | |
| 136 | static llvm::cl::opt<bool> |
| 137 | DisableLLVMOptimizations("disable-llvm-optzns", |
| 138 | llvm::cl::desc("Don't run LLVM optimization passes")); |
| 139 | |
| 140 | static llvm::cl::opt<bool> |
| 141 | DisableRedZone("disable-red-zone", |
| 142 | llvm::cl::desc("Do not emit code that uses the red zone."), |
| 143 | llvm::cl::init(false)); |
| 144 | |
| 145 | static llvm::cl::opt<bool> |
| 146 | GenerateDebugInfo("g", |
| 147 | llvm::cl::desc("Generate source level debug information")); |
| 148 | |
| 149 | static llvm::cl::opt<bool> |
| 150 | NoCommon("fno-common", |
| 151 | llvm::cl::desc("Compile common globals like normal definitions"), |
| 152 | llvm::cl::ValueDisallowed); |
| 153 | |
| 154 | static llvm::cl::opt<bool> |
| 155 | NoImplicitFloat("no-implicit-float", |
| 156 | llvm::cl::desc("Don't generate implicit floating point instructions (x86-only)"), |
| 157 | llvm::cl::init(false)); |
| 158 | |
| 159 | static llvm::cl::opt<bool> |
| 160 | NoMergeConstants("fno-merge-all-constants", |
| 161 | llvm::cl::desc("Disallow merging of constants.")); |
| 162 | |
| 163 | // It might be nice to add bounds to the CommandLine library directly. |
| 164 | struct OptLevelParser : public llvm::cl::parser<unsigned> { |
| 165 | bool parse(llvm::cl::Option &O, llvm::StringRef ArgName, |
| 166 | llvm::StringRef Arg, unsigned &Val) { |
| 167 | if (llvm::cl::parser<unsigned>::parse(O, ArgName, Arg, Val)) |
| 168 | return true; |
| 169 | if (Val > 3) |
| 170 | return O.error("'" + Arg + "' invalid optimization level!"); |
| 171 | return false; |
| 172 | } |
| 173 | }; |
| 174 | static llvm::cl::opt<unsigned, false, OptLevelParser> |
| 175 | OptLevel("O", llvm::cl::Prefix, |
| 176 | llvm::cl::desc("Optimization level"), |
| 177 | llvm::cl::init(0)); |
| 178 | |
| 179 | static llvm::cl::opt<bool> |
| 180 | OptSize("Os", llvm::cl::desc("Optimize for size")); |
| 181 | |
| 182 | static llvm::cl::opt<std::string> |
| 183 | TargetCPU("mcpu", |
| 184 | llvm::cl::desc("Target a specific cpu type (-mcpu=help for details)")); |
| 185 | |
| 186 | static llvm::cl::list<std::string> |
| 187 | TargetFeatures("target-feature", llvm::cl::desc("Target specific attributes")); |
| 188 | |
| 189 | } |
| 190 | |
| 191 | //===----------------------------------------------------------------------===// |
Daniel Dunbar | dcd40fb | 2009-11-11 08:13:40 +0000 | [diff] [blame] | 192 | // Diagnostic Options |
| 193 | //===----------------------------------------------------------------------===// |
| 194 | |
| 195 | namespace diagnosticoptions { |
| 196 | |
| 197 | static llvm::cl::opt<bool> |
| 198 | NoShowColumn("fno-show-column", |
| 199 | llvm::cl::desc("Do not include column number on diagnostics")); |
| 200 | |
| 201 | static llvm::cl::opt<bool> |
| 202 | NoShowLocation("fno-show-source-location", |
| 203 | llvm::cl::desc("Do not include source location information with" |
| 204 | " diagnostics")); |
| 205 | |
| 206 | static llvm::cl::opt<bool> |
| 207 | NoCaretDiagnostics("fno-caret-diagnostics", |
| 208 | llvm::cl::desc("Do not include source line and caret with" |
| 209 | " diagnostics")); |
| 210 | |
| 211 | static llvm::cl::opt<bool> |
| 212 | NoDiagnosticsFixIt("fno-diagnostics-fixit-info", |
| 213 | llvm::cl::desc("Do not include fixit information in" |
| 214 | " diagnostics")); |
| 215 | |
| 216 | static llvm::cl::opt<bool> |
| 217 | PrintSourceRangeInfo("fdiagnostics-print-source-range-info", |
| 218 | llvm::cl::desc("Print source range spans in numeric form")); |
| 219 | |
| 220 | static llvm::cl::opt<bool> |
| 221 | PrintDiagnosticOption("fdiagnostics-show-option", |
| 222 | llvm::cl::desc("Print diagnostic name with mappable diagnostics")); |
| 223 | |
| 224 | static llvm::cl::opt<unsigned> |
| 225 | MessageLength("fmessage-length", |
| 226 | llvm::cl::desc("Format message diagnostics so that they fit " |
| 227 | "within N columns or fewer, when possible."), |
| 228 | llvm::cl::value_desc("N")); |
| 229 | |
| 230 | static llvm::cl::opt<bool> |
| 231 | PrintColorDiagnostic("fcolor-diagnostics", |
| 232 | llvm::cl::desc("Use colors in diagnostics")); |
| 233 | |
| 234 | } |
| 235 | |
| 236 | //===----------------------------------------------------------------------===// |
Daniel Dunbar | 84dfbfd | 2009-11-11 07:26:12 +0000 | [diff] [blame] | 237 | // Language Options |
| 238 | //===----------------------------------------------------------------------===// |
| 239 | |
| 240 | namespace langoptions { |
| 241 | |
| 242 | static llvm::cl::opt<bool> |
| 243 | AllowBuiltins("fbuiltin", llvm::cl::init(true), |
| 244 | llvm::cl::desc("Disable implicit builtin knowledge of functions")); |
| 245 | |
| 246 | static llvm::cl::opt<bool> |
| 247 | AltiVec("faltivec", llvm::cl::desc("Enable AltiVec vector initializer syntax"), |
| 248 | llvm::cl::init(false)); |
| 249 | |
| 250 | static llvm::cl::opt<bool> |
| 251 | AccessControl("faccess-control", |
| 252 | llvm::cl::desc("Enable C++ access control")); |
| 253 | |
| 254 | static llvm::cl::opt<bool> |
| 255 | CharIsSigned("fsigned-char", |
| 256 | llvm::cl::desc("Force char to be a signed/unsigned type")); |
| 257 | |
| 258 | static llvm::cl::opt<bool> |
| 259 | DollarsInIdents("fdollars-in-identifiers", |
| 260 | llvm::cl::desc("Allow '$' in identifiers")); |
| 261 | |
| 262 | static llvm::cl::opt<bool> |
| 263 | EmitAllDecls("femit-all-decls", |
| 264 | llvm::cl::desc("Emit all declarations, even if unused")); |
| 265 | |
| 266 | static llvm::cl::opt<bool> |
| 267 | EnableBlocks("fblocks", llvm::cl::desc("enable the 'blocks' language feature")); |
| 268 | |
| 269 | static llvm::cl::opt<bool> |
| 270 | EnableHeinousExtensions("fheinous-gnu-extensions", |
| 271 | llvm::cl::desc("enable GNU extensions that you really really shouldn't use"), |
| 272 | llvm::cl::ValueDisallowed, llvm::cl::Hidden); |
| 273 | |
| 274 | static llvm::cl::opt<bool> |
| 275 | Exceptions("fexceptions", |
| 276 | llvm::cl::desc("Enable support for exception handling")); |
| 277 | |
| 278 | static llvm::cl::opt<bool> |
| 279 | Freestanding("ffreestanding", |
| 280 | llvm::cl::desc("Assert that the compilation takes place in a " |
| 281 | "freestanding environment")); |
| 282 | |
| 283 | static llvm::cl::opt<bool> |
| 284 | GNURuntime("fgnu-runtime", |
| 285 | llvm::cl::desc("Generate output compatible with the standard GNU " |
| 286 | "Objective-C runtime")); |
| 287 | |
| 288 | /// LangStds - Language standards we support. |
| 289 | enum LangStds { |
| 290 | lang_unspecified, |
| 291 | lang_c89, lang_c94, lang_c99, |
| 292 | lang_gnu89, lang_gnu99, |
| 293 | lang_cxx98, lang_gnucxx98, |
| 294 | lang_cxx0x, lang_gnucxx0x |
| 295 | }; |
| 296 | static llvm::cl::opt<LangStds> |
| 297 | LangStd("std", llvm::cl::desc("Language standard to compile for"), |
| 298 | llvm::cl::init(lang_unspecified), |
| 299 | llvm::cl::values(clEnumValN(lang_c89, "c89", "ISO C 1990"), |
| 300 | clEnumValN(lang_c89, "c90", "ISO C 1990"), |
| 301 | clEnumValN(lang_c89, "iso9899:1990", "ISO C 1990"), |
| 302 | clEnumValN(lang_c94, "iso9899:199409", |
| 303 | "ISO C 1990 with amendment 1"), |
| 304 | clEnumValN(lang_c99, "c99", "ISO C 1999"), |
| 305 | clEnumValN(lang_c99, "c9x", "ISO C 1999"), |
| 306 | clEnumValN(lang_c99, "iso9899:1999", "ISO C 1999"), |
| 307 | clEnumValN(lang_c99, "iso9899:199x", "ISO C 1999"), |
| 308 | clEnumValN(lang_gnu89, "gnu89", |
| 309 | "ISO C 1990 with GNU extensions"), |
| 310 | clEnumValN(lang_gnu99, "gnu99", |
| 311 | "ISO C 1999 with GNU extensions (default for C)"), |
| 312 | clEnumValN(lang_gnu99, "gnu9x", |
| 313 | "ISO C 1999 with GNU extensions"), |
| 314 | clEnumValN(lang_cxx98, "c++98", |
| 315 | "ISO C++ 1998 with amendments"), |
| 316 | clEnumValN(lang_gnucxx98, "gnu++98", |
| 317 | "ISO C++ 1998 with amendments and GNU " |
| 318 | "extensions (default for C++)"), |
| 319 | clEnumValN(lang_cxx0x, "c++0x", |
| 320 | "Upcoming ISO C++ 200x with amendments"), |
| 321 | clEnumValN(lang_gnucxx0x, "gnu++0x", |
| 322 | "Upcoming ISO C++ 200x with amendments and GNU " |
| 323 | "extensions"), |
| 324 | clEnumValEnd)); |
| 325 | |
| 326 | static llvm::cl::opt<bool> |
| 327 | MSExtensions("fms-extensions", |
| 328 | llvm::cl::desc("Accept some non-standard constructs used in " |
| 329 | "Microsoft header files ")); |
| 330 | |
| 331 | static llvm::cl::opt<std::string> |
| 332 | MainFileName("main-file-name", |
| 333 | llvm::cl::desc("Main file name to use for debug info")); |
| 334 | |
| 335 | static llvm::cl::opt<bool> |
| 336 | MathErrno("fmath-errno", llvm::cl::init(true), |
| 337 | llvm::cl::desc("Require math functions to respect errno")); |
| 338 | |
| 339 | static llvm::cl::opt<bool> |
| 340 | NeXTRuntime("fnext-runtime", |
| 341 | llvm::cl::desc("Generate output compatible with the NeXT " |
| 342 | "runtime")); |
| 343 | |
| 344 | static llvm::cl::opt<bool> |
| 345 | NoElideConstructors("fno-elide-constructors", |
| 346 | llvm::cl::desc("Disable C++ copy constructor elision")); |
| 347 | |
| 348 | static llvm::cl::opt<bool> |
| 349 | NoLaxVectorConversions("fno-lax-vector-conversions", |
| 350 | llvm::cl::desc("Disallow implicit conversions between " |
| 351 | "vectors with a different number of " |
| 352 | "elements or different element types")); |
| 353 | |
| 354 | |
| 355 | static llvm::cl::opt<bool> |
| 356 | NoOperatorNames("fno-operator-names", |
| 357 | llvm::cl::desc("Do not treat C++ operator name keywords as " |
| 358 | "synonyms for operators")); |
| 359 | |
| 360 | static llvm::cl::opt<std::string> |
| 361 | ObjCConstantStringClass("fconstant-string-class", |
| 362 | llvm::cl::value_desc("class name"), |
| 363 | llvm::cl::desc("Specify the class to use for constant " |
| 364 | "Objective-C string objects.")); |
| 365 | |
| 366 | static llvm::cl::opt<bool> |
| 367 | ObjCEnableGC("fobjc-gc", |
| 368 | llvm::cl::desc("Enable Objective-C garbage collection")); |
| 369 | |
| 370 | static llvm::cl::opt<bool> |
| 371 | ObjCExclusiveGC("fobjc-gc-only", |
| 372 | llvm::cl::desc("Use GC exclusively for Objective-C related " |
| 373 | "memory management")); |
| 374 | |
| 375 | static llvm::cl::opt<bool> |
| 376 | ObjCEnableGCBitmapPrint("print-ivar-layout", |
| 377 | llvm::cl::desc("Enable Objective-C Ivar layout bitmap print trace")); |
| 378 | |
| 379 | static llvm::cl::opt<bool> |
| 380 | ObjCNonFragileABI("fobjc-nonfragile-abi", |
| 381 | llvm::cl::desc("enable objective-c's nonfragile abi")); |
| 382 | |
| 383 | static llvm::cl::opt<bool> |
| 384 | OverflowChecking("ftrapv", |
| 385 | llvm::cl::desc("Trap on integer overflow"), |
| 386 | llvm::cl::init(false)); |
| 387 | |
| 388 | static llvm::cl::opt<unsigned> |
| 389 | PICLevel("pic-level", llvm::cl::desc("Value for __PIC__")); |
| 390 | |
| 391 | static llvm::cl::opt<bool> |
| 392 | PThread("pthread", llvm::cl::desc("Support POSIX threads in generated code"), |
| 393 | llvm::cl::init(false)); |
| 394 | |
| 395 | static llvm::cl::opt<bool> |
| 396 | PascalStrings("fpascal-strings", |
| 397 | llvm::cl::desc("Recognize and construct Pascal-style " |
| 398 | "string literals")); |
| 399 | |
Daniel Dunbar | 84dfbfd | 2009-11-11 07:26:12 +0000 | [diff] [blame] | 400 | static llvm::cl::opt<bool> |
| 401 | Rtti("frtti", llvm::cl::init(true), |
| 402 | llvm::cl::desc("Enable generation of rtti information")); |
| 403 | |
| 404 | static llvm::cl::opt<bool> |
| 405 | ShortWChar("fshort-wchar", |
| 406 | llvm::cl::desc("Force wchar_t to be a short unsigned int")); |
| 407 | |
| 408 | static llvm::cl::opt<bool> |
| 409 | StaticDefine("static-define", llvm::cl::desc("Should __STATIC__ be defined")); |
| 410 | |
| 411 | static llvm::cl::opt<int> |
| 412 | StackProtector("stack-protector", |
| 413 | llvm::cl::desc("Enable stack protectors"), |
| 414 | llvm::cl::init(-1)); |
| 415 | |
| 416 | static llvm::cl::opt<LangOptions::VisibilityMode> |
| 417 | SymbolVisibility("fvisibility", |
| 418 | llvm::cl::desc("Set the default symbol visibility:"), |
| 419 | llvm::cl::init(LangOptions::Default), |
| 420 | llvm::cl::values(clEnumValN(LangOptions::Default, "default", |
| 421 | "Use default symbol visibility"), |
| 422 | clEnumValN(LangOptions::Hidden, "hidden", |
| 423 | "Use hidden symbol visibility"), |
| 424 | clEnumValN(LangOptions::Protected,"protected", |
| 425 | "Use protected symbol visibility"), |
| 426 | clEnumValEnd)); |
| 427 | |
| 428 | static llvm::cl::opt<unsigned> |
| 429 | TemplateDepth("ftemplate-depth", llvm::cl::init(99), |
| 430 | llvm::cl::desc("Maximum depth of recursive template " |
| 431 | "instantiation")); |
| 432 | |
| 433 | static llvm::cl::opt<bool> |
| 434 | Trigraphs("trigraphs", llvm::cl::desc("Process trigraph sequences")); |
| 435 | |
| 436 | static llvm::cl::opt<bool> |
| 437 | WritableStrings("fwritable-strings", |
| 438 | llvm::cl::desc("Store string literals as writable data")); |
| 439 | |
| 440 | } |
| 441 | |
| 442 | //===----------------------------------------------------------------------===// |
Daniel Dunbar | 999215c | 2009-11-11 06:10:03 +0000 | [diff] [blame] | 443 | // General Preprocessor Options |
| 444 | //===----------------------------------------------------------------------===// |
| 445 | |
| 446 | namespace preprocessoroptions { |
| 447 | |
| 448 | static llvm::cl::list<std::string> |
| 449 | D_macros("D", llvm::cl::value_desc("macro"), llvm::cl::Prefix, |
| 450 | llvm::cl::desc("Predefine the specified macro")); |
| 451 | |
| 452 | static llvm::cl::list<std::string> |
| 453 | ImplicitIncludes("include", llvm::cl::value_desc("file"), |
| 454 | llvm::cl::desc("Include file before parsing")); |
| 455 | static llvm::cl::list<std::string> |
| 456 | ImplicitMacroIncludes("imacros", llvm::cl::value_desc("file"), |
| 457 | llvm::cl::desc("Include macros from file before parsing")); |
| 458 | |
| 459 | static llvm::cl::opt<std::string> |
| 460 | ImplicitIncludePCH("include-pch", llvm::cl::value_desc("file"), |
| 461 | llvm::cl::desc("Include precompiled header file")); |
| 462 | |
| 463 | static llvm::cl::opt<std::string> |
| 464 | ImplicitIncludePTH("include-pth", llvm::cl::value_desc("file"), |
| 465 | llvm::cl::desc("Include file before parsing")); |
| 466 | |
| 467 | static llvm::cl::list<std::string> |
| 468 | U_macros("U", llvm::cl::value_desc("macro"), llvm::cl::Prefix, |
| 469 | llvm::cl::desc("Undefine the specified macro")); |
| 470 | |
| 471 | static llvm::cl::opt<bool> |
| 472 | UndefMacros("undef", llvm::cl::value_desc("macro"), |
| 473 | llvm::cl::desc("undef all system defines")); |
| 474 | |
| 475 | } |
| 476 | |
| 477 | //===----------------------------------------------------------------------===// |
Daniel Dunbar | f527a12 | 2009-11-11 08:13:32 +0000 | [diff] [blame] | 478 | // Header Search Options |
| 479 | //===----------------------------------------------------------------------===// |
| 480 | |
| 481 | namespace headersearchoptions { |
| 482 | |
| 483 | static llvm::cl::opt<bool> |
| 484 | nostdinc("nostdinc", llvm::cl::desc("Disable standard #include directories")); |
| 485 | |
| 486 | static llvm::cl::opt<bool> |
| 487 | nobuiltininc("nobuiltininc", |
| 488 | llvm::cl::desc("Disable builtin #include directories")); |
| 489 | |
| 490 | // Various command line options. These four add directories to each chain. |
| 491 | static llvm::cl::list<std::string> |
| 492 | F_dirs("F", llvm::cl::value_desc("directory"), llvm::cl::Prefix, |
| 493 | llvm::cl::desc("Add directory to framework include search path")); |
| 494 | |
| 495 | static llvm::cl::list<std::string> |
| 496 | I_dirs("I", llvm::cl::value_desc("directory"), llvm::cl::Prefix, |
| 497 | llvm::cl::desc("Add directory to include search path")); |
| 498 | |
| 499 | static llvm::cl::list<std::string> |
| 500 | idirafter_dirs("idirafter", llvm::cl::value_desc("directory"), llvm::cl::Prefix, |
| 501 | llvm::cl::desc("Add directory to AFTER include search path")); |
| 502 | |
| 503 | static llvm::cl::list<std::string> |
| 504 | iquote_dirs("iquote", llvm::cl::value_desc("directory"), llvm::cl::Prefix, |
| 505 | llvm::cl::desc("Add directory to QUOTE include search path")); |
| 506 | |
| 507 | static llvm::cl::list<std::string> |
| 508 | isystem_dirs("isystem", llvm::cl::value_desc("directory"), llvm::cl::Prefix, |
| 509 | llvm::cl::desc("Add directory to SYSTEM include search path")); |
| 510 | |
| 511 | // These handle -iprefix/-iwithprefix/-iwithprefixbefore. |
| 512 | static llvm::cl::list<std::string> |
| 513 | iprefix_vals("iprefix", llvm::cl::value_desc("prefix"), llvm::cl::Prefix, |
| 514 | llvm::cl::desc("Set the -iwithprefix/-iwithprefixbefore prefix")); |
| 515 | static llvm::cl::list<std::string> |
| 516 | iwithprefix_vals("iwithprefix", llvm::cl::value_desc("dir"), llvm::cl::Prefix, |
| 517 | llvm::cl::desc("Set directory to SYSTEM include search path with prefix")); |
| 518 | static llvm::cl::list<std::string> |
| 519 | iwithprefixbefore_vals("iwithprefixbefore", llvm::cl::value_desc("dir"), |
| 520 | llvm::cl::Prefix, |
| 521 | llvm::cl::desc("Set directory to include search path with prefix")); |
| 522 | |
| 523 | static llvm::cl::opt<std::string> |
| 524 | isysroot("isysroot", llvm::cl::value_desc("dir"), llvm::cl::init("/"), |
| 525 | llvm::cl::desc("Set the system root directory (usually /)")); |
| 526 | |
| 527 | } |
| 528 | |
| 529 | //===----------------------------------------------------------------------===// |
Daniel Dunbar | f89a32a | 2009-11-10 19:51:53 +0000 | [diff] [blame] | 530 | // Option Object Construction |
| 531 | //===----------------------------------------------------------------------===// |
| 532 | |
Daniel Dunbar | 979586e | 2009-11-11 09:38:56 +0000 | [diff] [blame^] | 533 | void clang::InitializeCompileOptions(CompileOptions &Opts, |
| 534 | const TargetInfo &Target) { |
Daniel Dunbar | f89a32a | 2009-11-10 19:51:53 +0000 | [diff] [blame] | 535 | using namespace codegenoptions; |
Daniel Dunbar | f89a32a | 2009-11-10 19:51:53 +0000 | [diff] [blame] | 536 | |
Daniel Dunbar | 979586e | 2009-11-11 09:38:56 +0000 | [diff] [blame^] | 537 | // Compute the target features, we need the target to handle this because |
| 538 | // features may have dependencies on one another. |
| 539 | llvm::StringMap<bool> Features; |
Daniel Dunbar | f89a32a | 2009-11-10 19:51:53 +0000 | [diff] [blame] | 540 | Target.getDefaultFeatures(TargetCPU, Features); |
| 541 | |
| 542 | // Apply the user specified deltas. |
| 543 | for (llvm::cl::list<std::string>::iterator it = TargetFeatures.begin(), |
| 544 | ie = TargetFeatures.end(); it != ie; ++it) { |
| 545 | const char *Name = it->c_str(); |
| 546 | |
| 547 | // FIXME: Don't handle errors like this. |
| 548 | if (Name[0] != '-' && Name[0] != '+') { |
| 549 | fprintf(stderr, "error: clang-cc: invalid target feature string: %s\n", |
| 550 | Name); |
| 551 | exit(1); |
| 552 | } |
Daniel Dunbar | 979586e | 2009-11-11 09:38:56 +0000 | [diff] [blame^] | 553 | |
| 554 | // Apply the feature via the target. |
Daniel Dunbar | f89a32a | 2009-11-10 19:51:53 +0000 | [diff] [blame] | 555 | if (!Target.setFeatureEnabled(Features, Name + 1, (Name[0] == '+'))) { |
| 556 | fprintf(stderr, "error: clang-cc: invalid target feature name: %s\n", |
| 557 | Name + 1); |
| 558 | exit(1); |
| 559 | } |
| 560 | } |
Daniel Dunbar | f89a32a | 2009-11-10 19:51:53 +0000 | [diff] [blame] | 561 | |
Daniel Dunbar | 979586e | 2009-11-11 09:38:56 +0000 | [diff] [blame^] | 562 | // Add the features to the compile options. |
| 563 | // |
| 564 | // FIXME: If we are completely confident that we have the right set, we only |
| 565 | // need to pass the minuses. |
| 566 | for (llvm::StringMap<bool>::const_iterator it = Features.begin(), |
| 567 | ie = Features.end(); it != ie; ++it) |
| 568 | Opts.Features.push_back(std::string(it->second ? "+" : "-") + it->first()); |
Daniel Dunbar | f89a32a | 2009-11-10 19:51:53 +0000 | [diff] [blame] | 569 | |
| 570 | // -Os implies -O2 |
| 571 | Opts.OptimizationLevel = OptSize ? 2 : OptLevel; |
| 572 | |
| 573 | // We must always run at least the always inlining pass. |
| 574 | Opts.Inlining = (Opts.OptimizationLevel > 1) ? CompileOptions::NormalInlining |
| 575 | : CompileOptions::OnlyAlwaysInlining; |
| 576 | |
Daniel Dunbar | 979586e | 2009-11-11 09:38:56 +0000 | [diff] [blame^] | 577 | Opts.CPU = TargetCPU; |
| 578 | Opts.DebugInfo = GenerateDebugInfo; |
| 579 | Opts.DisableLLVMOpts = DisableLLVMOptimizations; |
| 580 | Opts.DisableRedZone = DisableRedZone; |
| 581 | Opts.MergeAllConstants = !NoMergeConstants; |
| 582 | Opts.NoCommon = NoCommon; |
| 583 | Opts.NoImplicitFloat = NoImplicitFloat; |
| 584 | Opts.OptimizeSize = OptSize; |
Daniel Dunbar | f89a32a | 2009-11-10 19:51:53 +0000 | [diff] [blame] | 585 | Opts.SimplifyLibCalls = 1; |
Daniel Dunbar | 979586e | 2009-11-11 09:38:56 +0000 | [diff] [blame^] | 586 | Opts.UnrollLoops = (Opts.OptimizationLevel > 1 && !OptSize); |
Daniel Dunbar | f89a32a | 2009-11-10 19:51:53 +0000 | [diff] [blame] | 587 | |
| 588 | #ifdef NDEBUG |
| 589 | Opts.VerifyModule = 0; |
| 590 | #endif |
Daniel Dunbar | f89a32a | 2009-11-10 19:51:53 +0000 | [diff] [blame] | 591 | } |
Daniel Dunbar | 999215c | 2009-11-11 06:10:03 +0000 | [diff] [blame] | 592 | |
Daniel Dunbar | dcd40fb | 2009-11-11 08:13:40 +0000 | [diff] [blame] | 593 | void clang::InitializeDiagnosticOptions(DiagnosticOptions &Opts) { |
| 594 | using namespace diagnosticoptions; |
| 595 | |
| 596 | Opts.ShowColumn = !NoShowColumn; |
| 597 | Opts.ShowLocation = !NoShowLocation; |
| 598 | Opts.ShowCarets = !NoCaretDiagnostics; |
| 599 | Opts.ShowFixits = !NoDiagnosticsFixIt; |
| 600 | Opts.ShowSourceRanges = PrintSourceRangeInfo; |
| 601 | Opts.ShowOptionNames = PrintDiagnosticOption; |
| 602 | Opts.ShowColors = PrintColorDiagnostic; |
| 603 | Opts.MessageLength = MessageLength; |
| 604 | } |
| 605 | |
Daniel Dunbar | f527a12 | 2009-11-11 08:13:32 +0000 | [diff] [blame] | 606 | void clang::InitializeHeaderSearchOptions(HeaderSearchOptions &Opts, |
| 607 | llvm::StringRef BuiltinIncludePath, |
| 608 | bool Verbose, |
| 609 | const LangOptions &Lang) { |
| 610 | using namespace headersearchoptions; |
| 611 | |
| 612 | Opts.Sysroot = isysroot; |
| 613 | Opts.Verbose = Verbose; |
| 614 | |
| 615 | // Handle -I... and -F... options, walking the lists in parallel. |
| 616 | unsigned Iidx = 0, Fidx = 0; |
| 617 | while (Iidx < I_dirs.size() && Fidx < F_dirs.size()) { |
| 618 | if (I_dirs.getPosition(Iidx) < F_dirs.getPosition(Fidx)) { |
| 619 | Opts.AddPath(I_dirs[Iidx], frontend::Angled, false, true, false); |
| 620 | ++Iidx; |
| 621 | } else { |
| 622 | Opts.AddPath(F_dirs[Fidx], frontend::Angled, false, true, true); |
| 623 | ++Fidx; |
| 624 | } |
| 625 | } |
| 626 | |
| 627 | // Consume what's left from whatever list was longer. |
| 628 | for (; Iidx != I_dirs.size(); ++Iidx) |
| 629 | Opts.AddPath(I_dirs[Iidx], frontend::Angled, false, true, false); |
| 630 | for (; Fidx != F_dirs.size(); ++Fidx) |
| 631 | Opts.AddPath(F_dirs[Fidx], frontend::Angled, false, true, true); |
| 632 | |
| 633 | // Handle -idirafter... options. |
| 634 | for (unsigned i = 0, e = idirafter_dirs.size(); i != e; ++i) |
| 635 | Opts.AddPath(idirafter_dirs[i], frontend::After, |
| 636 | false, true, false); |
| 637 | |
| 638 | // Handle -iquote... options. |
| 639 | for (unsigned i = 0, e = iquote_dirs.size(); i != e; ++i) |
| 640 | Opts.AddPath(iquote_dirs[i], frontend::Quoted, false, true, false); |
| 641 | |
| 642 | // Handle -isystem... options. |
| 643 | for (unsigned i = 0, e = isystem_dirs.size(); i != e; ++i) |
| 644 | Opts.AddPath(isystem_dirs[i], frontend::System, false, true, false); |
| 645 | |
| 646 | // Walk the -iprefix/-iwithprefix/-iwithprefixbefore argument lists in |
| 647 | // parallel, processing the values in order of occurance to get the right |
| 648 | // prefixes. |
| 649 | { |
| 650 | std::string Prefix = ""; // FIXME: this isn't the correct default prefix. |
| 651 | unsigned iprefix_idx = 0; |
| 652 | unsigned iwithprefix_idx = 0; |
| 653 | unsigned iwithprefixbefore_idx = 0; |
| 654 | bool iprefix_done = iprefix_vals.empty(); |
| 655 | bool iwithprefix_done = iwithprefix_vals.empty(); |
| 656 | bool iwithprefixbefore_done = iwithprefixbefore_vals.empty(); |
| 657 | while (!iprefix_done || !iwithprefix_done || !iwithprefixbefore_done) { |
| 658 | if (!iprefix_done && |
| 659 | (iwithprefix_done || |
| 660 | iprefix_vals.getPosition(iprefix_idx) < |
| 661 | iwithprefix_vals.getPosition(iwithprefix_idx)) && |
| 662 | (iwithprefixbefore_done || |
| 663 | iprefix_vals.getPosition(iprefix_idx) < |
| 664 | iwithprefixbefore_vals.getPosition(iwithprefixbefore_idx))) { |
| 665 | Prefix = iprefix_vals[iprefix_idx]; |
| 666 | ++iprefix_idx; |
| 667 | iprefix_done = iprefix_idx == iprefix_vals.size(); |
| 668 | } else if (!iwithprefix_done && |
| 669 | (iwithprefixbefore_done || |
| 670 | iwithprefix_vals.getPosition(iwithprefix_idx) < |
| 671 | iwithprefixbefore_vals.getPosition(iwithprefixbefore_idx))) { |
| 672 | Opts.AddPath(Prefix+iwithprefix_vals[iwithprefix_idx], |
| 673 | frontend::System, false, false, false); |
| 674 | ++iwithprefix_idx; |
| 675 | iwithprefix_done = iwithprefix_idx == iwithprefix_vals.size(); |
| 676 | } else { |
| 677 | Opts.AddPath(Prefix+iwithprefixbefore_vals[iwithprefixbefore_idx], |
| 678 | frontend::Angled, false, false, false); |
| 679 | ++iwithprefixbefore_idx; |
| 680 | iwithprefixbefore_done = |
| 681 | iwithprefixbefore_idx == iwithprefixbefore_vals.size(); |
| 682 | } |
| 683 | } |
| 684 | } |
| 685 | |
| 686 | // Add CPATH environment paths. |
| 687 | if (const char *Env = getenv("CPATH")) |
| 688 | Opts.EnvIncPath = Env; |
| 689 | |
| 690 | // Add language specific environment paths. |
| 691 | if (Lang.CPlusPlus && Lang.ObjC1) { |
| 692 | if (const char *Env = getenv("OBJCPLUS_INCLUDE_PATH")) |
| 693 | Opts.LangEnvIncPath = Env; |
| 694 | } else if (Lang.CPlusPlus) { |
| 695 | if (const char *Env = getenv("CPLUS_INCLUDE_PATH")) |
| 696 | Opts.LangEnvIncPath = Env; |
| 697 | } else if (Lang.ObjC1) { |
| 698 | if (const char *Env = getenv("OBJC_INCLUDE_PATH")) |
| 699 | Opts.LangEnvIncPath = Env; |
| 700 | } else { |
| 701 | if (const char *Env = getenv("C_INCLUDE_PATH")) |
| 702 | Opts.LangEnvIncPath = Env; |
| 703 | } |
| 704 | |
| 705 | if (!nobuiltininc) |
| 706 | Opts.BuiltinIncludePath = BuiltinIncludePath; |
| 707 | |
| 708 | Opts.UseStandardIncludes = !nostdinc; |
| 709 | } |
| 710 | |
Daniel Dunbar | 999215c | 2009-11-11 06:10:03 +0000 | [diff] [blame] | 711 | void clang::InitializePreprocessorOptions(PreprocessorOptions &Opts) { |
| 712 | using namespace preprocessoroptions; |
| 713 | |
| 714 | Opts.setImplicitPCHInclude(ImplicitIncludePCH); |
| 715 | Opts.setImplicitPTHInclude(ImplicitIncludePTH); |
| 716 | |
| 717 | // Use predefines? |
| 718 | Opts.setUsePredefines(!UndefMacros); |
| 719 | |
| 720 | // Add macros from the command line. |
| 721 | unsigned d = 0, D = D_macros.size(); |
| 722 | unsigned u = 0, U = U_macros.size(); |
| 723 | while (d < D || u < U) { |
| 724 | if (u == U || (d < D && D_macros.getPosition(d) < U_macros.getPosition(u))) |
| 725 | Opts.addMacroDef(D_macros[d++]); |
| 726 | else |
| 727 | Opts.addMacroUndef(U_macros[u++]); |
| 728 | } |
| 729 | |
| 730 | // If -imacros are specified, include them now. These are processed before |
| 731 | // any -include directives. |
| 732 | for (unsigned i = 0, e = ImplicitMacroIncludes.size(); i != e; ++i) |
| 733 | Opts.addMacroInclude(ImplicitMacroIncludes[i]); |
| 734 | |
| 735 | // Add the ordered list of -includes, sorting in the implicit include options |
| 736 | // at the appropriate location. |
| 737 | llvm::SmallVector<std::pair<unsigned, std::string*>, 8> OrderedPaths; |
| 738 | std::string OriginalFile; |
| 739 | |
| 740 | if (!ImplicitIncludePTH.empty()) |
| 741 | OrderedPaths.push_back(std::make_pair(ImplicitIncludePTH.getPosition(), |
| 742 | &ImplicitIncludePTH)); |
| 743 | if (!ImplicitIncludePCH.empty()) { |
| 744 | OriginalFile = PCHReader::getOriginalSourceFile(ImplicitIncludePCH); |
| 745 | // FIXME: Don't fail like this. |
| 746 | if (OriginalFile.empty()) |
| 747 | exit(1); |
| 748 | OrderedPaths.push_back(std::make_pair(ImplicitIncludePCH.getPosition(), |
| 749 | &OriginalFile)); |
| 750 | } |
| 751 | for (unsigned i = 0, e = ImplicitIncludes.size(); i != e; ++i) |
| 752 | OrderedPaths.push_back(std::make_pair(ImplicitIncludes.getPosition(i), |
| 753 | &ImplicitIncludes[i])); |
| 754 | llvm::array_pod_sort(OrderedPaths.begin(), OrderedPaths.end()); |
| 755 | |
| 756 | for (unsigned i = 0, e = OrderedPaths.size(); i != e; ++i) |
| 757 | Opts.addInclude(*OrderedPaths[i].second); |
| 758 | } |
Daniel Dunbar | 84dfbfd | 2009-11-11 07:26:12 +0000 | [diff] [blame] | 759 | |
| 760 | void clang::InitializeLangOptions(LangOptions &Options, LangKind LK, |
| 761 | TargetInfo &Target, |
Daniel Dunbar | 979586e | 2009-11-11 09:38:56 +0000 | [diff] [blame^] | 762 | const CompileOptions &CompileOpts) { |
Daniel Dunbar | 84dfbfd | 2009-11-11 07:26:12 +0000 | [diff] [blame] | 763 | using namespace langoptions; |
| 764 | |
| 765 | bool NoPreprocess = false; |
| 766 | |
| 767 | switch (LK) { |
| 768 | default: assert(0 && "Unknown language kind!"); |
| 769 | case langkind_asm_cpp: |
| 770 | Options.AsmPreprocessor = 1; |
| 771 | // FALLTHROUGH |
| 772 | case langkind_c_cpp: |
| 773 | NoPreprocess = true; |
| 774 | // FALLTHROUGH |
| 775 | case langkind_c: |
| 776 | // Do nothing. |
| 777 | break; |
| 778 | case langkind_cxx_cpp: |
| 779 | NoPreprocess = true; |
| 780 | // FALLTHROUGH |
| 781 | case langkind_cxx: |
| 782 | Options.CPlusPlus = 1; |
| 783 | break; |
| 784 | case langkind_objc_cpp: |
| 785 | NoPreprocess = true; |
| 786 | // FALLTHROUGH |
| 787 | case langkind_objc: |
| 788 | Options.ObjC1 = Options.ObjC2 = 1; |
| 789 | break; |
| 790 | case langkind_objcxx_cpp: |
| 791 | NoPreprocess = true; |
| 792 | // FALLTHROUGH |
| 793 | case langkind_objcxx: |
| 794 | Options.ObjC1 = Options.ObjC2 = 1; |
| 795 | Options.CPlusPlus = 1; |
| 796 | break; |
| 797 | case langkind_ocl: |
| 798 | Options.OpenCL = 1; |
| 799 | Options.AltiVec = 1; |
| 800 | Options.CXXOperatorNames = 1; |
| 801 | Options.LaxVectorConversions = 1; |
| 802 | break; |
| 803 | } |
| 804 | |
| 805 | if (ObjCExclusiveGC) |
| 806 | Options.setGCMode(LangOptions::GCOnly); |
| 807 | else if (ObjCEnableGC) |
| 808 | Options.setGCMode(LangOptions::HybridGC); |
| 809 | |
| 810 | if (ObjCEnableGCBitmapPrint) |
| 811 | Options.ObjCGCBitmapPrint = 1; |
| 812 | |
| 813 | if (AltiVec) |
| 814 | Options.AltiVec = 1; |
| 815 | |
| 816 | if (PThread) |
| 817 | Options.POSIXThreads = 1; |
| 818 | |
| 819 | Options.setVisibilityMode(SymbolVisibility); |
| 820 | Options.OverflowChecking = OverflowChecking; |
| 821 | |
| 822 | |
| 823 | // Allow the target to set the default the language options as it sees fit. |
| 824 | Target.getDefaultLangOptions(Options); |
| 825 | |
| 826 | // Pass the map of target features to the target for validation and |
| 827 | // processing. |
Daniel Dunbar | 979586e | 2009-11-11 09:38:56 +0000 | [diff] [blame^] | 828 | Target.HandleTargetFeatures(CompileOpts.Features); |
Daniel Dunbar | 84dfbfd | 2009-11-11 07:26:12 +0000 | [diff] [blame] | 829 | |
| 830 | if (LangStd == lang_unspecified) { |
| 831 | // Based on the base language, pick one. |
| 832 | switch (LK) { |
| 833 | case langkind_ast: assert(0 && "Invalid call for AST inputs"); |
| 834 | case lang_unspecified: assert(0 && "Unknown base language"); |
| 835 | case langkind_ocl: |
| 836 | LangStd = lang_c99; |
| 837 | break; |
| 838 | case langkind_c: |
| 839 | case langkind_asm_cpp: |
| 840 | case langkind_c_cpp: |
| 841 | case langkind_objc: |
| 842 | case langkind_objc_cpp: |
| 843 | LangStd = lang_gnu99; |
| 844 | break; |
| 845 | case langkind_cxx: |
| 846 | case langkind_cxx_cpp: |
| 847 | case langkind_objcxx: |
| 848 | case langkind_objcxx_cpp: |
| 849 | LangStd = lang_gnucxx98; |
| 850 | break; |
| 851 | } |
| 852 | } |
| 853 | |
| 854 | switch (LangStd) { |
| 855 | default: assert(0 && "Unknown language standard!"); |
| 856 | |
| 857 | // Fall through from newer standards to older ones. This isn't really right. |
| 858 | // FIXME: Enable specifically the right features based on the language stds. |
| 859 | case lang_gnucxx0x: |
| 860 | case lang_cxx0x: |
| 861 | Options.CPlusPlus0x = 1; |
| 862 | // FALL THROUGH |
| 863 | case lang_gnucxx98: |
| 864 | case lang_cxx98: |
| 865 | Options.CPlusPlus = 1; |
| 866 | Options.CXXOperatorNames = !NoOperatorNames; |
| 867 | // FALL THROUGH. |
| 868 | case lang_gnu99: |
| 869 | case lang_c99: |
| 870 | Options.C99 = 1; |
| 871 | Options.HexFloats = 1; |
| 872 | // FALL THROUGH. |
| 873 | case lang_gnu89: |
| 874 | Options.BCPLComment = 1; // Only for C99/C++. |
| 875 | // FALL THROUGH. |
| 876 | case lang_c94: |
| 877 | Options.Digraphs = 1; // C94, C99, C++. |
| 878 | // FALL THROUGH. |
| 879 | case lang_c89: |
| 880 | break; |
| 881 | } |
| 882 | |
| 883 | // GNUMode - Set if we're in gnu99, gnu89, gnucxx98, etc. |
| 884 | switch (LangStd) { |
| 885 | default: assert(0 && "Unknown language standard!"); |
| 886 | case lang_gnucxx0x: |
| 887 | case lang_gnucxx98: |
| 888 | case lang_gnu99: |
| 889 | case lang_gnu89: |
| 890 | Options.GNUMode = 1; |
| 891 | break; |
| 892 | case lang_cxx0x: |
| 893 | case lang_cxx98: |
| 894 | case lang_c99: |
| 895 | case lang_c94: |
| 896 | case lang_c89: |
| 897 | Options.GNUMode = 0; |
| 898 | break; |
| 899 | } |
| 900 | |
| 901 | if (Options.CPlusPlus) { |
| 902 | Options.C99 = 0; |
| 903 | Options.HexFloats = 0; |
| 904 | } |
| 905 | |
| 906 | if (LangStd == lang_c89 || LangStd == lang_c94 || LangStd == lang_gnu89) |
| 907 | Options.ImplicitInt = 1; |
| 908 | else |
| 909 | Options.ImplicitInt = 0; |
| 910 | |
| 911 | // Mimicing gcc's behavior, trigraphs are only enabled if -trigraphs |
| 912 | // is specified, or -std is set to a conforming mode. |
| 913 | Options.Trigraphs = !Options.GNUMode; |
| 914 | if (Trigraphs.getPosition()) |
| 915 | Options.Trigraphs = Trigraphs; // Command line option wins if specified. |
| 916 | |
| 917 | // If in a conformant language mode (e.g. -std=c99) Blocks defaults to off |
| 918 | // even if they are normally on for the target. In GNU modes (e.g. |
| 919 | // -std=gnu99) the default for blocks depends on the target settings. |
| 920 | // However, blocks are not turned off when compiling Obj-C or Obj-C++ code. |
| 921 | if (!Options.ObjC1 && !Options.GNUMode) |
| 922 | Options.Blocks = 0; |
| 923 | |
| 924 | // Default to not accepting '$' in identifiers when preprocessing assembler, |
| 925 | // but do accept when preprocessing C. FIXME: these defaults are right for |
| 926 | // darwin, are they right everywhere? |
| 927 | Options.DollarIdents = LK != langkind_asm_cpp; |
| 928 | if (DollarsInIdents.getPosition()) // Explicit setting overrides default. |
| 929 | Options.DollarIdents = DollarsInIdents; |
| 930 | |
| 931 | if (PascalStrings.getPosition()) |
| 932 | Options.PascalStrings = PascalStrings; |
| 933 | if (MSExtensions.getPosition()) |
| 934 | Options.Microsoft = MSExtensions; |
| 935 | Options.WritableStrings = WritableStrings; |
| 936 | if (NoLaxVectorConversions.getPosition()) |
| 937 | Options.LaxVectorConversions = 0; |
| 938 | Options.Exceptions = Exceptions; |
| 939 | Options.Rtti = Rtti; |
| 940 | if (EnableBlocks.getPosition()) |
| 941 | Options.Blocks = EnableBlocks; |
| 942 | if (CharIsSigned.getPosition()) |
| 943 | Options.CharIsSigned = CharIsSigned; |
| 944 | if (ShortWChar.getPosition()) |
| 945 | Options.ShortWChar = ShortWChar; |
| 946 | |
| 947 | if (!AllowBuiltins) |
| 948 | Options.NoBuiltin = 1; |
| 949 | if (Freestanding) |
| 950 | Options.Freestanding = Options.NoBuiltin = 1; |
| 951 | |
| 952 | if (EnableHeinousExtensions) |
| 953 | Options.HeinousExtensions = 1; |
| 954 | |
| 955 | if (AccessControl) |
| 956 | Options.AccessControl = 1; |
| 957 | |
| 958 | Options.ElideConstructors = !NoElideConstructors; |
| 959 | |
| 960 | // OpenCL and C++ both have bool, true, false keywords. |
| 961 | Options.Bool = Options.OpenCL | Options.CPlusPlus; |
| 962 | |
| 963 | Options.MathErrno = MathErrno; |
| 964 | |
| 965 | Options.InstantiationDepth = TemplateDepth; |
| 966 | |
| 967 | // Override the default runtime if the user requested it. |
| 968 | if (NeXTRuntime) |
| 969 | Options.NeXTRuntime = 1; |
| 970 | else if (GNURuntime) |
| 971 | Options.NeXTRuntime = 0; |
| 972 | |
| 973 | if (!ObjCConstantStringClass.empty()) |
| 974 | Options.ObjCConstantStringClass = ObjCConstantStringClass.c_str(); |
| 975 | |
| 976 | if (ObjCNonFragileABI) |
| 977 | Options.ObjCNonFragileABI = 1; |
| 978 | |
| 979 | if (EmitAllDecls) |
| 980 | Options.EmitAllDecls = 1; |
| 981 | |
| 982 | // The __OPTIMIZE_SIZE__ define is tied to -Oz, which we don't support. |
| 983 | Options.OptimizeSize = 0; |
| 984 | Options.Optimize = !!CompileOpts.OptimizationLevel; |
| 985 | |
| 986 | assert(PICLevel <= 2 && "Invalid value for -pic-level"); |
| 987 | Options.PICLevel = PICLevel; |
| 988 | |
| 989 | Options.GNUInline = !Options.C99; |
| 990 | // FIXME: This is affected by other options (-fno-inline). |
| 991 | |
| 992 | // This is the __NO_INLINE__ define, which just depends on things like the |
| 993 | // optimization level and -fno-inline, not actually whether the backend has |
| 994 | // inlining enabled. |
| 995 | Options.NoInline = !CompileOpts.OptimizationLevel; |
| 996 | |
| 997 | Options.Static = StaticDefine; |
| 998 | |
| 999 | switch (StackProtector) { |
| 1000 | default: |
| 1001 | assert(StackProtector <= 2 && "Invalid value for -stack-protector"); |
| 1002 | case -1: break; |
| 1003 | case 0: Options.setStackProtectorMode(LangOptions::SSPOff); break; |
| 1004 | case 1: Options.setStackProtectorMode(LangOptions::SSPOn); break; |
| 1005 | case 2: Options.setStackProtectorMode(LangOptions::SSPReq); break; |
| 1006 | } |
| 1007 | |
| 1008 | if (MainFileName.getPosition()) |
| 1009 | Options.setMainFileName(MainFileName.c_str()); |
| 1010 | |
| 1011 | Target.setForcedLangOptions(Options); |
| 1012 | } |