public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc(refs/users/ibuclaw/heads/mingw)] d: Add TARGET_D_OBJECT_FORMAT
@ 2021-04-13 20:42 Iain Buclaw
  0 siblings, 0 replies; only message in thread
From: Iain Buclaw @ 2021-04-13 20:42 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:5e4c80bd53a149436f466254b09a046d908b01a8

commit 5e4c80bd53a149436f466254b09a046d908b01a8
Author: Iain Buclaw <ibuclaw@gdcproject.org>
Date:   Mon Apr 12 01:39:08 2021 +0200

    d: Add TARGET_D_OBJECT_FORMAT
    
    This is used to implement `__traits(getTargetInfo, "objectFormat")' for
    all platforms that have D support files.  Some back-ends (i386, rs6000,
    and pa) are possibly aware of the what alternative object format they
    are compiling for, so macros have been conditionally defined in those
    locations as well.
    
    gcc/ChangeLog:
    
            * config/darwin-d.c (TARGET_D_OBJECT_FORMAT): Define.
            * config/dragonfly-d.c (TARGET_D_OBJECT_FORMAT): Likewise.
            * config/elfos.h (TARGET_D_OBJECT_FORMAT): Likewise.
            * config/freebsd-d.c (TARGET_D_OBJECT_FORMAT): Likewise.
            * config/glibc-d.c (TARGET_D_OBJECT_FORMAT): Likewise.
            * config/i386/winnt-d.c (TARGET_D_OBJECT_FORMAT): Define.
            * config/netbsd-d.c (TARGET_D_OBJECT_FORMAT): Likewise.
            * config/openbsd-d.c (TARGET_D_OBJECT_FORMAT): Likewise.
            * config/sol2-d.c (TARGET_D_OBJECT_FORMAT): Likewise.
            * config/i386/i386-d.c (ix86_d_handle_target_object_format): New
            function.
            (ix86_d_register_target_info): Add ix86_d_handle_target_object_format
            as handler for objectFormat key.
            * config/pa/pa-d.c (pa_d_handle_target_object_format): New function.
            (pa_d_register_target_info): Add pa_d_handle_target_object_format as
            handler for objectFormat key.
            * config/rs6000/rs6000-d.c (rs6000_d_handle_target_object_format): New
            function.
            (rs6000_d_register_target_info): Add
            rs6000_d_handle_target_object_format as handler for objectFormat key.
            * doc/tm.texi: Regenerate.
            * doc/tm.texi.in (D language and ABI): Add @hook for
            TARGET_D_OBJECT_FORMAT.
    
    gcc/d/ChangeLog:
    
            * d-target.cc (d_handle_target_object_format): New function.
            (d_target_info_spec): Add d_handle_target_object_format as handler for
            objectFormat key.
            (Target::getTargetInfo): Fix indentation.
            * d-target.def (d_object_format): New hook.

Diff:
---
 gcc/config/darwin-d.c        |  5 +++++
 gcc/config/dragonfly-d.c     |  5 +++++
 gcc/config/elfos.h           |  2 ++
 gcc/config/freebsd-d.c       |  5 +++++
 gcc/config/glibc-d.c         |  6 ++++++
 gcc/config/i386/i386-d.c     | 21 +++++++++++++++++++++
 gcc/config/i386/winnt-d.c    |  5 +++++
 gcc/config/netbsd-d.c        |  8 ++++++++
 gcc/config/openbsd-d.c       |  8 ++++++++
 gcc/config/pa/pa-d.c         | 14 ++++++++++++++
 gcc/config/rs6000/rs6000-d.c | 23 +++++++++++++++++++++++
 gcc/config/sol2-d.c          |  6 ++++++
 gcc/d/d-target.cc            | 23 +++++++++++++++++++----
 gcc/d/d-target.def           |  9 +++++++++
 gcc/doc/tm.texi              |  7 +++++++
 gcc/doc/tm.texi.in           |  2 ++
 16 files changed, 145 insertions(+), 4 deletions(-)

diff --git a/gcc/config/darwin-d.c b/gcc/config/darwin-d.c
index afc32da4ad8..63ed2011df7 100644
--- a/gcc/config/darwin-d.c
+++ b/gcc/config/darwin-d.c
@@ -35,6 +35,11 @@ darwin_d_os_builtins (void)
 #undef TARGET_D_OS_VERSIONS
 #define TARGET_D_OS_VERSIONS darwin_d_os_builtins
 
+/* Define TARGET_D_OBJECT_FORMAT for Darwin targets.  */
+
+#undef TARGET_D_OBJECT_FORMAT
+#define TARGET_D_OBJECT_FORMAT "macho"
+
 /* Define TARGET_D_MINFO_SECTION for Darwin targets.  */
 
 #undef TARGET_D_MINFO_SECTION
diff --git a/gcc/config/dragonfly-d.c b/gcc/config/dragonfly-d.c
index 76f4cc02ff7..679ee76cabe 100644
--- a/gcc/config/dragonfly-d.c
+++ b/gcc/config/dragonfly-d.c
@@ -34,4 +34,9 @@ dragonfly_d_os_builtins (void)
 #undef TARGET_D_OS_VERSIONS
 #define TARGET_D_OS_VERSIONS dragonfly_d_os_builtins
 
+/* Define TARGET_D_OBJECT_FORMAT for DragonFly targets.  */
+
+#undef TARGET_D_OBJECT_FORMAT
+#define TARGET_D_OBJECT_FORMAT "elf"
+
 struct gcc_targetdm targetdm = TARGETDM_INITIALIZER;
diff --git a/gcc/config/elfos.h b/gcc/config/elfos.h
index 7a736cc3b89..1a951f460a9 100644
--- a/gcc/config/elfos.h
+++ b/gcc/config/elfos.h
@@ -480,3 +480,5 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 #define TARGET_D_MINFO_SECTION "minfo"
 #define TARGET_D_MINFO_START_NAME "__start_minfo"
 #define TARGET_D_MINFO_END_NAME "__stop_minfo"
+#undef TARGET_D_OBJECT_FORMAT
+#define TARGET_D_OBJECT_FORMAT "elf"
diff --git a/gcc/config/freebsd-d.c b/gcc/config/freebsd-d.c
index 8a8ddd92884..7287797bddd 100644
--- a/gcc/config/freebsd-d.c
+++ b/gcc/config/freebsd-d.c
@@ -40,4 +40,9 @@ freebsd_d_os_builtins (void)
 #undef TARGET_D_OS_VERSIONS
 #define TARGET_D_OS_VERSIONS freebsd_d_os_builtins
 
+/* Define TARGET_D_OBJECT_FORMAT for FreeBSD targets.  */
+
+#undef TARGET_D_OBJECT_FORMAT
+#define TARGET_D_OBJECT_FORMAT "elf"
+
 struct gcc_targetdm targetdm = TARGETDM_INITIALIZER;
diff --git a/gcc/config/glibc-d.c b/gcc/config/glibc-d.c
index 092c5d805a6..e84e76d4d4d 100644
--- a/gcc/config/glibc-d.c
+++ b/gcc/config/glibc-d.c
@@ -45,4 +45,10 @@ glibc_d_os_builtins (void)
 #undef TARGET_D_OS_VERSIONS
 #define TARGET_D_OS_VERSIONS glibc_d_os_builtins
 
+/* Define TARGET_D_OBJECT_FORMAT for Glibc targets.  */
+
+#ifndef TARGET_D_OBJECT_FORMAT
+#define TARGET_D_OBJECT_FORMAT "elf"
+#endif
+
 struct gcc_targetdm targetdm = TARGETDM_INITIALIZER;
diff --git a/gcc/config/i386/i386-d.c b/gcc/config/i386/i386-d.c
index da5958c3e7d..043c8162843 100644
--- a/gcc/config/i386/i386-d.c
+++ b/gcc/config/i386/i386-d.c
@@ -60,6 +60,26 @@ ix86_d_handle_target_float_abi (void)
   return build_string_literal (strlen (abi) + 1, abi);
 }
 
+/* Handle a call to `__traits(getTargetInfo, "objectFormat")'.  */
+
+static tree
+ix86_d_handle_target_object_format (void)
+{
+  const char *objfmt = targetdm.d_object_format;
+
+  if (objfmt == NULL)
+    {
+      if (TARGET_MACHO)
+	objfmt = "macho";
+      else if (TARGET_COFF || TARGET_PECOFF)
+	objfmt = "coff";
+      else
+	objfmt = "";
+    }
+
+  return build_string_literal (strlen (objfmt) + 1, objfmt);
+}
+
 /* Implement TARGET_D_REGISTER_CPU_TARGET_INFO.  */
 
 void
@@ -67,6 +87,7 @@ ix86_d_register_target_info (void)
 {
   const struct d_target_info_spec handlers[] = {
     { "floatAbi", ix86_d_handle_target_float_abi },
+    { "objectFormat", ix86_d_handle_target_object_format },
     { NULL, NULL },
   };
 
diff --git a/gcc/config/i386/winnt-d.c b/gcc/config/i386/winnt-d.c
index 8a6b9c57d8d..79388b07185 100644
--- a/gcc/config/i386/winnt-d.c
+++ b/gcc/config/i386/winnt-d.c
@@ -42,6 +42,11 @@ winnt_d_os_builtins (void)
 #undef TARGET_D_OS_VERSIONS
 #define TARGET_D_OS_VERSIONS winnt_d_os_builtins
 
+/* Define TARGET_D_OBJECT_FORMAT for Windows targets.  */
+
+#undef TARGET_D_OBJECT_FORMAT
+#define TARGET_D_OBJECT_FORMAT "coff"
+
 /* Define TARGET_D_MINFO_SECTION for Windows targets.  */
 
 #undef TARGET_D_MINFO_SECTION
diff --git a/gcc/config/netbsd-d.c b/gcc/config/netbsd-d.c
index c3ac01067fe..a60fa71a542 100644
--- a/gcc/config/netbsd-d.c
+++ b/gcc/config/netbsd-d.c
@@ -26,6 +26,8 @@ along with GCC; see the file COPYING3.  If not see
 #include "d/d-target.h"
 #include "d/d-target-def.h"
 
+/* Define TARGET_D_OS_VERSIONS for NetBSD targets.  */
+
 static void
 netbsd_d_os_builtins (void)
 {
@@ -36,4 +38,10 @@ netbsd_d_os_builtins (void)
 #undef TARGET_D_OS_VERSIONS
 #define TARGET_D_OS_VERSIONS netbsd_d_os_builtins
 
+/* Define TARGET_D_OBJECT_FORMAT for NetBSD targets.  */
+
+#ifndef TARGET_D_OBJECT_FORMAT
+#define TARGET_D_OBJECT_FORMAT "elf"
+#endif
+
 struct gcc_targetdm targetdm = TARGETDM_INITIALIZER;
diff --git a/gcc/config/openbsd-d.c b/gcc/config/openbsd-d.c
index b42727e1d5a..a9ace1cc6d1 100644
--- a/gcc/config/openbsd-d.c
+++ b/gcc/config/openbsd-d.c
@@ -26,6 +26,8 @@ along with GCC; see the file COPYING3.  If not see
 #include "d/d-target.h"
 #include "d/d-target-def.h"
 
+/* Define TARGET_D_OS_VERSIONS for OpenBSD targets.  */
+
 static void
 openbsd_d_os_builtins (void)
 {
@@ -36,4 +38,10 @@ openbsd_d_os_builtins (void)
 #undef TARGET_D_OS_VERSIONS
 #define TARGET_D_OS_VERSIONS openbsd_d_os_builtins
 
+/* Define TARGET_D_OBJECT_FORMAT for OpenBSD targets.  */
+
+#ifndef TARGET_D_OBJECT_FORMAT
+#define TARGET_D_OBJECT_FORMAT "elf"
+#endif
+
 struct gcc_targetdm targetdm = TARGETDM_INITIALIZER;
diff --git a/gcc/config/pa/pa-d.c b/gcc/config/pa/pa-d.c
index 41b2f1848e7..54a373562aa 100644
--- a/gcc/config/pa/pa-d.c
+++ b/gcc/config/pa/pa-d.c
@@ -55,6 +55,19 @@ pa_d_handle_target_float_abi (void)
   return build_string_literal (strlen (abi) + 1, abi);
 }
 
+/* Handle a call to `__traits(getTargetInfo, "objectFormat")'.  */
+
+static tree
+pa_d_handle_target_object_format (void)
+{
+  const char *objfmt = targetdm.d_object_format;
+
+  if (objfmt == NULL)
+    objfmt = TARGET_SOM ? "som" : "elf";
+
+  return build_string_literal (strlen (objfmt) + 1, objfmt);
+}
+
 /* Implement TARGET_D_REGISTER_CPU_TARGET_INFO.  */
 
 void
@@ -62,6 +75,7 @@ pa_d_register_target_info (void)
 {
   const struct d_target_info_spec handlers[] = {
     { "floatAbi", pa_d_handle_target_float_abi },
+    { "objectFormat", pa_d_handle_target_object_format },
     { NULL, NULL },
   };
 
diff --git a/gcc/config/rs6000/rs6000-d.c b/gcc/config/rs6000/rs6000-d.c
index 755de42733b..0efb6e3e89a 100644
--- a/gcc/config/rs6000/rs6000-d.c
+++ b/gcc/config/rs6000/rs6000-d.c
@@ -63,6 +63,28 @@ rs6000_d_handle_target_float_abi (void)
   return build_string_literal (strlen (abi) + 1, abi);
 }
 
+/* Handle a call to `__traits(getTargetInfo, "objectFormat")'.  */
+
+static tree
+rs6000_d_handle_target_object_format (void)
+{
+  const char *objfmt = targetdm.d_object_format;
+
+  if (objfmt == NULL)
+    {
+      if (TARGET_ELF)
+	objfmt = "elf";
+      else if (TARGET_MACHO)
+	objfmt = "macho";
+      else if (TARGET_XCOFF)
+	objfmt = "coff";
+      else
+	objfmt = "";
+    }
+
+  return build_string_literal (strlen (objfmt) + 1, objfmt);
+}
+
 /* Implement TARGET_D_REGISTER_CPU_TARGET_INFO.  */
 
 void
@@ -70,6 +92,7 @@ rs6000_d_register_target_info (void)
 {
   const struct d_target_info_spec handlers[] = {
     { "floatAbi", rs6000_d_handle_target_float_abi },
+    { "objectFormat", rs6000_d_handle_target_object_format },
     { NULL, NULL },
   };
 
diff --git a/gcc/config/sol2-d.c b/gcc/config/sol2-d.c
index 529d365296c..84f7dad4035 100644
--- a/gcc/config/sol2-d.c
+++ b/gcc/config/sol2-d.c
@@ -36,4 +36,10 @@ solaris_d_os_builtins (void)
 #undef TARGET_D_OS_VERSIONS
 #define TARGET_D_OS_VERSIONS solaris_d_os_builtins
 
+/* Define TARGET_D_OBJECT_FORMAT for Solaris targets.  */
+
+#ifndef TARGET_D_OBJECT_FORMAT
+#define TARGET_D_OBJECT_FORMAT "elf"
+#endif
+
 struct gcc_targetdm targetdm = TARGETDM_INITIALIZER;
diff --git a/gcc/d/d-target.cc b/gcc/d/d-target.cc
index be354d9f1f0..6036905afb7 100644
--- a/gcc/d/d-target.cc
+++ b/gcc/d/d-target.cc
@@ -47,6 +47,7 @@ Target target;
 /* Internal key handlers for `__traits(getTargetInfo)'.  */
 static tree d_handle_target_cpp_std (void);
 static tree d_handle_target_cpp_runtime_library (void);
+static tree d_handle_target_object_format (void);
 
 /* In [traits/getTargetInfo], a reliable subset of getTargetInfo keys exists
    which are always available.  */
@@ -56,7 +57,7 @@ static const struct d_target_info_spec d_language_target_info[] =
   { "cppStd", d_handle_target_cpp_std },
   { "cppRuntimeLibrary", d_handle_target_cpp_runtime_library },
   { "floatAbi", NULL },
-  { "objectFormat", NULL },
+  { "objectFormat", d_handle_target_object_format },
   { NULL, NULL },
 };
 
@@ -517,6 +518,20 @@ d_handle_target_cpp_runtime_library (void)
   return build_string_literal (strlen (libstdcxx) + 1, libstdcxx);
 }
 
+/* Handle a call to `__traits(getTargetInfo, "objectFormat")'.  */
+
+tree
+d_handle_target_object_format (void)
+{
+  const char *objfmt = targetdm.d_object_format;
+
+  /* `objectFormat' key not supported.  */
+  if (objfmt == NULL)
+    objfmt = "";
+
+  return build_string_literal (strlen (objfmt) + 1, objfmt);
+}
+
 /* Look up the target info KEY in the available getTargetInfo tables, and return
    the result as an Expression, or NULL if KEY is not found.  When the key must
    always exist, but is not supported, an empty string expression is returned.
@@ -533,13 +548,13 @@ Target::getTargetInfo (const char *key, const Loc &loc)
       tree result;
 
       if (strcmp (key, spec->name) != 0)
-       continue;
+	continue;
 
       /* Get the requested information, or empty string if unhandled.  */
       if (spec->handler)
-       result = (spec->handler) ();
+	result = (spec->handler) ();
       else
-       result = build_string_literal (1, "");
+	result = build_string_literal (1, "");
 
       gcc_assert (result);
       return d_eval_constant_expression (loc, result);
diff --git a/gcc/d/d-target.def b/gcc/d/d-target.def
index aa6bf55e6e6..043e2a95522 100644
--- a/gcc/d/d-target.def
+++ b/gcc/d/d-target.def
@@ -66,6 +66,15 @@ the target operating system.",
  void, (void),
  hook_void_void)
 
+/* Target object format, for `__traits(getTargetInfo)'.  */
+DEFHOOKPOD
+(d_object_format,
+ "The target object format that code is being compiled for, used by the\n\
+@code{__traits(getTargetInfo)} extension to implement the target information\n\
+key @code{objectFormat}.  The default value of this hook is @code{NULL},\n\
+which indicates that the key is not supported.",
+ const char *, NULL)
+
 /* ModuleInfo section name and brackets.  */
 DEFHOOKPOD
 (d_minfo_section,
diff --git a/gcc/doc/tm.texi b/gcc/doc/tm.texi
index 97c8eebcd6f..1b198b47d47 100644
--- a/gcc/doc/tm.texi
+++ b/gcc/doc/tm.texi
@@ -10822,6 +10822,13 @@ Same as @code{TARGET_D_CPU_TARGET_INFO}, but is used for keys relating to
 the target operating system.
 @end deftypefn
 
+@deftypevr {D Target Hook} {const char *} TARGET_D_OBJECT_FORMAT
+The target object format that code is being compiled for, used by the
+@code{__traits(getTargetInfo)} extension to implement the target information
+key @code{objectFormat}.  The default value of this hook is @code{NULL},
+which indicates that the key is not supported.
+@end deftypevr
+
 @deftypevr {D Target Hook} {const char *} TARGET_D_MINFO_SECTION
 Contains the name of the section in which module info references should be
 placed.  This section is expected to be bracketed by two symbols to indicate
diff --git a/gcc/doc/tm.texi.in b/gcc/doc/tm.texi.in
index e2d49ee9f57..61e0f07c362 100644
--- a/gcc/doc/tm.texi.in
+++ b/gcc/doc/tm.texi.in
@@ -7361,6 +7361,8 @@ floating-point support; they are not included in this mechanism.
 
 @hook TARGET_D_REGISTER_OS_TARGET_INFO
 
+@hook TARGET_D_OBJECT_FORMAT
+
 @hook TARGET_D_MINFO_SECTION
 
 @hook TARGET_D_MINFO_START_NAME


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-04-13 20:42 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-13 20:42 [gcc(refs/users/ibuclaw/heads/mingw)] d: Add TARGET_D_OBJECT_FORMAT Iain Buclaw

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).