aboutsummaryrefslogtreecommitdiff
path: root/gcc/jit/libgccjit.c
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.c
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.c')
-rw-r--r--gcc/jit/libgccjit.c31
1 files changed, 30 insertions, 1 deletions
diff --git a/gcc/jit/libgccjit.c b/gcc/jit/libgccjit.c
index 0faf0f9..7eb66bd 100644
--- a/gcc/jit/libgccjit.c
+++ b/gcc/jit/libgccjit.c
@@ -2196,7 +2196,7 @@ gcc_jit_context_compile (gcc_jit_context *ctxt)
JIT_LOG_FUNC (ctxt->get_logger ());
- ctxt->log ("compiling ctxt: %p", (void *)ctxt);
+ ctxt->log ("in-memory compile of ctxt: %p", (void *)ctxt);
gcc_jit_result *result = (gcc_jit_result *)ctxt->compile ();
@@ -2209,6 +2209,35 @@ gcc_jit_context_compile (gcc_jit_context *ctxt)
/* Public entrypoint. See description in libgccjit.h.
After error-checking, the real work is done by the
+ gcc::jit::recording::context::compile_to_file method in
+ jit-recording.c. */
+
+void
+gcc_jit_context_compile_to_file (gcc_jit_context *ctxt,
+ enum gcc_jit_output_kind output_kind,
+ const char *output_path)
+{
+ RETURN_IF_FAIL (ctxt, NULL, NULL, "NULL context");
+ JIT_LOG_FUNC (ctxt->get_logger ());
+ RETURN_IF_FAIL_PRINTF1 (
+ ((output_kind >= GCC_JIT_OUTPUT_KIND_ASSEMBLER)
+ && (output_kind <= GCC_JIT_OUTPUT_KIND_EXECUTABLE)),
+ ctxt, NULL,
+ "unrecognized output_kind: %i",
+ output_kind);
+ RETURN_IF_FAIL (output_path, ctxt, NULL, "NULL output_path");
+
+ ctxt->log ("compile_to_file of ctxt: %p", (void *)ctxt);
+ ctxt->log ("output_kind: %i", output_kind);
+ ctxt->log ("output_path: %s", output_path);
+
+ ctxt->compile_to_file (output_kind, output_path);
+}
+
+
+/* Public entrypoint. See description in libgccjit.h.
+
+ After error-checking, the real work is done by the
gcc::jit::recording::context::dump_to_file method in
jit-recording.c. */