From 3e9557c0c3f1c704c51586891fca9a5d3dd577ab Mon Sep 17 00:00:00 2001 From: Izaak Schroeder Date: Tue, 2 Jul 2024 14:01:47 -0700 Subject: [PATCH] fixup! more locale funcs --- libc/config/linux/aarch64/entrypoints.txt | 8 ++++ libc/config/linux/x86_64/entrypoints.txt | 6 +++ libc/spec/stdc.td | 20 +++++++++ libc/src/ctype/CMakeLists.txt | 49 +++++++++++++++++++++++ libc/src/ctype/islower_l.cpp | 22 ++++++++++ libc/src/ctype/islower_l.h | 20 +++++++++ libc/src/ctype/isupper_l.cpp | 22 ++++++++++ libc/src/ctype/isupper_l.h | 20 +++++++++ libc/src/ctype/tolower_l.cpp | 20 +++++++++ libc/src/ctype/tolower_l.h | 20 +++++++++ libc/src/ctype/toupper_l.cpp | 23 +++++++++++ libc/src/ctype/toupper_l.h | 20 +++++++++ libc/src/string/CMakeLists.txt | 22 ++++++++++ libc/src/string/strcoll_l.cpp | 21 ++++++++++ libc/src/string/strcoll_l.h | 20 +++++++++ libc/src/string/strxfrm_l.cpp | 23 +++++++++++ libc/src/string/strxfrm_l.h | 21 ++++++++++ 17 files changed, 357 insertions(+) create mode 100644 libc/src/ctype/islower_l.cpp create mode 100644 libc/src/ctype/islower_l.h create mode 100644 libc/src/ctype/isupper_l.cpp create mode 100644 libc/src/ctype/isupper_l.h create mode 100644 libc/src/ctype/tolower_l.cpp create mode 100644 libc/src/ctype/tolower_l.h create mode 100644 libc/src/ctype/toupper_l.cpp create mode 100644 libc/src/ctype/toupper_l.h create mode 100644 libc/src/string/strcoll_l.cpp create mode 100644 libc/src/string/strcoll_l.h create mode 100644 libc/src/string/strxfrm_l.cpp create mode 100644 libc/src/string/strxfrm_l.h diff --git a/libc/config/linux/aarch64/entrypoints.txt b/libc/config/linux/aarch64/entrypoints.txt index ef490412a2d64b..ebef5927fdfebc 100644 --- a/libc/config/linux/aarch64/entrypoints.txt +++ b/libc/config/linux/aarch64/entrypoints.txt @@ -310,6 +310,8 @@ set(TARGET_LIBC_ENTRYPOINTS libc.src.unistd.write # XXX + libc.src.string.strxfrm + libc.src.string.strcoll libc.src.stdio.ungetc libc.src.stdio.getc libc.src.assert.__assert_fail @@ -344,6 +346,12 @@ set(TARGET_LIBC_ENTRYPOINTS libc.src.stdlib.strtoll_l libc.src.ctype.isdigit_l libc.src.ctype.isxdigit_l + libc.src.ctype.islower_l + libc.src.ctype.isupper_l + libc.src.ctype.tolower_l + libc.src.ctype.toupper_l + libc.src.string.strxfrm_l + libc.src.string.strcoll_l libc.src.stdio.vsscanf libc.src.stdio.vasprintf diff --git a/libc/config/linux/x86_64/entrypoints.txt b/libc/config/linux/x86_64/entrypoints.txt index a9741fad2c31ab..98527abb3fd67c 100644 --- a/libc/config/linux/x86_64/entrypoints.txt +++ b/libc/config/linux/x86_64/entrypoints.txt @@ -354,6 +354,12 @@ set(TARGET_LIBC_ENTRYPOINTS libc.src.stdlib.strtoll_l libc.src.ctype.isdigit_l libc.src.ctype.isxdigit_l + libc.src.ctype.islower_l + libc.src.ctype.isupper_l + libc.src.ctype.tolower_l + libc.src.ctype.toupper_l + libc.src.string.strxfrm_l + libc.src.string.strcoll_l libc.src.stdio.vsscanf libc.src.stdio.vasprintf ) diff --git a/libc/spec/stdc.td b/libc/spec/stdc.td index 9bde311fdc71e0..fa3f2238097e61 100644 --- a/libc/spec/stdc.td +++ b/libc/spec/stdc.td @@ -118,6 +118,26 @@ def StdC : StandardSpec<"stdc"> { RetValSpec, [ArgSpec, ArgSpec] >, + FunctionSpec< + "tolower_l", + RetValSpec, + [ArgSpec, ArgSpec] + >, + FunctionSpec< + "toupper_l", + RetValSpec, + [ArgSpec, ArgSpec] + >, + FunctionSpec< + "islower_l", + RetValSpec, + [ArgSpec, ArgSpec] + >, + FunctionSpec< + "isupper_l", + RetValSpec, + [ArgSpec, ArgSpec] + >, ] >; diff --git a/libc/src/ctype/CMakeLists.txt b/libc/src/ctype/CMakeLists.txt index ebe1948dbbb089..19e5ef609e93cb 100644 --- a/libc/src/ctype/CMakeLists.txt +++ b/libc/src/ctype/CMakeLists.txt @@ -170,3 +170,52 @@ add_entrypoint_object( libc.include.llvm-libc-types.locale_t libc.src.__support.ctype_utils ) + + +add_entrypoint_object( + islower_l + SRCS + islower_l.cpp + HDRS + islower_l.h + DEPENDS + libc.src.ctype.islower + libc.include.llvm-libc-types.locale_t + libc.src.__support.ctype_utils +) + +add_entrypoint_object( + isupper_l + SRCS + isupper_l.cpp + HDRS + isupper_l.h + DEPENDS + libc.src.ctype.isupper + libc.include.llvm-libc-types.locale_t + libc.src.__support.ctype_utils +) + +add_entrypoint_object( + tolower_l + SRCS + tolower_l.cpp + HDRS + tolower_l.h + DEPENDS + libc.src.ctype.tolower + libc.include.llvm-libc-types.locale_t + libc.src.__support.ctype_utils +) + +add_entrypoint_object( + toupper_l + SRCS + toupper_l.cpp + HDRS + toupper_l.h + DEPENDS + libc.src.ctype.toupper + libc.include.llvm-libc-types.locale_t + libc.src.__support.ctype_utils +) diff --git a/libc/src/ctype/islower_l.cpp b/libc/src/ctype/islower_l.cpp new file mode 100644 index 00000000000000..45977dc637fbba --- /dev/null +++ b/libc/src/ctype/islower_l.cpp @@ -0,0 +1,22 @@ +//===-- Implementation of islower_l----------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "src/ctype/islower_l.h" +#include "src/ctype/islower.h" + +#include "src/__support/common.h" + +namespace LIBC_NAMESPACE { + +// TODO: Currently restricted to default locale. +// These should be extended using locale information. +LLVM_LIBC_FUNCTION(int, islower_l, (int c, locale_t)) { + return islower(c); +} + +} // namespace LIBC_NAMESPACE diff --git a/libc/src/ctype/islower_l.h b/libc/src/ctype/islower_l.h new file mode 100644 index 00000000000000..dee277ce9af97c --- /dev/null +++ b/libc/src/ctype/islower_l.h @@ -0,0 +1,20 @@ +//===-- Implementation header for islower_l -----------------------*-C++-*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIBC_SRC_CTYPE_ISLOWER_L_H +#define LLVM_LIBC_SRC_CTYPE_ISLOWER_L_H + +#include "include/llvm-libc-types/locale_t.h" + +namespace LIBC_NAMESPACE { + +int islower_l(int c, locale_t locale); + +} // namespace LIBC_NAMESPACE + +#endif // LLVM_LIBC_SRC_CTYPE_ISLOWER_L_H diff --git a/libc/src/ctype/isupper_l.cpp b/libc/src/ctype/isupper_l.cpp new file mode 100644 index 00000000000000..e3b1250b940af3 --- /dev/null +++ b/libc/src/ctype/isupper_l.cpp @@ -0,0 +1,22 @@ +//===-- Implementation of isupper_l----------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "src/ctype/isupper_l.h" +#include "src/ctype/isupper.h" + +#include "src/__support/common.h" + +namespace LIBC_NAMESPACE { + +// TODO: Currently restricted to default locale. +// These should be extended using locale information. +LLVM_LIBC_FUNCTION(int, isupper_l, (int c, locale_t)) { + return isupper(c); +} + +} // namespace LIBC_NAMESPACE diff --git a/libc/src/ctype/isupper_l.h b/libc/src/ctype/isupper_l.h new file mode 100644 index 00000000000000..fbd49c97cb7fae --- /dev/null +++ b/libc/src/ctype/isupper_l.h @@ -0,0 +1,20 @@ +//===-- Implementation header for isupper -------------------------*-C++-*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIBC_SRC_CTYPE_ISUPPER_L_H +#define LLVM_LIBC_SRC_CTYPE_ISUPPER_L_H + +#include "include/llvm-libc-types/locale_t.h" + +namespace LIBC_NAMESPACE { + +int isupper_l(int c, locale_t locale); + +} // namespace LIBC_NAMESPACE + +#endif // LLVM_LIBC_SRC_CTYPE_ISUPPER_L_H diff --git a/libc/src/ctype/tolower_l.cpp b/libc/src/ctype/tolower_l.cpp new file mode 100644 index 00000000000000..c89c6d70381386 --- /dev/null +++ b/libc/src/ctype/tolower_l.cpp @@ -0,0 +1,20 @@ +//===-- Implementation of tolower_l----------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "src/ctype/tolower_l.h" +#include "src/ctype/tolower.h" + +#include "src/__support/common.h" + +namespace LIBC_NAMESPACE { + +// TODO: Currently restricted to default locale. +// These should be extended using locale information. +LLVM_LIBC_FUNCTION(int, tolower_l, (int c, locale_t)) { return tolower(c); } + +} // namespace LIBC_NAMESPACE diff --git a/libc/src/ctype/tolower_l.h b/libc/src/ctype/tolower_l.h new file mode 100644 index 00000000000000..624526dbe8f301 --- /dev/null +++ b/libc/src/ctype/tolower_l.h @@ -0,0 +1,20 @@ +//===-- Implementation header for tolower_l -----------------------*-C++-*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIBC_SRC_CTYPE_TOLOWER_L_H +#define LLVM_LIBC_SRC_CTYPE_TOLOWER_L_H + +#include "include/llvm-libc-types/locale_t.h" + +namespace LIBC_NAMESPACE { + +int tolower_l(int c, locale_t locale); + +} // namespace LIBC_NAMESPACE + +#endif // LLVM_LIBC_SRC_CTYPE_TOLOWER_L_H diff --git a/libc/src/ctype/toupper_l.cpp b/libc/src/ctype/toupper_l.cpp new file mode 100644 index 00000000000000..5806f22d699e6f --- /dev/null +++ b/libc/src/ctype/toupper_l.cpp @@ -0,0 +1,23 @@ +//===-- Implementation of toupper_l----------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "src/ctype/toupper_l.h" +#include "src/ctype/toupper.h" +#include "src/__support/ctype_utils.h" + +#include "src/__support/common.h" + +namespace LIBC_NAMESPACE { + +// TODO: Currently restricted to default locale. +// These should be extended using locale information. +LLVM_LIBC_FUNCTION(int, toupper_l, (int c, locale_t)) { + return toupper(c); +} + +} // namespace LIBC_NAMESPACE diff --git a/libc/src/ctype/toupper_l.h b/libc/src/ctype/toupper_l.h new file mode 100644 index 00000000000000..22a6b5c968b63c --- /dev/null +++ b/libc/src/ctype/toupper_l.h @@ -0,0 +1,20 @@ +//===-- Implementation header for toupper_l -----------------------*-C++-*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIBC_SRC_CTYPE_TOUPPER_L_H +#define LLVM_LIBC_SRC_CTYPE_TOUPPER_L_H + +#include "include/llvm-libc-types/locale_t.h" + +namespace LIBC_NAMESPACE { + +int toupper_l(int c, locale_t locale); + +} // namespace LIBC_NAMESPACE + +#endif // LLVM_LIBC_SRC_CTYPE_TOUPPER_L_H diff --git a/libc/src/string/CMakeLists.txt b/libc/src/string/CMakeLists.txt index 56588ffafb86f0..794e9206aded43 100644 --- a/libc/src/string/CMakeLists.txt +++ b/libc/src/string/CMakeLists.txt @@ -452,6 +452,28 @@ add_entrypoint_object( .memory_utils.inline_memset ) +add_entrypoint_object( + strcoll_l + SRCS + strcoll_l.cpp + HDRS + strcoll_l.h + DEPENDS + .strcoll + libc.include.llvm-libc-types.locale_t +) + +add_entrypoint_object( + strxfrm_l + SRCS + strxfrm_l.cpp + HDRS + strxfrm_l.h + DEPENDS + .strxfrm + libc.include.llvm-libc-types.locale_t +) + # Helper to define a function with multiple implementations # - Computes flags to satisfy required/rejected features and arch, # - Declares an entry point, diff --git a/libc/src/string/strcoll_l.cpp b/libc/src/string/strcoll_l.cpp new file mode 100644 index 00000000000000..5392b3553b3b14 --- /dev/null +++ b/libc/src/string/strcoll_l.cpp @@ -0,0 +1,21 @@ +//===-- Implementation of strcoll_l ---------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "src/string/strcoll_l.h" +#include "src/string/strcoll.h" + +#include "src/__support/common.h" + +namespace LIBC_NAMESPACE { + +// TODO: Add support for locales. +LLVM_LIBC_FUNCTION(int, strcoll_l, (const char *left, const char *right, locale_t)) { + return strcoll(left, right); +} + +} // namespace LIBC_NAMESPACE diff --git a/libc/src/string/strcoll_l.h b/libc/src/string/strcoll_l.h new file mode 100644 index 00000000000000..0eee80125a942a --- /dev/null +++ b/libc/src/string/strcoll_l.h @@ -0,0 +1,20 @@ +//===-- Implementation header for strcoll_l ---------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIBC_SRC_STRING_STRCOLL_L_H +#define LLVM_LIBC_SRC_STRING_STRCOLL_L_H + +#include "include/llvm-libc-types/locale_t.h" + +namespace LIBC_NAMESPACE { + +int strcoll_l(const char *left, const char *right, locale_t locale); + +} // namespace LIBC_NAMESPACE + +#endif // LLVM_LIBC_SRC_STRING_STRCOLL_L_H diff --git a/libc/src/string/strxfrm_l.cpp b/libc/src/string/strxfrm_l.cpp new file mode 100644 index 00000000000000..28f20985c28b4f --- /dev/null +++ b/libc/src/string/strxfrm_l.cpp @@ -0,0 +1,23 @@ +//===-- Implementation of strxfrm_l ---------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "src/string/strxfrm_l.h" +#include "src/string/strxfrm.h" + +#include "src/__support/common.h" + +namespace LIBC_NAMESPACE { + +// TODO: Add support for locales. +LLVM_LIBC_FUNCTION(size_t, strxfrm_l, + (char *__restrict dest, const char *__restrict src, + size_t n, locale_t)) { + return strxfrm(dest, src, n); +} + +} // namespace LIBC_NAMESPACE diff --git a/libc/src/string/strxfrm_l.h b/libc/src/string/strxfrm_l.h new file mode 100644 index 00000000000000..ae958a16f3254c --- /dev/null +++ b/libc/src/string/strxfrm_l.h @@ -0,0 +1,21 @@ +//===-- Implementation header for strxfrm_l -----------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIBC_SRC_STRING_STRXFRM_L_H +#define LLVM_LIBC_SRC_STRING_STRXFRM_L_H + +#include // For size_t +#include "include/llvm-libc-types/locale_t.h" + +namespace LIBC_NAMESPACE { + +size_t strxfrm_l(char *__restrict dest, const char *__restrict src, size_t n, locale_t locale); + +} // namespace LIBC_NAMESPACE + +#endif // LLVM_LIBC_SRC_STRING_STRXFRM_L_H