[llvm] r224720 - [C API] Expose LLVMGetGlobalValueAddress and LLVMGetFunctionAddress.

Peter Zotov whitequark at whitequark.org
Mon Dec 22 10:53:12 PST 2014


Author: whitequark
Date: Mon Dec 22 12:53:11 2014
New Revision: 224720

URL: http://llvm.org/viewvc/llvm-project?rev=224720&view=rev
Log:
[C API] Expose LLVMGetGlobalValueAddress and LLVMGetFunctionAddress.

Patch by Ramkumar Ramachandra <artagnon at gmail.com>

Modified:
    llvm/trunk/include/llvm-c/ExecutionEngine.h
    llvm/trunk/lib/ExecutionEngine/ExecutionEngineBindings.cpp
    llvm/trunk/unittests/ExecutionEngine/MCJIT/MCJITCAPITest.cpp

Modified: llvm/trunk/include/llvm-c/ExecutionEngine.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm-c/ExecutionEngine.h?rev=224720&r1=224719&r2=224720&view=diff
==============================================================================
--- llvm/trunk/include/llvm-c/ExecutionEngine.h (original)
+++ llvm/trunk/include/llvm-c/ExecutionEngine.h Mon Dec 22 12:53:11 2014
@@ -170,6 +170,10 @@ void LLVMAddGlobalMapping(LLVMExecutionE
 
 void *LLVMGetPointerToGlobal(LLVMExecutionEngineRef EE, LLVMValueRef Global);
 
+uint64_t LLVMGetGlobalValueAddress(LLVMExecutionEngineRef EE, const char *Name);
+
+uint64_t LLVMGetFunctionAddress(LLVMExecutionEngineRef EE, const char *Name);
+
 /*===-- Operations on memory managers -------------------------------------===*/
 
 typedef uint8_t *(*LLVMMemoryManagerAllocateCodeSectionCallback)(

Modified: llvm/trunk/lib/ExecutionEngine/ExecutionEngineBindings.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/ExecutionEngineBindings.cpp?rev=224720&r1=224719&r2=224720&view=diff
==============================================================================
--- llvm/trunk/lib/ExecutionEngine/ExecutionEngineBindings.cpp (original)
+++ llvm/trunk/lib/ExecutionEngine/ExecutionEngineBindings.cpp Mon Dec 22 12:53:11 2014
@@ -328,6 +328,14 @@ void *LLVMGetPointerToGlobal(LLVMExecuti
   return unwrap(EE)->getPointerToGlobal(unwrap<GlobalValue>(Global));
 }
 
+uint64_t LLVMGetGlobalValueAddress(LLVMExecutionEngineRef EE, const char *Name) {
+  return unwrap(EE)->getGlobalValueAddress(Name);
+}
+
+uint64_t LLVMGetFunctionAddress(LLVMExecutionEngineRef EE, const char *Name) {
+  return unwrap(EE)->getFunctionAddress(Name);
+}
+
 /*===-- Operations on memory managers -------------------------------------===*/
 
 namespace {

Modified: llvm/trunk/unittests/ExecutionEngine/MCJIT/MCJITCAPITest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/ExecutionEngine/MCJIT/MCJITCAPITest.cpp?rev=224720&r1=224719&r2=224720&view=diff
==============================================================================
--- llvm/trunk/unittests/ExecutionEngine/MCJIT/MCJITCAPITest.cpp (original)
+++ llvm/trunk/unittests/ExecutionEngine/MCJIT/MCJITCAPITest.cpp Mon Dec 22 12:53:11 2014
@@ -347,6 +347,44 @@ TEST_F(MCJITCAPITest, simple_function) {
   EXPECT_EQ(42, functionPointer.usable());
 }
 
+TEST_F(MCJITCAPITest, gva) {
+  SKIP_UNSUPPORTED_PLATFORM;
+
+  Module = LLVMModuleCreateWithName("simple_module");
+  LLVMSetTarget(Module, HostTriple.c_str());
+  LLVMValueRef GlobalVar = LLVMAddGlobal(Module, LLVMInt32Type(), "simple_value");
+  LLVMSetInitializer(GlobalVar, LLVMConstInt(LLVMInt32Type(), 42, 0));
+
+  buildMCJITOptions();
+  buildMCJITEngine();
+  buildAndRunPasses();
+
+  union {
+    uint64_t raw;
+    int32_t *usable;
+  } valuePointer;
+  valuePointer.raw = LLVMGetGlobalValueAddress(Engine, "simple_value");
+
+  EXPECT_EQ(42, *valuePointer.usable);
+}
+
+TEST_F(MCJITCAPITest, gfa) {
+  SKIP_UNSUPPORTED_PLATFORM;
+
+  buildSimpleFunction();
+  buildMCJITOptions();
+  buildMCJITEngine();
+  buildAndRunPasses();
+
+  union {
+    uint64_t raw;
+    int (*usable)();
+  } functionPointer;
+  functionPointer.raw = LLVMGetFunctionAddress(Engine, "simple_function");
+
+  EXPECT_EQ(42, functionPointer.usable());
+}
+
 TEST_F(MCJITCAPITest, custom_memory_manager) {
   SKIP_UNSUPPORTED_PLATFORM;
   





More information about the llvm-commits mailing list