Convert llvmc2 plugins to use llvm/Support/Registry.h machinery.
[oota-llvm.git] / include / llvm / CompilerDriver / Plugin.h
1 //===--- Plugin.h - The LLVM Compiler Driver --------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open
6 // Source License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 //  Plugin support for llvmc2.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef LLVM_TOOLS_LLVMC2_PLUGIN_H
15 #define LLVM_TOOLS_LLVMC2_PLUGIN_H
16
17 #include "llvm/Support/Registry.h"
18
19 namespace llvmc {
20
21   class LanguageMap;
22   class CompilationGraph;
23
24   /// BasePlugin - An abstract base class for all LLVMC plugins.
25   struct BasePlugin {
26
27     /// PopulateLanguageMap - The auto-generated function that fills in
28     /// the language map (map from file extensions to language names).
29     virtual void PopulateLanguageMap(LanguageMap&) const = 0;
30
31     /// PopulateCompilationGraph - The auto-generated function that
32     /// populates the compilation graph with nodes and edges.
33     virtual void PopulateCompilationGraph(CompilationGraph&) const = 0;
34   };
35
36   typedef llvm::Registry<BasePlugin> PluginRegistry;
37
38   template <class P>
39   struct RegisterPlugin
40     : public PluginRegistry::Add<P> {
41     typedef PluginRegistry::Add<P> Base;
42
43     RegisterPlugin(const char* Name = "Nameless",
44                    const char* Desc = "Auto-generated plugin")
45       : Base(Name, Desc) {}
46   };
47
48
49   /// PluginLoader - Helper class used by the main program for
50   /// lifetime management.
51   struct PluginLoader {
52     PluginLoader();
53     ~PluginLoader();
54
55     /// PopulateLanguageMap - Fills in the language map by calling
56     /// PopulateLanguageMap methods of all plugins.
57     void PopulateLanguageMap(LanguageMap& langMap);
58
59     /// PopulateCompilationGraph - Populates the compilation graph by
60     /// calling PopulateCompilationGraph methods of all plugins.
61     void PopulateCompilationGraph(CompilationGraph& tools);
62
63   private:
64     // noncopyable
65     PluginLoader(const PluginLoader& other);
66     const PluginLoader& operator=(const PluginLoader& other);
67   };
68
69 }
70
71 #endif // LLVM_TOOLS_LLVMC2_PLUGIN_H