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