[LLVMdev] PATCH: Registry template

Gordon Henriksen gordonhenriksen at mac.com
Fri Aug 31 05:32:34 PDT 2007


Woo, that got mangled by wrapping. Here's an attachment.

On 2007-08-31, at 01:32, Gordon Henriksen wrote:

> This is a template that takes care of managing plugin registries. I
> wrote it because I got the distinct feeling I was needlessly
> reinventing the wheel as I wrote a collector registry. I haven't
> converted anything else to use it, though. Still, it's orthogonal
> and has become stable in my usage, so I thought I'd submit it in
> advance.
>
> To get my collector registry going, all I needed was 5 lines:
>
>    // GCRegistry.h
>    typedef Registry<TargetCollector> CollectorRegistry;
>
>    // GCRegistry.cpp
>    template<> CollectorRegistry::node *CollectorRegistry::Head = 0;
>    template<> CollectorRegistry::node *CollectorRegistry::Tail = 0;
>    template<> CollectorRegistry::listener *CollectorRegistry::
>    ListenerHead = 0;
>    template<> CollectorRegistry::listener *CollectorRegistry::
>    ListenerTail = 0;
>
> Afterwards, the most important features work more or less as to be
> expected:
>
>    // ShadowStackCollector.cpp
>    CollectorRegistry::Add<ShadowStackGC>
>    Y("shadow-stack",
>      "Shadow stack collector, for uncooperative code generators");
>
>    // llc.cpp
>    static cl::opt<const CollectorRegistry::entry*, false,
>                   CollectorRegistry::Parser>
>    GC("gc", cl::desc("Enable garbage collection."));
>
>    Collector = GC->instantiate();
>
>    // nowhere
>    for (CollectorRegistry::iterator I = CollectorRegistry::begin(),
>                                     E = CollectorRegistry::end();
>                                     I ! = E; ++I)
>      cout << I->getName() << ": " << I->getDesc() << "\n";
>
> Granted, my needs are currently simple. The default entry type has
> just the name, description, and use the default constructor. To
> convert, many registries in the system would need to also define:
>
>   1. An custom entry type, particularly where the default
>      constructor was insufficient.
>   2. A custom traits type.
>   3. The RegisterFoo template, to create the constructor wrapper
>      springboard.
>
> Thanks,
> Gordon

-------------- next part --------------
A non-text attachment was scrubbed...
Name: registry-template.patch
Type: application/octet-stream
Size: 7133 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20070831/b303a41b/attachment.obj>


More information about the llvm-dev mailing list