mirror of
git://gcc.gnu.org/git/gcc.git
synced 2024-12-01 07:19:55 +08:00
libgccjit: Add support for setting the comment ident
gcc/jit/ChangeLog: * docs/topics/compatibility.rst (LIBGCCJIT_ABI_34): New ABI tag. * docs/topics/contexts.rst: Document gcc_jit_context_set_output_ident. * jit-playback.cc (set_output_ident): New method. * jit-playback.h (set_output_ident): New method. * jit-recording.cc (recording::context::set_output_ident, recording::output_ident::output_ident, recording::output_ident::~output_ident, recording::output_ident::replay_into, recording::output_ident::make_debug_string, recording::output_ident::write_reproducer): New methods. * jit-recording.h (class output_ident): New class. * libgccjit.cc (gcc_jit_context_set_output_ident): New function. * libgccjit.h (gcc_jit_context_set_output_ident): New function. * libgccjit.map: New function. gcc/testsuite/ChangeLog: * jit.dg/all-non-failing-tests.h: New test. * jit.dg/test-output-ident.c: New test.
This commit is contained in:
parent
d8cf8917ed
commit
cf544af03a
@ -445,3 +445,11 @@ on functions and variables:
|
|||||||
temporary variable:
|
temporary variable:
|
||||||
|
|
||||||
* :func:`gcc_jit_function_new_temp`
|
* :func:`gcc_jit_function_new_temp`
|
||||||
|
|
||||||
|
.. _LIBGCCJIT_ABI_34:
|
||||||
|
|
||||||
|
``LIBGCCJIT_ABI_34``
|
||||||
|
--------------------
|
||||||
|
``LIBGCCJIT_ABI_34`` covers the addition of
|
||||||
|
|
||||||
|
* :func:`gcc_jit_context_set_output_ident`
|
||||||
|
@ -604,3 +604,32 @@ Additional command-line options
|
|||||||
.. code-block:: c
|
.. code-block:: c
|
||||||
|
|
||||||
#ifdef LIBGCCJIT_HAVE_gcc_jit_context_add_driver_option
|
#ifdef LIBGCCJIT_HAVE_gcc_jit_context_add_driver_option
|
||||||
|
|
||||||
|
Output options
|
||||||
|
**************
|
||||||
|
|
||||||
|
.. function:: void gcc_jit_context_set_output_ident (gcc_jit_context *ctxt,\
|
||||||
|
const char* output_ident)
|
||||||
|
|
||||||
|
Set the identifier to write in the .comment section of the output file to
|
||||||
|
``output_ident``.
|
||||||
|
|
||||||
|
The parameter ``output_ident`` must be non-NULL.
|
||||||
|
|
||||||
|
This only works on some target, as you can see here:
|
||||||
|
https://gcc.gnu.org/onlinedocs/cpp/Other-Directives.html
|
||||||
|
|
||||||
|
Analogous to:
|
||||||
|
|
||||||
|
.. code-block:: c
|
||||||
|
|
||||||
|
#ident "My comment"
|
||||||
|
|
||||||
|
in C.
|
||||||
|
|
||||||
|
This entrypoint was added in :ref:`LIBGCCJIT_ABI_34`; you can test for
|
||||||
|
its presence using
|
||||||
|
|
||||||
|
.. code-block:: c
|
||||||
|
|
||||||
|
#ifdef LIBGCCJIT_HAVE_gcc_jit_context_set_output_ident
|
||||||
|
@ -329,6 +329,13 @@ get_type (enum gcc_jit_types type_)
|
|||||||
return new type (type_node);
|
return new type (type_node);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
playback::context::
|
||||||
|
set_output_ident (const char* ident)
|
||||||
|
{
|
||||||
|
targetm.asm_out.output_ident (ident);
|
||||||
|
}
|
||||||
|
|
||||||
/* Construct a playback::type instance (wrapping a tree) for the given
|
/* Construct a playback::type instance (wrapping a tree) for the given
|
||||||
array type. */
|
array type. */
|
||||||
|
|
||||||
|
@ -77,6 +77,9 @@ public:
|
|||||||
type *
|
type *
|
||||||
get_type (enum gcc_jit_types type);
|
get_type (enum gcc_jit_types type);
|
||||||
|
|
||||||
|
void
|
||||||
|
set_output_ident (const char* ident);
|
||||||
|
|
||||||
type *
|
type *
|
||||||
new_array_type (location *loc,
|
new_array_type (location *loc,
|
||||||
type *element_type,
|
type *element_type,
|
||||||
|
@ -1486,6 +1486,13 @@ recording::context::get_str_option (enum gcc_jit_str_option opt)
|
|||||||
return m_str_options[opt];
|
return m_str_options[opt];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
recording::context::set_output_ident (const char *ident)
|
||||||
|
{
|
||||||
|
recording::output_ident *memento = new output_ident (this, ident);
|
||||||
|
record (memento);
|
||||||
|
}
|
||||||
|
|
||||||
/* Set the given integer option for this context, or add an error if
|
/* Set the given integer option for this context, or add an error if
|
||||||
it's not recognized.
|
it's not recognized.
|
||||||
|
|
||||||
@ -2326,6 +2333,52 @@ recording::string::write_reproducer (reproducer &)
|
|||||||
/* Empty. */
|
/* Empty. */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* The implementation of class gcc::jit::recording::output_ident. */
|
||||||
|
|
||||||
|
/* Constructor for gcc::jit::recording::output_ident, allocating a
|
||||||
|
copy of the given text using new char[]. */
|
||||||
|
|
||||||
|
recording::output_ident::output_ident (context *ctxt, const char *ident)
|
||||||
|
: memento (ctxt)
|
||||||
|
{
|
||||||
|
m_ident = ident ? xstrdup (ident) : NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Destructor for gcc::jit::recording::output_ident. */
|
||||||
|
|
||||||
|
recording::output_ident::~output_ident ()
|
||||||
|
{
|
||||||
|
free (m_ident);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Implementation of pure virtual hook recording::memento::replay_into
|
||||||
|
for recording::output_ident. */
|
||||||
|
|
||||||
|
void
|
||||||
|
recording::output_ident::replay_into (replayer *r)
|
||||||
|
{
|
||||||
|
r->set_output_ident (m_ident);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Implementation of recording::memento::make_debug_string for output_ident. */
|
||||||
|
|
||||||
|
recording::string *
|
||||||
|
recording::output_ident::make_debug_string ()
|
||||||
|
{
|
||||||
|
return m_ctxt->new_string (m_ident);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Implementation of recording::memento::write_reproducer for output_ident. */
|
||||||
|
|
||||||
|
void
|
||||||
|
recording::output_ident::write_reproducer (reproducer &r)
|
||||||
|
{
|
||||||
|
r.write (" gcc_jit_context_set_output_ident (%s, \"%s\");",
|
||||||
|
r.get_identifier (get_context ()),
|
||||||
|
m_ident);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* The implementation of class gcc::jit::recording::location. */
|
/* The implementation of class gcc::jit::recording::location. */
|
||||||
|
|
||||||
/* Implementation of recording::memento::replay_into for locations.
|
/* Implementation of recording::memento::replay_into for locations.
|
||||||
|
@ -266,6 +266,9 @@ public:
|
|||||||
const char*
|
const char*
|
||||||
get_str_option (enum gcc_jit_str_option opt);
|
get_str_option (enum gcc_jit_str_option opt);
|
||||||
|
|
||||||
|
void
|
||||||
|
set_output_ident (const char *output_ident);
|
||||||
|
|
||||||
void
|
void
|
||||||
set_int_option (enum gcc_jit_int_option opt,
|
set_int_option (enum gcc_jit_int_option opt,
|
||||||
int value);
|
int value);
|
||||||
@ -505,6 +508,25 @@ private:
|
|||||||
bool m_escaped;
|
bool m_escaped;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class output_ident : public memento
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
output_ident (context *ctxt, const char *text);
|
||||||
|
~output_ident ();
|
||||||
|
|
||||||
|
void replay_into (replayer *) final override;
|
||||||
|
|
||||||
|
output_ident (const output_ident&) = delete;
|
||||||
|
output_ident& operator= (const output_ident&) = delete;
|
||||||
|
|
||||||
|
private:
|
||||||
|
string * make_debug_string () final override;
|
||||||
|
void write_reproducer (reproducer &r) final override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
char *m_ident;
|
||||||
|
};
|
||||||
|
|
||||||
class location : public memento
|
class location : public memento
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@ -3883,6 +3883,22 @@ gcc_jit_context_compile_to_file (gcc_jit_context *ctxt,
|
|||||||
ctxt->compile_to_file (output_kind, output_path);
|
ctxt->compile_to_file (output_kind, output_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Public entrypoint. See description in libgccjit.h.
|
||||||
|
|
||||||
|
After error-checking, the real work is done by the
|
||||||
|
gcc::jit::recording::context::set_str_option method in
|
||||||
|
jit-recording.cc. */
|
||||||
|
|
||||||
|
void
|
||||||
|
gcc_jit_context_set_output_ident (gcc_jit_context *ctxt,
|
||||||
|
const char* output_ident)
|
||||||
|
{
|
||||||
|
RETURN_IF_FAIL (ctxt, NULL, NULL, "NULL context");
|
||||||
|
RETURN_IF_FAIL (output_ident, ctxt, NULL, "NULL output_ident");
|
||||||
|
JIT_LOG_FUNC (ctxt->get_logger ());
|
||||||
|
|
||||||
|
ctxt->set_output_ident (output_ident);
|
||||||
|
}
|
||||||
|
|
||||||
/* Public entrypoint. See description in libgccjit.h.
|
/* Public entrypoint. See description in libgccjit.h.
|
||||||
|
|
||||||
|
@ -2153,6 +2153,12 @@ gcc_jit_lvalue_add_string_attribute (gcc_jit_lvalue *variable,
|
|||||||
enum gcc_jit_variable_attribute attribute,
|
enum gcc_jit_variable_attribute attribute,
|
||||||
const char* value);
|
const char* value);
|
||||||
|
|
||||||
|
extern void
|
||||||
|
gcc_jit_context_set_output_ident (gcc_jit_context *ctxt,
|
||||||
|
const char* output_ident);
|
||||||
|
|
||||||
|
#define LIBGCCJIT_HAVE_gcc_jit_context_set_output_ident
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif /* __cplusplus */
|
#endif /* __cplusplus */
|
||||||
|
@ -320,3 +320,8 @@ LIBGCCJIT_ABI_33 {
|
|||||||
global:
|
global:
|
||||||
gcc_jit_function_new_temp;
|
gcc_jit_function_new_temp;
|
||||||
} LIBGCCJIT_ABI_32;
|
} LIBGCCJIT_ABI_32;
|
||||||
|
|
||||||
|
LIBGCCJIT_ABI_34 {
|
||||||
|
global:
|
||||||
|
gcc_jit_context_set_output_ident;
|
||||||
|
} LIBGCCJIT_ABI_33;
|
||||||
|
@ -283,6 +283,9 @@
|
|||||||
#undef create_code
|
#undef create_code
|
||||||
#undef verify_code
|
#undef verify_code
|
||||||
|
|
||||||
|
/* test-output-ident.c: This can't be in the testcases array as it
|
||||||
|
is target-specific. */
|
||||||
|
|
||||||
/* test-quadratic.c */
|
/* test-quadratic.c */
|
||||||
#define create_code create_code_quadratic
|
#define create_code create_code_quadratic
|
||||||
#define verify_code verify_code_quadratic
|
#define verify_code verify_code_quadratic
|
||||||
|
23
gcc/testsuite/jit.dg/test-output-ident.c
Normal file
23
gcc/testsuite/jit.dg/test-output-ident.c
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
/* { dg-do compile { target x86_64-*-* } } */
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#include "libgccjit.h"
|
||||||
|
|
||||||
|
#define TEST_COMPILING_TO_FILE
|
||||||
|
#define OUTPUT_KIND GCC_JIT_OUTPUT_KIND_ASSEMBLER
|
||||||
|
#define OUTPUT_FILENAME "output-of-test-output-ident.c.s"
|
||||||
|
#include "harness.h"
|
||||||
|
|
||||||
|
void
|
||||||
|
create_code (gcc_jit_context *ctxt, void *user_data)
|
||||||
|
{
|
||||||
|
/* Let's try to inject the equivalent of:
|
||||||
|
#ident "My comment"
|
||||||
|
*/
|
||||||
|
gcc_jit_context_set_output_ident (ctxt, "My comment");
|
||||||
|
}
|
||||||
|
|
||||||
|
/* { dg-final { jit-verify-output-file-was-created "" } } */
|
||||||
|
/* { dg-final { jit-verify-assembler-output ".ident \"My comment\"" } } */
|
Loading…
Reference in New Issue
Block a user