1 //===-- PluginLoader.cpp - Implement -load command line option ------------===//
3 // The LLVM Compiler Infrastructure
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.
8 //===----------------------------------------------------------------------===//
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/Support/Streams.h"
17 #include "llvm/System/DynamicLibrary.h"
22 static std::vector<std::string> *Plugins;
24 void PluginLoader::operator=(const std::string &Filename) {
26 Plugins = new std::vector<std::string>();
29 if (sys::DynamicLibrary::LoadLibraryPermanently(Filename.c_str(), &Error)) {
30 cerr << "Error opening '" << Filename << "': " << Error
31 << "\n -load request ignored.\n";
33 Plugins->push_back(Filename);
37 unsigned PluginLoader::getNumPlugins() {
38 return Plugins ? Plugins->size() : 0;
41 std::string &PluginLoader::getPlugin(unsigned num) {
42 assert(Plugins && num < Plugins->size() && "Asking for an out of bounds plugin");
43 return (*Plugins)[num];