LLVM API Documentation

PluginLoader.cpp

Go to the documentation of this file.
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 using namespace llvm;
00020 
00021 static std::vector<std::string> *Plugins;
00022 
00023 void PluginLoader::operator=(const std::string &Filename) {
00024   if (!Plugins)
00025     Plugins = new std::vector<std::string>();
00026 
00027   std::string Error;
00028   if (sys::DynamicLibrary::LoadLibraryPermanently(Filename.c_str(), &Error)) {
00029     std::cerr << "Error opening '" << Filename << "': " << Error
00030               << "\n  -load request ignored.\n";
00031   } else {
00032     Plugins->push_back(Filename);
00033   }
00034 }
00035 
00036 unsigned PluginLoader::getNumPlugins() {
00037   return Plugins ? Plugins->size() : 0;
00038 }
00039 
00040 std::string &PluginLoader::getPlugin(unsigned num) {
00041   assert(Plugins && num < Plugins->size() && "Asking for an out of bounds plugin");
00042   return (*Plugins)[num];
00043 }