Mercurial > projects > ldc
comparison gen/cl_helpers.cpp @ 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 | 40d7f9b7357f |
comparison
equal
deleted
inserted
replaced
985:bce024c60adc | 986:a8cb25d478c4 |
---|---|
1 #include "gen/cl_helpers.h" | |
2 | |
3 #include "dmd/root.h" | |
4 #include "dmd/mem.h" | |
5 | |
6 #include <cctype> // isupper, tolower | |
7 #include <algorithm> | |
8 #include <utility> | |
9 #include <stdarg.h> | |
10 | |
11 namespace opts { | |
12 | |
13 // Helper function | |
14 static char toLower(char c) { | |
15 if (isupper(c)) | |
16 return tolower(c); | |
17 return c; | |
18 } | |
19 | |
20 bool FlagParser::parse(cl::Option &O, const char *ArgName, const std::string &Arg, bool &Val) { | |
21 // Make a std::string out of it to make comparisons easier | |
22 // (and avoid repeated conversion) | |
23 std::string argname = ArgName; | |
24 | |
25 typedef std::vector<std::pair<std::string, bool> >::iterator It; | |
26 for (It I = switches.begin(), E = switches.end(); I != E; ++I) { | |
27 std::string name = I->first; | |
28 if (name == argname | |
29 || (name.length() < argname.length() | |
30 && argname.substr(0, name.length()) == name | |
31 && argname[name.length()] == '=')) { | |
32 | |
33 if (!cl::parser<bool>::parse(O, ArgName, Arg, Val)) { | |
34 Val = (Val == I->second); | |
35 return false; | |
36 } | |
37 // Invalid option value | |
38 break; | |
39 } | |
40 } | |
41 return true; | |
42 } | |
43 | |
44 void FlagParser::getExtraOptionNames(std::vector<const char*> &Names) { | |
45 typedef std::vector<std::pair<std::string, bool> >::iterator It; | |
46 for (It I = switches.begin() + 1, E = switches.end(); I != E; ++I) { | |
47 Names.push_back(I->first.c_str()); | |
48 } | |
49 } | |
50 | |
51 | |
52 MultiSetter::MultiSetter(bool invert, bool* p, ...) { | |
53 this->invert = invert; | |
54 if (p) { | |
55 locations.push_back(p); | |
56 va_list va; | |
57 va_start(va, p); | |
58 while (p = va_arg(va, bool*)) { | |
59 locations.push_back(p); | |
60 } | |
61 } | |
62 } | |
63 | |
64 void MultiSetter::operator=(bool val) { | |
65 typedef std::vector<bool*>::iterator It; | |
66 for (It I = locations.begin(), E = locations.end(); I != E; ++I) { | |
67 **I = (val != invert); | |
68 } | |
69 } | |
70 | |
71 | |
72 void ArrayAdapter::push_back(const char* cstr) { | |
73 if (!cstr || !*cstr) | |
74 error("Expected argument to '-%s'", name); | |
75 | |
76 if (!*arrp) | |
77 *arrp = new Array; | |
78 (*arrp)->push(mem.strdup(cstr)); | |
79 } | |
80 | |
81 } // namespace opts |