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