136ac495dSmrg /* A pure C API to enable client code to embed GCC as a JIT-compiler. 2*8feb0f0bSmrg Copyright (C) 2013-2020 Free Software Foundation, Inc. 336ac495dSmrg 436ac495dSmrg This file is part of GCC. 536ac495dSmrg 636ac495dSmrg GCC is free software; you can redistribute it and/or modify it 736ac495dSmrg under the terms of the GNU General Public License as published by 836ac495dSmrg the Free Software Foundation; either version 3, or (at your option) 936ac495dSmrg any later version. 1036ac495dSmrg 1136ac495dSmrg GCC is distributed in the hope that it will be useful, but 1236ac495dSmrg WITHOUT ANY WARRANTY; without even the implied warranty of 1336ac495dSmrg MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 1436ac495dSmrg General Public License for more details. 1536ac495dSmrg 1636ac495dSmrg You should have received a copy of the GNU General Public License 1736ac495dSmrg along with GCC; see the file COPYING3. If not see 1836ac495dSmrg <http://www.gnu.org/licenses/>. */ 1936ac495dSmrg 2036ac495dSmrg #ifndef LIBGCCJIT_H 2136ac495dSmrg #define LIBGCCJIT_H 2236ac495dSmrg 2336ac495dSmrg #include <stdio.h> 2436ac495dSmrg 2536ac495dSmrg #ifdef __cplusplus 2636ac495dSmrg extern "C" { 2736ac495dSmrg #endif /* __cplusplus */ 2836ac495dSmrg 2936ac495dSmrg /********************************************************************** 3036ac495dSmrg Data structures. 3136ac495dSmrg **********************************************************************/ 3236ac495dSmrg /* All structs within the API are opaque. */ 3336ac495dSmrg 3436ac495dSmrg /* A gcc_jit_context encapsulates the state of a compilation. 3536ac495dSmrg You can set up options on it, and add types, functions and code, using 3636ac495dSmrg the API below. 3736ac495dSmrg 3836ac495dSmrg Invoking gcc_jit_context_compile on it gives you a gcc_jit_result * 3936ac495dSmrg (or NULL), representing in-memory machine code. 4036ac495dSmrg 4136ac495dSmrg You can call gcc_jit_context_compile repeatedly on one context, giving 4236ac495dSmrg multiple independent results. 4336ac495dSmrg 4436ac495dSmrg Similarly, you can call gcc_jit_context_compile_to_file on a context 4536ac495dSmrg to compile to disk. 4636ac495dSmrg 4736ac495dSmrg Eventually you can call gcc_jit_context_release to clean up the 4836ac495dSmrg context; any in-memory results created from it are still usable, and 4936ac495dSmrg should be cleaned up via gcc_jit_result_release. */ 5036ac495dSmrg typedef struct gcc_jit_context gcc_jit_context; 5136ac495dSmrg 5236ac495dSmrg /* A gcc_jit_result encapsulates the result of an in-memory compilation. */ 5336ac495dSmrg typedef struct gcc_jit_result gcc_jit_result; 5436ac495dSmrg 5536ac495dSmrg /* An object created within a context. Such objects are automatically 5636ac495dSmrg cleaned up when the context is released. 5736ac495dSmrg 5836ac495dSmrg The class hierarchy looks like this: 5936ac495dSmrg 6036ac495dSmrg +- gcc_jit_object 6136ac495dSmrg +- gcc_jit_location 6236ac495dSmrg +- gcc_jit_type 6336ac495dSmrg +- gcc_jit_struct 6436ac495dSmrg +- gcc_jit_field 6536ac495dSmrg +- gcc_jit_function 6636ac495dSmrg +- gcc_jit_block 6736ac495dSmrg +- gcc_jit_rvalue 6836ac495dSmrg +- gcc_jit_lvalue 6936ac495dSmrg +- gcc_jit_param 7036ac495dSmrg +- gcc_jit_case 7136ac495dSmrg */ 7236ac495dSmrg typedef struct gcc_jit_object gcc_jit_object; 7336ac495dSmrg 7436ac495dSmrg /* A gcc_jit_location encapsulates a source code location, so that 7536ac495dSmrg you can (optionally) associate locations in your language with 7636ac495dSmrg statements in the JIT-compiled code, allowing the debugger to 7736ac495dSmrg single-step through your language. 7836ac495dSmrg 7936ac495dSmrg Note that to do so, you also need to enable 8036ac495dSmrg GCC_JIT_BOOL_OPTION_DEBUGINFO 8136ac495dSmrg on the gcc_jit_context. 8236ac495dSmrg 8336ac495dSmrg gcc_jit_location instances are optional; you can always pass 8436ac495dSmrg NULL. */ 8536ac495dSmrg typedef struct gcc_jit_location gcc_jit_location; 8636ac495dSmrg 8736ac495dSmrg /* A gcc_jit_type encapsulates a type e.g. "int" or a "struct foo*". */ 8836ac495dSmrg typedef struct gcc_jit_type gcc_jit_type; 8936ac495dSmrg 9036ac495dSmrg /* A gcc_jit_field encapsulates a field within a struct; it is used 9136ac495dSmrg when creating a struct type (using gcc_jit_context_new_struct_type). 9236ac495dSmrg Fields cannot be shared between structs. */ 9336ac495dSmrg typedef struct gcc_jit_field gcc_jit_field; 9436ac495dSmrg 9536ac495dSmrg /* A gcc_jit_struct encapsulates a struct type, either one that we have 9636ac495dSmrg the layout for, or an opaque type. */ 9736ac495dSmrg typedef struct gcc_jit_struct gcc_jit_struct; 9836ac495dSmrg 9936ac495dSmrg /* A gcc_jit_function encapsulates a function: either one that you're 10036ac495dSmrg creating yourself, or a reference to one that you're dynamically 10136ac495dSmrg linking to within the rest of the process. */ 10236ac495dSmrg typedef struct gcc_jit_function gcc_jit_function; 10336ac495dSmrg 10436ac495dSmrg /* A gcc_jit_block encapsulates a "basic block" of statements within a 10536ac495dSmrg function (i.e. with one entry point and one exit point). 10636ac495dSmrg 10736ac495dSmrg Every block within a function must be terminated with a conditional, 10836ac495dSmrg a branch, or a return. 10936ac495dSmrg 11036ac495dSmrg The blocks within a function form a directed graph. 11136ac495dSmrg 11236ac495dSmrg The entrypoint to the function is the first block created within 11336ac495dSmrg it. 11436ac495dSmrg 11536ac495dSmrg All of the blocks in a function must be reachable via some path from 11636ac495dSmrg the first block. 11736ac495dSmrg 11836ac495dSmrg It's OK to have more than one "return" from a function (i.e. multiple 11936ac495dSmrg blocks that terminate by returning). */ 12036ac495dSmrg typedef struct gcc_jit_block gcc_jit_block; 12136ac495dSmrg 12236ac495dSmrg /* A gcc_jit_rvalue is an expression within your code, with some type. */ 12336ac495dSmrg typedef struct gcc_jit_rvalue gcc_jit_rvalue; 12436ac495dSmrg 12536ac495dSmrg /* A gcc_jit_lvalue is a storage location within your code (e.g. a 12636ac495dSmrg variable, a parameter, etc). It is also a gcc_jit_rvalue; use 12736ac495dSmrg gcc_jit_lvalue_as_rvalue to cast. */ 12836ac495dSmrg typedef struct gcc_jit_lvalue gcc_jit_lvalue; 12936ac495dSmrg 13036ac495dSmrg /* A gcc_jit_param is a function parameter, used when creating a 13136ac495dSmrg gcc_jit_function. It is also a gcc_jit_lvalue (and thus also an 13236ac495dSmrg rvalue); use gcc_jit_param_as_lvalue to convert. */ 13336ac495dSmrg typedef struct gcc_jit_param gcc_jit_param; 13436ac495dSmrg 13536ac495dSmrg /* A gcc_jit_case is for use when building multiway branches via 13636ac495dSmrg gcc_jit_block_end_with_switch and represents a range of integer 13736ac495dSmrg values (or an individual integer value) together with an associated 13836ac495dSmrg destination block. */ 13936ac495dSmrg typedef struct gcc_jit_case gcc_jit_case; 14036ac495dSmrg 14136ac495dSmrg /* Acquire a JIT-compilation context. */ 14236ac495dSmrg extern gcc_jit_context * 14336ac495dSmrg gcc_jit_context_acquire (void); 14436ac495dSmrg 14536ac495dSmrg /* Release the context. After this call, it's no longer valid to use 14636ac495dSmrg the ctxt. */ 14736ac495dSmrg extern void 14836ac495dSmrg gcc_jit_context_release (gcc_jit_context *ctxt); 14936ac495dSmrg 15036ac495dSmrg /* Options present in the initial release of libgccjit. 15136ac495dSmrg These were handled using enums. */ 15236ac495dSmrg 15336ac495dSmrg /* Options taking string values. */ 15436ac495dSmrg enum gcc_jit_str_option 15536ac495dSmrg { 15636ac495dSmrg /* The name of the program, for use as a prefix when printing error 15736ac495dSmrg messages to stderr. If NULL, or default, "libgccjit.so" is used. */ 15836ac495dSmrg GCC_JIT_STR_OPTION_PROGNAME, 15936ac495dSmrg 16036ac495dSmrg GCC_JIT_NUM_STR_OPTIONS 16136ac495dSmrg }; 16236ac495dSmrg 16336ac495dSmrg /* Options taking int values. */ 16436ac495dSmrg enum gcc_jit_int_option 16536ac495dSmrg { 16636ac495dSmrg /* How much to optimize the code. 16736ac495dSmrg Valid values are 0-3, corresponding to GCC's command-line options 16836ac495dSmrg -O0 through -O3. 16936ac495dSmrg 17036ac495dSmrg The default value is 0 (unoptimized). */ 17136ac495dSmrg GCC_JIT_INT_OPTION_OPTIMIZATION_LEVEL, 17236ac495dSmrg 17336ac495dSmrg GCC_JIT_NUM_INT_OPTIONS 17436ac495dSmrg }; 17536ac495dSmrg 17636ac495dSmrg /* Options taking boolean values. 17736ac495dSmrg These all default to "false". */ 17836ac495dSmrg enum gcc_jit_bool_option 17936ac495dSmrg { 18036ac495dSmrg /* If true, gcc_jit_context_compile will attempt to do the right 18136ac495dSmrg thing so that if you attach a debugger to the process, it will 18236ac495dSmrg be able to inspect variables and step through your code. 18336ac495dSmrg 18436ac495dSmrg Note that you can't step through code unless you set up source 18536ac495dSmrg location information for the code (by creating and passing in 18636ac495dSmrg gcc_jit_location instances). */ 18736ac495dSmrg GCC_JIT_BOOL_OPTION_DEBUGINFO, 18836ac495dSmrg 18936ac495dSmrg /* If true, gcc_jit_context_compile will dump its initial "tree" 19036ac495dSmrg representation of your code to stderr (before any 19136ac495dSmrg optimizations). */ 19236ac495dSmrg GCC_JIT_BOOL_OPTION_DUMP_INITIAL_TREE, 19336ac495dSmrg 19436ac495dSmrg /* If true, gcc_jit_context_compile will dump the "gimple" 19536ac495dSmrg representation of your code to stderr, before any optimizations 19636ac495dSmrg are performed. The dump resembles C code. */ 19736ac495dSmrg GCC_JIT_BOOL_OPTION_DUMP_INITIAL_GIMPLE, 19836ac495dSmrg 19936ac495dSmrg /* If true, gcc_jit_context_compile will dump the final 20036ac495dSmrg generated code to stderr, in the form of assembly language. */ 20136ac495dSmrg GCC_JIT_BOOL_OPTION_DUMP_GENERATED_CODE, 20236ac495dSmrg 20336ac495dSmrg /* If true, gcc_jit_context_compile will print information to stderr 20436ac495dSmrg on the actions it is performing, followed by a profile showing 20536ac495dSmrg the time taken and memory usage of each phase. 20636ac495dSmrg */ 20736ac495dSmrg GCC_JIT_BOOL_OPTION_DUMP_SUMMARY, 20836ac495dSmrg 20936ac495dSmrg /* If true, gcc_jit_context_compile will dump copious 21036ac495dSmrg amount of information on what it's doing to various 21136ac495dSmrg files within a temporary directory. Use 21236ac495dSmrg GCC_JIT_BOOL_OPTION_KEEP_INTERMEDIATES (see below) to 21336ac495dSmrg see the results. The files are intended to be human-readable, 21436ac495dSmrg but the exact files and their formats are subject to change. 21536ac495dSmrg */ 21636ac495dSmrg GCC_JIT_BOOL_OPTION_DUMP_EVERYTHING, 21736ac495dSmrg 21836ac495dSmrg /* If true, libgccjit will aggressively run its garbage collector, to 21936ac495dSmrg shake out bugs (greatly slowing down the compile). This is likely 22036ac495dSmrg to only be of interest to developers *of* the library. It is 22136ac495dSmrg used when running the selftest suite. */ 22236ac495dSmrg GCC_JIT_BOOL_OPTION_SELFCHECK_GC, 22336ac495dSmrg 22436ac495dSmrg /* If true, gcc_jit_context_release will not clean up 22536ac495dSmrg intermediate files written to the filesystem, and will display 22636ac495dSmrg their location on stderr. */ 22736ac495dSmrg GCC_JIT_BOOL_OPTION_KEEP_INTERMEDIATES, 22836ac495dSmrg 22936ac495dSmrg GCC_JIT_NUM_BOOL_OPTIONS 23036ac495dSmrg }; 23136ac495dSmrg 23236ac495dSmrg /* Set a string option on the given context. 23336ac495dSmrg 23436ac495dSmrg The context takes a copy of the string, so the 23536ac495dSmrg (const char *) buffer is not needed anymore after the call 23636ac495dSmrg returns. */ 23736ac495dSmrg extern void 23836ac495dSmrg gcc_jit_context_set_str_option (gcc_jit_context *ctxt, 23936ac495dSmrg enum gcc_jit_str_option opt, 24036ac495dSmrg const char *value); 24136ac495dSmrg 24236ac495dSmrg /* Set an int option on the given context. */ 24336ac495dSmrg extern void 24436ac495dSmrg gcc_jit_context_set_int_option (gcc_jit_context *ctxt, 24536ac495dSmrg enum gcc_jit_int_option opt, 24636ac495dSmrg int value); 24736ac495dSmrg 24836ac495dSmrg /* Set a boolean option on the given context. 24936ac495dSmrg 25036ac495dSmrg Zero is "false" (the default), non-zero is "true". */ 25136ac495dSmrg extern void 25236ac495dSmrg gcc_jit_context_set_bool_option (gcc_jit_context *ctxt, 25336ac495dSmrg enum gcc_jit_bool_option opt, 25436ac495dSmrg int value); 25536ac495dSmrg 25636ac495dSmrg /* Options added after the initial release of libgccjit. 25736ac495dSmrg These are handled by providing an entrypoint per option, 25836ac495dSmrg rather than by extending the enum gcc_jit_*_option, 25936ac495dSmrg so that client code that use these new options can be identified 26036ac495dSmrg from binary metadata. */ 26136ac495dSmrg 26236ac495dSmrg /* By default, libgccjit will issue an error about unreachable blocks 26336ac495dSmrg within a function. 26436ac495dSmrg 26536ac495dSmrg This option can be used to disable that error. 26636ac495dSmrg 26736ac495dSmrg This entrypoint was added in LIBGCCJIT_ABI_2; you can test for 26836ac495dSmrg its presence using 26936ac495dSmrg #ifdef LIBGCCJIT_HAVE_gcc_jit_context_set_bool_allow_unreachable_blocks 27036ac495dSmrg */ 27136ac495dSmrg 27236ac495dSmrg extern void 27336ac495dSmrg gcc_jit_context_set_bool_allow_unreachable_blocks (gcc_jit_context *ctxt, 27436ac495dSmrg int bool_value); 27536ac495dSmrg 27636ac495dSmrg /* Pre-canned feature macro to indicate the presence of 27736ac495dSmrg gcc_jit_context_set_bool_allow_unreachable_blocks. This can be 27836ac495dSmrg tested for with #ifdef. */ 27936ac495dSmrg #define LIBGCCJIT_HAVE_gcc_jit_context_set_bool_allow_unreachable_blocks 28036ac495dSmrg 28136ac495dSmrg /* Implementation detail: 28236ac495dSmrg libgccjit internally generates assembler, and uses "driver" code 28336ac495dSmrg for converting it to other formats (e.g. shared libraries). 28436ac495dSmrg 28536ac495dSmrg By default, libgccjit will use an embedded copy of the driver 28636ac495dSmrg code. 28736ac495dSmrg 28836ac495dSmrg This option can be used to instead invoke an external driver executable 28936ac495dSmrg as a subprocess. 29036ac495dSmrg 29136ac495dSmrg This entrypoint was added in LIBGCCJIT_ABI_5; you can test for 29236ac495dSmrg its presence using 29336ac495dSmrg #ifdef LIBGCCJIT_HAVE_gcc_jit_context_set_bool_use_external_driver 29436ac495dSmrg */ 29536ac495dSmrg 29636ac495dSmrg extern void 29736ac495dSmrg gcc_jit_context_set_bool_use_external_driver (gcc_jit_context *ctxt, 29836ac495dSmrg int bool_value); 29936ac495dSmrg 30036ac495dSmrg /* Pre-canned feature macro to indicate the presence of 30136ac495dSmrg gcc_jit_context_set_bool_use_external_driver. This can be 30236ac495dSmrg tested for with #ifdef. */ 30336ac495dSmrg #define LIBGCCJIT_HAVE_gcc_jit_context_set_bool_use_external_driver 30436ac495dSmrg 30536ac495dSmrg /* Add an arbitrary gcc command-line option to the context. 30636ac495dSmrg The context takes a copy of the string, so the 30736ac495dSmrg (const char *) optname is not needed anymore after the call 30836ac495dSmrg returns. 30936ac495dSmrg 31036ac495dSmrg Note that only some options are likely to be meaningful; there is no 31136ac495dSmrg "frontend" within libgccjit, so typically only those affecting 31236ac495dSmrg optimization and code-generation are likely to be useful. 31336ac495dSmrg 31436ac495dSmrg This entrypoint was added in LIBGCCJIT_ABI_1; you can test for 31536ac495dSmrg its presence using 31636ac495dSmrg #ifdef LIBGCCJIT_HAVE_gcc_jit_context_add_command_line_option 31736ac495dSmrg */ 31836ac495dSmrg 31936ac495dSmrg extern void 32036ac495dSmrg gcc_jit_context_add_command_line_option (gcc_jit_context *ctxt, 32136ac495dSmrg const char *optname); 32236ac495dSmrg 32336ac495dSmrg /* Pre-canned feature-test macro for detecting the presence of 32436ac495dSmrg gcc_jit_context_add_command_line_option within libgccjit.h. */ 32536ac495dSmrg 32636ac495dSmrg #define LIBGCCJIT_HAVE_gcc_jit_context_add_command_line_option 32736ac495dSmrg 328c0a68be4Smrg /* Add an arbitrary gcc driver option to the context. 329c0a68be4Smrg The context takes a copy of the string, so the 330c0a68be4Smrg (const char *) optname is not needed anymore after the call 331c0a68be4Smrg returns. 332c0a68be4Smrg 333c0a68be4Smrg Note that only some options are likely to be meaningful; there is no 334c0a68be4Smrg "frontend" within libgccjit, so typically only those affecting 335c0a68be4Smrg assembler and linker are likely to be useful. 336c0a68be4Smrg 337c0a68be4Smrg This entrypoint was added in LIBGCCJIT_ABI_11; you can test for 338c0a68be4Smrg its presence using 339c0a68be4Smrg #ifdef LIBGCCJIT_HAVE_gcc_jit_context_add_driver_option 340c0a68be4Smrg */ 341c0a68be4Smrg extern void 342c0a68be4Smrg gcc_jit_context_add_driver_option (gcc_jit_context *ctxt, 343c0a68be4Smrg const char *optname); 344c0a68be4Smrg 345c0a68be4Smrg /* Pre-canned feature-test macro for detecting the presence of 346c0a68be4Smrg gcc_jit_context_add_driver_option within libgccjit.h. */ 347c0a68be4Smrg 348c0a68be4Smrg #define LIBGCCJIT_HAVE_gcc_jit_context_add_driver_option 349c0a68be4Smrg 35036ac495dSmrg /* Compile the context to in-memory machine code. 35136ac495dSmrg 35236ac495dSmrg This can be called more that once on a given context, 35336ac495dSmrg although any errors that occur will block further compilation. */ 35436ac495dSmrg 35536ac495dSmrg extern gcc_jit_result * 35636ac495dSmrg gcc_jit_context_compile (gcc_jit_context *ctxt); 35736ac495dSmrg 35836ac495dSmrg /* Kinds of ahead-of-time compilation, for use with 35936ac495dSmrg gcc_jit_context_compile_to_file. */ 36036ac495dSmrg 36136ac495dSmrg enum gcc_jit_output_kind 36236ac495dSmrg { 36336ac495dSmrg /* Compile the context to an assembler file. */ 36436ac495dSmrg GCC_JIT_OUTPUT_KIND_ASSEMBLER, 36536ac495dSmrg 36636ac495dSmrg /* Compile the context to an object file. */ 36736ac495dSmrg GCC_JIT_OUTPUT_KIND_OBJECT_FILE, 36836ac495dSmrg 36936ac495dSmrg /* Compile the context to a dynamic library. */ 37036ac495dSmrg GCC_JIT_OUTPUT_KIND_DYNAMIC_LIBRARY, 37136ac495dSmrg 37236ac495dSmrg /* Compile the context to an executable. */ 37336ac495dSmrg GCC_JIT_OUTPUT_KIND_EXECUTABLE 37436ac495dSmrg }; 37536ac495dSmrg 37636ac495dSmrg /* Compile the context to a file of the given kind. 37736ac495dSmrg 37836ac495dSmrg This can be called more that once on a given context, 37936ac495dSmrg although any errors that occur will block further compilation. */ 38036ac495dSmrg 38136ac495dSmrg extern void 38236ac495dSmrg gcc_jit_context_compile_to_file (gcc_jit_context *ctxt, 38336ac495dSmrg enum gcc_jit_output_kind output_kind, 38436ac495dSmrg const char *output_path); 38536ac495dSmrg 38636ac495dSmrg /* To help with debugging: dump a C-like representation to the given path, 38736ac495dSmrg describing what's been set up on the context. 38836ac495dSmrg 38936ac495dSmrg If "update_locations" is true, then also set up gcc_jit_location 39036ac495dSmrg information throughout the context, pointing at the dump file as if it 39136ac495dSmrg were a source file. This may be of use in conjunction with 39236ac495dSmrg GCC_JIT_BOOL_OPTION_DEBUGINFO to allow stepping through the code in a 39336ac495dSmrg debugger. */ 39436ac495dSmrg extern void 39536ac495dSmrg gcc_jit_context_dump_to_file (gcc_jit_context *ctxt, 39636ac495dSmrg const char *path, 39736ac495dSmrg int update_locations); 39836ac495dSmrg 39936ac495dSmrg /* To help with debugging; enable ongoing logging of the context's 40036ac495dSmrg activity to the given FILE *. 40136ac495dSmrg 40236ac495dSmrg The caller remains responsible for closing "logfile". 40336ac495dSmrg 40436ac495dSmrg Params "flags" and "verbosity" are reserved for future use, and 40536ac495dSmrg must both be 0 for now. */ 40636ac495dSmrg extern void 40736ac495dSmrg gcc_jit_context_set_logfile (gcc_jit_context *ctxt, 40836ac495dSmrg FILE *logfile, 40936ac495dSmrg int flags, 41036ac495dSmrg int verbosity); 41136ac495dSmrg 41236ac495dSmrg /* To be called after any API call, this gives the first error message 41336ac495dSmrg that occurred on the context. 41436ac495dSmrg 41536ac495dSmrg The returned string is valid for the rest of the lifetime of the 41636ac495dSmrg context. 41736ac495dSmrg 41836ac495dSmrg If no errors occurred, this will be NULL. */ 41936ac495dSmrg extern const char * 42036ac495dSmrg gcc_jit_context_get_first_error (gcc_jit_context *ctxt); 42136ac495dSmrg 42236ac495dSmrg /* To be called after any API call, this gives the last error message 42336ac495dSmrg that occurred on the context. 42436ac495dSmrg 42536ac495dSmrg If no errors occurred, this will be NULL. 42636ac495dSmrg 42736ac495dSmrg If non-NULL, the returned string is only guaranteed to be valid until 42836ac495dSmrg the next call to libgccjit relating to this context. */ 42936ac495dSmrg extern const char * 43036ac495dSmrg gcc_jit_context_get_last_error (gcc_jit_context *ctxt); 43136ac495dSmrg 43236ac495dSmrg /* Locate a given function within the built machine code. 43336ac495dSmrg This will need to be cast to a function pointer of the 43436ac495dSmrg correct type before it can be called. */ 43536ac495dSmrg extern void * 43636ac495dSmrg gcc_jit_result_get_code (gcc_jit_result *result, 43736ac495dSmrg const char *funcname); 43836ac495dSmrg 43936ac495dSmrg /* Locate a given global within the built machine code. 44036ac495dSmrg It must have been created using GCC_JIT_GLOBAL_EXPORTED. 44136ac495dSmrg This is a ptr to the global, so e.g. for an int this is an int *. */ 44236ac495dSmrg extern void * 44336ac495dSmrg gcc_jit_result_get_global (gcc_jit_result *result, 44436ac495dSmrg const char *name); 44536ac495dSmrg 44636ac495dSmrg /* Once we're done with the code, this unloads the built .so file. 44736ac495dSmrg This cleans up the result; after calling this, it's no longer 44836ac495dSmrg valid to use the result. */ 44936ac495dSmrg extern void 45036ac495dSmrg gcc_jit_result_release (gcc_jit_result *result); 45136ac495dSmrg 45236ac495dSmrg 45336ac495dSmrg /********************************************************************** 45436ac495dSmrg Functions for creating "contextual" objects. 45536ac495dSmrg 45636ac495dSmrg All objects created by these functions share the lifetime of the context 45736ac495dSmrg they are created within, and are automatically cleaned up for you when 45836ac495dSmrg you call gcc_jit_context_release on the context. 45936ac495dSmrg 46036ac495dSmrg Note that this means you can't use references to them after you've 46136ac495dSmrg released their context. 46236ac495dSmrg 46336ac495dSmrg All (const char *) string arguments passed to these functions are 46436ac495dSmrg copied, so you don't need to keep them around. 46536ac495dSmrg 46636ac495dSmrg You create code by adding a sequence of statements to blocks. 46736ac495dSmrg **********************************************************************/ 46836ac495dSmrg 46936ac495dSmrg /********************************************************************** 47036ac495dSmrg The base class of "contextual" object. 47136ac495dSmrg **********************************************************************/ 47236ac495dSmrg /* Which context is "obj" within? */ 47336ac495dSmrg extern gcc_jit_context * 47436ac495dSmrg gcc_jit_object_get_context (gcc_jit_object *obj); 47536ac495dSmrg 47636ac495dSmrg /* Get a human-readable description of this object. 47736ac495dSmrg The string buffer is created the first time this is called on a given 47836ac495dSmrg object, and persists until the object's context is released. */ 47936ac495dSmrg extern const char * 48036ac495dSmrg gcc_jit_object_get_debug_string (gcc_jit_object *obj); 48136ac495dSmrg 48236ac495dSmrg /********************************************************************** 48336ac495dSmrg Debugging information. 48436ac495dSmrg **********************************************************************/ 48536ac495dSmrg 48636ac495dSmrg /* Creating source code locations for use by the debugger. 48736ac495dSmrg Line and column numbers are 1-based. */ 48836ac495dSmrg extern gcc_jit_location * 48936ac495dSmrg gcc_jit_context_new_location (gcc_jit_context *ctxt, 49036ac495dSmrg const char *filename, 49136ac495dSmrg int line, 49236ac495dSmrg int column); 49336ac495dSmrg 49436ac495dSmrg /* Upcasting from location to object. */ 49536ac495dSmrg extern gcc_jit_object * 49636ac495dSmrg gcc_jit_location_as_object (gcc_jit_location *loc); 49736ac495dSmrg 49836ac495dSmrg 49936ac495dSmrg /********************************************************************** 50036ac495dSmrg Types. 50136ac495dSmrg **********************************************************************/ 50236ac495dSmrg 50336ac495dSmrg /* Upcasting from type to object. */ 50436ac495dSmrg extern gcc_jit_object * 50536ac495dSmrg gcc_jit_type_as_object (gcc_jit_type *type); 50636ac495dSmrg 50736ac495dSmrg /* Access to specific types. */ 50836ac495dSmrg enum gcc_jit_types 50936ac495dSmrg { 51036ac495dSmrg /* C's "void" type. */ 51136ac495dSmrg GCC_JIT_TYPE_VOID, 51236ac495dSmrg 51336ac495dSmrg /* "void *". */ 51436ac495dSmrg GCC_JIT_TYPE_VOID_PTR, 51536ac495dSmrg 51636ac495dSmrg /* C++'s bool type; also C99's "_Bool" type, aka "bool" if using 51736ac495dSmrg stdbool.h. */ 51836ac495dSmrg GCC_JIT_TYPE_BOOL, 51936ac495dSmrg 52036ac495dSmrg /* Various integer types. */ 52136ac495dSmrg 52236ac495dSmrg /* C's "char" (of some signedness) and the variants where the 52336ac495dSmrg signedness is specified. */ 52436ac495dSmrg GCC_JIT_TYPE_CHAR, 52536ac495dSmrg GCC_JIT_TYPE_SIGNED_CHAR, 52636ac495dSmrg GCC_JIT_TYPE_UNSIGNED_CHAR, 52736ac495dSmrg 52836ac495dSmrg /* C's "short" and "unsigned short". */ 52936ac495dSmrg GCC_JIT_TYPE_SHORT, /* signed */ 53036ac495dSmrg GCC_JIT_TYPE_UNSIGNED_SHORT, 53136ac495dSmrg 53236ac495dSmrg /* C's "int" and "unsigned int". */ 53336ac495dSmrg GCC_JIT_TYPE_INT, /* signed */ 53436ac495dSmrg GCC_JIT_TYPE_UNSIGNED_INT, 53536ac495dSmrg 53636ac495dSmrg /* C's "long" and "unsigned long". */ 53736ac495dSmrg GCC_JIT_TYPE_LONG, /* signed */ 53836ac495dSmrg GCC_JIT_TYPE_UNSIGNED_LONG, 53936ac495dSmrg 54036ac495dSmrg /* C99's "long long" and "unsigned long long". */ 54136ac495dSmrg GCC_JIT_TYPE_LONG_LONG, /* signed */ 54236ac495dSmrg GCC_JIT_TYPE_UNSIGNED_LONG_LONG, 54336ac495dSmrg 54436ac495dSmrg /* Floating-point types */ 54536ac495dSmrg 54636ac495dSmrg GCC_JIT_TYPE_FLOAT, 54736ac495dSmrg GCC_JIT_TYPE_DOUBLE, 54836ac495dSmrg GCC_JIT_TYPE_LONG_DOUBLE, 54936ac495dSmrg 55036ac495dSmrg /* C type: (const char *). */ 55136ac495dSmrg GCC_JIT_TYPE_CONST_CHAR_PTR, 55236ac495dSmrg 55336ac495dSmrg /* The C "size_t" type. */ 55436ac495dSmrg GCC_JIT_TYPE_SIZE_T, 55536ac495dSmrg 55636ac495dSmrg /* C type: (FILE *) */ 55736ac495dSmrg GCC_JIT_TYPE_FILE_PTR, 55836ac495dSmrg 55936ac495dSmrg /* Complex numbers. */ 56036ac495dSmrg GCC_JIT_TYPE_COMPLEX_FLOAT, 56136ac495dSmrg GCC_JIT_TYPE_COMPLEX_DOUBLE, 56236ac495dSmrg GCC_JIT_TYPE_COMPLEX_LONG_DOUBLE 56336ac495dSmrg 56436ac495dSmrg }; 56536ac495dSmrg 56636ac495dSmrg extern gcc_jit_type * 56736ac495dSmrg gcc_jit_context_get_type (gcc_jit_context *ctxt, 56836ac495dSmrg enum gcc_jit_types type_); 56936ac495dSmrg 57036ac495dSmrg /* Get the integer type of the given size and signedness. */ 57136ac495dSmrg extern gcc_jit_type * 57236ac495dSmrg gcc_jit_context_get_int_type (gcc_jit_context *ctxt, 57336ac495dSmrg int num_bytes, int is_signed); 57436ac495dSmrg 57536ac495dSmrg /* Constructing new types. */ 57636ac495dSmrg 57736ac495dSmrg /* Given type "T", get type "T*". */ 57836ac495dSmrg extern gcc_jit_type * 57936ac495dSmrg gcc_jit_type_get_pointer (gcc_jit_type *type); 58036ac495dSmrg 58136ac495dSmrg /* Given type "T", get type "const T". */ 58236ac495dSmrg extern gcc_jit_type * 58336ac495dSmrg gcc_jit_type_get_const (gcc_jit_type *type); 58436ac495dSmrg 58536ac495dSmrg /* Given type "T", get type "volatile T". */ 58636ac495dSmrg extern gcc_jit_type * 58736ac495dSmrg gcc_jit_type_get_volatile (gcc_jit_type *type); 58836ac495dSmrg 58936ac495dSmrg /* Given type "T", get type "T[N]" (for a constant N). */ 59036ac495dSmrg extern gcc_jit_type * 59136ac495dSmrg gcc_jit_context_new_array_type (gcc_jit_context *ctxt, 59236ac495dSmrg gcc_jit_location *loc, 59336ac495dSmrg gcc_jit_type *element_type, 59436ac495dSmrg int num_elements); 59536ac495dSmrg 59636ac495dSmrg /* Struct-handling. */ 59736ac495dSmrg 59836ac495dSmrg /* Create a field, for use within a struct or union. */ 59936ac495dSmrg extern gcc_jit_field * 60036ac495dSmrg gcc_jit_context_new_field (gcc_jit_context *ctxt, 60136ac495dSmrg gcc_jit_location *loc, 60236ac495dSmrg gcc_jit_type *type, 60336ac495dSmrg const char *name); 60436ac495dSmrg 605*8feb0f0bSmrg #define LIBGCCJIT_HAVE_gcc_jit_context_new_bitfield 606*8feb0f0bSmrg 607*8feb0f0bSmrg /* Create a bit field, for use within a struct or union. 608*8feb0f0bSmrg 609*8feb0f0bSmrg This API entrypoint was added in LIBGCCJIT_ABI_12; you can test for its 610*8feb0f0bSmrg presence using 611*8feb0f0bSmrg #ifdef LIBGCCJIT_HAVE_gcc_jit_context_new_bitfield 612*8feb0f0bSmrg */ 613*8feb0f0bSmrg extern gcc_jit_field * 614*8feb0f0bSmrg gcc_jit_context_new_bitfield (gcc_jit_context *ctxt, 615*8feb0f0bSmrg gcc_jit_location *loc, 616*8feb0f0bSmrg gcc_jit_type *type, 617*8feb0f0bSmrg int width, 618*8feb0f0bSmrg const char *name); 619*8feb0f0bSmrg 62036ac495dSmrg /* Upcasting from field to object. */ 62136ac495dSmrg extern gcc_jit_object * 62236ac495dSmrg gcc_jit_field_as_object (gcc_jit_field *field); 62336ac495dSmrg 62436ac495dSmrg /* Create a struct type from an array of fields. */ 62536ac495dSmrg extern gcc_jit_struct * 62636ac495dSmrg gcc_jit_context_new_struct_type (gcc_jit_context *ctxt, 62736ac495dSmrg gcc_jit_location *loc, 62836ac495dSmrg const char *name, 62936ac495dSmrg int num_fields, 63036ac495dSmrg gcc_jit_field **fields); 63136ac495dSmrg 63236ac495dSmrg /* Create an opaque struct type. */ 63336ac495dSmrg extern gcc_jit_struct * 63436ac495dSmrg gcc_jit_context_new_opaque_struct (gcc_jit_context *ctxt, 63536ac495dSmrg gcc_jit_location *loc, 63636ac495dSmrg const char *name); 63736ac495dSmrg 63836ac495dSmrg /* Upcast a struct to a type. */ 63936ac495dSmrg extern gcc_jit_type * 64036ac495dSmrg gcc_jit_struct_as_type (gcc_jit_struct *struct_type); 64136ac495dSmrg 64236ac495dSmrg /* Populating the fields of a formerly-opaque struct type. 64336ac495dSmrg This can only be called once on a given struct type. */ 64436ac495dSmrg extern void 64536ac495dSmrg gcc_jit_struct_set_fields (gcc_jit_struct *struct_type, 64636ac495dSmrg gcc_jit_location *loc, 64736ac495dSmrg int num_fields, 64836ac495dSmrg gcc_jit_field **fields); 64936ac495dSmrg 65036ac495dSmrg /* Unions work similarly to structs. */ 65136ac495dSmrg extern gcc_jit_type * 65236ac495dSmrg gcc_jit_context_new_union_type (gcc_jit_context *ctxt, 65336ac495dSmrg gcc_jit_location *loc, 65436ac495dSmrg const char *name, 65536ac495dSmrg int num_fields, 65636ac495dSmrg gcc_jit_field **fields); 65736ac495dSmrg 65836ac495dSmrg /* Function pointers. */ 65936ac495dSmrg 66036ac495dSmrg extern gcc_jit_type * 66136ac495dSmrg gcc_jit_context_new_function_ptr_type (gcc_jit_context *ctxt, 66236ac495dSmrg gcc_jit_location *loc, 66336ac495dSmrg gcc_jit_type *return_type, 66436ac495dSmrg int num_params, 66536ac495dSmrg gcc_jit_type **param_types, 66636ac495dSmrg int is_variadic); 66736ac495dSmrg 66836ac495dSmrg /********************************************************************** 66936ac495dSmrg Constructing functions. 67036ac495dSmrg **********************************************************************/ 67136ac495dSmrg /* Create a function param. */ 67236ac495dSmrg extern gcc_jit_param * 67336ac495dSmrg gcc_jit_context_new_param (gcc_jit_context *ctxt, 67436ac495dSmrg gcc_jit_location *loc, 67536ac495dSmrg gcc_jit_type *type, 67636ac495dSmrg const char *name); 67736ac495dSmrg 67836ac495dSmrg /* Upcasting from param to object. */ 67936ac495dSmrg extern gcc_jit_object * 68036ac495dSmrg gcc_jit_param_as_object (gcc_jit_param *param); 68136ac495dSmrg 68236ac495dSmrg /* Upcasting from param to lvalue. */ 68336ac495dSmrg extern gcc_jit_lvalue * 68436ac495dSmrg gcc_jit_param_as_lvalue (gcc_jit_param *param); 68536ac495dSmrg 68636ac495dSmrg /* Upcasting from param to rvalue. */ 68736ac495dSmrg extern gcc_jit_rvalue * 68836ac495dSmrg gcc_jit_param_as_rvalue (gcc_jit_param *param); 68936ac495dSmrg 69036ac495dSmrg /* Kinds of function. */ 69136ac495dSmrg enum gcc_jit_function_kind 69236ac495dSmrg { 69336ac495dSmrg /* Function is defined by the client code and visible 69436ac495dSmrg by name outside of the JIT. */ 69536ac495dSmrg GCC_JIT_FUNCTION_EXPORTED, 69636ac495dSmrg 69736ac495dSmrg /* Function is defined by the client code, but is invisible 69836ac495dSmrg outside of the JIT. Analogous to a "static" function. */ 69936ac495dSmrg GCC_JIT_FUNCTION_INTERNAL, 70036ac495dSmrg 70136ac495dSmrg /* Function is not defined by the client code; we're merely 70236ac495dSmrg referring to it. Analogous to using an "extern" function from a 70336ac495dSmrg header file. */ 70436ac495dSmrg GCC_JIT_FUNCTION_IMPORTED, 70536ac495dSmrg 70636ac495dSmrg /* Function is only ever inlined into other functions, and is 70736ac495dSmrg invisible outside of the JIT. 70836ac495dSmrg 70936ac495dSmrg Analogous to prefixing with "inline" and adding 71036ac495dSmrg __attribute__((always_inline)). 71136ac495dSmrg 71236ac495dSmrg Inlining will only occur when the optimization level is 71336ac495dSmrg above 0; when optimization is off, this is essentially the 71436ac495dSmrg same as GCC_JIT_FUNCTION_INTERNAL. */ 71536ac495dSmrg GCC_JIT_FUNCTION_ALWAYS_INLINE 71636ac495dSmrg }; 71736ac495dSmrg 71836ac495dSmrg /* Create a function. */ 71936ac495dSmrg extern gcc_jit_function * 72036ac495dSmrg gcc_jit_context_new_function (gcc_jit_context *ctxt, 72136ac495dSmrg gcc_jit_location *loc, 72236ac495dSmrg enum gcc_jit_function_kind kind, 72336ac495dSmrg gcc_jit_type *return_type, 72436ac495dSmrg const char *name, 72536ac495dSmrg int num_params, 72636ac495dSmrg gcc_jit_param **params, 72736ac495dSmrg int is_variadic); 72836ac495dSmrg 72936ac495dSmrg /* Create a reference to a builtin function (sometimes called 73036ac495dSmrg intrinsic functions). */ 73136ac495dSmrg extern gcc_jit_function * 73236ac495dSmrg gcc_jit_context_get_builtin_function (gcc_jit_context *ctxt, 73336ac495dSmrg const char *name); 73436ac495dSmrg 73536ac495dSmrg /* Upcasting from function to object. */ 73636ac495dSmrg extern gcc_jit_object * 73736ac495dSmrg gcc_jit_function_as_object (gcc_jit_function *func); 73836ac495dSmrg 73936ac495dSmrg /* Get a specific param of a function by index. */ 74036ac495dSmrg extern gcc_jit_param * 74136ac495dSmrg gcc_jit_function_get_param (gcc_jit_function *func, int index); 74236ac495dSmrg 74336ac495dSmrg /* Emit the function in graphviz format. */ 74436ac495dSmrg extern void 74536ac495dSmrg gcc_jit_function_dump_to_dot (gcc_jit_function *func, 74636ac495dSmrg const char *path); 74736ac495dSmrg 74836ac495dSmrg /* Create a block. 74936ac495dSmrg 75036ac495dSmrg The name can be NULL, or you can give it a meaningful name, which 75136ac495dSmrg may show up in dumps of the internal representation, and in error 75236ac495dSmrg messages. */ 75336ac495dSmrg extern gcc_jit_block * 75436ac495dSmrg gcc_jit_function_new_block (gcc_jit_function *func, 75536ac495dSmrg const char *name); 75636ac495dSmrg 75736ac495dSmrg /* Upcasting from block to object. */ 75836ac495dSmrg extern gcc_jit_object * 75936ac495dSmrg gcc_jit_block_as_object (gcc_jit_block *block); 76036ac495dSmrg 76136ac495dSmrg /* Which function is this block within? */ 76236ac495dSmrg extern gcc_jit_function * 76336ac495dSmrg gcc_jit_block_get_function (gcc_jit_block *block); 76436ac495dSmrg 76536ac495dSmrg /********************************************************************** 76636ac495dSmrg lvalues, rvalues and expressions. 76736ac495dSmrg **********************************************************************/ 76836ac495dSmrg enum gcc_jit_global_kind 76936ac495dSmrg { 77036ac495dSmrg /* Global is defined by the client code and visible 77136ac495dSmrg by name outside of this JIT context via gcc_jit_result_get_global. */ 77236ac495dSmrg GCC_JIT_GLOBAL_EXPORTED, 77336ac495dSmrg 77436ac495dSmrg /* Global is defined by the client code, but is invisible 77536ac495dSmrg outside of this JIT context. Analogous to a "static" global. */ 77636ac495dSmrg GCC_JIT_GLOBAL_INTERNAL, 77736ac495dSmrg 77836ac495dSmrg /* Global is not defined by the client code; we're merely 77936ac495dSmrg referring to it. Analogous to using an "extern" global from a 78036ac495dSmrg header file. */ 78136ac495dSmrg GCC_JIT_GLOBAL_IMPORTED 78236ac495dSmrg }; 78336ac495dSmrg 78436ac495dSmrg extern gcc_jit_lvalue * 78536ac495dSmrg gcc_jit_context_new_global (gcc_jit_context *ctxt, 78636ac495dSmrg gcc_jit_location *loc, 78736ac495dSmrg enum gcc_jit_global_kind kind, 78836ac495dSmrg gcc_jit_type *type, 78936ac495dSmrg const char *name); 79036ac495dSmrg 79136ac495dSmrg /* Upcasting. */ 79236ac495dSmrg extern gcc_jit_object * 79336ac495dSmrg gcc_jit_lvalue_as_object (gcc_jit_lvalue *lvalue); 79436ac495dSmrg 79536ac495dSmrg extern gcc_jit_rvalue * 79636ac495dSmrg gcc_jit_lvalue_as_rvalue (gcc_jit_lvalue *lvalue); 79736ac495dSmrg 79836ac495dSmrg extern gcc_jit_object * 79936ac495dSmrg gcc_jit_rvalue_as_object (gcc_jit_rvalue *rvalue); 80036ac495dSmrg 80136ac495dSmrg extern gcc_jit_type * 80236ac495dSmrg gcc_jit_rvalue_get_type (gcc_jit_rvalue *rvalue); 80336ac495dSmrg 80436ac495dSmrg /* Integer constants. */ 80536ac495dSmrg extern gcc_jit_rvalue * 80636ac495dSmrg gcc_jit_context_new_rvalue_from_int (gcc_jit_context *ctxt, 80736ac495dSmrg gcc_jit_type *numeric_type, 80836ac495dSmrg int value); 80936ac495dSmrg 81036ac495dSmrg extern gcc_jit_rvalue * 81136ac495dSmrg gcc_jit_context_new_rvalue_from_long (gcc_jit_context *ctxt, 81236ac495dSmrg gcc_jit_type *numeric_type, 81336ac495dSmrg long value); 81436ac495dSmrg 81536ac495dSmrg extern gcc_jit_rvalue * 81636ac495dSmrg gcc_jit_context_zero (gcc_jit_context *ctxt, 81736ac495dSmrg gcc_jit_type *numeric_type); 81836ac495dSmrg 81936ac495dSmrg extern gcc_jit_rvalue * 82036ac495dSmrg gcc_jit_context_one (gcc_jit_context *ctxt, 82136ac495dSmrg gcc_jit_type *numeric_type); 82236ac495dSmrg 82336ac495dSmrg /* Floating-point constants. */ 82436ac495dSmrg extern gcc_jit_rvalue * 82536ac495dSmrg gcc_jit_context_new_rvalue_from_double (gcc_jit_context *ctxt, 82636ac495dSmrg gcc_jit_type *numeric_type, 82736ac495dSmrg double value); 82836ac495dSmrg 82936ac495dSmrg /* Pointers. */ 83036ac495dSmrg extern gcc_jit_rvalue * 83136ac495dSmrg gcc_jit_context_new_rvalue_from_ptr (gcc_jit_context *ctxt, 83236ac495dSmrg gcc_jit_type *pointer_type, 83336ac495dSmrg void *value); 83436ac495dSmrg 83536ac495dSmrg extern gcc_jit_rvalue * 83636ac495dSmrg gcc_jit_context_null (gcc_jit_context *ctxt, 83736ac495dSmrg gcc_jit_type *pointer_type); 83836ac495dSmrg 83936ac495dSmrg /* String literals. */ 84036ac495dSmrg extern gcc_jit_rvalue * 84136ac495dSmrg gcc_jit_context_new_string_literal (gcc_jit_context *ctxt, 84236ac495dSmrg const char *value); 84336ac495dSmrg 84436ac495dSmrg enum gcc_jit_unary_op 84536ac495dSmrg { 84636ac495dSmrg /* Negate an arithmetic value; analogous to: 84736ac495dSmrg -(EXPR) 84836ac495dSmrg in C. */ 84936ac495dSmrg GCC_JIT_UNARY_OP_MINUS, 85036ac495dSmrg 85136ac495dSmrg /* Bitwise negation of an integer value (one's complement); analogous 85236ac495dSmrg to: 85336ac495dSmrg ~(EXPR) 85436ac495dSmrg in C. */ 85536ac495dSmrg GCC_JIT_UNARY_OP_BITWISE_NEGATE, 85636ac495dSmrg 85736ac495dSmrg /* Logical negation of an arithmetic or pointer value; analogous to: 85836ac495dSmrg !(EXPR) 85936ac495dSmrg in C. */ 86036ac495dSmrg GCC_JIT_UNARY_OP_LOGICAL_NEGATE, 86136ac495dSmrg 86236ac495dSmrg /* Absolute value of an arithmetic expression; analogous to: 86336ac495dSmrg abs (EXPR) 86436ac495dSmrg in C. */ 86536ac495dSmrg GCC_JIT_UNARY_OP_ABS 86636ac495dSmrg 86736ac495dSmrg }; 86836ac495dSmrg 86936ac495dSmrg extern gcc_jit_rvalue * 87036ac495dSmrg gcc_jit_context_new_unary_op (gcc_jit_context *ctxt, 87136ac495dSmrg gcc_jit_location *loc, 87236ac495dSmrg enum gcc_jit_unary_op op, 87336ac495dSmrg gcc_jit_type *result_type, 87436ac495dSmrg gcc_jit_rvalue *rvalue); 87536ac495dSmrg 87636ac495dSmrg enum gcc_jit_binary_op 87736ac495dSmrg { 87836ac495dSmrg /* Addition of arithmetic values; analogous to: 87936ac495dSmrg (EXPR_A) + (EXPR_B) 88036ac495dSmrg in C. 88136ac495dSmrg For pointer addition, use gcc_jit_context_new_array_access. */ 88236ac495dSmrg GCC_JIT_BINARY_OP_PLUS, 88336ac495dSmrg 88436ac495dSmrg /* Subtraction of arithmetic values; analogous to: 88536ac495dSmrg (EXPR_A) - (EXPR_B) 88636ac495dSmrg in C. */ 88736ac495dSmrg GCC_JIT_BINARY_OP_MINUS, 88836ac495dSmrg 88936ac495dSmrg /* Multiplication of a pair of arithmetic values; analogous to: 89036ac495dSmrg (EXPR_A) * (EXPR_B) 89136ac495dSmrg in C. */ 89236ac495dSmrg GCC_JIT_BINARY_OP_MULT, 89336ac495dSmrg 89436ac495dSmrg /* Quotient of division of arithmetic values; analogous to: 89536ac495dSmrg (EXPR_A) / (EXPR_B) 89636ac495dSmrg in C. 89736ac495dSmrg The result type affects the kind of division: if the result type is 89836ac495dSmrg integer-based, then the result is truncated towards zero, whereas 89936ac495dSmrg a floating-point result type indicates floating-point division. */ 90036ac495dSmrg GCC_JIT_BINARY_OP_DIVIDE, 90136ac495dSmrg 90236ac495dSmrg /* Remainder of division of arithmetic values; analogous to: 90336ac495dSmrg (EXPR_A) % (EXPR_B) 90436ac495dSmrg in C. */ 90536ac495dSmrg GCC_JIT_BINARY_OP_MODULO, 90636ac495dSmrg 90736ac495dSmrg /* Bitwise AND; analogous to: 90836ac495dSmrg (EXPR_A) & (EXPR_B) 90936ac495dSmrg in C. */ 91036ac495dSmrg GCC_JIT_BINARY_OP_BITWISE_AND, 91136ac495dSmrg 91236ac495dSmrg /* Bitwise exclusive OR; analogous to: 91336ac495dSmrg (EXPR_A) ^ (EXPR_B) 91436ac495dSmrg in C. */ 91536ac495dSmrg GCC_JIT_BINARY_OP_BITWISE_XOR, 91636ac495dSmrg 91736ac495dSmrg /* Bitwise inclusive OR; analogous to: 91836ac495dSmrg (EXPR_A) | (EXPR_B) 91936ac495dSmrg in C. */ 92036ac495dSmrg GCC_JIT_BINARY_OP_BITWISE_OR, 92136ac495dSmrg 92236ac495dSmrg /* Logical AND; analogous to: 92336ac495dSmrg (EXPR_A) && (EXPR_B) 92436ac495dSmrg in C. */ 92536ac495dSmrg GCC_JIT_BINARY_OP_LOGICAL_AND, 92636ac495dSmrg 92736ac495dSmrg /* Logical OR; analogous to: 92836ac495dSmrg (EXPR_A) || (EXPR_B) 92936ac495dSmrg in C. */ 93036ac495dSmrg GCC_JIT_BINARY_OP_LOGICAL_OR, 93136ac495dSmrg 93236ac495dSmrg /* Left shift; analogous to: 93336ac495dSmrg (EXPR_A) << (EXPR_B) 93436ac495dSmrg in C. */ 93536ac495dSmrg GCC_JIT_BINARY_OP_LSHIFT, 93636ac495dSmrg 93736ac495dSmrg /* Right shift; analogous to: 93836ac495dSmrg (EXPR_A) >> (EXPR_B) 93936ac495dSmrg in C. */ 94036ac495dSmrg GCC_JIT_BINARY_OP_RSHIFT 94136ac495dSmrg }; 94236ac495dSmrg 94336ac495dSmrg extern gcc_jit_rvalue * 94436ac495dSmrg gcc_jit_context_new_binary_op (gcc_jit_context *ctxt, 94536ac495dSmrg gcc_jit_location *loc, 94636ac495dSmrg enum gcc_jit_binary_op op, 94736ac495dSmrg gcc_jit_type *result_type, 94836ac495dSmrg gcc_jit_rvalue *a, gcc_jit_rvalue *b); 94936ac495dSmrg 95036ac495dSmrg /* (Comparisons are treated as separate from "binary_op" to save 95136ac495dSmrg you having to specify the result_type). */ 95236ac495dSmrg 95336ac495dSmrg enum gcc_jit_comparison 95436ac495dSmrg { 95536ac495dSmrg /* (EXPR_A) == (EXPR_B). */ 95636ac495dSmrg GCC_JIT_COMPARISON_EQ, 95736ac495dSmrg 95836ac495dSmrg /* (EXPR_A) != (EXPR_B). */ 95936ac495dSmrg GCC_JIT_COMPARISON_NE, 96036ac495dSmrg 96136ac495dSmrg /* (EXPR_A) < (EXPR_B). */ 96236ac495dSmrg GCC_JIT_COMPARISON_LT, 96336ac495dSmrg 96436ac495dSmrg /* (EXPR_A) <=(EXPR_B). */ 96536ac495dSmrg GCC_JIT_COMPARISON_LE, 96636ac495dSmrg 96736ac495dSmrg /* (EXPR_A) > (EXPR_B). */ 96836ac495dSmrg GCC_JIT_COMPARISON_GT, 96936ac495dSmrg 97036ac495dSmrg /* (EXPR_A) >= (EXPR_B). */ 97136ac495dSmrg GCC_JIT_COMPARISON_GE 97236ac495dSmrg }; 97336ac495dSmrg 97436ac495dSmrg extern gcc_jit_rvalue * 97536ac495dSmrg gcc_jit_context_new_comparison (gcc_jit_context *ctxt, 97636ac495dSmrg gcc_jit_location *loc, 97736ac495dSmrg enum gcc_jit_comparison op, 97836ac495dSmrg gcc_jit_rvalue *a, gcc_jit_rvalue *b); 97936ac495dSmrg 98036ac495dSmrg /* Function calls. */ 98136ac495dSmrg 98236ac495dSmrg /* Call of a specific function. */ 98336ac495dSmrg extern gcc_jit_rvalue * 98436ac495dSmrg gcc_jit_context_new_call (gcc_jit_context *ctxt, 98536ac495dSmrg gcc_jit_location *loc, 98636ac495dSmrg gcc_jit_function *func, 98736ac495dSmrg int numargs , gcc_jit_rvalue **args); 98836ac495dSmrg 98936ac495dSmrg /* Call through a function pointer. */ 99036ac495dSmrg extern gcc_jit_rvalue * 99136ac495dSmrg gcc_jit_context_new_call_through_ptr (gcc_jit_context *ctxt, 99236ac495dSmrg gcc_jit_location *loc, 99336ac495dSmrg gcc_jit_rvalue *fn_ptr, 99436ac495dSmrg int numargs, gcc_jit_rvalue **args); 99536ac495dSmrg 99636ac495dSmrg /* Type-coercion. 99736ac495dSmrg 99836ac495dSmrg Currently only a limited set of conversions are possible: 99936ac495dSmrg int <-> float 100036ac495dSmrg int <-> bool */ 100136ac495dSmrg extern gcc_jit_rvalue * 100236ac495dSmrg gcc_jit_context_new_cast (gcc_jit_context *ctxt, 100336ac495dSmrg gcc_jit_location *loc, 100436ac495dSmrg gcc_jit_rvalue *rvalue, 100536ac495dSmrg gcc_jit_type *type); 100636ac495dSmrg 100736ac495dSmrg extern gcc_jit_lvalue * 100836ac495dSmrg gcc_jit_context_new_array_access (gcc_jit_context *ctxt, 100936ac495dSmrg gcc_jit_location *loc, 101036ac495dSmrg gcc_jit_rvalue *ptr, 101136ac495dSmrg gcc_jit_rvalue *index); 101236ac495dSmrg 101336ac495dSmrg /* Field access is provided separately for both lvalues and rvalues. */ 101436ac495dSmrg 101536ac495dSmrg /* Accessing a field of an lvalue of struct type, analogous to: 101636ac495dSmrg (EXPR).field = ...; 101736ac495dSmrg in C. */ 101836ac495dSmrg extern gcc_jit_lvalue * 101936ac495dSmrg gcc_jit_lvalue_access_field (gcc_jit_lvalue *struct_or_union, 102036ac495dSmrg gcc_jit_location *loc, 102136ac495dSmrg gcc_jit_field *field); 102236ac495dSmrg 102336ac495dSmrg /* Accessing a field of an rvalue of struct type, analogous to: 102436ac495dSmrg (EXPR).field 102536ac495dSmrg in C. */ 102636ac495dSmrg extern gcc_jit_rvalue * 102736ac495dSmrg gcc_jit_rvalue_access_field (gcc_jit_rvalue *struct_or_union, 102836ac495dSmrg gcc_jit_location *loc, 102936ac495dSmrg gcc_jit_field *field); 103036ac495dSmrg 103136ac495dSmrg /* Accessing a field of an rvalue of pointer type, analogous to: 103236ac495dSmrg (EXPR)->field 103336ac495dSmrg in C, itself equivalent to (*EXPR).FIELD */ 103436ac495dSmrg extern gcc_jit_lvalue * 103536ac495dSmrg gcc_jit_rvalue_dereference_field (gcc_jit_rvalue *ptr, 103636ac495dSmrg gcc_jit_location *loc, 103736ac495dSmrg gcc_jit_field *field); 103836ac495dSmrg 103936ac495dSmrg /* Dereferencing a pointer; analogous to: 104036ac495dSmrg *(EXPR) 104136ac495dSmrg */ 104236ac495dSmrg extern gcc_jit_lvalue * 104336ac495dSmrg gcc_jit_rvalue_dereference (gcc_jit_rvalue *rvalue, 104436ac495dSmrg gcc_jit_location *loc); 104536ac495dSmrg 104636ac495dSmrg /* Taking the address of an lvalue; analogous to: 104736ac495dSmrg &(EXPR) 104836ac495dSmrg in C. */ 104936ac495dSmrg extern gcc_jit_rvalue * 105036ac495dSmrg gcc_jit_lvalue_get_address (gcc_jit_lvalue *lvalue, 105136ac495dSmrg gcc_jit_location *loc); 105236ac495dSmrg 105336ac495dSmrg extern gcc_jit_lvalue * 105436ac495dSmrg gcc_jit_function_new_local (gcc_jit_function *func, 105536ac495dSmrg gcc_jit_location *loc, 105636ac495dSmrg gcc_jit_type *type, 105736ac495dSmrg const char *name); 105836ac495dSmrg 105936ac495dSmrg /********************************************************************** 106036ac495dSmrg Statement-creation. 106136ac495dSmrg **********************************************************************/ 106236ac495dSmrg 106336ac495dSmrg /* Add evaluation of an rvalue, discarding the result 106436ac495dSmrg (e.g. a function call that "returns" void). 106536ac495dSmrg 106636ac495dSmrg This is equivalent to this C code: 106736ac495dSmrg 106836ac495dSmrg (void)expression; 106936ac495dSmrg */ 107036ac495dSmrg extern void 107136ac495dSmrg gcc_jit_block_add_eval (gcc_jit_block *block, 107236ac495dSmrg gcc_jit_location *loc, 107336ac495dSmrg gcc_jit_rvalue *rvalue); 107436ac495dSmrg 107536ac495dSmrg /* Add evaluation of an rvalue, assigning the result to the given 107636ac495dSmrg lvalue. 107736ac495dSmrg 107836ac495dSmrg This is roughly equivalent to this C code: 107936ac495dSmrg 108036ac495dSmrg lvalue = rvalue; 108136ac495dSmrg */ 108236ac495dSmrg extern void 108336ac495dSmrg gcc_jit_block_add_assignment (gcc_jit_block *block, 108436ac495dSmrg gcc_jit_location *loc, 108536ac495dSmrg gcc_jit_lvalue *lvalue, 108636ac495dSmrg gcc_jit_rvalue *rvalue); 108736ac495dSmrg 108836ac495dSmrg /* Add evaluation of an rvalue, using the result to modify an 108936ac495dSmrg lvalue. 109036ac495dSmrg 109136ac495dSmrg This is analogous to "+=" and friends: 109236ac495dSmrg 109336ac495dSmrg lvalue += rvalue; 109436ac495dSmrg lvalue *= rvalue; 109536ac495dSmrg lvalue /= rvalue; 109636ac495dSmrg etc */ 109736ac495dSmrg extern void 109836ac495dSmrg gcc_jit_block_add_assignment_op (gcc_jit_block *block, 109936ac495dSmrg gcc_jit_location *loc, 110036ac495dSmrg gcc_jit_lvalue *lvalue, 110136ac495dSmrg enum gcc_jit_binary_op op, 110236ac495dSmrg gcc_jit_rvalue *rvalue); 110336ac495dSmrg 110436ac495dSmrg /* Add a no-op textual comment to the internal representation of the 110536ac495dSmrg code. It will be optimized away, but will be visible in the dumps 110636ac495dSmrg seen via 110736ac495dSmrg GCC_JIT_BOOL_OPTION_DUMP_INITIAL_TREE 110836ac495dSmrg and 110936ac495dSmrg GCC_JIT_BOOL_OPTION_DUMP_INITIAL_GIMPLE, 111036ac495dSmrg and thus may be of use when debugging how your project's internal 111136ac495dSmrg representation gets converted to the libgccjit IR. */ 111236ac495dSmrg extern void 111336ac495dSmrg gcc_jit_block_add_comment (gcc_jit_block *block, 111436ac495dSmrg gcc_jit_location *loc, 111536ac495dSmrg const char *text); 111636ac495dSmrg 111736ac495dSmrg /* Terminate a block by adding evaluation of an rvalue, branching on the 111836ac495dSmrg result to the appropriate successor block. 111936ac495dSmrg 112036ac495dSmrg This is roughly equivalent to this C code: 112136ac495dSmrg 112236ac495dSmrg if (boolval) 112336ac495dSmrg goto on_true; 112436ac495dSmrg else 112536ac495dSmrg goto on_false; 112636ac495dSmrg 112736ac495dSmrg block, boolval, on_true, and on_false must be non-NULL. */ 112836ac495dSmrg extern void 112936ac495dSmrg gcc_jit_block_end_with_conditional (gcc_jit_block *block, 113036ac495dSmrg gcc_jit_location *loc, 113136ac495dSmrg gcc_jit_rvalue *boolval, 113236ac495dSmrg gcc_jit_block *on_true, 113336ac495dSmrg gcc_jit_block *on_false); 113436ac495dSmrg 113536ac495dSmrg /* Terminate a block by adding a jump to the given target block. 113636ac495dSmrg 113736ac495dSmrg This is roughly equivalent to this C code: 113836ac495dSmrg 113936ac495dSmrg goto target; 114036ac495dSmrg */ 114136ac495dSmrg extern void 114236ac495dSmrg gcc_jit_block_end_with_jump (gcc_jit_block *block, 114336ac495dSmrg gcc_jit_location *loc, 114436ac495dSmrg gcc_jit_block *target); 114536ac495dSmrg 114636ac495dSmrg /* Terminate a block by adding evaluation of an rvalue, returning the value. 114736ac495dSmrg 114836ac495dSmrg This is roughly equivalent to this C code: 114936ac495dSmrg 115036ac495dSmrg return expression; 115136ac495dSmrg */ 115236ac495dSmrg extern void 115336ac495dSmrg gcc_jit_block_end_with_return (gcc_jit_block *block, 115436ac495dSmrg gcc_jit_location *loc, 115536ac495dSmrg gcc_jit_rvalue *rvalue); 115636ac495dSmrg 115736ac495dSmrg /* Terminate a block by adding a valueless return, for use within a function 115836ac495dSmrg with "void" return type. 115936ac495dSmrg 116036ac495dSmrg This is equivalent to this C code: 116136ac495dSmrg 116236ac495dSmrg return; 116336ac495dSmrg */ 116436ac495dSmrg extern void 116536ac495dSmrg gcc_jit_block_end_with_void_return (gcc_jit_block *block, 116636ac495dSmrg gcc_jit_location *loc); 116736ac495dSmrg 116836ac495dSmrg /* Create a new gcc_jit_case instance for use in a switch statement. 116936ac495dSmrg min_value and max_value must be constants of integer type. 117036ac495dSmrg 117136ac495dSmrg This API entrypoint was added in LIBGCCJIT_ABI_3; you can test for its 117236ac495dSmrg presence using 117336ac495dSmrg #ifdef LIBGCCJIT_HAVE_SWITCH_STATEMENTS 117436ac495dSmrg */ 117536ac495dSmrg extern gcc_jit_case * 117636ac495dSmrg gcc_jit_context_new_case (gcc_jit_context *ctxt, 117736ac495dSmrg gcc_jit_rvalue *min_value, 117836ac495dSmrg gcc_jit_rvalue *max_value, 117936ac495dSmrg gcc_jit_block *dest_block); 118036ac495dSmrg 118136ac495dSmrg /* Upcasting from case to object. 118236ac495dSmrg 118336ac495dSmrg This API entrypoint was added in LIBGCCJIT_ABI_3; you can test for its 118436ac495dSmrg presence using 118536ac495dSmrg #ifdef LIBGCCJIT_HAVE_SWITCH_STATEMENTS 118636ac495dSmrg */ 118736ac495dSmrg 118836ac495dSmrg extern gcc_jit_object * 118936ac495dSmrg gcc_jit_case_as_object (gcc_jit_case *case_); 119036ac495dSmrg 119136ac495dSmrg /* Terminate a block by adding evalation of an rvalue, then performing 119236ac495dSmrg a multiway branch. 119336ac495dSmrg 119436ac495dSmrg This is roughly equivalent to this C code: 119536ac495dSmrg 119636ac495dSmrg switch (expr) 119736ac495dSmrg { 119836ac495dSmrg default: 119936ac495dSmrg goto default_block; 120036ac495dSmrg 120136ac495dSmrg case C0.min_value ... C0.max_value: 120236ac495dSmrg goto C0.dest_block; 120336ac495dSmrg 120436ac495dSmrg case C1.min_value ... C1.max_value: 120536ac495dSmrg goto C1.dest_block; 120636ac495dSmrg 120736ac495dSmrg ...etc... 120836ac495dSmrg 120936ac495dSmrg case C[N - 1].min_value ... C[N - 1].max_value: 121036ac495dSmrg goto C[N - 1].dest_block; 121136ac495dSmrg } 121236ac495dSmrg 121336ac495dSmrg block, expr, default_block and cases must all be non-NULL. 121436ac495dSmrg 121536ac495dSmrg expr must be of the same integer type as all of the min_value 121636ac495dSmrg and max_value within the cases. 121736ac495dSmrg 121836ac495dSmrg num_cases must be >= 0. 121936ac495dSmrg 122036ac495dSmrg The ranges of the cases must not overlap (or have duplicate 122136ac495dSmrg values). 122236ac495dSmrg 122336ac495dSmrg This API entrypoint was added in LIBGCCJIT_ABI_3; you can test for its 122436ac495dSmrg presence using 122536ac495dSmrg #ifdef LIBGCCJIT_HAVE_SWITCH_STATEMENTS 122636ac495dSmrg */ 122736ac495dSmrg 122836ac495dSmrg extern void 122936ac495dSmrg gcc_jit_block_end_with_switch (gcc_jit_block *block, 123036ac495dSmrg gcc_jit_location *loc, 123136ac495dSmrg gcc_jit_rvalue *expr, 123236ac495dSmrg gcc_jit_block *default_block, 123336ac495dSmrg int num_cases, 123436ac495dSmrg gcc_jit_case **cases); 123536ac495dSmrg 123636ac495dSmrg /* Pre-canned feature macro to indicate the presence of 123736ac495dSmrg gcc_jit_block_end_with_switch, gcc_jit_case_as_object, and 123836ac495dSmrg gcc_jit_context_new_case. 123936ac495dSmrg 124036ac495dSmrg This can be tested for with #ifdef. */ 124136ac495dSmrg #define LIBGCCJIT_HAVE_SWITCH_STATEMENTS 124236ac495dSmrg 124336ac495dSmrg /********************************************************************** 124436ac495dSmrg Nested contexts. 124536ac495dSmrg **********************************************************************/ 124636ac495dSmrg 124736ac495dSmrg /* Given an existing JIT context, create a child context. 124836ac495dSmrg 124936ac495dSmrg The child inherits a copy of all option-settings from the parent. 125036ac495dSmrg 125136ac495dSmrg The child can reference objects created within the parent, but not 125236ac495dSmrg vice-versa. 125336ac495dSmrg 125436ac495dSmrg The lifetime of the child context must be bounded by that of the 125536ac495dSmrg parent: you should release a child context before releasing the parent 125636ac495dSmrg context. 125736ac495dSmrg 125836ac495dSmrg If you use a function from a parent context within a child context, 125936ac495dSmrg you have to compile the parent context before you can compile the 126036ac495dSmrg child context, and the gcc_jit_result of the parent context must 126136ac495dSmrg outlive the gcc_jit_result of the child context. 126236ac495dSmrg 126336ac495dSmrg This allows caching of shared initializations. For example, you could 126436ac495dSmrg create types and declarations of global functions in a parent context 126536ac495dSmrg once within a process, and then create child contexts whenever a 126636ac495dSmrg function or loop becomes hot. Each such child context can be used for 126736ac495dSmrg JIT-compiling just one function or loop, but can reference types 126836ac495dSmrg and helper functions created within the parent context. 126936ac495dSmrg 127036ac495dSmrg Contexts can be arbitrarily nested, provided the above rules are 127136ac495dSmrg followed, but it's probably not worth going above 2 or 3 levels, and 127236ac495dSmrg there will likely be a performance hit for such nesting. */ 127336ac495dSmrg 127436ac495dSmrg extern gcc_jit_context * 127536ac495dSmrg gcc_jit_context_new_child_context (gcc_jit_context *parent_ctxt); 127636ac495dSmrg 127736ac495dSmrg /********************************************************************** 127836ac495dSmrg Implementation support. 127936ac495dSmrg **********************************************************************/ 128036ac495dSmrg 128136ac495dSmrg /* Write C source code into "path" that can be compiled into a 128236ac495dSmrg self-contained executable (i.e. with libgccjit as the only dependency). 128336ac495dSmrg The generated code will attempt to replay the API calls that have been 128436ac495dSmrg made into the given context. 128536ac495dSmrg 128636ac495dSmrg This may be useful when debugging the library or client code, for 128736ac495dSmrg reducing a complicated recipe for reproducing a bug into a simpler 128836ac495dSmrg form. 128936ac495dSmrg 129036ac495dSmrg Typically you need to supply the option "-Wno-unused-variable" when 129136ac495dSmrg compiling the generated file (since the result of each API call is 129236ac495dSmrg assigned to a unique variable within the generated C source, and not 129336ac495dSmrg all are necessarily then used). */ 129436ac495dSmrg 129536ac495dSmrg extern void 129636ac495dSmrg gcc_jit_context_dump_reproducer_to_file (gcc_jit_context *ctxt, 129736ac495dSmrg const char *path); 129836ac495dSmrg 129936ac495dSmrg /* Enable the dumping of a specific set of internal state from the 130036ac495dSmrg compilation, capturing the result in-memory as a buffer. 130136ac495dSmrg 130236ac495dSmrg Parameter "dumpname" corresponds to the equivalent gcc command-line 130336ac495dSmrg option, without the "-fdump-" prefix. 130436ac495dSmrg For example, to get the equivalent of "-fdump-tree-vrp1", supply 130536ac495dSmrg "tree-vrp1". 130636ac495dSmrg The context directly stores the dumpname as a (const char *), so the 130736ac495dSmrg passed string must outlive the context. 130836ac495dSmrg 130936ac495dSmrg gcc_jit_context_compile and gcc_jit_context_to_file 131036ac495dSmrg will capture the dump as a dynamically-allocated buffer, writing 131136ac495dSmrg it to ``*out_ptr``. 131236ac495dSmrg 131336ac495dSmrg The caller becomes responsible for calling 131436ac495dSmrg free (*out_ptr) 131536ac495dSmrg each time that gcc_jit_context_compile or gcc_jit_context_to_file 131636ac495dSmrg are called. *out_ptr will be written to, either with the address of a 131736ac495dSmrg buffer, or with NULL if an error occurred. 131836ac495dSmrg 131936ac495dSmrg This API entrypoint is likely to be less stable than the others. 132036ac495dSmrg In particular, both the precise dumpnames, and the format and content 132136ac495dSmrg of the dumps are subject to change. 132236ac495dSmrg 132336ac495dSmrg It exists primarily for writing the library's own test suite. */ 132436ac495dSmrg 132536ac495dSmrg extern void 132636ac495dSmrg gcc_jit_context_enable_dump (gcc_jit_context *ctxt, 132736ac495dSmrg const char *dumpname, 132836ac495dSmrg char **out_ptr); 132936ac495dSmrg 133036ac495dSmrg /********************************************************************** 133136ac495dSmrg Timing support. 133236ac495dSmrg **********************************************************************/ 133336ac495dSmrg 133436ac495dSmrg /* The timing API was added in LIBGCCJIT_ABI_4; you can test for its 133536ac495dSmrg presence using 133636ac495dSmrg #ifdef LIBGCCJIT_HAVE_TIMING_API 133736ac495dSmrg */ 133836ac495dSmrg #define LIBGCCJIT_HAVE_TIMING_API 133936ac495dSmrg 134036ac495dSmrg typedef struct gcc_jit_timer gcc_jit_timer; 134136ac495dSmrg 134236ac495dSmrg /* Create a gcc_jit_timer instance, and start timing. 134336ac495dSmrg 134436ac495dSmrg This API entrypoint was added in LIBGCCJIT_ABI_4; you can test for its 134536ac495dSmrg presence using 134636ac495dSmrg #ifdef LIBGCCJIT_HAVE_TIMING_API 134736ac495dSmrg */ 134836ac495dSmrg extern gcc_jit_timer * 134936ac495dSmrg gcc_jit_timer_new (void); 135036ac495dSmrg 135136ac495dSmrg /* Release a gcc_jit_timer instance. 135236ac495dSmrg 135336ac495dSmrg This API entrypoint was added in LIBGCCJIT_ABI_4; you can test for its 135436ac495dSmrg presence using 135536ac495dSmrg #ifdef LIBGCCJIT_HAVE_TIMING_API 135636ac495dSmrg */ 135736ac495dSmrg extern void 135836ac495dSmrg gcc_jit_timer_release (gcc_jit_timer *timer); 135936ac495dSmrg 136036ac495dSmrg /* Associate a gcc_jit_timer instance with a context. 136136ac495dSmrg 136236ac495dSmrg This API entrypoint was added in LIBGCCJIT_ABI_4; you can test for its 136336ac495dSmrg presence using 136436ac495dSmrg #ifdef LIBGCCJIT_HAVE_TIMING_API 136536ac495dSmrg */ 136636ac495dSmrg extern void 136736ac495dSmrg gcc_jit_context_set_timer (gcc_jit_context *ctxt, 136836ac495dSmrg gcc_jit_timer *timer); 136936ac495dSmrg 137036ac495dSmrg /* Get the timer associated with a context (if any). 137136ac495dSmrg 137236ac495dSmrg This API entrypoint was added in LIBGCCJIT_ABI_4; you can test for its 137336ac495dSmrg presence using 137436ac495dSmrg #ifdef LIBGCCJIT_HAVE_TIMING_API 137536ac495dSmrg */ 137636ac495dSmrg 137736ac495dSmrg extern gcc_jit_timer * 137836ac495dSmrg gcc_jit_context_get_timer (gcc_jit_context *ctxt); 137936ac495dSmrg 138036ac495dSmrg /* Push the given item onto the timing stack. 138136ac495dSmrg 138236ac495dSmrg This API entrypoint was added in LIBGCCJIT_ABI_4; you can test for its 138336ac495dSmrg presence using 138436ac495dSmrg #ifdef LIBGCCJIT_HAVE_TIMING_API 138536ac495dSmrg */ 138636ac495dSmrg 138736ac495dSmrg extern void 138836ac495dSmrg gcc_jit_timer_push (gcc_jit_timer *timer, 138936ac495dSmrg const char *item_name); 139036ac495dSmrg 139136ac495dSmrg /* Pop the top item from the timing stack. 139236ac495dSmrg 139336ac495dSmrg This API entrypoint was added in LIBGCCJIT_ABI_4; you can test for its 139436ac495dSmrg presence using 139536ac495dSmrg #ifdef LIBGCCJIT_HAVE_TIMING_API 139636ac495dSmrg */ 139736ac495dSmrg 139836ac495dSmrg extern void 139936ac495dSmrg gcc_jit_timer_pop (gcc_jit_timer *timer, 140036ac495dSmrg const char *item_name); 140136ac495dSmrg 140236ac495dSmrg /* Print timing information to the given stream about activity since 140336ac495dSmrg the timer was started. 140436ac495dSmrg 140536ac495dSmrg This API entrypoint was added in LIBGCCJIT_ABI_4; you can test for its 140636ac495dSmrg presence using 140736ac495dSmrg #ifdef LIBGCCJIT_HAVE_TIMING_API 140836ac495dSmrg */ 140936ac495dSmrg 141036ac495dSmrg extern void 141136ac495dSmrg gcc_jit_timer_print (gcc_jit_timer *timer, 141236ac495dSmrg FILE *f_out); 141336ac495dSmrg 141436ac495dSmrg 141536ac495dSmrg #define LIBGCCJIT_HAVE_gcc_jit_rvalue_set_bool_require_tail_call 141636ac495dSmrg 141736ac495dSmrg /* Mark/clear a call as needing tail-call optimization. 141836ac495dSmrg 141936ac495dSmrg This API entrypoint was added in LIBGCCJIT_ABI_6; you can test for its 142036ac495dSmrg presence using 142136ac495dSmrg #ifdef LIBGCCJIT_HAVE_gcc_jit_rvalue_set_bool_require_tail_call 142236ac495dSmrg */ 142336ac495dSmrg extern void 142436ac495dSmrg gcc_jit_rvalue_set_bool_require_tail_call (gcc_jit_rvalue *call, 142536ac495dSmrg int require_tail_call); 142636ac495dSmrg 1427a2dc1f3fSmrg #define LIBGCCJIT_HAVE_gcc_jit_type_get_aligned 1428a2dc1f3fSmrg 1429a2dc1f3fSmrg /* Given type "T", get type: 1430a2dc1f3fSmrg 1431a2dc1f3fSmrg T __attribute__ ((aligned (ALIGNMENT_IN_BYTES))) 1432a2dc1f3fSmrg 1433a2dc1f3fSmrg The alignment must be a power of two. 1434a2dc1f3fSmrg 1435a2dc1f3fSmrg This API entrypoint was added in LIBGCCJIT_ABI_7; you can test for its 1436a2dc1f3fSmrg presence using 1437a2dc1f3fSmrg #ifdef LIBGCCJIT_HAVE_gcc_jit_type_get_aligned 1438a2dc1f3fSmrg */ 1439a2dc1f3fSmrg extern gcc_jit_type * 1440a2dc1f3fSmrg gcc_jit_type_get_aligned (gcc_jit_type *type, 1441a2dc1f3fSmrg size_t alignment_in_bytes); 1442a2dc1f3fSmrg 1443a2dc1f3fSmrg #define LIBGCCJIT_HAVE_gcc_jit_type_get_vector 1444a2dc1f3fSmrg 1445a2dc1f3fSmrg /* Given type "T", get type: 1446a2dc1f3fSmrg 1447a2dc1f3fSmrg T __attribute__ ((vector_size (sizeof(T) * num_units)) 1448a2dc1f3fSmrg 1449a2dc1f3fSmrg T must be integral/floating point; num_units must be a power of two. 1450a2dc1f3fSmrg 1451a2dc1f3fSmrg This API entrypoint was added in LIBGCCJIT_ABI_8; you can test for its 1452a2dc1f3fSmrg presence using 1453a2dc1f3fSmrg #ifdef LIBGCCJIT_HAVE_gcc_jit_type_get_vector 1454a2dc1f3fSmrg */ 1455a2dc1f3fSmrg extern gcc_jit_type * 1456a2dc1f3fSmrg gcc_jit_type_get_vector (gcc_jit_type *type, size_t num_units); 1457a2dc1f3fSmrg 1458a2dc1f3fSmrg 1459a2dc1f3fSmrg #define LIBGCCJIT_HAVE_gcc_jit_function_get_address 1460a2dc1f3fSmrg 1461a2dc1f3fSmrg /* Get the address of a function as an rvalue, of function pointer 1462a2dc1f3fSmrg type. 1463a2dc1f3fSmrg 1464a2dc1f3fSmrg This API entrypoint was added in LIBGCCJIT_ABI_9; you can test for its 1465a2dc1f3fSmrg presence using 1466a2dc1f3fSmrg #ifdef LIBGCCJIT_HAVE_gcc_jit_function_get_address 1467a2dc1f3fSmrg */ 1468a2dc1f3fSmrg extern gcc_jit_rvalue * 1469a2dc1f3fSmrg gcc_jit_function_get_address (gcc_jit_function *fn, 1470a2dc1f3fSmrg gcc_jit_location *loc); 1471a2dc1f3fSmrg 1472a2dc1f3fSmrg 1473a2dc1f3fSmrg #define LIBGCCJIT_HAVE_gcc_jit_context_new_rvalue_from_vector 1474a2dc1f3fSmrg 1475a2dc1f3fSmrg /* Build a vector rvalue from an array of elements. 1476a2dc1f3fSmrg 1477a2dc1f3fSmrg "vec_type" should be a vector type, created using gcc_jit_type_get_vector. 1478a2dc1f3fSmrg 1479a2dc1f3fSmrg This API entrypoint was added in LIBGCCJIT_ABI_10; you can test for its 1480a2dc1f3fSmrg presence using 1481a2dc1f3fSmrg #ifdef LIBGCCJIT_HAVE_gcc_jit_context_new_rvalue_from_vector 1482a2dc1f3fSmrg */ 1483a2dc1f3fSmrg extern gcc_jit_rvalue * 1484a2dc1f3fSmrg gcc_jit_context_new_rvalue_from_vector (gcc_jit_context *ctxt, 1485a2dc1f3fSmrg gcc_jit_location *loc, 1486a2dc1f3fSmrg gcc_jit_type *vec_type, 1487a2dc1f3fSmrg size_t num_elements, 1488a2dc1f3fSmrg gcc_jit_rvalue **elements); 1489a2dc1f3fSmrg 1490*8feb0f0bSmrg #define LIBGCCJIT_HAVE_gcc_jit_version 1491*8feb0f0bSmrg 1492*8feb0f0bSmrg /* Functions to retrive libgccjit version. 1493*8feb0f0bSmrg Analogous to __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__ in C code. 1494*8feb0f0bSmrg 1495*8feb0f0bSmrg These API entrypoints were added in LIBGCCJIT_ABI_13; you can test for their 1496*8feb0f0bSmrg presence using 1497*8feb0f0bSmrg #ifdef LIBGCCJIT_HAVE_gcc_jit_version 1498*8feb0f0bSmrg */ 1499*8feb0f0bSmrg extern int 1500*8feb0f0bSmrg gcc_jit_version_major (void); 1501*8feb0f0bSmrg extern int 1502*8feb0f0bSmrg gcc_jit_version_minor (void); 1503*8feb0f0bSmrg extern int 1504*8feb0f0bSmrg gcc_jit_version_patchlevel (void); 1505*8feb0f0bSmrg 150636ac495dSmrg #ifdef __cplusplus 150736ac495dSmrg } 150836ac495dSmrg #endif /* __cplusplus */ 150936ac495dSmrg 151036ac495dSmrg #endif /* LIBGCCJIT_H */ 1511