~louis/ubuntu/trusty/clamav/lp799623_fix_logrotate

« back to all changes in this revision

Viewing changes to libclamav/c++/llvm/include/llvm/Support/PassNameParser.h

  • Committer: Bazaar Package Importer
  • Author(s): Scott Kitterman
  • Date: 2010-03-12 11:30:04 UTC
  • mfrom: (0.41.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20100312113004-b0fop4bkycszdd0z
Tags: 0.96~rc1+dfsg-0ubuntu1
* New upstream RC - FFE (LP: #537636):
  - Add OfficialDatabaseOnly option to clamav-base.postinst.in
  - Add LocalSocketGroup option to clamav-base.postinst.in
  - Add LocalSocketMode option to clamav-base.postinst.in
  - Add CrossFilesystems option to clamav-base.postinst.in
  - Add ClamukoScannerCount option to clamav-base.postinst.in
  - Add BytecodeSecurity opiton to clamav-base.postinst.in
  - Add DetectionStatsHostID option to clamav-freshclam.postinst.in
  - Add Bytecode option to clamav-freshclam.postinst.in
  - Add MilterSocketGroup option to clamav-milter.postinst.in
  - Add MilterSocketMode option to clamav-milter.postinst.in
  - Add ReportHostname option to clamav-milter.postinst.in
  - Bump libclamav SO version to 6.1.0 in libclamav6.install
  - Drop clamdmon from clamav.examples (no longer shipped by upstream)
  - Drop libclamav.a from libclamav-dev.install (not built by upstream)
  - Update SO version for lintian override for libclamav6
  - Add new Bytecode Testing Tool, usr/bin/clambc, to clamav.install
  - Add build-depends on python and python-setuptools for new test suite
  - Update debian/copyright for the embedded copy of llvm (using the system
    llvm is not currently feasible)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//===- llvm/Support/PassNameParser.h ----------------------------*- C++ -*-===//
 
2
//
 
3
//                     The LLVM Compiler Infrastructure
 
4
//
 
5
// This file is distributed under the University of Illinois Open Source
 
6
// License. See LICENSE.TXT for details.
 
7
//
 
8
//===----------------------------------------------------------------------===//
 
9
//
 
10
// This file the PassNameParser and FilteredPassNameParser<> classes, which are
 
11
// used to add command line arguments to a utility for all of the passes that
 
12
// have been registered into the system.
 
13
//
 
14
// The PassNameParser class adds ALL passes linked into the system (that are
 
15
// creatable) as command line arguments to the tool (when instantiated with the
 
16
// appropriate command line option template).  The FilteredPassNameParser<>
 
17
// template is used for the same purposes as PassNameParser, except that it only
 
18
// includes passes that have a PassType that are compatible with the filter
 
19
// (which is the template argument).
 
20
//
 
21
//===----------------------------------------------------------------------===//
 
22
 
 
23
#ifndef LLVM_SUPPORT_PASS_NAME_PARSER_H
 
24
#define LLVM_SUPPORT_PASS_NAME_PARSER_H
 
25
 
 
26
#include "llvm/Support/CommandLine.h"
 
27
#include "llvm/Support/ErrorHandling.h"
 
28
#include "llvm/Support/raw_ostream.h"
 
29
#include "llvm/Pass.h"
 
30
#include <algorithm>
 
31
#include <cstring>
 
32
 
 
33
namespace llvm {
 
34
 
 
35
//===----------------------------------------------------------------------===//
 
36
// PassNameParser class - Make use of the pass registration mechanism to
 
37
// automatically add a command line argument to opt for each pass.
 
38
//
 
39
class PassNameParser : public PassRegistrationListener,
 
40
                       public cl::parser<const PassInfo*> {
 
41
  cl::Option *Opt;
 
42
public:
 
43
  PassNameParser() : Opt(0) {}
 
44
  virtual ~PassNameParser();
 
45
                         
 
46
                         
 
47
  void initialize(cl::Option &O) {
 
48
    Opt = &O;
 
49
    cl::parser<const PassInfo*>::initialize(O);
 
50
 
 
51
    // Add all of the passes to the map that got initialized before 'this' did.
 
52
    enumeratePasses();
 
53
  }
 
54
 
 
55
  // ignorablePassImpl - Can be overriden in subclasses to refine the list of
 
56
  // which passes we want to include.
 
57
  //
 
58
  virtual bool ignorablePassImpl(const PassInfo *P) const { return false; }
 
59
 
 
60
  inline bool ignorablePass(const PassInfo *P) const {
 
61
    // Ignore non-selectable and non-constructible passes!  Ignore
 
62
    // non-optimizations.
 
63
    return P->getPassArgument() == 0 || *P->getPassArgument() == 0 ||
 
64
           P->getNormalCtor() == 0 || ignorablePassImpl(P);
 
65
  }
 
66
 
 
67
  // Implement the PassRegistrationListener callbacks used to populate our map
 
68
  //
 
69
  virtual void passRegistered(const PassInfo *P) {
 
70
    if (ignorablePass(P) || !Opt) return;
 
71
    if (findOption(P->getPassArgument()) != getNumOptions()) {
 
72
      errs() << "Two passes with the same argument (-"
 
73
           << P->getPassArgument() << ") attempted to be registered!\n";
 
74
      llvm_unreachable(0);
 
75
    }
 
76
    addLiteralOption(P->getPassArgument(), P, P->getPassName());
 
77
  }
 
78
  virtual void passEnumerate(const PassInfo *P) { passRegistered(P); }
 
79
 
 
80
  // ValLessThan - Provide a sorting comparator for Values elements...
 
81
  typedef std::pair<const char*,
 
82
                    std::pair<const PassInfo*, const char*> > ValType;
 
83
  static bool ValLessThan(const ValType &VT1, const ValType &VT2) {
 
84
    return std::string(VT1.first) < std::string(VT2.first);
 
85
  }
 
86
 
 
87
  // printOptionInfo - Print out information about this option.  Override the
 
88
  // default implementation to sort the table before we print...
 
89
  virtual void printOptionInfo(const cl::Option &O, size_t GlobalWidth) const {
 
90
    PassNameParser *PNP = const_cast<PassNameParser*>(this);
 
91
    std::sort(PNP->Values.begin(), PNP->Values.end(), ValLessThan);
 
92
    cl::parser<const PassInfo*>::printOptionInfo(O, GlobalWidth);
 
93
  }
 
94
};
 
95
 
 
96
///===----------------------------------------------------------------------===//
 
97
/// FilteredPassNameParser class - Make use of the pass registration
 
98
/// mechanism to automatically add a command line argument to opt for
 
99
/// each pass that satisfies a filter criteria.  Filter should return
 
100
/// true for passes to be registered as command-line options.
 
101
///
 
102
template<typename Filter>
 
103
class FilteredPassNameParser : public PassNameParser {
 
104
private:
 
105
  Filter filter;
 
106
 
 
107
public:
 
108
  bool ignorablePassImpl(const PassInfo *P) const { return !filter(*P); }
 
109
};
 
110
 
 
111
///===----------------------------------------------------------------------===//
 
112
/// PassArgFilter - A filter for use with PassNameFilterParser that only
 
113
/// accepts a Pass whose Arg matches certain strings.
 
114
///
 
115
/// Use like this:
 
116
///
 
117
/// extern const char AllowedPassArgs[] = "-anders_aa -dse";
 
118
///
 
119
/// static cl::list<
 
120
///   const PassInfo*,
 
121
///   bool,
 
122
///   FilteredPassNameParser<PassArgFilter<AllowedPassArgs> > >
 
123
/// PassList(cl::desc("Passes available:"));
 
124
///
 
125
/// Only the -anders_aa and -dse options will be available to the user.
 
126
///
 
127
template<const char *Args>
 
128
class PassArgFilter {
 
129
public:
 
130
  bool operator()(const PassInfo &P) const {
 
131
    return(std::strstr(Args, P.getPassArgument()));
 
132
  }
 
133
};
 
134
 
 
135
} // End llvm namespace
 
136
 
 
137
#endif