summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 7b88565)
raw | patch | inline | side by side (parent: 7b88565)
author | Peter Zotov <whitequark@whitequark.org> | |
Mon, 22 Dec 2014 18:53:11 +0000 (18:53 +0000) | ||
committer | Peter Zotov <whitequark@whitequark.org> | |
Mon, 22 Dec 2014 18:53:11 +0000 (18:53 +0000) |
Patch by Ramkumar Ramachandra <artagnon@gmail.com>
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@224720 91177308-0d34-0410-b5e6-96231b3b80d8
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@224720 91177308-0d34-0410-b5e6-96231b3b80d8
include/llvm-c/ExecutionEngine.h | patch | blob | history | |
lib/ExecutionEngine/ExecutionEngineBindings.cpp | patch | blob | history | |
unittests/ExecutionEngine/MCJIT/MCJITCAPITest.cpp | patch | blob | history |
index f1f4cadec3488c551df8addfcb8a2db6ba5510c3..eb3ecabfa8a8c1ffda2e5f1064806263450e1a00 100644 (file)
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)(
diff --git a/lib/ExecutionEngine/ExecutionEngineBindings.cpp b/lib/ExecutionEngine/ExecutionEngineBindings.cpp
index 7fc72ae19c525259f3a676a90eb4a98333454729..aaa53f0c69539adbdef88af25dec65a012cd5659 100644 (file)
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 {
diff --git a/unittests/ExecutionEngine/MCJIT/MCJITCAPITest.cpp b/unittests/ExecutionEngine/MCJIT/MCJITCAPITest.cpp
index c80b88b8c2b137ca0586d21390c09881331ab36e..62967bdd32702dea7aa0cf1620405e8c39240e5e 100644 (file)
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;