LCOV - code coverage report
Current view: top level - lib/Support - PluginLoader.cpp (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 12 14 85.7 %
Date: 2017-09-14 15:23:50 Functions: 3 3 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       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>
      21             : using namespace llvm;
      22             : 
      23             : static ManagedStatic<std::vector<std::string> > Plugins;
      24             : static ManagedStatic<sys::SmartMutex<true> > PluginsLock;
      25             : 
      26          95 : void PluginLoader::operator=(const std::string &Filename) {
      27         285 :   sys::SmartScopedLock<true> Lock(*PluginsLock);
      28         190 :   std::string Error;
      29         190 :   if (sys::DynamicLibrary::LoadLibraryPermanently(Filename.c_str(), &Error)) {
      30           0 :     errs() << "Error opening '" << Filename << "': " << Error
      31           0 :            << "\n  -load request ignored.\n";
      32             :   } else {
      33          95 :     Plugins->push_back(Filename);
      34             :   }
      35          95 : }
      36             : 
      37         211 : unsigned PluginLoader::getNumPlugins() {
      38         633 :   sys::SmartScopedLock<true> Lock(*PluginsLock);
      39         844 :   return Plugins.isConstructed() ? Plugins->size() : 0;
      40             : }
      41             : 
      42         211 : std::string &PluginLoader::getPlugin(unsigned num) {
      43         633 :   sys::SmartScopedLock<true> Lock(*PluginsLock);
      44             :   assert(Plugins.isConstructed() && num < Plugins->size() &&
      45             :          "Asking for an out of bounds plugin");
      46         633 :   return (*Plugins)[num];
      47             : }

Generated by: LCOV version 1.13