#ifndef __SHARED__LIBRARY__MANIPULATION_HPP
#define __SHARED__LIBRARY__MANIPULATION_HPP

#include <llvm/Module.h>
#include <memory>
#include <string>

/*!
  Given a shared library with embedded bitcode fragments (in a .llvm_bc ELF
  section), extract them all and link into a single whole-library bitcode file.

  This process will create an LLVM Module, which it will return.

  If no such section exists, throw an exception.
 */
std::auto_ptr<llvm::Module> assembleBitcodeFile(const std::string & sharedLib);

/*!
  Given a shared library with an embedded .llvm_pid ELF section, extract it
  and return the contents.

  If no section exists, throw an exception.
 */
std::string extractPartialInterfaceDescription(const std::string & sharedLib);

/*!
  Run ldd over the shared library and return a list of all shared library deps that need to be loaded

  Each entry is in the form "libBLAH.id".  Basically, all shared object
  dependencies just have their extension replaced by .id
  
  This is not 100% complete, and some libraries may require additional explicitly
  provided deps.  One example of this is the GSL library - it has an implicit
  dependency on a BLAS implementation, but this does not show up in the ldd output
  because GSL does not directly link to a BLAS.
 */
std::vector<std::string> findImplicitDependencies(const std::string & sharedLib);

#endif // __SHARED__LIBRARY__MANIPULATION_HPP
