diff options
| author | gingerBill <bill@gingerbill.org> | 2021-05-30 13:21:56 +0100 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2021-05-30 13:21:56 +0100 |
| commit | 0f91ffe28fe0a6773e15fe415c50c7f468ae3cc2 (patch) | |
| tree | 6ee52501cd9fa6c8af994441bfa9b86c23b4ed24 /src/llvm_backend.cpp | |
| parent | 4b46d691f829d4547bfba2648fb04bfd03a2123a (diff) | |
Add intrinsics.{ptr_offset, ptr_sub}
Diffstat (limited to 'src/llvm_backend.cpp')
| -rw-r--r-- | src/llvm_backend.cpp | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/llvm_backend.cpp b/src/llvm_backend.cpp index ca8b3d5a2..c31d1f34f 100644 --- a/src/llvm_backend.cpp +++ b/src/llvm_backend.cpp @@ -9580,6 +9580,37 @@ lbValue lb_build_builtin_proc(lbProcedure *p, Ast *expr, TypeAndValue const &tv, return {}; } + case BuiltinProc_ptr_offset: + { + lbValue ptr = lb_build_expr(p, ce->args[0]); + lbValue len = lb_build_expr(p, ce->args[1]); + len = lb_emit_conv(p, len, t_int); + + LLVMValueRef indices[1] = { + len.value, + }; + + lbValue res = {}; + res.type = tv.type; + res.value = LLVMBuildGEP(p->builder, ptr.value, indices, gb_count_of(indices), ""); + return res; + } + case BuiltinProc_ptr_sub: + { + lbValue ptr0 = lb_build_expr(p, ce->args[0]); + lbValue ptr1 = lb_build_expr(p, ce->args[1]); + + LLVMTypeRef type_int = lb_type(p->module, t_int); + LLVMValueRef diff = LLVMBuildPtrDiff(p->builder, ptr0.value, ptr1.value, ""); + diff = LLVMBuildIntCast2(p->builder, diff, type_int, /*signed*/true, ""); + + lbValue res = {}; + res.type = t_int; + res.value = diff; + return res; + } + + case BuiltinProc_atomic_fence: LLVMBuildFence(p->builder, LLVMAtomicOrderingSequentiallyConsistent, false, ""); |