adding both at once since these are trivial functions.
Reviewed By: sivachandra
Differential Revision: https://reviews.llvm.org/D94558
# ctype.h entrypoints
libc.src.ctype.isalnum
libc.src.ctype.isalpha
+ libc.src.ctype.isascii
libc.src.ctype.isblank
libc.src.ctype.iscntrl
libc.src.ctype.isdigit
libc.src.ctype.isspace
libc.src.ctype.isupper
libc.src.ctype.isxdigit
+ libc.src.ctype.toascii
libc.src.ctype.tolower
libc.src.ctype.toupper
# ctype.h entrypoints
libc.src.ctype.isalnum
libc.src.ctype.isalpha
+ libc.src.ctype.isascii
libc.src.ctype.isblank
libc.src.ctype.iscntrl
libc.src.ctype.isdigit
libc.src.ctype.isspace
libc.src.ctype.isupper
libc.src.ctype.isxdigit
+ libc.src.ctype.toascii
libc.src.ctype.tolower
libc.src.ctype.toupper
def GnuExtensions : StandardSpec<"GNUExtensions"> {
+ HeaderSpec CType = HeaderSpec<
+ "ctype.h",
+ [], // Macros
+ [], // Types
+ [], // Enumerations
+ [
+ FunctionSpec<
+ "toascii",
+ RetValSpec<IntType>,
+ [ArgSpec<IntType>]
+ >,
+ ]
+ >;
+
HeaderSpec Math = HeaderSpec<
"math.h",
[], // Macros
]
>;
+
let Headers = [
- Math, String,
+ CType,
+ Math,
+ String,
];
}
]
>;
+ HeaderSpec CType = HeaderSpec<
+ "ctype.h",
+ [], // Macros
+ [], // Types
+ [], // Enumerations
+ [
+ FunctionSpec<
+ "isascii",
+ RetValSpec<IntType>,
+ [ArgSpec<IntType>]
+ >,
+ ]
+ >;
+
let Headers = [
+ CType,
Errno,
SysMMan,
Signal,
)
add_entrypoint_object(
+ isascii
+ SRCS
+ isascii.cpp
+ HDRS
+ isascii.h
+)
+
+add_entrypoint_object(
isblank
SRCS
isblank.cpp
)
add_entrypoint_object(
+ toascii
+ SRCS
+ toascii.cpp
+ HDRS
+ toascii.h
+)
+
+add_entrypoint_object(
toupper
SRCS
toupper.cpp
--- /dev/null
+//===-- Implementation of isascii------------------------------------------===//
+//
+// 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/isascii.h"
+
+#include "src/__support/common.h"
+
+namespace __llvm_libc {
+
+LLVM_LIBC_FUNCTION(int, isascii, (int c)) { return (c & (~0x7f)) == 0; }
+
+} // namespace __llvm_libc
--- /dev/null
+//===-- Implementation header for isascii -------------------------*-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_ISASCII_H
+#define LLVM_LIBC_SRC_CTYPE_ISASCII_H
+
+namespace __llvm_libc {
+
+int isascii(int c);
+
+} // namespace __llvm_libc
+
+#endif // LLVM_LIBC_SRC_CTYPE_ISASCII_H
--- /dev/null
+//===-- Implementation of toascii------------------------------------------===//
+//
+// 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/toascii.h"
+
+#include "src/__support/common.h"
+
+namespace __llvm_libc {
+
+LLVM_LIBC_FUNCTION(int, toascii, (int c)) { return (c & 0x7f); }
+
+} // namespace __llvm_libc
--- /dev/null
+//===-- Implementation header for toascii -------------------------*-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_TOASCII_H
+#define LLVM_LIBC_SRC_CTYPE_TOASCII_H
+
+namespace __llvm_libc {
+
+int toascii(int c);
+
+} // namespace __llvm_libc
+
+#endif // LLVM_LIBC_SRC_CTYPE_TOASCII_H
)
add_libc_unittest(
+ isascii
+ SUITE
+ libc_ctype_unittests
+ SRCS
+ isascii_test.cpp
+ DEPENDS
+ libc.src.ctype.isascii
+)
+
+add_libc_unittest(
isblank
SUITE
libc_ctype_unittests
)
add_libc_unittest(
+ toascii
+ SUITE
+ libc_ctype_unittests
+ SRCS
+ toascii_test.cpp
+ DEPENDS
+ libc.src.ctype.toascii
+)
+
+add_libc_unittest(
tolower
SUITE
libc_ctype_unittests
--- /dev/null
+//===-- Unittests for isascii----------------------------------------------===//
+//
+// 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/isascii.h"
+
+#include "utils/UnitTest/Test.h"
+
+TEST(IsAscii, DefaultLocale) {
+ // Loops through all characters, verifying that ascii characters
+ // (which are all 7 bit unsigned integers)
+ // return a non-zero integer and everything else returns zero.
+ for (int ch = 0; ch < 255; ++ch) {
+ if (ch <= 0x7f)
+ EXPECT_NE(__llvm_libc::isascii(ch), 0);
+ else
+ EXPECT_EQ(__llvm_libc::isascii(ch), 0);
+ }
+}
--- /dev/null
+//===-- Unittests for toascii----------------------------------------------===//
+//
+// 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/toascii.h"
+
+#include "utils/UnitTest/Test.h"
+
+TEST(ToAscii, DefaultLocale) {
+ // Loops through all characters, verifying that ascii characters
+ // (which are all 7 bit unsigned integers)
+ // return themself, and that all other characters return themself
+ // mod 128 (which is equivalent to & 0x7f)
+ for (int ch = 0; ch < 255; ++ch) {
+ if (ch <= 0x7f)
+ EXPECT_EQ(__llvm_libc::toascii(ch), ch);
+ else
+ EXPECT_EQ(__llvm_libc::toascii(ch), ch & 0x7f);
+ }
+}