| 1 |
/* A pure C API to enable client code to embed GCC as a JIT-compiler. |
| 2 |
Copyright (C) 2013-2025 Free Software Foundation, Inc. |
| 3 |
|
| 4 |
This file is part of GCC. |
| 5 |
|
| 6 |
GCC is free software; you can redistribute it and/or modify it |
| 7 |
under the terms of the GNU General Public License as published by |
| 8 |
the Free Software Foundation; either version 3, or (at your option) |
| 9 |
any later version. |
| 10 |
|
| 11 |
GCC is distributed in the hope that it will be useful, but |
| 12 |
WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 |
General Public License for more details. |
| 15 |
|
| 16 |
You should have received a copy of the GNU General Public License |
| 17 |
along with GCC; see the file COPYING3. If not see |
| 18 |
<http://www.gnu.org/licenses/>. */ |
| 19 |
|
| 20 |
#ifndef LIBGCCJIT_H |
| 21 |
#define LIBGCCJIT_H |
| 22 |
|
| 23 |
#include <stdio.h> |
| 24 |
#ifdef __has_include |
| 25 |
#if __has_include (<sys/types.h>) |
| 26 |
#include <sys/types.h> |
| 27 |
#endif |
| 28 |
#endif |
| 29 |
|
| 30 |
#ifdef __cplusplus |
| 31 |
extern "C" { |
| 32 |
#endif /* __cplusplus */ |
| 33 |
|
| 34 |
/********************************************************************** |
| 35 |
Data structures. |
| 36 |
**********************************************************************/ |
| 37 |
/* All structs within the API are opaque. */ |
| 38 |
|
| 39 |
/* A gcc_jit_context encapsulates the state of a compilation. |
| 40 |
You can set up options on it, and add types, functions and code, using |
| 41 |
the API below. |
| 42 |
|
| 43 |
Invoking gcc_jit_context_compile on it gives you a gcc_jit_result * |
| 44 |
(or NULL), representing in-memory machine code. |
| 45 |
|
| 46 |
You can call gcc_jit_context_compile repeatedly on one context, giving |
| 47 |
multiple independent results. |
| 48 |
|
| 49 |
Similarly, you can call gcc_jit_context_compile_to_file on a context |
| 50 |
to compile to disk. |
| 51 |
|
| 52 |
Eventually you can call gcc_jit_context_release to clean up the |
| 53 |
context; any in-memory results created from it are still usable, and |
| 54 |
should be cleaned up via gcc_jit_result_release. */ |
| 55 |
typedef struct gcc_jit_context gcc_jit_context; |
| 56 |
|
| 57 |
/* A gcc_jit_result encapsulates the result of an in-memory compilation. */ |
| 58 |
typedef struct gcc_jit_result gcc_jit_result; |
| 59 |
|
| 60 |
/* An object created within a context. Such objects are automatically |
| 61 |
cleaned up when the context is released. |
| 62 |
|
| 63 |
The class hierarchy looks like this: |
| 64 |
|
| 65 |
+- gcc_jit_object |
| 66 |
+- gcc_jit_location |
| 67 |
+- gcc_jit_type |
| 68 |
+- gcc_jit_struct |
| 69 |
+- gcc_jit_function_type |
| 70 |
+- gcc_jit_vector_type |
| 71 |
+- gcc_jit_field |
| 72 |
+- gcc_jit_function |
| 73 |
+- gcc_jit_block |
| 74 |
+- gcc_jit_rvalue |
| 75 |
+- gcc_jit_lvalue |
| 76 |
+- gcc_jit_param |
| 77 |
+- gcc_jit_case |
| 78 |
+- gcc_jit_extended_asm |
| 79 |
*/ |
| 80 |
typedef struct gcc_jit_object gcc_jit_object; |
| 81 |
|
| 82 |
/* A gcc_jit_location encapsulates a source code location, so that |
| 83 |
you can (optionally) associate locations in your language with |
| 84 |
statements in the JIT-compiled code, allowing the debugger to |
| 85 |
single-step through your language. |
| 86 |
|
| 87 |
Note that to do so, you also need to enable |
| 88 |
GCC_JIT_BOOL_OPTION_DEBUGINFO |
| 89 |
on the gcc_jit_context. |
| 90 |
|
| 91 |
gcc_jit_location instances are optional; you can always pass |
| 92 |
NULL. */ |
| 93 |
typedef struct gcc_jit_location gcc_jit_location; |
| 94 |
|
| 95 |
/* A gcc_jit_type encapsulates a type e.g. "int" or a "struct foo*". */ |
| 96 |
typedef struct gcc_jit_type gcc_jit_type; |
| 97 |
|
| 98 |
/* A gcc_jit_field encapsulates a field within a struct; it is used |
| 99 |
when creating a struct type (using gcc_jit_context_new_struct_type). |
| 100 |
Fields cannot be shared between structs. */ |
| 101 |
typedef struct gcc_jit_field gcc_jit_field; |
| 102 |
|
| 103 |
/* A gcc_jit_struct encapsulates a struct type, either one that we have |
| 104 |
the layout for, or an opaque type. */ |
| 105 |
typedef struct gcc_jit_struct gcc_jit_struct; |
| 106 |
|
| 107 |
/* A gcc_jit_function_type encapsulates a function type. */ |
| 108 |
typedef struct gcc_jit_function_type gcc_jit_function_type; |
| 109 |
|
| 110 |
/* A gcc_jit_vector_type encapsulates a vector type. */ |
| 111 |
typedef struct gcc_jit_vector_type gcc_jit_vector_type; |
| 112 |
|
| 113 |
/* A gcc_jit_function encapsulates a function: either one that you're |
| 114 |
creating yourself, or a reference to one that you're dynamically |
| 115 |
linking to within the rest of the process. */ |
| 116 |
typedef struct gcc_jit_function gcc_jit_function; |
| 117 |
|
| 118 |
/* A gcc_jit_block encapsulates a "basic block" of statements within a |
| 119 |
function (i.e. with one entry point and one exit point). |
| 120 |
|
| 121 |
Every block within a function must be terminated with a conditional, |
| 122 |
a branch, or a return. |
| 123 |
|
| 124 |
The blocks within a function form a directed graph. |
| 125 |
|
| 126 |
The entrypoint to the function is the first block created within |
| 127 |
it. |
| 128 |
|
| 129 |
All of the blocks in a function must be reachable via some path from |
| 130 |
the first block. |
| 131 |
|
| 132 |
It's OK to have more than one "return" from a function (i.e. multiple |
| 133 |
blocks that terminate by returning). */ |
| 134 |
typedef struct gcc_jit_block gcc_jit_block; |
| 135 |
|
| 136 |
/* A gcc_jit_rvalue is an expression within your code, with some type. */ |
| 137 |
typedef struct gcc_jit_rvalue gcc_jit_rvalue; |
| 138 |
|
| 139 |
/* A gcc_jit_lvalue is a storage location within your code (e.g. a |
| 140 |
variable, a parameter, etc). It is also a gcc_jit_rvalue; use |
| 141 |
gcc_jit_lvalue_as_rvalue to cast. */ |
| 142 |
typedef struct gcc_jit_lvalue gcc_jit_lvalue; |
| 143 |
|
| 144 |
/* A gcc_jit_param is a function parameter, used when creating a |
| 145 |
gcc_jit_function. It is also a gcc_jit_lvalue (and thus also an |
| 146 |
rvalue); use gcc_jit_param_as_lvalue to convert. */ |
| 147 |
typedef struct gcc_jit_param gcc_jit_param; |
| 148 |
|
| 149 |
/* A gcc_jit_case is for use when building multiway branches via |
| 150 |
gcc_jit_block_end_with_switch and represents a range of integer |
| 151 |
values (or an individual integer value) together with an associated |
| 152 |
destination block. */ |
| 153 |
typedef struct gcc_jit_case gcc_jit_case; |
| 154 |
|
| 155 |
/* A gcc_jit_extended_asm represents an assembly language statement, |
| 156 |
analogous to an extended "asm" statement in GCC's C front-end: a series |
| 157 |
of low-level instructions inside a function that convert inputs to |
| 158 |
outputs. */ |
| 159 |
typedef struct gcc_jit_extended_asm gcc_jit_extended_asm; |
| 160 |
|
| 161 |
/* Acquire a JIT-compilation context. */ |
| 162 |
extern gcc_jit_context * |
| 163 |
gcc_jit_context_acquire (void); |
| 164 |
|
| 165 |
/* Release the context. After this call, it's no longer valid to use |
| 166 |
the ctxt. */ |
| 167 |
extern void |
| 168 |
gcc_jit_context_release (gcc_jit_context *ctxt); |
| 169 |
|
| 170 |
/* Options present in the initial release of libgccjit. |
| 171 |
These were handled using enums. */ |
| 172 |
|
| 173 |
/* Options taking string values. */ |
| 174 |
enum gcc_jit_str_option |
| 175 |
{ |
| 176 |
/* The name of the program, for use as a prefix when printing error |
| 177 |
messages to stderr. If NULL, or default, "libgccjit.so" is used. */ |
| 178 |
GCC_JIT_STR_OPTION_PROGNAME, |
| 179 |
|
| 180 |
/* Special characters to allow in function names. */ |
| 181 |
GCC_JIT_STR_OPTION_SPECIAL_CHARS_IN_FUNC_NAMES, |
| 182 |
|
| 183 |
GCC_JIT_NUM_STR_OPTIONS |
| 184 |
}; |
| 185 |
|
| 186 |
/* Options taking int values. */ |
| 187 |
enum gcc_jit_int_option |
| 188 |
{ |
| 189 |
/* How much to optimize the code. |
| 190 |
Valid values are 0-3, corresponding to GCC's command-line options |
| 191 |
-O0 through -O3. |
| 192 |
|
| 193 |
The default value is 0 (unoptimized). */ |
| 194 |
GCC_JIT_INT_OPTION_OPTIMIZATION_LEVEL, |
| 195 |
|
| 196 |
GCC_JIT_NUM_INT_OPTIONS |
| 197 |
}; |
| 198 |
|
| 199 |
/* Options taking boolean values. |
| 200 |
These all default to "false". */ |
| 201 |
enum gcc_jit_bool_option |
| 202 |
{ |
| 203 |
/* If true, gcc_jit_context_compile will attempt to do the right |
| 204 |
thing so that if you attach a debugger to the process, it will |
| 205 |
be able to inspect variables and step through your code. |
| 206 |
|
| 207 |
Note that you can't step through code unless you set up source |
| 208 |
location information for the code (by creating and passing in |
| 209 |
gcc_jit_location instances). */ |
| 210 |
GCC_JIT_BOOL_OPTION_DEBUGINFO, |
| 211 |
|
| 212 |
/* If true, gcc_jit_context_compile will dump its initial "tree" |
| 213 |
representation of your code to stderr (before any |
| 214 |
optimizations). */ |
| 215 |
GCC_JIT_BOOL_OPTION_DUMP_INITIAL_TREE, |
| 216 |
|
| 217 |
/* If true, gcc_jit_context_compile will dump the "gimple" |
| 218 |
representation of your code to stderr, before any optimizations |
| 219 |
are performed. The dump resembles C code. */ |
| 220 |
GCC_JIT_BOOL_OPTION_DUMP_INITIAL_GIMPLE, |
| 221 |
|
| 222 |
/* If true, gcc_jit_context_compile will dump the final |
| 223 |
generated code to stderr, in the form of assembly language. */ |
| 224 |
GCC_JIT_BOOL_OPTION_DUMP_GENERATED_CODE, |
| 225 |
|
| 226 |
/* If true, gcc_jit_context_compile will print information to stderr |
| 227 |
on the actions it is performing, followed by a profile showing |
| 228 |
the time taken and memory usage of each phase. |
| 229 |
*/ |
| 230 |
GCC_JIT_BOOL_OPTION_DUMP_SUMMARY, |
| 231 |
|
| 232 |
/* If true, gcc_jit_context_compile will dump copious |
| 233 |
amount of information on what it's doing to various |
| 234 |
files within a temporary directory. Use |
| 235 |
GCC_JIT_BOOL_OPTION_KEEP_INTERMEDIATES (see below) to |
| 236 |
see the results. The files are intended to be human-readable, |
| 237 |
but the exact files and their formats are subject to change. |
| 238 |
*/ |
| 239 |
GCC_JIT_BOOL_OPTION_DUMP_EVERYTHING, |
| 240 |
|
| 241 |
/* If true, libgccjit will aggressively run its garbage collector, to |
| 242 |
shake out bugs (greatly slowing down the compile). This is likely |
| 243 |
to only be of interest to developers *of* the library. It is |
| 244 |
used when running the selftest suite. */ |
| 245 |
GCC_JIT_BOOL_OPTION_SELFCHECK_GC, |
| 246 |
|
| 247 |
/* If true, gcc_jit_context_release will not clean up |
| 248 |
intermediate files written to the filesystem, and will display |
| 249 |
their location on stderr. */ |
| 250 |
GCC_JIT_BOOL_OPTION_KEEP_INTERMEDIATES, |
| 251 |
|
| 252 |
GCC_JIT_NUM_BOOL_OPTIONS |
| 253 |
}; |
| 254 |
|
| 255 |
/* Set a string option on the given context. |
| 256 |
|
| 257 |
The context takes a copy of the string, so the |
| 258 |
(const char *) buffer is not needed anymore after the call |
| 259 |
returns. */ |
| 260 |
extern void |
| 261 |
gcc_jit_context_set_str_option (gcc_jit_context *ctxt, |
| 262 |
enum gcc_jit_str_option opt, |
| 263 |
const char *value); |
| 264 |
|
| 265 |
/* Set an int option on the given context. */ |
| 266 |
extern void |
| 267 |
gcc_jit_context_set_int_option (gcc_jit_context *ctxt, |
| 268 |
enum gcc_jit_int_option opt, |
| 269 |
int value); |
| 270 |
|
| 271 |
/* Set a boolean option on the given context. |
| 272 |
|
| 273 |
Zero is "false" (the default), non-zero is "true". */ |
| 274 |
extern void |
| 275 |
gcc_jit_context_set_bool_option (gcc_jit_context *ctxt, |
| 276 |
enum gcc_jit_bool_option opt, |
| 277 |
int value); |
| 278 |
|
| 279 |
/* Options added after the initial release of libgccjit. |
| 280 |
These are handled by providing an entrypoint per option, |
| 281 |
rather than by extending the enum gcc_jit_*_option, |
| 282 |
so that client code that use these new options can be identified |
| 283 |
from binary metadata. */ |
| 284 |
|
| 285 |
/* By default, libgccjit will issue an error about unreachable blocks |
| 286 |
within a function. |
| 287 |
|
| 288 |
This option can be used to disable that error. |
| 289 |
|
| 290 |
This entrypoint was added in LIBGCCJIT_ABI_2; you can test for |
| 291 |
its presence using |
| 292 |
#ifdef LIBGCCJIT_HAVE_gcc_jit_context_set_bool_allow_unreachable_blocks |
| 293 |
*/ |
| 294 |
|
| 295 |
extern void |
| 296 |
gcc_jit_context_set_bool_allow_unreachable_blocks (gcc_jit_context *ctxt, |
| 297 |
int bool_value); |
| 298 |
|
| 299 |
/* Pre-canned feature macro to indicate the presence of |
| 300 |
gcc_jit_context_set_bool_allow_unreachable_blocks. This can be |
| 301 |
tested for with #ifdef. */ |
| 302 |
#define LIBGCCJIT_HAVE_gcc_jit_context_set_bool_allow_unreachable_blocks |
| 303 |
|
| 304 |
/* By default, libgccjit will print errors to stderr. |
| 305 |
|
| 306 |
This option can be used to disable the printing. |
| 307 |
|
| 308 |
This entrypoint was added in LIBGCCJIT_ABI_23; you can test for |
| 309 |
its presence using |
| 310 |
#ifdef LIBGCCJIT_HAVE_gcc_jit_context_set_bool_print_errors_to_stderr |
| 311 |
*/ |
| 312 |
|
| 313 |
extern void |
| 314 |
gcc_jit_context_set_bool_print_errors_to_stderr (gcc_jit_context *ctxt, |
| 315 |
int enabled); |
| 316 |
|
| 317 |
/* Pre-canned feature macro to indicate the presence of |
| 318 |
gcc_jit_context_set_bool_print_errors_to_stderr. This can be |
| 319 |
tested for with #ifdef. */ |
| 320 |
#define LIBGCCJIT_HAVE_gcc_jit_context_set_bool_print_errors_to_stderr |
| 321 |
|
| 322 |
/* Implementation detail: |
| 323 |
libgccjit internally generates assembler, and uses "driver" code |
| 324 |
for converting it to other formats (e.g. shared libraries). |
| 325 |
|
| 326 |
By default, libgccjit will use an embedded copy of the driver |
| 327 |
code. |
| 328 |
|
| 329 |
This option can be used to instead invoke an external driver executable |
| 330 |
as a subprocess. |
| 331 |
|
| 332 |
This entrypoint was added in LIBGCCJIT_ABI_5; you can test for |
| 333 |
its presence using |
| 334 |
#ifdef LIBGCCJIT_HAVE_gcc_jit_context_set_bool_use_external_driver |
| 335 |
*/ |
| 336 |
|
| 337 |
extern void |
| 338 |
gcc_jit_context_set_bool_use_external_driver (gcc_jit_context *ctxt, |
| 339 |
int bool_value); |
| 340 |
|
| 341 |
/* Pre-canned feature macro to indicate the presence of |
| 342 |
gcc_jit_context_set_bool_use_external_driver. This can be |
| 343 |
tested for with #ifdef. */ |
| 344 |
#define LIBGCCJIT_HAVE_gcc_jit_context_set_bool_use_external_driver |
| 345 |
|
| 346 |
/* Add an arbitrary gcc command-line option to the context. |
| 347 |
The context takes a copy of the string, so the |
| 348 |
(const char *) optname is not needed anymore after the call |
| 349 |
returns. |
| 350 |
|
| 351 |
Note that only some options are likely to be meaningful; there is no |
| 352 |
"frontend" within libgccjit, so typically only those affecting |
| 353 |
optimization and code-generation are likely to be useful. |
| 354 |
|
| 355 |
This entrypoint was added in LIBGCCJIT_ABI_1; you can test for |
| 356 |
its presence using |
| 357 |
#ifdef LIBGCCJIT_HAVE_gcc_jit_context_add_command_line_option |
| 358 |
*/ |
| 359 |
|
| 360 |
extern void |
| 361 |
gcc_jit_context_add_command_line_option (gcc_jit_context *ctxt, |
| 362 |
const char *optname); |
| 363 |
|
| 364 |
/* Pre-canned feature-test macro for detecting the presence of |
| 365 |
gcc_jit_context_add_command_line_option within libgccjit.h. */ |
| 366 |
|
| 367 |
#define LIBGCCJIT_HAVE_gcc_jit_context_add_command_line_option |
| 368 |
|
| 369 |
/* Add an arbitrary gcc driver option to the context. |
| 370 |
The context takes a copy of the string, so the |
| 371 |
(const char *) optname is not needed anymore after the call |
| 372 |
returns. |
| 373 |
|
| 374 |
Note that only some options are likely to be meaningful; there is no |
| 375 |
"frontend" within libgccjit, so typically only those affecting |
| 376 |
assembler and linker are likely to be useful. |
| 377 |
|
| 378 |
This entrypoint was added in LIBGCCJIT_ABI_11; you can test for |
| 379 |
its presence using |
| 380 |
#ifdef LIBGCCJIT_HAVE_gcc_jit_context_add_driver_option |
| 381 |
*/ |
| 382 |
extern void |
| 383 |
gcc_jit_context_add_driver_option (gcc_jit_context *ctxt, |
| 384 |
const char *optname); |
| 385 |
|
| 386 |
/* Pre-canned feature-test macro for detecting the presence of |
| 387 |
gcc_jit_context_add_driver_option within libgccjit.h. */ |
| 388 |
|
| 389 |
#define LIBGCCJIT_HAVE_gcc_jit_context_add_driver_option |
| 390 |
|
| 391 |
/* Compile the context to in-memory machine code. |
| 392 |
|
| 393 |
This can be called more that once on a given context, |
| 394 |
although any errors that occur will block further compilation. */ |
| 395 |
|
| 396 |
extern gcc_jit_result * |
| 397 |
gcc_jit_context_compile (gcc_jit_context *ctxt); |
| 398 |
|
| 399 |
/* Kinds of ahead-of-time compilation, for use with |
| 400 |
gcc_jit_context_compile_to_file. */ |
| 401 |
|
| 402 |
enum gcc_jit_output_kind |
| 403 |
{ |
| 404 |
/* Compile the context to an assembler file. */ |
| 405 |
GCC_JIT_OUTPUT_KIND_ASSEMBLER, |
| 406 |
|
| 407 |
/* Compile the context to an object file. */ |
| 408 |
GCC_JIT_OUTPUT_KIND_OBJECT_FILE, |
| 409 |
|
| 410 |
/* Compile the context to a dynamic library. */ |
| 411 |
GCC_JIT_OUTPUT_KIND_DYNAMIC_LIBRARY, |
| 412 |
|
| 413 |
/* Compile the context to an executable. */ |
| 414 |
GCC_JIT_OUTPUT_KIND_EXECUTABLE |
| 415 |
}; |
| 416 |
|
| 417 |
/* Compile the context to a file of the given kind. |
| 418 |
|
| 419 |
This can be called more that once on a given context, |
| 420 |
although any errors that occur will block further compilation. */ |
| 421 |
|
| 422 |
extern void |
| 423 |
gcc_jit_context_compile_to_file (gcc_jit_context *ctxt, |
| 424 |
enum gcc_jit_output_kind output_kind, |
| 425 |
const char *output_path); |
| 426 |
|
| 427 |
/* To help with debugging: dump a C-like representation to the given path, |
| 428 |
describing what's been set up on the context. |
| 429 |
|
| 430 |
If "update_locations" is true, then also set up gcc_jit_location |
| 431 |
information throughout the context, pointing at the dump file as if it |
| 432 |
were a source file. This may be of use in conjunction with |
| 433 |
GCC_JIT_BOOL_OPTION_DEBUGINFO to allow stepping through the code in a |
| 434 |
debugger. */ |
| 435 |
extern void |
| 436 |
gcc_jit_context_dump_to_file (gcc_jit_context *ctxt, |
| 437 |
const char *path, |
| 438 |
int update_locations); |
| 439 |
|
| 440 |
/* To help with debugging; enable ongoing logging of the context's |
| 441 |
activity to the given FILE *. |
| 442 |
|
| 443 |
The caller remains responsible for closing "logfile". |
| 444 |
|
| 445 |
Params "flags" and "verbosity" are reserved for future use, and |
| 446 |
must both be 0 for now. */ |
| 447 |
extern void |
| 448 |
gcc_jit_context_set_logfile (gcc_jit_context *ctxt, |
| 449 |
FILE *logfile, |
| 450 |
int flags, |
| 451 |
int verbosity); |
| 452 |
|
| 453 |
/* To be called after any API call, this gives the first error message |
| 454 |
that occurred on the context. |
| 455 |
|
| 456 |
The returned string is valid for the rest of the lifetime of the |
| 457 |
context. |
| 458 |
|
| 459 |
If no errors occurred, this will be NULL. */ |
| 460 |
extern const char * |
| 461 |
gcc_jit_context_get_first_error (gcc_jit_context *ctxt); |
| 462 |
|
| 463 |
/* To be called after any API call, this gives the last error message |
| 464 |
that occurred on the context. |
| 465 |
|
| 466 |
If no errors occurred, this will be NULL. |
| 467 |
|
| 468 |
If non-NULL, the returned string is only guaranteed to be valid until |
| 469 |
the next call to libgccjit relating to this context. */ |
| 470 |
extern const char * |
| 471 |
gcc_jit_context_get_last_error (gcc_jit_context *ctxt); |
| 472 |
|
| 473 |
/* Locate a given function within the built machine code. |
| 474 |
This will need to be cast to a function pointer of the |
| 475 |
correct type before it can be called. */ |
| 476 |
extern void * |
| 477 |
gcc_jit_result_get_code (gcc_jit_result *result, |
| 478 |
const char *funcname); |
| 479 |
|
| 480 |
/* Locate a given global within the built machine code. |
| 481 |
It must have been created using GCC_JIT_GLOBAL_EXPORTED. |
| 482 |
This is a ptr to the global, so e.g. for an int this is an int *. */ |
| 483 |
extern void * |
| 484 |
gcc_jit_result_get_global (gcc_jit_result *result, |
| 485 |
const char *name); |
| 486 |
|
| 487 |
/* Once we're done with the code, this unloads the built .so file. |
| 488 |
This cleans up the result; after calling this, it's no longer |
| 489 |
valid to use the result. */ |
| 490 |
extern void |
| 491 |
gcc_jit_result_release (gcc_jit_result *result); |
| 492 |
|
| 493 |
|
| 494 |
/********************************************************************** |
| 495 |
Functions for creating "contextual" objects. |
| 496 |
|
| 497 |
All objects created by these functions share the lifetime of the context |
| 498 |
they are created within, and are automatically cleaned up for you when |
| 499 |
you call gcc_jit_context_release on the context. |
| 500 |
|
| 501 |
Note that this means you can't use references to them after you've |
| 502 |
released their context. |
| 503 |
|
| 504 |
All (const char *) string arguments passed to these functions are |
| 505 |
copied, so you don't need to keep them around. |
| 506 |
|
| 507 |
You create code by adding a sequence of statements to blocks. |
| 508 |
**********************************************************************/ |
| 509 |
|
| 510 |
/********************************************************************** |
| 511 |
The base class of "contextual" object. |
| 512 |
**********************************************************************/ |
| 513 |
/* Which context is "obj" within? */ |
| 514 |
extern gcc_jit_context * |
| 515 |
gcc_jit_object_get_context (gcc_jit_object *obj); |
| 516 |
|
| 517 |
/* Get a human-readable description of this object. |
| 518 |
The string buffer is created the first time this is called on a given |
| 519 |
object, and persists until the object's context is released. */ |
| 520 |
extern const char * |
| 521 |
gcc_jit_object_get_debug_string (gcc_jit_object *obj); |
| 522 |
|
| 523 |
/********************************************************************** |
| 524 |
Debugging information. |
| 525 |
**********************************************************************/ |
| 526 |
|
| 527 |
/* Creating source code locations for use by the debugger. |
| 528 |
Line and column numbers are 1-based. */ |
| 529 |
extern gcc_jit_location * |
| 530 |
gcc_jit_context_new_location (gcc_jit_context *ctxt, |
| 531 |
const char *filename, |
| 532 |
int line, |
| 533 |
int column); |
| 534 |
|
| 535 |
/* Upcasting from location to object. */ |
| 536 |
extern gcc_jit_object * |
| 537 |
gcc_jit_location_as_object (gcc_jit_location *loc); |
| 538 |
|
| 539 |
|
| 540 |
/********************************************************************** |
| 541 |
Types. |
| 542 |
**********************************************************************/ |
| 543 |
|
| 544 |
/* Upcasting from type to object. */ |
| 545 |
extern gcc_jit_object * |
| 546 |
gcc_jit_type_as_object (gcc_jit_type *type); |
| 547 |
|
| 548 |
/* Access to specific types. */ |
| 549 |
enum gcc_jit_types |
| 550 |
{ |
| 551 |
/* C's "void" type. */ |
| 552 |
GCC_JIT_TYPE_VOID, |
| 553 |
|
| 554 |
/* "void *". */ |
| 555 |
GCC_JIT_TYPE_VOID_PTR, |
| 556 |
|
| 557 |
/* C++'s bool type; also C99's "_Bool" type, aka "bool" if using |
| 558 |
stdbool.h. */ |
| 559 |
GCC_JIT_TYPE_BOOL, |
| 560 |
|
| 561 |
/* Various integer types. */ |
| 562 |
|
| 563 |
/* C's "char" (of some signedness) and the variants where the |
| 564 |
signedness is specified. */ |
| 565 |
GCC_JIT_TYPE_CHAR, |
| 566 |
GCC_JIT_TYPE_SIGNED_CHAR, |
| 567 |
GCC_JIT_TYPE_UNSIGNED_CHAR, |
| 568 |
|
| 569 |
/* C's "short" and "unsigned short". */ |
| 570 |
GCC_JIT_TYPE_SHORT, /* signed */ |
| 571 |
GCC_JIT_TYPE_UNSIGNED_SHORT, |
| 572 |
|
| 573 |
/* C's "int" and "unsigned int". */ |
| 574 |
GCC_JIT_TYPE_INT, /* signed */ |
| 575 |
GCC_JIT_TYPE_UNSIGNED_INT, |
| 576 |
|
| 577 |
/* C's "long" and "unsigned long". */ |
| 578 |
GCC_JIT_TYPE_LONG, /* signed */ |
| 579 |
GCC_JIT_TYPE_UNSIGNED_LONG, |
| 580 |
|
| 581 |
/* C99's "long long" and "unsigned long long". */ |
| 582 |
GCC_JIT_TYPE_LONG_LONG, /* signed */ |
| 583 |
GCC_JIT_TYPE_UNSIGNED_LONG_LONG, |
| 584 |
|
| 585 |
/* Floating-point types */ |
| 586 |
|
| 587 |
GCC_JIT_TYPE_FLOAT, |
| 588 |
GCC_JIT_TYPE_DOUBLE, |
| 589 |
GCC_JIT_TYPE_LONG_DOUBLE, |
| 590 |
|
| 591 |
/* C type: (const char *). */ |
| 592 |
GCC_JIT_TYPE_CONST_CHAR_PTR, |
| 593 |
|
| 594 |
/* The C "size_t" type. */ |
| 595 |
GCC_JIT_TYPE_SIZE_T, |
| 596 |
|
| 597 |
/* C type: (FILE *) */ |
| 598 |
GCC_JIT_TYPE_FILE_PTR, |
| 599 |
|
| 600 |
/* Complex numbers. */ |
| 601 |
GCC_JIT_TYPE_COMPLEX_FLOAT, |
| 602 |
GCC_JIT_TYPE_COMPLEX_DOUBLE, |
| 603 |
GCC_JIT_TYPE_COMPLEX_LONG_DOUBLE, |
| 604 |
|
| 605 |
/* Sized integer types. */ |
| 606 |
GCC_JIT_TYPE_UINT8_T, |
| 607 |
GCC_JIT_TYPE_UINT16_T, |
| 608 |
GCC_JIT_TYPE_UINT32_T, |
| 609 |
GCC_JIT_TYPE_UINT64_T, |
| 610 |
GCC_JIT_TYPE_UINT128_T, |
| 611 |
GCC_JIT_TYPE_INT8_T, |
| 612 |
GCC_JIT_TYPE_INT16_T, |
| 613 |
GCC_JIT_TYPE_INT32_T, |
| 614 |
GCC_JIT_TYPE_INT64_T, |
| 615 |
GCC_JIT_TYPE_INT128_T, |
| 616 |
|
| 617 |
GCC_JIT_TYPE_BFLOAT16, |
| 618 |
}; |
| 619 |
|
| 620 |
extern gcc_jit_type * |
| 621 |
gcc_jit_context_get_type (gcc_jit_context *ctxt, |
| 622 |
enum gcc_jit_types type_); |
| 623 |
|
| 624 |
/* Get the integer type of the given size and signedness. */ |
| 625 |
extern gcc_jit_type * |
| 626 |
gcc_jit_context_get_int_type (gcc_jit_context *ctxt, |
| 627 |
int num_bytes, int is_signed); |
| 628 |
|
| 629 |
/* Constructing new types. */ |
| 630 |
|
| 631 |
/* Given type "T", get type "T*". */ |
| 632 |
extern gcc_jit_type * |
| 633 |
gcc_jit_type_get_pointer (gcc_jit_type *type); |
| 634 |
|
| 635 |
/* Given type "T", get type "const T". */ |
| 636 |
extern gcc_jit_type * |
| 637 |
gcc_jit_type_get_const (gcc_jit_type *type); |
| 638 |
|
| 639 |
/* Given type "T", get type "volatile T". */ |
| 640 |
extern gcc_jit_type * |
| 641 |
gcc_jit_type_get_volatile (gcc_jit_type *type); |
| 642 |
|
| 643 |
#define LIBGCCJIT_HAVE_gcc_jit_type_get_restrict |
| 644 |
|
| 645 |
/* Given type "T", get type "restrict T". |
| 646 |
This API entrypoint was added in LIBGCCJIT_ABI_25; you can test for its |
| 647 |
presence using |
| 648 |
#ifdef LIBGCCJIT_HAVE_gcc_jit_type_get_restrict */ |
| 649 |
extern gcc_jit_type * |
| 650 |
gcc_jit_type_get_restrict (gcc_jit_type *type); |
| 651 |
|
| 652 |
#define LIBGCCJIT_HAVE_SIZED_INTEGERS |
| 653 |
|
| 654 |
/* Given types LTYPE and RTYPE, return non-zero if they are compatible. |
| 655 |
This API entrypoint was added in LIBGCCJIT_ABI_20; you can test for its |
| 656 |
presence using |
| 657 |
#ifdef LIBGCCJIT_HAVE_SIZED_INTEGERS */ |
| 658 |
extern int |
| 659 |
gcc_jit_compatible_types (gcc_jit_type *ltype, |
| 660 |
gcc_jit_type *rtype); |
| 661 |
|
| 662 |
/* Given type "T", get its size. |
| 663 |
This API entrypoint was added in LIBGCCJIT_ABI_20; you can test for its |
| 664 |
presence using |
| 665 |
#ifdef LIBGCCJIT_HAVE_SIZED_INTEGERS */ |
| 666 |
extern ssize_t |
| 667 |
gcc_jit_type_get_size (gcc_jit_type *type); |
| 668 |
|
| 669 |
/* Given type "T", get type "T[N]" (for a constant N). */ |
| 670 |
extern gcc_jit_type * |
| 671 |
gcc_jit_context_new_array_type (gcc_jit_context *ctxt, |
| 672 |
gcc_jit_location *loc, |
| 673 |
gcc_jit_type *element_type, |
| 674 |
int num_elements); |
| 675 |
|
| 676 |
/* Struct-handling. */ |
| 677 |
|
| 678 |
/* Create a field, for use within a struct or union. */ |
| 679 |
extern gcc_jit_field * |
| 680 |
gcc_jit_context_new_field (gcc_jit_context *ctxt, |
| 681 |
gcc_jit_location *loc, |
| 682 |
gcc_jit_type *type, |
| 683 |
const char *name); |
| 684 |
|
| 685 |
#define LIBGCCJIT_HAVE_gcc_jit_context_new_bitfield |
| 686 |
|
| 687 |
/* Create a bit field, for use within a struct or union. |
| 688 |
|
| 689 |
This API entrypoint was added in LIBGCCJIT_ABI_12; you can test for its |
| 690 |
presence using |
| 691 |
#ifdef LIBGCCJIT_HAVE_gcc_jit_context_new_bitfield |
| 692 |
*/ |
| 693 |
extern gcc_jit_field * |
| 694 |
gcc_jit_context_new_bitfield (gcc_jit_context *ctxt, |
| 695 |
gcc_jit_location *loc, |
| 696 |
gcc_jit_type *type, |
| 697 |
int width, |
| 698 |
const char *name); |
| 699 |
|
| 700 |
/* Upcasting from field to object. */ |
| 701 |
extern gcc_jit_object * |
| 702 |
gcc_jit_field_as_object (gcc_jit_field *field); |
| 703 |
|
| 704 |
/* Create a struct type from an array of fields. */ |
| 705 |
extern gcc_jit_struct * |
| 706 |
gcc_jit_context_new_struct_type (gcc_jit_context *ctxt, |
| 707 |
gcc_jit_location *loc, |
| 708 |
const char *name, |
| 709 |
int num_fields, |
| 710 |
gcc_jit_field **fields); |
| 711 |
|
| 712 |
/* Create an opaque struct type. */ |
| 713 |
extern gcc_jit_struct * |
| 714 |
gcc_jit_context_new_opaque_struct (gcc_jit_context *ctxt, |
| 715 |
gcc_jit_location *loc, |
| 716 |
const char *name); |
| 717 |
|
| 718 |
/* Upcast a struct to a type. */ |
| 719 |
extern gcc_jit_type * |
| 720 |
gcc_jit_struct_as_type (gcc_jit_struct *struct_type); |
| 721 |
|
| 722 |
/* Populating the fields of a formerly-opaque struct type. |
| 723 |
This can only be called once on a given struct type. */ |
| 724 |
extern void |
| 725 |
gcc_jit_struct_set_fields (gcc_jit_struct *struct_type, |
| 726 |
gcc_jit_location *loc, |
| 727 |
int num_fields, |
| 728 |
gcc_jit_field **fields); |
| 729 |
|
| 730 |
/* Get a field by index. */ |
| 731 |
extern gcc_jit_field * |
| 732 |
gcc_jit_struct_get_field (gcc_jit_struct *struct_type, |
| 733 |
size_t index); |
| 734 |
|
| 735 |
/* Get the number of fields. */ |
| 736 |
extern size_t |
| 737 |
gcc_jit_struct_get_field_count (gcc_jit_struct *struct_type); |
| 738 |
|
| 739 |
/* Unions work similarly to structs. */ |
| 740 |
extern gcc_jit_type * |
| 741 |
gcc_jit_context_new_union_type (gcc_jit_context *ctxt, |
| 742 |
gcc_jit_location *loc, |
| 743 |
const char *name, |
| 744 |
int num_fields, |
| 745 |
gcc_jit_field **fields); |
| 746 |
|
| 747 |
/* Function pointers. */ |
| 748 |
|
| 749 |
extern gcc_jit_type * |
| 750 |
gcc_jit_context_new_function_ptr_type (gcc_jit_context *ctxt, |
| 751 |
gcc_jit_location *loc, |
| 752 |
gcc_jit_type *return_type, |
| 753 |
int num_params, |
| 754 |
gcc_jit_type **param_types, |
| 755 |
int is_variadic); |
| 756 |
|
| 757 |
/********************************************************************** |
| 758 |
Constructing functions. |
| 759 |
**********************************************************************/ |
| 760 |
/* Create a function param. */ |
| 761 |
extern gcc_jit_param * |
| 762 |
gcc_jit_context_new_param (gcc_jit_context *ctxt, |
| 763 |
gcc_jit_location *loc, |
| 764 |
gcc_jit_type *type, |
| 765 |
const char *name); |
| 766 |
|
| 767 |
/* Upcasting from param to object. */ |
| 768 |
extern gcc_jit_object * |
| 769 |
gcc_jit_param_as_object (gcc_jit_param *param); |
| 770 |
|
| 771 |
/* Upcasting from param to lvalue. */ |
| 772 |
extern gcc_jit_lvalue * |
| 773 |
gcc_jit_param_as_lvalue (gcc_jit_param *param); |
| 774 |
|
| 775 |
/* Upcasting from param to rvalue. */ |
| 776 |
extern gcc_jit_rvalue * |
| 777 |
gcc_jit_param_as_rvalue (gcc_jit_param *param); |
| 778 |
|
| 779 |
/* Kinds of function. */ |
| 780 |
enum gcc_jit_function_kind |
| 781 |
{ |
| 782 |
/* Function is defined by the client code and visible |
| 783 |
by name outside of the JIT. */ |
| 784 |
GCC_JIT_FUNCTION_EXPORTED, |
| 785 |
|
| 786 |
/* Function is defined by the client code, but is invisible |
| 787 |
outside of the JIT. Analogous to a "static" function. */ |
| 788 |
GCC_JIT_FUNCTION_INTERNAL, |
| 789 |
|
| 790 |
/* Function is not defined by the client code; we're merely |
| 791 |
referring to it. Analogous to using an "extern" function from a |
| 792 |
header file. */ |
| 793 |
GCC_JIT_FUNCTION_IMPORTED, |
| 794 |
|
| 795 |
/* Function is only ever inlined into other functions, and is |
| 796 |
invisible outside of the JIT. |
| 797 |
|
| 798 |
Analogous to prefixing with "inline" and adding |
| 799 |
__attribute__((always_inline)). |
| 800 |
|
| 801 |
Inlining will only occur when the optimization level is |
| 802 |
above 0; when optimization is off, this is essentially the |
| 803 |
same as GCC_JIT_FUNCTION_INTERNAL. */ |
| 804 |
GCC_JIT_FUNCTION_ALWAYS_INLINE |
| 805 |
}; |
| 806 |
|
| 807 |
/* Thread local storage model. */ |
| 808 |
enum gcc_jit_tls_model |
| 809 |
{ |
| 810 |
GCC_JIT_TLS_MODEL_NONE, |
| 811 |
GCC_JIT_TLS_MODEL_GLOBAL_DYNAMIC, |
| 812 |
GCC_JIT_TLS_MODEL_LOCAL_DYNAMIC, |
| 813 |
GCC_JIT_TLS_MODEL_INITIAL_EXEC, |
| 814 |
GCC_JIT_TLS_MODEL_LOCAL_EXEC, |
| 815 |
}; |
| 816 |
|
| 817 |
/* Create a function. */ |
| 818 |
extern gcc_jit_function * |
| 819 |
gcc_jit_context_new_function (gcc_jit_context *ctxt, |
| 820 |
gcc_jit_location *loc, |
| 821 |
enum gcc_jit_function_kind kind, |
| 822 |
gcc_jit_type *return_type, |
| 823 |
const char *name, |
| 824 |
int num_params, |
| 825 |
gcc_jit_param **params, |
| 826 |
int is_variadic); |
| 827 |
|
| 828 |
/* Create a reference to a builtin function (sometimes called |
| 829 |
intrinsic functions). */ |
| 830 |
extern gcc_jit_function * |
| 831 |
gcc_jit_context_get_builtin_function (gcc_jit_context *ctxt, |
| 832 |
const char *name); |
| 833 |
|
| 834 |
/* Upcasting from function to object. */ |
| 835 |
extern gcc_jit_object * |
| 836 |
gcc_jit_function_as_object (gcc_jit_function *func); |
| 837 |
|
| 838 |
/* Get a specific param of a function by index. */ |
| 839 |
extern gcc_jit_param * |
| 840 |
gcc_jit_function_get_param (gcc_jit_function *func, int index); |
| 841 |
|
| 842 |
/* Emit the function in graphviz format. */ |
| 843 |
extern void |
| 844 |
gcc_jit_function_dump_to_dot (gcc_jit_function *func, |
| 845 |
const char *path); |
| 846 |
|
| 847 |
/* Create a block. |
| 848 |
|
| 849 |
The name can be NULL, or you can give it a meaningful name, which |
| 850 |
may show up in dumps of the internal representation, and in error |
| 851 |
messages. */ |
| 852 |
extern gcc_jit_block * |
| 853 |
gcc_jit_function_new_block (gcc_jit_function *func, |
| 854 |
const char *name); |
| 855 |
|
| 856 |
/* Upcasting from block to object. */ |
| 857 |
extern gcc_jit_object * |
| 858 |
gcc_jit_block_as_object (gcc_jit_block *block); |
| 859 |
|
| 860 |
/* Which function is this block within? */ |
| 861 |
extern gcc_jit_function * |
| 862 |
gcc_jit_block_get_function (gcc_jit_block *block); |
| 863 |
|
| 864 |
/********************************************************************** |
| 865 |
lvalues, rvalues and expressions. |
| 866 |
**********************************************************************/ |
| 867 |
enum gcc_jit_global_kind |
| 868 |
{ |
| 869 |
/* Global is defined by the client code and visible |
| 870 |
by name outside of this JIT context via gcc_jit_result_get_global. */ |
| 871 |
GCC_JIT_GLOBAL_EXPORTED, |
| 872 |
|
| 873 |
/* Global is defined by the client code, but is invisible |
| 874 |
outside of this JIT context. Analogous to a "static" global. */ |
| 875 |
GCC_JIT_GLOBAL_INTERNAL, |
| 876 |
|
| 877 |
/* Global is not defined by the client code; we're merely |
| 878 |
referring to it. Analogous to using an "extern" global from a |
| 879 |
header file. */ |
| 880 |
GCC_JIT_GLOBAL_IMPORTED |
| 881 |
}; |
| 882 |
|
| 883 |
extern gcc_jit_lvalue * |
| 884 |
gcc_jit_context_new_global (gcc_jit_context *ctxt, |
| 885 |
gcc_jit_location *loc, |
| 886 |
enum gcc_jit_global_kind kind, |
| 887 |
gcc_jit_type *type, |
| 888 |
const char *name); |
| 889 |
|
| 890 |
#define LIBGCCJIT_HAVE_CTORS |
| 891 |
|
| 892 |
/* Create a constructor for a struct as an rvalue. |
| 893 |
|
| 894 |
Returns NULL on error. The two parameter arrays are copied and |
| 895 |
do not have to outlive the context. |
| 896 |
|
| 897 |
`type` specifies what the constructor will build and has to be |
| 898 |
a struct. |
| 899 |
|
| 900 |
`num_values` specifies the number of elements in `values`. |
| 901 |
|
| 902 |
`fields` need to have the same length as `values`, or be NULL. |
| 903 |
|
| 904 |
If `fields` is null, the values are applied in definition order. |
| 905 |
|
| 906 |
Otherwise, each field in `fields` specifies which field in the struct to |
| 907 |
set to the corresponding value in `values`. `fields` and `values` |
| 908 |
are paired by index. |
| 909 |
|
| 910 |
Each value has to have the same unqualified type as the field |
| 911 |
it is applied to. |
| 912 |
|
| 913 |
A NULL value element in `values` is a shorthand for zero initialization |
| 914 |
of the corresponding field. |
| 915 |
|
| 916 |
The fields in `fields` have to be in definition order, but there |
| 917 |
can be gaps. Any field in the struct that is not specified in |
| 918 |
`fields` will be zeroed. |
| 919 |
|
| 920 |
The fields in `fields` need to be the same objects that were used |
| 921 |
to create the struct. |
| 922 |
|
| 923 |
If `num_values` is 0, the array parameters will be |
| 924 |
ignored and zero initialization will be used. |
| 925 |
|
| 926 |
The constructor rvalue can be used for assignment to locals. |
| 927 |
It can be used to initialize global variables with |
| 928 |
gcc_jit_global_set_initializer_rvalue. It can also be used as a |
| 929 |
temporary value for function calls and return values. |
| 930 |
|
| 931 |
The constructor can contain nested constructors. |
| 932 |
|
| 933 |
This entrypoint was added in LIBGCCJIT_ABI_19; you can test for its |
| 934 |
presence using: |
| 935 |
#ifdef LIBGCCJIT_HAVE_CTORS |
| 936 |
*/ |
| 937 |
|
| 938 |
extern gcc_jit_rvalue * |
| 939 |
gcc_jit_context_new_struct_constructor (gcc_jit_context *ctxt, |
| 940 |
gcc_jit_location *loc, |
| 941 |
gcc_jit_type *type, |
| 942 |
size_t num_values, |
| 943 |
gcc_jit_field **fields, |
| 944 |
gcc_jit_rvalue **values); |
| 945 |
|
| 946 |
/* Create a constructor for a union as an rvalue. |
| 947 |
|
| 948 |
Returns NULL on error. |
| 949 |
|
| 950 |
`type` specifies what the constructor will build and has to be |
| 951 |
an union. |
| 952 |
|
| 953 |
`field` specifies which field to set. If it is NULL, the first |
| 954 |
field in the union will be set. `field` need to be the same |
| 955 |
object that were used to create the union. |
| 956 |
|
| 957 |
`value` specifies what value to set the corresponding field to. |
| 958 |
If `value` is NULL, zero initialization will be used. |
| 959 |
|
| 960 |
Each value has to have the same unqualified type as the field |
| 961 |
it is applied to. |
| 962 |
|
| 963 |
`field` need to be the same objects that were used |
| 964 |
to create the union. |
| 965 |
|
| 966 |
The constructor rvalue can be used for assignment to locals. |
| 967 |
It can be used to initialize global variables with |
| 968 |
gcc_jit_global_set_initializer_rvalue. It can also be used as a |
| 969 |
temporary value for function calls and return values. |
| 970 |
|
| 971 |
The constructor can contain nested constructors. |
| 972 |
|
| 973 |
This entrypoint was added in LIBGCCJIT_ABI_19; you can test for its |
| 974 |
presence using: |
| 975 |
#ifdef LIBGCCJIT_HAVE_CTORS |
| 976 |
*/ |
| 977 |
|
| 978 |
extern gcc_jit_rvalue * |
| 979 |
gcc_jit_context_new_union_constructor (gcc_jit_context *ctxt, |
| 980 |
gcc_jit_location *loc, |
| 981 |
gcc_jit_type *type, |
| 982 |
gcc_jit_field *field, |
| 983 |
gcc_jit_rvalue *value); |
| 984 |
|
| 985 |
/* Create a constructor for an array as an rvalue. |
| 986 |
|
| 987 |
Returns NULL on error. `values` are copied and |
| 988 |
do not have to outlive the context. |
| 989 |
|
| 990 |
`type` specifies what the constructor will build and has to be |
| 991 |
an array. |
| 992 |
|
| 993 |
`num_values` specifies the number of elements in `values` and |
| 994 |
it can't have more elements than the array type. |
| 995 |
|
| 996 |
Each value in `values` sets the corresponding value in the array. |
| 997 |
If the array type itself has more elements than `values`, the |
| 998 |
left-over elements will be zeroed. |
| 999 |
|
| 1000 |
Each value in `values` need to be the same unqualified type as the |
| 1001 |
array type's element type. |
| 1002 |
|
| 1003 |
If `num_values` is 0, the `values` parameter will be |
| 1004 |
ignored and zero initialization will be used. |
| 1005 |
|
| 1006 |
Note that a string literal rvalue can't be used to construct a char |
| 1007 |
array. It needs one rvalue for each char. |
| 1008 |
|
| 1009 |
This entrypoint was added in LIBGCCJIT_ABI_19; you can test for its |
| 1010 |
presence using: |
| 1011 |
#ifdef LIBGCCJIT_HAVE_CTORS |
| 1012 |
*/ |
| 1013 |
|
| 1014 |
extern gcc_jit_rvalue * |
| 1015 |
gcc_jit_context_new_array_constructor (gcc_jit_context *ctxt, |
| 1016 |
gcc_jit_location *loc, |
| 1017 |
gcc_jit_type *type, |
| 1018 |
size_t num_values, |
| 1019 |
gcc_jit_rvalue **values); |
| 1020 |
|
| 1021 |
/* Set the initial value of a global of any type with an rvalue. |
| 1022 |
|
| 1023 |
The rvalue needs to be a constant expression, e.g. no function calls. |
| 1024 |
|
| 1025 |
The global can't have the 'kind' GCC_JIT_GLOBAL_IMPORTED. |
| 1026 |
|
| 1027 |
Use together with gcc_jit_context_new_constructor () to |
| 1028 |
initialize structs, unions and arrays. |
| 1029 |
|
| 1030 |
On success, returns the 'global' parameter unchanged. Otherwise, NULL. |
| 1031 |
|
| 1032 |
'values' is copied and does not have to outlive the context. |
| 1033 |
|
| 1034 |
This entrypoint was added in LIBGCCJIT_ABI_19; you can test for its |
| 1035 |
presence using: |
| 1036 |
#ifdef LIBGCCJIT_HAVE_CTORS |
| 1037 |
*/ |
| 1038 |
|
| 1039 |
extern gcc_jit_lvalue * |
| 1040 |
gcc_jit_global_set_initializer_rvalue (gcc_jit_lvalue *global, |
| 1041 |
gcc_jit_rvalue *init_value); |
| 1042 |
|
| 1043 |
#define LIBGCCJIT_HAVE_gcc_jit_context_get_target_builtin_function |
| 1044 |
|
| 1045 |
/* Create a reference to a machine-specific builtin function (sometimes called |
| 1046 |
intrinsic functions). |
| 1047 |
|
| 1048 |
This API entrypoint was added in LIBGCCJIT_ABI_32; you can test for its |
| 1049 |
presence using |
| 1050 |
#ifdef LIBGCCJIT_HAVE_gcc_jit_context_get_target_builtin_function |
| 1051 |
*/ |
| 1052 |
extern gcc_jit_function * |
| 1053 |
gcc_jit_context_get_target_builtin_function (gcc_jit_context *ctxt, |
| 1054 |
const char *name); |
| 1055 |
|
| 1056 |
#define LIBGCCJIT_HAVE_gcc_jit_global_set_initializer |
| 1057 |
|
| 1058 |
/* Set an initial value for a global, which must be an array of |
| 1059 |
integral type. Return the global itself. |
| 1060 |
|
| 1061 |
This API entrypoint was added in LIBGCCJIT_ABI_14; you can test for its |
| 1062 |
presence using |
| 1063 |
#ifdef LIBGCCJIT_HAVE_gcc_jit_global_set_initializer |
| 1064 |
*/ |
| 1065 |
|
| 1066 |
extern gcc_jit_lvalue * |
| 1067 |
gcc_jit_global_set_initializer (gcc_jit_lvalue *global, |
| 1068 |
const void *blob, |
| 1069 |
size_t num_bytes); |
| 1070 |
|
| 1071 |
extern void |
| 1072 |
gcc_jit_global_set_readonly (gcc_jit_lvalue *global); |
| 1073 |
|
| 1074 |
#define LIBGCCJIT_HAVE_gcc_jit_global_set_readonly |
| 1075 |
|
| 1076 |
/* Upcasting. */ |
| 1077 |
extern gcc_jit_object * |
| 1078 |
gcc_jit_lvalue_as_object (gcc_jit_lvalue *lvalue); |
| 1079 |
|
| 1080 |
extern gcc_jit_rvalue * |
| 1081 |
gcc_jit_lvalue_as_rvalue (gcc_jit_lvalue *lvalue); |
| 1082 |
|
| 1083 |
extern gcc_jit_object * |
| 1084 |
gcc_jit_rvalue_as_object (gcc_jit_rvalue *rvalue); |
| 1085 |
|
| 1086 |
extern gcc_jit_type * |
| 1087 |
gcc_jit_rvalue_get_type (gcc_jit_rvalue *rvalue); |
| 1088 |
|
| 1089 |
/* Integer constants. */ |
| 1090 |
extern gcc_jit_rvalue * |
| 1091 |
gcc_jit_context_new_rvalue_from_int (gcc_jit_context *ctxt, |
| 1092 |
gcc_jit_type *numeric_type, |
| 1093 |
int value); |
| 1094 |
|
| 1095 |
extern gcc_jit_rvalue * |
| 1096 |
gcc_jit_context_new_rvalue_from_long (gcc_jit_context *ctxt, |
| 1097 |
gcc_jit_type *numeric_type, |
| 1098 |
long value); |
| 1099 |
|
| 1100 |
extern gcc_jit_rvalue * |
| 1101 |
gcc_jit_context_zero (gcc_jit_context *ctxt, |
| 1102 |
gcc_jit_type *numeric_type); |
| 1103 |
|
| 1104 |
extern gcc_jit_rvalue * |
| 1105 |
gcc_jit_context_one (gcc_jit_context *ctxt, |
| 1106 |
gcc_jit_type *numeric_type); |
| 1107 |
|
| 1108 |
/* Floating-point constants. */ |
| 1109 |
extern gcc_jit_rvalue * |
| 1110 |
gcc_jit_context_new_rvalue_from_double (gcc_jit_context *ctxt, |
| 1111 |
gcc_jit_type *numeric_type, |
| 1112 |
double value); |
| 1113 |
|
| 1114 |
/* Pointers. */ |
| 1115 |
extern gcc_jit_rvalue * |
| 1116 |
gcc_jit_context_new_rvalue_from_ptr (gcc_jit_context *ctxt, |
| 1117 |
gcc_jit_type *pointer_type, |
| 1118 |
void *value); |
| 1119 |
|
| 1120 |
extern gcc_jit_rvalue * |
| 1121 |
gcc_jit_context_null (gcc_jit_context *ctxt, |
| 1122 |
gcc_jit_type *pointer_type); |
| 1123 |
|
| 1124 |
#define LIBGCCJIT_HAVE_gcc_jit_context_new_sizeof |
| 1125 |
|
| 1126 |
/* Generates an rvalue that is equal to the size of type. |
| 1127 |
|
| 1128 |
This API entrypoint was added in LIBGCCJIT_ABI_27; you can test for its |
| 1129 |
presence using |
| 1130 |
#ifdef LIBGCCJIT_HAVE_gcc_jit_context_new_sizeof */ |
| 1131 |
|
| 1132 |
extern gcc_jit_rvalue * |
| 1133 |
gcc_jit_context_new_sizeof (gcc_jit_context *ctxt, |
| 1134 |
gcc_jit_type *type); |
| 1135 |
|
| 1136 |
#define LIBGCCJIT_HAVE_gcc_jit_context_new_alignof |
| 1137 |
|
| 1138 |
/* Generates an rvalue that is equal to the alignment of type. |
| 1139 |
|
| 1140 |
This API entrypoint was added in LIBGCCJIT_ABI_38; you can test for its |
| 1141 |
presence using |
| 1142 |
#ifdef LIBGCCJIT_HAVE_gcc_jit_context_new_alignof */ |
| 1143 |
|
| 1144 |
extern gcc_jit_rvalue * |
| 1145 |
gcc_jit_context_new_alignof (gcc_jit_context *ctxt, |
| 1146 |
gcc_jit_type *type); |
| 1147 |
|
| 1148 |
|
| 1149 |
/* String literals. */ |
| 1150 |
extern gcc_jit_rvalue * |
| 1151 |
gcc_jit_context_new_string_literal (gcc_jit_context *ctxt, |
| 1152 |
const char *value); |
| 1153 |
|
| 1154 |
enum gcc_jit_unary_op |
| 1155 |
{ |
| 1156 |
/* Negate an arithmetic value; analogous to: |
| 1157 |
-(EXPR) |
| 1158 |
in C. */ |
| 1159 |
GCC_JIT_UNARY_OP_MINUS, |
| 1160 |
|
| 1161 |
/* Bitwise negation of an integer value (one's complement); analogous |
| 1162 |
to: |
| 1163 |
~(EXPR) |
| 1164 |
in C. */ |
| 1165 |
GCC_JIT_UNARY_OP_BITWISE_NEGATE, |
| 1166 |
|
| 1167 |
/* Logical negation of an arithmetic or pointer value; analogous to: |
| 1168 |
!(EXPR) |
| 1169 |
in C. */ |
| 1170 |
GCC_JIT_UNARY_OP_LOGICAL_NEGATE, |
| 1171 |
|
| 1172 |
/* Absolute value of an arithmetic expression; analogous to: |
| 1173 |
abs (EXPR) |
| 1174 |
in C. */ |
| 1175 |
GCC_JIT_UNARY_OP_ABS |
| 1176 |
|
| 1177 |
}; |
| 1178 |
|
| 1179 |
extern gcc_jit_rvalue * |
| 1180 |
gcc_jit_context_new_unary_op (gcc_jit_context *ctxt, |
| 1181 |
gcc_jit_location *loc, |
| 1182 |
enum gcc_jit_unary_op op, |
| 1183 |
gcc_jit_type *result_type, |
| 1184 |
gcc_jit_rvalue *rvalue); |
| 1185 |
|
| 1186 |
enum gcc_jit_binary_op |
| 1187 |
{ |
| 1188 |
/* Addition of arithmetic values; analogous to: |
| 1189 |
(EXPR_A) + (EXPR_B) |
| 1190 |
in C. |
| 1191 |
For pointer addition, use gcc_jit_context_new_array_access. */ |
| 1192 |
GCC_JIT_BINARY_OP_PLUS, |
| 1193 |
|
| 1194 |
/* Subtraction of arithmetic values; analogous to: |
| 1195 |
(EXPR_A) - (EXPR_B) |
| 1196 |
in C. */ |
| 1197 |
GCC_JIT_BINARY_OP_MINUS, |
| 1198 |
|
| 1199 |
/* Multiplication of a pair of arithmetic values; analogous to: |
| 1200 |
(EXPR_A) * (EXPR_B) |
| 1201 |
in C. */ |
| 1202 |
GCC_JIT_BINARY_OP_MULT, |
| 1203 |
|
| 1204 |
/* Quotient of division of arithmetic values; analogous to: |
| 1205 |
(EXPR_A) / (EXPR_B) |
| 1206 |
in C. |
| 1207 |
The result type affects the kind of division: if the result type is |
| 1208 |
integer-based, then the result is truncated towards zero, whereas |
| 1209 |
a floating-point result type indicates floating-point division. */ |
| 1210 |
GCC_JIT_BINARY_OP_DIVIDE, |
| 1211 |
|
| 1212 |
/* Remainder of division of arithmetic values; analogous to: |
| 1213 |
(EXPR_A) % (EXPR_B) |
| 1214 |
in C. */ |
| 1215 |
GCC_JIT_BINARY_OP_MODULO, |
| 1216 |
|
| 1217 |
/* Bitwise AND; analogous to: |
| 1218 |
(EXPR_A) & (EXPR_B) |
| 1219 |
in C. */ |
| 1220 |
GCC_JIT_BINARY_OP_BITWISE_AND, |
| 1221 |
|
| 1222 |
/* Bitwise exclusive OR; analogous to: |
| 1223 |
(EXPR_A) ^ (EXPR_B) |
| 1224 |
in C. */ |
| 1225 |
GCC_JIT_BINARY_OP_BITWISE_XOR, |
| 1226 |
|
| 1227 |
/* Bitwise inclusive OR; analogous to: |
| 1228 |
(EXPR_A) | (EXPR_B) |
| 1229 |
in C. */ |
| 1230 |
GCC_JIT_BINARY_OP_BITWISE_OR, |
| 1231 |
|
| 1232 |
/* Logical AND; analogous to: |
| 1233 |
(EXPR_A) && (EXPR_B) |
| 1234 |
in C. */ |
| 1235 |
GCC_JIT_BINARY_OP_LOGICAL_AND, |
| 1236 |
|
| 1237 |
/* Logical OR; analogous to: |
| 1238 |
(EXPR_A) || (EXPR_B) |
| 1239 |
in C. */ |
| 1240 |
GCC_JIT_BINARY_OP_LOGICAL_OR, |
| 1241 |
|
| 1242 |
/* Left shift; analogous to: |
| 1243 |
(EXPR_A) << (EXPR_B) |
| 1244 |
in C. */ |
| 1245 |
GCC_JIT_BINARY_OP_LSHIFT, |
| 1246 |
|
| 1247 |
/* Right shift; analogous to: |
| 1248 |
(EXPR_A) >> (EXPR_B) |
| 1249 |
in C. */ |
| 1250 |
GCC_JIT_BINARY_OP_RSHIFT |
| 1251 |
}; |
| 1252 |
|
| 1253 |
extern gcc_jit_rvalue * |
| 1254 |
gcc_jit_context_new_binary_op (gcc_jit_context *ctxt, |
| 1255 |
gcc_jit_location *loc, |
| 1256 |
enum gcc_jit_binary_op op, |
| 1257 |
gcc_jit_type *result_type, |
| 1258 |
gcc_jit_rvalue *a, gcc_jit_rvalue *b); |
| 1259 |
|
| 1260 |
/* (Comparisons are treated as separate from "binary_op" to save |
| 1261 |
you having to specify the result_type). */ |
| 1262 |
|
| 1263 |
enum gcc_jit_comparison |
| 1264 |
{ |
| 1265 |
/* (EXPR_A) == (EXPR_B). */ |
| 1266 |
GCC_JIT_COMPARISON_EQ, |
| 1267 |
|
| 1268 |
/* (EXPR_A) != (EXPR_B). */ |
| 1269 |
GCC_JIT_COMPARISON_NE, |
| 1270 |
|
| 1271 |
/* (EXPR_A) < (EXPR_B). */ |
| 1272 |
GCC_JIT_COMPARISON_LT, |
| 1273 |
|
| 1274 |
/* (EXPR_A) <=(EXPR_B). */ |
| 1275 |
GCC_JIT_COMPARISON_LE, |
| 1276 |
|
| 1277 |
/* (EXPR_A) > (EXPR_B). */ |
| 1278 |
GCC_JIT_COMPARISON_GT, |
| 1279 |
|
| 1280 |
/* (EXPR_A) >= (EXPR_B). */ |
| 1281 |
GCC_JIT_COMPARISON_GE |
| 1282 |
}; |
| 1283 |
|
| 1284 |
extern gcc_jit_rvalue * |
| 1285 |
gcc_jit_context_new_comparison (gcc_jit_context *ctxt, |
| 1286 |
gcc_jit_location *loc, |
| 1287 |
enum gcc_jit_comparison op, |
| 1288 |
gcc_jit_rvalue *a, gcc_jit_rvalue *b); |
| 1289 |
|
| 1290 |
/* Function calls. */ |
| 1291 |
|
| 1292 |
/* Call of a specific function. */ |
| 1293 |
extern gcc_jit_rvalue * |
| 1294 |
gcc_jit_context_new_call (gcc_jit_context *ctxt, |
| 1295 |
gcc_jit_location *loc, |
| 1296 |
gcc_jit_function *func, |
| 1297 |
int numargs , gcc_jit_rvalue **args); |
| 1298 |
|
| 1299 |
/* Call through a function pointer. */ |
| 1300 |
extern gcc_jit_rvalue * |
| 1301 |
gcc_jit_context_new_call_through_ptr (gcc_jit_context *ctxt, |
| 1302 |
gcc_jit_location *loc, |
| 1303 |
gcc_jit_rvalue *fn_ptr, |
| 1304 |
int numargs, gcc_jit_rvalue **args); |
| 1305 |
|
| 1306 |
/* Type-coercion. |
| 1307 |
|
| 1308 |
Currently only a limited set of conversions are possible: |
| 1309 |
int <-> float |
| 1310 |
int <-> bool */ |
| 1311 |
extern gcc_jit_rvalue * |
| 1312 |
gcc_jit_context_new_cast (gcc_jit_context *ctxt, |
| 1313 |
gcc_jit_location *loc, |
| 1314 |
gcc_jit_rvalue *rvalue, |
| 1315 |
gcc_jit_type *type); |
| 1316 |
|
| 1317 |
#define LIBGCCJIT_HAVE_gcc_jit_context_new_bitcast |
| 1318 |
|
| 1319 |
/* Reinterpret a value as another type. |
| 1320 |
|
| 1321 |
The types must be of the same size. |
| 1322 |
|
| 1323 |
This API entrypoint was added in LIBGCCJIT_ABI_21; you can test for its |
| 1324 |
presence using |
| 1325 |
#ifdef LIBGCCJIT_HAVE_gcc_jit_context_new_bitcast */ |
| 1326 |
extern gcc_jit_rvalue * |
| 1327 |
gcc_jit_context_new_bitcast (gcc_jit_context *ctxt, |
| 1328 |
gcc_jit_location *loc, |
| 1329 |
gcc_jit_rvalue *rvalue, |
| 1330 |
gcc_jit_type *type); |
| 1331 |
|
| 1332 |
#define LIBGCCJIT_HAVE_ALIGNMENT |
| 1333 |
|
| 1334 |
/* Set the alignment of a variable. |
| 1335 |
|
| 1336 |
This API entrypoint was added in LIBGCCJIT_ABI_24; you can test for its |
| 1337 |
presence using |
| 1338 |
#ifdef LIBGCCJIT_HAVE_ALIGNMENT */ |
| 1339 |
extern void |
| 1340 |
gcc_jit_lvalue_set_alignment (gcc_jit_lvalue *lvalue, |
| 1341 |
unsigned bytes); |
| 1342 |
|
| 1343 |
/* Get the alignment of a variable. |
| 1344 |
|
| 1345 |
This API entrypoint was added in LIBGCCJIT_ABI_24; you can test for its |
| 1346 |
presence using |
| 1347 |
#ifdef LIBGCCJIT_HAVE_ALIGNMENT */ |
| 1348 |
extern unsigned |
| 1349 |
gcc_jit_lvalue_get_alignment (gcc_jit_lvalue *lvalue); |
| 1350 |
|
| 1351 |
extern gcc_jit_lvalue * |
| 1352 |
gcc_jit_context_new_array_access (gcc_jit_context *ctxt, |
| 1353 |
gcc_jit_location *loc, |
| 1354 |
gcc_jit_rvalue *ptr, |
| 1355 |
gcc_jit_rvalue *index); |
| 1356 |
|
| 1357 |
#define LIBGCCJIT_HAVE_gcc_jit_context_convert_vector |
| 1358 |
|
| 1359 |
/* Given a vector rvalue, cast it to the type ``type``, doing an element-wise |
| 1360 |
conversion. */ |
| 1361 |
extern gcc_jit_rvalue * |
| 1362 |
gcc_jit_context_convert_vector (gcc_jit_context *ctxt, |
| 1363 |
gcc_jit_location *loc, |
| 1364 |
gcc_jit_rvalue *vector, |
| 1365 |
gcc_jit_type *type); |
| 1366 |
|
| 1367 |
/* Build a permutation vector rvalue from an 3 arrays of elements. |
| 1368 |
|
| 1369 |
"vec_type" should be a vector type, created using gcc_jit_type_get_vector. |
| 1370 |
|
| 1371 |
This API entrypoint was added in LIBGCCJIT_ABI_31; you can test for its |
| 1372 |
presence using |
| 1373 |
#ifdef LIBGCCJIT_HAVE_VECTOR_OPERATIONS |
| 1374 |
*/ |
| 1375 |
extern gcc_jit_rvalue * |
| 1376 |
gcc_jit_context_new_rvalue_vector_perm (gcc_jit_context *ctxt, |
| 1377 |
gcc_jit_location *loc, |
| 1378 |
gcc_jit_rvalue *elements1, |
| 1379 |
gcc_jit_rvalue *elements2, |
| 1380 |
gcc_jit_rvalue *mask); |
| 1381 |
|
| 1382 |
#define LIBGCCJIT_HAVE_VECTOR_OPERATIONS |
| 1383 |
|
| 1384 |
/* Get the element at INDEX in VECTOR. |
| 1385 |
|
| 1386 |
This API entrypoint was added in LIBGCCJIT_ABI_31; you can test for its |
| 1387 |
presence using |
| 1388 |
#ifdef LIBGCCJIT_HAVE_VECTOR_OPERATIONS |
| 1389 |
*/ |
| 1390 |
extern gcc_jit_lvalue * |
| 1391 |
gcc_jit_context_new_vector_access (gcc_jit_context *ctxt, |
| 1392 |
gcc_jit_location *loc, |
| 1393 |
gcc_jit_rvalue *vector, |
| 1394 |
gcc_jit_rvalue *index); |
| 1395 |
|
| 1396 |
/* Field access is provided separately for both lvalues and rvalues. */ |
| 1397 |
|
| 1398 |
/* Accessing a field of an lvalue of struct type, analogous to: |
| 1399 |
(EXPR).field = ...; |
| 1400 |
in C. */ |
| 1401 |
extern gcc_jit_lvalue * |
| 1402 |
gcc_jit_lvalue_access_field (gcc_jit_lvalue *struct_or_union, |
| 1403 |
gcc_jit_location *loc, |
| 1404 |
gcc_jit_field *field); |
| 1405 |
|
| 1406 |
/* Accessing a field of an rvalue of struct type, analogous to: |
| 1407 |
(EXPR).field |
| 1408 |
in C. */ |
| 1409 |
extern gcc_jit_rvalue * |
| 1410 |
gcc_jit_rvalue_access_field (gcc_jit_rvalue *struct_or_union, |
| 1411 |
gcc_jit_location *loc, |
| 1412 |
gcc_jit_field *field); |
| 1413 |
|
| 1414 |
/* Accessing a field of an rvalue of pointer type, analogous to: |
| 1415 |
(EXPR)->field |
| 1416 |
in C, itself equivalent to (*EXPR).FIELD */ |
| 1417 |
extern gcc_jit_lvalue * |
| 1418 |
gcc_jit_rvalue_dereference_field (gcc_jit_rvalue *ptr, |
| 1419 |
gcc_jit_location *loc, |
| 1420 |
gcc_jit_field *field); |
| 1421 |
|
| 1422 |
/* Dereferencing a pointer; analogous to: |
| 1423 |
*(EXPR) |
| 1424 |
*/ |
| 1425 |
extern gcc_jit_lvalue * |
| 1426 |
gcc_jit_rvalue_dereference (gcc_jit_rvalue *rvalue, |
| 1427 |
gcc_jit_location *loc); |
| 1428 |
|
| 1429 |
/* Taking the address of an lvalue; analogous to: |
| 1430 |
&(EXPR) |
| 1431 |
in C. */ |
| 1432 |
extern gcc_jit_rvalue * |
| 1433 |
gcc_jit_lvalue_get_address (gcc_jit_lvalue *lvalue, |
| 1434 |
gcc_jit_location *loc); |
| 1435 |
|
| 1436 |
#define LIBGCCJIT_HAVE_gcc_jit_lvalue_set_tls_model |
| 1437 |
|
| 1438 |
/* Set the thread-local storage model of a global variable |
| 1439 |
|
| 1440 |
This API entrypoint was added in LIBGCCJIT_ABI_17; you can test for its |
| 1441 |
presence using |
| 1442 |
#ifdef LIBGCCJIT_HAVE_gcc_jit_lvalue_set_tls_model */ |
| 1443 |
extern void |
| 1444 |
gcc_jit_lvalue_set_tls_model (gcc_jit_lvalue *lvalue, |
| 1445 |
enum gcc_jit_tls_model model); |
| 1446 |
|
| 1447 |
#define LIBGCCJIT_HAVE_gcc_jit_lvalue_set_link_section |
| 1448 |
|
| 1449 |
/* Set the link section of a global variable; analogous to: |
| 1450 |
__attribute__((section(".section_name"))) |
| 1451 |
in C. |
| 1452 |
|
| 1453 |
This API entrypoint was added in LIBGCCJIT_ABI_18; you can test for its |
| 1454 |
presence using |
| 1455 |
#ifdef LIBGCCJIT_HAVE_gcc_jit_lvalue_set_link_section |
| 1456 |
*/ |
| 1457 |
extern void |
| 1458 |
gcc_jit_lvalue_set_link_section (gcc_jit_lvalue *lvalue, |
| 1459 |
const char *section_name); |
| 1460 |
|
| 1461 |
#define LIBGCCJIT_HAVE_gcc_jit_lvalue_set_register_name |
| 1462 |
|
| 1463 |
/* Make this variable a register variable and set its register name. |
| 1464 |
|
| 1465 |
This API entrypoint was added in LIBGCCJIT_ABI_22; you can test for its |
| 1466 |
presence using |
| 1467 |
#ifdef LIBGCCJIT_HAVE_gcc_jit_lvalue_set_register_name |
| 1468 |
*/ |
| 1469 |
void |
| 1470 |
gcc_jit_lvalue_set_register_name (gcc_jit_lvalue *lvalue, |
| 1471 |
const char *reg_name); |
| 1472 |
|
| 1473 |
extern gcc_jit_lvalue * |
| 1474 |
gcc_jit_function_new_local (gcc_jit_function *func, |
| 1475 |
gcc_jit_location *loc, |
| 1476 |
gcc_jit_type *type, |
| 1477 |
const char *name); |
| 1478 |
|
| 1479 |
extern gcc_jit_lvalue * |
| 1480 |
gcc_jit_function_new_temp (gcc_jit_function *func, |
| 1481 |
gcc_jit_location *loc, |
| 1482 |
gcc_jit_type *type); |
| 1483 |
|
| 1484 |
#define LIBGCCJIT_HAVE_gcc_jit_function_new_temp |
| 1485 |
|
| 1486 |
/********************************************************************** |
| 1487 |
Statement-creation. |
| 1488 |
**********************************************************************/ |
| 1489 |
|
| 1490 |
/* Add evaluation of an rvalue, discarding the result |
| 1491 |
(e.g. a function call that "returns" void). |
| 1492 |
|
| 1493 |
This is equivalent to this C code: |
| 1494 |
|
| 1495 |
(void)expression; |
| 1496 |
*/ |
| 1497 |
extern void |
| 1498 |
gcc_jit_block_add_eval (gcc_jit_block *block, |
| 1499 |
gcc_jit_location *loc, |
| 1500 |
gcc_jit_rvalue *rvalue); |
| 1501 |
|
| 1502 |
/* Add evaluation of an rvalue, assigning the result to the given |
| 1503 |
lvalue. |
| 1504 |
|
| 1505 |
This is roughly equivalent to this C code: |
| 1506 |
|
| 1507 |
lvalue = rvalue; |
| 1508 |
*/ |
| 1509 |
extern void |
| 1510 |
gcc_jit_block_add_assignment (gcc_jit_block *block, |
| 1511 |
gcc_jit_location *loc, |
| 1512 |
gcc_jit_lvalue *lvalue, |
| 1513 |
gcc_jit_rvalue *rvalue); |
| 1514 |
|
| 1515 |
/* Add evaluation of an rvalue, using the result to modify an |
| 1516 |
lvalue. |
| 1517 |
|
| 1518 |
This is analogous to "+=" and friends: |
| 1519 |
|
| 1520 |
lvalue += rvalue; |
| 1521 |
lvalue *= rvalue; |
| 1522 |
lvalue /= rvalue; |
| 1523 |
etc */ |
| 1524 |
extern void |
| 1525 |
gcc_jit_block_add_assignment_op (gcc_jit_block *block, |
| 1526 |
gcc_jit_location *loc, |
| 1527 |
gcc_jit_lvalue *lvalue, |
| 1528 |
enum gcc_jit_binary_op op, |
| 1529 |
gcc_jit_rvalue *rvalue); |
| 1530 |
|
| 1531 |
/* Add a no-op textual comment to the internal representation of the |
| 1532 |
code. It will be optimized away, but will be visible in the dumps |
| 1533 |
seen via |
| 1534 |
GCC_JIT_BOOL_OPTION_DUMP_INITIAL_TREE |
| 1535 |
and |
| 1536 |
GCC_JIT_BOOL_OPTION_DUMP_INITIAL_GIMPLE, |
| 1537 |
and thus may be of use when debugging how your project's internal |
| 1538 |
representation gets converted to the libgccjit IR. */ |
| 1539 |
extern void |
| 1540 |
gcc_jit_block_add_comment (gcc_jit_block *block, |
| 1541 |
gcc_jit_location *loc, |
| 1542 |
const char *text); |
| 1543 |
|
| 1544 |
/* Terminate a block by adding evaluation of an rvalue, branching on the |
| 1545 |
result to the appropriate successor block. |
| 1546 |
|
| 1547 |
This is roughly equivalent to this C code: |
| 1548 |
|
| 1549 |
if (boolval) |
| 1550 |
goto on_true; |
| 1551 |
else |
| 1552 |
goto on_false; |
| 1553 |
|
| 1554 |
block, boolval, on_true, and on_false must be non-NULL. */ |
| 1555 |
extern void |
| 1556 |
gcc_jit_block_end_with_conditional (gcc_jit_block *block, |
| 1557 |
gcc_jit_location *loc, |
| 1558 |
gcc_jit_rvalue *boolval, |
| 1559 |
gcc_jit_block *on_true, |
| 1560 |
gcc_jit_block *on_false); |
| 1561 |
|
| 1562 |
/* Terminate a block by adding a jump to the given target block. |
| 1563 |
|
| 1564 |
This is roughly equivalent to this C code: |
| 1565 |
|
| 1566 |
goto target; |
| 1567 |
*/ |
| 1568 |
extern void |
| 1569 |
gcc_jit_block_end_with_jump (gcc_jit_block *block, |
| 1570 |
gcc_jit_location *loc, |
| 1571 |
gcc_jit_block *target); |
| 1572 |
|
| 1573 |
/* Terminate a block by adding evaluation of an rvalue, returning the value. |
| 1574 |
|
| 1575 |
This is roughly equivalent to this C code: |
| 1576 |
|
| 1577 |
return expression; |
| 1578 |
*/ |
| 1579 |
extern void |
| 1580 |
gcc_jit_block_end_with_return (gcc_jit_block *block, |
| 1581 |
gcc_jit_location *loc, |
| 1582 |
gcc_jit_rvalue *rvalue); |
| 1583 |
|
| 1584 |
/* Terminate a block by adding a valueless return, for use within a function |
| 1585 |
with "void" return type. |
| 1586 |
|
| 1587 |
This is equivalent to this C code: |
| 1588 |
|
| 1589 |
return; |
| 1590 |
*/ |
| 1591 |
extern void |
| 1592 |
gcc_jit_block_end_with_void_return (gcc_jit_block *block, |
| 1593 |
gcc_jit_location *loc); |
| 1594 |
|
| 1595 |
/* Create a new gcc_jit_case instance for use in a switch statement. |
| 1596 |
min_value and max_value must be constants of integer type. |
| 1597 |
|
| 1598 |
This API entrypoint was added in LIBGCCJIT_ABI_3; you can test for its |
| 1599 |
presence using |
| 1600 |
#ifdef LIBGCCJIT_HAVE_SWITCH_STATEMENTS |
| 1601 |
*/ |
| 1602 |
extern gcc_jit_case * |
| 1603 |
gcc_jit_context_new_case (gcc_jit_context *ctxt, |
| 1604 |
gcc_jit_rvalue *min_value, |
| 1605 |
gcc_jit_rvalue *max_value, |
| 1606 |
gcc_jit_block *dest_block); |
| 1607 |
|
| 1608 |
/* Upcasting from case to object. |
| 1609 |
|
| 1610 |
This API entrypoint was added in LIBGCCJIT_ABI_3; you can test for its |
| 1611 |
presence using |
| 1612 |
#ifdef LIBGCCJIT_HAVE_SWITCH_STATEMENTS |
| 1613 |
*/ |
| 1614 |
|
| 1615 |
extern gcc_jit_object * |
| 1616 |
gcc_jit_case_as_object (gcc_jit_case *case_); |
| 1617 |
|
| 1618 |
/* Terminate a block by adding evalation of an rvalue, then performing |
| 1619 |
a multiway branch. |
| 1620 |
|
| 1621 |
This is roughly equivalent to this C code: |
| 1622 |
|
| 1623 |
switch (expr) |
| 1624 |
{ |
| 1625 |
default: |
| 1626 |
goto default_block; |
| 1627 |
|
| 1628 |
case C0.min_value ... C0.max_value: |
| 1629 |
goto C0.dest_block; |
| 1630 |
|
| 1631 |
case C1.min_value ... C1.max_value: |
| 1632 |
goto C1.dest_block; |
| 1633 |
|
| 1634 |
...etc... |
| 1635 |
|
| 1636 |
case C[N - 1].min_value ... C[N - 1].max_value: |
| 1637 |
goto C[N - 1].dest_block; |
| 1638 |
} |
| 1639 |
|
| 1640 |
block, expr, default_block and cases must all be non-NULL. |
| 1641 |
|
| 1642 |
expr must be of the same integer type as all of the min_value |
| 1643 |
and max_value within the cases. |
| 1644 |
|
| 1645 |
num_cases must be >= 0. |
| 1646 |
|
| 1647 |
The ranges of the cases must not overlap (or have duplicate |
| 1648 |
values). |
| 1649 |
|
| 1650 |
This API entrypoint was added in LIBGCCJIT_ABI_3; you can test for its |
| 1651 |
presence using |
| 1652 |
#ifdef LIBGCCJIT_HAVE_SWITCH_STATEMENTS |
| 1653 |
*/ |
| 1654 |
|
| 1655 |
extern void |
| 1656 |
gcc_jit_block_end_with_switch (gcc_jit_block *block, |
| 1657 |
gcc_jit_location *loc, |
| 1658 |
gcc_jit_rvalue *expr, |
| 1659 |
gcc_jit_block *default_block, |
| 1660 |
int num_cases, |
| 1661 |
gcc_jit_case **cases); |
| 1662 |
|
| 1663 |
/* Pre-canned feature macro to indicate the presence of |
| 1664 |
gcc_jit_block_end_with_switch, gcc_jit_case_as_object, and |
| 1665 |
gcc_jit_context_new_case. |
| 1666 |
|
| 1667 |
This can be tested for with #ifdef. */ |
| 1668 |
#define LIBGCCJIT_HAVE_SWITCH_STATEMENTS |
| 1669 |
|
| 1670 |
/********************************************************************** |
| 1671 |
Nested contexts. |
| 1672 |
**********************************************************************/ |
| 1673 |
|
| 1674 |
/* Given an existing JIT context, create a child context. |
| 1675 |
|
| 1676 |
The child inherits a copy of all option-settings from the parent. |
| 1677 |
|
| 1678 |
The child can reference objects created within the parent, but not |
| 1679 |
vice-versa. |
| 1680 |
|
| 1681 |
The lifetime of the child context must be bounded by that of the |
| 1682 |
parent: you should release a child context before releasing the parent |
| 1683 |
context. |
| 1684 |
|
| 1685 |
If you use a function from a parent context within a child context, |
| 1686 |
you have to compile the parent context before you can compile the |
| 1687 |
child context, and the gcc_jit_result of the parent context must |
| 1688 |
outlive the gcc_jit_result of the child context. |
| 1689 |
|
| 1690 |
This allows caching of shared initializations. For example, you could |
| 1691 |
create types and declarations of global functions in a parent context |
| 1692 |
once within a process, and then create child contexts whenever a |
| 1693 |
function or loop becomes hot. Each such child context can be used for |
| 1694 |
JIT-compiling just one function or loop, but can reference types |
| 1695 |
and helper functions created within the parent context. |
| 1696 |
|
| 1697 |
Contexts can be arbitrarily nested, provided the above rules are |
| 1698 |
followed, but it's probably not worth going above 2 or 3 levels, and |
| 1699 |
there will likely be a performance hit for such nesting. */ |
| 1700 |
|
| 1701 |
extern gcc_jit_context * |
| 1702 |
gcc_jit_context_new_child_context (gcc_jit_context *parent_ctxt); |
| 1703 |
|
| 1704 |
/********************************************************************** |
| 1705 |
Implementation support. |
| 1706 |
**********************************************************************/ |
| 1707 |
|
| 1708 |
/* Write C source code into "path" that can be compiled into a |
| 1709 |
self-contained executable (i.e. with libgccjit as the only dependency). |
| 1710 |
The generated code will attempt to replay the API calls that have been |
| 1711 |
made into the given context. |
| 1712 |
|
| 1713 |
This may be useful when debugging the library or client code, for |
| 1714 |
reducing a complicated recipe for reproducing a bug into a simpler |
| 1715 |
form. |
| 1716 |
|
| 1717 |
Typically you need to supply the option "-Wno-unused-variable" when |
| 1718 |
compiling the generated file (since the result of each API call is |
| 1719 |
assigned to a unique variable within the generated C source, and not |
| 1720 |
all are necessarily then used). */ |
| 1721 |
|
| 1722 |
extern void |
| 1723 |
gcc_jit_context_dump_reproducer_to_file (gcc_jit_context *ctxt, |
| 1724 |
const char *path); |
| 1725 |
|
| 1726 |
/* Enable the dumping of a specific set of internal state from the |
| 1727 |
compilation, capturing the result in-memory as a buffer. |
| 1728 |
|
| 1729 |
Parameter "dumpname" corresponds to the equivalent gcc command-line |
| 1730 |
option, without the "-fdump-" prefix. |
| 1731 |
For example, to get the equivalent of "-fdump-tree-vrp1", supply |
| 1732 |
"tree-vrp1". |
| 1733 |
The context directly stores the dumpname as a (const char *), so the |
| 1734 |
passed string must outlive the context. |
| 1735 |
|
| 1736 |
gcc_jit_context_compile and gcc_jit_context_to_file |
| 1737 |
will capture the dump as a dynamically-allocated buffer, writing |
| 1738 |
it to ``*out_ptr``. |
| 1739 |
|
| 1740 |
The caller becomes responsible for calling |
| 1741 |
free (*out_ptr) |
| 1742 |
each time that gcc_jit_context_compile or gcc_jit_context_to_file |
| 1743 |
are called. *out_ptr will be written to, either with the address of a |
| 1744 |
buffer, or with NULL if an error occurred. |
| 1745 |
|
| 1746 |
This API entrypoint is likely to be less stable than the others. |
| 1747 |
In particular, both the precise dumpnames, and the format and content |
| 1748 |
of the dumps are subject to change. |
| 1749 |
|
| 1750 |
It exists primarily for writing the library's own test suite. */ |
| 1751 |
|
| 1752 |
extern void |
| 1753 |
gcc_jit_context_enable_dump (gcc_jit_context *ctxt, |
| 1754 |
const char *dumpname, |
| 1755 |
char **out_ptr); |
| 1756 |
|
| 1757 |
/********************************************************************** |
| 1758 |
Timing support. |
| 1759 |
**********************************************************************/ |
| 1760 |
|
| 1761 |
/* The timing API was added in LIBGCCJIT_ABI_4; you can test for its |
| 1762 |
presence using |
| 1763 |
#ifdef LIBGCCJIT_HAVE_TIMING_API |
| 1764 |
*/ |
| 1765 |
#define LIBGCCJIT_HAVE_TIMING_API |
| 1766 |
|
| 1767 |
typedef struct gcc_jit_timer gcc_jit_timer; |
| 1768 |
|
| 1769 |
/* Create a gcc_jit_timer instance, and start timing. |
| 1770 |
|
| 1771 |
This API entrypoint was added in LIBGCCJIT_ABI_4; you can test for its |
| 1772 |
presence using |
| 1773 |
#ifdef LIBGCCJIT_HAVE_TIMING_API |
| 1774 |
*/ |
| 1775 |
extern gcc_jit_timer * |
| 1776 |
gcc_jit_timer_new (void); |
| 1777 |
|
| 1778 |
/* Release a gcc_jit_timer instance. |
| 1779 |
|
| 1780 |
This API entrypoint was added in LIBGCCJIT_ABI_4; you can test for its |
| 1781 |
presence using |
| 1782 |
#ifdef LIBGCCJIT_HAVE_TIMING_API |
| 1783 |
*/ |
| 1784 |
extern void |
| 1785 |
gcc_jit_timer_release (gcc_jit_timer *timer); |
| 1786 |
|
| 1787 |
/* Associate a gcc_jit_timer instance with a context. |
| 1788 |
|
| 1789 |
This API entrypoint was added in LIBGCCJIT_ABI_4; you can test for its |
| 1790 |
presence using |
| 1791 |
#ifdef LIBGCCJIT_HAVE_TIMING_API |
| 1792 |
*/ |
| 1793 |
extern void |
| 1794 |
gcc_jit_context_set_timer (gcc_jit_context *ctxt, |
| 1795 |
gcc_jit_timer *timer); |
| 1796 |
|
| 1797 |
/* Get the timer associated with a context (if any). |
| 1798 |
|
| 1799 |
This API entrypoint was added in LIBGCCJIT_ABI_4; you can test for its |
| 1800 |
presence using |
| 1801 |
#ifdef LIBGCCJIT_HAVE_TIMING_API |
| 1802 |
*/ |
| 1803 |
|
| 1804 |
extern gcc_jit_timer * |
| 1805 |
gcc_jit_context_get_timer (gcc_jit_context *ctxt); |
| 1806 |
|
| 1807 |
/* Push the given item onto the timing stack. |
| 1808 |
|
| 1809 |
This API entrypoint was added in LIBGCCJIT_ABI_4; you can test for its |
| 1810 |
presence using |
| 1811 |
#ifdef LIBGCCJIT_HAVE_TIMING_API |
| 1812 |
*/ |
| 1813 |
|
| 1814 |
extern void |
| 1815 |
gcc_jit_timer_push (gcc_jit_timer *timer, |
| 1816 |
const char *item_name); |
| 1817 |
|
| 1818 |
/* Pop the top item from the timing stack. |
| 1819 |
|
| 1820 |
This API entrypoint was added in LIBGCCJIT_ABI_4; you can test for its |
| 1821 |
presence using |
| 1822 |
#ifdef LIBGCCJIT_HAVE_TIMING_API |
| 1823 |
*/ |
| 1824 |
|
| 1825 |
extern void |
| 1826 |
gcc_jit_timer_pop (gcc_jit_timer *timer, |
| 1827 |
const char *item_name); |
| 1828 |
|
| 1829 |
/* Print timing information to the given stream about activity since |
| 1830 |
the timer was started. |
| 1831 |
|
| 1832 |
This API entrypoint was added in LIBGCCJIT_ABI_4; you can test for its |
| 1833 |
presence using |
| 1834 |
#ifdef LIBGCCJIT_HAVE_TIMING_API |
| 1835 |
*/ |
| 1836 |
|
| 1837 |
extern void |
| 1838 |
gcc_jit_timer_print (gcc_jit_timer *timer, |
| 1839 |
FILE *f_out); |
| 1840 |
|
| 1841 |
|
| 1842 |
#define LIBGCCJIT_HAVE_gcc_jit_rvalue_set_bool_require_tail_call |
| 1843 |
|
| 1844 |
/* Mark/clear a call as needing tail-call optimization. |
| 1845 |
|
| 1846 |
This API entrypoint was added in LIBGCCJIT_ABI_6; you can test for its |
| 1847 |
presence using |
| 1848 |
#ifdef LIBGCCJIT_HAVE_gcc_jit_rvalue_set_bool_require_tail_call |
| 1849 |
*/ |
| 1850 |
extern void |
| 1851 |
gcc_jit_rvalue_set_bool_require_tail_call (gcc_jit_rvalue *call, |
| 1852 |
int require_tail_call); |
| 1853 |
|
| 1854 |
#define LIBGCCJIT_HAVE_gcc_jit_type_get_aligned |
| 1855 |
|
| 1856 |
/* Given type "T", get type: |
| 1857 |
|
| 1858 |
T __attribute__ ((aligned (ALIGNMENT_IN_BYTES))) |
| 1859 |
|
| 1860 |
The alignment must be a power of two. |
| 1861 |
|
| 1862 |
This API entrypoint was added in LIBGCCJIT_ABI_7; you can test for its |
| 1863 |
presence using |
| 1864 |
#ifdef LIBGCCJIT_HAVE_gcc_jit_type_get_aligned |
| 1865 |
*/ |
| 1866 |
extern gcc_jit_type * |
| 1867 |
gcc_jit_type_get_aligned (gcc_jit_type *type, |
| 1868 |
size_t alignment_in_bytes); |
| 1869 |
|
| 1870 |
#define LIBGCCJIT_HAVE_gcc_jit_type_get_vector |
| 1871 |
|
| 1872 |
/* Given type "T", get type: |
| 1873 |
|
| 1874 |
T __attribute__ ((vector_size (sizeof(T) * num_units)) |
| 1875 |
|
| 1876 |
T must be integral/floating point; num_units must be a power of two. |
| 1877 |
|
| 1878 |
This API entrypoint was added in LIBGCCJIT_ABI_8; you can test for its |
| 1879 |
presence using |
| 1880 |
#ifdef LIBGCCJIT_HAVE_gcc_jit_type_get_vector |
| 1881 |
*/ |
| 1882 |
extern gcc_jit_type * |
| 1883 |
gcc_jit_type_get_vector (gcc_jit_type *type, size_t num_units); |
| 1884 |
|
| 1885 |
|
| 1886 |
#define LIBGCCJIT_HAVE_gcc_jit_function_get_address |
| 1887 |
|
| 1888 |
/* Get the address of a function as an rvalue, of function pointer |
| 1889 |
type. |
| 1890 |
|
| 1891 |
This API entrypoint was added in LIBGCCJIT_ABI_9; you can test for its |
| 1892 |
presence using |
| 1893 |
#ifdef LIBGCCJIT_HAVE_gcc_jit_function_get_address |
| 1894 |
*/ |
| 1895 |
extern gcc_jit_rvalue * |
| 1896 |
gcc_jit_function_get_address (gcc_jit_function *fn, |
| 1897 |
gcc_jit_location *loc); |
| 1898 |
|
| 1899 |
|
| 1900 |
#define LIBGCCJIT_HAVE_gcc_jit_context_new_rvalue_from_vector |
| 1901 |
|
| 1902 |
/* Build a vector rvalue from an array of elements. |
| 1903 |
|
| 1904 |
"vec_type" should be a vector type, created using gcc_jit_type_get_vector. |
| 1905 |
|
| 1906 |
This API entrypoint was added in LIBGCCJIT_ABI_10; you can test for its |
| 1907 |
presence using |
| 1908 |
#ifdef LIBGCCJIT_HAVE_gcc_jit_context_new_rvalue_from_vector |
| 1909 |
*/ |
| 1910 |
extern gcc_jit_rvalue * |
| 1911 |
gcc_jit_context_new_rvalue_from_vector (gcc_jit_context *ctxt, |
| 1912 |
gcc_jit_location *loc, |
| 1913 |
gcc_jit_type *vec_type, |
| 1914 |
size_t num_elements, |
| 1915 |
gcc_jit_rvalue **elements); |
| 1916 |
|
| 1917 |
#define LIBGCCJIT_HAVE_gcc_jit_version |
| 1918 |
|
| 1919 |
/* Functions to retrieve libgccjit version. |
| 1920 |
Analogous to __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__ in C code. |
| 1921 |
|
| 1922 |
These API entrypoints were added in LIBGCCJIT_ABI_13; you can test for their |
| 1923 |
presence using |
| 1924 |
#ifdef LIBGCCJIT_HAVE_gcc_jit_version |
| 1925 |
*/ |
| 1926 |
extern int |
| 1927 |
gcc_jit_version_major (void); |
| 1928 |
extern int |
| 1929 |
gcc_jit_version_minor (void); |
| 1930 |
extern int |
| 1931 |
gcc_jit_version_patchlevel (void); |
| 1932 |
|
| 1933 |
/********************************************************************** |
| 1934 |
Asm support. |
| 1935 |
**********************************************************************/ |
| 1936 |
|
| 1937 |
/* Functions for adding inline assembler code, analogous to GCC's |
| 1938 |
"extended asm" syntax. |
| 1939 |
|
| 1940 |
See https://gcc.gnu.org/onlinedocs/gcc/Using-Assembly-Language-with-C.html |
| 1941 |
|
| 1942 |
These API entrypoints were added in LIBGCCJIT_ABI_15; you can test for their |
| 1943 |
presence using |
| 1944 |
#ifdef LIBGCCJIT_HAVE_ASM_STATEMENTS |
| 1945 |
*/ |
| 1946 |
|
| 1947 |
#define LIBGCCJIT_HAVE_ASM_STATEMENTS |
| 1948 |
|
| 1949 |
/* Create a gcc_jit_extended_asm for an extended asm statement |
| 1950 |
with no control flow (i.e. without the goto qualifier). |
| 1951 |
|
| 1952 |
The asm_template parameter corresponds to the AssemblerTemplate |
| 1953 |
within C's extended asm syntax. It must be non-NULL. */ |
| 1954 |
|
| 1955 |
extern gcc_jit_extended_asm * |
| 1956 |
gcc_jit_block_add_extended_asm (gcc_jit_block *block, |
| 1957 |
gcc_jit_location *loc, |
| 1958 |
const char *asm_template); |
| 1959 |
|
| 1960 |
/* Create a gcc_jit_extended_asm for an extended asm statement |
| 1961 |
that may perform jumps, and use it to terminate the given block. |
| 1962 |
This is equivalent to the "goto" qualifier in C's extended asm |
| 1963 |
syntax. */ |
| 1964 |
|
| 1965 |
extern gcc_jit_extended_asm * |
| 1966 |
gcc_jit_block_end_with_extended_asm_goto (gcc_jit_block *block, |
| 1967 |
gcc_jit_location *loc, |
| 1968 |
const char *asm_template, |
| 1969 |
int num_goto_blocks, |
| 1970 |
gcc_jit_block **goto_blocks, |
| 1971 |
gcc_jit_block *fallthrough_block); |
| 1972 |
|
| 1973 |
/* Upcasting from extended asm to object. */ |
| 1974 |
|
| 1975 |
extern gcc_jit_object * |
| 1976 |
gcc_jit_extended_asm_as_object (gcc_jit_extended_asm *ext_asm); |
| 1977 |
|
| 1978 |
/* Set whether the gcc_jit_extended_asm has side-effects, equivalent to |
| 1979 |
the "volatile" qualifier in C's extended asm syntax. */ |
| 1980 |
|
| 1981 |
extern void |
| 1982 |
gcc_jit_extended_asm_set_volatile_flag (gcc_jit_extended_asm *ext_asm, |
| 1983 |
int flag); |
| 1984 |
|
| 1985 |
/* Set the equivalent of the "inline" qualifier in C's extended asm |
| 1986 |
syntax. */ |
| 1987 |
|
| 1988 |
extern void |
| 1989 |
gcc_jit_extended_asm_set_inline_flag (gcc_jit_extended_asm *ext_asm, |
| 1990 |
int flag); |
| 1991 |
|
| 1992 |
/* Add an output operand to the extended asm statement. |
| 1993 |
"asm_symbolic_name" can be NULL. |
| 1994 |
"constraint" and "dest" must be non-NULL. |
| 1995 |
This function can't be called on an "asm goto" as such instructions |
| 1996 |
can't have outputs */ |
| 1997 |
|
| 1998 |
extern void |
| 1999 |
gcc_jit_extended_asm_add_output_operand (gcc_jit_extended_asm *ext_asm, |
| 2000 |
const char *asm_symbolic_name, |
| 2001 |
const char *constraint, |
| 2002 |
gcc_jit_lvalue *dest); |
| 2003 |
|
| 2004 |
/* Add an input operand to the extended asm statement. |
| 2005 |
"asm_symbolic_name" can be NULL. |
| 2006 |
"constraint" and "src" must be non-NULL. */ |
| 2007 |
|
| 2008 |
extern void |
| 2009 |
gcc_jit_extended_asm_add_input_operand (gcc_jit_extended_asm *ext_asm, |
| 2010 |
const char *asm_symbolic_name, |
| 2011 |
const char *constraint, |
| 2012 |
gcc_jit_rvalue *src); |
| 2013 |
|
| 2014 |
/* Add "victim" to the list of registers clobbered by the extended |
| 2015 |
asm statement. It must be non-NULL. */ |
| 2016 |
|
| 2017 |
extern void |
| 2018 |
gcc_jit_extended_asm_add_clobber (gcc_jit_extended_asm *ext_asm, |
| 2019 |
const char *victim); |
| 2020 |
|
| 2021 |
/* Add "asm_stmts", a set of top-level asm statements, analogous to |
| 2022 |
those created by GCC's "basic" asm syntax in C at file scope. */ |
| 2023 |
|
| 2024 |
extern void |
| 2025 |
gcc_jit_context_add_top_level_asm (gcc_jit_context *ctxt, |
| 2026 |
gcc_jit_location *loc, |
| 2027 |
const char *asm_stmts); |
| 2028 |
|
| 2029 |
#define LIBGCCJIT_HAVE_REFLECTION |
| 2030 |
|
| 2031 |
/* Reflection functions to get the number of parameters, return type of |
| 2032 |
a function and whether a type is a bool from the C API. |
| 2033 |
|
| 2034 |
This API entrypoint was added in LIBGCCJIT_ABI_16; you can test for its |
| 2035 |
presence using |
| 2036 |
#ifdef LIBGCCJIT_HAVE_REFLECTION |
| 2037 |
*/ |
| 2038 |
/* Get the return type of a function. */ |
| 2039 |
extern gcc_jit_type * |
| 2040 |
gcc_jit_function_get_return_type (gcc_jit_function *func); |
| 2041 |
|
| 2042 |
/* Get the number of params of a function. */ |
| 2043 |
extern size_t |
| 2044 |
gcc_jit_function_get_param_count (gcc_jit_function *func); |
| 2045 |
|
| 2046 |
/* Get the element type of an array type or NULL if it's not an array. */ |
| 2047 |
extern gcc_jit_type * |
| 2048 |
gcc_jit_type_dyncast_array (gcc_jit_type *type); |
| 2049 |
|
| 2050 |
/* Return non-zero if the type is a bool. */ |
| 2051 |
extern int |
| 2052 |
gcc_jit_type_is_bool (gcc_jit_type *type); |
| 2053 |
|
| 2054 |
/* Return the function type if it is one or NULL. */ |
| 2055 |
extern gcc_jit_function_type * |
| 2056 |
gcc_jit_type_dyncast_function_ptr_type (gcc_jit_type *type); |
| 2057 |
|
| 2058 |
/* Given a function type, return its return type. */ |
| 2059 |
extern gcc_jit_type * |
| 2060 |
gcc_jit_function_type_get_return_type (gcc_jit_function_type *function_type); |
| 2061 |
|
| 2062 |
/* Given a function type, return its number of parameters. */ |
| 2063 |
extern size_t |
| 2064 |
gcc_jit_function_type_get_param_count (gcc_jit_function_type *function_type); |
| 2065 |
|
| 2066 |
/* Given a function type, return the type of the specified parameter. */ |
| 2067 |
extern gcc_jit_type * |
| 2068 |
gcc_jit_function_type_get_param_type (gcc_jit_function_type *function_type, |
| 2069 |
size_t index); |
| 2070 |
|
| 2071 |
/* Return non-zero if the type is an integral. */ |
| 2072 |
extern int |
| 2073 |
gcc_jit_type_is_integral (gcc_jit_type *type); |
| 2074 |
|
| 2075 |
/* Return the type pointed by the pointer type or NULL if it's not a |
| 2076 |
* pointer. */ |
| 2077 |
extern gcc_jit_type * |
| 2078 |
gcc_jit_type_is_pointer (gcc_jit_type *type); |
| 2079 |
|
| 2080 |
/* Given a type, return a dynamic cast to a vector type or NULL. */ |
| 2081 |
extern gcc_jit_vector_type * |
| 2082 |
gcc_jit_type_dyncast_vector (gcc_jit_type *type); |
| 2083 |
|
| 2084 |
/* Given a type, return a dynamic cast to a struct type or NULL. */ |
| 2085 |
extern gcc_jit_struct * |
| 2086 |
gcc_jit_type_is_struct (gcc_jit_type *type); |
| 2087 |
|
| 2088 |
/* Given a vector type, return the number of units it contains. */ |
| 2089 |
extern size_t |
| 2090 |
gcc_jit_vector_type_get_num_units (gcc_jit_vector_type *vector_type); |
| 2091 |
|
| 2092 |
/* Given a vector type, return the type of its elements. */ |
| 2093 |
extern gcc_jit_type * |
| 2094 |
gcc_jit_vector_type_get_element_type (gcc_jit_vector_type *vector_type); |
| 2095 |
|
| 2096 |
/* Given a type, return the unqualified type, removing "const", "volatile" |
| 2097 |
* and alignment qualifiers. */ |
| 2098 |
extern gcc_jit_type * |
| 2099 |
gcc_jit_type_unqualified (gcc_jit_type *type); |
| 2100 |
|
| 2101 |
#define LIBGCCJIT_HAVE_ATTRIBUTES |
| 2102 |
|
| 2103 |
/* Function attributes. */ |
| 2104 |
enum gcc_jit_fn_attribute |
| 2105 |
{ |
| 2106 |
GCC_JIT_FN_ATTRIBUTE_ALIAS, |
| 2107 |
GCC_JIT_FN_ATTRIBUTE_ALWAYS_INLINE, |
| 2108 |
GCC_JIT_FN_ATTRIBUTE_INLINE, |
| 2109 |
GCC_JIT_FN_ATTRIBUTE_NOINLINE, |
| 2110 |
GCC_JIT_FN_ATTRIBUTE_TARGET, |
| 2111 |
GCC_JIT_FN_ATTRIBUTE_USED, |
| 2112 |
GCC_JIT_FN_ATTRIBUTE_VISIBILITY, |
| 2113 |
GCC_JIT_FN_ATTRIBUTE_COLD, |
| 2114 |
GCC_JIT_FN_ATTRIBUTE_RETURNS_TWICE, |
| 2115 |
GCC_JIT_FN_ATTRIBUTE_PURE, |
| 2116 |
GCC_JIT_FN_ATTRIBUTE_CONST, |
| 2117 |
GCC_JIT_FN_ATTRIBUTE_WEAK, |
| 2118 |
GCC_JIT_FN_ATTRIBUTE_NONNULL, |
| 2119 |
|
| 2120 |
/* Maximum value of this enum, should always be last. */ |
| 2121 |
GCC_JIT_FN_ATTRIBUTE_MAX, |
| 2122 |
}; |
| 2123 |
|
| 2124 |
/* Add an attribute to a function. */ |
| 2125 |
extern void |
| 2126 |
gcc_jit_function_add_attribute (gcc_jit_function *func, |
| 2127 |
enum gcc_jit_fn_attribute attribute); |
| 2128 |
|
| 2129 |
extern void |
| 2130 |
gcc_jit_function_add_string_attribute (gcc_jit_function *func, |
| 2131 |
enum gcc_jit_fn_attribute attribute, |
| 2132 |
const char* value); |
| 2133 |
|
| 2134 |
extern void |
| 2135 |
gcc_jit_function_add_integer_array_attribute ( |
| 2136 |
gcc_jit_function *func, |
| 2137 |
enum gcc_jit_fn_attribute attribute, |
| 2138 |
const int* value, |
| 2139 |
size_t length); |
| 2140 |
|
| 2141 |
/* Variable attributes. */ |
| 2142 |
enum gcc_jit_variable_attribute |
| 2143 |
{ |
| 2144 |
GCC_JIT_VARIABLE_ATTRIBUTE_VISIBILITY, |
| 2145 |
|
| 2146 |
/* Maximum value of this enum, should always be last. */ |
| 2147 |
GCC_JIT_VARIABLE_ATTRIBUTE_MAX, |
| 2148 |
}; |
| 2149 |
|
| 2150 |
/* Add a string attribute to a variable. */ |
| 2151 |
extern void |
| 2152 |
gcc_jit_lvalue_add_string_attribute (gcc_jit_lvalue *variable, |
| 2153 |
enum gcc_jit_variable_attribute attribute, |
| 2154 |
const char* value); |
| 2155 |
|
| 2156 |
extern void |
| 2157 |
gcc_jit_context_set_output_ident (gcc_jit_context *ctxt, |
| 2158 |
const char* output_ident); |
| 2159 |
|
| 2160 |
#define LIBGCCJIT_HAVE_gcc_jit_context_set_output_ident |
| 2161 |
|
| 2162 |
#ifdef __cplusplus |
| 2163 |
} |
| 2164 |
#endif /* __cplusplus */ |
| 2165 |
|
| 2166 |
#endif /* LIBGCCJIT_H */ |