libgo: update to Go1.10beta1
[official-gcc.git] / gcc / testsuite / jit.dg / test-compile-to-dynamic-library.c
blobc29e6f6d6289b0e209e21afa6d47e9f8f6123b20
1 #include <stdlib.h>
2 #include <stdio.h>
4 #include "libgccjit.h"
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"
9 #include "harness.h"
11 void
12 create_code (gcc_jit_context *ctxt, void *user_data)
14 /* Let's try to inject the equivalent of:
15 void
16 hello_world (const char *name)
18 // a test comment
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,
31 void_type,
32 "hello_world",
33 1, &param_name,
34 0);
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),
43 "printf",
44 1, &param_format,
45 1);
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 (
53 block, NULL,
54 "a test comment");
56 gcc_jit_block_add_eval (
57 block, NULL,
58 gcc_jit_context_new_call (ctxt,
59 NULL,
60 printf_func,
61 2, args));
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" } } */