Get rid of exceptions in llvmc.
[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 llvmc.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef LLVM_INCLUDE_COMPILER_DRIVER_PLUGIN_H
15 #define LLVM_INCLUDE_COMPILER_DRIVER_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     /// Priority - Plugin priority, useful for handling dependencies
28     /// between plugins. Plugins with lower priorities are loaded
29     /// first.
30     virtual int Priority() const { return 0; }
31
32     /// PreprocessOptions - The auto-generated function that performs various
33     /// consistency checks on options (like ensuring that -O2 and -O3 are not
34     /// used together).
35     virtual int PreprocessOptions() const = 0;
36
37     /// PopulateLanguageMap - The auto-generated function that fills in
38     /// the language map (map from file extensions to language names).
39     virtual int PopulateLanguageMap(LanguageMap&) const = 0;
40
41     /// PopulateCompilationGraph - The auto-generated function that
42     /// populates the compilation graph with nodes and edges.
43     virtual int PopulateCompilationGraph(CompilationGraph&) const = 0;
44
45     /// Needed to avoid a compiler warning.
46     virtual ~BasePlugin() {}
47   };
48
49   typedef llvm::Registry<BasePlugin> PluginRegistry;
50
51   template <class P>
52   struct RegisterPlugin
53     : public PluginRegistry::Add<P> {
54     typedef PluginRegistry::Add<P> Base;
55
56     RegisterPlugin(const char* Name = "Nameless",
57                    const char* Desc = "Auto-generated plugin")
58       : Base(Name, Desc) {}
59   };
60
61
62   /// PluginLoader - Helper class used by the main program for
63   /// lifetime management.
64   struct PluginLoader {
65     PluginLoader();
66     ~PluginLoader();
67
68     /// RunInitialization - Calls PreprocessOptions, PopulateLanguageMap and
69     /// PopulateCompilationGraph methods of all plugins. This populates the
70     /// global language map and the compilation graph.
71     int RunInitialization(LanguageMap& langMap, CompilationGraph& graph) const;
72
73   private:
74     // noncopyable
75     PluginLoader(const PluginLoader& other);
76     const PluginLoader& operator=(const PluginLoader& other);
77   };
78
79 }
80
81 #endif // LLVM_INCLUDE_COMPILER_DRIVER_PLUGIN_H