diff --git a/interpreter/cling/lib/Interpreter/ExecutionContext.cpp b/interpreter/cling/lib/Interpreter/ExecutionContext.cpp index 371eead34ef55077caf3c4976fcd83c3f1d10637..7a44299ab8b11ec379a5743b895c4616e9091a63 100644 --- a/interpreter/cling/lib/Interpreter/ExecutionContext.cpp +++ b/interpreter/cling/lib/Interpreter/ExecutionContext.cpp @@ -413,3 +413,12 @@ void* ExecutionContext::getAddressOfGlobal(llvm::Module* m, } return address; } + +void* +ExecutionContext::getPointerToGlobalFromJIT(const llvm::GlobalValue& GV) const { + if (void* addr = m_engine->getPointerToGlobalIfAvailable(&GV)) + return addr; + + // Function not yet codegened by the JIT, force this to happen now. + return m_engine->getPointerToGlobal(&GV); +} diff --git a/interpreter/cling/lib/Interpreter/ExecutionContext.h b/interpreter/cling/lib/Interpreter/ExecutionContext.h index 28bed25993e7d9d6192704a1c8cb36414adadf12..26f323be1220c464f741e9b71503f342459e3822 100644 --- a/interpreter/cling/lib/Interpreter/ExecutionContext.h +++ b/interpreter/cling/lib/Interpreter/ExecutionContext.h @@ -14,8 +14,9 @@ #include <set> namespace llvm { - class Module; class ExecutionEngine; + class GlobalValue; + class Module; } namespace clang { @@ -177,6 +178,13 @@ namespace cling { void* getAddressOfGlobal(llvm::Module* m, const char* mangledName, bool* fromJIT = 0) const; + ///\brief Return the address of a global from the ExecutionEngine (as + /// opposed to dynamic libraries). Forces the emission of the symbol if + /// it has not happened yet. + /// + ///param[in] GV - global value for which the address will be returned. + void* getPointerToGlobalFromJIT(const llvm::GlobalValue& GV) const; + llvm::ExecutionEngine* getExecutionEngine() const { if (!m_engine) return 0;