Wiki Roadmap Timeline Tickets New Ticket Source Search Help / Guide About Trac Login

root/gen/cl_helpers.h

Revision 1650:40bd4a0d4870, 2.1 kB (checked in by Tomas Lindquist Olsen, 2 years ago)

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.

Line 
1 #ifndef LDC_CL_HELPERS_H
2 #define LDC_CL_HELPERS_H
3
4 #include <string>
5
6 #include "llvm/Support/CommandLine.h"
7 #include "llvm/Support/Compiler.h"
8
9 struct Array;
10
11 namespace opts {
12     namespace cl = llvm::cl;
13
14     /// Helper class for fancier options
15     class FlagParser : public cl::parser<bool> {
16         std::vector<std::pair<std::string, bool> > switches;
17     public:
18         template <class Opt>
19         void initialize(Opt &O) {
20             std::string Name = O.ArgStr;
21             switches.push_back(make_pair("enable-" + Name, true));
22             switches.push_back(make_pair("disable-" + Name, false));
23             // Replace <foo> with -enable-<foo>
24             O.ArgStr = switches[0].first.data();
25         }
26
27         bool parse(cl::Option &O, llvm::StringRef ArgName, llvm::StringRef ArgValue, bool &Val);
28
29         void getExtraOptionNames(llvm::SmallVectorImpl<const char*> &Names);
30     };
31
32     /// Helper class for options that set multiple flags
33     class MultiSetter {
34         std::vector<bool*> locations;
35         bool invert;
36         MultiSetter(bool); //not implemented, disable auto-conversion
37     public:
38         MultiSetter(bool invert, bool* p, ...) END_WITH_NULL;
39
40         void operator=(bool val);
41     };
42
43     /// Helper class to fill Array with char* when given strings
44     /// (Errors on empty strings)
45     class ArrayAdapter {
46         const char* name;
47         Array** arrp;
48     public:
49         ArrayAdapter(const char* name_, Array*& arr) {
50             name = name_;
51             arrp = &arr;
52             assert(name);
53             assert(arrp);
54         }
55
56         void push_back(const char* cstr);
57
58         void push_back(const std::string& str) {
59             push_back(str.c_str());
60         }
61     };
62
63     /// Helper class to allow use of a parser<bool> with BoolOrDefault
64     class BoolOrDefaultAdapter {
65         cl::boolOrDefault value;
66     public:
67         operator cl::boolOrDefault() {
68             return value;
69         }
70
71         void operator=(cl::boolOrDefault val) {
72             value = val;
73         }
74
75         void operator=(bool val) {
76             *this = (val ? cl::BOU_TRUE : cl::BOU_FALSE);
77         }
78     };
79 }
80
81 #endif
Note: See TracBrowser for help on using the browser.
Copyright © 2008, LDC Development Team.