Merge branch 'master' into msp430
[llvm/msp430.git] / lib / CompilerDriver / Plugin.cpp
blob75abbd041d32cfa5d007a60b630ab4b1b20f43c2
1 //===--- Plugin.cpp - 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.
12 //===----------------------------------------------------------------------===//
14 #include "llvm/CompilerDriver/Plugin.h"
16 #include <algorithm>
17 #include <vector>
19 namespace {
21 // Registry::Add<> does not do lifetime management (probably issues
22 // with static constructor/destructor ordering), so we have to
23 // implement it here.
25 // All this static registration/life-before-main model seems
26 // unnecessary convoluted to me.
28 static bool pluginListInitialized = false;
29 typedef std::vector<const llvmc::BasePlugin*> PluginList;
30 static PluginList Plugins;
32 struct ByPriority {
33 bool operator()(const llvmc::BasePlugin* lhs,
34 const llvmc::BasePlugin* rhs) {
35 return lhs->Priority() < rhs->Priority();
40 namespace llvmc {
42 PluginLoader::PluginLoader() {
43 if (!pluginListInitialized) {
44 for (PluginRegistry::iterator B = PluginRegistry::begin(),
45 E = PluginRegistry::end(); B != E; ++B)
46 Plugins.push_back(B->instantiate());
47 std::sort(Plugins.begin(), Plugins.end(), ByPriority());
49 pluginListInitialized = true;
52 PluginLoader::~PluginLoader() {
53 if (pluginListInitialized) {
54 for (PluginList::iterator B = Plugins.begin(), E = Plugins.end();
55 B != E; ++B)
56 delete (*B);
58 pluginListInitialized = false;
61 void PluginLoader::PopulateLanguageMap(LanguageMap& langMap) {
62 for (PluginList::iterator B = Plugins.begin(), E = Plugins.end();
63 B != E; ++B)
64 (*B)->PopulateLanguageMap(langMap);
67 void PluginLoader::PopulateCompilationGraph(CompilationGraph& graph) {
68 for (PluginList::iterator B = Plugins.begin(), E = Plugins.end();
69 B != E; ++B)
70 (*B)->PopulateCompilationGraph(graph);