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
1 changed files with 21 additions and 19 deletions

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 =
llvm_sys::LLVMIntPredicate::LLVMIntNE, LLVMWrap::BuildICmp(data.builder,
condition_value, llvm_sys::LLVMIntPredicate::LLVMIntNE,
zero, condition_value,
"is_nonzero"); zero,
"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!(),
} }