]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/jit/docs/topics/results.rst
Avoid undefined behavior in gcc.target/i386/pr64291-1.c
[thirdparty/gcc.git] / gcc / jit / docs / topics / results.rst
CommitLineData
35485da9
DM
1.. Copyright (C) 2014 Free Software Foundation, Inc.
2 Originally contributed by David Malcolm <dmalcolm@redhat.com>
3
4 This is free software: you can redistribute it and/or modify it
5 under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful, but
10 WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see
16 <http://www.gnu.org/licenses/>.
17
18.. default-domain:: c
19
20Compilation results
21===================
22
23.. type:: gcc_jit_result
24
81ba15f1
DM
25 A `gcc_jit_result` encapsulates the result of compiling a context,
26 and the lifetimes of any machine code functions that are
27 returned.
35485da9
DM
28
29.. function:: gcc_jit_result *\
30 gcc_jit_context_compile (gcc_jit_context *ctxt)
31
32 This calls into GCC and builds the code, returning a
33 `gcc_jit_result *`.
34
35
36.. function:: void *\
37 gcc_jit_result_get_code (gcc_jit_result *result,\
38 const char *funcname)
39
40 Locate a given function within the built machine code.
81ba15f1
DM
41
42 Functions are looked up by name. For this to succeed, a function
43 with a name matching `funcname` must have been created on
44 `result`'s context (or a parent context) via a call to
45 :func:`gcc_jit_context_new_function` with `kind`
46 :macro:`GCC_JIT_FUNCTION_EXPORTED`:
47
48 .. code-block:: c
49
50 gcc_jit_context_new_function (ctxt,
51 any_location, /* or NULL */
52 /* Required for func to be visible to
53 gcc_jit_result_get_code: */
54 GCC_JIT_FUNCTION_EXPORTED,
55 any_return_type,
56 /* Must string-compare equal: */
57 funcname,
58 /* etc */);
59
60 If such a function is not found (or `result` or `funcname` are
61 ``NULL``), an error message will be emitted on stderr and
62 ``NULL`` will be returned.
63
64 If the function is found, the result will need to be cast to a
65 function pointer of the correct type before it can be called.
66
67 Note that the resulting machine code becomes invalid after
68 :func:`gcc_jit_result_release` is called on the
69 `gcc_jit_result *`; attempting to call it after that may lead
70 to a segmentation fault.
35485da9
DM
71
72
73.. function:: void\
74 gcc_jit_result_release (gcc_jit_result *result)
75
76 Once we're done with the code, this unloads the built .so file.
77 This cleans up the result; after calling this, it's no longer
81ba15f1
DM
78 valid to use the result, or any code that was obtained by calling
79 :func:`gcc_jit_result_get_code` on it.