From 193688f2fc34c03a32b1e013d74fd6e5fac845c7 Mon Sep 17 00:00:00 2001 From: Andrea Corallo Date: Tue, 2 Jul 2019 23:14:36 +0200 Subject: [PATCH] add emit_ptr_arithmetic --- src/comp.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/comp.c b/src/comp.c index 301ff83c8e6..a9b46fc8605 100644 --- a/src/comp.c +++ b/src/comp.c @@ -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) { -- 2.39.5