diff options
author | Iain Buclaw <ibuclaw@gdcproject.org> | 2021-04-12 01:39:08 +0200 |
---|---|---|
committer | Iain Buclaw <ibuclaw@gdcproject.org> | 2021-04-17 12:50:25 +0200 |
commit | d81bc495a426b0020e44a9764fd904462a39983b (patch) | |
tree | 8376a0f59ea36d081a0c1e6c8628ff0cdf560b2d /gcc/d | |
parent | b96c7a063b27986e6e0ef2b7a1684421583a332d (diff) | |
download | gcc-d81bc495a426b0020e44a9764fd904462a39983b.zip gcc-d81bc495a426b0020e44a9764fd904462a39983b.tar.gz gcc-d81bc495a426b0020e44a9764fd904462a39983b.tar.bz2 |
d: Implement __traits(getTargetInfo, "objectFormat")
Following on from adding TARGET_D_REGISTER_OS_TARGET_INFO, this adds the
required handlers to implement `__traits(getTargetInfo, "objectFormat")'
for all platforms that have D support files.
Some back-ends (i386, rs6000, and pa) have some awarenes of the what
object format they are compiling for, so new getTargetInfo handlers have
been have added both to those back-ends as well as platform-specific
target files to override the default in the D front-end.
gcc/ChangeLog:
* config/darwin-d.c (darwin_d_handle_target_object_format): New
function.
(darwin_d_register_target_info): New function.
(TARGET_D_REGISTER_OS_TARGET_INFO): Define.
* config/dragonfly-d.c (dragonfly_d_handle_target_object_format): New
function.
(dragonfly_d_register_target_info): New function.
(TARGET_D_REGISTER_OS_TARGET_INFO): Define.
* config/freebsd-d.c (freebsd_d_handle_target_object_format): New
function.
(freebsd_d_register_target_info): New function.
(TARGET_D_REGISTER_OS_TARGET_INFO): Define.
* config/glibc-d.c (glibc_d_handle_target_object_format): New
function.
(glibc_d_register_target_info): New function.
(TARGET_D_REGISTER_OS_TARGET_INFO): Define.
* 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/i386/winnt-d.c (winnt_d_handle_target_object_format): New
function.
(winnt_d_register_target_info): New function.
(TARGET_D_REGISTER_OS_TARGET_INFO): Define.
* config/netbsd-d.c (netbsd_d_handle_target_object_format): New
function.
(netbsd_d_register_target_info): New function.
(TARGET_D_REGISTER_OS_TARGET_INFO): Define.
* config/openbsd-d.c (openbsd_d_handle_target_object_format): New
function.
(openbsd_d_register_target_info): New function.
(TARGET_D_REGISTER_OS_TARGET_INFO): Define.
* 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.
* config/sol2-d.c (solaris_d_handle_target_object_format): New
function.
(solaris_d_register_target_info): New function.
(TARGET_D_REGISTER_OS_TARGET_INFO): Define.
gcc/d/ChangeLog:
* d-target.cc (d_handle_target_object_format): New function.
(d_language_target_info): Add d_handle_target_object_format as handler
for objectFormat key.
(Target::getTargetInfo): Continue if handler returned NULL_TREE.
Diffstat (limited to 'gcc/d')
-rw-r--r-- | gcc/d/d-target.cc | 35 |
1 files changed, 31 insertions, 4 deletions
diff --git a/gcc/d/d-target.cc b/gcc/d/d-target.cc index be354d9..1488bce 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,25 @@ 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; + +#ifdef OBJECT_FORMAT_ELF + objfmt = "elf"; +#else + if (TARGET_COFF || TARGET_PECOFF) + objfmt = "coff"; + else + objfmt = ""; +#endif + + 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 +553,20 @@ 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) (); + /* Handler didn't return a result, meaning it really does not support + the key in the current target configuration. Check whether there + are any other handlers which may recognize the key. */ + if (result == NULL_TREE) + continue; + } else - result = build_string_literal (1, ""); + result = build_string_literal (1, ""); gcc_assert (result); return d_eval_constant_expression (loc, result); |