1 /* Subroutines for the D front end on the x86 architecture.
2    Copyright (C) 2017-2021 Free Software Foundation, Inc.
3 
4 GCC is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 3, or (at your option)
7 any later version.
8 
9 GCC is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 GNU General Public License for more details.
13 
14 You should have received a copy of the GNU General Public License
15 along with GCC; see the file COPYING3.  If not see
16 <http://www.gnu.org/licenses/>.  */
17 
18 #define IN_TARGET_CODE 1
19 
20 #include "config.h"
21 #include "system.h"
22 #include "coretypes.h"
23 #include "tm.h"
24 #include "d/d-target.h"
25 #include "d/d-target-def.h"
26 
27 /* Implement TARGET_D_CPU_VERSIONS for x86 targets.  */
28 
29 void
ix86_d_target_versions(void)30 ix86_d_target_versions (void)
31 {
32   if (TARGET_64BIT)
33     {
34       d_add_builtin_version ("X86_64");
35 
36       if (TARGET_X32)
37 	d_add_builtin_version ("D_X32");
38     }
39   else
40     d_add_builtin_version ("X86");
41 
42   if (TARGET_80387)
43     d_add_builtin_version ("D_HardFloat");
44   else
45     d_add_builtin_version ("D_SoftFloat");
46 }
47 
48 /* Handle a call to `__traits(getTargetInfo, "floatAbi")'.  */
49 
50 static tree
ix86_d_handle_target_float_abi(void)51 ix86_d_handle_target_float_abi (void)
52 {
53   const char *abi;
54 
55   if (! (TARGET_80387 || TARGET_FLOAT_RETURNS_IN_80387))
56     abi = "soft";
57   else
58     abi = "hard";
59 
60   return build_string_literal (strlen (abi) + 1, abi);
61 }
62 
63 /* Handle a call to `__traits(getTargetInfo, "objectFormat")'.  */
64 
65 static tree
ix86_d_handle_target_object_format(void)66 ix86_d_handle_target_object_format (void)
67 {
68   const char *objfmt = NULL;
69 
70   if (TARGET_MACHO)
71     objfmt = "macho";
72   else if (TARGET_COFF || TARGET_PECOFF)
73     objfmt = "coff";
74 
75   if (objfmt == NULL)
76     return NULL_TREE;
77 
78   return build_string_literal (strlen (objfmt) + 1, objfmt);
79 }
80 
81 /* Implement TARGET_D_REGISTER_CPU_TARGET_INFO.  */
82 
83 void
ix86_d_register_target_info(void)84 ix86_d_register_target_info (void)
85 {
86   const struct d_target_info_spec handlers[] = {
87     { "floatAbi", ix86_d_handle_target_float_abi },
88     { "objectFormat", ix86_d_handle_target_object_format },
89     { NULL, NULL },
90   };
91 
92   d_add_target_info_handlers (handlers);
93 }
94 
95 /* Implement TARGET_D_HAS_STDCALL_CONVENTION for x86 targets.  */
96 
97 bool
ix86_d_has_stdcall_convention(unsigned int * link_system,unsigned int * link_windows)98 ix86_d_has_stdcall_convention (unsigned int *link_system,
99 			       unsigned int *link_windows)
100 {
101   if (ix86_abi == MS_ABI)
102     {
103       *link_system = 1;
104       *link_windows = (!TARGET_64BIT) ? 1 : 0;
105     }
106   else
107     {
108       *link_system = 0;
109       *link_windows = 0;
110     }
111 
112   return true;
113 }
114