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/System/DynamicLibrary.h"
22 std::vector<std::string> plugins;
24 void PluginLoader::operator=(const std::string &Filename) {
25 std::string ErrorMessage;
27 sys::DynamicLibrary::LoadLibraryPermanently(Filename.c_str());
28 plugins.push_back(Filename);
29 } catch (const std::string& errmsg) {
31 ErrorMessage = "Unknown";
33 ErrorMessage = errmsg;
36 if (!ErrorMessage.empty())
37 std::cerr << "Error opening '" << Filename << "': " << ErrorMessage
38 << "\n -load request ignored.\n";
41 unsigned PluginLoader::getNumPlugins()
43 return plugins.size();
46 std::string& PluginLoader::getPlugin(unsigned num)
48 assert(num < plugins.size() && "Asking for an out of bounds plugin");