Reverting back to original 1.8 version so I can manually merge in patch.
[llvm-complete.git] / lib / Support / PluginLoader.cpp
blob2ed9836fd09ad8fc31dd78d17a67e35b944c42ad
1 //===-- PluginLoader.cpp - Implement -load command line option ------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file was developed by the LLVM research group and is distributed under
6 // the University of Illinois Open Source License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file implements the -load <plugin> command line option handler.
12 //===----------------------------------------------------------------------===//
14 #define DONT_GET_PLUGIN_LOADER_OPTION
15 #include "llvm/Support/PluginLoader.h"
16 #include "llvm/System/DynamicLibrary.h"
17 #include <iostream>
18 #include <vector>
19 using namespace llvm;
21 static std::vector<std::string> *Plugins;
23 void PluginLoader::operator=(const std::string &Filename) {
24 if (!Plugins)
25 Plugins = new std::vector<std::string>();
27 std::string Error;
28 if (sys::DynamicLibrary::LoadLibraryPermanently(Filename.c_str(), &Error)) {
29 std::cerr << "Error opening '" << Filename << "': " << Error
30 << "\n -load request ignored.\n";
31 } else {
32 Plugins->push_back(Filename);
36 unsigned PluginLoader::getNumPlugins() {
37 return Plugins ? Plugins->size() : 0;
40 std::string &PluginLoader::getPlugin(unsigned num) {
41 assert(Plugins && num < Plugins->size() && "Asking for an out of bounds plugin");
42 return (*Plugins)[num];