Mercurial > projects > ldc
view gen/cl_helpers.h @ 1170:e40c65bd8c5d
Allow specific optimization passes to be requested from the command line.
Now you can run "`ldc test.d -c -mem2reg -simplifycfg`" if you feel the urge.
The -O<N> options are still supported, and are inserted in the passes list in
the position where they appear on the command line.
(so -simplifycfg -O1 -instcombine does the "right thing")
One small change: -inline is renamed to -enable-inlining due to a naming
conflict with the option to add the -inline pass. -inline now inserts the
inlining pass in the position specified, not in the middle of -O<N>.
(ldmd has been updated to translate -inline to -enable-inlining)
author | Frits van Bommel <fvbommel wxs.nl> |
---|---|
date | Sun, 29 Mar 2009 15:46:55 +0200 |
parents | a8cb25d478c4 |
children | cc1efa23030a |
line wrap: on
line source
#ifndef LDC_CL_HELPERS_H #define LDC_CL_HELPERS_H #include <string> #include "llvm/Support/CommandLine.h" #include "llvm/Support/Compiler.h" struct Array; namespace opts { namespace cl = llvm::cl; /// Helper class for fancier options class FlagParser : public cl::parser<bool> { std::vector<std::pair<std::string, bool> > switches; public: template <class Opt> void initialize(Opt &O) { assert(!(O.getMiscFlags() & cl::AllowInverse) && "FlagParser doesn't support redundant AllowInverse flag"); std::string Name = O.ArgStr; switches.push_back(make_pair("enable-" + Name, true)); switches.push_back(make_pair("disable-" + Name, false)); // Replace <foo> with -enable-<foo> O.ArgStr = switches[0].first.c_str(); } bool parse(cl::Option &O, const char *ArgName, const std::string &ArgValue, bool &Val); void getExtraOptionNames(std::vector<const char*> &Names); }; /// Helper class for options that set multiple flags class MultiSetter { std::vector<bool*> locations; bool invert; MultiSetter(bool); //not implemented, disable auto-conversion public: MultiSetter(bool invert, bool* p, ...) END_WITH_NULL; void operator=(bool val); }; /// Helper class to fill Array with char* when given strings /// (Errors on empty strings) class ArrayAdapter { const char* name; Array** arrp; public: ArrayAdapter(const char* name_, Array*& arr) { name = name_; arrp = &arr; assert(name); assert(arrp); } void push_back(const char* cstr); void push_back(const std::string& str) { push_back(str.c_str()); } }; } #endif