Skip to content

Commit 78d8ab2

Browse files
authored
[libc] Initial support for 'locale.h' in the LLVM libc (#102689)
Summary: This patch adds the macros and entrypoints associated with the `locale.h` entrypoints. These are mostly stubs, as we (for now and the forseeable future) only expect to support the C and maybe C.UTF-8 locales in the LLVM libc.
1 parent 2f4232d commit 78d8ab2

35 files changed

+788
-0
lines changed

libc/config/gpu/entrypoints.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,15 @@ set(TARGET_LIBC_ENTRYPOINTS
233233
# wchar.h entrypoints
234234
libc.src.wchar.wctob
235235

236+
# locale.h entrypoints
237+
libc.src.locale.localeconv
238+
libc.src.locale.duplocale
239+
libc.src.locale.freelocale
240+
libc.src.locale.localeconv
241+
libc.src.locale.newlocale
242+
libc.src.locale.setlocale
243+
libc.src.locale.uselocale
244+
236245
# gpu/rpc.h entrypoints
237246
libc.src.gpu.rpc_host_call
238247
)

libc/config/gpu/headers.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ set(TARGET_PUBLIC_HEADERS
1616
libc.include.wchar
1717
libc.include.uchar
1818
libc.include.features
19+
libc.include.locale
1920

2021
# Header for RPC extensions
2122
libc.include.gpu_rpc

libc/config/linux/x86_64/entrypoints.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -982,6 +982,15 @@ if(LLVM_LIBC_FULL_BUILD)
982982
libc.src.time.nanosleep
983983
libc.src.time.time
984984

985+
# locale.h entrypoints
986+
libc.src.locale.localeconv
987+
libc.src.locale.duplocale
988+
libc.src.locale.freelocale
989+
libc.src.locale.localeconv
990+
libc.src.locale.newlocale
991+
libc.src.locale.setlocale
992+
libc.src.locale.uselocale
993+
985994
# unistd.h entrypoints
986995
libc.src.unistd.__llvm_libc_syscall
987996
libc.src.unistd._exit

libc/config/linux/x86_64/headers.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ set(TARGET_PUBLIC_HEADERS
3333
libc.include.unistd
3434
libc.include.wchar
3535
libc.include.uchar
36+
libc.include.locale
3637

3738
libc.include.arpa_inet
3839

libc/hdr/types/CMakeLists.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,3 +162,12 @@ add_proxy_header_library(
162162
libc.include.llvm-libc-types.cookie_io_functions_t
163163
libc.include.stdio
164164
)
165+
166+
add_proxy_header_library(
167+
locale_t
168+
HDRS
169+
locale_t.h
170+
FULL_BUILD_DEPENDS
171+
libc.include.llvm-libc-types.locale_t
172+
libc.include.locale
173+
)

libc/hdr/types/locale_t.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//===-- Definition of macros from locale_t.h ------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef LLVM_LIBC_HDR_LOCALE_T_H
10+
#define LLVM_LIBC_HDR_LOCALE_T_H
11+
12+
#ifdef LIBC_FULL_BUILD
13+
14+
#include "include/llvm-libc-types/locale_t.h"
15+
16+
#else // overlay mode
17+
18+
#error "type not available in overlay mode"
19+
20+
#endif // LLVM_LIBC_FULL_BUILD
21+
22+
#endif // LLVM_LIBC_HDR_LOCALE_T_H

libc/include/CMakeLists.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -719,6 +719,18 @@ add_header_macro(
719719
.llvm-libc-types.wchar_t
720720
)
721721

722+
add_header_macro(
723+
locale
724+
../libc/newhdrgen/yaml/locale.yaml
725+
locale.h.def
726+
locale.h
727+
DEPENDS
728+
.llvm_libc_common_h
729+
.llvm-libc-macros.locale_macros
730+
.llvm-libc-types.locale_t
731+
.llvm-libc-types.struct_lconv
732+
)
733+
722734
if(LIBC_TARGET_OS_IS_GPU)
723735
file(MAKE_DIRECTORY ${LIBC_INCLUDE_DIR}/gpu)
724736

libc/include/llvm-libc-macros/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,3 +295,9 @@ add_macro_header(
295295
HDR
296296
elf-macros.h
297297
)
298+
299+
add_macro_header(
300+
locale_macros
301+
HDR
302+
locale-macros.h
303+
)
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
//===-- Definition of macros from locale.h --------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef LLVM_LIBC_MACROS_LOCALE_MACROS_H
10+
#define LLVM_LIBC_MACROS_LOCALE_MACROS_H
11+
12+
#include "../llvm-libc-types/locale_t.h"
13+
14+
#define LC_CTYPE 0
15+
#define LC_NUMERIC 1
16+
#define LC_TIME 2
17+
#define LC_COLLATE 3
18+
#define LC_MONETARY 4
19+
#define LC_MESSAGES 5
20+
#define LC_ALL 6
21+
22+
#define LC_GLOBAL_LOCALE ((locale_t)(-1))
23+
24+
#define LC_CTYPE_MASK (1 << LC_CTYPE)
25+
#define LC_NUMERIC_MASK (1 << LC_NUMERIC)
26+
#define LC_TIME_MASK (1 << LC_TIME)
27+
#define LC_COLLATE_MASK (1 << LC_COLLATE)
28+
#define LC_MONETARY_MASK (1 << LC_MONETARY)
29+
#define LC_MESSAGES_MASK (1 << LC_MESSAGES)
30+
#define LC_ALL_MASK 0x7fffffff
31+
32+
#endif // LLVM_LIBC_MACROS_LOCALE_MACROS_H

libc/include/llvm-libc-types/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,3 +142,5 @@ DEPENDS
142142
.fsblkcnt_t
143143
.fsfilcnt_t
144144
)
145+
add_header(locale_t HDR locale_t.h)
146+
add_header(struct_lconv HDR struct_lconv.h)

0 commit comments

Comments
 (0)