Skip to content

Commit 7a9d9cb

Browse files
committed
Make BasicBlock implement Sub<Value>
1 parent 225cc54 commit 7a9d9cb

File tree

3 files changed

+22
-6
lines changed

3 files changed

+22
-6
lines changed

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,5 @@ cbox = "0.*"
2424
libc = "0.*"
2525

2626
[dependencies.llvm-sys]
27-
version = "0.*"
28-
git = "https://github.com/TomBebbington/llvm-rs"
27+
version = "*"
28+
git = "https://github.com/TomBebbington/llvm-sys.rs"

src/block.rs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,28 @@
11
use ffi::core;
22
use ffi::prelude::LLVMBasicBlockRef;
33
use std::marker::PhantomData;
4-
use value::Function;
5-
use util;
4+
use std::mem;
5+
use value::{Function, Value};
6+
use util::{self, Sub};
67

78
/// A container of instructions that execute sequentially.
89
pub struct BasicBlock(PhantomData<[u8]>);
910
native_ref!(&BasicBlock = LLVMBasicBlockRef);
11+
12+
unsafe impl Sub<Value> for BasicBlock {
13+
fn is(value: &Value) -> bool {
14+
unsafe { core::LLVMValueIsBasicBlock(value.into()) != 0 }
15+
}
16+
fn from_super(value: &Value) -> Option<&BasicBlock> {
17+
unsafe {
18+
mem::transmute(core::LLVMValueAsBasicBlock(value.into()))
19+
}
20+
}
21+
fn to_super(&self) -> &Value {
22+
unsafe { core::LLVMBasicBlockAsValue(self.into()).into() }
23+
}
24+
}
25+
1026
impl BasicBlock {
1127
/// Return the enclosing method, or `None` if it is not attached to a method.
1228
pub fn get_parent(&self) -> Option<&Function> {

0 commit comments

Comments
 (0)