2008-09-22 20:49:34 +00:00
|
|
|
//===--- Plugin.cpp - 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.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
2008-11-25 21:38:12 +00:00
|
|
|
// Plugin support.
|
2008-09-22 20:49:34 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2008-09-22 20:50:40 +00:00
|
|
|
#include "llvm/CompilerDriver/Plugin.h"
|
2009-06-26 00:06:28 +00:00
|
|
|
#include "llvm/Support/ManagedStatic.h"
|
|
|
|
#include "llvm/System/Mutex.h"
|
2008-11-17 17:30:25 +00:00
|
|
|
#include <algorithm>
|
2008-09-22 20:49:34 +00:00
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
namespace {
|
2008-09-22 20:51:19 +00:00
|
|
|
|
|
|
|
// Registry::Add<> does not do lifetime management (probably issues
|
|
|
|
// with static constructor/destructor ordering), so we have to
|
|
|
|
// implement it here.
|
|
|
|
//
|
|
|
|
// All this static registration/life-before-main model seems
|
|
|
|
// unnecessary convoluted to me.
|
|
|
|
|
|
|
|
static bool pluginListInitialized = false;
|
|
|
|
typedef std::vector<const llvmc::BasePlugin*> PluginList;
|
|
|
|
static PluginList Plugins;
|
2009-06-26 00:06:28 +00:00
|
|
|
static llvm::ManagedStatic<llvm::sys::SmartMutex<true> > PluginMutex;
|
2008-11-17 17:30:25 +00:00
|
|
|
|
|
|
|
struct ByPriority {
|
|
|
|
bool operator()(const llvmc::BasePlugin* lhs,
|
|
|
|
const llvmc::BasePlugin* rhs) {
|
|
|
|
return lhs->Priority() < rhs->Priority();
|
|
|
|
}
|
|
|
|
};
|
2008-09-22 20:49:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
namespace llvmc {
|
|
|
|
|
2008-09-22 20:51:19 +00:00
|
|
|
PluginLoader::PluginLoader() {
|
2009-07-07 18:33:04 +00:00
|
|
|
llvm::sys::SmartScopedLock<true> Lock(*PluginMutex);
|
2008-09-22 20:51:19 +00:00
|
|
|
if (!pluginListInitialized) {
|
|
|
|
for (PluginRegistry::iterator B = PluginRegistry::begin(),
|
|
|
|
E = PluginRegistry::end(); B != E; ++B)
|
|
|
|
Plugins.push_back(B->instantiate());
|
2008-11-17 17:30:25 +00:00
|
|
|
std::sort(Plugins.begin(), Plugins.end(), ByPriority());
|
2008-09-22 20:51:19 +00:00
|
|
|
}
|
|
|
|
pluginListInitialized = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
PluginLoader::~PluginLoader() {
|
2009-07-07 18:33:04 +00:00
|
|
|
llvm::sys::SmartScopedLock<true> Lock(*PluginMutex);
|
2008-09-22 20:51:19 +00:00
|
|
|
if (pluginListInitialized) {
|
|
|
|
for (PluginList::iterator B = Plugins.begin(), E = Plugins.end();
|
|
|
|
B != E; ++B)
|
|
|
|
delete (*B);
|
|
|
|
}
|
|
|
|
pluginListInitialized = false;
|
2008-09-22 20:49:34 +00:00
|
|
|
}
|
|
|
|
|
2008-09-22 20:51:19 +00:00
|
|
|
void PluginLoader::PopulateLanguageMap(LanguageMap& langMap) {
|
2009-07-07 18:33:04 +00:00
|
|
|
llvm::sys::SmartScopedLock<true> Lock(*PluginMutex);
|
2008-09-22 20:51:19 +00:00
|
|
|
for (PluginList::iterator B = Plugins.begin(), E = Plugins.end();
|
|
|
|
B != E; ++B)
|
2008-09-22 20:49:34 +00:00
|
|
|
(*B)->PopulateLanguageMap(langMap);
|
|
|
|
}
|
|
|
|
|
2008-09-22 20:51:19 +00:00
|
|
|
void PluginLoader::PopulateCompilationGraph(CompilationGraph& graph) {
|
2009-07-07 18:33:04 +00:00
|
|
|
llvm::sys::SmartScopedLock<true> Lock(*PluginMutex);
|
2008-09-22 20:51:19 +00:00
|
|
|
for (PluginList::iterator B = Plugins.begin(), E = Plugins.end();
|
|
|
|
B != E; ++B)
|
2008-09-22 20:49:34 +00:00
|
|
|
(*B)->PopulateCompilationGraph(graph);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|