Debian Codegraph @

gcc/config/i386/i386-d.cc

raw
1 /* Subroutines for the D front end on the x86 architecture.
2 Copyright (C) 2017-2025 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 "tm_d.h"
25 #include "d/d-target.h"
26 #include "d/d-target-def.h"
27
28 /* Implement TARGET_D_CPU_VERSIONS for x86 targets. */
29
30 void
31 ix86_d_target_versions (void)
32 {
33 if (TARGET_64BIT)
34 {
35 d_add_builtin_version ("X86_64");
36
37 if (TARGET_X32)
38 d_add_builtin_version ("D_X32");
39 }
40 else
41 d_add_builtin_version ("X86");
42
43 if (TARGET_80387)
44 d_add_builtin_version ("D_HardFloat");
45 else
46 d_add_builtin_version ("D_SoftFloat");
47
48 if (flag_cf_protection != CF_NONE)
49 d_add_builtin_version ("GNU_CET");
50 }
51
52 /* Handle a call to `__traits(getTargetInfo, "floatAbi")'. */
53
54 static tree
55 ix86_d_handle_target_float_abi (void)
56 {
57 const char *abi;
58
59 if (! (TARGET_80387 || TARGET_FLOAT_RETURNS_IN_80387))
60 abi = "soft";
61 else
62 abi = "hard";
63
64 return build_string_literal (strlen (abi) + 1, abi);
65 }
66
67 /* Handle a call to `__traits(getTargetInfo, "objectFormat")'. */
68
69 static tree
70 ix86_d_handle_target_object_format (void)
71 {
72 const char *objfmt = NULL;
73
74 if (TARGET_MACHO)
75 objfmt = "macho";
76 else if (TARGET_COFF || TARGET_PECOFF)
77 objfmt = "coff";
78
79 if (objfmt == NULL)
80 return NULL_TREE;
81
82 return build_string_literal (strlen (objfmt) + 1, objfmt);
83 }
84
85 /* Handle a call to `__traits(getTargetInfo, "CET")'. */
86
87 static tree
88 ix86_d_handle_target_cf_protection (void)
89 {
90 return build_int_cst_type (uint32_type_node, flag_cf_protection & ~CF_SET);
91 }
92
93 /* Implement TARGET_D_REGISTER_CPU_TARGET_INFO. */
94
95 void
96 ix86_d_register_target_info (void)
97 {
98 const struct d_target_info_spec handlers[] = {
99 { "floatAbi", ix86_d_handle_target_float_abi },
100 { "objectFormat", ix86_d_handle_target_object_format },
101 { "CET", ix86_d_handle_target_cf_protection },
102 { NULL, NULL },
103 };
104
105 d_add_target_info_handlers (handlers);
106 }
107
108 /* Implement TARGET_D_HAS_STDCALL_CONVENTION for x86 targets. */
109
110 bool
111 ix86_d_has_stdcall_convention (unsigned int *link_system,
112 unsigned int *link_windows)
113 {
114 if (ix86_abi == MS_ABI)
115 {
116 *link_system = 1;
117 *link_windows = (!TARGET_64BIT) ? 1 : 0;
118 }
119 else
120 {
121 *link_system = 0;
122 *link_windows = 0;
123 }
124
125 return true;
126 }