zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit 7eb6af1d3e92510cb558d43ac80c45964f183bb7 (tree)
parent 21eca6478f80f871f839b20044869cead55582a5
Author: Andrew Kelley <superjoe30@gmail.com>
Date:   Sat,  9 Apr 2016 16:52:52 -0700

add @breakpoint()

Diffstat:
Msrc/all_types.hpp | 1+
Msrc/analyze.cpp | 2++
Msrc/codegen.cpp | 12++++++++++--
3 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/src/all_types.hpp b/src/all_types.hpp @@ -1050,6 +1050,7 @@ enum BuiltinFnId { BuiltinFnIdImport, BuiltinFnIdCImport, BuiltinFnIdErrName, + BuiltinFnIdBreakpoint, }; struct BuiltinFnEntry { diff --git a/src/analyze.cpp b/src/analyze.cpp @@ -4606,6 +4606,8 @@ static TypeTableEntry *analyze_builtin_fn_call_expr(CodeGen *g, ImportTableEntry return analyze_c_import(g, import, context, node); case BuiltinFnIdErrName: return analyze_err_name(g, import, context, node); + case BuiltinFnIdBreakpoint: + return g->builtin_types.entry_void; } zig_unreachable(); } diff --git a/src/codegen.cpp b/src/codegen.cpp @@ -513,6 +513,8 @@ static LLVMValueRef gen_builtin_fn_call_expr(CodeGen *g, AstNode *node) { return nullptr; case BuiltinFnIdErrName: return gen_err_name(g, node); + case BuiltinFnIdBreakpoint: + return LLVMBuildCall(g->builder, g->trap_fn_val, nullptr, 0, ""); } zig_unreachable(); } @@ -3790,9 +3792,15 @@ static BuiltinFnEntry *create_builtin_fn_with_arg_count(CodeGen *g, BuiltinFnId static void define_builtin_fns(CodeGen *g) { { + BuiltinFnEntry *builtin_fn = create_builtin_fn_with_arg_count(g, BuiltinFnIdBreakpoint, "breakpoint", 0); + builtin_fn->return_type = g->builtin_types.entry_void; + builtin_fn->ref_count = 1; + LLVMTypeRef fn_type = LLVMFunctionType(LLVMVoidType(), nullptr, 0, false); - g->trap_fn_val = LLVMAddFunction(g->module, "llvm.debugtrap", fn_type); - assert(LLVMGetIntrinsicID(g->trap_fn_val)); + builtin_fn->fn_val = LLVMAddFunction(g->module, "llvm.debugtrap", fn_type); + assert(LLVMGetIntrinsicID(builtin_fn->fn_val)); + + g->trap_fn_val = builtin_fn->fn_val; } { BuiltinFnEntry *builtin_fn = create_builtin_fn(g, BuiltinFnIdMemcpy, "memcpy");