Skip to content

Commit b7e7cf7

Browse files
GuillaumeGomezantoyo
authored andcommitted
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 873c468 commit b7e7cf7

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
@@ -466,3 +466,10 @@ information:
466466
* :func:`gcc_jit_target_info_cpu_supports`
467467
* :func:`gcc_jit_target_info_arch`
468468
* :func:`gcc_jit_target_info_supports_target_dependent_type`
469+
470+
``LIBGCCJIT_ABI_44``
471+
--------------------
472+
``LIBGCCJIT_ABI_44`` covers the addition of a function to get the name
473+
of an lvalue.
474+
475+
* :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
@@ -1511,6 +1511,7 @@ class lvalue : public rvalue
15111511
void set_register_name (const char *reg_name);
15121512
void set_alignment (unsigned bytes);
15131513
unsigned get_alignment () const { return m_alignment; }
1514+
virtual string * get_name () const { return NULL; }
15141515

15151516
protected:
15161517
string *m_link_section;
@@ -1551,6 +1552,8 @@ class param : public lvalue
15511552
const char *access_as_rvalue (reproducer &r) final override;
15521553
const char *access_as_lvalue (reproducer &r) final override;
15531554

1555+
string * get_name () const final override { return m_name; }
1556+
15541557
private:
15551558
string * make_debug_string () final override { return m_name; }
15561559
void write_reproducer (reproducer &r) final override;
@@ -1819,6 +1822,8 @@ class global : public lvalue
18191822

18201823
void set_rvalue_init (rvalue *val) { m_rvalue_init = val; }
18211824

1825+
string * get_name () const final override { return m_name; }
1826+
18221827
private:
18231828
string * make_debug_string () final override { return m_name; }
18241829
template <typename T>

gcc/jit/libgccjit.cc

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4849,6 +4849,22 @@ gcc_jit_context_add_top_level_asm (gcc_jit_context *ctxt,
48494849
ctxt->add_top_level_asm (loc, asm_stmts);
48504850
}
48514851

4852+
/* Public entrypoint. See description in libgccjit.h.
4853+
4854+
After error-checking, this calls the trivial
4855+
gcc::jit::recording::lvalue::get_name method, in jit-recording.h. */
4856+
4857+
extern const char *
4858+
gcc_jit_lvalue_get_name (gcc_jit_lvalue *lvalue)
4859+
{
4860+
RETURN_NULL_IF_FAIL (lvalue, NULL, NULL, "NULL lvalue");
4861+
auto name = lvalue->get_name ();
4862+
4863+
if (!name)
4864+
return NULL;
4865+
return name->c_str ();
4866+
}
4867+
48524868
/* Public entrypoint. See description in libgccjit.h.
48534869
48544870
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
@@ -2290,6 +2290,12 @@ gcc_jit_lvalue_add_string_attribute (gcc_jit_lvalue *variable,
22902290
enum gcc_jit_variable_attribute attribute,
22912291
const char* value);
22922292

2293+
/* Returns the name of the `lvalue`, if any. Returns NULL otherwise. */
2294+
extern const char *
2295+
gcc_jit_lvalue_get_name (gcc_jit_lvalue *lvalue);
2296+
2297+
#define LIBGCCJIT_HAVE_gcc_jit_lvalue_get_name
2298+
22932299
extern void
22942300
gcc_jit_context_set_output_ident (gcc_jit_context *ctxt,
22952301
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)