LLVM API Documentation

Plugin.h

Go to the documentation of this file.
00001 //===--- Plugin.h - The LLVM Compiler Driver --------------------*- C++ -*-===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open
00006 // Source License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 //  Plugin support for llvmc2.
00011 //
00012 //===----------------------------------------------------------------------===//
00013 
00014 #ifndef LLVM_TOOLS_LLVMC2_PLUGIN_H
00015 #define LLVM_TOOLS_LLVMC2_PLUGIN_H
00016 
00017 #include "llvm/Support/Registry.h"
00018 
00019 namespace llvmc {
00020 
00021   class LanguageMap;
00022   class CompilationGraph;
00023 
00024   /// BasePlugin - An abstract base class for all LLVMC plugins.
00025   struct BasePlugin {
00026 
00027     /// Priority - Plugin priority, useful for handling dependencies
00028     /// between plugins. Plugins with lower priorities are loaded
00029     /// first.
00030     virtual int Priority() const = 0;
00031 
00032     /// PopulateLanguageMap - The auto-generated function that fills in
00033     /// the language map (map from file extensions to language names).
00034     virtual void PopulateLanguageMap(LanguageMap&) const = 0;
00035 
00036     /// PopulateCompilationGraph - The auto-generated function that
00037     /// populates the compilation graph with nodes and edges.
00038     virtual void PopulateCompilationGraph(CompilationGraph&) const = 0;
00039 
00040     /// Needed to avoid a compiler warning.
00041     virtual ~BasePlugin() {}
00042   };
00043 
00044   typedef llvm::Registry<BasePlugin> PluginRegistry;
00045 
00046   template <class P>
00047   struct RegisterPlugin
00048     : public PluginRegistry::Add<P> {
00049     typedef PluginRegistry::Add<P> Base;
00050 
00051     RegisterPlugin(const char* Name = "Nameless",
00052                    const char* Desc = "Auto-generated plugin")
00053       : Base(Name, Desc) {}
00054   };
00055 
00056 
00057   /// PluginLoader - Helper class used by the main program for
00058   /// lifetime management.
00059   struct PluginLoader {
00060     PluginLoader();
00061     ~PluginLoader();
00062 
00063     /// PopulateLanguageMap - Fills in the language map by calling
00064     /// PopulateLanguageMap methods of all plugins.
00065     void PopulateLanguageMap(LanguageMap& langMap);
00066 
00067     /// PopulateCompilationGraph - Populates the compilation graph by
00068     /// calling PopulateCompilationGraph methods of all plugins.
00069     void PopulateCompilationGraph(CompilationGraph& tools);
00070 
00071   private:
00072     // noncopyable
00073     PluginLoader(const PluginLoader& other);
00074     const PluginLoader& operator=(const PluginLoader& other);
00075   };
00076 
00077 }
00078 
00079 #endif // LLVM_TOOLS_LLVMC2_PLUGIN_H