10 create_code (gcc_jit_context
*ctxt
, void *user_data
)
12 /* Let's try to inject the equivalent of:
15 test_string_literal (void)
20 gcc_jit_type
*const_char_ptr_type
=
21 gcc_jit_context_get_type (ctxt
, GCC_JIT_TYPE_CONST_CHAR_PTR
);
23 /* Build the test_fn. */
24 gcc_jit_function
*test_fn
=
25 gcc_jit_context_new_function (ctxt
, NULL
,
26 GCC_JIT_FUNCTION_EXPORTED
,
28 "test_string_literal",
31 gcc_jit_block
*block
= gcc_jit_function_new_block (test_fn
, NULL
);
33 gcc_jit_block_end_with_return (
35 gcc_jit_context_new_string_literal (ctxt
, "hello world"));
39 verify_code (gcc_jit_context
*ctxt
, gcc_jit_result
*result
)
41 typedef const char *(*fn_type
) (void);
42 CHECK_NON_NULL (result
);
43 fn_type test_string_literal
=
44 (fn_type
)gcc_jit_result_get_code (result
, "test_string_literal");
45 CHECK_NON_NULL (test_string_literal
);
47 /* Call the JIT-generated function. */
48 const char *str
= test_string_literal ();
50 CHECK_VALUE (strcmp (str
, "hello world"), 0);