Move isLoadFrom/StoreToStackSlot from MRegisterInfo to TargetInstrInfo,a far more...
[oota-llvm.git] / lib / Support / PluginLoader.cpp
1 //===-- PluginLoader.cpp - Implement -load command line option ------------===//
2 //
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.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file implements the -load <plugin> command line option handler.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #define DONT_GET_PLUGIN_LOADER_OPTION
15 #include "llvm/Support/PluginLoader.h"
16 #include "llvm/System/DynamicLibrary.h"
17 #include <iostream>
18 #include <vector>
19
20 using namespace llvm;
21
22 static std::vector<std::string>* plugins;
23
24 void PluginLoader::operator=(const std::string &Filename) {
25   std::string ErrorMessage;
26
27   if (!plugins)
28     plugins = new std::vector<std::string>();
29
30   try {
31     sys::DynamicLibrary::LoadLibraryPermanently(Filename.c_str());
32     plugins->push_back(Filename);
33   } catch (const std::string& errmsg) {
34     if (errmsg.empty()) {
35       ErrorMessage = "Unknown";
36     } else {
37       ErrorMessage = errmsg;
38     }
39   }
40   if (!ErrorMessage.empty())
41     std::cerr << "Error opening '" << Filename << "': " << ErrorMessage
42               << "\n  -load request ignored.\n";
43 }
44
45 unsigned PluginLoader::getNumPlugins()
46 {
47   if(plugins)
48     return plugins->size();
49   else 
50     return 0;
51 }
52
53 std::string& PluginLoader::getPlugin(unsigned num)
54 {
55   assert(plugins && num < plugins->size() && "Asking for an out of bounds plugin");
56   return (*plugins)[num];
57 }