[libc-commits] [libc] 10ed3c9 - [libc] Move type definitions to their own self contained header files.

Siva Chandra Reddy via libc-commits libc-commits at lists.llvm.org
Wed Jan 19 16:13:49 PST 2022


Author: Siva Chandra Reddy
Date: 2022-01-20T00:13:32Z
New Revision: 10ed3c9d2ca4af604bb90d9eaa3eefca5b02f2d4

URL: https://github.com/llvm/llvm-project/commit/10ed3c9d2ca4af604bb90d9eaa3eefca5b02f2d4
DIFF: https://github.com/llvm/llvm-project/commit/10ed3c9d2ca4af604bb90d9eaa3eefca5b02f2d4.diff

LOG: [libc] Move type definitions to their own self contained header files.

Reviewed By: michaelrj

Differential Revision: https://reviews.llvm.org/D117282

Added: 
    libc/include/llvm-libc-types/CMakeLists.txt
    libc/include/llvm-libc-types/double_t.h
    libc/include/llvm-libc-types/float_t.h
    libc/include/llvm-libc-types/off_t.h
    libc/include/llvm-libc-types/size_t.h
    libc/include/llvm-libc-types/ssize_t.h

Modified: 
    libc/config/linux/api.td
    libc/include/CMakeLists.txt

Removed: 
    libc/include/__llvm-libc-stdc-types.h
    libc/include/__posix-types.h


################################################################################
diff  --git a/libc/config/linux/api.td b/libc/config/linux/api.td
index d60d17b6d403..8201edb76682 100644
--- a/libc/config/linux/api.td
+++ b/libc/config/linux/api.td
@@ -6,17 +6,19 @@ include "spec/llvm_libc_ext.td"
 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 <stddef.h>
+    #include <llvm-libc-types/size_t.h>
   }];
 }
 
 def SSizeT : TypeDecl<"ssize_t"> {
   let Decl = [{
-    #define __need_ssize_t
-    #include <__posix-types.h>
+    #include <llvm-libc-types/ssize_t.h>
   }];
 }
 
@@ -44,8 +46,7 @@ def TimeT: TypeDecl<"time_t"> {
 
 def OffT : TypeDecl<"off_t"> {
   let Decl = [{
-    #define __need_off_t
-    #include <__posix-types.h>
+    #include <llvm-libc-types/off_t.h>
   }];
 }
 
@@ -160,15 +161,13 @@ def IsNanMacro : MacroDef<"isnan"> {
 
 def FloatT : TypeDecl<"float_t"> {
   let Decl = [{
-    #define __need_float_t
-    #include <__llvm-libc-stdc-types.h>
+    #include <llvm-libc-types/float_t.h>
   }];
 }
 
 def DoubleT : TypeDecl<"double_t"> {
   let Decl = [{
-    #define __need_double_t
-    #include <__llvm-libc-stdc-types.h>
+    #include <llvm-libc-types/double_t.h>
   }];
 }
 

diff  --git a/libc/include/CMakeLists.txt b/libc/include/CMakeLists.txt
index d6101edac846..ba6b47c3d185 100644
--- 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 @@ add_header(
     __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 @@ add_gen_header(
   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 @@ add_gen_header(
   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 @@ add_gen_header(
   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
index 8e3bad652df0..000000000000
--- 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
index 30844728633b..000000000000
--- 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
index 000000000000..ced6a38a2de3
--- /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
index 000000000000..2aa471de4840
--- /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
index 000000000000..8df3bf05f6a1
--- /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
index 000000000000..111b29aa68d8
--- /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
index 000000000000..ce055d0bc3ba
--- /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 <stddef.h>
+
+#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
index 000000000000..b8874538b1bf
--- /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__


        


More information about the libc-commits mailing list