Cache MangleContext as a private member of the interpreter, so we don't have to re-create it all the time.
Implement JITed version of ExecutionContext::getAddressOfGlobal(), which now also needs a Module. git-svn-id: http://root.cern.ch/svn/root/trunk@46139 27541ba8-7e3a-0410-8455-c3a389f83636
This commit is contained in:
parent
6323e0e50c
commit
621c0173c2
@ -26,6 +26,7 @@ namespace clang {
|
||||
class Decl;
|
||||
class DeclContext;
|
||||
class NamedDecl;
|
||||
class MangleContext;
|
||||
}
|
||||
|
||||
namespace cling {
|
||||
@ -82,6 +83,10 @@ namespace cling {
|
||||
///
|
||||
llvm::OwningPtr<LookupHelper> m_LookupHelper;
|
||||
|
||||
///\brief Helper object for mangling names.
|
||||
///
|
||||
mutable llvm::OwningPtr<clang::MangleContext> m_MangleCtx;
|
||||
|
||||
///\brief Counter used when we need unique names.
|
||||
///
|
||||
unsigned long long m_UniqueCounter;
|
||||
|
@ -273,11 +273,19 @@ bool ExecutionContext::addSymbol(const char* symbolName, void* symbolAddress) {
|
||||
return true;
|
||||
}
|
||||
|
||||
void* ExecutionContext::getAddressOfGlobal(const char* symbolName,
|
||||
bool* fromJIT /*=0*/) const {
|
||||
void* ExecutionContext::getAddressOfGlobal(llvm::Module* m,
|
||||
const char* symbolName,
|
||||
bool* fromJIT /*=0*/) const {
|
||||
// Return a symbol's address, and whether it was jitted.
|
||||
void* actualAddress
|
||||
void* address
|
||||
= llvm::sys::DynamicLibrary::SearchForAddressOfSymbol(symbolName);
|
||||
if (fromJIT) *fromJIT = false;
|
||||
return 0;
|
||||
if (address) {
|
||||
if (fromJIT) *fromJIT = false;
|
||||
} else {
|
||||
if (fromJIT) *fromJIT = true;
|
||||
llvm::GlobalVariable* gvar
|
||||
= m->getGlobalVariable(symbolName, true);
|
||||
address = m_engine->getPointerToGlobalIfAvailable(gvar);
|
||||
}
|
||||
return address;
|
||||
}
|
||||
|
@ -61,10 +61,12 @@ namespace cling {
|
||||
/// JIT symbols might not be immediately convertible to e.g. a function
|
||||
/// pointer as their call setup is different.
|
||||
///
|
||||
///\param[in] D - the global's Decl to find
|
||||
///\param[in] m - the module to use for finging the global
|
||||
///\param[in] mangledName - the globa's name
|
||||
///\param[out] fromJIT - whether the symbol was JITted.
|
||||
///
|
||||
void* getAddressOfGlobal(const char* mangledName, bool* fromJIT = 0) const;
|
||||
void* getAddressOfGlobal(llvm::Module* m, const char* mangledName,
|
||||
bool* fromJIT = 0) const;
|
||||
|
||||
llvm::ExecutionEngine* getExecutionEngine() const {
|
||||
return m_engine;
|
||||
|
@ -768,11 +768,12 @@ namespace cling {
|
||||
///
|
||||
///D - mangle this decl's name
|
||||
///mangledName - put the mangled name in here
|
||||
llvm::OwningPtr<MangleContext>
|
||||
Mangle(getCI()->getASTContext().createMangleContext());
|
||||
if (Mangle->shouldMangleDeclName(D)) {
|
||||
if (!m_MangleCtx) {
|
||||
m_MangleCtx.reset(getCI()->getASTContext().createMangleContext());
|
||||
}
|
||||
if (m_MangleCtx->shouldMangleDeclName(D)) {
|
||||
llvm::raw_string_ostream RawStr(mangledName);
|
||||
Mangle->mangleName(D, RawStr);
|
||||
m_MangleCtx->mangleName(D, RawStr);
|
||||
RawStr.flush();
|
||||
} else {
|
||||
mangledName = D->getNameAsString();
|
||||
@ -793,7 +794,10 @@ namespace cling {
|
||||
// Return a symbol's address, and whether it was jitted.
|
||||
std::string mangledName;
|
||||
getMangledName(D, mangledName);
|
||||
return m_ExecutionContext->getAddressOfGlobal(mangledName.c_str(), fromJIT);
|
||||
llvm::Module* module = m_IncrParser->getCodeGenerator()->GetModule();
|
||||
return m_ExecutionContext->getAddressOfGlobal(module,
|
||||
mangledName.c_str(),
|
||||
fromJIT);
|
||||
}
|
||||
|
||||
} // namespace cling
|
||||
|
Loading…
Reference in New Issue
Block a user