PageRenderTime 27ms CodeModel.GetById 0ms app.highlight 23ms RepoModel.GetById 1ms app.codeStats 0ms

/3rd_party/llvm/lib/Support/PluginLoader.cpp

https://code.google.com/p/softart/
C++ | 47 lines | 30 code | 5 blank | 12 comment | 3 complexity | 837e418b5b543bc6a0bea9ee52dca636 MD5 | raw file
Possible License(s): LGPL-2.1, BSD-3-Clause, JSON, MPL-2.0-no-copyleft-exception, GPL-2.0, GPL-3.0, LGPL-3.0, BSD-2-Clause
 1//===-- PluginLoader.cpp - Implement -load command line option ------------===//
 2//
 3//                     The LLVM Compiler Infrastructure
 4//
 5// This file is distributed under the University of Illinois Open Source
 6// 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/Support/DynamicLibrary.h"
17#include "llvm/Support/ManagedStatic.h"
18#include "llvm/Support/Mutex.h"
19#include "llvm/Support/raw_ostream.h"
20#include <vector>
21using namespace llvm;
22
23static ManagedStatic<std::vector<std::string> > Plugins;
24static ManagedStatic<sys::SmartMutex<true> > PluginsLock;
25
26void PluginLoader::operator=(const std::string &Filename) {
27  sys::SmartScopedLock<true> Lock(*PluginsLock);
28  std::string Error;
29  if (sys::DynamicLibrary::LoadLibraryPermanently(Filename.c_str(), &Error)) {
30    errs() << "Error opening '" << Filename << "': " << Error
31           << "\n  -load request ignored.\n";
32  } else {
33    Plugins->push_back(Filename);
34  }
35}
36
37unsigned PluginLoader::getNumPlugins() {
38  sys::SmartScopedLock<true> Lock(*PluginsLock);
39  return Plugins.isConstructed() ? Plugins->size() : 0;
40}
41
42std::string &PluginLoader::getPlugin(unsigned num) {
43  sys::SmartScopedLock<true> Lock(*PluginsLock);
44  assert(Plugins.isConstructed() && num < Plugins->size() &&
45         "Asking for an out of bounds plugin");
46  return (*Plugins)[num];
47}