blob: 97b253e4eb6fc1fd526e3b1d95c7f77d0fae52bf [file] [log] [blame]
Chris Lattner2c54a0d2002-07-23 17:56:53 +00001//===-- PluginLoader.cpp - Implement -load command line option ------------===//
Misha Brukman10468d82005-04-21 22:55:34 +00002//
John Criswell482202a2003-10-20 19:43:21 +00003// The LLVM Compiler Infrastructure
4//
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.
Misha Brukman10468d82005-04-21 22:55:34 +00007//
John Criswell482202a2003-10-20 19:43:21 +00008//===----------------------------------------------------------------------===//
Chris Lattner2c54a0d2002-07-23 17:56:53 +00009//
Chris Lattner99dcad42004-07-11 01:04:33 +000010// This file implements the -load <plugin> command line option handler.
Chris Lattner2c54a0d2002-07-23 17:56:53 +000011//
12//===----------------------------------------------------------------------===//
13
Chris Lattner99dcad42004-07-11 01:04:33 +000014#define DONT_GET_PLUGIN_LOADER_OPTION
Reid Spencer7c16caa2004-09-01 22:55:40 +000015#include "llvm/Support/PluginLoader.h"
Bill Wendling3750ae22006-11-26 10:52:51 +000016#include "llvm/Support/Streams.h"
Reid Spencer9ec27612004-11-29 14:07:46 +000017#include "llvm/System/DynamicLibrary.h"
Andrew Lenharthbb4c9c02006-01-26 18:36:50 +000018#include <vector>
Chris Lattnerc9499b62003-12-14 21:35:53 +000019using namespace llvm;
Brian Gaeke960707c2003-11-11 22:41:34 +000020
Chris Lattnera41def52006-07-07 17:14:04 +000021static std::vector<std::string> *Plugins;
Andrew Lenharthbb4c9c02006-01-26 18:36:50 +000022
Chris Lattner99dcad42004-07-11 01:04:33 +000023void PluginLoader::operator=(const std::string &Filename) {
Chris Lattnera41def52006-07-07 17:14:04 +000024 if (!Plugins)
25 Plugins = new std::vector<std::string>();
Andrew Lenharth4558e4a2006-01-26 19:38:58 +000026
Chris Lattnera41def52006-07-07 17:14:04 +000027 std::string Error;
28 if (sys::DynamicLibrary::LoadLibraryPermanently(Filename.c_str(), &Error)) {
Bill Wendlingf3baad32006-12-07 01:30:32 +000029 cerr << "Error opening '" << Filename << "': " << Error
30 << "\n -load request ignored.\n";
Chris Lattnera41def52006-07-07 17:14:04 +000031 } else {
32 Plugins->push_back(Filename);
33 }
Chris Lattner2c54a0d2002-07-23 17:56:53 +000034}
Andrew Lenharthbb4c9c02006-01-26 18:36:50 +000035
Chris Lattnera41def52006-07-07 17:14:04 +000036unsigned PluginLoader::getNumPlugins() {
37 return Plugins ? Plugins->size() : 0;
Andrew Lenharthbb4c9c02006-01-26 18:36:50 +000038}
39
Chris Lattnera41def52006-07-07 17:14:04 +000040std::string &PluginLoader::getPlugin(unsigned num) {
41 assert(Plugins && num < Plugins->size() && "Asking for an out of bounds plugin");
42 return (*Plugins)[num];
Andrew Lenharthbb4c9c02006-01-26 18:36:50 +000043}