diff --git a/libc/config/linux/api.td b/libc/config/linux/api.td --- a/libc/config/linux/api.td +++ b/libc/config/linux/api.td @@ -6,17 +6,19 @@ include "spec/posix.td" include "spec/stdc.td" +// TODO: Eliminate all TypeDecl specializations. Since we define all public +// types in their own self contained header files, the header generator can +// produce the boiler plate which pulls in the type definitions. + def SizeT : TypeDecl<"size_t"> { let Decl = [{ - #define __need_size_t - #include + #include }]; } def SSizeT : TypeDecl<"ssize_t"> { let Decl = [{ - #define __need_ssize_t - #include <__posix-types.h> + #include }]; } @@ -44,8 +46,7 @@ def OffT : TypeDecl<"off_t"> { let Decl = [{ - #define __need_off_t - #include <__posix-types.h> + #include }]; } @@ -160,15 +161,13 @@ def FloatT : TypeDecl<"float_t"> { let Decl = [{ - #define __need_float_t - #include <__llvm-libc-stdc-types.h> + #include }]; } def DoubleT : TypeDecl<"double_t"> { let Decl = [{ - #define __need_double_t - #include <__llvm-libc-stdc-types.h> + #include }]; } diff --git a/libc/include/CMakeLists.txt b/libc/include/CMakeLists.txt --- a/libc/include/CMakeLists.txt +++ b/libc/include/CMakeLists.txt @@ -1,3 +1,4 @@ +add_subdirectory(llvm-libc-types) add_header( llvm_libc_common_h @@ -5,18 +6,6 @@ __llvm-libc-common.h ) -add_header( - libc_posix_types - HDR - __posix-types.h -) - -add_header( - stdc_types - HDR - __llvm-libc-stdc-types.h -) - add_gen_header( ctype DEF_FILE ctype.h.def @@ -47,7 +36,8 @@ GEN_HDR math.h DEPENDS .llvm_libc_common_h - .stdc_types + .llvm-libc-types.double_t + .llvm-libc-types.float_t ) add_gen_header( @@ -127,8 +117,9 @@ DEF_FILE unistd.h.def GEN_HDR unistd.h DEPENDS - .libc_posix_types .llvm_libc_common_h + .llvm-libc-types.size_t + .llvm-libc-types.ssize_t ) # TODO: Not all platforms will have a include/sys directory. Add the sys @@ -141,8 +132,9 @@ DEF_FILE sys/mman.h.def GEN_HDR sys/mman.h DEPENDS - .libc_posix_types .llvm_libc_common_h + .llvm-libc-types.off_t + .llvm-libc-types.ssize_t ) add_gen_header( diff --git a/libc/include/__llvm-libc-stdc-types.h b/libc/include/__llvm-libc-stdc-types.h deleted file mode 100644 --- a/libc/include/__llvm-libc-stdc-types.h +++ /dev/null @@ -1,37 +0,0 @@ -//===-- Definitions of common types from the C standard. ------------------===// -// -// 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 -// -//===----------------------------------------------------------------------===// - -// This header file does not have a header guard. It is internal to LLVM libc -// and intended to be used to pick specific definitions without polluting the -// public headers with unnecessary definitions. - -#undef __LLVM_LIBC_FLOAT_T -#undef __LLVM_LIBC_DOUBLE_T - -#if !defined(__FLT_EVAL_METHOD__) || __FLT_EVAL_METHOD__ == 0 -#define __LLVM_LIBC_FLOAT_T float -#define __LLVM_LIBC_DOUBLE_T double -#elif __FLT_EVAL_METHOD__ == 1 -#define __LLVM_LIBC_FLOAT_T double -#define __LLVM_LIBC_DOUBLE_T double -#elif __FLT_EVAL_METHOD__ == 2 -#define __LLVM_LIBC_FLOAT_T long double -#define __LLVM_LIBC_DOUBLE_T long double -#else -#error "Unsupported __FLT_EVAL_METHOD__ value." -#endif - -#if defined(__need_float_t) && !defined(__llvm_libc_float_t_defined) -typedef __LLVM_LIBC_FLOAT_T float_t; -#define __llvm_libc_float_t_defined -#endif // __need_float_t - -#if defined(__need_double_t) && !defined(__llvm_libc_double_t_defined) -typedef __LLVM_LIBC_DOUBLE_T double_t; -#define __llvm_libc_double_t_defined -#endif // __need_double_t diff --git a/libc/include/__posix-types.h b/libc/include/__posix-types.h deleted file mode 100644 --- a/libc/include/__posix-types.h +++ /dev/null @@ -1,21 +0,0 @@ -//===-- Definitions of common POSIX types ---------------------------------===// -// -// 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 -// -//===----------------------------------------------------------------------===// - -// This header file does not have a header guard. It is internal to LLVM libc -// and intended to be used to pick specific definitions without polluting the -// public headers with unnecessary definitions. - -#if defined(__need_off_t) && !defined(__llvm_libc_off_t_defined) -typedef __INT64_TYPE__ off_t; -#define __llvm_libc_off_t_defined -#endif // __need_off_t - -#if defined(__need_ssize_t) && !defined(__llvm_libc_ssize_t_defined) -typedef __INT64_TYPE__ ssize_t; -#define __llvm_libc_ssize_t_defined -#endif // __need_ssize_t diff --git a/libc/include/llvm-libc-types/CMakeLists.txt b/libc/include/llvm-libc-types/CMakeLists.txt new file mode 100644 --- /dev/null +++ b/libc/include/llvm-libc-types/CMakeLists.txt @@ -0,0 +1,5 @@ +add_header(double_t HDR double_t.h) +add_header(float_t HDR float_t.h) +add_header(off_t HDR off_t.h) +add_header(size_t HDR size_t.h) +add_header(ssize_t HDR ssize_t.h) diff --git a/libc/include/llvm-libc-types/double_t.h b/libc/include/llvm-libc-types/double_t.h new file mode 100644 --- /dev/null +++ b/libc/include/llvm-libc-types/double_t.h @@ -0,0 +1,24 @@ +//===-- Definition of double_t type ---------------------------------------===// +// +// 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_TYPES_DOUBLE_T_H__ +#define __LLVM_LIBC_TYPES_DOUBLE_T_H__ + +#if !defined(__FLT_EVAL_METHOD__) || __FLT_EVAL_METHOD__ == 0 +#define __LLVM_LIBC_DOUBLE_T double +#elif __FLT_EVAL_METHOD__ == 1 +#define __LLVM_LIBC_DOUBLE_T double +#elif __FLT_EVAL_METHOD__ == 2 +#define __LLVM_LIBC_DOUBLE_T long double +#else +#error "Unsupported __FLT_EVAL_METHOD__ value." +#endif + +typedef __LLVM_LIBC_DOUBLE_T double_t; + +#endif // __LLVM_LIBC_TYPES_DOUBLE_T_H__ diff --git a/libc/include/llvm-libc-types/float_t.h b/libc/include/llvm-libc-types/float_t.h new file mode 100644 --- /dev/null +++ b/libc/include/llvm-libc-types/float_t.h @@ -0,0 +1,24 @@ +//===-- Definition of float_t type ----------------------------------------===// +// +// 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_TYPES_FLOAT_T_H__ +#define __LLVM_LIBC_TYPES_FLOAT_T_H__ + +#if !defined(__FLT_EVAL_METHOD__) || __FLT_EVAL_METHOD__ == 0 +#define __LLVM_LIBC_FLOAT_T float +#elif __FLT_EVAL_METHOD__ == 1 +#define __LLVM_LIBC_FLOAT_T double +#elif __FLT_EVAL_METHOD__ == 2 +#define __LLVM_LIBC_FLOAT_T long double +#else +#error "Unsupported __FLT_EVAL_METHOD__ value." +#endif + +typedef __LLVM_LIBC_FLOAT_T float_t; + +#endif // __LLVM_LIBC_TYPES_FLOAT_T_H__ diff --git a/libc/include/llvm-libc-types/off_t.h b/libc/include/llvm-libc-types/off_t.h new file mode 100644 --- /dev/null +++ b/libc/include/llvm-libc-types/off_t.h @@ -0,0 +1,14 @@ +//===-- Definition of off_t type ------------------------------------------===// +// +// 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_TYPES_OFF_T_H__ +#define __LLVM_LIBC_TYPES_OFF_T_H__ + +typedef __INT64_TYPE__ off_t; + +#endif // __LLVM_LIBC_TYPES_OFF_T_H__ diff --git a/libc/include/llvm-libc-types/size_t.h b/libc/include/llvm-libc-types/size_t.h new file mode 100644 --- /dev/null +++ b/libc/include/llvm-libc-types/size_t.h @@ -0,0 +1,18 @@ +//===-- Definition of size_t types ----------------------------------------===// +// +// 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_TYPES_SIZE_T_H__ +#define __LLVM_LIBC_TYPES_SIZE_T_H__ + +// Since __need_size_t is defined, we get the definition of size_t from the +// standalone C header stddef.h. Also, because __need_size_t is defined, +// including stddef.h will pull only the type size_t and nothing else.a +#define __need_size_t +#include + +#endif // __LLVM_LIBC_TYPES_SIZE_T_H__ diff --git a/libc/include/llvm-libc-types/ssize_t.h b/libc/include/llvm-libc-types/ssize_t.h new file mode 100644 --- /dev/null +++ b/libc/include/llvm-libc-types/ssize_t.h @@ -0,0 +1,14 @@ +//===-- Definition of ssize_t type ----------------------------------------===// +// +// 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_TYPES_SSIZE_T_H__ +#define __LLVM_LIBC_TYPES_SSIZE_T_H__ + +typedef __INT64_TYPE__ ssize_t; + +#endif // __LLVM_LIBC_TYPES_SSIZE_T_H__