1 /* d-port.cc -- D frontend interface to the gcc back-end.
2 Copyright (C) 2013-2023 Free Software Foundation, Inc.
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)
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.
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/>. */
20 #include "coretypes.h"
22 #include "dmd/root/port.h"
23 #include "dmd/target.h"
28 /* Implements the Port interface defined by the frontend.
29 A mini library for doing compiler/system specific things. */
31 /* Compare the first N bytes of S1 and S2 without regard to the case. */
34 Port::memicmp (const char *s1
, const char *s2
, d_size_t n
)
38 for (d_size_t i
= 0; i
< n
; i
++)
46 result
= TOUPPER (c1
) - TOUPPER (c2
);
55 /* Convert all characters in S to uppercase. */
58 Port::strupr (char *s
)
71 /* Return true if the real_t value from string BUFFER overflows
72 as a result of rounding down to float mode. */
75 Port::isFloat32LiteralOutOfRange (const char *buffer
)
79 real_from_string3 (&r
.rv (), buffer
, TYPE_MODE (float_type_node
));
81 return r
== target
.RealProperties
.infinity
;
84 /* Return true if the real_t value from string BUFFER overflows
85 as a result of rounding down to double mode. */
88 Port::isFloat64LiteralOutOfRange (const char *buffer
)
92 real_from_string3 (&r
.rv (), buffer
, TYPE_MODE (double_type_node
));
94 return r
== target
.RealProperties
.infinity
;
97 /* Fetch a little-endian 16-bit value from BUFFER. */
100 Port::readwordLE (const void *buffer
)
102 const unsigned char *p
= (const unsigned char *) buffer
;
104 return ((unsigned) p
[1] << 8) | (unsigned) p
[0];
107 /* Fetch a big-endian 16-bit value from BUFFER. */
110 Port::readwordBE (const void *buffer
)
112 const unsigned char *p
= (const unsigned char *) buffer
;
114 return ((unsigned) p
[0] << 8) | (unsigned) p
[1];
117 /* Fetch a little-endian 32-bit value from BUFFER. */
120 Port::readlongLE (const void *buffer
)
122 const unsigned char *p
= (const unsigned char *) buffer
;
124 return (((unsigned) p
[3] << 24)
125 | ((unsigned) p
[2] << 16)
126 | ((unsigned) p
[1] << 8)
130 /* Fetch a big-endian 32-bit value from BUFFER. */
133 Port::readlongBE (const void *buffer
)
135 const unsigned char *p
= (const unsigned char *) buffer
;
137 return (((unsigned) p
[0] << 24)
138 | ((unsigned) p
[1] << 16)
139 | ((unsigned) p
[2] << 8)
143 /* Write an SZ-byte sized VALUE to BUFFER, ignoring endian-ness. */
146 Port::valcpy (void *buffer
, uint64_t value
, d_size_t sz
)
148 gcc_assert (((d_size_t
) buffer
) % sz
== 0);
153 *(uint8_t *) buffer
= (uint8_t) value
;
157 *(uint16_t *) buffer
= (uint16_t) value
;
161 *(uint32_t *) buffer
= (uint32_t) value
;
165 *(uint64_t *) buffer
= (uint64_t) value
;