Eliminate compiler warnings.
[oota-llvm.git] / lib / CompilerDriver / Plugin.cpp
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.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #include "llvm/CompilerDriver/Plugin.h"
15
16 #include <algorithm>
17 #include <vector>
18
19 namespace {
20
21   // Registry::Add<> does not do lifetime management (probably issues
22   // with static constructor/destructor ordering), so we have to
23   // implement it here.
24   //
25   // All this static registration/life-before-main model seems
26   // unnecessary convoluted to me.
27
28   static bool pluginListInitialized = false;
29   typedef std::vector<const llvmc::BasePlugin*> PluginList;
30   static PluginList Plugins;
31
32   struct ByPriority {
33     bool operator()(const llvmc::BasePlugin* lhs,
34                     const llvmc::BasePlugin* rhs) {
35       return lhs->Priority() < rhs->Priority();
36     }
37   };
38 }
39
40 namespace llvmc {
41
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());
48     }
49     pluginListInitialized = true;
50   }
51
52   PluginLoader::~PluginLoader() {
53     if (pluginListInitialized) {
54       for (PluginList::iterator B = Plugins.begin(), E = Plugins.end();
55            B != E; ++B)
56         delete (*B);
57     }
58     pluginListInitialized = false;
59   }
60
61   void PluginLoader::PopulateLanguageMap(LanguageMap& langMap) {
62     for (PluginList::iterator B = Plugins.begin(), E = Plugins.end();
63          B != E; ++B)
64       (*B)->PopulateLanguageMap(langMap);
65   }
66
67   void PluginLoader::PopulateCompilationGraph(CompilationGraph& graph) {
68     for (PluginList::iterator B = Plugins.begin(), E = Plugins.end();
69          B != E; ++B)
70       (*B)->PopulateCompilationGraph(graph);
71   }
72
73 }