authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2016-01-02 20:42:32-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2016-01-02 20:42:32-07:00
logfb1e3a5be976c76f821abf387bdd69446f2ab07b
tree197fbb7935881c53804dfc29007da0c7063f5b80
parent258bc73eee557ada944c9d25ed85d9baf8035ad7

codegen: emit debug metadata for parameters


5 files changed, 39 insertions(+), 1 deletions(-)

src/analyze.cpp+3
......@@ -1898,6 +1898,9 @@ static void analyze_top_level_declaration(CodeGen *g, ImportTableEntry *import,
18981898 variable_entry->decl_node = param_decl_node;
18991899 variable_entry->arg_index = i;
19001900
1901 alloc_codegen_node(param_decl_node);
1902 param_decl_node->codegen_node->data.param_decl_node.variable = variable_entry;
1903
19011904 VariableTableEntry *existing_entry = find_local_variable(context, &variable_entry->name);
19021905 if (!existing_entry) {
19031906 // unique definition
src/analyze.hpp+5
......@@ -322,6 +322,10 @@ struct IfVarNode {
322322 BlockContext *block_context;
323323};
324324
325struct ParamDeclNode {
326 VariableTableEntry *variable;
327};
328
325329struct CodeGenNode {
326330 union {
327331 TypeNode type_node; // for NodeTypeType
......@@ -338,6 +342,7 @@ struct CodeGenNode {
338342 StructValFieldNode struct_val_field_node; // for NodeTypeStructValueField
339343 StructValExprNode struct_val_expr_node; // for NodeTypeStructValueExpr
340344 IfVarNode if_var_node; // for NodeTypeStructValueExpr
345 ParamDeclNode param_decl_node; // for NodeTypeParamDecl
341346 } data;
342347 ExprNode expr_node; // for all the expression nodes
343348};
src/codegen.cpp+18-1
......@@ -1530,7 +1530,8 @@ static void do_code_gen(CodeGen *g) {
15301530 non_void_index += 1;
15311531 }
15321532
1533 build_label_blocks(g, fn_def_node->data.fn_def.body);
1533 AstNode *body_node = fn_def_node->data.fn_def.body;
1534 build_label_blocks(g, body_node);
15341535
15351536 // Set up debug info for blocks and variables and
15361537 // allocate all local variables
......@@ -1593,6 +1594,22 @@ static void do_code_gen(CodeGen *g) {
15931594 }
15941595 }
15951596
1597 // create debug variable declarations for parameters
1598 for (int param_i = 0; param_i < fn_proto->params.length; param_i += 1) {
1599 AstNode *param_decl = fn_proto->params.at(param_i);
1600 assert(param_decl->type == NodeTypeParamDecl);
1601
1602 if (is_param_decl_type_void(g, param_decl))
1603 continue;
1604
1605 VariableTableEntry *variable = param_decl->codegen_node->data.param_decl_node.variable;
1606
1607 LLVMZigDILocation *debug_loc = LLVMZigGetDebugLoc(param_decl->line + 1, param_decl->column + 1,
1608 codegen_fn_def->block_context->di_scope);
1609 LLVMZigInsertDeclareAtEnd(g->dbuilder, variable->value_ref, variable->di_loc_var, debug_loc,
1610 entry_block);
1611 }
1612
15961613 TypeTableEntry *implicit_return_type = codegen_fn_def->implicit_return_type;
15971614 gen_block(g, fn_def_node->data.fn_def.body, implicit_return_type);
15981615
src/zig_llvm.cpp+11
......@@ -387,6 +387,17 @@ void LLVMZigRestoreInsertPoint(LLVMBuilderRef builder, LLVMZigInsertionPoint *ip
387387 unwrap(builder)->restoreIP(*ip);
388388}
389389
390LLVMValueRef LLVMZigInsertDeclareAtEnd(LLVMZigDIBuilder *dibuilder, LLVMValueRef storage,
391 LLVMZigDILocalVariable *var_info, LLVMZigDILocation *debug_loc, LLVMBasicBlockRef basic_block_ref)
392{
393 Instruction *result = reinterpret_cast<DIBuilder*>(dibuilder)->insertDeclare(
394 unwrap(storage),
395 reinterpret_cast<DILocalVariable *>(var_info),
396 reinterpret_cast<DIBuilder*>(dibuilder)->createExpression(),
397 reinterpret_cast<DILocation*>(debug_loc),
398 static_cast<BasicBlock*>(unwrap(basic_block_ref)));
399 return wrap(result);
400}
390401
391402LLVMValueRef LLVMZigInsertDeclare(LLVMZigDIBuilder *dibuilder, LLVMValueRef storage,
392403 LLVMZigDILocalVariable *var_info, LLVMZigDILocation *debug_loc, LLVMValueRef insert_before_instr)
src/zig_llvm.hpp+2
......@@ -113,6 +113,8 @@ void LLVMZigDIBuilderFinalize(LLVMZigDIBuilder *dibuilder);
113113LLVMZigInsertionPoint *LLVMZigSaveInsertPoint(LLVMBuilderRef builder);
114114void LLVMZigRestoreInsertPoint(LLVMBuilderRef builder, LLVMZigInsertionPoint *point);
115115
116LLVMValueRef LLVMZigInsertDeclareAtEnd(LLVMZigDIBuilder *dibuilder, LLVMValueRef storage,
117 LLVMZigDILocalVariable *var_info, LLVMZigDILocation *debug_loc, LLVMBasicBlockRef basic_block_ref);
116118LLVMValueRef LLVMZigInsertDeclare(LLVMZigDIBuilder *dibuilder, LLVMValueRef storage,
117119 LLVMZigDILocalVariable *var_info, LLVMZigDILocation *debug_loc, LLVMValueRef insert_before_instr);
118120LLVMZigDILocation *LLVMZigGetDebugLoc(unsigned line, unsigned col, LLVMZigDIScope *scope);