More work on codegen for conditionals
Still doesn't compile
This commit is contained in:
parent
8c4f7e141a
commit
825c271b17
@ -158,29 +158,31 @@ impl CodeGen for Expression {
|
||||
let int_value: LLVMValueRef = LLVMWrap::ConstInt(int_type, native_val, false);
|
||||
int_value
|
||||
}
|
||||
Conditional(ref test, ref then_block, ref else_block) => {
|
||||
Conditional(ref test, ref then_expr, ref else_expr) => {
|
||||
let condition_value = test.codegen(data);
|
||||
let zero = LLVMWrap::ConstInt(int_type, 0, false);
|
||||
let is_nonzero = LLVMWrap::BuildICmp(data.builder,
|
||||
let is_nonzero =
|
||||
LLVMWrap::BuildICmp(data.builder,
|
||||
llvm_sys::LLVMIntPredicate::LLVMIntNE,
|
||||
condition_value,
|
||||
zero,
|
||||
"is_nonzero");
|
||||
|
||||
let func = 4;
|
||||
let then_block = LLVMWrap::AppendBasicBlockInContext(data.context,
|
||||
func,
|
||||
"entry");
|
||||
let else_block = LLVMWrap::AppendBasicBlockInContext(data.context,
|
||||
func,
|
||||
"entry");
|
||||
let merge_block = LLVMWrap::AppendBasicBlockInContext(data.context,
|
||||
func,
|
||||
"entry");
|
||||
//LLVMWrap::BuildCondBr(data.builder, is_nonzero, g
|
||||
|
||||
unimplemented!()
|
||||
|
||||
let then_block =
|
||||
LLVMWrap::AppendBasicBlockInContext(data.context, func, "entry");
|
||||
let else_block =
|
||||
LLVMWrap::AppendBasicBlockInContext(data.context, func, "entry");
|
||||
let merge_block =
|
||||
LLVMWrap::AppendBasicBlockInContext(data.context, func, "entry");
|
||||
LLVMWrap::BuildCondBr(data.builder, is_nonzero, then_block, else_block);
|
||||
LLVMWrap::PositionBuilderAtEnd(data.builder, then_block);
|
||||
let then_return = then_expr.codegen(data);
|
||||
LLVMWrap::BuildBr(data.builder, merge_block);
|
||||
let else_return = else_expr.codegen(data);
|
||||
LLVMWrap::BuildBr(data.builder, merge_block);
|
||||
LLVMWrap::PositionBuilderAtEnd(data.builder, else_block);
|
||||
zero
|
||||
}
|
||||
_ => unimplemented!(),
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user