More work on codegen for conditionals

Still doesn't compile
This commit is contained in:
greg 2017-01-10 10:30:08 -08:00
parent 8c4f7e141a
commit 825c271b17

View File

@ -158,29 +158,31 @@ impl CodeGen for Expression {
let int_value: LLVMValueRef = LLVMWrap::ConstInt(int_type, native_val, false); let int_value: LLVMValueRef = LLVMWrap::ConstInt(int_type, native_val, false);
int_value 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 condition_value = test.codegen(data);
let zero = LLVMWrap::ConstInt(int_type, 0, false); 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, llvm_sys::LLVMIntPredicate::LLVMIntNE,
condition_value, condition_value,
zero, zero,
"is_nonzero"); "is_nonzero");
let func = 4; let func = 4;
let then_block = LLVMWrap::AppendBasicBlockInContext(data.context, let then_block =
func, LLVMWrap::AppendBasicBlockInContext(data.context, func, "entry");
"entry"); let else_block =
let else_block = LLVMWrap::AppendBasicBlockInContext(data.context, LLVMWrap::AppendBasicBlockInContext(data.context, func, "entry");
func, let merge_block =
"entry"); LLVMWrap::AppendBasicBlockInContext(data.context, func, "entry");
let merge_block = LLVMWrap::AppendBasicBlockInContext(data.context, LLVMWrap::BuildCondBr(data.builder, is_nonzero, then_block, else_block);
func, LLVMWrap::PositionBuilderAtEnd(data.builder, then_block);
"entry"); let then_return = then_expr.codegen(data);
//LLVMWrap::BuildCondBr(data.builder, is_nonzero, g LLVMWrap::BuildBr(data.builder, merge_block);
let else_return = else_expr.codegen(data);
unimplemented!() LLVMWrap::BuildBr(data.builder, merge_block);
LLVMWrap::PositionBuilderAtEnd(data.builder, else_block);
zero
} }
_ => unimplemented!(), _ => unimplemented!(),
} }