Skip to content

Commit 0084a73

Browse files
gcc/jit/ChangeLog: (#77)
* jit-recording.h: Add lvalue::get_name method * libgccjit.cc (gcc_jit_lvalue_get_name): Likewise * libgccjit.h (gcc_jit_lvalue_get_name): Likewise * libgccjit.map: Likewise gcc/testsuite/ChangeLog: * jit.dg/test-tls.c: Add test for gcc_jit_lvalue_get_name
1 parent df53431 commit 0084a73

File tree

7 files changed

+54
-1
lines changed

7 files changed

+54
-1
lines changed

gcc/jit/docs/topics/compatibility.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,3 +453,10 @@ temporary variable:
453453
``LIBGCCJIT_ABI_34`` covers the addition of
454454

455455
* :func:`gcc_jit_context_set_output_ident`
456+
457+
``LIBGCCJIT_ABI_44``
458+
--------------------
459+
``LIBGCCJIT_ABI_44`` covers the addition of a function to get the name
460+
of an lvalue.
461+
462+
* :func:`gcc_jit_lvalue_get_name`

gcc/jit/docs/topics/expressions.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -923,6 +923,18 @@ where the rvalue is computed by reading from the storage area.
923923
924924
#ifdef LIBGCCJIT_HAVE_ALIGNMENT
925925
926+
.. function:: const char *\
927+
gcc_jit_lvalue_get_name (gcc_jit_lvalue *lvalue)
928+
929+
Returns the name of an lvalue.
930+
931+
This entrypoint was added in :ref:`LIBGCCJIT_ABI_44`; you can test for
932+
its present using
933+
934+
.. code-block:: c
935+
936+
#ifdef LIBGCCJIT_HAVE_gcc_jit_lvalue_get_name
937+
926938
Global variables
927939
****************
928940

gcc/jit/jit-recording.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1499,6 +1499,7 @@ class lvalue : public rvalue
14991499
void set_register_name (const char *reg_name);
15001500
void set_alignment (unsigned bytes);
15011501
unsigned get_alignment () const { return m_alignment; }
1502+
virtual string * get_name () const { return NULL; }
15021503

15031504
protected:
15041505
string *m_link_section;
@@ -1539,6 +1540,8 @@ class param : public lvalue
15391540
const char *access_as_rvalue (reproducer &r) final override;
15401541
const char *access_as_lvalue (reproducer &r) final override;
15411542

1543+
string * get_name () const final override { return m_name; }
1544+
15421545
private:
15431546
string * make_debug_string () final override { return m_name; }
15441547
void write_reproducer (reproducer &r) final override;
@@ -1807,6 +1810,8 @@ class global : public lvalue
18071810

18081811
void set_rvalue_init (rvalue *val) { m_rvalue_init = val; }
18091812

1813+
string * get_name () const final override { return m_name; }
1814+
18101815
private:
18111816
string * make_debug_string () final override { return m_name; }
18121817
template <typename T>

gcc/jit/libgccjit.cc

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4842,6 +4842,22 @@ gcc_jit_context_add_top_level_asm (gcc_jit_context *ctxt,
48424842
ctxt->add_top_level_asm (loc, asm_stmts);
48434843
}
48444844

4845+
/* Public entrypoint. See description in libgccjit.h.
4846+
4847+
After error-checking, this calls the trivial
4848+
gcc::jit::recording::lvalue::get_name method, in jit-recording.h. */
4849+
4850+
extern const char *
4851+
gcc_jit_lvalue_get_name (gcc_jit_lvalue *lvalue)
4852+
{
4853+
RETURN_NULL_IF_FAIL (lvalue, NULL, NULL, "NULL lvalue");
4854+
auto name = lvalue->get_name ();
4855+
4856+
if (!name)
4857+
return NULL;
4858+
return name->c_str ();
4859+
}
4860+
48454861
/* Public entrypoint. See description in libgccjit.h.
48464862
48474863
After error-checking, this calls the trivial

gcc/jit/libgccjit.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2236,6 +2236,12 @@ gcc_jit_lvalue_add_string_attribute (gcc_jit_lvalue *variable,
22362236
enum gcc_jit_variable_attribute attribute,
22372237
const char* value);
22382238

2239+
/* Returns the name of the `lvalue`, if any. Returns NULL otherwise. */
2240+
extern const char *
2241+
gcc_jit_lvalue_get_name (gcc_jit_lvalue *lvalue);
2242+
2243+
#define LIBGCCJIT_HAVE_gcc_jit_lvalue_get_name
2244+
22392245
extern void
22402246
gcc_jit_context_set_output_ident (gcc_jit_context *ctxt,
22412247
const char* output_ident);

gcc/jit/libgccjit.map

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,4 +377,9 @@ LIBGCCJIT_ABI_42 {
377377
LIBGCCJIT_ABI_43{
378378
global:
379379
gcc_jit_type_set_tree_addressable;
380-
} LIBGCCJIT_ABI_42;
380+
} LIBGCCJIT_ABI_42;
381+
382+
LIBGCCJIT_ABI_44{
383+
global:
384+
gcc_jit_lvalue_get_name;
385+
} LIBGCCJIT_ABI_43;

gcc/testsuite/jit.dg/test-tls.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ create_code (gcc_jit_context *ctxt, void *user_data)
2828
ctxt, NULL, GCC_JIT_GLOBAL_EXPORTED, int_type, "foo");
2929
gcc_jit_lvalue_set_tls_model (foo, GCC_JIT_TLS_MODEL_GLOBAL_DYNAMIC);
3030

31+
CHECK_STRING_VALUE (gcc_jit_lvalue_get_name (foo), "foo");
32+
3133
/* Build the test_fn. */
3234
gcc_jit_function *test_fn =
3335
gcc_jit_context_new_function (ctxt, NULL,

0 commit comments

Comments
 (0)