6 #define TEST_COMPILING_TO_FILE
7 #define OUTPUT_KIND GCC_JIT_OUTPUT_KIND_DYNAMIC_LIBRARY
8 #define OUTPUT_FILENAME "output-of-test-compile-to-dynamic-library.c.so"
12 create_code (gcc_jit_context
*ctxt
, void *user_data
)
14 /* Let's try to inject the equivalent of:
16 hello_world (const char *name)
19 printf ("hello from %s\n", name);
22 gcc_jit_type
*void_type
=
23 gcc_jit_context_get_type (ctxt
, GCC_JIT_TYPE_VOID
);
24 gcc_jit_type
*const_char_ptr_type
=
25 gcc_jit_context_get_type (ctxt
, GCC_JIT_TYPE_CONST_CHAR_PTR
);
26 gcc_jit_param
*param_name
=
27 gcc_jit_context_new_param (ctxt
, NULL
, const_char_ptr_type
, "name");
28 gcc_jit_function
*func
=
29 gcc_jit_context_new_function (ctxt
, NULL
,
30 GCC_JIT_FUNCTION_EXPORTED
,
36 gcc_jit_param
*param_format
=
37 gcc_jit_context_new_param (ctxt
, NULL
, const_char_ptr_type
, "format");
38 gcc_jit_function
*printf_func
=
39 gcc_jit_context_new_function (ctxt
, NULL
,
40 GCC_JIT_FUNCTION_IMPORTED
,
41 gcc_jit_context_get_type (
42 ctxt
, GCC_JIT_TYPE_INT
),
46 gcc_jit_rvalue
*args
[2];
47 args
[0] = gcc_jit_context_new_string_literal (ctxt
, "hello from %s\n");
48 args
[1] = gcc_jit_param_as_rvalue (param_name
);
50 gcc_jit_block
*block
= gcc_jit_function_new_block (func
, NULL
);
52 gcc_jit_block_add_comment (
56 gcc_jit_block_add_eval (
58 gcc_jit_context_new_call (ctxt
,
62 gcc_jit_block_end_with_void_return (block
, NULL
);
65 /* { dg-final { jit-verify-output-file-was-created "" } } */
66 /* { dg-final { jit-verify-dynamic-library "hello from ./verify-dynamic-library.c.exe" } } */