comparison 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
comparison
equal deleted inserted replaced
1649:36da40ecbbe0 1650:40bd4a0d4870
8 8
9 struct Array; 9 struct Array;
10 10
11 namespace opts { 11 namespace opts {
12 namespace cl = llvm::cl; 12 namespace cl = llvm::cl;
13 13
14 /// Helper class for fancier options 14 /// Helper class for fancier options
15 class FlagParser : public cl::parser<bool> { 15 class FlagParser : public cl::parser<bool> {
16 std::vector<std::pair<std::string, bool> > switches; 16 std::vector<std::pair<std::string, bool> > switches;
17 public: 17 public:
18 template <class Opt> 18 template <class Opt>
19 void initialize(Opt &O) { 19 void initialize(Opt &O) {
20 std::string Name = O.ArgStr; 20 std::string Name = O.ArgStr;
21 switches.push_back(make_pair("enable-" + Name, true)); 21 switches.push_back(make_pair("enable-" + Name, true));
22 switches.push_back(make_pair("disable-" + Name, false)); 22 switches.push_back(make_pair("disable-" + Name, false));
23 // Replace <foo> with -enable-<foo> 23 // Replace <foo> with -enable-<foo>
24 O.ArgStr = switches[0].first.c_str(); 24 O.ArgStr = switches[0].first.data();
25 } 25 }
26 26
27 bool parse(cl::Option &O, const char *ArgName, const std::string &ArgValue, bool &Val); 27 bool parse(cl::Option &O, llvm::StringRef ArgName, llvm::StringRef ArgValue, bool &Val);
28 28
29 void getExtraOptionNames(std::vector<const char*> &Names); 29 void getExtraOptionNames(llvm::SmallVectorImpl<const char*> &Names);
30 }; 30 };
31 31
32 /// Helper class for options that set multiple flags 32 /// Helper class for options that set multiple flags
33 class MultiSetter { 33 class MultiSetter {
34 std::vector<bool*> locations; 34 std::vector<bool*> locations;
35 bool invert; 35 bool invert;
36 MultiSetter(bool); //not implemented, disable auto-conversion 36 MultiSetter(bool); //not implemented, disable auto-conversion
37 public: 37 public:
38 MultiSetter(bool invert, bool* p, ...) END_WITH_NULL; 38 MultiSetter(bool invert, bool* p, ...) END_WITH_NULL;
39 39
40 void operator=(bool val); 40 void operator=(bool val);
41 }; 41 };
42 42
43 /// Helper class to fill Array with char* when given strings 43 /// Helper class to fill Array with char* when given strings
44 /// (Errors on empty strings) 44 /// (Errors on empty strings)
45 class ArrayAdapter { 45 class ArrayAdapter {
46 const char* name; 46 const char* name;
47 Array** arrp; 47 Array** arrp;
50 name = name_; 50 name = name_;
51 arrp = &arr; 51 arrp = &arr;
52 assert(name); 52 assert(name);
53 assert(arrp); 53 assert(arrp);
54 } 54 }
55 55
56 void push_back(const char* cstr); 56 void push_back(const char* cstr);
57 57
58 void push_back(const std::string& str) { 58 void push_back(const std::string& str) {
59 push_back(str.c_str()); 59 push_back(str.c_str());
60 } 60 }
61 }; 61 };
62 62
63 /// Helper class to allow use of a parser<bool> with BoolOrDefault 63 /// Helper class to allow use of a parser<bool> with BoolOrDefault
64 class BoolOrDefaultAdapter { 64 class BoolOrDefaultAdapter {
65 cl::boolOrDefault value; 65 cl::boolOrDefault value;
66 public: 66 public:
67 operator cl::boolOrDefault() { 67 operator cl::boolOrDefault() {
68 return value; 68 return value;
69 } 69 }
70 70
71 void operator=(cl::boolOrDefault val) { 71 void operator=(cl::boolOrDefault val) {
72 value = val; 72 value = val;
73 } 73 }
74 74
75 void operator=(bool val) { 75 void operator=(bool val) {
76 *this = (val ? cl::BOU_TRUE : cl::BOU_FALSE); 76 *this = (val ? cl::BOU_TRUE : cl::BOU_FALSE);
77 } 77 }
78 }; 78 };
79 } 79 }