#undef gcc_jit_context_get_type
#undef gcc_jit_context_new_array_access
#undef gcc_jit_context_new_array_type
+#undef gcc_jit_context_new_bitcast
#undef gcc_jit_context_new_binary_op
#undef gcc_jit_context_new_call
#undef gcc_jit_context_new_call_through_ptr
(gcc_jit_context *ctxt, gcc_jit_location *loc,
gcc_jit_rvalue *fn_ptr, int numargs, gcc_jit_rvalue **args));
DEF_DLL_FN (gcc_jit_rvalue *, gcc_jit_context_new_cast,
+ (gcc_jit_context * ctxt, gcc_jit_location *loc,
+ gcc_jit_rvalue *rvalue, gcc_jit_type *type));
+#ifdef LIBGCCJIT_HAVE_gcc_jit_context_new_bitcast
+DEF_DLL_FN (gcc_jit_rvalue *, gcc_jit_context_new_bitcast,
(gcc_jit_context *ctxt, gcc_jit_location *loc,
gcc_jit_rvalue *rvalue, gcc_jit_type *type));
+#endif
DEF_DLL_FN (gcc_jit_rvalue *, gcc_jit_context_new_comparison,
(gcc_jit_context *ctxt, gcc_jit_location *loc,
enum gcc_jit_comparison op, gcc_jit_rvalue *a, gcc_jit_rvalue *b));
LOAD_DLL_FN (library, gcc_jit_context_get_type);
LOAD_DLL_FN (library, gcc_jit_context_new_array_access);
LOAD_DLL_FN (library, gcc_jit_context_new_array_type);
+#ifdef LIBGCCJIT_HAVE_gcc_jit_context_new_bitcast
+ LOAD_DLL_FN (library, gcc_jit_context_new_bitcast);
+#endif
LOAD_DLL_FN (library, gcc_jit_context_new_binary_op);
LOAD_DLL_FN (library, gcc_jit_context_new_call);
LOAD_DLL_FN (library, gcc_jit_context_new_call_through_ptr);
#define gcc_jit_context_get_type fn_gcc_jit_context_get_type
#define gcc_jit_context_new_array_access fn_gcc_jit_context_new_array_access
#define gcc_jit_context_new_array_type fn_gcc_jit_context_new_array_type
+#ifdef LIBGCCJIT_HAVE_gcc_jit_context_new_bitcast
+ #define gcc_jit_context_new_bitcast fn_gcc_jit_context_new_bitcast
+#endif
#define gcc_jit_context_new_binary_op fn_gcc_jit_context_new_binary_op
#define gcc_jit_context_new_call fn_gcc_jit_context_new_call
#define gcc_jit_context_new_call_through_ptr fn_gcc_jit_context_new_call_through_ptr
static f_reloc_t freloc;
+#ifndef LIBGCCJIT_HAVE_gcc_jit_context_new_bitcast
#define NUM_CAST_TYPES 15
+#endif
typedef struct {
EMACS_INT len;
gcc_jit_rvalue *current_thread_ref;
/* Other globals. */
gcc_jit_rvalue *pure_ptr;
- /* libgccjit has really limited support for casting therefore this union will
- be used for the scope. */
+#ifndef LIBGCCJIT_HAVE_gcc_jit_context_new_bitcast
+ /* This version of libgccjit has really limited support for casting
+ therefore this union will be used for the scope. */
gcc_jit_type *cast_union_type;
gcc_jit_function *cast_functions_from_to[NUM_CAST_TYPES][NUM_CAST_TYPES];
gcc_jit_function *cast_ptr_to_int;
gcc_jit_function *cast_int_to_ptr;
gcc_jit_type *cast_types[NUM_CAST_TYPES];
+#endif
gcc_jit_function *func; /* Current function being compiled. */
bool func_has_non_local; /* From comp-func has-non-local slot. */
EMACS_INT func_speed; /* From comp-func speed slot. */
}
+#ifndef LIBGCCJIT_HAVE_gcc_jit_context_new_bitcast
static int
type_to_cast_index (gcc_jit_type * type)
{
xsignal1 (Qnative_ice, build_string ("unsupported cast"));
}
+#endif
static gcc_jit_rvalue *
emit_coerce (gcc_jit_type *new_type, gcc_jit_rvalue *obj)
}
#endif
+#ifdef LIBGCCJIT_HAVE_gcc_jit_context_new_bitcast
+ bool old_is_ptr = gcc_jit_type_is_pointer (old_type);
+ bool new_is_ptr = gcc_jit_type_is_pointer (new_type);
+
+ gcc_jit_rvalue *tmp = obj;
+
+ if (old_is_ptr != new_is_ptr)
+ {
+ if (old_is_ptr)
+ {
+ tmp = gcc_jit_context_new_cast (comp.ctxt, NULL, tmp,
+ comp.void_ptr_type);
+ tmp = gcc_jit_context_new_bitcast (comp.ctxt, NULL, tmp,
+ comp.uintptr_type);
+ }
+ else
+ {
+ tmp = gcc_jit_context_new_cast (comp.ctxt, NULL, tmp,
+ comp.uintptr_type);
+ tmp = gcc_jit_context_new_bitcast (comp.ctxt, NULL, tmp,
+ comp.void_ptr_type);
+ }
+ }
+ return gcc_jit_context_new_cast (comp.ctxt, NULL, tmp, new_type);
+#else /* !defined(LIBGCCJIT_HAVE_gcc_jit_context_new_bitcast) */
int old_index = type_to_cast_index (old_type);
int new_index = type_to_cast_index (new_type);
/* Lookup the appropriate cast function in the cast matrix. */
return gcc_jit_context_new_call (comp.ctxt,
- NULL,
- comp.cast_functions_from_to[old_index][new_index],
- 1, &obj);
+ NULL,
+ comp.cast_functions_from_to
+ [old_index][new_index],
+ 1, &obj);
+#endif
}
static gcc_jit_rvalue *
gcc_jit_type_get_pointer (gcc_jit_struct_as_type (comp.thread_state_s));
}
+#ifndef LIBGCCJIT_HAVE_gcc_jit_context_new_bitcast
static gcc_jit_function *
define_type_punning (const char *name,
gcc_jit_type *from, gcc_jit_field *from_field,
DECL_BLOCK (entry_block, result);
+
gcc_jit_lvalue *tmp_union
= gcc_jit_function_new_local (result,
NULL,
{ comp.unsigned_long_type, "unsigned_long", false },
{ comp.unsigned_type, "unsigned", false },
{ comp.void_ptr_type, "void_ptr", true } };
+
gcc_jit_field *cast_union_fields[2];
/* Define the union used for type punning. */
comp.void_ptr_type,
cast_union_fields[0]);
+
for (int i = 0; i < NUM_CAST_TYPES; ++i)
comp.cast_types[i] = cast_types[i].type;
comp.cast_functions_from_to[i][j] =
define_cast_from_to (cast_types[i], cast_types[j]);
}
+#endif /* !defined(LIBGCCJIT_HAVE_gcc_jit_context_new_bitcast) */
static void
define_CHECK_TYPE (void)
define_jmp_buf ();
define_handler_struct ();
define_thread_state_struct ();
+#ifndef LIBGCCJIT_HAVE_gcc_jit_context_new_bitcast
define_cast_functions ();
+#endif
return Qt;
}