Chris Lattner | c1b5d09 | 2002-07-23 17:56:53 +0000 | [diff] [blame] | 1 | //===-- PluginLoader.cpp - Implement -load command line option ------------===// |
Misha Brukman | f976c85 | 2005-04-21 22:55:34 +0000 | [diff] [blame] | 2 | // |
John Criswell | b576c94 | 2003-10-20 19:43:21 +0000 | [diff] [blame] | 3 | // 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 Brukman | f976c85 | 2005-04-21 22:55:34 +0000 | [diff] [blame] | 7 | // |
John Criswell | b576c94 | 2003-10-20 19:43:21 +0000 | [diff] [blame] | 8 | //===----------------------------------------------------------------------===// |
Chris Lattner | c1b5d09 | 2002-07-23 17:56:53 +0000 | [diff] [blame] | 9 | // |
Chris Lattner | 13a253a | 2004-07-11 01:04:33 +0000 | [diff] [blame] | 10 | // This file implements the -load <plugin> command line option handler. |
Chris Lattner | c1b5d09 | 2002-07-23 17:56:53 +0000 | [diff] [blame] | 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Chris Lattner | 13a253a | 2004-07-11 01:04:33 +0000 | [diff] [blame] | 14 | #define DONT_GET_PLUGIN_LOADER_OPTION |
Reid Spencer | 551ccae | 2004-09-01 22:55:40 +0000 | [diff] [blame] | 15 | #include "llvm/Support/PluginLoader.h" |
Bill Wendling | fe6b146 | 2006-11-26 10:52:51 +0000 | [diff] [blame] | 16 | #include "llvm/Support/Streams.h" |
Reid Spencer | 737459d | 2004-11-29 14:07:46 +0000 | [diff] [blame] | 17 | #include "llvm/System/DynamicLibrary.h" |
Andrew Lenharth | 4b93476 | 2006-01-26 18:36:50 +0000 | [diff] [blame] | 18 | #include <vector> |
Chris Lattner | 2cdd21c | 2003-12-14 21:35:53 +0000 | [diff] [blame] | 19 | using namespace llvm; |
Brian Gaeke | d0fde30 | 2003-11-11 22:41:34 +0000 | [diff] [blame] | 20 | |
Chris Lattner | 17aa9d3 | 2006-07-07 17:14:04 +0000 | [diff] [blame] | 21 | static std::vector<std::string> *Plugins; |
Andrew Lenharth | 4b93476 | 2006-01-26 18:36:50 +0000 | [diff] [blame] | 22 | |
Chris Lattner | 13a253a | 2004-07-11 01:04:33 +0000 | [diff] [blame] | 23 | void PluginLoader::operator=(const std::string &Filename) { |
Chris Lattner | 17aa9d3 | 2006-07-07 17:14:04 +0000 | [diff] [blame] | 24 | if (!Plugins) |
| 25 | Plugins = new std::vector<std::string>(); |
Andrew Lenharth | 9d90144 | 2006-01-26 19:38:58 +0000 | [diff] [blame] | 26 | |
Chris Lattner | 17aa9d3 | 2006-07-07 17:14:04 +0000 | [diff] [blame] | 27 | std::string Error; |
| 28 | if (sys::DynamicLibrary::LoadLibraryPermanently(Filename.c_str(), &Error)) { |
Bill Wendling | e815619 | 2006-12-07 01:30:32 +0000 | [diff] [blame] | 29 | cerr << "Error opening '" << Filename << "': " << Error |
| 30 | << "\n -load request ignored.\n"; |
Chris Lattner | 17aa9d3 | 2006-07-07 17:14:04 +0000 | [diff] [blame] | 31 | } else { |
| 32 | Plugins->push_back(Filename); |
| 33 | } |
Chris Lattner | c1b5d09 | 2002-07-23 17:56:53 +0000 | [diff] [blame] | 34 | } |
Andrew Lenharth | 4b93476 | 2006-01-26 18:36:50 +0000 | [diff] [blame] | 35 | |
Chris Lattner | 17aa9d3 | 2006-07-07 17:14:04 +0000 | [diff] [blame] | 36 | unsigned PluginLoader::getNumPlugins() { |
| 37 | return Plugins ? Plugins->size() : 0; |
Andrew Lenharth | 4b93476 | 2006-01-26 18:36:50 +0000 | [diff] [blame] | 38 | } |
| 39 | |
Chris Lattner | 17aa9d3 | 2006-07-07 17:14:04 +0000 | [diff] [blame] | 40 | std::string &PluginLoader::getPlugin(unsigned num) { |
| 41 | assert(Plugins && num < Plugins->size() && "Asking for an out of bounds plugin"); |
| 42 | return (*Plugins)[num]; |
Andrew Lenharth | 4b93476 | 2006-01-26 18:36:50 +0000 | [diff] [blame] | 43 | } |