8 /* Build various compound expressions, and verify that they have sane debug
11 create_code (gcc_jit_context
*ctxt
, void *user_data
)
13 /* Make a singly-linked list type:
21 gcc_jit_context_get_type (ctxt
, GCC_JIT_TYPE_INT
);
22 gcc_jit_struct
*t_node
=
23 gcc_jit_context_new_opaque_struct (ctxt
, NULL
, "node");
24 gcc_jit_type
*t_node_ptr
=
25 gcc_jit_type_get_pointer (gcc_jit_struct_as_type (t_node
));
26 gcc_jit_field
*f_next
=
27 gcc_jit_context_new_field (ctxt
, NULL
, t_node_ptr
, "next");
28 gcc_jit_field
*f_value
=
29 gcc_jit_context_new_field (ctxt
, NULL
, t_int
, "value");
30 gcc_jit_field
*fields
[] = {f_next
, f_value
};
31 gcc_jit_struct_set_fields (t_node
, NULL
, 2, fields
);
33 /* Create a dummy function so that we have locals/params to build
35 gcc_jit_type
*t_void
=
36 gcc_jit_context_get_type (ctxt
, GCC_JIT_TYPE_VOID
);
37 gcc_jit_function
*fn
=
38 gcc_jit_context_new_function (ctxt
, NULL
,
39 GCC_JIT_FUNCTION_EXPORTED
,
44 gcc_jit_lvalue_as_rvalue (
45 gcc_jit_function_new_local (fn
,
50 gcc_jit_lvalue_as_rvalue (
51 gcc_jit_function_new_local (fn
, NULL
, t_int
, "a"));
53 gcc_jit_lvalue_as_rvalue (
54 gcc_jit_function_new_local (fn
, NULL
, t_int
, "b"));
56 gcc_jit_lvalue_as_rvalue (
57 gcc_jit_function_new_local (fn
, NULL
, t_int
, "c"));
59 gcc_jit_lvalue_as_rvalue (
60 gcc_jit_function_new_local (fn
, NULL
, t_int
, "d"));
62 #define CHECK_RVALUE_DEBUG_STRING(RVALUE, EXPECTED) \
63 CHECK_STRING_VALUE ( \
64 gcc_jit_object_get_debug_string (gcc_jit_rvalue_as_object (RVALUE)), \
67 #define CHECK_LVALUE_DEBUG_STRING(LVALUE, EXPECTED) \
68 CHECK_STRING_VALUE ( \
69 gcc_jit_object_get_debug_string (gcc_jit_lvalue_as_object (LVALUE)), \
72 /* Verify various simple compound expressions. */
74 CHECK_RVALUE_DEBUG_STRING (ptr
, "ptr");
76 gcc_jit_lvalue
*deref
=
77 gcc_jit_rvalue_dereference_field (ptr
,
80 CHECK_LVALUE_DEBUG_STRING (deref
, "ptr->value");
82 gcc_jit_rvalue
*deref_as_rvalue
= gcc_jit_lvalue_as_rvalue (deref
);
84 #define BINOP(OP, A, B) \
85 gcc_jit_context_new_binary_op (ctxt, NULL, \
86 GCC_JIT_BINARY_OP_##OP, t_int, (A), (B))
87 #define COMPARISON(OP, A, B) \
88 gcc_jit_context_new_comparison (ctxt, NULL, \
89 GCC_JIT_COMPARISON_##OP,(A), (B))
91 CHECK_RVALUE_DEBUG_STRING (
92 BINOP (PLUS
, deref_as_rvalue
, deref_as_rvalue
),
93 "ptr->value + ptr->value");
94 CHECK_RVALUE_DEBUG_STRING (
95 BINOP (MULT
, deref_as_rvalue
, deref_as_rvalue
),
96 "ptr->value * ptr->value");
98 /* Multiplication has higher precedence in C than addition, so this
99 dump shouldn't contain parentheses. */
100 CHECK_RVALUE_DEBUG_STRING (
106 /* ...but this one should. */
107 CHECK_RVALUE_DEBUG_STRING (
111 "(a + b) * (c + d)");
113 /* Equal precedences don't need parentheses. */
114 CHECK_RVALUE_DEBUG_STRING (
120 /* Comparisons and logical ops. */
121 CHECK_RVALUE_DEBUG_STRING (
122 COMPARISON (LT
, a
, b
),
125 CHECK_RVALUE_DEBUG_STRING (
127 COMPARISON (LT
, a
, b
),
128 COMPARISON (GT
, c
, d
)),
131 CHECK_RVALUE_DEBUG_STRING (
134 COMPARISON (LT
, a
, b
),
135 COMPARISON (LT
, a
, c
)),
137 COMPARISON (GT
, d
, b
),
138 COMPARISON (GT
, d
, c
))),
139 "(a < b || a < c) && (d > b || d > c)");
141 CHECK_RVALUE_DEBUG_STRING (
144 COMPARISON (LT
, a
, b
),
145 COMPARISON (LT
, a
, c
)),
147 COMPARISON (GT
, d
, b
),
148 COMPARISON (GT
, d
, c
))),
149 "a < b && a < c || d > b && d > c");
155 /* PR jit/66539 "Missing parentheses in jit dumps".
156 Construct the equivalent of
157 ((cast)ptr->next)->next
158 and verify that the appropriate parentheses appear in the debug
162 gcc_jit_lvalue
*inner_deref
=
163 gcc_jit_rvalue_dereference_field (ptr
,
166 /* "((node *)ptr->next)"; the cast is redundant, purely
167 to exercise dumping. */
168 gcc_jit_rvalue
*test_cast
=
169 gcc_jit_context_new_cast (ctxt
, NULL
,
170 gcc_jit_lvalue_as_rvalue (inner_deref
),
172 /* "((node *)ptr->next)->next". */
173 gcc_jit_lvalue
*outer_deref
=
174 gcc_jit_rvalue_dereference_field (test_cast
, /* gcc_jit_rvalue *ptr */
175 NULL
, /* gcc_jit_location *loc */
176 f_next
); /* gcc_jit_field *field */
177 CHECK_LVALUE_DEBUG_STRING (outer_deref
,
178 "((struct node *)ptr->next)->next");
181 #undef CHECK_LVALUE_DEBUG_STRING
185 verify_code (gcc_jit_context
*ctxt
, gcc_jit_result
*result
)
187 CHECK_NON_NULL (result
);
188 /* We don't actually build any functions above;
189 nothing more to verify. */