diff options
author | Andrea Corallo <andrea.corallo@arm.com> | 2020-05-30 10:33:08 +0100 |
---|---|---|
committer | Andrea Corallo <andrea.corallo@arm.com> | 2020-09-11 12:18:59 +0200 |
commit | 4ecc0061c400102859dd630cce84d1cc5be0fbf7 (patch) | |
tree | 7d5e9b91b960800e48074ba848e723990048acaf /gcc/jit/libgccjit.c | |
parent | 15545563128f0240192c263522d4a36b7f86250f (diff) | |
download | gcc-4ecc0061c400102859dd630cce84d1cc5be0fbf7.zip gcc-4ecc0061c400102859dd630cce84d1cc5be0fbf7.tar.gz gcc-4ecc0061c400102859dd630cce84d1cc5be0fbf7.tar.bz2 |
libgccjit: Add new gcc_jit_global_set_initializer entry point
gcc/jit/ChangeLog
2020-08-01 Andrea Corallo <andrea.corallo@arm.com>
* docs/topics/compatibility.rst (LIBGCCJIT_ABI_14): New ABI tag.
* docs/topics/expressions.rst (gcc_jit_global_set_initializer):
Document new entry point in section 'Global variables'.
* jit-playback.c (global_new_decl, global_finalize_lvalue): New
method.
(playback::context::new_global): Make use of global_new_decl,
global_finalize_lvalue.
(load_blob_in_ctor): New template function in use by the
following.
(playback::context::new_global_initialized): New method.
* jit-playback.h (class context): Decl 'new_global_initialized',
'global_new_decl', 'global_finalize_lvalue'.
(lvalue::set_initializer): Add implementation.
* jit-recording.c (recording::memento_of_get_pointer::get_size)
(recording::memento_of_get_type::get_size): Add implementation.
(recording::global::write_initializer_reproducer): New function in
use by 'recording::global::write_reproducer'.
(recording::global::replay_into)
(recording::global::write_to_dump)
(recording::global::write_reproducer): Handle
initialized case.
* jit-recording.h (class type): Decl 'get_size' and
'num_elements'.
* libgccjit++.h (class lvalue): Declare new 'set_initializer'
method.
(class lvalue): Decl 'is_global' and 'set_initializer'.
(class global) Decl 'write_initializer_reproducer'. Add
'm_initializer', 'm_initializer_num_bytes' fields. Implement
'set_initializer'. Add a destructor to free 'm_initializer'.
* libgccjit.c (gcc_jit_global_set_initializer): New function.
* libgccjit.h (gcc_jit_global_set_initializer): New function
declaration.
* libgccjit.map (LIBGCCJIT_ABI_14): New ABI tag.
gcc/testsuite/ChangeLog
2020-08-01 Andrea Corallo <andrea.corallo@arm.com>
* jit.dg/all-non-failing-tests.h: Add test-blob.c.
* jit.dg/test-global-set-initializer.c: New testcase.
Diffstat (limited to 'gcc/jit/libgccjit.c')
-rw-r--r-- | gcc/jit/libgccjit.c | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/gcc/jit/libgccjit.c b/gcc/jit/libgccjit.c index 50130fb..a00aefc 100644 --- a/gcc/jit/libgccjit.c +++ b/gcc/jit/libgccjit.c @@ -1119,6 +1119,45 @@ gcc_jit_context_new_global (gcc_jit_context *ctxt, /* Public entrypoint. See description in libgccjit.h. + After error-checking, the real work is done by the + gcc::jit::recording::global::set_initializer method, in + jit-recording.c. */ + +extern gcc_jit_lvalue * +gcc_jit_global_set_initializer (gcc_jit_lvalue *global, + const void *blob, + size_t num_bytes) +{ + RETURN_NULL_IF_FAIL (global, NULL, NULL, "NULL global"); + RETURN_NULL_IF_FAIL (blob, NULL, NULL, "NULL blob"); + RETURN_NULL_IF_FAIL_PRINTF1 (global->is_global (), NULL, NULL, + "lvalue \"%s\" not a global", + global->get_debug_string ()); + + gcc::jit::recording::type *lval_type = global->get_type (); + RETURN_NULL_IF_FAIL_PRINTF1 (lval_type->is_array (), NULL, NULL, + "global \"%s\" is not an array", + global->get_debug_string ()); + RETURN_NULL_IF_FAIL_PRINTF1 (lval_type->dereference ()->is_int (), NULL, NULL, + "global \"%s\" is not an array of integral type", + global->get_debug_string ()); + size_t lvalue_size = + lval_type->dereference ()->get_size () + * static_cast <gcc::jit::recording::array_type *> (lval_type)->num_elements (); + RETURN_NULL_IF_FAIL_PRINTF3 ( + lvalue_size == num_bytes, NULL, NULL, + "mismatching sizes:" + " global \"%s\" has size %zu whereas initializer has size %zu", + global->get_debug_string (), lvalue_size, num_bytes); + + reinterpret_cast <gcc::jit::recording::global *> (global) + ->set_initializer (blob, num_bytes); + + return global; +} + +/* Public entrypoint. See description in libgccjit.h. + After error-checking, this calls the trivial gcc::jit::recording::memento::as_object method (an lvalue is a memento), in jit-recording.h. */ |