[libc] Move type definitions to their own self contained header files.
authorSiva Chandra Reddy <sivachandra@google.com>
Thu, 13 Jan 2022 23:40:49 +0000 (23:40 +0000)
committerSiva Chandra Reddy <sivachandra@google.com>
Thu, 20 Jan 2022 00:13:32 +0000 (00:13 +0000)
Reviewed By: michaelrj

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

libc/config/linux/api.td
libc/include/CMakeLists.txt
libc/include/__llvm-libc-stdc-types.h [deleted file]
libc/include/__posix-types.h [deleted file]
libc/include/llvm-libc-types/CMakeLists.txt [new file with mode: 0644]
libc/include/llvm-libc-types/double_t.h [new file with mode: 0644]
libc/include/llvm-libc-types/float_t.h [new file with mode: 0644]
libc/include/llvm-libc-types/off_t.h [new file with mode: 0644]
libc/include/llvm-libc-types/size_t.h [new file with mode: 0644]
libc/include/llvm-libc-types/ssize_t.h [new file with mode: 0644]

index d60d17b..8201edb 100644 (file)
@@ -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>
   }];
 }
 
index d6101ed..ba6b47c 100644 (file)
@@ -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 (file)
index 8e3bad6..0000000
+++ /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 (file)
index 3084472..0000000
+++ /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 (file)
index 0000000..ced6a38
--- /dev/null
@@ -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 (file)
index 0000000..2aa471d
--- /dev/null
@@ -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 (file)
index 0000000..8df3bf0
--- /dev/null
@@ -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 (file)
index 0000000..111b29a
--- /dev/null
@@ -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 (file)
index 0000000..ce055d0
--- /dev/null
@@ -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 (file)
index 0000000..b887453
--- /dev/null
@@ -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__