annotate gen/cl_helpers.h @ 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 3171f67ad006
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 #ifndef LDC_CL_HELPERS_H
a8cb25d478c4 Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
2 #define LDC_CL_HELPERS_H
a8cb25d478c4 Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
3
a8cb25d478c4 Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
4 #include <string>
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 "llvm/Support/CommandLine.h"
a8cb25d478c4 Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
7 #include "llvm/Support/Compiler.h"
a8cb25d478c4 Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
8
a8cb25d478c4 Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
9 struct Array;
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 namespace cl = llvm::cl;
1650
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1200
diff changeset
13
986
a8cb25d478c4 Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
14 /// Helper class for fancier options
a8cb25d478c4 Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
15 class FlagParser : public cl::parser<bool> {
a8cb25d478c4 Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
16 std::vector<std::pair<std::string, bool> > switches;
a8cb25d478c4 Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
17 public:
a8cb25d478c4 Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
18 template <class Opt>
a8cb25d478c4 Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
19 void initialize(Opt &O) {
a8cb25d478c4 Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
20 std::string Name = O.ArgStr;
a8cb25d478c4 Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
21 switches.push_back(make_pair("enable-" + Name, true));
a8cb25d478c4 Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
22 switches.push_back(make_pair("disable-" + Name, false));
a8cb25d478c4 Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
23 // Replace <foo> with -enable-<foo>
1650
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1200
diff changeset
24 O.ArgStr = switches[0].first.data();
986
a8cb25d478c4 Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
25 }
1650
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1200
diff changeset
26
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1200
diff changeset
27 bool parse(cl::Option &O, llvm::StringRef ArgName, llvm::StringRef ArgValue, bool &Val);
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1200
diff changeset
28
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1200
diff changeset
29 void 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
30 };
1650
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1200
diff changeset
31
986
a8cb25d478c4 Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
32 /// Helper class for options that set multiple flags
a8cb25d478c4 Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
33 class MultiSetter {
a8cb25d478c4 Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
34 std::vector<bool*> locations;
a8cb25d478c4 Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
35 bool invert;
a8cb25d478c4 Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
36 MultiSetter(bool); //not implemented, disable auto-conversion
a8cb25d478c4 Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
37 public:
a8cb25d478c4 Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
38 MultiSetter(bool invert, bool* p, ...) END_WITH_NULL;
1650
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1200
diff changeset
39
986
a8cb25d478c4 Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
40 void operator=(bool val);
a8cb25d478c4 Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
41 };
1650
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1200
diff changeset
42
986
a8cb25d478c4 Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
43 /// Helper class to fill Array with char* when given strings
a8cb25d478c4 Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
44 /// (Errors on empty strings)
a8cb25d478c4 Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
45 class ArrayAdapter {
a8cb25d478c4 Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
46 const char* name;
a8cb25d478c4 Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
47 Array** arrp;
a8cb25d478c4 Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
48 public:
a8cb25d478c4 Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
49 ArrayAdapter(const char* name_, Array*& arr) {
a8cb25d478c4 Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
50 name = name_;
a8cb25d478c4 Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
51 arrp = &arr;
a8cb25d478c4 Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
52 assert(name);
a8cb25d478c4 Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
53 assert(arrp);
a8cb25d478c4 Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
54 }
1650
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1200
diff changeset
55
986
a8cb25d478c4 Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
56 void push_back(const char* cstr);
1650
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1200
diff changeset
57
986
a8cb25d478c4 Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
58 void push_back(const std::string& str) {
a8cb25d478c4 Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
59 push_back(str.c_str());
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 };
1650
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1200
diff changeset
62
1175
cc1efa23030a Enable inlining by default for -O3+.
Frits van Bommel <fvbommel wxs.nl>
parents: 986
diff changeset
63 /// Helper class to allow use of a parser<bool> with BoolOrDefault
cc1efa23030a Enable inlining by default for -O3+.
Frits van Bommel <fvbommel wxs.nl>
parents: 986
diff changeset
64 class BoolOrDefaultAdapter {
cc1efa23030a Enable inlining by default for -O3+.
Frits van Bommel <fvbommel wxs.nl>
parents: 986
diff changeset
65 cl::boolOrDefault value;
cc1efa23030a Enable inlining by default for -O3+.
Frits van Bommel <fvbommel wxs.nl>
parents: 986
diff changeset
66 public:
cc1efa23030a Enable inlining by default for -O3+.
Frits van Bommel <fvbommel wxs.nl>
parents: 986
diff changeset
67 operator cl::boolOrDefault() {
cc1efa23030a Enable inlining by default for -O3+.
Frits van Bommel <fvbommel wxs.nl>
parents: 986
diff changeset
68 return value;
cc1efa23030a Enable inlining by default for -O3+.
Frits van Bommel <fvbommel wxs.nl>
parents: 986
diff changeset
69 }
1650
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1200
diff changeset
70
1175
cc1efa23030a Enable inlining by default for -O3+.
Frits van Bommel <fvbommel wxs.nl>
parents: 986
diff changeset
71 void operator=(cl::boolOrDefault val) {
cc1efa23030a Enable inlining by default for -O3+.
Frits van Bommel <fvbommel wxs.nl>
parents: 986
diff changeset
72 value = val;
cc1efa23030a Enable inlining by default for -O3+.
Frits van Bommel <fvbommel wxs.nl>
parents: 986
diff changeset
73 }
1650
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1200
diff changeset
74
1175
cc1efa23030a Enable inlining by default for -O3+.
Frits van Bommel <fvbommel wxs.nl>
parents: 986
diff changeset
75 void operator=(bool val) {
cc1efa23030a Enable inlining by default for -O3+.
Frits van Bommel <fvbommel wxs.nl>
parents: 986
diff changeset
76 *this = (val ? cl::BOU_TRUE : cl::BOU_FALSE);
cc1efa23030a Enable inlining by default for -O3+.
Frits van Bommel <fvbommel wxs.nl>
parents: 986
diff changeset
77 }
cc1efa23030a Enable inlining by default for -O3+.
Frits van Bommel <fvbommel wxs.nl>
parents: 986
diff changeset
78 };
986
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 #endif