Skip to content

Commit 4d3151a

Browse files
committed
---
yaml --- r: 195516 b: refs/heads/master c: 2e93e38 h: refs/heads/master v: v3
1 parent bf9be61 commit 4d3151a

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 7875dae83fac23fdf59765eb548c2237850d6b15
2+
refs/heads/master: 2e93e386fd228176aeb1100bfdf961bdae2b51b9
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: b3317d68910900f135f9f38e43a7a699bc736b4a
55
refs/heads/try: 961e0358e1a5c0faaef606e31e9965742c1643bf

trunk/src/librustc_llvm/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1976,6 +1976,7 @@ extern {
19761976
pub fn LLVMIsAArgument(value_ref: ValueRef) -> ValueRef;
19771977

19781978
pub fn LLVMIsAAllocaInst(value_ref: ValueRef) -> ValueRef;
1979+
pub fn LLVMIsAConstantInt(value_ref: ValueRef) -> ValueRef;
19791980

19801981
pub fn LLVMInitializeX86TargetInfo();
19811982
pub fn LLVMInitializeX86Target();

trunk/src/librustc_trans/trans/common.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -963,6 +963,32 @@ pub fn const_to_uint(v: ValueRef) -> u64 {
963963
}
964964
}
965965

966+
fn is_const_integral(v: ValueRef) -> bool {
967+
unsafe {
968+
!llvm::LLVMIsAConstantInt(v).is_null()
969+
}
970+
}
971+
972+
pub fn const_to_opt_int(v: ValueRef) -> Option<i64> {
973+
unsafe {
974+
if is_const_integral(v) {
975+
Some(llvm::LLVMConstIntGetSExtValue(v))
976+
} else {
977+
None
978+
}
979+
}
980+
}
981+
982+
pub fn const_to_opt_uint(v: ValueRef) -> Option<u64> {
983+
unsafe {
984+
if is_const_integral(v) {
985+
Some(llvm::LLVMConstIntGetZExtValue(v))
986+
} else {
987+
None
988+
}
989+
}
990+
}
991+
966992
pub fn is_undef(val: ValueRef) -> bool {
967993
unsafe {
968994
llvm::LLVMIsUndef(val) != False

0 commit comments

Comments
 (0)