Skip to content

Commit

Permalink
fixup! more locale funcs
Browse files Browse the repository at this point in the history
  • Loading branch information
izaakschroeder committed Jul 2, 2024
1 parent 59e2b1d commit 3e9557c
Show file tree
Hide file tree
Showing 17 changed files with 357 additions and 0 deletions.
8 changes: 8 additions & 0 deletions libc/config/linux/aarch64/entrypoints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
6 changes: 6 additions & 0 deletions libc/config/linux/x86_64/entrypoints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down
20 changes: 20 additions & 0 deletions libc/spec/stdc.td
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,26 @@ def StdC : StandardSpec<"stdc"> {
RetValSpec<IntType>,
[ArgSpec<IntType>, ArgSpec<LocaleTType>]
>,
FunctionSpec<
"tolower_l",
RetValSpec<IntType>,
[ArgSpec<IntType>, ArgSpec<LocaleTType>]
>,
FunctionSpec<
"toupper_l",
RetValSpec<IntType>,
[ArgSpec<IntType>, ArgSpec<LocaleTType>]
>,
FunctionSpec<
"islower_l",
RetValSpec<IntType>,
[ArgSpec<IntType>, ArgSpec<LocaleTType>]
>,
FunctionSpec<
"isupper_l",
RetValSpec<IntType>,
[ArgSpec<IntType>, ArgSpec<LocaleTType>]
>,
]
>;

Expand Down
49 changes: 49 additions & 0 deletions libc/src/ctype/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
22 changes: 22 additions & 0 deletions libc/src/ctype/islower_l.cpp
Original file line number Diff line number Diff line change
@@ -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
20 changes: 20 additions & 0 deletions libc/src/ctype/islower_l.h
Original file line number Diff line number Diff line change
@@ -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
22 changes: 22 additions & 0 deletions libc/src/ctype/isupper_l.cpp
Original file line number Diff line number Diff line change
@@ -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
20 changes: 20 additions & 0 deletions libc/src/ctype/isupper_l.h
Original file line number Diff line number Diff line change
@@ -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
20 changes: 20 additions & 0 deletions libc/src/ctype/tolower_l.cpp
Original file line number Diff line number Diff line change
@@ -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
20 changes: 20 additions & 0 deletions libc/src/ctype/tolower_l.h
Original file line number Diff line number Diff line change
@@ -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
23 changes: 23 additions & 0 deletions libc/src/ctype/toupper_l.cpp
Original file line number Diff line number Diff line change
@@ -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
20 changes: 20 additions & 0 deletions libc/src/ctype/toupper_l.h
Original file line number Diff line number Diff line change
@@ -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
22 changes: 22 additions & 0 deletions libc/src/string/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
21 changes: 21 additions & 0 deletions libc/src/string/strcoll_l.cpp
Original file line number Diff line number Diff line change
@@ -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
20 changes: 20 additions & 0 deletions libc/src/string/strcoll_l.h
Original file line number Diff line number Diff line change
@@ -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
23 changes: 23 additions & 0 deletions libc/src/string/strxfrm_l.cpp
Original file line number Diff line number Diff line change
@@ -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
Loading

0 comments on commit 3e9557c

Please sign in to comment.