[PATCH 7/13] D: Add D language support to GCC targets.
This patch add D language support to targets of GCC itself.
These are used to declare pre-defined version identifiers in the D language that describe something about the target that the front-end itself is unable to obtain. Version conditions in D can be thought of as being like the target macros of C, but that where the similarity ends.
---
gcc/ChangeLog:
* config/aarch64/aarch64.h (TARGET_CPU_D_BUILTINS): Define.
* config/alpha/alpha.h (TARGET_CPU_D_BUILTINS): Define.
* config/alpha/linux.h (TARGET_OS_D_BUILTINS): Define.
* config/arm/arm.h (TARGET_CPU_D_BUILTINS): Define.
* config/arm/linux-eabi.h (TARGET_OS_D_BUILTINS): Define.
* config/darwin.h (TARGET_OS_D_BUILTINS): Define.
* config/freebsd.h (TARGET_OS_D_BUILTINS): Define.
* config/gnu.h (TARGET_OS_D_BUILTINS): Define.
* config/i386/cygwin.h (TARGET_OS_D_BUILTINS): Define.
* config/i386/i386.h (TARGET_CPU_D_BUILTINS): Define.
* config/i386/linux-common.h (TARGET_OS_D_BUILTINS): Define.
* config/i386/mingw32.h (TARGET_OS_D_BUILTINS): Define.
(TARGET_GENERIC_MINGW_OS_D_BUILTINS): Define.
* config/ia64/ia64.h (TARGET_CPU_D_BUILTINS): Define.
* config/kfreebsd-gnu.h (TARGET_OS_D_BUILTINS): Define.
* config/kopernsolaris-gnu.h (TARGET_OS_D_BUILTINS): Define.
* config/linux-android.h (ANDROID_TARGET_OS_D_BUILTINS): Define.
* config/linux.h (TARGET_OS_D_BUILTINS): Define.
(TARGET_GENERIC_LINUX_OS_D_BUILTINS): Define.
* config/mips/linux-common.h (TARGET_OS_D_BUILTINS): Define.
* config/mips/mips.h (TARGET_CPU_D_BUILTINS): Define.
* config/netbsd.h (TARGET_OS_D_BUILTINS): Define.
* config/openbsd.h (TARGET_OS_D_BUILTINS): Define.
* config/pa.h (TARGET_CPU_D_BUILTINS): Define.
* config/rs6000/aix.h (TARGET_OS_D_BUILTINS): Define.
* config/rs6000/linux.h (TARGET_OS_D_BUILTINS): Define.
* config/rs6000/linux64.h (TARGET_OS_D_BUILTINS): Define.
* config/rs6000/rs6000.h (TARGET_CPU_D_BUILTINS): Define.
* config/s390/s390.h (TARGET_CPU_D_BUILTINS): Define.
* config/sh/sh.h (TARGET_CPU_D_BUILTINS): Define.
* config/sparc/sparc.h (TARGET_CPU_D_BUILTINS): Define.
@@ -26,6 +26,14 @@
#define TARGET_CPU_CPP_BUILTINS() \
aarch64_cpu_cpp_builtins (pfile)
+/* Target CPU builtins for D. */
+#define TARGET_CPU_D_BUILTINS() \
+ do \
+ { \
+ builtin_define ("AArch64"); \
+ builtin_define ("D_HardFloat"); \
+ } while (0)
+
#define REGISTER_TARGET_PRAGMAS() aarch64_register_pragmas ()
@@ -72,6 +72,23 @@ along with GCC; see the file COPYING3. If not see
SUBTARGET_LANGUAGE_CPP_BUILTINS(); \
} while (0)
+/* Target CPU builtins for D. */
+#define TARGET_CPU_D_BUILTINS() \
+ do \
+ { \
+ builtin_define ("Alpha"); \
+ if (TARGET_SOFT_FP) \
+ { \
+ builtin_define ("D_SoftFloat"); \
+ builtin_define ("Alpha_SoftFloat"); \
+ } \
+ else \
+ { \
+ builtin_define ("D_HardFloat"); \
+ builtin_define ("Alpha_HardFloat"); \
+ } \
+} while (0)
+
#ifndef SUBTARGET_LANGUAGE_CPP_BUILTINS
#define SUBTARGET_LANGUAGE_CPP_BUILTINS() \
do \
@@ -33,6 +33,16 @@ along with GCC; see the file COPYING3. If not see
builtin_define ("_GNU_SOURCE"); \
} while (0)
+#undef TARGET_OS_D_BUILTINS
+#define TARGET_OS_D_BUILTINS() \
+ do { \
+ if (OPTION_GLIBC) \
+ builtin_define ("GNU_GLibc"); \
+ \
+ builtin_define ("linux"); \
+ builtin_define ("Posix"); \
+ } while (0)
+
#undef LIB_SPEC
#define LIB_SPEC \
"%{pthread:-lpthread} \
@@ -47,6 +47,31 @@ extern char arm_arch_name[];
/* Target CPU builtins. */
#define TARGET_CPU_CPP_BUILTINS() arm_cpu_cpp_builtins (pfile)
+/* Target CPU builtins for D. */
+#define TARGET_CPU_D_BUILTINS() \
+ do \
+ { \
+ builtin_define ("ARM"); \
+ \
+ if (TARGET_THUMB || TARGET_THUMB2) \
+ builtin_define ("ARM_Thumb"); \
+ \
+ if (TARGET_HARD_FLOAT_ABI) \
+ builtin_define ("ARM_HardFloat"); \
+ else \
+ { \
+ if(TARGET_SOFT_FLOAT) \
+ builtin_define ("ARM_SoftFloat"); \
+ else if(TARGET_HARD_FLOAT) \
+ builtin_define ("ARM_SoftFP"); \
+ } \
+ \
+ if(TARGET_SOFT_FLOAT) \
+ builtin_define ("D_SoftFloat"); \
+ else if(TARGET_HARD_FLOAT) \
+ builtin_define ("D_HardFloat"); \
+ } while (0)
+
#include "config/arm/arm-opts.h"
/* The processor for which instructions should be scheduled. */
@@ -30,6 +30,15 @@
} \
while (false)
+#undef TARGET_OS_D_BUILTINS
+#define TARGET_OS_D_BUILTINS() \
+ do \
+ { \
+ TARGET_GENERIC_LINUX_OS_D_BUILTINS(); \
+ ANDROID_TARGET_OS_D_BUILTINS(); \
+ } \
+ while (false)
+
/* We default to a soft-float ABI so that binaries can run on all
target hardware. If you override this to use the hard-float ABI then
change the setting of GLIBC_DYNAMIC_LINKER_DEFAULT as well. */
@@ -968,4 +968,10 @@ extern void darwin_driver_init (unsigned int *,struct cl_decoded_option **);
#define DEF_LD64 LD64_VERSION
#endif
+#define TARGET_OS_D_BUILTINS() \
+ do { \
+ builtin_define ("OSX"); \
+ builtin_define ("Posix"); \
+ } while (0)
+
#endif /* CONFIG_DARWIN_H */
@@ -32,6 +32,13 @@ along with GCC; see the file COPYING3. If not see
#undef TARGET_OS_CPP_BUILTINS
#define TARGET_OS_CPP_BUILTINS() FBSD_TARGET_OS_CPP_BUILTINS()
+#undef TARGET_OS_D_BUILTINS
+#define TARGET_OS_D_BUILTINS() \
+ do { \
+ builtin_define ("FreeBSD"); \
+ builtin_define ("Posix"); \
+ } while (0)
+
#undef CPP_SPEC
#define CPP_SPEC FBSD_CPP_SPEC
@@ -31,3 +31,11 @@ along with GCC. If not, see <http://www.gnu.org/licenses/>.
builtin_assert ("system=unix"); \
builtin_assert ("system=posix"); \
} while (0)
+
+#undef TARGET_OS_D_BUILTINS
+#define TARGET_OS_D_BUILTINS() \
+ do { \
+ \
+ builtin_define ("Hurd"); \
+ builtin_define ("Posix"); \
+ } while (0)
@@ -29,6 +29,13 @@ along with GCC; see the file COPYING3. If not see
} \
while (0)
+#define TARGET_OS_D_BUILTINS() \
+ do { \
+ builtin_define ("Windows"); \
+ builtin_define ("Cygwin"); \
+ builtin_define ("Posix"); \
+ } while (0)
+
#undef CPP_SPEC
#define CPP_SPEC "%(cpp_cpu) %{posix:-D_POSIX_SOURCE} \
%{!ansi:-Dunix} \
@@ -669,6 +669,24 @@ extern const char *host_detect_local_cpu (int argc, const char **argv);
/* Target CPU builtins. */
#define TARGET_CPU_CPP_BUILTINS() ix86_target_macros ()
+/* Target CPU builtins for D. */
+#define TARGET_CPU_D_BUILTINS() \
+ do { \
+ if (TARGET_64BIT) \
+ { \
+ builtin_define("X86_64"); \
+ if (TARGET_X32) \
+ builtin_define("D_X32"); \
+ } \
+ else \
+ builtin_define("X86"); \
+ \
+ if (TARGET_80387) \
+ builtin_define("D_HardFloat"); \
+ else \
+ builtin_define("D_SoftFloat"); \
+ } while (0)
+
/* Target Pragmas. */
#define REGISTER_TARGET_PRAGMAS() ix86_register_pragmas ()
@@ -27,6 +27,15 @@ along with GCC; see the file COPYING3. If not see
} \
while (0)
+#undef TARGET_OS_D_BUILTINS
+#define TARGET_OS_D_BUILTINS() \
+ do \
+ { \
+ TARGET_GENERIC_LINUX_OS_D_BUILTINS(); \
+ ANDROID_TARGET_OS_D_BUILTINS(); \
+ } \
+ while (0)
+
#undef CC1_SPEC
#define CC1_SPEC \
LINUX_OR_ANDROID_CC (GNU_USER_TARGET_CC1_SPEC, \
@@ -89,3 +89,10 @@ along with GCC; see the file COPYING3. If not see
%{static:-Bstatic} %{!static:-Bdynamic} \
%{shared|mdll: " SUB_LINK_ENTRY " --enable-auto-image-base} \
%(shared_libgcc_undefs)"
+
+#undef TARGET_OS_D_BUILTINS
+#define TARGET_OS_D_BUILTINS() \
+ do { \
+ TARGET_GENERIC_MINGW_OS_D_BUILTINS(); \
+ builtin_define ("GNU_MinGW64"); \
+ } while (0)
@@ -53,6 +53,18 @@ along with GCC; see the file COPYING3. If not see
} \
while (0)
+#define TARGET_OS_D_BUILTINS() TARGET_GENERIC_MINGW_OS_D_BUILTINS()
+#define TARGET_GENERIC_MINGW_OS_D_BUILTINS() \
+ do { \
+ builtin_define ("Windows"); \
+ builtin_define ("MinGW"); \
+ \
+ if (TARGET_64BIT && ix86_abi == MS_ABI) \
+ builtin_define ("Win64"); \
+ else if (!TARGET_64BIT) \
+ builtin_define ("Win32"); \
+ } while (0)
+
#ifndef TARGET_USE_PTHREAD_BY_DEFAULT
#define SPEC_PTHREAD1 "pthread"
#define SPEC_PTHREAD2 "!no-pthread"
@@ -40,6 +40,13 @@ do { \
builtin_define("__BIG_ENDIAN__"); \
} while (0)
+/* Target CPU builtins for D. */
+#define TARGET_CPU_D_BUILTINS() \
+do { \
+ builtin_define ("IA64"); \
+ builtin_define ("D_HardFloat"); \
+} while (0)
+
#ifndef SUBTARGET_EXTRA_SPECS
#define SUBTARGET_EXTRA_SPECS
#endif
@@ -29,6 +29,14 @@ along with GCC; see the file COPYING3. If not see
} \
while (0)
+#undef TARGET_OS_D_BUILTINS
+#define TARGET_OS_D_BUILTINS() \
+ do { \
+ builtin_define ("FreeBSD"); \
+ builtin_define ("Posix"); \
+ builtin_define ("GNU_GLibc"); \
+ } while (0)
+
#define GNU_USER_DYNAMIC_LINKER GLIBC_DYNAMIC_LINKER
#define GNU_USER_DYNAMIC_LINKER32 GLIBC_DYNAMIC_LINKER32
#define GNU_USER_DYNAMIC_LINKER64 GLIBC_DYNAMIC_LINKER64
@@ -30,5 +30,15 @@ along with GCC; see the file COPYING3. If not see
} \
while (0)
+#define TARGET_OS_D_BUILTINS() \
+ do \
+ { \
+ builtin_define ("Solaris"); \
+ builtin_define ("Posix"); \
+ builtin_define ("GNU_OpenSolaris"); \
+ builtin_define ("GNU_GLibc"); \
+ } \
+ while (0)
+
#undef GNU_USER_DYNAMIC_LINKER
#define GNU_USER_DYNAMIC_LINKER "/lib/ld.so.1"
@@ -25,6 +25,12 @@
builtin_define ("__ANDROID__"); \
} while (0)
+#define ANDROID_TARGET_OS_D_BUILTINS() \
+ do { \
+ if (TARGET_ANDROID) \
+ builtin_define ("Android"); \
+ } while (0)
+
#if ANDROID_DEFAULT
# define NOANDROID "mno-android"
#else
@@ -53,6 +53,28 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
builtin_assert ("system=posix"); \
} while (0)
+#define TARGET_OS_D_BUILTINS() TARGET_GENERIC_LINUX_OS_D_BUILTINS()
+#define TARGET_GENERIC_LINUX_OS_D_BUILTINS() \
+ do { \
+ if (OPTION_GLIBC) \
+ { \
+ builtin_define ("GNU_GLibc"); \
+ builtin_define ("CRuntime_Glibc"); \
+ } \
+ else if (OPTION_UCLIBC) \
+ { \
+ builtin_define ("GNU_UCLibc"); \
+ } \
+ else if (OPTION_BIONIC) \
+ { \
+ builtin_define ("GNU_Bionic"); \
+ builtin_define ("CRuntime_Bionic"); \
+ } \
+ \
+ builtin_define ("linux"); \
+ builtin_define ("Posix"); \
+ } while (0)
+
/* Determine which dynamic linker to use depending on whether GLIBC or
uClibc or Bionic or musl is the default C library and whether
-muclibc or -mglibc or -mbionic or -mmusl has been passed to change
@@ -27,6 +27,15 @@ along with GCC; see the file COPYING3. If not see
ANDROID_TARGET_OS_CPP_BUILTINS(); \
} while (0)
+#undef TARGET_OS_D_BUILTINS
+#define TARGET_OS_D_BUILTINS() \
+ do \
+ { \
+ TARGET_GENERIC_LINUX_OS_D_BUILTINS(); \
+ ANDROID_TARGET_OS_D_BUILTINS(); \
+ } \
+ while (0)
+
#undef LINK_SPEC
#define LINK_SPEC \
LINUX_OR_ANDROID_LD (GNU_USER_TARGET_LINK_SPEC, \
@@ -644,6 +644,54 @@ struct mips_cpu_info {
} \
while (0)
+/* Target CPU builtins for D. */
+#define TARGET_CPU_D_BUILTINS() \
+ do \
+ { \
+ if (TARGET_64BIT) \
+ builtin_define("MIPS64"); \
+ else \
+ builtin_define("MIPS32"); \
+ \
+ switch (mips_abi) \
+ { \
+ case ABI_32: \
+ builtin_define("MIPS_O32"); \
+ break; \
+ \
+ case ABI_O64: \
+ builtin_define("MIPS_O64"); \
+ break; \
+ \
+ case ABI_N32: \
+ builtin_define("MIPS_N32"); \
+ break; \
+ \
+ case ABI_64: \
+ builtin_define("MIPS_N64"); \
+ break; \
+ \
+ case ABI_EABI: \
+ builtin_define("MIPS_EABI"); \
+ break; \
+ \
+ default: \
+ gcc_unreachable(); \
+ } \
+ \
+ if (TARGET_HARD_FLOAT_ABI) \
+ { \
+ builtin_define("MIPS_HardFloat"); \
+ builtin_define("D_HardFloat"); \
+ } \
+ else if (TARGET_SOFT_FLOAT_ABI) \
+ { \
+ builtin_define("MIPS_SoftFloat"); \
+ builtin_define("D_SoftFloat"); \
+ } \
+ } \
+ while (0)
+
/* Default target_flags if no switches are specified */
#ifndef TARGET_DEFAULT
@@ -29,6 +29,14 @@ along with GCC; see the file COPYING3. If not see
} \
while (0)
+#define TARGET_OS_D_BUILTINS() \
+ do \
+ { \
+ builtin_define ("NetBSD"); \
+ builtin_define ("Posix"); \
+ } \
+ while (0)
+
/* CPP_SPEC parts common to all NetBSD targets. */
#define NETBSD_CPP_SPEC \
"%{posix:-D_POSIX_SOURCE} \
@@ -84,6 +84,14 @@ along with GCC; see the file COPYING3. If not see
} \
while (0)
+#define TARGET_OS_D_BUILTINS() \
+ do \
+ { \
+ builtin_define ("OpenBSD"); \
+ builtin_define ("Posix"); \
+ } \
+ while (0)
+
/* TARGET_OS_CPP_BUILTINS() common to all OpenBSD ELF targets. */
#define OPENBSD_OS_CPP_BUILTINS_ELF() \
do \
@@ -179,6 +179,20 @@ do { \
builtin_define("_PA_RISC1_0"); \
} while (0)
+/* Target CPU builtins for D. */
+#define TARGET_CPU_D_BUILTINS() \
+do { \
+ if(TARGET_64BIT) \
+ builtin_define("HPPA64"); \
+ else \
+ builtin_define("HPPA"); \
+ \
+ if(TARGET_SOFT_FLOAT) \
+ builtin_define ("D_SoftFloat"); \
+ else \
+ builtin_define ("D_HardFloat"); \
+} while (0)
+
/* An old set of OS defines for various BSD-like systems. */
#define TARGET_OS_CPP_BUILTINS() \
do \
@@ -164,6 +164,13 @@
} \
while (0)
+#define TARGET_OS_D_BUILTINS() \
+ do { \
+ \
+ builtin_define ("AIX"); \
+ builtin_define ("Posix"); \
+ } while (0)
+
/* Define appropriate architecture macros for preprocessor depending on
target switches. */
@@ -57,6 +57,17 @@
} \
while (0)
+#undef TARGET_OS_D_BUILTINS
+#define TARGET_OS_D_BUILTINS() \
+ do \
+ { \
+ builtin_define ("linux"); \
+ builtin_define ("Posix"); \
+ if (OPTION_GLIBC) \
+ builtin_define ("GNU_GLibc"); \
+ } \
+ while (0)
+
#undef CPP_OS_DEFAULT_SPEC
#define CPP_OS_DEFAULT_SPEC "%(cpp_os_linux)"
@@ -391,6 +391,17 @@ extern int dot_symbols;
} \
while (0)
+#undef TARGET_OS_D_BUILTINS
+#define TARGET_OS_D_BUILTINS() \
+ do \
+ { \
+ builtin_define ("linux"); \
+ builtin_define ("Posix"); \
+ if (OPTION_GLIBC) \
+ builtin_define ("GNU_GLibc"); \
+ } \
+ while (0)
+
#undef CPP_OS_DEFAULT_SPEC
#define CPP_OS_DEFAULT_SPEC "%(cpp_os_linux) %(include_extra)"
@@ -822,6 +822,28 @@ extern unsigned char rs6000_recip_bits[];
#define TARGET_CPU_CPP_BUILTINS() \
rs6000_cpu_cpp_builtins (pfile)
+/* Target CPU builtins for D. */
+#define TARGET_CPU_D_BUILTINS() \
+ do \
+ { \
+ if (TARGET_64BIT) \
+ builtin_define ("PPC64"); \
+ else \
+ builtin_define ("PPC"); \
+ \
+ if (TARGET_HARD_FLOAT) \
+ { \
+ builtin_define ("PPC_HardFloat"); \
+ builtin_define ("D_HardFloat"); \
+ } \
+ else if (TARGET_SOFT_FLOAT) \
+ { \
+ builtin_define ("PPC_SoftFloat"); \
+ builtin_define ("D_SoftFloat"); \
+ } \
+ } \
+ while (0)
+
/* This is used by rs6000_cpu_cpp_builtins to indicate the byte order
we're compiling for. Some configurations may need to override it. */
#define RS6000_CPU_CPP_ENDIAN_BUILTINS() \
@@ -194,6 +194,22 @@ enum processor_flags
/* Target CPU builtins. */
#define TARGET_CPU_CPP_BUILTINS() s390_cpu_cpp_builtins (pfile)
+/* Target CPU builtins for D. */
+#define TARGET_CPU_D_BUILTINS() \
+ do \
+ { \
+ if (TARGET_64BIT) \
+ builtin_define ("S390X"); \
+ else \
+ builtin_define ("S390"); \
+ \
+ if(TARGET_SOFT_FLOAT) \
+ builtin_define ("D_SoftFloat"); \
+ else if(TARGET_HARD_FLOAT) \
+ builtin_define ("D_HardFloat"); \
+ } \
+ while (0)
+
#ifdef DEFAULT_TARGET_64BIT
#define TARGET_DEFAULT (MASK_64BIT | MASK_ZARCH | MASK_HARD_DFP \
| MASK_OPT_HTM | MASK_OPT_VX)
@@ -31,6 +31,19 @@ extern int code_for_indirect_jump_scratch;
#define TARGET_CPU_CPP_BUILTINS() sh_cpu_cpp_builtins (pfile)
+/* Target CPU builtins for D. */
+#define TARGET_CPU_D_BUILTINS() \
+ do \
+ { \
+ builtin_define ("SH"); \
+ \
+ if (TARGET_FPU_ANY) \
+ builtin_define ("D_HardFloat"); \
+ else \
+ builtin_define ("D_SoftFloat"); \
+ } \
+ while (0)
+
/* Value should be nonzero if functions must have frame pointers.
Zero means the frame pointer need not be set up (and parms may be accessed
via the stack pointer) in functions that seem suitable. */
@@ -27,6 +27,31 @@ along with GCC; see the file COPYING3. If not see
#define TARGET_CPU_CPP_BUILTINS() sparc_target_macros ()
+/* Target CPU builtins for D. */
+#define TARGET_CPU_D_BUILTINS() \
+do \
+ { \
+ if (TARGET_64BIT) \
+ builtin_define ("SPARC64"); \
+ else \
+ builtin_define ("SPARC"); \
+ \
+ if(TARGET_V8PLUS) \
+ builtin_define ("SPARC_V8Plus"); \
+ \
+ if(TARGET_FPU) \
+ { \
+ builtin_define ("D_HardFloat"); \
+ builtin_define ("SPARC_HardFloat"); \
+ } \
+ else \
+ { \
+ builtin_define ("D_SoftFloat"); \
+ builtin_define ("SPARC_SoftFloat"); \
+ } \
+ } \
+ while (0)
+
/* Specify this in a cover file to provide bi-architecture (32/64) support. */
/* #define SPARC_BI_ARCH */