annotate gen/cl_helpers.cpp @ 1650:40bd4a0d4870

Update to work with LLVM 2.7. Removed use of dyn_cast, llvm no compiles without exceptions and rtti by default. We do need exceptions for the libconfig stuff, but rtti isn't necessary (anymore). Debug info needs to be rewritten, as in LLVM 2.7 the format has completely changed. To have something to look at while rewriting, the old code has been wrapped inside #ifndef DISABLE_DEBUG_INFO , this means that you have to define this to compile at the moment. Updated tango 0.99.9 patch to include updated EH runtime code, which is needed for LLVM 2.7 as well.
author Tomas Lindquist Olsen
date Wed, 19 May 2010 12:42:32 +0200
parents b30fe7e1dbb9
children
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
1063
40d7f9b7357f Fixed some #includes to be correct for both D1 and D2
Frits van Bommel <fvbommel wxs.nl>
parents: 986
diff changeset
3 #include "root.h"
1103
b30fe7e1dbb9 - Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1063
diff changeset
4 #include "rmem.h"
986
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
1650
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1103
diff changeset
20 bool FlagParser::parse(cl::Option &O, llvm::StringRef ArgName, llvm::StringRef Arg, bool &Val) {
986
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)
1650
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1103
diff changeset
23 llvm::StringRef argname = ArgName;
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1103
diff changeset
24
986
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) {
1650
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1103
diff changeset
27 llvm::StringRef name = I->first;
986
a8cb25d478c4 Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
28 if (name == argname
1650
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1103
diff changeset
29 || (name.size() < argname.size()
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1103
diff changeset
30 && argname.substr(0, name.size()) == name
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1103
diff changeset
31 && argname[name.size()] == '=')) {
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1103
diff changeset
32
986
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
1650
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1103
diff changeset
44 void FlagParser::getExtraOptionNames(llvm::SmallVectorImpl<const char*> &Names) {
986
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) {
1650
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1103
diff changeset
47 Names.push_back(I->first.data());
986
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 }
1650
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1103
diff changeset
63
986
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);
1650
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1103
diff changeset
75
986
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