2002-07-24 01:56:53 +08:00
|
|
|
//===-- PluginLoader.cpp - Implement -load command line option ------------===//
|
2005-04-22 06:55:34 +08:00
|
|
|
//
|
2003-10-21 03:43:21 +08: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-22 06:55:34 +08:00
|
|
|
//
|
2003-10-21 03:43:21 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
2002-07-24 01:56:53 +08:00
|
|
|
//
|
2004-07-11 09:04:33 +08:00
|
|
|
// This file implements the -load <plugin> command line option handler.
|
2002-07-24 01:56:53 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2004-07-11 09:04:33 +08:00
|
|
|
#define DONT_GET_PLUGIN_LOADER_OPTION
|
2004-09-02 06:55:40 +08:00
|
|
|
#include "llvm/Support/PluginLoader.h"
|
2004-11-29 22:07:46 +08:00
|
|
|
#include "llvm/System/DynamicLibrary.h"
|
2002-07-25 14:17:51 +08:00
|
|
|
#include <iostream>
|
2006-01-27 02:36:50 +08:00
|
|
|
#include <vector>
|
2004-11-29 22:07:46 +08:00
|
|
|
|
2003-12-15 05:35:53 +08:00
|
|
|
using namespace llvm;
|
2003-11-12 06:41:34 +08:00
|
|
|
|
2006-01-27 03:38:58 +08:00
|
|
|
static std::vector<std::string>* plugins;
|
2006-01-27 02:36:50 +08:00
|
|
|
|
2004-07-11 09:04:33 +08:00
|
|
|
void PluginLoader::operator=(const std::string &Filename) {
|
|
|
|
std::string ErrorMessage;
|
2006-01-27 03:38:58 +08:00
|
|
|
|
|
|
|
if (!plugins)
|
|
|
|
plugins = new std::vector<std::string>();
|
|
|
|
|
2004-11-29 22:07:46 +08:00
|
|
|
try {
|
|
|
|
sys::DynamicLibrary::LoadLibraryPermanently(Filename.c_str());
|
2006-01-27 03:38:58 +08:00
|
|
|
plugins->push_back(Filename);
|
2004-11-29 22:07:46 +08:00
|
|
|
} catch (const std::string& errmsg) {
|
|
|
|
if (errmsg.empty()) {
|
|
|
|
ErrorMessage = "Unknown";
|
|
|
|
} else {
|
|
|
|
ErrorMessage = errmsg;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!ErrorMessage.empty())
|
2004-07-11 09:04:33 +08:00
|
|
|
std::cerr << "Error opening '" << Filename << "': " << ErrorMessage
|
2005-04-22 12:08:30 +08:00
|
|
|
<< "\n -load request ignored.\n";
|
2002-07-24 01:56:53 +08:00
|
|
|
}
|
2006-01-27 02:36:50 +08:00
|
|
|
|
|
|
|
unsigned PluginLoader::getNumPlugins()
|
|
|
|
{
|
2006-01-27 03:38:58 +08:00
|
|
|
if(plugins)
|
|
|
|
return plugins->size();
|
|
|
|
else
|
|
|
|
return 0;
|
2006-01-27 02:36:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string& PluginLoader::getPlugin(unsigned num)
|
|
|
|
{
|
2006-01-27 03:38:58 +08:00
|
|
|
assert(plugins && num < plugins->size() && "Asking for an out of bounds plugin");
|
|
|
|
return (*plugins)[num];
|
2006-01-27 02:36:50 +08:00
|
|
|
}
|