summaryrefslogtreecommitdiff
path: root/include/llvm/CompilerDriver/Plugin.h
blob: 9f9eee3c0db99b566b5ec5225a1d5aa830de8d91 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
//===--- Plugin.h - The LLVM Compiler Driver --------------------*- C++ -*-===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open
// Source License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
//  Plugin support for llvmc.
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_INCLUDE_COMPILER_DRIVER_PLUGIN_H
#define LLVM_INCLUDE_COMPILER_DRIVER_PLUGIN_H

#include "llvm/Support/Registry.h"

namespace llvmc {

  class LanguageMap;
  class CompilationGraph;

  /// 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; }

    /// PopulateLanguageMap - The auto-generated function that fills in
    /// the language map (map from file extensions to language names).
    virtual void PopulateLanguageMap(LanguageMap&) const = 0;

    /// PopulateCompilationGraph - The auto-generated function that
    /// populates the compilation graph with nodes and edges.
    virtual void PopulateCompilationGraph(CompilationGraph&) const = 0;

    /// Needed to avoid a compiler warning.
    virtual ~BasePlugin() {}
  };

  typedef llvm::Registry<BasePlugin> PluginRegistry;

  template <class P>
  struct RegisterPlugin
    : public PluginRegistry::Add<P> {
    typedef PluginRegistry::Add<P> Base;

    RegisterPlugin(const char* Name = "Nameless",
                   const char* Desc = "Auto-generated plugin")
      : Base(Name, Desc) {}
  };


  /// PluginLoader - Helper class used by the main program for
  /// lifetime management.
  struct PluginLoader {
    PluginLoader();
    ~PluginLoader();

    /// 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);

  private:
    // noncopyable
    PluginLoader(const PluginLoader& other);
    const PluginLoader& operator=(const PluginLoader& other);
  };

}

#endif // LLVM_INCLUDE_COMPILER_DRIVER_PLUGIN_H