| author | |
| committer | |
| log | 7026bed4625b4fe9ac068b045a17e822791ceb93 |
| tree | 652760a2b18c6f7b2f303074705e333ba4c7d500 |
| parent | 7a05e18efb35330475e7ee6253f9fec6103c560f |
5 files changed, 23 insertions(+), 9 deletions(-)
src/analyze.cpp+1| ... | @@ -1012,6 +1012,7 @@ static void resolve_function_proto(CodeGen *g, AstNode *node, FnTableEntry *fn_t | ... | @@ -1012,6 +1012,7 @@ static void resolve_function_proto(CodeGen *g, AstNode *node, FnTableEntry *fn_t |
| 1012 | BlockContext *context = new_block_context(fn_table_entry->fn_def_node, containing_context); | 1012 | BlockContext *context = new_block_context(fn_table_entry->fn_def_node, containing_context); |
| 1013 | fn_table_entry->fn_def_node->data.fn_def.block_context = context; | 1013 | fn_table_entry->fn_def_node->data.fn_def.block_context = context; |
| 1014 | context->di_scope = LLVMZigSubprogramToScope(subprogram); | 1014 | context->di_scope = LLVMZigSubprogramToScope(subprogram); |
| 1015 | ZigLLVMFnSetSubprogram(fn_table_entry->fn_value, subprogram); | ||
| 1015 | } | 1016 | } |
| 1016 | } | 1017 | } |
| 1017 | 1018 |
src/codegen.cpp+4| ... | @@ -744,6 +744,7 @@ static LLVMValueRef gen_cast_expr(CodeGen *g, AstNode *node) { | ... | @@ -744,6 +744,7 @@ static LLVMValueRef gen_cast_expr(CodeGen *g, AstNode *node) { |
| 744 | case CastOpBoolToInt: | 744 | case CastOpBoolToInt: |
| 745 | assert(wanted_type->id == TypeTableEntryIdInt); | 745 | assert(wanted_type->id == TypeTableEntryIdInt); |
| 746 | assert(actual_type->id == TypeTableEntryIdBool); | 746 | assert(actual_type->id == TypeTableEntryIdBool); |
| 747 | add_debug_source_node(g, node); | ||
| 747 | return LLVMBuildZExt(g->builder, expr_val, wanted_type->type_ref, ""); | 748 | return LLVMBuildZExt(g->builder, expr_val, wanted_type->type_ref, ""); |
| 748 | 749 | ||
| 749 | } | 750 | } |
| ... | @@ -1965,6 +1966,7 @@ static LLVMValueRef gen_if_bool_expr_raw(CodeGen *g, AstNode *source_node, LLVMV | ... | @@ -1965,6 +1966,7 @@ static LLVMValueRef gen_if_bool_expr_raw(CodeGen *g, AstNode *source_node, LLVMV |
| 1965 | endif_block = LLVMAppendBasicBlock(g->cur_fn->fn_value, "EndIf"); | 1966 | endif_block = LLVMAppendBasicBlock(g->cur_fn->fn_value, "EndIf"); |
| 1966 | } | 1967 | } |
| 1967 | 1968 | ||
| 1969 | add_debug_source_node(g, source_node); | ||
| 1968 | LLVMBuildCondBr(g->builder, cond_value, then_block, else_block); | 1970 | LLVMBuildCondBr(g->builder, cond_value, then_block, else_block); |
| 1969 | 1971 | ||
| 1970 | LLVMPositionBuilderAtEnd(g->builder, then_block); | 1972 | LLVMPositionBuilderAtEnd(g->builder, then_block); |
| ... | @@ -3836,6 +3838,8 @@ static void init(CodeGen *g, Buf *source_path) { | ... | @@ -3836,6 +3838,8 @@ static void init(CodeGen *g, Buf *source_path) { |
| 3836 | 3838 | ||
| 3837 | LLVMSetTarget(g->module, buf_ptr(&g->triple_str)); | 3839 | LLVMSetTarget(g->module, buf_ptr(&g->triple_str)); |
| 3838 | 3840 | ||
| 3841 | ZigLLVMAddModuleDebugInfoFlag(g->module); | ||
| 3842 | |||
| 3839 | LLVMTargetRef target_ref; | 3843 | LLVMTargetRef target_ref; |
| 3840 | char *err_msg = nullptr; | 3844 | char *err_msg = nullptr; |
| 3841 | if (LLVMGetTargetFromTriple(buf_ptr(&g->triple_str), &target_ref, &err_msg)) { | 3845 | if (LLVMGetTargetFromTriple(buf_ptr(&g->triple_str), &target_ref, &err_msg)) { |
src/zig_llvm.cpp+12-1| ... | @@ -150,6 +150,12 @@ void LLVMZigAddNonNullAttr(LLVMValueRef fn, unsigned i) | ... | @@ -150,6 +150,12 @@ void LLVMZigAddNonNullAttr(LLVMValueRef fn, unsigned i) |
| 150 | unwrapped_function->addAttribute(i, Attribute::NonNull); | 150 | unwrapped_function->addAttribute(i, Attribute::NonNull); |
| 151 | } | 151 | } |
| 152 | 152 | ||
| 153 | void ZigLLVMFnSetSubprogram(LLVMValueRef fn, LLVMZigDISubprogram *subprogram) { | ||
| 154 | assert( isa<Function>(unwrap(fn)) ); | ||
| 155 | Function *unwrapped_function = reinterpret_cast<Function*>(unwrap(fn)); | ||
| 156 | unwrapped_function->setSubprogram(reinterpret_cast<DISubprogram*>(subprogram)); | ||
| 157 | } | ||
| 158 | |||
| 153 | 159 | ||
| 154 | LLVMZigDIType *LLVMZigCreateDebugPointerType(LLVMZigDIBuilder *dibuilder, LLVMZigDIType *pointee_type, | 160 | LLVMZigDIType *LLVMZigCreateDebugPointerType(LLVMZigDIBuilder *dibuilder, LLVMZigDIType *pointee_type, |
| 155 | uint64_t size_in_bits, uint64_t align_in_bits, const char *name) | 161 | uint64_t size_in_bits, uint64_t align_in_bits, const char *name) |
| ... | @@ -612,6 +618,10 @@ const char *ZigLLVMGetSubArchTypeName(ZigLLVM_SubArchType sub_arch) { | ... | @@ -612,6 +618,10 @@ const char *ZigLLVMGetSubArchTypeName(ZigLLVM_SubArchType sub_arch) { |
| 612 | abort(); | 618 | abort(); |
| 613 | } | 619 | } |
| 614 | 620 | ||
| 621 | void ZigLLVMAddModuleDebugInfoFlag(LLVMModuleRef module) { | ||
| 622 | unwrap(module)->addModuleFlag(Module::Warning, "Debug Info Version", DEBUG_METADATA_VERSION); | ||
| 623 | } | ||
| 624 | |||
| 615 | //------------------------------------ | 625 | //------------------------------------ |
| 616 | 626 | ||
| 617 | #include "buffer.hpp" | 627 | #include "buffer.hpp" |
| ... | @@ -627,7 +637,8 @@ void ZigLLVMGetTargetTriple(Buf *out_buf, ZigLLVM_ArchType arch_type, ZigLLVM_Su | ... | @@ -627,7 +637,8 @@ void ZigLLVMGetTargetTriple(Buf *out_buf, ZigLLVM_ArchType arch_type, ZigLLVM_Su |
| 627 | triple.setVendor((Triple::VendorType)vendor_type); | 637 | triple.setVendor((Triple::VendorType)vendor_type); |
| 628 | triple.setOS((Triple::OSType)os_type); | 638 | triple.setOS((Triple::OSType)os_type); |
| 629 | triple.setEnvironment((Triple::EnvironmentType)environ_type); | 639 | triple.setEnvironment((Triple::EnvironmentType)environ_type); |
| 630 | triple.setObjectFormat((Triple::ObjectFormatType)oformat); | 640 | // I guess it's a "triple" because we don't set the object format? |
| 641 | //triple.setObjectFormat((Triple::ObjectFormatType)oformat); | ||
| 631 | 642 | ||
| 632 | const std::string &str = triple.str(); | 643 | const std::string &str = triple.str(); |
| 633 | buf_init_from_mem(out_buf, str.c_str(), str.size()); | 644 | buf_init_from_mem(out_buf, str.c_str(), str.size()); |
src/zig_llvm.hpp+4| ... | @@ -100,6 +100,7 @@ unsigned LLVMZigTag_DW_variable(void); | ... | @@ -100,6 +100,7 @@ unsigned LLVMZigTag_DW_variable(void); |
| 100 | unsigned LLVMZigTag_DW_structure_type(void); | 100 | unsigned LLVMZigTag_DW_structure_type(void); |
| 101 | 101 | ||
| 102 | LLVMZigDIBuilder *LLVMZigCreateDIBuilder(LLVMModuleRef module, bool allow_unresolved); | 102 | LLVMZigDIBuilder *LLVMZigCreateDIBuilder(LLVMModuleRef module, bool allow_unresolved); |
| 103 | void ZigLLVMAddModuleDebugInfoFlag(LLVMModuleRef module); | ||
| 103 | 104 | ||
| 104 | void LLVMZigSetCurrentDebugLocation(LLVMBuilderRef builder, int line, int column, LLVMZigDIScope *scope); | 105 | void LLVMZigSetCurrentDebugLocation(LLVMBuilderRef builder, int line, int column, LLVMZigDIScope *scope); |
| 105 | 106 | ||
| ... | @@ -132,6 +133,9 @@ LLVMZigDISubprogram *LLVMZigCreateFunction(LLVMZigDIBuilder *dibuilder, LLVMZigD | ... | @@ -132,6 +133,9 @@ LLVMZigDISubprogram *LLVMZigCreateFunction(LLVMZigDIBuilder *dibuilder, LLVMZigD |
| 132 | LLVMZigDIType *fn_di_type, bool is_local_to_unit, bool is_definition, unsigned scope_line, | 133 | LLVMZigDIType *fn_di_type, bool is_local_to_unit, bool is_definition, unsigned scope_line, |
| 133 | unsigned flags, bool is_optimized, LLVMZigDISubprogram *decl_subprogram); | 134 | unsigned flags, bool is_optimized, LLVMZigDISubprogram *decl_subprogram); |
| 134 | 135 | ||
| 136 | |||
| 137 | void ZigLLVMFnSetSubprogram(LLVMValueRef fn, LLVMZigDISubprogram *subprogram); | ||
| 138 | |||
| 135 | void LLVMZigDIBuilderFinalize(LLVMZigDIBuilder *dibuilder); | 139 | void LLVMZigDIBuilderFinalize(LLVMZigDIBuilder *dibuilder); |
| 136 | 140 | ||
| 137 | LLVMZigInsertionPoint *LLVMZigSaveInsertPoint(LLVMBuilderRef builder); | 141 | LLVMZigInsertionPoint *LLVMZigSaveInsertPoint(LLVMBuilderRef builder); |
test/self_hosted.zig+2-8| ... | @@ -55,14 +55,8 @@ fn test_loc_vars(b: i32) { | ... | @@ -55,14 +55,8 @@ fn test_loc_vars(b: i32) { |
| 55 | 55 | ||
| 56 | #attribute("test") | 56 | #attribute("test") |
| 57 | fn bool_literals() { | 57 | fn bool_literals() { |
| 58 | should_be_true(true); | 58 | assert(true); |
| 59 | should_be_false(false); | 59 | assert(!false); |
| 60 | } | ||
| 61 | fn should_be_true(b: bool) { | ||
| 62 | if (!b) unreachable{}; | ||
| 63 | } | ||
| 64 | fn should_be_false(b: bool) { | ||
| 65 | if (b) unreachable{}; | ||
| 66 | } | 60 | } |
| 67 | 61 | ||
| 68 | 62 |