summaryrefslogtreecommitdiff
path: root/tools/opt
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2002-07-26 21:09:32 +0000
committerChris Lattner <sabre@nondot.org>2002-07-26 21:09:32 +0000
commit2053a2a2720ea93550b230da6ceac371014c20c2 (patch)
tree0ae46291096f8ca36e28e73a228f20739a974b39 /tools/opt
parent7b499f7303940db399562b9ca0abd2ba692cf6a1 (diff)
downloadllvm-2053a2a2720ea93550b230da6ceac371014c20c2.tar.gz
llvm-2053a2a2720ea93550b230da6ceac371014c20c2.tar.bz2
llvm-2053a2a2720ea93550b230da6ceac371014c20c2.tar.xz
Factor PassNamePArser out into llvm/Support/PassNameParser.h
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@3109 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools/opt')
-rw-r--r--tools/opt/opt.cpp66
1 files changed, 3 insertions, 63 deletions
diff --git a/tools/opt/opt.cpp b/tools/opt/opt.cpp
index 9fbfea7564..463b37c387 100644
--- a/tools/opt/opt.cpp
+++ b/tools/opt/opt.cpp
@@ -13,7 +13,7 @@
#include "llvm/Assembly/PrintModulePass.h"
#include "llvm/Analysis/Verifier.h"
#include "llvm/Target/TargetData.h"
-#include "Support/CommandLine.h"
+#include "llvm/Support/PassNameParser.h"
#include "Support/Signals.h"
#include <fstream>
#include <memory>
@@ -22,72 +22,12 @@
using std::cerr;
using std::string;
-//===----------------------------------------------------------------------===//
-// PassNameParser class - Make use of the pass registration mechanism to
-// automatically add a command line argument to opt for each pass.
-//
-namespace { // anonymous namespace for local class...
-class PassNameParser : public PassRegistrationListener,
- public cl::parser<const PassInfo*> {
- cl::Option *Opt;
-public:
- PassNameParser() : Opt(0) {}
-
- void initialize(cl::Option &O) {
- Opt = &O;
- cl::parser<const PassInfo*>::initialize(O);
-
- // Add all of the passes to the map that got initialized before 'this' did.
- enumeratePasses();
- }
-
- static inline bool ignorablePass(const PassInfo *P) {
- // Ignore non-selectable and non-constructible passes!
- return P->getPassArgument() == 0 ||
- (P->getNormalCtor() == 0 && P->getDataCtor() == 0);
- }
-
- // Implement the PassRegistrationListener callbacks used to populate our map
- //
- virtual void passRegistered(const PassInfo *P) {
- if (ignorablePass(P) || !Opt) return;
- assert(findOption(P->getPassArgument()) == getNumOptions() &&
- "Two passes with the same argument attempted to be registered!");
- addLiteralOption(P->getPassArgument(), P, P->getPassName());
- Opt->addArgument(P->getPassArgument());
- }
- virtual void passEnumerate(const PassInfo *P) { passRegistered(P); }
-
- virtual void passUnregistered(const PassInfo *P) {
- if (ignorablePass(P) || !Opt) return;
- assert(findOption(P->getPassArgument()) != getNumOptions() &&
- "Registered Pass not in the pass map!");
- removeLiteralOption(P->getPassArgument());
- Opt->removeArgument(P->getPassArgument());
- }
-
- // ValLessThan - Provide a sorting comparator for Values elements...
- typedef std::pair<const char*,
- std::pair<const PassInfo*, const char*> > ValType;
- static bool ValLessThan(const ValType &VT1, const ValType &VT2) {
- return std::string(VT1.first) < std::string(VT2.first);
- }
-
- // printOptionInfo - Print out information about this option. Override the
- // default implementation to sort the table before we print...
- virtual void printOptionInfo(const cl::Option &O, unsigned GlobalWidth) const{
- PassNameParser *PNP = const_cast<PassNameParser*>(this);
- std::sort(PNP->Values.begin(), PNP->Values.end(), ValLessThan);
- cl::parser<const PassInfo*>::printOptionInfo(O, GlobalWidth);
- }
-};
-} // end anonymous namespace
-
// The OptimizationList is automatically populated with registered Passes by the
// PassNameParser.
//
-static cl::list<const PassInfo*, bool, PassNameParser>
+static cl::list<const PassInfo*, bool,
+ FilteredPassNameParser<PassInfo::Optimization> >
OptimizationList(cl::desc("Optimizations available:"));