[PATCH] [llvm-c] Expose getFunctionAddress, as a modern alternative
Ramkumar Ramachandra
artagnon at gmail.com
Mon Dec 22 10:49:18 PST 2014
Respond to whitequark's review:
1. Remove the unnecessary finalizeObject() call.
2. Wrap getGlobalValueAddress() as well.
http://reviews.llvm.org/D6760
Files:
include/llvm-c/ExecutionEngine.h
lib/ExecutionEngine/ExecutionEngineBindings.cpp
unittests/ExecutionEngine/MCJIT/MCJITCAPITest.cpp
Index: include/llvm-c/ExecutionEngine.h
===================================================================
--- include/llvm-c/ExecutionEngine.h
+++ include/llvm-c/ExecutionEngine.h
@@ -170,6 +170,10 @@
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)(
Index: lib/ExecutionEngine/ExecutionEngineBindings.cpp
===================================================================
--- lib/ExecutionEngine/ExecutionEngineBindings.cpp
+++ lib/ExecutionEngine/ExecutionEngineBindings.cpp
@@ -328,6 +328,14 @@
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 {
Index: unittests/ExecutionEngine/MCJIT/MCJITCAPITest.cpp
===================================================================
--- unittests/ExecutionEngine/MCJIT/MCJITCAPITest.cpp
+++ unittests/ExecutionEngine/MCJIT/MCJITCAPITest.cpp
@@ -347,6 +347,44 @@
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;
EMAIL PREFERENCES
http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D6760.17566.patch
Type: text/x-patch
Size: 2627 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20141222/67e6e691/attachment.bin>
More information about the llvm-commits
mailing list