Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions gcc/jit/docs/topics/compatibility.rst
Original file line number Diff line number Diff line change
Expand Up @@ -460,3 +460,10 @@ temporary variable:
of an lvalue.

* :func:`gcc_jit_lvalue_get_name`

``LIBGCCJIT_ABI_45``
--------------------
``LIBGCCJIT_ABI_45`` covers the addition of a function to set the name
of an lvalue.

* :func:`gcc_jit_lvalue_set_name`
11 changes: 10 additions & 1 deletion gcc/jit/docs/topics/expressions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -929,12 +929,21 @@ where the rvalue is computed by reading from the storage area.
Returns the name of an lvalue.

This entrypoint was added in :ref:`LIBGCCJIT_ABI_44`; you can test for
its present using
its presence using

.. code-block:: c

#ifdef LIBGCCJIT_HAVE_gcc_jit_lvalue_get_name

Sets the name of an lvalue.

This entrypoint was added in :ref:`LIBGCCJIT_ABI_45`; you can test for
its presence using

.. code-block:: c

#ifdef LIBGCCJIT_HAVE_gcc_jit_lvalue_set_name

Global variables
****************

Expand Down
35 changes: 35 additions & 0 deletions gcc/jit/jit-recording.h
Original file line number Diff line number Diff line change
Expand Up @@ -1500,6 +1500,7 @@ class lvalue : public rvalue
void set_alignment (unsigned bytes);
unsigned get_alignment () const { return m_alignment; }
virtual string * get_name () const { return NULL; }
virtual void set_name (const char *new_name) = 0;

protected:
string *m_link_section;
Expand Down Expand Up @@ -1541,6 +1542,9 @@ class param : public lvalue
const char *access_as_lvalue (reproducer &r) final override;

string * get_name () const final override { return m_name; }
void set_name (const char *new_name) final override {
m_name = m_ctxt->new_string (new_name);
}

private:
string * make_debug_string () final override { return m_name; }
Expand Down Expand Up @@ -1811,6 +1815,9 @@ class global : public lvalue
void set_rvalue_init (rvalue *val) { m_rvalue_init = val; }

string * get_name () const final override { return m_name; }
void set_name (const char *new_name) final override {
m_name = m_ctxt->new_string (new_name);
}

private:
string * make_debug_string () final override { return m_name; }
Expand Down Expand Up @@ -2255,6 +2262,10 @@ class array_access : public lvalue

void replay_into (replayer *r) final override;

void set_name (const char *new_name) final override {
m_ctxt->add_error (NULL, "cannot change the name of type `array_access`");
}

void visit_children (rvalue_visitor *v) final override;

private:
Expand Down Expand Up @@ -2316,6 +2327,10 @@ class vector_access : public lvalue

void visit_children (rvalue_visitor *v) final override;

void set_name (const char *new_name) final override {
m_ctxt->add_error (NULL, "cannot change the name of type `vector_access`");
}

private:
string * make_debug_string () final override;
void write_reproducer (reproducer &r) final override;
Expand Down Expand Up @@ -2345,6 +2360,11 @@ class access_field_of_lvalue : public lvalue

void visit_children (rvalue_visitor *v) final override;

void set_name (const char *new_name) final override {
m_ctxt->add_error (
NULL, "cannot change the name of type `access_field_of_lvalue`");
}

private:
string * make_debug_string () final override;
void write_reproducer (reproducer &r) final override;
Expand Down Expand Up @@ -2403,6 +2423,11 @@ class dereference_field_rvalue : public lvalue

void visit_children (rvalue_visitor *v) final override;

void set_name (const char *new_name) final override {
m_ctxt->add_error (
NULL, "cannot change the name of type `dereference_field_rvalue`");
}

private:
string * make_debug_string () final override;
void write_reproducer (reproducer &r) final override;
Expand All @@ -2429,6 +2454,11 @@ class dereference_rvalue : public lvalue

void visit_children (rvalue_visitor *v) final override;

void set_name (const char *new_name) final override {
m_ctxt->add_error (
NULL, "cannot change the name of type `dereference_rvalue`");
}

private:
string * make_debug_string () final override;
void write_reproducer (reproducer &r) final override;
Expand Down Expand Up @@ -2512,6 +2542,11 @@ class local : public lvalue

void write_to_dump (dump &d) final override;

string * get_name () const final override { return m_name; }
void set_name (const char *new_name) final override {
m_name = m_ctxt->new_string (new_name);
}

private:
string * make_debug_string () final override {
if (m_name)
Expand Down
13 changes: 13 additions & 0 deletions gcc/jit/libgccjit.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4858,6 +4858,19 @@ gcc_jit_lvalue_get_name (gcc_jit_lvalue *lvalue)
return name->c_str ();
}

/* Public entrypoint. See description in libgccjit.h.

After error-checking, this calls the trivial
gcc::jit::recording::lvalue::set_name method, in jit-recording.h. */

extern void
gcc_jit_lvalue_set_name (gcc_jit_lvalue *lvalue, const char *new_name)
{
RETURN_IF_FAIL (lvalue, NULL, NULL, "NULL lvalue");
RETURN_IF_FAIL (new_name, NULL, NULL, "NULL new_name");
lvalue->set_name (new_name);
}

/* Public entrypoint. See description in libgccjit.h.

After error-checking, this calls the trivial
Expand Down
6 changes: 6 additions & 0 deletions gcc/jit/libgccjit.h
Original file line number Diff line number Diff line change
Expand Up @@ -2242,6 +2242,12 @@ gcc_jit_lvalue_get_name (gcc_jit_lvalue *lvalue);

#define LIBGCCJIT_HAVE_gcc_jit_lvalue_get_name

/* Set a new name to the `lvalue`. */
extern void
gcc_jit_lvalue_set_name (gcc_jit_lvalue *lvalue, const char *new_name);

#define LIBGCCJIT_HAVE_gcc_jit_lvalue_set_name

extern void
gcc_jit_context_set_output_ident (gcc_jit_context *ctxt,
const char* output_ident);
Expand Down
5 changes: 5 additions & 0 deletions gcc/jit/libgccjit.map
Original file line number Diff line number Diff line change
Expand Up @@ -383,3 +383,8 @@ LIBGCCJIT_ABI_44{
global:
gcc_jit_lvalue_get_name;
} LIBGCCJIT_ABI_43;

LIBGCCJIT_ABI_45{
global:
gcc_jit_lvalue_set_name;
} LIBGCCJIT_ABI_44;
81 changes: 81 additions & 0 deletions gcc/testsuite/jit.dg/test-name.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/* { dg-do compile { target x86_64-*-* } } */

#include <stdlib.h>
#include <stdio.h>

#include "libgccjit.h"

// We want the debug info to check the function variable's name.
#define TEST_ESCHEWS_SET_OPTIONS
static void set_options (gcc_jit_context *ctxt, const char *argv0)
{
gcc_jit_context_set_bool_option(ctxt, GCC_JIT_BOOL_OPTION_DEBUGINFO, 1);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This already seems to be set by the test harness.
Was there a reason to add it here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Making it explicit.

}

#define TEST_COMPILING_TO_FILE
#define OUTPUT_KIND GCC_JIT_OUTPUT_KIND_ASSEMBLER
#define OUTPUT_FILENAME "output-of-test-name.c.s"
#include "harness.h"

void
create_code (gcc_jit_context *ctxt, void *user_data)
{
/* Let's try to inject the equivalent of:

int original_foo = 10;
*/
gcc_jit_type *int_type =
gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_INT);
gcc_jit_lvalue *foo =
gcc_jit_context_new_global (ctxt, NULL, GCC_JIT_GLOBAL_EXPORTED,
int_type, "original_foo");
gcc_jit_rvalue *ten = gcc_jit_context_new_rvalue_from_int (ctxt, int_type, 10);
gcc_jit_global_set_initializer_rvalue (foo, ten);

CHECK_STRING_VALUE (gcc_jit_lvalue_get_name (foo), "original_foo");
gcc_jit_lvalue_set_name (foo, "new_one");
CHECK_STRING_VALUE (gcc_jit_lvalue_get_name (foo), "new_one");

/* Let's try to inject te equivalent of:
int blabla() {
int the_var = 12;

return the_var;
}
*/
gcc_jit_function *blabla_func =
gcc_jit_context_new_function (ctxt, NULL,
GCC_JIT_FUNCTION_EXPORTED,
int_type,
"blabla",
0, NULL,
0);

gcc_jit_block *blabla_block = gcc_jit_function_new_block (blabla_func, NULL);

/* Build locals: */
gcc_jit_lvalue *the_var =
gcc_jit_function_new_local (blabla_func, NULL, int_type, "the_var");

/* int the_var = 0; */
gcc_jit_block_add_assignment (
blabla_block, NULL,
the_var,
gcc_jit_context_new_rvalue_from_int (ctxt, int_type, 0));

gcc_jit_block_end_with_return (
blabla_block, NULL,
gcc_jit_lvalue_as_rvalue (the_var));

CHECK_STRING_VALUE (gcc_jit_lvalue_get_name (the_var), "the_var");
gcc_jit_lvalue_set_name (the_var, "confiture");
CHECK_STRING_VALUE (gcc_jit_lvalue_get_name (the_var), "confiture");
}

/* { dg-final { jit-verify-output-file-was-created "" } } */
/* Check that the global was correctly renamed */
/* { dg-final { jit-verify-assembler-output-not "original_foo:" } } */
/* { dg-final { jit-verify-assembler-output "new_one:" } } */

/* { dg-final { jit-verify-assembler-output-not ".string\\s+\"the_var\"" } } */
/* { dg-final { jit-verify-assembler-output ".string\\s+\"confiture\"" } } */