comparison gen/cl_helpers.h @ 986:a8cb25d478c4

Use LLVM-style command line (instead of DMD-style) Note: For a backward compatible interface, use the new bin/ldmd script. It supports all old options while passing on anything it doesn't recognize. Some changes caused by this: * -debug and -version are now -d-debug and -d-version due to a conflict with standard LLVM options. * All "flag" options now allow an optional =true/=1/=false/=0 suffix. * Some "hidden debug switches" starting with "--" were renamed because LLVM doesn't care about the number of dashes, so they were conflicting with other options (such as -c). The new versions start with "-hidden-debug-" instead of "--" * --help works, but has a non-zero exit code. This breaks some Tango scripts which use it to test for compiler existence. See tango.patch. Some changes not (directly) caused by this; * (-enable/-disable)-FOO options are now available for pre- and postconditions. * -march is used instead of -m (like other LLVM programs), but -m is an alias for it. * -defaultlib, -debuglib, -d-debug and -d-version allow comma-separated values. The effect should be identical to specifying the same option multiple times. I decided against allowing these for some other options because paths might contain commas on some systems. * -fPIC is removed in favor of the standard LLVM option -relocation-model=pic Bug: * If -run is specified as the last argument in DFLAGS, no error is generated. (Not very serious IMHO)
author Frits van Bommel <fvbommel wxs.nl>
date Wed, 25 Feb 2009 17:34:51 +0100
parents
children cc1efa23030a
comparison
equal deleted inserted replaced
985:bce024c60adc 986:a8cb25d478c4
1 #ifndef LDC_CL_HELPERS_H
2 #define LDC_CL_HELPERS_H
3
4 #include <string>
5
6 #include "llvm/Support/CommandLine.h"
7 #include "llvm/Support/Compiler.h"
8
9 struct Array;
10
11 namespace opts {
12 namespace cl = llvm::cl;
13
14 /// Helper class for fancier options
15 class FlagParser : public cl::parser<bool> {
16 std::vector<std::pair<std::string, bool> > switches;
17 public:
18 template <class Opt>
19 void initialize(Opt &O) {
20 assert(!(O.getMiscFlags() & cl::AllowInverse)
21 && "FlagParser doesn't support redundant AllowInverse flag");
22
23 std::string Name = O.ArgStr;
24 switches.push_back(make_pair("enable-" + Name, true));
25 switches.push_back(make_pair("disable-" + Name, false));
26 // Replace <foo> with -enable-<foo>
27 O.ArgStr = switches[0].first.c_str();
28 }
29
30 bool parse(cl::Option &O, const char *ArgName, const std::string &ArgValue, bool &Val);
31
32 void getExtraOptionNames(std::vector<const char*> &Names);
33 };
34
35 /// Helper class for options that set multiple flags
36 class MultiSetter {
37 std::vector<bool*> locations;
38 bool invert;
39 MultiSetter(bool); //not implemented, disable auto-conversion
40 public:
41 MultiSetter(bool invert, bool* p, ...) END_WITH_NULL;
42
43 void operator=(bool val);
44 };
45
46 /// Helper class to fill Array with char* when given strings
47 /// (Errors on empty strings)
48 class ArrayAdapter {
49 const char* name;
50 Array** arrp;
51 public:
52 ArrayAdapter(const char* name_, Array*& arr) {
53 name = name_;
54 arrp = &arr;
55 assert(name);
56 assert(arrp);
57 }
58
59 void push_back(const char* cstr);
60
61 void push_back(const std::string& str) {
62 push_back(str.c_str());
63 }
64 };
65
66 }
67
68 #endif