aboutsummaryrefslogtreecommitdiff
path: root/src/codegen.cpp
diff options
context:
space:
mode:
authorAndrew Kelley <superjoe30@gmail.com>2016-12-05 18:43:16 -0500
committerAndrew Kelley <superjoe30@gmail.com>2016-12-05 18:43:16 -0500
commit24048b2af62f1b36678aa08a20d0754cb712e485 (patch)
tree09519ba8509ba40a3c1d9c85eee7d35f181ca37b /src/codegen.cpp
parent0541532ed6cf5a32b57a4a3f74e6d3a1699223a7 (diff)
downloadzig-24048b2af62f1b36678aa08a20d0754cb712e485.tar.gz
zig-24048b2af62f1b36678aa08a20d0754cb712e485.zip
IR: implement break and continue
Diffstat (limited to 'src/codegen.cpp')
-rw-r--r--src/codegen.cpp85
1 files changed, 50 insertions, 35 deletions
diff --git a/src/codegen.cpp b/src/codegen.cpp
index 6b872e8775..8106b9f33a 100644
--- a/src/codegen.cpp
+++ b/src/codegen.cpp
@@ -277,40 +277,55 @@ static ZigLLVMDIScope *get_di_scope(CodeGen *g, Scope *scope) {
if (scope->di_scope)
return scope->di_scope;
- if (scope->node->type == NodeTypeFnDef) {
- assert(scope->parent);
- ScopeFnDef *fn_scope = (ScopeFnDef *)scope;
- FnTableEntry *fn_table_entry = fn_scope->fn_entry;
- unsigned line_number = fn_table_entry->proto_node->line + 1;
- unsigned scope_line = line_number;
- bool is_definition = fn_table_entry->fn_def_node != nullptr;
- unsigned flags = 0;
- bool is_optimized = g->is_release_build;
- ZigLLVMDISubprogram *subprogram = ZigLLVMCreateFunction(g->dbuilder,
- get_di_scope(g, scope->parent), buf_ptr(&fn_table_entry->symbol_name), "",
- scope->node->owner->di_file, line_number,
- fn_table_entry->type_entry->di_type, fn_table_entry->internal_linkage,
- is_definition, scope_line, flags, is_optimized, nullptr);
-
- scope->di_scope = ZigLLVMSubprogramToScope(subprogram);
- ZigLLVMFnSetSubprogram(fn_llvm_value(g, fn_table_entry), subprogram);
- } else if (scope->node->type == NodeTypeRoot) {
- scope->di_scope = ZigLLVMFileToScope(scope->node->owner->di_file);
- } else if (scope->node->type == NodeTypeContainerDecl) {
- ScopeDecls *decls_scope = (ScopeDecls *)scope;
- assert(decls_scope->container_type);
- scope->di_scope = ZigLLVMTypeToScope(decls_scope->container_type->di_type);
- } else {
- assert(scope->parent);
- ZigLLVMDILexicalBlock *di_block = ZigLLVMCreateLexicalBlock(g->dbuilder,
- get_di_scope(g, scope->parent),
- scope->node->owner->di_file,
- scope->node->line + 1,
- scope->node->column + 1);
- scope->di_scope = ZigLLVMLexicalBlockToScope(di_block);
+ ImportTableEntry *import = get_scope_import(scope);
+ switch (scope->id) {
+ case ScopeIdCImport:
+ zig_unreachable();
+ case ScopeIdFnDef:
+ {
+ assert(scope->parent);
+ ScopeFnDef *fn_scope = (ScopeFnDef *)scope;
+ FnTableEntry *fn_table_entry = fn_scope->fn_entry;
+ unsigned line_number = fn_table_entry->proto_node->line + 1;
+ unsigned scope_line = line_number;
+ bool is_definition = fn_table_entry->fn_def_node != nullptr;
+ unsigned flags = 0;
+ bool is_optimized = g->is_release_build;
+ ZigLLVMDISubprogram *subprogram = ZigLLVMCreateFunction(g->dbuilder,
+ get_di_scope(g, scope->parent), buf_ptr(&fn_table_entry->symbol_name), "",
+ import->di_file, line_number,
+ fn_table_entry->type_entry->di_type, fn_table_entry->internal_linkage,
+ is_definition, scope_line, flags, is_optimized, nullptr);
+
+ scope->di_scope = ZigLLVMSubprogramToScope(subprogram);
+ ZigLLVMFnSetSubprogram(fn_llvm_value(g, fn_table_entry), subprogram);
+ return scope->di_scope;
+ }
+ case ScopeIdDecls:
+ if (scope->parent) {
+ ScopeDecls *decls_scope = (ScopeDecls *)scope;
+ assert(decls_scope->container_type);
+ scope->di_scope = ZigLLVMTypeToScope(decls_scope->container_type->di_type);
+ } else {
+ scope->di_scope = ZigLLVMFileToScope(import->di_file);
+ }
+ return scope->di_scope;
+ case ScopeIdBlock:
+ case ScopeIdDefer:
+ case ScopeIdVarDecl:
+ case ScopeIdLoop:
+ {
+ assert(scope->parent);
+ ZigLLVMDILexicalBlock *di_block = ZigLLVMCreateLexicalBlock(g->dbuilder,
+ get_di_scope(g, scope->parent),
+ import->di_file,
+ scope->source_node->line + 1,
+ scope->source_node->column + 1);
+ scope->di_scope = ZigLLVMLexicalBlockToScope(di_block);
+ return scope->di_scope;
+ }
}
-
- return scope->di_scope;
+ zig_unreachable();
}
static void clear_debug_source_node(CodeGen *g) {
@@ -400,11 +415,11 @@ static bool ir_want_debug_safety(CodeGen *g, IrInstruction *instruction) {
// TODO memoize
Scope *scope = instruction->scope;
while (scope) {
- if (scope->node->type == NodeTypeBlock) {
+ if (scope->id == ScopeIdBlock) {
ScopeBlock *block_scope = (ScopeBlock *)scope;
if (block_scope->safety_set_node)
return !block_scope->safety_off;
- } else if (scope->node->type == NodeTypeRoot || scope->node->type == NodeTypeContainerDecl) {
+ } else if (scope->id == ScopeIdDecls) {
ScopeDecls *decls_scope = (ScopeDecls *)scope;
if (decls_scope->safety_set_node)
return !decls_scope->safety_off;