diff options
| author | Simonas Kazlauskas <git@kazlauskas.me> | 2016-08-26 01:32:46 +0300 |
|---|---|---|
| committer | est31 <MTest31@outlook.com> | 2016-12-30 15:17:26 +0100 |
| commit | 9aad2d551e76d80783e812be70de5f49fb038b5e (patch) | |
| tree | 5ed61b4debe55d287d4babb25be7ccf3eabc7722 /src/rustllvm/RustWrapper.cpp | |
| parent | 508fef5dffa5e0fad578f6faa13cfce86ead9463 (diff) | |
| download | rust-9aad2d551e76d80783e812be70de5f49fb038b5e.tar.gz rust-9aad2d551e76d80783e812be70de5f49fb038b5e.zip | |
Add a way to retrieve constant value in 128 bits
Fixes rebase fallout, makes code correct in presence of 128-bit constants. This commit includes manual merge conflict resolution changes from a rebase by @est31.
Diffstat (limited to 'src/rustllvm/RustWrapper.cpp')
| -rw-r--r-- | src/rustllvm/RustWrapper.cpp | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/rustllvm/RustWrapper.cpp b/src/rustllvm/RustWrapper.cpp index 5d5845213e2..81093249318 100644 --- a/src/rustllvm/RustWrapper.cpp +++ b/src/rustllvm/RustWrapper.cpp @@ -1456,6 +1456,22 @@ extern "C" LLVMRustLinkage LLVMRustGetLinkage(LLVMValueRef V) { extern "C" void LLVMRustSetLinkage(LLVMValueRef V, LLVMRustLinkage RustLinkage) { LLVMSetLinkage(V, from_rust(RustLinkage)); + +// Returns true if both high and low were successfully set. Fails in case constant wasn’t any of +// the common sizes (1, 8, 16, 32, 64, 128 bits) +extern "C" bool LLVMRustConstInt128Get(LLVMValueRef CV, bool sext, uint64_t *high, uint64_t *low) +{ + auto C = unwrap<llvm::ConstantInt>(CV); + if (C->getBitWidth() > 128) { return false; } + APInt AP; + if (sext) { + AP = C->getValue().sextOrSelf(128); + } else { + AP = C->getValue().zextOrSelf(128); + } + *low = AP.getLoBits(64).getZExtValue(); + *high = AP.getHiBits(64).getZExtValue(); + return true; } extern "C" LLVMContextRef LLVMRustGetValueContext(LLVMValueRef V) { |
