blob: 5acf1d13ee9c2c95c20d7293684afd725c2b3130 [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
Julien Lerouged231d182008-10-22 16:30:41 +000015#include "llvm/Support/ManagedStatic.h"
Dan Gohmanf17a25c2007-07-18 16:29:46 +000016#include "llvm/Support/PluginLoader.h"
17#include "llvm/Support/Streams.h"
18#include "llvm/System/DynamicLibrary.h"
19#include <ostream>
20#include <vector>
21using namespace llvm;
22
Julien Lerouged231d182008-10-22 16:30:41 +000023static ManagedStatic<std::vector<std::string> > Plugins;
Dan Gohmanf17a25c2007-07-18 16:29:46 +000024
25void PluginLoader::operator=(const std::string &Filename) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +000026 std::string Error;
27 if (sys::DynamicLibrary::LoadLibraryPermanently(Filename.c_str(), &Error)) {
28 cerr << "Error opening '" << Filename << "': " << Error
29 << "\n -load request ignored.\n";
30 } else {
31 Plugins->push_back(Filename);
32 }
33}
34
35unsigned PluginLoader::getNumPlugins() {
Julien Lerouged231d182008-10-22 16:30:41 +000036 return Plugins.isConstructed() ? Plugins->size() : 0;
Dan Gohmanf17a25c2007-07-18 16:29:46 +000037}
38
39std::string &PluginLoader::getPlugin(unsigned num) {
Julien Lerouged231d182008-10-22 16:30:41 +000040 assert(Plugins.isConstructed() && num < Plugins->size() &&
41 "Asking for an out of bounds plugin");
Dan Gohmanf17a25c2007-07-18 16:29:46 +000042 return (*Plugins)[num];
43}