9 /* Quote from here in docs/topics/functions.rst. */
12 create_code (gcc_jit_context
*ctxt
, void *user_data
)
14 /* Let's try to inject the equivalent of:
38 gcc_jit_context_get_type (ctxt
, GCC_JIT_TYPE_INT
);
39 gcc_jit_type
*return_type
= t_int
;
41 gcc_jit_context_new_param (ctxt
, NULL
, t_int
, "x");
42 gcc_jit_param
*params
[1] = {x
};
43 gcc_jit_function
*func
=
44 gcc_jit_context_new_function (ctxt
, NULL
,
45 GCC_JIT_FUNCTION_EXPORTED
,
50 gcc_jit_block
*b_initial
=
51 gcc_jit_function_new_block (func
, "initial");
53 gcc_jit_block
*b_default
=
54 gcc_jit_function_new_block (func
, "default");
55 gcc_jit_block
*b_case_0_5
=
56 gcc_jit_function_new_block (func
, "case_0_5");
57 gcc_jit_block
*b_case_25_27
=
58 gcc_jit_function_new_block (func
, "case_25_27");
59 gcc_jit_block
*b_case_m42_m17
=
60 gcc_jit_function_new_block (func
, "case_m42_m17");
61 gcc_jit_block
*b_case_40
=
62 gcc_jit_function_new_block (func
, "case_40");
64 gcc_jit_case
*cases
[4] = {
65 gcc_jit_context_new_case (
67 gcc_jit_context_new_rvalue_from_int (ctxt
, t_int
, 0),
68 gcc_jit_context_new_rvalue_from_int (ctxt
, t_int
, 5),
70 gcc_jit_context_new_case (
72 gcc_jit_context_new_rvalue_from_int (ctxt
, t_int
, 25),
73 gcc_jit_context_new_rvalue_from_int (ctxt
, t_int
, 27),
75 gcc_jit_context_new_case (
77 gcc_jit_context_new_rvalue_from_int (ctxt
, t_int
, -42),
78 gcc_jit_context_new_rvalue_from_int (ctxt
, t_int
, -17),
80 gcc_jit_context_new_case (
82 gcc_jit_context_new_rvalue_from_int (ctxt
, t_int
, 40),
83 gcc_jit_context_new_rvalue_from_int (ctxt
, t_int
, 40),
86 gcc_jit_block_end_with_switch (
88 gcc_jit_param_as_rvalue (x
),
92 gcc_jit_block_end_with_return (
94 gcc_jit_context_new_rvalue_from_int (ctxt
, t_int
, 3));
95 gcc_jit_block_end_with_return (
97 gcc_jit_context_new_rvalue_from_int (ctxt
, t_int
, 4));
98 gcc_jit_block_end_with_return (
100 gcc_jit_context_new_rvalue_from_int (ctxt
, t_int
, 83));
101 gcc_jit_block_end_with_return (
103 gcc_jit_context_new_rvalue_from_int (ctxt
, t_int
, 8));
104 gcc_jit_block_end_with_return (
106 gcc_jit_context_new_rvalue_from_int (ctxt
, t_int
, 10));
109 /* Quote up to here in docs/topics/functions.rst. */
112 c_test_switch (int x
)
130 verify_code (gcc_jit_context
*ctxt
, gcc_jit_result
*result
)
132 typedef int (*test_switch_type
) (int);
133 CHECK_NON_NULL (result
);
134 test_switch_type test_switch
=
135 (test_switch_type
)gcc_jit_result_get_code (result
, "test_switch");
136 CHECK_NON_NULL (test_switch
);
140 for (i
= -255; i
< 255; i
++)
142 int val
= test_switch (i
);
143 int exp
= c_test_switch (i
);
145 fail ("test_switch (%i) returned: %i; expected; %i", i
, val
, exp
);