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" |
Reid Spencer | 737459d | 2004-11-29 14:07:46 +0000 | [diff] [blame] | 16 | #include "llvm/System/DynamicLibrary.h" |
Chris Lattner | 0c0edf8 | 2002-07-25 06:17:51 +0000 | [diff] [blame] | 17 | #include <iostream> |
Andrew Lenharth | 4b93476 | 2006-01-26 18:36:50 +0000 | [diff] [blame] | 18 | #include <vector> |
Reid Spencer | 737459d | 2004-11-29 14:07:46 +0000 | [diff] [blame] | 19 | |
Chris Lattner | 2cdd21c | 2003-12-14 21:35:53 +0000 | [diff] [blame] | 20 | using namespace llvm; |
Brian Gaeke | d0fde30 | 2003-11-11 22:41:34 +0000 | [diff] [blame] | 21 | |
Andrew Lenharth | 4b93476 | 2006-01-26 18:36:50 +0000 | [diff] [blame] | 22 | std::vector<std::string> plugins; |
| 23 | |
Chris Lattner | 13a253a | 2004-07-11 01:04:33 +0000 | [diff] [blame] | 24 | void PluginLoader::operator=(const std::string &Filename) { |
| 25 | std::string ErrorMessage; |
Reid Spencer | 737459d | 2004-11-29 14:07:46 +0000 | [diff] [blame] | 26 | try { |
| 27 | sys::DynamicLibrary::LoadLibraryPermanently(Filename.c_str()); |
Andrew Lenharth | 4b93476 | 2006-01-26 18:36:50 +0000 | [diff] [blame] | 28 | plugins.push_back(Filename); |
Reid Spencer | 737459d | 2004-11-29 14:07:46 +0000 | [diff] [blame] | 29 | } catch (const std::string& errmsg) { |
| 30 | if (errmsg.empty()) { |
| 31 | ErrorMessage = "Unknown"; |
| 32 | } else { |
| 33 | ErrorMessage = errmsg; |
| 34 | } |
| 35 | } |
| 36 | if (!ErrorMessage.empty()) |
Chris Lattner | 13a253a | 2004-07-11 01:04:33 +0000 | [diff] [blame] | 37 | std::cerr << "Error opening '" << Filename << "': " << ErrorMessage |
Misha Brukman | 3c94497 | 2005-04-22 04:08:30 +0000 | [diff] [blame] | 38 | << "\n -load request ignored.\n"; |
Chris Lattner | c1b5d09 | 2002-07-23 17:56:53 +0000 | [diff] [blame] | 39 | } |
Andrew Lenharth | 4b93476 | 2006-01-26 18:36:50 +0000 | [diff] [blame] | 40 | |
| 41 | unsigned PluginLoader::getNumPlugins() |
| 42 | { |
| 43 | return plugins.size(); |
| 44 | } |
| 45 | |
| 46 | std::string& PluginLoader::getPlugin(unsigned num) |
| 47 | { |
| 48 | assert(num < plugins.size() && "Asking for an out of bounds plugin"); |
| 49 | return plugins[num]; |
| 50 | } |