We don't need to keep track of the .L-ed files. The implementation of TCling is very raw and I bet we can improve it a lot.
This commit is contained in:
parent
156e74b8dd
commit
b4f912f8c5
@ -9,13 +9,12 @@
|
||||
|
||||
#include "cling/Interpreter/InvocationOptions.h"
|
||||
|
||||
#include "llvm/ADT/DenseMap.h"
|
||||
#include "llvm/ADT/OwningPtr.h"
|
||||
#include "llvm/ADT/StringRef.h"
|
||||
|
||||
#include <cstdlib>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <set>
|
||||
|
||||
namespace llvm {
|
||||
class raw_ostream;
|
||||
@ -120,44 +119,6 @@ namespace cling {
|
||||
kNumExeResults
|
||||
};
|
||||
|
||||
|
||||
class LoadedFileInfo {
|
||||
public:
|
||||
enum FileType {
|
||||
kSource,
|
||||
kDynamicLibrary,
|
||||
kNumFileTypes
|
||||
};
|
||||
|
||||
///\brief Name as loaded for the first time.
|
||||
///
|
||||
const std::string& getName() const { return m_Name; }
|
||||
|
||||
///\brief Type of the file.
|
||||
FileType getType() const { return m_Type; }
|
||||
|
||||
const void* getDyLibHandle() const { return m_DynLibHandle; }
|
||||
|
||||
private:
|
||||
///\brief Constructor used by Interpreter.
|
||||
LoadedFileInfo(const std::string& name, FileType type,
|
||||
const void* dynLibHandle):
|
||||
m_Name(name), m_Type(type), m_DynLibHandle(dynLibHandle) {}
|
||||
|
||||
///\brief Name as loaded for the first time.
|
||||
///
|
||||
std::string m_Name;
|
||||
|
||||
///\brief Type of the file.
|
||||
FileType m_Type;
|
||||
|
||||
///\brief A shared library handle if dynamic library
|
||||
///
|
||||
const void* m_DynLibHandle;
|
||||
|
||||
friend class Interpreter;
|
||||
};
|
||||
|
||||
private:
|
||||
|
||||
///\brief Interpreter invocation options.
|
||||
@ -260,13 +221,11 @@ namespace cling {
|
||||
///
|
||||
std::vector<CXAAtExitElement> m_AtExitFuncs;
|
||||
|
||||
typedef const void* DyLibHandle;
|
||||
typedef llvm::DenseMap<DyLibHandle, std::string> DyLibs;
|
||||
///\brief DynamicLibraries loaded by this Interpreter.
|
||||
///
|
||||
std::set<const void*> m_DyLibs;
|
||||
|
||||
///\brief Information about loaded files.
|
||||
///
|
||||
std::vector<LoadedFileInfo*> m_LoadedFiles;
|
||||
DyLibs m_DyLibs;
|
||||
|
||||
///\brief Information about the last stored states through .storeState
|
||||
///
|
||||
@ -277,9 +236,6 @@ namespace cling {
|
||||
LoadLibResult tryLinker(const std::string& filename, bool permanent,
|
||||
bool isAbsolute, bool& exists, bool& isDyLib);
|
||||
|
||||
void addLoadedFile(const std::string& name, LoadedFileInfo::FileType type,
|
||||
const void* dyLibHandle = 0);
|
||||
|
||||
///\brief Processes the invocation options.
|
||||
///
|
||||
void handleFrontendOptions();
|
||||
@ -610,17 +566,18 @@ namespace cling {
|
||||
LoadLibResult loadLibrary(const std::string& filename, bool permanent,
|
||||
bool *tryCode = 0);
|
||||
|
||||
|
||||
///\brief Returns true if the file was a dynamic library and it was already
|
||||
/// loaded.
|
||||
///
|
||||
bool isDynamicLibraryLoaded(llvm::StringRef fullPath) const;
|
||||
|
||||
///\brief Explicitly tell the execution engine to use symbols from
|
||||
/// a shared library that would otherwise not be used for symbol
|
||||
/// resolution, e.g. because it was dlopened with RTLD_LOCAL.
|
||||
///\param [in] DyLibHandle - the system specific shared library handle.
|
||||
static void ExposeHiddenSharedLibrarySymbols(void* DyLibHandle);
|
||||
|
||||
///\brief Get the collection of loaded files.
|
||||
///
|
||||
const std::vector<LoadedFileInfo*>& getLoadedFiles() const {
|
||||
return m_LoadedFiles;
|
||||
}
|
||||
static void ExposeHiddenSharedLibrarySymbols(void* DyLibHandle);
|
||||
|
||||
bool isPrintingAST() const { return m_PrintAST; }
|
||||
void enablePrintAST(bool print = true) { m_PrintAST = print; }
|
||||
|
@ -163,7 +163,6 @@ namespace cling {
|
||||
m_DynamicLookupEnabled(false), m_RawInputEnabled(false) {
|
||||
|
||||
m_AtExitFuncs.reserve(200);
|
||||
m_LoadedFiles.reserve(20);
|
||||
|
||||
m_LLVMContext.reset(new llvm::LLVMContext);
|
||||
std::vector<unsigned> LeftoverArgsIdx;
|
||||
@ -744,12 +743,6 @@ namespace cling {
|
||||
return Interpreter::kFailure;
|
||||
}
|
||||
|
||||
void Interpreter::addLoadedFile(const std::string& name,
|
||||
Interpreter::LoadedFileInfo::FileType type,
|
||||
const void* dyLibHandle) {
|
||||
m_LoadedFiles.push_back(new LoadedFileInfo(name, type, dyLibHandle));
|
||||
}
|
||||
|
||||
Interpreter::CompilationResult
|
||||
Interpreter::loadFile(const std::string& filename,
|
||||
bool allowSharedLib /*=true*/) {
|
||||
@ -764,8 +757,6 @@ namespace cling {
|
||||
std::string code;
|
||||
code += "#include \"" + filename + "\"";
|
||||
CompilationResult res = declare(code);
|
||||
if (res == kSuccess)
|
||||
addLoadedFile(filename, LoadedFileInfo::kSource);
|
||||
return res;
|
||||
}
|
||||
|
||||
@ -833,26 +824,25 @@ namespace cling {
|
||||
|
||||
// TODO: !permanent case
|
||||
#ifdef WIN32
|
||||
void* DyLibHandle = needs to be implemented!;
|
||||
void* dyLibHandle = needs to be implemented!;
|
||||
std::string errMsg;
|
||||
#else
|
||||
const void* DyLibHandle
|
||||
const void* dyLibHandle
|
||||
= dlopen(FoundDyLib.str().c_str(), RTLD_LAZY|RTLD_GLOBAL);
|
||||
std::string errMsg;
|
||||
if (const char* DyLibError = dlerror()) {
|
||||
errMsg = DyLibError;
|
||||
}
|
||||
#endif
|
||||
if (!DyLibHandle) {
|
||||
if (!dyLibHandle) {
|
||||
llvm::errs() << "cling::Interpreter::tryLinker(): " << errMsg << '\n';
|
||||
return kLoadLibError;
|
||||
}
|
||||
std::pair<std::set<const void*>::iterator, bool> insRes
|
||||
= m_DyLibs.insert(DyLibHandle);
|
||||
std::pair<DyLibs::iterator, bool> insRes
|
||||
= m_DyLibs.insert(std::pair<DyLibHandle, std::string>(dyLibHandle,
|
||||
FoundDyLib.str()));
|
||||
if (!insRes.second)
|
||||
return kLoadLibExists;
|
||||
addLoadedFile(FoundDyLib.str(), LoadedFileInfo::kDynamicLibrary,
|
||||
DyLibHandle);
|
||||
return kLoadLibSuccess;
|
||||
}
|
||||
|
||||
@ -893,6 +883,15 @@ namespace cling {
|
||||
return kLoadLibError;
|
||||
}
|
||||
|
||||
bool Interpreter::isDynamicLibraryLoaded(llvm::StringRef fullPath) const {
|
||||
for(DyLibs::const_iterator I = m_DyLibs.begin(), E = m_DyLibs.end();
|
||||
I != E; ++I) {
|
||||
if (fullPath.equals((I->second)))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void
|
||||
Interpreter::ExposeHiddenSharedLibrarySymbols(void* DyLibHandle) {
|
||||
llvm::sys::DynamicLibrary::addPermanentLibrary(const_cast<void*>(DyLibHandle));
|
||||
|
Loading…
Reference in New Issue
Block a user