Ensure -mcpu=xscale works for arm targets, after rL252903 and rL252904
[oota-llvm.git] / include / llvm / Support / Registry.h
index 4db88825afb55b96fdbe43779352423f0a5b13ea..bbea97b289a6e1a3f22801c60990f0be21b50ab3 100644 (file)
 #ifndef LLVM_SUPPORT_REGISTRY_H
 #define LLVM_SUPPORT_REGISTRY_H
 
+#include "llvm/ADT/iterator_range.h"
+#include "llvm/ADT/STLExtras.h"
+#include "llvm/Support/Compiler.h"
+#include <memory>
+
 namespace llvm {
   /// A simple registry entry which provides only a name, description, and
   /// no-argument constructor.
   template <typename T>
   class SimpleRegistryEntry {
     const char *Name, *Desc;
-    T *(*Ctor)();
+    std::unique_ptr<T> (*Ctor)();
 
   public:
-    SimpleRegistryEntry(const char *N, const char *D, T *(*C)())
+    SimpleRegistryEntry(const char *N, const char *D, std::unique_ptr<T> (*C)())
       : Name(N), Desc(D), Ctor(C)
     {}
 
     const char *getName() const { return Name; }
     const char *getDesc() const { return Desc; }
-    T *instantiate() const { return Ctor(); }
+    std::unique_ptr<T> instantiate() const { return Ctor(); }
   };
 
-
   /// Traits for registry entries. If using other than SimpleRegistryEntry, it
   /// is necessary to define an alternate traits class.
   template <typename T>
   class RegistryTraits {
-    RegistryTraits(); // Do not implement.
+    RegistryTraits() = delete;
 
   public:
     typedef SimpleRegistryEntry<T> entry;
@@ -48,7 +52,6 @@ namespace llvm {
     static const char *descof(const entry &Entry) { return Entry.getDesc(); }
   };
 
-
   /// A global registry used in conjunction with static constructors to make
   /// pluggable components (like targets or garbage collectors) "just work" when
   /// linked with an executable.
@@ -63,7 +66,7 @@ namespace llvm {
     class iterator;
 
   private:
-    Registry(); // Do not implement.
+    Registry() = delete;
 
     static void Announce(const entry &E) {
       for (listener *Cur = ListenerHead; Cur; Cur = Cur->Next)
@@ -86,7 +89,7 @@ namespace llvm {
       const entry& Val;
 
     public:
-      node(const entry& V) : Next(0), Val(V) {
+      node(const entry& V) : Next(nullptr), Val(V) {
         if (Tail)
           Tail->Next = this;
         else
@@ -97,7 +100,6 @@ namespace llvm {
       }
     };
 
-
     /// Iterators for registry entries.
     ///
     class iterator {
@@ -114,12 +116,16 @@ namespace llvm {
     };
 
     static iterator begin() { return iterator(Head); }
-    static iterator end()   { return iterator(0); }
+    static iterator end()   { return iterator(nullptr); }
 
+    static iterator_range<iterator> entries() {
+      return make_range(begin(), end());
+    }
 
     /// Abstract base class for registry listeners, which are informed when new
     /// entries are added to the registry. Simply subclass and instantiate:
     ///
+    /// \code
     ///   class CollectorPrinter : public Registry<Collector>::listener {
     ///   protected:
     ///     void registered(const Registry<Collector>::entry &e) {
@@ -131,7 +137,7 @@ namespace llvm {
     ///   };
     ///
     ///   CollectorPrinter Printer;
-    ///
+    /// \endcode
     class listener {
       listener *Prev, *Next;
 
@@ -150,7 +156,7 @@ namespace llvm {
       }
 
     public:
-      listener() : Prev(ListenerTail), Next(0) {
+      listener() : Prev(ListenerTail), Next(nullptr) {
         if (Prev)
           Prev->Next = this;
         else
@@ -170,7 +176,6 @@ namespace llvm {
       }
     };
 
-
     /// A static registration template. Use like such:
     ///
     ///   Registry<Collector>::Add<FancyGC>
@@ -192,7 +197,7 @@ namespace llvm {
       entry Entry;
       node Node;
 
-      static T *CtorFn() { return new V(); }
+      static std::unique_ptr<T> CtorFn() { return make_unique<V>(); }
 
     public:
       Add(const char *Name, const char *Desc)
@@ -200,9 +205,10 @@ namespace llvm {
     };
 
     /// Registry::Parser now lives in llvm/Support/RegistryParser.h.
-
   };
 
+  // Since these are defined in a header file, plugins must be sure to export
+  // these symbols.
 
   template <typename T, typename U>
   typename Registry<T,U>::node *Registry<T,U>::Head;
@@ -216,6 +222,6 @@ namespace llvm {
   template <typename T, typename U>
   typename Registry<T,U>::listener *Registry<T,U>::ListenerTail;
 
-}
+} // end namespace llvm
 
-#endif
+#endif // LLVM_SUPPORT_REGISTRY_H