Still cranking away at conditional compilation

This commit is contained in:
greg 2017-01-11 00:36:16 -08:00
parent 0b9dc113d1
commit d93b5c0a2e
2 changed files with 7 additions and 6 deletions

View File

@ -1,9 +1,8 @@
a = 1 a = 1
if a { if a {
a = 40 a = 42
} else { } else {
a = 2 a = 23
} }
a = a - 1
a a

View File

@ -19,7 +19,6 @@ pub fn compilation_sequence(ast: AST, sourcefile: &str) {
}; };
compile_ast(ast, ll_filename); compile_ast(ast, ll_filename);
println!("YOLO");
Command::new("llc") Command::new("llc")
.arg("-filetype=obj") .arg("-filetype=obj")
.arg(ll_filename) .arg(ll_filename)
@ -32,7 +31,6 @@ pub fn compilation_sequence(ast: AST, sourcefile: &str) {
.output() .output()
.expect("failed to run gcc"); .expect("failed to run gcc");
println!("ai");
for filename in [obj_filename].iter() { for filename in [obj_filename].iter() {
Command::new("rm") Command::new("rm")
.arg(filename) .arg(filename)
@ -181,16 +179,20 @@ impl CodeGen for Expression {
LLVMWrap::AppendBasicBlockInContext(data.context, func, "entry"); LLVMWrap::AppendBasicBlockInContext(data.context, func, "entry");
let merge_block = let merge_block =
LLVMWrap::AppendBasicBlockInContext(data.context, func, "entry"); LLVMWrap::AppendBasicBlockInContext(data.context, func, "entry");
LLVMWrap::BuildCondBr(data.builder, is_nonzero, then_block, else_block); LLVMWrap::BuildCondBr(data.builder, is_nonzero, then_block, else_block);
LLVMWrap::PositionBuilderAtEnd(data.builder, then_block); LLVMWrap::PositionBuilderAtEnd(data.builder, then_block);
let then_return = then_expr.codegen(data); let then_return = then_expr.codegen(data);
LLVMWrap::BuildBr(data.builder, merge_block); LLVMWrap::BuildBr(data.builder, merge_block);
LLVMWrap::PositionBuilderAtEnd(data.builder, else_block);
let else_return = match *else_expr { let else_return = match *else_expr {
Some(ref e) => e.codegen(data), Some(ref e) => e.codegen(data),
None => zero, None => zero,
}; };
LLVMWrap::BuildBr(data.builder, merge_block); LLVMWrap::BuildBr(data.builder, merge_block);
LLVMWrap::PositionBuilderAtEnd(data.builder, else_block); LLVMWrap::PositionBuilderAtEnd(data.builder, merge_block);
zero zero
} }
Block(ref exprs) => { Block(ref exprs) => {