]> git.eshelyaron.com Git - emacs.git/commitdiff
add emit_ptr_arithmetic
authorAndrea Corallo <andrea_corallo@yahoo.it>
Tue, 2 Jul 2019 21:14:36 +0000 (23:14 +0200)
committerAndrea Corallo <akrl@sdf.org>
Wed, 1 Jan 2020 10:33:49 +0000 (11:33 +0100)
src/comp.c

index 301ff83c8e6f1cea3a080e5a07bce92c9e19a63d..a9b46fc8605fa7bd02567bca7b5bdd52752a3bdf 100644 (file)
@@ -567,6 +567,41 @@ emit_cast (gcc_jit_type *new_type, gcc_jit_rvalue *obj)
                                       dest_field);
 }
 
+/*
+   Emit the equivalent of
+   ptr[i]
+   ptr + size_of_ptr_ref * i
+*/
+
+static gcc_jit_rvalue *
+emit_ptr_arithmetic (gcc_jit_rvalue *ptr, gcc_jit_type *ptr_type,
+                    int size_of_ptr_ref, gcc_jit_rvalue *i)
+{
+  emit_comment ("ptr_arithmetic");
+
+  gcc_jit_rvalue *offset =
+    gcc_jit_context_new_binary_op (
+      comp.ctxt,
+      NULL,
+      GCC_JIT_BINARY_OP_MULT,
+      comp.uintptr_type,
+      gcc_jit_context_new_rvalue_from_int (comp.ctxt,
+                                          comp.uintptr_type,
+                                          size_of_ptr_ref),
+      emit_cast (comp.uintptr_type, i));
+
+  return
+    emit_cast (
+      ptr_type,
+      gcc_jit_context_new_binary_op (
+        comp.ctxt,
+       NULL,
+       GCC_JIT_BINARY_OP_PLUS,
+       comp.uintptr_type,
+       emit_cast (comp.uintptr_type, ptr),
+       offset));
+}
+
 INLINE static gcc_jit_rvalue *
 emit_XLI (gcc_jit_rvalue *obj)
 {