1 //===--- Plugin.cpp - The LLVM Compiler Driver ------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open
6 // Source License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
12 //===----------------------------------------------------------------------===//
14 #include "llvm/CompilerDriver/Plugin.h"
21 // Registry::Add<> does not do lifetime management (probably issues
22 // with static constructor/destructor ordering), so we have to
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
;
33 bool operator()(const llvmc::BasePlugin
* lhs
,
34 const llvmc::BasePlugin
* rhs
) {
35 return lhs
->Priority() < rhs
->Priority();
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();
58 pluginListInitialized
= false;
61 void PluginLoader::PopulateLanguageMap(LanguageMap
& langMap
) {
62 for (PluginList::iterator B
= Plugins
.begin(), E
= Plugins
.end();
64 (*B
)->PopulateLanguageMap(langMap
);
67 void PluginLoader::PopulateCompilationGraph(CompilationGraph
& graph
) {
68 for (PluginList::iterator B
= Plugins
.begin(), E
= Plugins
.end();
70 (*B
)->PopulateCompilationGraph(graph
);