aboutsummaryrefslogtreecommitdiff
path: root/gcc/jit/libgccjit.h
diff options
context:
space:
mode:
authorDavid Malcolm <dmalcolm@redhat.com>2015-01-20 01:32:48 +0000
committerDavid Malcolm <dmalcolm@gcc.gnu.org>2015-01-20 01:32:48 +0000
commitfdce7209c23212b50f08604f242e9bbb5281818b (patch)
tree474c9e2fbfe804a349ce0083fd02f728b0475514 /gcc/jit/libgccjit.h
parentcb22ab4164a2140fa7ec38cd929d464224d9c222 (diff)
downloadgcc-fdce7209c23212b50f08604f242e9bbb5281818b.zip
gcc-fdce7209c23212b50f08604f242e9bbb5281818b.tar.gz
gcc-fdce7209c23212b50f08604f242e9bbb5281818b.tar.bz2
New jit API entrypoint: gcc_jit_context_compile_to_file
gcc/jit/ChangeLog: * docs/cp/topics/results.rst: Rename to... * docs/cp/topics/compilation.rst: ...this, and add section on ahead-of-time compilation. * docs/cp/topics/index.rst: Update for renaming of results.rst to compilation.rst. * docs/examples/emit-alphabet.bf: New file, a sample "brainf" script. * docs/examples/tut05-bf.c: New file, implementing a compiler for "brainf". * docs/internals/test-hello-world.exe.log.txt: Update to reflect changes to logger output. * docs/intro/index.rst: Add tutorial05.rst * docs/intro/tutorial05.rst: New file. * docs/topics/results.rst: Rename to... * docs/topics/compilation.rst: ...this, and add section on ahead-of-time compilation. * docs/topics/index.rst: Update for renaming of results.rst to compilation.rst. * jit-playback.c (gcc::jit::playback::context::compile): Convert return type from result * to void. Move the code to convert to dso and dlopen the result to a new pure virtual "postprocess" method. (gcc::jit::playback::compile_to_memory::compile_to_memory): New function. (gcc::jit::playback::compile_to_memory::postprocess): New function, based on playback::context::compile. (gcc::jit::playback::compile_to_file::compile_to_file): New function. (gcc::jit::playback::compile_to_file::postprocess): New function. (gcc::jit::playback::compile_to_file::copy_file): New function. (gcc::jit::playback::context::convert_to_dso): Move internals to... (gcc::jit::playback::context::invoke_driver): New method. Add "-shared" and "-c" options to driver's argv as needed. * jit-playback.h: Include "timevar.h". (gcc::jit::playback::context::compile): Convert return type from result * to void. (gcc::jit::playback::context::postprocess): New pure virtual function, making this an abstract base class. (gcc::jit::playback::context::get_tempdir): New accessor. (gcc::jit::playback::context::invoke_driver): New function. (class gcc::jit::playback::compile_to_memory): New subclass of playback::context. (class gcc::jit::playback::compile_to_file): Likewise. * jit-recording.c (gcc::jit::recording::context::compile): Use a playback::compile_to_memory, and extract its result. (gcc::jit::recording::context::compile_to_file): New function. * jit-recording.h (gcc::jit::recording::context::compile_to_file): New function. * libgccjit++.h (gccjit::context::compile_to_file): New method. * libgccjit.c (gcc_jit_context_compile): Update log message to clarify that this is an in-memory compile. (gcc_jit_context_compile_to_file): New function. * libgccjit.h (gcc_jit_context): Clarify that you can compile a context more than once, and that you can compile to a file as well as to memory. (gcc_jit_result): Clarify that this is the result of an in-memory compilation. (gcc_jit_context_compile): Clarify that you can compile, and that this is an in-memory compilation. (enum gcc_jit_output_kind): New enum. (gcc_jit_context_compile_to_file): New function. (gcc_jit_context_enable_dump): Clarify comment to cover both forms of compilation. * libgccjit.map (gcc_jit_context_compile_to_file): New API entrypoint. * notes.txt: Update to show the playback::context::postprocess virtual function. gcc/testsuite/ChangeLog: * jit.dg/harness.h: Include <unistd.h>. (CHECK_NO_ERRORS): New. (verify_code): Wrap prototype in #ifndef TEST_COMPILING_TO_FILE. (test_jit): Support new macro TEST_COMPILING_TO_FILE for exercising gcc_jit_context_compile_to_file. * jit.dg/jit.exp (fixed_host_execute): Fix the code for passing on args to the spawned executable. (jit-expand-vars): New function. (jit-exe-params): New variable. (dg-jit-set-exe-params): New function. (jit-dg-test): Detect testcases that use jit-verify-compile-to-file and call jit-setup-compile-to-file. Set arguments of spawned process to jit-exe-params. (jit-get-output-filename): New function. (jit-setup-compile-to-file): New function. (jit-verify-compile-to-file): New function. (jit-run-executable): New function. (jit-verify-executable): New function. * jit.dg/test-compile-to-assembler.c: New testcase. * jit.dg/test-compile-to-dynamic-library.c: New testcase. * jit.dg/test-compile-to-executable.c: New testcase. * jit.dg/test-compile-to-object.c: New testcase. From-SVN: r219876
Diffstat (limited to 'gcc/jit/libgccjit.h')
-rw-r--r--gcc/jit/libgccjit.h58
1 files changed, 46 insertions, 12 deletions
diff --git a/gcc/jit/libgccjit.h b/gcc/jit/libgccjit.h
index 2f41087..12514ba 100644
--- a/gcc/jit/libgccjit.h
+++ b/gcc/jit/libgccjit.h
@@ -36,17 +36,20 @@ extern "C" {
the API below.
Invoking gcc_jit_context_compile on it gives you a gcc_jit_result *
- (or NULL).
+ (or NULL), representing in-memory machine code.
You can call gcc_jit_context_compile repeatedly on one context, giving
multiple independent results.
+ Similarly, you can call gcc_jit_context_compile_to_file on a context
+ to compile to disk.
+
Eventually you can call gcc_jit_context_release to clean up the
- context; any results created from it are still usable, and should be
- cleaned up via gcc_jit_result_release. */
+ context; any in-memory results created from it are still usable, and
+ should be cleaned up via gcc_jit_result_release. */
typedef struct gcc_jit_context gcc_jit_context;
-/* A gcc_jit_result encapsulates the result of a compilation. */
+/* A gcc_jit_result encapsulates the result of an in-memory compilation. */
typedef struct gcc_jit_result gcc_jit_result;
/* An object created within a context. Such objects are automatically
@@ -240,12 +243,42 @@ gcc_jit_context_set_bool_option (gcc_jit_context *ctxt,
enum gcc_jit_bool_option opt,
int value);
-/* This actually calls into GCC and runs the build, all
- in a mutex for now. The result is a wrapper around a .so file.
- It can only be called once on a given context. */
+/* Compile the context to in-memory machine code.
+
+ This can be called more that once on a given context,
+ although any errors that occur will block further compilation. */
+
extern gcc_jit_result *
gcc_jit_context_compile (gcc_jit_context *ctxt);
+/* Kinds of ahead-of-time compilation, for use with
+ gcc_jit_context_compile_to_file. */
+
+enum gcc_jit_output_kind
+{
+ /* Compile the context to an assembler file. */
+ GCC_JIT_OUTPUT_KIND_ASSEMBLER,
+
+ /* Compile the context to an object file. */
+ GCC_JIT_OUTPUT_KIND_OBJECT_FILE,
+
+ /* Compile the context to a dynamic library. */
+ GCC_JIT_OUTPUT_KIND_DYNAMIC_LIBRARY,
+
+ /* Compile the context to an executable. */
+ GCC_JIT_OUTPUT_KIND_EXECUTABLE
+};
+
+/* Compile the context to a file of the given kind.
+
+ This can be called more that once on a given context,
+ although any errors that occur will block further compilation. */
+
+extern void
+gcc_jit_context_compile_to_file (gcc_jit_context *ctxt,
+ enum gcc_jit_output_kind output_kind,
+ const char *output_path);
+
/* To help with debugging: dump a C-like representation to the given path,
describing what's been set up on the context.
@@ -1079,14 +1112,15 @@ gcc_jit_context_dump_reproducer_to_file (gcc_jit_context *ctxt,
The context directly stores the dumpname as a (const char *), so the
passed string must outlive the context.
- gcc_jit_context_compile will capture the dump as a
- dynamically-allocated buffer, writing it to ``*out_ptr``.
+ gcc_jit_context_compile and gcc_jit_context_to_file
+ will capture the dump as a dynamically-allocated buffer, writing
+ it to ``*out_ptr``.
The caller becomes responsible for calling
free (*out_ptr)
- each time that gcc_jit_context_compile is called. *out_ptr will be
- written to, either with the address of a buffer, or with NULL if an
- error occurred.
+ each time that gcc_jit_context_compile or gcc_jit_context_to_file
+ are called. *out_ptr will be written to, either with the address of a
+ buffer, or with NULL if an error occurred.
This API entrypoint is likely to be less stable than the others.
In particular, both the precise dumpnames, and the format and content