LLVM  8.0.1
PluginLoader.cpp
Go to the documentation of this file.
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
18 #include "llvm/Support/Mutex.h"
20 #include <vector>
21 using namespace llvm;
22 
25 
26 void 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 
38  sys::SmartScopedLock<true> Lock(*PluginsLock);
39  return Plugins.isConstructed() ? Plugins->size() : 0;
40 }
41 
42 std::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 }
raw_ostream & errs()
This returns a reference to a raw_ostream for standard error.
This class represents lattice values for constants.
Definition: AllocatorList.h:24
void operator=(const std::string &Filename)
static sys::Mutex Lock
static ManagedStatic< sys::SmartMutex< true > > PluginsLock
static bool LoadLibraryPermanently(const char *Filename, std::string *ErrMsg=nullptr)
This function permanently loads the dynamic library at the given path.
static unsigned getNumPlugins()
static ManagedStatic< std::vector< std::string > > Plugins
bool isConstructed() const
isConstructed - Return true if this object has not been created yet.
Definition: ManagedStatic.h:49
static std::string & getPlugin(unsigned num)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
ManagedStatic - This transparently changes the behavior of global statics to be lazily constructed on...
Definition: ManagedStatic.h:61