From: Andrea Corallo <Andrea.Corallo@arm.com>
To: "gcc-patches@gcc.gnu.org" <gcc-patches@gcc.gnu.org>,
"jit@gcc.gnu.org" <jit@gcc.gnu.org>
Cc: "dmalcolm@redhat.com" <dmalcolm@redhat.com>, nd <nd@arm.com>
Subject: [PATCH][gcc] libgccjit: introduce version entry points
Date: Wed, 01 Jan 2020 00:00:00 -0000 [thread overview]
Message-ID: <gkrwo9stwq1.fsf@arm.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 1070 bytes --]
Hi all,
I think would be quite useful for client code to be able to probe for
the libgccjit version.
This patch add three entry points for that: gcc_jit_version_major,
gcc_jit_version_minor, gcc_jit_version_patchlevel.
Does not introduce regressions running make check-jit.
Feedback are welcome.
Andrea
gcc/jit/ChangeLog
2020-??-?? Andrea Corallo <andrea.corallo@arm.com>
* Make-lang.in (libgccjit.o): Add dependecy plus define BASEVER.
* docs/topics/compatibility.rst (LIBGCCJIT_ABI_13): New ABI tag
plus add version paragraph.
* libgccjit++.h (namespace gccjit::version): Add new namespace.
* libgccjit.c (gcc_jit_version_major, gcc_jit_version_minor)
(gcc_jit_version_patchlevel): New functions.
* libgccjit.h (LIBGCCJIT_HAVE_gcc_jit_version): New macro.
(gcc_jit_version_major, gcc_jit_version_minor)
(gcc_jit_version_patchlevel): New functions.
* libgccjit.map (LIBGCCJIT_ABI_13) New ABI tag.
gcc/testsuite/ChangeLog
2020-??-?? Andrea Corallo <andrea.corallo@arm.com>
* jit.dg/test-version.c: New testcase.
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: jit-version.patch --]
[-- Type: text/x-diff; name="jit-version.patch", Size: 5779 bytes --]
diff --git a/gcc/jit/Make-lang.in b/gcc/jit/Make-lang.in
index 38ddfad2889..d9430672283 100644
--- a/gcc/jit/Make-lang.in
+++ b/gcc/jit/Make-lang.in
@@ -84,6 +84,9 @@ jit_OBJS = attribs.o \
jit/jit-spec.o \
gcc.o
+CFLAGS-jit/libgccjit.o += -DBASEVER=$(BASEVER_s)
+libgccjit.o: $(BASEVER)
+
# Use strict warnings for this front end.
jit-warn = $(STRICT_WARN)
diff --git a/gcc/jit/docs/topics/compatibility.rst b/gcc/jit/docs/topics/compatibility.rst
index a6faee0810e..0c0ce070d72 100644
--- a/gcc/jit/docs/topics/compatibility.rst
+++ b/gcc/jit/docs/topics/compatibility.rst
@@ -61,6 +61,28 @@ You can see the symbol tags provided by libgccjit.so using ``objdump``:
LIBGCCJIT_ABI_0
[...snip...]
+Programmatically checking version
+***************
+
+Client code can programmatically check libgccjit version using:
+
+.. function:: int gcc_jit_version_major (void)
+
+ Return libgccjit major version. This is analogous to __GNUC__ in C code.
+
+.. function:: int gcc_jit_version_minor (void)
+
+ Return libgccjit minor version. This is analogous to
+ __GNUC_MINOR__ in C code.
+
+.. function:: int gcc_jit_version_patchlevel (void)
+
+ Return libgccjit patchlevel version. This is analogous to
+ __GNUC_PATCHLEVEL__ in C code.
+
+.. note:: These entry points has been added with ``LIBGCCJIT_ABI_13``
+ (see below).
+
ABI symbol tags
***************
@@ -182,3 +204,14 @@ entrypoints:
--------------------
``LIBGCCJIT_ABI_12`` covers the addition of
:func:`gcc_jit_context_new_bitfield`
+
+``LIBGCCJIT_ABI_13``
+--------------------
+``LIBGCCJIT_ABI_13`` covers the addition of version functions via API
+entrypoints:
+
+ * :func:`gcc_jit_version_major`
+
+ * :func:`gcc_jit_version_minor`
+
+ * :func:`gcc_jit_version_patchlevel`
diff --git a/gcc/jit/libgccjit++.h b/gcc/jit/libgccjit++.h
index 82a62d614c5..afb92194c28 100644
--- a/gcc/jit/libgccjit++.h
+++ b/gcc/jit/libgccjit++.h
@@ -49,6 +49,8 @@ namespace gccjit
class timer;
class auto_time;
+ namespace version {};
+
/* Errors within the API become C++ exceptions of this class. */
class error
{
@@ -1913,6 +1915,26 @@ auto_time::~auto_time ()
m_timer.pop (m_item_name);
}
+namespace version
+{
+inline int
+major ()
+{
+ return gcc_jit_version_major ();
+}
+
+inline int
+minor ()
+{
+ return gcc_jit_version_minor ();
+}
+
+inline int
+patchlevel ()
+{
+ return gcc_jit_version_patchlevel ();
+}
+} // namespace version
} // namespace gccjit
#endif /* #ifndef LIBGCCJIT_PLUS_PLUS_H */
diff --git a/gcc/jit/libgccjit.c b/gcc/jit/libgccjit.c
index 83055fc297b..572c82f053c 100644
--- a/gcc/jit/libgccjit.c
+++ b/gcc/jit/libgccjit.c
@@ -23,6 +23,7 @@ along with GCC; see the file COPYING3. If not see
#include "coretypes.h"
#include "timevar.h"
#include "typed-splay-tree.h"
+#include "cppbuiltin.h"
#include "libgccjit.h"
#include "jit-recording.h"
@@ -3175,3 +3176,27 @@ gcc_jit_context_new_rvalue_from_vector (gcc_jit_context *ctxt,
as_vec_type,
(gcc::jit::recording::rvalue **)elements);
}
+
+extern int
+gcc_jit_version_major (void)
+{
+ int major, minor, patchlevel;
+ parse_basever (&major, &minor, &patchlevel);
+ return major;
+}
+
+extern int
+gcc_jit_version_minor (void)
+{
+ int major, minor, patchlevel;
+ parse_basever (&major, &minor, &patchlevel);
+ return minor;
+}
+
+extern int
+gcc_jit_version_patchlevel (void)
+{
+ int major, minor, patchlevel;
+ parse_basever (&major, &minor, &patchlevel);
+ return patchlevel;
+}
diff --git a/gcc/jit/libgccjit.h b/gcc/jit/libgccjit.h
index 21a0dc09b03..1c5a12e9c01 100644
--- a/gcc/jit/libgccjit.h
+++ b/gcc/jit/libgccjit.h
@@ -1487,6 +1487,22 @@ gcc_jit_context_new_rvalue_from_vector (gcc_jit_context *ctxt,
size_t num_elements,
gcc_jit_rvalue **elements);
+#define LIBGCCJIT_HAVE_gcc_jit_version
+
+/* Functions to retrive libgccjit version.
+ Analogous to __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__ in C code.
+
+ These API entrypoints were added in LIBGCCJIT_ABI_13; you can test for their
+ presence using
+ #ifdef LIBGCCJIT_HAVE_gcc_jit_version
+ */
+extern int
+gcc_jit_version_major (void);
+extern int
+gcc_jit_version_minor (void);
+extern int
+gcc_jit_version_patchlevel (void);
+
#ifdef __cplusplus
}
#endif /* __cplusplus */
diff --git a/gcc/jit/libgccjit.map b/gcc/jit/libgccjit.map
index 4514bd3aa33..6137dd4b4b0 100644
--- a/gcc/jit/libgccjit.map
+++ b/gcc/jit/libgccjit.map
@@ -179,4 +179,11 @@ LIBGCCJIT_ABI_11 {
LIBGCCJIT_ABI_12 {
global:
gcc_jit_context_new_bitfield;
-} LIBGCCJIT_ABI_11;
\ No newline at end of file
+} LIBGCCJIT_ABI_11;
+
+LIBGCCJIT_ABI_13 {
+ global:
+ gcc_jit_version_major;
+ gcc_jit_version_minor;
+ gcc_jit_version_patchlevel;
+} LIBGCCJIT_ABI_12;
\ No newline at end of file
diff --git a/gcc/testsuite/jit.dg/test-version.c b/gcc/testsuite/jit.dg/test-version.c
new file mode 100644
index 00000000000..4338a00018b
--- /dev/null
+++ b/gcc/testsuite/jit.dg/test-version.c
@@ -0,0 +1,26 @@
+#include <stdlib.h>
+#include <stdio.h>
+
+#include "libgccjit.h"
+
+#include "harness.h"
+
+#ifndef LIBGCCJIT_HAVE_gcc_jit_version
+#error LIBGCCJIT_HAVE_gcc_jit_version was not defined
+#endif
+
+void
+create_code (gcc_jit_context *ctxt, void *user_data)
+{
+ /* Do nothing. */
+}
+
+void
+verify_code (gcc_jit_context *ctxt, gcc_jit_result *result)
+{
+ if (!gcc_jit_version_major ())
+ fail ("Major version is zero");
+ /* Minor and patchlevel can be zero. */
+ gcc_jit_version_minor ();
+ gcc_jit_version_patchlevel ();
+}
next reply other threads:[~2020-01-15 18:13 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-01-01 0:00 Andrea Corallo [this message]
2020-01-01 0:00 Andrea Corallo
2020-01-01 0:00 ` David Malcolm
2020-01-01 0:00 ` Florian Weimer
2020-01-01 0:00 ` Andrea Corallo
2020-01-01 0:00 ` David Malcolm
2020-03-08 14:08 ` Andrea Corallo
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=gkrwo9stwq1.fsf@arm.com \
--to=andrea.corallo@arm.com \
--cc=dmalcolm@redhat.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=jit@gcc.gnu.org \
--cc=nd@arm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).