aboutsummaryrefslogtreecommitdiff
path: root/src/llvm_backend.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/llvm_backend.cpp')
-rw-r--r--src/llvm_backend.cpp31
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, "");