aboutsummaryrefslogtreecommitdiff
path: root/gcc/jit/libgccjit.c
diff options
context:
space:
mode:
authorDavid Malcolm <dmalcolm@redhat.com>2015-01-12 17:14:02 +0000
committerDavid Malcolm <dmalcolm@gcc.gnu.org>2015-01-12 17:14:02 +0000
commit791cfef8e7553e4939a1ed095e25414f6dc713d6 (patch)
tree062ae8773efd3200e81a237028025864147648c8 /gcc/jit/libgccjit.c
parent6c0fcb81dad4c8f2f9c687a40627db0442a475f4 (diff)
downloadgcc-791cfef8e7553e4939a1ed095e25414f6dc713d6.zip
gcc-791cfef8e7553e4939a1ed095e25414f6dc713d6.tar.gz
gcc-791cfef8e7553e4939a1ed095e25414f6dc713d6.tar.bz2
jit: API change to gcc_jit_context_new_global
gcc/jit/ChangeLog: * docs/cp/topics/expressions.rst (Global variables): Add enum gcc_jit_global_kind param to gccjit::context::new_global. * docs/topics/expressions.rst (Global variables): Likewise. Document the new enum. * docs/topics/results.rst (Compilation results): Document globals-handling. * dummy-frontend.c (jit_langhook_write_globals): Call into the playback context's write_global_decls_1 and write_global_decls_2 before and after calling symtab->finalize_compilation_unit (). * jit-playback.c: Include "debug.h". (gcc::jit::playback::context::new_global): Add "kind" param and use it to set TREE_PUBLIC, TREE_STATIC and DECL_EXTERNAL on the underlying VAR_DECL. Call varpool_node::get_create on the VAR_DECL, and add it to m_globals. (gcc::jit::playback::context::write_global_decls_1): New function. (gcc::jit::playback::context::write_global_decls_2): New function. * jit-playback.h (gcc::jit::playback::context::context): Call create on m_globals. (gcc::jit::playback::context::new_global): Add "kind" param. (gcc::jit::playback::context::write_global_decls_1): New function. (gcc::jit::playback::context::write_global_decls_2): New function. (gcc::jit::playback::context::m_globals): New field. * jit-recording.c (gcc::jit::recording::context::context): Initialize m_globals. (gcc::jit::recording::context::new_global): Add param "kind". Add the new global to m_globals. (gcc::jit::recording::context::dump_to_file): Dump the globals. (gcc::jit::recording::global::replay_into): Add field m_kind. (gcc::jit::recording::global::write_to_dump): New override. * jit-recording.h (gcc::jit::recording::context::new_global): Add param "kind". (gcc::jit::recording::context::m_globals): New field. (gcc::jit::recording::global::global): Add param kind. (gcc::jit::recording::global::write_to_dump): New override. (gcc::jit::recording::global::m_kind): New field. * jit-result.c (gcc::jit::result::get_global): New function. * jit-result.h (gcc::jit::result::get_global): New function. * libgccjit++.h (gccjit::context::new_global): Add "kind" param. * libgccjit.c (gcc_jit_context_new_global): Likewise. (gcc_jit_result_get_global): New API entrypoint. * libgccjit.h (gcc_jit_result_get_global): New API entrypoint. (enum gcc_jit_global_kind): New enum. (gcc_jit_context_new_global): API change: add "kind" param. * libgccjit.map (gcc_jit_result_get_global): New symbol. gcc/testsuite/ChangeLog: * jit.dg/test-array-as-pointer.c (create_code): Update call to gcc_jit_context_new_global by setting "kind" to GCC_JIT_GLOBAL_IMPORTED. * jit.dg/test-error-array-as-pointer.c: Likewise. * jit.dg/test-expressions.c (make_test_of_get_address): Likewise. * jit.dg/test-fuzzer.c (make_random_global): Likewise, but setting kind to GCC_JIT_GLOBAL_EXPORTED. * jit.dg/test-using-global.c (the_global): Rename to... (imported_global): ...this. (create_code): Update to test the three kinds of global. (verify_code): Likewise. From-SVN: r219480
Diffstat (limited to 'gcc/jit/libgccjit.c')
-rw-r--r--gcc/jit/libgccjit.c28
1 files changed, 27 insertions, 1 deletions
diff --git a/gcc/jit/libgccjit.c b/gcc/jit/libgccjit.c
index 62d3edf..d596d08 100644
--- a/gcc/jit/libgccjit.c
+++ b/gcc/jit/libgccjit.c
@@ -987,16 +987,23 @@ gcc_jit_block_get_function (gcc_jit_block *block)
gcc_jit_lvalue *
gcc_jit_context_new_global (gcc_jit_context *ctxt,
gcc_jit_location *loc,
+ enum gcc_jit_global_kind kind,
gcc_jit_type *type,
const char *name)
{
RETURN_NULL_IF_FAIL (ctxt, NULL, loc, "NULL context");
JIT_LOG_FUNC (ctxt->get_logger ());
/* LOC can be NULL. */
+ RETURN_NULL_IF_FAIL_PRINTF1 (
+ ((kind >= GCC_JIT_GLOBAL_EXPORTED)
+ && (kind <= GCC_JIT_GLOBAL_IMPORTED)),
+ ctxt, loc,
+ "unrecognized value for enum gcc_jit_global_kind: %i",
+ kind);
RETURN_NULL_IF_FAIL (type, ctxt, loc, "NULL type");
RETURN_NULL_IF_FAIL (name, ctxt, loc, "NULL name");
- return (gcc_jit_lvalue *)ctxt->new_global (loc, type, name);
+ return (gcc_jit_lvalue *)ctxt->new_global (loc, kind, type, name);
}
/* Public entrypoint. See description in libgccjit.h.
@@ -2215,6 +2222,25 @@ gcc_jit_result_get_code (gcc_jit_result *result,
/* Public entrypoint. See description in libgccjit.h.
+ After error-checking, the real work is done by the
+ gcc::jit::result::get_global method in jit-result.c. */
+
+void *
+gcc_jit_result_get_global (gcc_jit_result *result,
+ const char *name)
+{
+ RETURN_NULL_IF_FAIL (result, NULL, NULL, "NULL result");
+ JIT_LOG_FUNC (result->get_logger ());
+ RETURN_NULL_IF_FAIL (name, NULL, NULL, "NULL name");
+
+ void *global = result->get_global (name);
+ result->log ("%s: returning (void *)%p", __func__, global);
+
+ return global;
+}
+
+/* Public entrypoint. See description in libgccjit.h.
+
After error-checking, this is essentially a wrapper around the
destructor for gcc::jit::result in jit-result.c. */