2008-09-22 22:49:34 +02: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 22:38:12 +01:00
|
|
|
// Plugin support.
|
2008-09-22 22:49:34 +02:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2008-09-22 22:50:40 +02:00
|
|
|
#include "llvm/CompilerDriver/Plugin.h"
|
2009-06-26 02:06:28 +02:00
|
|
|
#include "llvm/Support/ManagedStatic.h"
|
|
|
|
#include "llvm/System/Mutex.h"
|
2008-11-17 18:30:25 +01:00
|
|
|
#include <algorithm>
|
2008-09-22 22:49:34 +02:00
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
namespace {
|
2008-09-22 22:51:19 +02: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 02:06:28 +02:00
|
|
|
static llvm::ManagedStatic<llvm::sys::SmartMutex<true> > PluginMutex;
|
2008-11-17 18:30:25 +01:00
|
|
|
|
|
|
|
struct ByPriority {
|
|
|
|
bool operator()(const llvmc::BasePlugin* lhs,
|
|
|
|
const llvmc::BasePlugin* rhs) {
|
|
|
|
return lhs->Priority() < rhs->Priority();
|
|
|
|
}
|
|
|
|
};
|
2008-09-22 22:49:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
namespace llvmc {
|
|
|
|
|
2008-09-22 22:51:19 +02:00
|
|
|
PluginLoader::PluginLoader() {
|
2009-07-07 20:33:04 +02:00
|
|
|
llvm::sys::SmartScopedLock<true> Lock(*PluginMutex);
|
2008-09-22 22:51:19 +02:00
|
|
|
if (!pluginListInitialized) {
|
|
|
|
for (PluginRegistry::iterator B = PluginRegistry::begin(),
|
|
|
|
E = PluginRegistry::end(); B != E; ++B)
|
|
|
|
Plugins.push_back(B->instantiate());
|
2008-11-17 18:30:25 +01:00
|
|
|
std::sort(Plugins.begin(), Plugins.end(), ByPriority());
|
2008-09-22 22:51:19 +02:00
|
|
|
}
|
|
|
|
pluginListInitialized = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
PluginLoader::~PluginLoader() {
|
2009-07-07 20:33:04 +02:00
|
|
|
llvm::sys::SmartScopedLock<true> Lock(*PluginMutex);
|
2008-09-22 22:51:19 +02:00
|
|
|
if (pluginListInitialized) {
|
|
|
|
for (PluginList::iterator B = Plugins.begin(), E = Plugins.end();
|
|
|
|
B != E; ++B)
|
|
|
|
delete (*B);
|
|
|
|
}
|
|
|
|
pluginListInitialized = false;
|
2008-09-22 22:49:34 +02:00
|
|
|
}
|
|
|
|
|
2009-10-17 22:09:29 +02:00
|
|
|
void PluginLoader::RunInitialization(LanguageMap& langMap,
|
|
|
|
CompilationGraph& graph) const
|
|
|
|
{
|
2009-07-07 20:33:04 +02:00
|
|
|
llvm::sys::SmartScopedLock<true> Lock(*PluginMutex);
|
2008-09-22 22:51:19 +02:00
|
|
|
for (PluginList::iterator B = Plugins.begin(), E = Plugins.end();
|
2009-10-17 22:09:29 +02:00
|
|
|
B != E; ++B) {
|
|
|
|
const BasePlugin* BP = *B;
|
|
|
|
BP->PreprocessOptions();
|
|
|
|
BP->PopulateLanguageMap(langMap);
|
|
|
|
BP->PopulateCompilationGraph(graph);
|
|
|
|
}
|
2008-09-22 22:49:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|