LLVM API Documentation
00001 //===-- PluginLoader.cpp - Implement -load command line option ------------===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file was developed by the LLVM research group and is distributed under 00006 // the University of Illinois Open Source License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // This file implements the -load <plugin> command line option handler. 00011 // 00012 //===----------------------------------------------------------------------===// 00013 00014 #define DONT_GET_PLUGIN_LOADER_OPTION 00015 #include "llvm/Support/PluginLoader.h" 00016 #include "llvm/System/DynamicLibrary.h" 00017 #include <iostream> 00018 #include <vector> 00019 00020 using namespace llvm; 00021 00022 static std::vector<std::string>* plugins; 00023 00024 void PluginLoader::operator=(const std::string &Filename) { 00025 std::string ErrorMessage; 00026 00027 if (!plugins) 00028 plugins = new std::vector<std::string>(); 00029 00030 try { 00031 sys::DynamicLibrary::LoadLibraryPermanently(Filename.c_str()); 00032 plugins->push_back(Filename); 00033 } catch (const std::string& errmsg) { 00034 if (errmsg.empty()) { 00035 ErrorMessage = "Unknown"; 00036 } else { 00037 ErrorMessage = errmsg; 00038 } 00039 } 00040 if (!ErrorMessage.empty()) 00041 std::cerr << "Error opening '" << Filename << "': " << ErrorMessage 00042 << "\n -load request ignored.\n"; 00043 } 00044 00045 unsigned PluginLoader::getNumPlugins() 00046 { 00047 if(plugins) 00048 return plugins->size(); 00049 else 00050 return 0; 00051 } 00052 00053 std::string& PluginLoader::getPlugin(unsigned num) 00054 { 00055 assert(plugins && num < plugins->size() && "Asking for an out of bounds plugin"); 00056 return (*plugins)[num]; 00057 }