X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=include%2Fllvm%2FCompilerDriver%2FPlugin.h;h=75fd9162dfef55c24e86098c23dce0b8b948e0d6;hb=3d72367d30c9ce6f387764a028763f7a366cc443;hp=ba22450697b31a33696348e1b6a3d89dd50d8b20;hpb=4a1a77c1c9e0992735aa66b75c9e4c75c3b70561;p=oota-llvm.git diff --git a/include/llvm/CompilerDriver/Plugin.h b/include/llvm/CompilerDriver/Plugin.h index ba22450697b..75fd9162dfe 100644 --- a/include/llvm/CompilerDriver/Plugin.h +++ b/include/llvm/CompilerDriver/Plugin.h @@ -7,12 +7,14 @@ // //===----------------------------------------------------------------------===// // -// Plugin support for llvmc2. +// Plugin support for llvmc. // //===----------------------------------------------------------------------===// -#ifndef LLVM_TOOLS_LLVMC2_PLUGIN_H -#define LLVM_TOOLS_LLVMC2_PLUGIN_H +#ifndef LLVM_INCLUDE_COMPILER_DRIVER_PLUGIN_H +#define LLVM_INCLUDE_COMPILER_DRIVER_PLUGIN_H + +#include "llvm/Support/Registry.h" namespace llvmc { @@ -22,35 +24,58 @@ namespace llvmc { /// BasePlugin - An abstract base class for all LLVMC plugins. struct BasePlugin { + /// Priority - Plugin priority, useful for handling dependencies + /// between plugins. Plugins with lower priorities are loaded + /// first. + virtual int Priority() const { return 0; } + + /// PreprocessOptions - The auto-generated function that performs various + /// consistency checks on options (like ensuring that -O2 and -O3 are not + /// used together). + virtual int PreprocessOptions() const = 0; + /// PopulateLanguageMap - The auto-generated function that fills in /// the language map (map from file extensions to language names). - virtual void PopulateLanguageMap(LanguageMap&) const = 0; + virtual int PopulateLanguageMap(LanguageMap&) const = 0; /// PopulateCompilationGraph - The auto-generated function that /// populates the compilation graph with nodes and edges. - virtual void PopulateCompilationGraph(CompilationGraph&) const = 0; - }; + virtual int PopulateCompilationGraph(CompilationGraph&) const = 0; - // Helper class for RegisterPlugin. - class RegisterPluginImpl { - protected: - RegisterPluginImpl(BasePlugin*); + /// Needed to avoid a compiler warning. + virtual ~BasePlugin() {} }; - /// RegisterPlugin template - Used to register LLVMC plugins. - template - struct RegisterPlugin : RegisterPluginImpl { - RegisterPlugin() : RegisterPluginImpl (new T()) {} + typedef llvm::Registry PluginRegistry; + + template + struct RegisterPlugin + : public PluginRegistry::Add

{ + typedef PluginRegistry::Add

Base; + + RegisterPlugin(const char* Name = "Nameless", + const char* Desc = "Auto-generated plugin") + : Base(Name, Desc) {} }; - /// PopulateLanguageMap - Fills in the language map by calling - /// PopulateLanguageMap methods of all plugins. - void PopulateLanguageMap(LanguageMap& langMap); - /// PopulateCompilationGraph - Populates the compilation graph by - /// calling PopulateCompilationGraph methods of all plugins. - void PopulateCompilationGraph(CompilationGraph& tools); + /// PluginLoader - Helper class used by the main program for + /// lifetime management. + struct PluginLoader { + PluginLoader(); + ~PluginLoader(); + + /// RunInitialization - Calls PreprocessOptions, PopulateLanguageMap and + /// PopulateCompilationGraph methods of all plugins. This populates the + /// global language map and the compilation graph. + int RunInitialization(LanguageMap& langMap, CompilationGraph& graph) const; + + private: + // noncopyable + PluginLoader(const PluginLoader& other); + const PluginLoader& operator=(const PluginLoader& other); + }; } -#endif // LLVM_TOOLS_LLVMC2_PLUGIN_H +#endif // LLVM_INCLUDE_COMPILER_DRIVER_PLUGIN_H