1 /* Test of using the API with very long names. */
11 #define NAME_LENGTH (65 * 1024)
13 static struct long_names
15 char struct_name
[NAME_LENGTH
];
16 char fn_name
[NAME_LENGTH
];
17 char local_name
[NAME_LENGTH
];
18 char block_name
[NAME_LENGTH
];
22 populate_name (const char *prefix
, char *buffer
)
26 /* Begin with the given prefix: */
27 sprintf (buffer
, prefix
);
29 /* Populate the rest of the buffer with 0123456789 repeatedly: */
30 for (i
= strlen (prefix
); i
< NAME_LENGTH
- 1; i
++)
31 buffer
[i
] = '0' + (i
% 10);
33 /* NIL-terminate the buffer: */
34 buffer
[NAME_LENGTH
- 1] = '\0';
40 populate_name ("struct_", long_names
.struct_name
);
41 populate_name ("test_fn_", long_names
.fn_name
);
42 populate_name ("local_", long_names
.local_name
);
43 populate_name ("block_", long_names
.block_name
);
47 create_code (gcc_jit_context
*ctxt
, void *user_data
)
49 /* Where "ETC" is a very long suffix, let's try to inject the
62 to verify that the API copes with such long names. */
66 gcc_jit_type
*int_type
=
67 gcc_jit_context_get_type (ctxt
, GCC_JIT_TYPE_INT
);
69 /* We don't yet use this struct. */
70 (void)gcc_jit_context_new_opaque_struct (ctxt
, NULL
,
71 long_names
.struct_name
);
73 gcc_jit_function
*test_fn
=
74 gcc_jit_context_new_function (ctxt
, NULL
,
75 GCC_JIT_FUNCTION_EXPORTED
,
80 gcc_jit_lvalue
*local
=
81 gcc_jit_function_new_local (test_fn
,
84 long_names
.local_name
);
86 gcc_jit_block
*block
=
87 gcc_jit_function_new_block (test_fn
, long_names
.block_name
);
89 gcc_jit_block_add_assignment (
93 gcc_jit_context_new_rvalue_from_int (ctxt
, int_type
, 42));
95 gcc_jit_block_end_with_return (
97 gcc_jit_lvalue_as_rvalue (local
));
101 verify_code (gcc_jit_context
*ctxt
, gcc_jit_result
*result
)
103 CHECK_NON_NULL (result
);
105 typedef int (*my_fn_type
) (void);
106 CHECK_NON_NULL (result
);
108 (my_fn_type
)gcc_jit_result_get_code (result
, long_names
.fn_name
);
109 CHECK_NON_NULL (my_fn
);
111 CHECK_VALUE (val
, 42);