summaryrefslogtreecommitdiff
path: root/gcc/jit/jit-playback.h
diff options
context:
space:
mode:
authordmalcolm <dmalcolm@138bc75d-0d04-0410-961f-82ee72b054a4>2015-01-20 01:32:48 +0000
committerdmalcolm <dmalcolm@138bc75d-0d04-0410-961f-82ee72b054a4>2015-01-20 01:32:48 +0000
commit69834ed91f49e3b391ef47e81c34a033519c76c5 (patch)
tree474c9e2fbfe804a349ce0083fd02f728b0475514 /gcc/jit/jit-playback.h
parent25032ab834678429cbed51c8974e98acb929649e (diff)
downloadgcc-69834ed91f49e3b391ef47e81c34a033519c76c5.tar.gz
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. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@219876 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/jit/jit-playback.h')
-rw-r--r--gcc/jit/jit-playback.h54
1 files changed, 53 insertions, 1 deletions
diff --git a/gcc/jit/jit-playback.h b/gcc/jit/jit-playback.h
index 8efd506ff89..e9832f0378e 100644
--- a/gcc/jit/jit-playback.h
+++ b/gcc/jit/jit-playback.h
@@ -23,6 +23,8 @@ along with GCC; see the file COPYING3. If not see
#include <utility> // for std::pair
+#include "timevar.h"
+
#include "jit-recording.h"
namespace gcc {
@@ -35,6 +37,12 @@ namespace jit {
namespace playback {
+/* playback::context is an abstract base class.
+
+ The two concrete subclasses are:
+ - playback::compile_to_memory
+ - playback::compile_to_file. */
+
class context : public log_user
{
public:
@@ -174,7 +182,7 @@ public:
return m_recording_ctxt->get_builtins_manager ();
}
- result *
+ void
compile ();
void
@@ -252,9 +260,22 @@ private:
char *
read_dump_file (const char *path);
+ virtual void postprocess (const char *ctxt_progname) = 0;
+
+protected:
+ tempdir *get_tempdir () { return m_tempdir; }
+
void
convert_to_dso (const char *ctxt_progname);
+ void
+ invoke_driver (const char *ctxt_progname,
+ const char *input_file,
+ const char *output_file,
+ timevar_id_t tv_id,
+ bool shared,
+ bool run_linker);
+
result *
dlopen_built_dso ();
@@ -274,6 +295,37 @@ private:
auto_vec<std::pair<tree, location *> > m_cached_locations;
};
+class compile_to_memory : public context
+{
+ public:
+ compile_to_memory (recording::context *ctxt);
+ void postprocess (const char *ctxt_progname);
+
+ result *get_result_obj () const { return m_result; }
+
+ private:
+ result *m_result;
+};
+
+class compile_to_file : public context
+{
+ public:
+ compile_to_file (recording::context *ctxt,
+ enum gcc_jit_output_kind output_kind,
+ const char *output_path);
+ void postprocess (const char *ctxt_progname);
+
+ private:
+ void
+ copy_file (const char *src_path,
+ const char *dst_path);
+
+ private:
+ enum gcc_jit_output_kind m_output_kind;
+ const char *m_output_path;
+};
+
+
/* A temporary wrapper object.
These objects are (mostly) only valid during replay.
We allocate them on the GC heap, so that they will be cleaned