2002-07-23 19:56:53 +02:00
|
|
|
//===-- PluginLoader.cpp - Implement -load command line option ------------===//
|
2005-04-22 00:55:34 +02:00
|
|
|
//
|
2003-10-20 21:43:21 +02:00
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-29 21:36:04 +01:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2005-04-22 00:55:34 +02:00
|
|
|
//
|
2003-10-20 21:43:21 +02:00
|
|
|
//===----------------------------------------------------------------------===//
|
2002-07-23 19:56:53 +02:00
|
|
|
//
|
2004-07-11 03:04:33 +02:00
|
|
|
// This file implements the -load <plugin> command line option handler.
|
2002-07-23 19:56:53 +02:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2004-07-11 03:04:33 +02:00
|
|
|
#define DONT_GET_PLUGIN_LOADER_OPTION
|
2008-10-22 18:30:41 +02:00
|
|
|
#include "llvm/Support/ManagedStatic.h"
|
2004-09-02 00:55:40 +02:00
|
|
|
#include "llvm/Support/PluginLoader.h"
|
2009-08-23 10:43:55 +02:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2004-11-29 15:07:46 +01:00
|
|
|
#include "llvm/System/DynamicLibrary.h"
|
2009-06-23 02:02:39 +02:00
|
|
|
#include "llvm/System/Mutex.h"
|
2006-01-26 19:36:50 +01:00
|
|
|
#include <vector>
|
2003-12-14 22:35:53 +01:00
|
|
|
using namespace llvm;
|
2003-11-11 23:41:34 +01:00
|
|
|
|
2008-10-22 18:30:41 +02:00
|
|
|
static ManagedStatic<std::vector<std::string> > Plugins;
|
2009-06-23 02:02:39 +02:00
|
|
|
static ManagedStatic<sys::SmartMutex<true> > PluginsLock;
|
2006-01-26 19:36:50 +01:00
|
|
|
|
2004-07-11 03:04:33 +02:00
|
|
|
void PluginLoader::operator=(const std::string &Filename) {
|
2009-07-07 20:33:04 +02:00
|
|
|
sys::SmartScopedLock<true> Lock(*PluginsLock);
|
2006-07-07 19:14:04 +02:00
|
|
|
std::string Error;
|
|
|
|
if (sys::DynamicLibrary::LoadLibraryPermanently(Filename.c_str(), &Error)) {
|
2009-08-23 10:43:55 +02:00
|
|
|
errs() << "Error opening '" << Filename << "': " << Error
|
|
|
|
<< "\n -load request ignored.\n";
|
2006-07-07 19:14:04 +02:00
|
|
|
} else {
|
|
|
|
Plugins->push_back(Filename);
|
|
|
|
}
|
2002-07-23 19:56:53 +02:00
|
|
|
}
|
2006-01-26 19:36:50 +01:00
|
|
|
|
2006-07-07 19:14:04 +02:00
|
|
|
unsigned PluginLoader::getNumPlugins() {
|
2009-07-07 20:33:04 +02:00
|
|
|
sys::SmartScopedLock<true> Lock(*PluginsLock);
|
2008-10-22 18:30:41 +02:00
|
|
|
return Plugins.isConstructed() ? Plugins->size() : 0;
|
2006-01-26 19:36:50 +01:00
|
|
|
}
|
|
|
|
|
2006-07-07 19:14:04 +02:00
|
|
|
std::string &PluginLoader::getPlugin(unsigned num) {
|
2009-07-07 20:33:04 +02:00
|
|
|
sys::SmartScopedLock<true> Lock(*PluginsLock);
|
2008-10-22 18:30:41 +02:00
|
|
|
assert(Plugins.isConstructed() && num < Plugins->size() &&
|
|
|
|
"Asking for an out of bounds plugin");
|
2006-07-07 19:14:04 +02:00
|
|
|
return (*Plugins)[num];
|
2006-01-26 19:36:50 +01:00
|
|
|
}
|