aboutsummaryrefslogtreecommitdiff
path: root/src/codegen.cpp
diff options
context:
space:
mode:
authorAndrew Kelley <superjoe30@gmail.com>2016-02-04 02:49:12 -0700
committerAndrew Kelley <superjoe30@gmail.com>2016-02-04 02:49:12 -0700
commit32642ac9cb00b59fef97c1888e0424b0eb4db784 (patch)
tree11fc77184d633811f0a78289d0feb7c663175f08 /src/codegen.cpp
parentfdadab40c61a6f70a65472cc95ccd5ba52c01772 (diff)
downloadzig-32642ac9cb00b59fef97c1888e0424b0eb4db784.tar.gz
zig-32642ac9cb00b59fef97c1888e0424b0eb4db784.zip
for loop supports break and continue
See #51
Diffstat (limited to 'src/codegen.cpp')
-rw-r--r--src/codegen.cpp13
1 files changed, 9 insertions, 4 deletions
diff --git a/src/codegen.cpp b/src/codegen.cpp
index 7dd91b6a66..5c07b34097 100644
--- a/src/codegen.cpp
+++ b/src/codegen.cpp
@@ -2089,6 +2089,7 @@ static LLVMValueRef gen_for_expr(CodeGen *g, AstNode *node) {
LLVMBasicBlockRef cond_block = LLVMAppendBasicBlock(g->cur_fn->fn_value, "ForCond");
LLVMBasicBlockRef body_block = LLVMAppendBasicBlock(g->cur_fn->fn_value, "ForBody");
LLVMBasicBlockRef end_block = LLVMAppendBasicBlock(g->cur_fn->fn_value, "ForEnd");
+ LLVMBasicBlockRef continue_block = LLVMAppendBasicBlock(g->cur_fn->fn_value, "ForContinue");
LLVMValueRef array_val = gen_array_base_ptr(g, node->data.for_expr.array_expr);
add_debug_source_node(g, node);
@@ -2122,17 +2123,21 @@ static LLVMValueRef gen_for_expr(CodeGen *g, AstNode *node) {
gen_assign_raw(g, node, BinOpTypeAssign, elem_var->value_ref, elem_val,
elem_var->type, child_type);
g->break_block_stack.append(end_block);
- g->continue_block_stack.append(cond_block);
+ g->continue_block_stack.append(continue_block);
gen_expr(g, node->data.for_expr.body);
g->break_block_stack.pop();
g->continue_block_stack.pop();
if (get_expr_type(node->data.for_expr.body)->id != TypeTableEntryIdUnreachable) {
add_debug_source_node(g, node);
- LLVMValueRef new_index_val = LLVMBuildAdd(g->builder, index_val, one_const, "");
- LLVMBuildStore(g->builder, new_index_val, index_ptr);
- LLVMBuildBr(g->builder, cond_block);
+ LLVMBuildBr(g->builder, continue_block);
}
+ LLVMPositionBuilderAtEnd(g->builder, continue_block);
+ add_debug_source_node(g, node);
+ LLVMValueRef new_index_val = LLVMBuildAdd(g->builder, index_val, one_const, "");
+ LLVMBuildStore(g->builder, new_index_val, index_ptr);
+ LLVMBuildBr(g->builder, cond_block);
+
LLVMPositionBuilderAtEnd(g->builder, end_block);
return nullptr;
}