1 //===-- PluginLoader.cpp - Implement -load command line option ------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // 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/ManagedStatic.h"
16 #include "llvm/Support/PluginLoader.h"
17 #include "llvm/Support/Streams.h"
18 #include "llvm/System/DynamicLibrary.h"
23 static ManagedStatic
<std::vector
<std::string
> > Plugins
;
25 void PluginLoader::operator=(const std::string
&Filename
) {
27 if (sys::DynamicLibrary::LoadLibraryPermanently(Filename
.c_str(), &Error
)) {
28 cerr
<< "Error opening '" << Filename
<< "': " << Error
29 << "\n -load request ignored.\n";
31 Plugins
->push_back(Filename
);
35 unsigned PluginLoader::getNumPlugins() {
36 return Plugins
.isConstructed() ? Plugins
->size() : 0;
39 std::string
&PluginLoader::getPlugin(unsigned num
) {
40 assert(Plugins
.isConstructed() && num
< Plugins
->size() &&
41 "Asking for an out of bounds plugin");
42 return (*Plugins
)[num
];