Conditionals work!
This commit is contained in:
parent
d5f01a7b1f
commit
e103ba221c
@ -7,7 +7,14 @@ fn paha(x, y, z) {
|
||||
x * y * z
|
||||
}
|
||||
|
||||
a = 0
|
||||
|
||||
c = if a {
|
||||
10
|
||||
} else {
|
||||
20
|
||||
}
|
||||
|
||||
q = 4
|
||||
|
||||
q + 1
|
||||
q + 1 + c
|
||||
|
||||
|
@ -271,10 +271,11 @@ impl CodeGen for Expression {
|
||||
|
||||
LLVMWrap::PositionBuilderAtEnd(data.builder, merge_block);
|
||||
|
||||
let phi = LLVMWrap::BuildPhi(data.builder, int_type, "phinnode");
|
||||
|
||||
|
||||
zero
|
||||
let phi = LLVMWrap::BuildPhi(data.builder, int_type, "phinode");
|
||||
let values = vec![then_return, else_return];
|
||||
let blocks = vec![then_block, else_block];
|
||||
LLVMWrap::AddIncoming(phi, values, blocks);
|
||||
phi
|
||||
}
|
||||
Block(ref exprs) => {
|
||||
let mut ret = zero;
|
||||
|
@ -170,12 +170,6 @@ pub fn BuildPhi(builder: LLVMBuilderRef, ty: LLVMTypeRef, name: &str) -> LLVMVal
|
||||
unsafe { core::LLVMBuildPhi(builder, ty, name.as_ptr()) }
|
||||
}
|
||||
|
||||
pub fn AddIncoming(phi: LLVMValueRef, incoming_values: *mut LLVMValueRef, incoming_blocks: *mut LLVMBasicBlockRef,
|
||||
count: u32) {
|
||||
|
||||
unsafe { core::LLVMAddIncoming(phi, incoming_values, incoming_blocks, count) }
|
||||
}
|
||||
|
||||
pub fn SetValueName(value: LLVMValueRef, name: &str) {
|
||||
let name = CString::new(name).unwrap();
|
||||
unsafe {
|
||||
@ -264,23 +258,18 @@ pub fn PrintModuleToString(module: LLVMModuleRef) -> String {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn BuildPhi(builder: LLVMBuilderRef, ty: LLVMTypeRef, name: &str) -> LLVMValueRef {
|
||||
unsafe {
|
||||
let name = CString::new(name).unwrap();
|
||||
unsafe { core::LLVMBuildPhi(builder, ty, name.as_ptr()) }
|
||||
}
|
||||
}
|
||||
pub fn AddIncoming(phi_node: LLVMValueRef, mut incoming_values: Vec<LLVMValueRef>,
|
||||
mut incoming_blocks: Vec<LLVMBasicBlockRef>) {
|
||||
|
||||
pub fn AddIncoming(phi_node: LLVMValueRef, incoming_values: Vec<LLVMValueRef>,
|
||||
incoming_blocks: Vec<LLVMBasicBlockRef>) {
|
||||
|
||||
let count = incoming_blocks.len();
|
||||
if incoming_values.len() != count {
|
||||
let count = incoming_blocks.len() as u32;
|
||||
if incoming_values.len() as u32 != count {
|
||||
panic!("Bad invocation of AddIncoming");
|
||||
}
|
||||
unsafe {
|
||||
//core::LLVMAddIncoming(phi_node);
|
||||
|
||||
unsafe {
|
||||
let vals = incoming_values.as_mut_ptr();
|
||||
let blocks = incoming_blocks.as_mut_ptr();
|
||||
core::LLVMAddIncoming(phi_node, vals, blocks, count)
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user