1 .. Copyright (C) 2014-2024 Free Software Foundation, Inc.
2 Originally contributed by David Malcolm <dmalcolm@redhat.com>
4 This is free software: you can redistribute it and/or modify it
5 under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful, but
10 WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see
16 <https://www.gnu.org/licenses/>.
25 .. type:: gcc_jit_rvalue
27 A :c:type:`gcc_jit_rvalue` is an expression that can be computed.
29 It can be simple, e.g.:
31 * an integer value e.g. `0` or `42`
32 * a string literal e.g. `"Hello world"`
33 * a variable e.g. `i`. These are also lvalues (see below).
37 * a unary expression e.g. `!cond`
38 * a binary expression e.g. `(a + b)`
39 * a function call e.g. `get_distance (&player_ship, &target)`
42 Every rvalue has an associated type, and the API will check to ensure
43 that types match up correctly (otherwise the context will emit an error).
45 .. function:: gcc_jit_type *gcc_jit_rvalue_get_type (gcc_jit_rvalue *rvalue)
47 Get the type of this rvalue.
49 .. function:: gcc_jit_object *gcc_jit_rvalue_as_object (gcc_jit_rvalue *rvalue)
51 Upcast the given rvalue to be an object.
57 .. function:: gcc_jit_rvalue *\
58 gcc_jit_context_new_rvalue_from_int (gcc_jit_context *ctxt, \
59 gcc_jit_type *numeric_type, \
62 Given a numeric type (integer or floating point), build an rvalue for
63 the given constant :expr:`int` value.
65 .. function:: gcc_jit_rvalue *\
66 gcc_jit_context_new_rvalue_from_long (gcc_jit_context *ctxt, \
67 gcc_jit_type *numeric_type, \
70 Given a numeric type (integer or floating point), build an rvalue for
71 the given constant :expr:`long` value.
73 .. function:: gcc_jit_rvalue *gcc_jit_context_zero (gcc_jit_context *ctxt, \
74 gcc_jit_type *numeric_type)
76 Given a numeric type (integer or floating point), get the rvalue for
77 zero. Essentially this is just a shortcut for:
81 gcc_jit_context_new_rvalue_from_int (ctxt, numeric_type, 0)
83 .. function:: gcc_jit_rvalue *gcc_jit_context_one (gcc_jit_context *ctxt, \
84 gcc_jit_type *numeric_type)
86 Given a numeric type (integer or floating point), get the rvalue for
87 one. Essentially this is just a shortcut for:
91 gcc_jit_context_new_rvalue_from_int (ctxt, numeric_type, 1)
93 .. function:: gcc_jit_rvalue *\
94 gcc_jit_context_new_rvalue_from_double (gcc_jit_context *ctxt, \
95 gcc_jit_type *numeric_type, \
98 Given a numeric type (integer or floating point), build an rvalue for
99 the given constant :expr:`double` value.
101 .. function:: gcc_jit_rvalue *\
102 gcc_jit_context_new_rvalue_from_ptr (gcc_jit_context *ctxt, \
103 gcc_jit_type *pointer_type, \
106 Given a pointer type, build an rvalue for the given address.
108 .. function:: gcc_jit_rvalue *gcc_jit_context_null (gcc_jit_context *ctxt, \
109 gcc_jit_type *pointer_type)
111 Given a pointer type, build an rvalue for ``NULL``. Essentially this
112 is just a shortcut for:
116 gcc_jit_context_new_rvalue_from_ptr (ctxt, pointer_type, NULL)
118 .. function:: gcc_jit_rvalue *\
119 gcc_jit_context_new_string_literal (gcc_jit_context *ctxt, \
122 Generate an rvalue for the given NIL-terminated string, of type
123 :c:data:`GCC_JIT_TYPE_CONST_CHAR_PTR`.
125 The parameter ``value`` must be non-NULL. The call takes a copy of the
126 underlying string, so it is valid to pass in a pointer to an on-stack
129 Constructor expressions
130 ***********************
132 The following functions make constructors for array, struct and union
135 The constructor rvalue can be used for assignment to locals.
136 It can be used to initialize global variables with
137 :func:`gcc_jit_global_set_initializer_rvalue`. It can also be used as a
138 temporary value for function calls and return values, but its address
141 Note that arrays in libgccjit do not collapse to pointers like in
142 C. I.e. if an array constructor is used as e.g. a return value, the whole
143 array would be returned by value - array constructors can be assigned to
146 The constructor can contain nested constructors.
148 Note that a string literal rvalue can't be used to construct a char array;
149 the latter needs one rvalue for each char.
151 These entrypoints were added in :ref:`LIBGCCJIT_ABI_19`; you can test for
152 their presence using:
156 #ifdef LIBGCCJIT_HAVE_CTORS
158 .. function:: gcc_jit_rvalue *\
159 gcc_jit_context_new_array_constructor (gcc_jit_context *ctxt,\
160 gcc_jit_location *loc,\
163 gcc_jit_rvalue **values)
165 Create a constructor for an array as an rvalue.
167 Returns NULL on error. ``values`` are copied and
168 do not have to outlive the context.
170 ``type`` specifies what the constructor will build and has to be
173 ``num_values`` specifies the number of elements in ``values`` and
174 it can't have more elements than the array type.
176 Each value in ``values`` sets the corresponding value in the array.
177 If the array type itself has more elements than ``values``, the
178 left-over elements will be zeroed.
180 Each value in ``values`` need to be the same unqualified type as the
181 array type's element type.
183 If ``num_values`` is 0, the ``values`` parameter will be
184 ignored and zero initialization will be used.
186 This entrypoint was added in :ref:`LIBGCCJIT_ABI_19`; you can test for its
191 #ifdef LIBGCCJIT_HAVE_CTORS
193 .. function:: gcc_jit_rvalue *\
194 gcc_jit_context_new_struct_constructor (gcc_jit_context *ctxt,\
195 gcc_jit_location *loc,\
198 gcc_jit_field **fields,\
199 gcc_jit_rvalue **values)
202 Create a constructor for a struct as an rvalue.
204 Returns NULL on error. The two parameter arrays are copied and
205 do not have to outlive the context.
207 ``type`` specifies what the constructor will build and has to be
210 ``num_values`` specifies the number of elements in ``values``.
212 ``fields`` need to have the same length as ``values``, or be NULL.
214 If ``fields`` is null, the values are applied in definition order.
216 Otherwise, each field in ``fields`` specifies which field in the struct to
217 set to the corresponding value in ``values``. ``fields`` and ``values``
220 The fields in ``fields`` have to be in definition order, but there
221 can be gaps. Any field in the struct that is not specified in
222 ``fields`` will be zeroed.
224 The fields in ``fields`` need to be the same objects that were used
225 to create the struct.
227 Each value has to have have the same unqualified type as the field
230 A NULL value element in ``values`` is a shorthand for zero initialization
231 of the corresponding field.
233 If ``num_values`` is 0, the array parameters will be
234 ignored and zero initialization will be used.
236 This entrypoint was added in :ref:`LIBGCCJIT_ABI_19`; you can test for its
241 #ifdef LIBGCCJIT_HAVE_CTORS
243 .. function:: gcc_jit_rvalue *\
244 gcc_jit_context_new_union_constructor (gcc_jit_context *ctxt,\
245 gcc_jit_location *loc,\
247 gcc_jit_field *field,\
248 gcc_jit_rvalue *value)
250 Create a constructor for a union as an rvalue.
252 Returns NULL on error.
254 ``type`` specifies what the constructor will build and has to be
257 ``field`` specifies which field to set. If it is NULL, the first
258 field in the union will be set.``field`` need to be the same object
259 that were used to create the union.
261 ``value`` specifies what value to set the corresponding field to.
262 If ``value`` is NULL, zero initialization will be used.
264 Each value has to have have the same unqualified type as the field
267 This entrypoint was added in :ref:`LIBGCCJIT_ABI_19`; you can test for its
272 #ifdef LIBGCCJIT_HAVE_CTORS
277 .. function:: gcc_jit_rvalue * \
278 gcc_jit_context_new_rvalue_from_vector (gcc_jit_context *ctxt, \
279 gcc_jit_location *loc, \
280 gcc_jit_type *vec_type, \
281 size_t num_elements, \
282 gcc_jit_rvalue **elements)
284 Build a vector rvalue from an array of elements.
286 "vec_type" should be a vector type, created using
287 :func:`gcc_jit_type_get_vector`.
289 "num_elements" should match that of the vector type.
291 This entrypoint was added in :ref:`LIBGCCJIT_ABI_10`; you can test for
296 #ifdef LIBGCCJIT_HAVE_gcc_jit_context_new_rvalue_from_vector
301 .. function:: gcc_jit_rvalue * \
302 gcc_jit_context_new_unary_op (gcc_jit_context *ctxt, \
303 gcc_jit_location *loc, \
304 enum gcc_jit_unary_op op, \
305 gcc_jit_type *result_type, \
306 gcc_jit_rvalue *rvalue)
308 Build a unary operation out of an input rvalue.
310 The parameter ``result_type`` must be a numeric type.
312 .. enum:: gcc_jit_unary_op
314 The available unary operations are:
322 * - :c:macro:`GCC_JIT_UNARY_OP_MINUS`
324 * - :c:macro:`GCC_JIT_UNARY_OP_BITWISE_NEGATE`
326 * - :c:macro:`GCC_JIT_UNARY_OP_LOGICAL_NEGATE`
328 * - :c:macro:`GCC_JIT_UNARY_OP_ABS`
331 .. c:macro:: GCC_JIT_UNARY_OP_MINUS
333 Negate an arithmetic value; analogous to:
341 .. c:macro:: GCC_JIT_UNARY_OP_BITWISE_NEGATE
343 Bitwise negation of an integer value (one's complement); analogous
352 .. c:macro:: GCC_JIT_UNARY_OP_LOGICAL_NEGATE
354 Logical negation of an arithmetic or pointer value; analogous to:
362 .. c:macro:: GCC_JIT_UNARY_OP_ABS
364 Absolute value of an arithmetic expression; analogous to:
375 .. function:: gcc_jit_rvalue *gcc_jit_context_new_binary_op (gcc_jit_context *ctxt, \
376 gcc_jit_location *loc, \
377 enum gcc_jit_binary_op op, \
378 gcc_jit_type *result_type, \
379 gcc_jit_rvalue *a, gcc_jit_rvalue *b)
381 Build a binary operation out of two constituent rvalues.
383 The parameter ``result_type`` must be a numeric type.
385 .. enum:: gcc_jit_binary_op
387 The available binary operations are:
395 * - :c:macro:`GCC_JIT_BINARY_OP_PLUS`
397 * - :c:macro:`GCC_JIT_BINARY_OP_MINUS`
399 * - :c:macro:`GCC_JIT_BINARY_OP_MULT`
401 * - :c:macro:`GCC_JIT_BINARY_OP_DIVIDE`
403 * - :c:macro:`GCC_JIT_BINARY_OP_MODULO`
405 * - :c:macro:`GCC_JIT_BINARY_OP_BITWISE_AND`
407 * - :c:macro:`GCC_JIT_BINARY_OP_BITWISE_XOR`
409 * - :c:macro:`GCC_JIT_BINARY_OP_BITWISE_OR`
411 * - :c:macro:`GCC_JIT_BINARY_OP_LOGICAL_AND`
413 * - :c:macro:`GCC_JIT_BINARY_OP_LOGICAL_OR`
415 * - :c:macro:`GCC_JIT_BINARY_OP_LSHIFT`
417 * - :c:macro:`GCC_JIT_BINARY_OP_RSHIFT`
420 .. c:macro:: GCC_JIT_BINARY_OP_PLUS
422 Addition of arithmetic values; analogous to:
430 For pointer addition, use :c:func:`gcc_jit_context_new_array_access`.
432 .. c:macro:: GCC_JIT_BINARY_OP_MINUS
434 Subtraction of arithmetic values; analogous to:
442 .. c:macro:: GCC_JIT_BINARY_OP_MULT
444 Multiplication of a pair of arithmetic values; analogous to:
452 .. c:macro:: GCC_JIT_BINARY_OP_DIVIDE
454 Quotient of division of arithmetic values; analogous to:
462 The result type affects the kind of division: if the result type is
463 integer-based, then the result is truncated towards zero, whereas
464 a floating-point result type indicates floating-point division.
466 .. c:macro:: GCC_JIT_BINARY_OP_MODULO
468 Remainder of division of arithmetic values; analogous to:
476 .. c:macro:: GCC_JIT_BINARY_OP_BITWISE_AND
478 Bitwise AND; analogous to:
486 .. c:macro:: GCC_JIT_BINARY_OP_BITWISE_XOR
488 Bitwise exclusive OR; analogous to:
496 .. c:macro:: GCC_JIT_BINARY_OP_BITWISE_OR
498 Bitwise inclusive OR; analogous to:
506 .. c:macro:: GCC_JIT_BINARY_OP_LOGICAL_AND
508 Logical AND; analogous to:
516 .. c:macro:: GCC_JIT_BINARY_OP_LOGICAL_OR
518 Logical OR; analogous to:
526 .. c:macro:: GCC_JIT_BINARY_OP_LSHIFT
528 Left shift; analogous to:
536 .. c:macro:: GCC_JIT_BINARY_OP_RSHIFT
538 Right shift; analogous to:
549 .. function:: gcc_jit_rvalue *\
550 gcc_jit_context_new_comparison (gcc_jit_context *ctxt,\
551 gcc_jit_location *loc,\
552 enum gcc_jit_comparison op,\
553 gcc_jit_rvalue *a, gcc_jit_rvalue *b)
555 Build a boolean rvalue out of the comparison of two other rvalues.
557 .. enum:: gcc_jit_comparison
565 * - :c:macro:`GCC_JIT_COMPARISON_EQ`
567 * - :c:macro:`GCC_JIT_COMPARISON_NE`
569 * - :c:macro:`GCC_JIT_COMPARISON_LT`
571 * - :c:macro:`GCC_JIT_COMPARISON_LE`
573 * - :c:macro:`GCC_JIT_COMPARISON_GT`
575 * - :c:macro:`GCC_JIT_COMPARISON_GE`
580 .. function:: gcc_jit_rvalue *\
581 gcc_jit_context_new_call (gcc_jit_context *ctxt,\
582 gcc_jit_location *loc,\
583 gcc_jit_function *func,\
584 int numargs , gcc_jit_rvalue **args)
586 Given a function and the given table of argument rvalues, construct a
587 call to the function, with the result as an rvalue.
591 :c:func:`gcc_jit_context_new_call` merely builds a
592 :c:type:`gcc_jit_rvalue` i.e. an expression that can be evaluated,
593 perhaps as part of a more complicated expression.
594 The call *won't* happen unless you add a statement to a function
595 that evaluates the expression.
597 For example, if you want to call a function and discard the result
598 (or to call a function with ``void`` return type), use
599 :c:func:`gcc_jit_block_add_eval`:
603 /* Add "(void)printf (arg0, arg1);". */
604 gcc_jit_block_add_eval (
606 gcc_jit_context_new_call (
612 .. function:: gcc_jit_rvalue *\
613 gcc_jit_context_new_call_through_ptr (gcc_jit_context *ctxt,\
614 gcc_jit_location *loc,\
615 gcc_jit_rvalue *fn_ptr,\
617 gcc_jit_rvalue **args)
619 Given an rvalue of function pointer type (e.g. from
620 :c:func:`gcc_jit_context_new_function_ptr_type`), and the given table of
621 argument rvalues, construct a call to the function pointer, with the
626 The same caveat as for :c:func:`gcc_jit_context_new_call` applies.
629 gcc_jit_rvalue_set_bool_require_tail_call (gcc_jit_rvalue *call,\
630 int require_tail_call)
632 Given an :c:type:`gcc_jit_rvalue` for a call created through
633 :c:func:`gcc_jit_context_new_call` or
634 :c:func:`gcc_jit_context_new_call_through_ptr`, mark/clear the
635 call as needing tail-call optimization. The optimizer will
636 attempt to optimize the call into a jump instruction; if it is
637 unable to do do, an error will be emitted.
639 This may be useful when implementing functions that use the
640 continuation-passing style (e.g. for functional programming
641 languages), in which every function "returns" by calling a
642 "continuation" function pointer. This call must be
643 guaranteed to be implemented as a jump, otherwise the program
644 could consume an arbitrary amount of stack space as it executed.
646 This entrypoint was added in :ref:`LIBGCCJIT_ABI_6`; you can test for
651 #ifdef LIBGCCJIT_HAVE_gcc_jit_rvalue_set_bool_require_tail_call
656 Function pointers can be obtained:
658 * from a :c:type:`gcc_jit_function` using
659 :c:func:`gcc_jit_function_get_address`, or
661 * from an existing function using
662 :c:func:`gcc_jit_context_new_rvalue_from_ptr`,
663 using a function pointer type obtained using
664 :c:func:`gcc_jit_context_new_function_ptr_type`.
669 .. function:: gcc_jit_rvalue *\
670 gcc_jit_context_new_cast (gcc_jit_context *ctxt,\
671 gcc_jit_location *loc,\
672 gcc_jit_rvalue *rvalue,\
675 Given an rvalue of T, construct another rvalue of another type.
677 Currently only a limited set of conversions are possible:
681 * P* <-> Q*, for pointer types P and Q
683 .. function:: gcc_jit_rvalue *\
684 gcc_jit_context_new_bitcast (gcc_jit_context *ctxt,\
685 gcc_jit_location *loc,\
686 gcc_jit_rvalue *rvalue,\
689 Given an rvalue of T, bitcast it to another type, meaning that this will
690 generate a new rvalue by interpreting the bits of ``rvalue`` to the layout
693 The type of rvalue must be the same size as the size of ``type``.
695 This entrypoint was added in :ref:`LIBGCCJIT_ABI_21`; you can test for
700 #ifdef LIBGCCJIT_HAVE_gcc_jit_context_new_bitcast
705 .. type:: gcc_jit_lvalue
707 An lvalue is something that can of the *left*-hand side of an assignment:
708 a storage area (such as a variable). It is also usable as an rvalue,
709 where the rvalue is computed by reading from the storage area.
711 .. function:: gcc_jit_object *\
712 gcc_jit_lvalue_as_object (gcc_jit_lvalue *lvalue)
714 Upcast an lvalue to be an object.
716 .. function:: gcc_jit_rvalue *\
717 gcc_jit_lvalue_as_rvalue (gcc_jit_lvalue *lvalue)
719 Upcast an lvalue to be an rvalue.
721 .. function:: gcc_jit_rvalue *\
722 gcc_jit_lvalue_get_address (gcc_jit_lvalue *lvalue,\
723 gcc_jit_location *loc)
725 Take the address of an lvalue; analogous to:
734 gcc_jit_lvalue_set_tls_model (gcc_jit_lvalue *lvalue,\
735 enum gcc_jit_tls_model model)
737 Make a variable a thread-local variable.
739 The "model" parameter determines the thread-local storage model of the "lvalue":
741 .. enum:: gcc_jit_tls_model
743 .. c:macro:: GCC_JIT_TLS_MODEL_NONE
745 Don't set the TLS model.
747 .. c:macro:: GCC_JIT_TLS_MODEL_GLOBAL_DYNAMIC
749 .. c:macro:: GCC_JIT_TLS_MODEL_LOCAL_DYNAMIC
751 .. c:macro:: GCC_JIT_TLS_MODEL_INITIAL_EXEC
753 .. c:macro:: GCC_JIT_TLS_MODEL_LOCAL_EXEC
755 This is analogous to:
759 _Thread_local int foo __attribute__ ((tls_model("MODEL")));
763 This entrypoint was added in :ref:`LIBGCCJIT_ABI_17`; you can test for
768 #ifdef LIBGCCJIT_HAVE_gcc_jit_lvalue_set_tls_model
771 gcc_jit_lvalue_set_link_section (gcc_jit_lvalue *lvalue,\
772 const char *section_name)
774 Set the link section of a variable.
775 The parameter ``section_name`` must be non-NULL and must contain the
776 leading dot. Analogous to:
780 int variable __attribute__((section(".section")));
784 This entrypoint was added in :ref:`LIBGCCJIT_ABI_18`; you can test for
789 #ifdef LIBGCCJIT_HAVE_gcc_jit_lvalue_set_link_section
792 gcc_jit_lvalue_set_register_name (gcc_jit_lvalue *lvalue,\
793 const char *reg_name);
795 Set the register name of a variable.
796 The parameter ``reg_name`` must be non-NULL. Analogous to:
800 register int variable asm ("r12");
804 This entrypoint was added in :ref:`LIBGCCJIT_ABI_22`; you can test for
809 #ifdef LIBGCCJIT_HAVE_gcc_jit_lvalue_set_register_name
812 gcc_jit_lvalue_set_alignment (gcc_jit_lvalue *lvalue,\
815 Set the alignment of a variable, in bytes.
820 int variable __attribute__((aligned (16)));
824 This entrypoint was added in :ref:`LIBGCCJIT_ABI_24`; you can test for
829 #ifdef LIBGCCJIT_HAVE_ALIGNMENT
831 .. function:: unsigned\
832 gcc_jit_lvalue_get_alignment (gcc_jit_lvalue *lvalue)
834 Return the alignment of a variable set by ``gcc_jit_lvalue_set_alignment``.
835 Return 0 if the alignment was not set. Analogous to:
843 This entrypoint was added in :ref:`LIBGCCJIT_ABI_24`; you can test for
848 #ifdef LIBGCCJIT_HAVE_ALIGNMENT
853 .. function:: gcc_jit_lvalue *\
854 gcc_jit_context_new_global (gcc_jit_context *ctxt,\
855 gcc_jit_location *loc,\
856 enum gcc_jit_global_kind kind,\
860 Add a new global variable of the given type and name to the context.
862 The parameter ``type`` must be non-`void`.
864 The parameter ``name`` must be non-NULL. The call takes a copy of the
865 underlying string, so it is valid to pass in a pointer to an on-stack
868 The "kind" parameter determines the visibility of the "global" outside
869 of the :c:type:`gcc_jit_result`:
871 .. enum:: gcc_jit_global_kind
873 .. c:macro:: GCC_JIT_GLOBAL_EXPORTED
875 Global is defined by the client code and is visible
876 by name outside of this JIT context via
877 :c:func:`gcc_jit_result_get_global` (and this value is required for
878 the global to be accessible via that entrypoint).
880 .. c:macro:: GCC_JIT_GLOBAL_INTERNAL
882 Global is defined by the client code, but is invisible
883 outside of it. Analogous to a "static" global within a .c file.
884 Specifically, the variable will only be visible within this
885 context and within child contexts.
887 .. c:macro:: GCC_JIT_GLOBAL_IMPORTED
889 Global is not defined by the client code; we're merely
890 referring to it. Analogous to using an "extern" global from a
893 .. function:: gcc_jit_lvalue *\
894 gcc_jit_global_set_initializer (gcc_jit_lvalue *global,\
898 Set an initializer for ``global`` using the memory content pointed
899 by ``blob`` for ``num_bytes``. ``global`` must be an array of an
900 integral type. Return the global itself.
902 The parameter ``blob`` must be non-NULL. The call copies the memory
903 pointed by ``blob`` for ``num_bytes`` bytes, so it is valid to pass
904 in a pointer to an on-stack buffer. The content will be stored in
905 the compilation unit and used as initialization value of the array.
907 This entrypoint was added in :ref:`LIBGCCJIT_ABI_14`; you can test for
912 #ifdef LIBGCCJIT_HAVE_gcc_jit_global_set_initializer
914 .. function:: gcc_jit_lvalue *\
915 gcc_jit_global_set_initializer_rvalue (gcc_jit_lvalue *global,\
916 gcc_jit_rvalue *init_value)
918 Set the initial value of a global with an rvalue.
920 The rvalue needs to be a constant expression, e.g. no function calls.
922 The global can't have the ``kind`` :c:macro:`GCC_JIT_GLOBAL_IMPORTED`.
924 As a non-comprehensive example it is OK to do the equivalent of:
928 int foo = 3 * 2; /* rvalue from gcc_jit_context_new_binary_op. */
929 int arr[] = {1,2,3,4}; /* rvalue from gcc_jit_context_new_constructor. */
930 int *bar = &arr[2] + 1; /* rvalue from nested "get address" of "array access". */
931 const int baz = 3; /* rvalue from gcc_jit_context_rvalue_from_int. */
932 int boz = baz; /* rvalue from gcc_jit_lvalue_as_rvalue. */
934 Use together with :c:func:`gcc_jit_context_new_struct_constructor`,
935 :c:func:`gcc_jit_context_new_union_constructor`, :c:func:`gcc_jit_context_new_array_constructor`
936 to initialize structs, unions and arrays.
938 On success, returns the ``global`` parameter unchanged. Otherwise, ``NULL``.
940 This entrypoint was added in :ref:`LIBGCCJIT_ABI_19`; you can test for its
945 #ifdef LIBGCCJIT_HAVE_CTORS
947 Working with pointers, structs and unions
948 -----------------------------------------
950 .. function:: gcc_jit_lvalue *\
951 gcc_jit_rvalue_dereference (gcc_jit_rvalue *rvalue,\
952 gcc_jit_location *loc)
954 Given an rvalue of pointer type ``T *``, dereferencing the pointer,
955 getting an lvalue of type ``T``. Analogous to:
963 Field access is provided separately for both lvalues and rvalues.
965 .. function:: gcc_jit_lvalue *\
966 gcc_jit_lvalue_access_field (gcc_jit_lvalue *struct_,\
967 gcc_jit_location *loc,\
968 gcc_jit_field *field)
970 Given an lvalue of struct or union type, access the given field,
971 getting an lvalue of the field's type. Analogous to:
979 .. function:: gcc_jit_rvalue *\
980 gcc_jit_rvalue_access_field (gcc_jit_rvalue *struct_,\
981 gcc_jit_location *loc,\
982 gcc_jit_field *field)
984 Given an rvalue of struct or union type, access the given field
985 as an rvalue. Analogous to:
993 .. function:: gcc_jit_lvalue *\
994 gcc_jit_rvalue_dereference_field (gcc_jit_rvalue *ptr,\
995 gcc_jit_location *loc,\
996 gcc_jit_field *field)
998 Given an rvalue of pointer type ``T *`` where T is of struct or union
999 type, access the given field as an lvalue. Analogous to:
1005 in C, itself equivalent to ``(*EXPR).FIELD``.
1007 .. function:: gcc_jit_lvalue *\
1008 gcc_jit_context_new_array_access (gcc_jit_context *ctxt,\
1009 gcc_jit_location *loc,\
1010 gcc_jit_rvalue *ptr,\
1011 gcc_jit_rvalue *index)
1013 Given an rvalue of pointer type ``T *``, get at the element `T` at
1014 the given index, using standard C array indexing rules i.e. each
1015 increment of ``index`` corresponds to ``sizeof(T)`` bytes.
1022 in C (or, indeed, to ``PTR + INDEX``).