2002-07-23 17:56:53 +00:00
|
|
|
//===-- PluginLoader.cpp - Implement -load command line option ------------===//
|
2005-04-21 22:55:34 +00:00
|
|
|
//
|
2003-10-20 19:43:21 +00:00
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file was developed by the LLVM research group and is distributed under
|
|
|
|
// the University of Illinois Open Source License. See LICENSE.TXT for details.
|
2005-04-21 22:55:34 +00:00
|
|
|
//
|
2003-10-20 19:43:21 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
2002-07-23 17:56:53 +00:00
|
|
|
//
|
2004-07-11 01:04:33 +00:00
|
|
|
// This file implements the -load <plugin> command line option handler.
|
2002-07-23 17:56:53 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2004-07-11 01:04:33 +00:00
|
|
|
#define DONT_GET_PLUGIN_LOADER_OPTION
|
2004-09-01 22:55:40 +00:00
|
|
|
#include "llvm/Support/PluginLoader.h"
|
2006-11-26 10:52:51 +00:00
|
|
|
#include "llvm/Support/Streams.h"
|
2004-11-29 14:07:46 +00:00
|
|
|
#include "llvm/System/DynamicLibrary.h"
|
2006-12-07 23:41:45 +00:00
|
|
|
#include <ostream>
|
2006-01-26 18:36:50 +00:00
|
|
|
#include <vector>
|
2003-12-14 21:35:53 +00:00
|
|
|
using namespace llvm;
|
2003-11-11 22:41:34 +00:00
|
|
|
|
2006-07-07 17:14:04 +00:00
|
|
|
static std::vector<std::string> *Plugins;
|
2006-01-26 18:36:50 +00:00
|
|
|
|
2004-07-11 01:04:33 +00:00
|
|
|
void PluginLoader::operator=(const std::string &Filename) {
|
2006-07-07 17:14:04 +00:00
|
|
|
if (!Plugins)
|
|
|
|
Plugins = new std::vector<std::string>();
|
2006-01-26 19:38:58 +00:00
|
|
|
|
2006-07-07 17:14:04 +00:00
|
|
|
std::string Error;
|
|
|
|
if (sys::DynamicLibrary::LoadLibraryPermanently(Filename.c_str(), &Error)) {
|
2006-12-07 01:30:32 +00:00
|
|
|
cerr << "Error opening '" << Filename << "': " << Error
|
|
|
|
<< "\n -load request ignored.\n";
|
2006-07-07 17:14:04 +00:00
|
|
|
} else {
|
|
|
|
Plugins->push_back(Filename);
|
|
|
|
}
|
2002-07-23 17:56:53 +00:00
|
|
|
}
|
2006-01-26 18:36:50 +00:00
|
|
|
|
2006-07-07 17:14:04 +00:00
|
|
|
unsigned PluginLoader::getNumPlugins() {
|
|
|
|
return Plugins ? Plugins->size() : 0;
|
2006-01-26 18:36:50 +00:00
|
|
|
}
|
|
|
|
|
2006-07-07 17:14:04 +00:00
|
|
|
std::string &PluginLoader::getPlugin(unsigned num) {
|
|
|
|
assert(Plugins && num < Plugins->size() && "Asking for an out of bounds plugin");
|
|
|
|
return (*Plugins)[num];
|
2006-01-26 18:36:50 +00:00
|
|
|
}
|