1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401
|
//===-- cl_options.cpp ----------------------------------------------------===//
//
// LDC – the LLVM D compiler
//
// This file is distributed under the BSD-style LDC license. See the LICENSE
// file for details.
//
//===----------------------------------------------------------------------===//
#include "driver/cl_options.h"
#include "mars.h"
#include "gen/cl_helpers.h"
#include "gen/logger.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Target/TargetMachine.h"
#if LDC_LLVM_VER >= 303
#include "llvm/IR/DataLayout.h"
#elif LDC_LLVM_VER == 302
#include "llvm/DataLayout.h"
#else
#include "llvm/Target/TargetData.h"
#endif
namespace opts {
// Positional options first, in order:
cl::list<std::string> fileList(
cl::Positional, cl::desc("files"));
cl::list<std::string> runargs("run",
cl::desc("Runs the resulting program, passing the remaining arguments to it"),
cl::Positional,
cl::PositionalEatsArgs);
static cl::opt<ubyte, true> useDeprecated(
cl::desc("Allow deprecated code/language features:"),
cl::ZeroOrMore,
cl::values(
clEnumValN(0, "de", "Do not allow deprecated features"),
clEnumValN(1, "d", "Silently allow deprecated features"),
clEnumValN(2, "dw", "Warn about the use of deprecated features"),
clEnumValEnd),
cl::location(global.params.useDeprecated),
cl::init(2));
cl::opt<bool, true> enforcePropertySyntax("property",
cl::desc("Enforce property syntax"),
cl::ZeroOrMore,
cl::location(global.params.enforcePropertySyntax));
static cl::opt<ubyte, true> useDv1(
cl::desc("Force language version:"),
cl::ZeroOrMore,
cl::values(
clEnumValN(1, "v1", "D language version 1.00"),
clEnumValEnd),
cl::location(global.params.Dversion),
cl::init(2),
cl::Hidden);
cl::opt<bool> compileOnly("c",
cl::desc("Do not link"),
cl::ZeroOrMore);
cl::opt<bool> createStaticLib("lib",
cl::desc("Create static library"),
cl::ZeroOrMore);
cl::opt<bool> createSharedLib("shared",
cl::desc("Create shared library"),
cl::ZeroOrMore);
static cl::opt<bool, true> verbose("v",
cl::desc("Verbose"),
cl::ZeroOrMore,
cl::location(global.params.verbose));
static cl::opt<bool, true> verbose_cg("v-cg",
cl::desc("Verbose codegen"),
cl::ZeroOrMore,
cl::location(global.params.verbose_cg));
static cl::opt<ubyte, true> warnings(
cl::desc("Warnings:"),
cl::ZeroOrMore,
cl::values(
clEnumValN(1, "w", "Enable warnings"),
clEnumValN(2, "wi", "Enable informational warnings"),
clEnumValEnd),
cl::location(global.params.warnings),
cl::init(0));
static cl::opt<bool, true> ignoreUnsupportedPragmas("ignore",
cl::desc("Ignore unsupported pragmas"),
cl::ZeroOrMore,
cl::location(global.params.ignoreUnsupportedPragmas));
static cl::opt<ubyte, true> debugInfo(
cl::desc("Generating debug information:"),
cl::ZeroOrMore,
cl::values(
clEnumValN(1, "g", "Generate debug information"),
clEnumValN(2, "gc", "Same as -g, but pretend to be C"),
clEnumValEnd),
cl::location(global.params.symdebug),
cl::init(0));
cl::opt<bool> noAsm("noasm",
cl::desc("Disallow use of inline assembler"));
// Output file options
cl::opt<bool> dontWriteObj("o-",
cl::desc("Do not write object file"));
cl::opt<std::string> objectFile("of",
cl::value_desc("filename"),
cl::Prefix,
cl::desc("Use <filename> as output file name"));
cl::opt<std::string> objectDir("od",
cl::value_desc("objdir"),
cl::Prefix,
cl::desc("Write object files to directory <objdir>"));
cl::opt<std::string> soname("soname",
cl::value_desc("soname"),
cl::Hidden,
cl::Prefix,
cl::desc("Use <soname> as output shared library soname"));
// Output format options
cl::opt<bool> output_bc("output-bc",
cl::desc("Write LLVM bitcode"));
cl::opt<bool> output_ll("output-ll",
cl::desc("Write LLVM IR"));
cl::opt<bool> output_s("output-s",
cl::desc("Write native assembly"));
cl::opt<cl::boolOrDefault> output_o("output-o",
cl::desc("Write native object"));
// Disabling Red Zone
cl::opt<bool, true> disableRedZone("disable-red-zone",
cl::desc("Do not emit code that uses the red zone."),
cl::location(global.params.disableRedZone),
cl::init(false));
// DDoc options
static cl::opt<bool, true> doDdoc("D",
cl::desc("Generate documentation"),
cl::location(global.params.doDocComments));
cl::opt<std::string> ddocDir("Dd",
cl::desc("Write documentation file to <docdir> directory"),
cl::value_desc("docdir"),
cl::Prefix);
cl::opt<std::string> ddocFile("Df",
cl::desc("Write documentation file to <filename>"),
cl::value_desc("filename"),
cl::Prefix);
// Json options
static cl::opt<bool, true> doJson("X",
cl::desc("Generate JSON file"),
cl::location(global.params.doXGeneration));
cl::opt<std::string> jsonFile("Xf",
cl::desc("Write JSON file to <filename>"),
cl::value_desc("filename"),
cl::Prefix);
// Header generation options
static cl::opt<bool, true> doHdrGen("H",
cl::desc("Generate 'header' file"),
cl::location(global.params.doHdrGeneration));
cl::opt<std::string> hdrDir("Hd",
cl::desc("Write 'header' file to <hdrdir> directory"),
cl::value_desc("hdrdir"),
cl::Prefix);
cl::opt<std::string> hdrFile("Hf",
cl::desc("Write 'header' file to <filename>"),
cl::value_desc("filename"),
cl::Prefix);
static cl::opt<bool, true> hdrKeepAllBodies("Hkeep-all-bodies",
cl::desc("Keep all function bodies in .di files"),
cl::ZeroOrMore,
cl::location(global.params.hdrKeepAllBodies));
static cl::opt<bool, true> unittest("unittest",
cl::desc("Compile in unit tests"),
cl::location(global.params.useUnitTests));
static StringsAdapter strImpPathStore("J", global.params.fileImppath);
static cl::list<std::string, StringsAdapter> stringImportPaths("J",
cl::desc("Where to look for string imports"),
cl::value_desc("path"),
cl::location(strImpPathStore),
cl::Prefix);
static cl::opt<bool, true> addMain("main",
cl::desc("Add empty main() (e.g. for unittesting)"),
cl::ZeroOrMore,
cl::location(global.params.addMain));
// -d-debug is a bit messy, it has 3 modes:
// -d-debug=ident, -d-debug=level and -d-debug (without argument)
// That last of these must be acted upon immediately to ensure proper
// interaction with other options, so it needs some special handling:
std::vector<std::string> debugArgs;
struct D_DebugStorage {
void push_back(const std::string& str) {
if (str.empty()) {
// Bare "-d-debug" has a special meaning.
global.params.useAssert = true;
global.params.useArrayBounds = 2;
global.params.useInvariants = true;
global.params.useIn = true;
global.params.useOut = true;
debugArgs.push_back("1");
} else {
debugArgs.push_back(str);
}
}
};
static D_DebugStorage dds;
// -debug is already declared in LLVM (at least, in debug builds),
// so we need to be a bit more verbose.
static cl::list<std::string, D_DebugStorage> debugVersionsOption("d-debug",
cl::desc("Compile in debug code >= <level> or identified by <idents>."),
cl::value_desc("level/idents"),
cl::location(dds),
cl::CommaSeparated,
cl::ValueOptional);
// -version is also declared in LLVM, so again we need to be a bit more verbose.
cl::list<std::string> versions("d-version",
cl::desc("Compile in version code >= <level> or identified by <idents>"),
cl::value_desc("level/idents"),
cl::CommaSeparated);
static StringsAdapter linkSwitchStore("L", global.params.linkswitches);
static cl::list<std::string, StringsAdapter> linkerSwitches("L",
cl::desc("Pass <linkerflag> to the linker"),
cl::value_desc("linkerflag"),
cl::location(linkSwitchStore),
cl::Prefix);
cl::opt<std::string> moduleDepsFile("deps",
cl::desc("Write module dependencies to filename"),
cl::value_desc("filename"));
cl::opt<std::string> mArch("march",
cl::desc("Architecture to generate code for:"));
cl::opt<bool> m32bits("m32",
cl::desc("32 bit target"),
cl::ZeroOrMore);
cl::opt<bool> m64bits("m64",
cl::desc("64 bit target"),
cl::ZeroOrMore);
cl::opt<std::string> mCPU("mcpu",
cl::desc("Target a specific cpu type (-mcpu=help for details)"),
cl::value_desc("cpu-name"),
cl::init(""));
cl::list<std::string> mAttrs("mattr",
cl::CommaSeparated,
cl::desc("Target specific attributes (-mattr=help for details)"),
cl::value_desc("a1,+a2,-a3,..."));
cl::opt<std::string> mTargetTriple("mtriple",
cl::desc("Override target triple"));
cl::opt<llvm::Reloc::Model> mRelocModel("relocation-model",
cl::desc("Relocation model"),
cl::init(llvm::Reloc::Default),
cl::values(
clEnumValN(llvm::Reloc::Default, "default",
"Target default relocation model"),
clEnumValN(llvm::Reloc::Static, "static",
"Non-relocatable code"),
clEnumValN(llvm::Reloc::PIC_, "pic",
"Fully relocatable, position independent code"),
clEnumValN(llvm::Reloc::DynamicNoPIC, "dynamic-no-pic",
"Relocatable external references, non-relocatable code"),
clEnumValEnd));
cl::opt<llvm::CodeModel::Model> mCodeModel("code-model",
cl::desc("Code model"),
cl::init(llvm::CodeModel::Default),
cl::values(
clEnumValN(llvm::CodeModel::Default, "default", "Target default code model"),
clEnumValN(llvm::CodeModel::Small, "small", "Small code model"),
clEnumValN(llvm::CodeModel::Kernel, "kernel", "Kernel code model"),
clEnumValN(llvm::CodeModel::Medium, "medium", "Medium code model"),
clEnumValN(llvm::CodeModel::Large, "large", "Large code model"),
clEnumValEnd));
cl::opt<FloatABI::Type> mFloatABI("float-abi",
cl::desc("ABI/operations to use for floating-point types:"),
cl::init(FloatABI::Default),
cl::values(
clEnumValN(FloatABI::Default, "default", "Target default floating-point ABI"),
clEnumValN(FloatABI::Soft, "soft", "Software floating-point ABI and operations"),
clEnumValN(FloatABI::SoftFP, "softfp", "Soft-float ABI, but hardware floating-point instructions"),
clEnumValN(FloatABI::Hard, "hard", "Hardware floating-point ABI and instructions"),
clEnumValEnd));
cl::opt<bool> disableFpElim("disable-fp-elim",
cl::desc("Disable frame pointer elimination optimization"),
cl::init(false));
static cl::opt<bool, true, FlagParser> asserts("asserts",
cl::desc("(*) Enable assertions"),
cl::value_desc("bool"),
cl::location(global.params.useAssert),
cl::init(true));
cl::opt<BoolOrDefaultAdapter, false, FlagParser> boundsChecks("boundscheck",
cl::desc("(*) Enable array bounds checks"));
static cl::opt<bool, true, FlagParser> invariants("invariants",
cl::desc("(*) Enable invariants"),
cl::location(global.params.useInvariants),
cl::init(true));
static cl::opt<bool, true, FlagParser> preconditions("preconditions",
cl::desc("(*) Enable function preconditions"),
cl::location(global.params.useIn),
cl::init(true));
static cl::opt<bool, true, FlagParser> postconditions("postconditions",
cl::desc("(*) Enable function postconditions"),
cl::location(global.params.useOut),
cl::init(true));
static MultiSetter ContractsSetter(false,
&global.params.useIn, &global.params.useOut, NULL);
static cl::opt<MultiSetter, true, FlagParser> contracts("contracts",
cl::desc("(*) Enable function pre- and post-conditions"),
cl::location(ContractsSetter));
bool nonSafeBoundsChecks = true;
static MultiSetter ReleaseSetter(true, &global.params.useAssert,
&nonSafeBoundsChecks, &global.params.useInvariants,
&global.params.useOut, &global.params.useIn, NULL);
static cl::opt<MultiSetter, true, cl::parser<bool> > release("release",
cl::desc("Disables asserts, invariants, contracts and boundscheck"),
cl::location(ReleaseSetter),
cl::ValueDisallowed);
cl::opt<bool, true> singleObj("singleobj",
cl::desc("Create only a single output object file"),
cl::location(global.params.singleObj));
cl::opt<bool> linkonceTemplates("linkonce-templates",
cl::desc("Use linkonce_odr linkage for template symbols instead of weak_odr"),
cl::ZeroOrMore);
cl::opt<bool> disableLinkerStripDead("disable-linker-strip-dead",
cl::desc("Do not try to remove unused symbols during linking"),
cl::init(false));
cl::opt<bool, true> allinst("allinst",
cl::desc("generate code for all template instantiations"),
cl::location(global.params.allInst));
cl::opt<unsigned, true> nestedTemplateDepth("template-depth",
cl::desc("(experimental) set maximum number of nested template instantiations"),
cl::location(global.params.nestedTmpl),
cl::init(500));
static cl::extrahelp footer("\n"
"-d-debug can also be specified without options, in which case it enables all\n"
"debug checks (i.e. (asserts, boundchecks, contracts and invariants) as well\n"
"as acting as -d-debug=1\n\n"
"Options marked with (*) also have a -disable-FOO variant with inverted\n"
"meaning.\n");
} // namespace opts
|