blob: 0635a9d52ca375eae3174ad84e43f19d5504db51 [file] [log] [blame]
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001//===-- PluginLoader.cpp - Implement -load command line option ------------===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner081ce942007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Dan Gohmanf17a25c2007-07-18 16:29:46 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This file implements the -load <plugin> command line option handler.
11//
12//===----------------------------------------------------------------------===//
13
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"
18#include <ostream>
19#include <vector>
20using namespace llvm;
21
22static std::vector<std::string> *Plugins;
23
24void PluginLoader::operator=(const std::string &Filename) {
25 if (!Plugins)
26 Plugins = new std::vector<std::string>();
27
28 std::string Error;
29 if (sys::DynamicLibrary::LoadLibraryPermanently(Filename.c_str(), &Error)) {
30 cerr << "Error opening '" << Filename << "': " << Error
31 << "\n -load request ignored.\n";
32 } else {
33 Plugins->push_back(Filename);
34 }
35}
36
37unsigned PluginLoader::getNumPlugins() {
38 return Plugins ? Plugins->size() : 0;
39}
40
41std::string &PluginLoader::getPlugin(unsigned num) {
42 assert(Plugins && num < Plugins->size() && "Asking for an out of bounds plugin");
43 return (*Plugins)[num];
44}