| author | |
| committer | |
| log | fb1e3a5be976c76f821abf387bdd69446f2ab07b |
| tree | 197fbb7935881c53804dfc29007da0c7063f5b80 |
| parent | 258bc73eee557ada944c9d25ed85d9baf8035ad7 |
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, |
| 1898 | 1898 | variable_entry->decl_node = param_decl_node; |
| 1899 | 1899 | variable_entry->arg_index = i; |
| 1900 | 1900 | |
| 1901 | alloc_codegen_node(param_decl_node); | |
| 1902 | param_decl_node->codegen_node->data.param_decl_node.variable = variable_entry; | |
| 1903 | ||
| 1901 | 1904 | VariableTableEntry *existing_entry = find_local_variable(context, &variable_entry->name); |
| 1902 | 1905 | if (!existing_entry) { |
| 1903 | 1906 | // unique definition |
src/analyze.hpp+5| ... | ... | @@ -322,6 +322,10 @@ struct IfVarNode { |
| 322 | 322 | BlockContext *block_context; |
| 323 | 323 | }; |
| 324 | 324 | |
| 325 | struct ParamDeclNode { | |
| 326 | VariableTableEntry *variable; | |
| 327 | }; | |
| 328 | ||
| 325 | 329 | struct CodeGenNode { |
| 326 | 330 | union { |
| 327 | 331 | TypeNode type_node; // for NodeTypeType |
| ... | ... | @@ -338,6 +342,7 @@ struct CodeGenNode { |
| 338 | 342 | StructValFieldNode struct_val_field_node; // for NodeTypeStructValueField |
| 339 | 343 | StructValExprNode struct_val_expr_node; // for NodeTypeStructValueExpr |
| 340 | 344 | IfVarNode if_var_node; // for NodeTypeStructValueExpr |
| 345 | ParamDeclNode param_decl_node; // for NodeTypeParamDecl | |
| 341 | 346 | } data; |
| 342 | 347 | ExprNode expr_node; // for all the expression nodes |
| 343 | 348 | }; |
src/codegen.cpp+18-1| ... | ... | @@ -1530,7 +1530,8 @@ static void do_code_gen(CodeGen *g) { |
| 1530 | 1530 | non_void_index += 1; |
| 1531 | 1531 | } |
| 1532 | 1532 | |
| 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); | |
| 1534 | 1535 | |
| 1535 | 1536 | // Set up debug info for blocks and variables and |
| 1536 | 1537 | // allocate all local variables |
| ... | ... | @@ -1593,6 +1594,22 @@ static void do_code_gen(CodeGen *g) { |
| 1593 | 1594 | } |
| 1594 | 1595 | } |
| 1595 | 1596 | |
| 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 | ||
| 1596 | 1613 | TypeTableEntry *implicit_return_type = codegen_fn_def->implicit_return_type; |
| 1597 | 1614 | gen_block(g, fn_def_node->data.fn_def.body, implicit_return_type); |
| 1598 | 1615 |
src/zig_llvm.cpp+11| ... | ... | @@ -387,6 +387,17 @@ void LLVMZigRestoreInsertPoint(LLVMBuilderRef builder, LLVMZigInsertionPoint *ip |
| 387 | 387 | unwrap(builder)->restoreIP(*ip); |
| 388 | 388 | } |
| 389 | 389 | |
| 390 | LLVMValueRef 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 | } | |
| 390 | 401 | |
| 391 | 402 | LLVMValueRef LLVMZigInsertDeclare(LLVMZigDIBuilder *dibuilder, LLVMValueRef storage, |
| 392 | 403 | LLVMZigDILocalVariable *var_info, LLVMZigDILocation *debug_loc, LLVMValueRef insert_before_instr) |
src/zig_llvm.hpp+2| ... | ... | @@ -113,6 +113,8 @@ void LLVMZigDIBuilderFinalize(LLVMZigDIBuilder *dibuilder); |
| 113 | 113 | LLVMZigInsertionPoint *LLVMZigSaveInsertPoint(LLVMBuilderRef builder); |
| 114 | 114 | void LLVMZigRestoreInsertPoint(LLVMBuilderRef builder, LLVMZigInsertionPoint *point); |
| 115 | 115 | |
| 116 | LLVMValueRef LLVMZigInsertDeclareAtEnd(LLVMZigDIBuilder *dibuilder, LLVMValueRef storage, | |
| 117 | LLVMZigDILocalVariable *var_info, LLVMZigDILocation *debug_loc, LLVMBasicBlockRef basic_block_ref); | |
| 116 | 118 | LLVMValueRef LLVMZigInsertDeclare(LLVMZigDIBuilder *dibuilder, LLVMValueRef storage, |
| 117 | 119 | LLVMZigDILocalVariable *var_info, LLVMZigDILocation *debug_loc, LLVMValueRef insert_before_instr); |
| 118 | 120 | LLVMZigDILocation *LLVMZigGetDebugLoc(unsigned line, unsigned col, LLVMZigDIScope *scope); |