[libc-commits] [libc] 2517497 - [libc] Rearrange error and signal tables.

Siva Chandra Reddy via libc-commits libc-commits at lists.llvm.org
Wed May 24 22:51:55 PDT 2023


Author: Siva Chandra Reddy
Date: 2023-05-25T05:51:32Z
New Revision: 25174976e19b2ef916bb94f4613662646c95cd46

URL: https://github.com/llvm/llvm-project/commit/25174976e19b2ef916bb94f4613662646c95cd46
DIFF: https://github.com/llvm/llvm-project/commit/25174976e19b2ef916bb94f4613662646c95cd46.diff

LOG: [libc] Rearrange error and signal tables.

This is largely a cosmetic change done with a few goals:
1. Reduce the conditionals in picking the correct set of tables for the
   platform.
2. Avoid exposing, for example Linux errors, when building for non-Linux
   platforms. This also prevents build failures when Linux errors are not
   defined on the target non-Linux platform.
3. Some "_table" suffixes have been removed to avoid repeated
   occurance of "table" like "tables/linux_error_table.h".

Reviewed By: michaelrj

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

Added: 
    libc/src/__support/StringUtil/platform_errors.h
    libc/src/__support/StringUtil/platform_signals.h
    libc/src/__support/StringUtil/tables/linux_extension_errors.h
    libc/src/__support/StringUtil/tables/linux_extension_signals.h
    libc/src/__support/StringUtil/tables/linux_platform_errors.h
    libc/src/__support/StringUtil/tables/linux_platform_signals.h
    libc/src/__support/StringUtil/tables/minimal_platform_errors.h
    libc/src/__support/StringUtil/tables/minimal_platform_signals.h
    libc/src/__support/StringUtil/tables/posix_errors.h
    libc/src/__support/StringUtil/tables/posix_signals.h
    libc/src/__support/StringUtil/tables/stdc_errors.h
    libc/src/__support/StringUtil/tables/stdc_signals.h

Modified: 
    libc/src/__support/StringUtil/CMakeLists.txt
    libc/src/__support/StringUtil/error_to_string.cpp
    libc/src/__support/StringUtil/message_mapper.h
    libc/src/__support/StringUtil/signal_to_string.cpp
    libc/src/__support/StringUtil/tables/CMakeLists.txt

Removed: 
    libc/src/__support/StringUtil/tables/error_table.h
    libc/src/__support/StringUtil/tables/linux/CMakeLists.txt
    libc/src/__support/StringUtil/tables/linux/error_table.h
    libc/src/__support/StringUtil/tables/linux/signal_table.h
    libc/src/__support/StringUtil/tables/posix_error_table.h
    libc/src/__support/StringUtil/tables/posix_signal_table.h
    libc/src/__support/StringUtil/tables/stdc_error_table.h
    libc/src/__support/StringUtil/tables/stdc_signal_table.h


################################################################################
diff  --git a/libc/src/__support/StringUtil/CMakeLists.txt b/libc/src/__support/StringUtil/CMakeLists.txt
index 528f1e8896637..52daa303f3da0 100644
--- a/libc/src/__support/StringUtil/CMakeLists.txt
+++ b/libc/src/__support/StringUtil/CMakeLists.txt
@@ -3,6 +3,7 @@ add_header_library(
   HDRS
     message_mapper.h
   DEPENDS
+    libc.src.__support.CPP.array
     libc.src.__support.CPP.string_view
     libc.src.__support.CPP.optional
 )
@@ -10,6 +11,30 @@ add_header_library(
 # The table maps depend on message_mapper.
 add_subdirectory(tables)
 
+add_header_library(
+  platform_errors
+  HDRS
+    platform_errors.h
+  DEPENDS
+    # To avoid complicated conditionals, we will unconditionally add dependency
+    # on all platform errors which are included in platform_error_table.h.
+    # Ultimately, only the relevent error table will be used.
+    .tables.linux_platform_errors
+    .tables.minimal_platform_errors
+)
+
+add_header_library(
+  platform_signals
+  HDRS
+    platform_signals.h
+  DEPENDS
+    # To avoid complicated conditionals, we will unconditionally add dependency
+    # on all platform signals which are included in platform_signal_table.h.
+    # Ultimately, only the relevent signal table will be used.
+    .tables.linux_platform_signals
+    .tables.minimal_platform_signals
+)
+
 add_object_library(
   error_to_string
   HDRS
@@ -18,12 +43,11 @@ add_object_library(
     error_to_string.cpp
   DEPENDS
     .message_mapper
-    libc.src.errno.errno
+    .platform_errors
     libc.src.__support.CPP.span
     libc.src.__support.CPP.string_view
     libc.src.__support.CPP.stringstream
     libc.src.__support.integer_to_string
-    libc.src.__support.StringUtil.tables.error_table
 )
 
 add_object_library(
@@ -34,10 +58,10 @@ add_object_library(
     signal_to_string.cpp
   DEPENDS
     .message_mapper
+    .platform_signals
     libc.include.signal
     libc.src.__support.CPP.span
     libc.src.__support.CPP.string_view
     libc.src.__support.CPP.stringstream
     libc.src.__support.integer_to_string
-    libc.src.__support.StringUtil.tables.signal_table
 )

diff  --git a/libc/src/__support/StringUtil/error_to_string.cpp b/libc/src/__support/StringUtil/error_to_string.cpp
index 6a35b359220a0..193d7d0e34aa5 100644
--- a/libc/src/__support/StringUtil/error_to_string.cpp
+++ b/libc/src/__support/StringUtil/error_to_string.cpp
@@ -6,19 +6,15 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "src/__support/StringUtil/error_to_string.h"
+#include "error_to_string.h"
+#include "platform_errors.h"
 
-#include "src/errno/libc_errno.h" // For error macros
-
-#include "src/__support/CPP/array.h"
 #include "src/__support/CPP/span.h"
 #include "src/__support/CPP/string_view.h"
 #include "src/__support/CPP/stringstream.h"
 #include "src/__support/StringUtil/message_mapper.h"
 #include "src/__support/integer_to_string.h"
 
-#include "src/__support/StringUtil/tables/error_table.h"
-
 #include <stddef.h>
 
 namespace __llvm_libc {

diff  --git a/libc/src/__support/StringUtil/message_mapper.h b/libc/src/__support/StringUtil/message_mapper.h
index 91b13549a2000..f73b8de6cc57e 100644
--- a/libc/src/__support/StringUtil/message_mapper.h
+++ b/libc/src/__support/StringUtil/message_mapper.h
@@ -15,7 +15,6 @@
 #include <stddef.h>
 
 namespace __llvm_libc {
-namespace internal {
 
 struct MsgMapping {
   int num;
@@ -99,7 +98,6 @@ constexpr MsgTable<N1 + N2> operator+(const MsgTable<N1> &t1,
   return res;
 }
 
-} // namespace internal
 } // namespace __llvm_libc
 
 #endif // LLVM_LIBC_SRC_SUPPORT_STRING_UTIL_MESSAGE_MAPPER_H

diff  --git a/libc/src/__support/StringUtil/platform_errors.h b/libc/src/__support/StringUtil/platform_errors.h
new file mode 100644
index 0000000000000..8ca3baee421b5
--- /dev/null
+++ b/libc/src/__support/StringUtil/platform_errors.h
@@ -0,0 +1,18 @@
+//===-- The error table for the current platform ----------------*- 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_SUPPORT_STRING_UTIL_PLATFORM_ERROR_TABLE_H
+#define LLVM_LIBC_SRC_SUPPORT_STRING_UTIL_PLATFORM_ERROR_TABLE_H
+
+#if defined(__linux__) || defined(__Fuchsia__)
+#include "tables/linux_platform_errors.h"
+#else
+#include "tables/minimal_platform_errors.h"
+#endif
+
+#endif // LLVM_LIBC_SRC_SUPPORT_STRING_UTIL_PLATFORM_ERROR_TABLE_H

diff  --git a/libc/src/__support/StringUtil/platform_signals.h b/libc/src/__support/StringUtil/platform_signals.h
new file mode 100644
index 0000000000000..eef0d3ddefaed
--- /dev/null
+++ b/libc/src/__support/StringUtil/platform_signals.h
@@ -0,0 +1,18 @@
+//===-- The signal table for the current platform ---------------*- 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_SUPPORT_STRING_UTIL_PLATFORM_SIGNAL_TABLE_H
+#define LLVM_LIBC_SRC_SUPPORT_STRING_UTIL_PLATFORM_SIGNAL_TABLE_H
+
+#if defined(__linux__) || defined(__Fuchsia__)
+#include "tables/linux_platform_signals.h"
+#else
+#include "tables/minimal_platform_signals.h"
+#endif
+
+#endif // LLVM_LIBC_SRC_SUPPORT_STRING_UTIL_PLATFORM_SIGNAL_TABLE_H

diff  --git a/libc/src/__support/StringUtil/signal_to_string.cpp b/libc/src/__support/StringUtil/signal_to_string.cpp
index b3201380af8f0..c14123ab161d1 100644
--- a/libc/src/__support/StringUtil/signal_to_string.cpp
+++ b/libc/src/__support/StringUtil/signal_to_string.cpp
@@ -6,13 +6,13 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "src/__support/StringUtil/signal_to_string.h"
+#include "signal_to_string.h"
+#include "platform_signals.h"
 
 #include "src/__support/CPP/span.h"
 #include "src/__support/CPP/string_view.h"
 #include "src/__support/CPP/stringstream.h"
 #include "src/__support/StringUtil/message_mapper.h"
-#include "src/__support/StringUtil/tables/signal_table.h"
 #include "src/__support/integer_to_string.h"
 
 #include <signal.h>

diff  --git a/libc/src/__support/StringUtil/tables/CMakeLists.txt b/libc/src/__support/StringUtil/tables/CMakeLists.txt
index e8208f3973c8c..faba4fdb86b7d 100644
--- a/libc/src/__support/StringUtil/tables/CMakeLists.txt
+++ b/libc/src/__support/StringUtil/tables/CMakeLists.txt
@@ -1,35 +1,89 @@
-if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${LIBC_TARGET_OS})
-  add_subdirectory(${LIBC_TARGET_OS})
-endif()
+add_header_library(
+  stdc_errors
+  HDRS
+    stdc_errors.h
+  DEPENDS
+    libc.include.errno
+    libc.src.__support.StringUtil.message_mapper
+)
 
-set(error_to_string_platform_dep "")
-if(TARGET libc.src.__support.StringUtil.tables.${LIBC_TARGET_OS}.error_table)
-  set(error_to_string_platform_dep 
-  libc.src.__support.StringUtil.tables.${LIBC_TARGET_OS}.error_table)
-endif()
+add_header_library(
+  posix_errors
+  HDRS
+    posix_errors.h
+  DEPENDS
+    libc.include.errno
+    libc.src.__support.StringUtil.message_mapper
+)
 
 add_header_library(
-  error_table
+  linux_extension_errors
   HDRS
-    error_table.h  
-    stdc_error_table.h  
-    posix_error_table.h  
+    linux_extension_errors.h
   DEPENDS
-    ${error_to_string_platform_dep}
+    libc.include.errno
+    libc.src.__support.StringUtil.message_mapper
 )
 
-set(signal_to_string_platform_dep "")
-if(TARGET libc.src.__support.StringUtil.tables.${LIBC_TARGET_OS}.signal_table)
-  set(signal_to_string_platform_dep 
-  libc.src.__support.StringUtil.tables.${LIBC_TARGET_OS}.signal_table)
-endif()
+add_header_library(
+  linux_platform_errors
+  HDRS
+    linux_platform_errors
+  DEPENDS
+    .linux_extension_errors
+    .posix_errors
+    .stdc_errors
+)
+
+add_header_library(
+  minimal_platform_errors
+  HDRS
+    minimal_platform_errors
+  DEPENDS
+    .stdc_errors
+)
+
+add_header_library(
+  stdc_signals
+  HDRS
+    stdc_signals.h
+  DEPENDS
+    libc.include.signal
+    libc.src.__support.StringUtil.message_mapper
+)
+
+add_header_library(
+  posix_signals
+  HDRS
+    posix_signals.h
+  DEPENDS
+    libc.include.signal
+    libc.src.__support.StringUtil.message_mapper
+)
+
+add_header_library(
+  linux_extension_signals
+  HDRS
+    linux_extension_signals.h
+  DEPENDS
+    libc.include.signal
+    libc.src.__support.StringUtil.message_mapper
+)
+
+add_header_library(
+  linux_platform_signals
+  HDRS
+    linux_platform_signals
+  DEPENDS
+    .linux_extension_signals
+    .posix_signals
+    .stdc_signals
+)
 
 add_header_library(
-  signal_table
+  minimal_platform_signals
   HDRS
-    signal_table.h  
-    stdc_signal_table.h  
-    posix_signal_table.h  
+    minimal_platform_signals
   DEPENDS
-    ${signal_to_string_platform_dep}
+    .stdc_signals
 )

diff  --git a/libc/src/__support/StringUtil/tables/error_table.h b/libc/src/__support/StringUtil/tables/error_table.h
deleted file mode 100644
index 5e8226e7d390b..0000000000000
--- a/libc/src/__support/StringUtil/tables/error_table.h
+++ /dev/null
@@ -1,39 +0,0 @@
-//===-- Map from error numbers to strings -----------------------*- 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_SUPPORT_STRING_UTIL_TABLES_ERROR_TABLE_H
-#define LLVM_LIBC_SRC_SUPPORT_STRING_UTIL_TABLES_ERROR_TABLE_H
-
-#include "src/__support/StringUtil/message_mapper.h"
-
-#include "posix_error_table.h"
-#include "stdc_error_table.h"
-
-#if defined(__linux__) || defined(__Fuchsia__)
-#define USE_LINUX_PLATFORM_ERRORS 1
-#else
-#define USE_LINUX_PLATFORM_ERRORS 0
-#endif
-
-#if USE_LINUX_PLATFORM_ERRORS
-#include "linux/error_table.h"
-#endif
-
-namespace __llvm_libc::internal {
-
-inline constexpr auto PLATFORM_ERRORS = []() {
-  if constexpr (USE_LINUX_PLATFORM_ERRORS) {
-    return STDC_ERRORS + POSIX_ERRORS + LINUX_ERRORS;
-  } else {
-    return STDC_ERRORS;
-  }
-}();
-
-} // namespace __llvm_libc::internal
-
-#endif // LLVM_LIBC_SRC_SUPPORT_STRING_UTIL_TABLES_ERROR_TABLE_H

diff  --git a/libc/src/__support/StringUtil/tables/linux/CMakeLists.txt b/libc/src/__support/StringUtil/tables/linux/CMakeLists.txt
deleted file mode 100644
index 82d3a293570e8..0000000000000
--- a/libc/src/__support/StringUtil/tables/linux/CMakeLists.txt
+++ /dev/null
@@ -1,17 +0,0 @@
-add_header_library(
-  error_table
-  HDRS
-    error_table.h
-  DEPENDS
-  libc.src.__support.StringUtil.message_mapper
-  libc.src.errno.errno
-)
-
-add_header_library(
-  signal_table
-  HDRS
-    signal_table.h
-  DEPENDS
-  libc.src.__support.StringUtil.message_mapper
-  libc.include.signal
-)

diff  --git a/libc/src/__support/StringUtil/tables/linux/error_table.h b/libc/src/__support/StringUtil/tables/linux_extension_errors.h
similarity index 87%
rename from libc/src/__support/StringUtil/tables/linux/error_table.h
rename to libc/src/__support/StringUtil/tables/linux_extension_errors.h
index c898cf9728d15..632c563241021 100644
--- a/libc/src/__support/StringUtil/tables/linux/error_table.h
+++ b/libc/src/__support/StringUtil/tables/linux_extension_errors.h
@@ -1,4 +1,4 @@
-//===-- Map from error numbers to strings on linux --------------*- C++ -*-===//
+//===-- Map of Linux extension error numbers to strings ---------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -6,15 +6,14 @@
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef LLVM_LIBC_SRC_SUPPORT_STRING_UTIL_TABLES_LINUX_ERROR_TABLE_H
-#define LLVM_LIBC_SRC_SUPPORT_STRING_UTIL_TABLES_LINUX_ERROR_TABLE_H
+#ifndef LLVM_LIBC_SRC_SUPPORT_STRING_UTIL_TABLES_LINUX_EXTENSION_ERRORS_H
+#define LLVM_LIBC_SRC_SUPPORT_STRING_UTIL_TABLES_LINUX_EXTENSION_ERRORS_H
 
-#include "src/errno/libc_errno.h" // For error macros
-
-#include "src/__support/CPP/array.h"
 #include "src/__support/StringUtil/message_mapper.h"
 
-namespace __llvm_libc::internal {
+#include <errno.h> // For error macros
+
+namespace __llvm_libc {
 
 constexpr MsgTable<52> LINUX_ERRORS = {
     MsgMapping(ENOTBLK, "Block device required"),
@@ -71,6 +70,6 @@ constexpr MsgTable<52> LINUX_ERRORS = {
     MsgMapping(EHWPOISON, "Memory page has hardware error"),
 };
 
-} // namespace __llvm_libc::internal
+} // namespace __llvm_libc
 
-#endif // LLVM_LIBC_SRC_SUPPORT_STRING_UTIL_TABLES_LINUX_ERROR_TABLE_H
+#endif // LLVM_LIBC_SRC_SUPPORT_STRING_UTIL_TABLES_LINUX_EXTENSION_ERRORS_H

diff  --git a/libc/src/__support/StringUtil/tables/linux/signal_table.h b/libc/src/__support/StringUtil/tables/linux_extension_signals.h
similarity index 68%
rename from libc/src/__support/StringUtil/tables/linux/signal_table.h
rename to libc/src/__support/StringUtil/tables/linux_extension_signals.h
index 864cd6f9ba022..7e31009608687 100644
--- a/libc/src/__support/StringUtil/tables/linux/signal_table.h
+++ b/libc/src/__support/StringUtil/tables/linux_extension_signals.h
@@ -1,4 +1,4 @@
-//===-- Map from signal numbers to strings on linux -------------*- C++ -*-===//
+//===-- Map of Linux extension signal numbers to strings --------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -6,14 +6,14 @@
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef LLVM_LIBC_SRC_SUPPORT_STRING_UTIL_TABLES_LINUX_SIGNAL_TABLE_H
-#define LLVM_LIBC_SRC_SUPPORT_STRING_UTIL_TABLES_LINUX_SIGNAL_TABLE_H
-
-#include <signal.h>
+#ifndef LLVM_LIBC_SRC_SUPPORT_STRING_UTIL_TABLES_LINUX_EXTENSION_SIGNALS_H
+#define LLVM_LIBC_SRC_SUPPORT_STRING_UTIL_TABLES_LINUX_EXTENSION_SIGNALS_H
 
 #include "src/__support/StringUtil/message_mapper.h"
 
-namespace __llvm_libc::internal {
+#include <signal.h> // For signal numbers
+
+namespace __llvm_libc {
 
 // The array being larger than necessary isn't a problem. The MsgMappings will
 // be set to their default state which maps 0 to an empty string. This will get
@@ -28,6 +28,6 @@ inline constexpr const MsgTable<3> LINUX_SIGNALS = {
 #endif
 };
 
-} // namespace __llvm_libc::internal
+} // namespace __llvm_libc
 
-#endif // LLVM_LIBC_SRC_SUPPORT_STRING_UTIL_TABLES_LINUX_SIGNAL_TABLE_H
+#endif // LLVM_LIBC_SRC_SUPPORT_STRING_UTIL_TABLES_LINUX_EXTENSION_SIGNALS_H

diff  --git a/libc/src/__support/StringUtil/tables/linux_platform_errors.h b/libc/src/__support/StringUtil/tables/linux_platform_errors.h
new file mode 100644
index 0000000000000..e6d20106f2526
--- /dev/null
+++ b/libc/src/__support/StringUtil/tables/linux_platform_errors.h
@@ -0,0 +1,23 @@
+//===-- Map of error numbers to strings for the Linux platform --*- 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_SUPPORT_STRING_UTIL_TABLES_LINUX_PLATFORM_ERRORS_H
+#define LLVM_LIBC_SRC_SUPPORT_STRING_UTIL_TABLES_LINUX_PLATFORM_ERRORS_H
+
+#include "linux_extension_errors.h"
+#include "posix_errors.h"
+#include "stdc_errors.h"
+
+namespace __llvm_libc {
+
+inline constexpr auto PLATFORM_ERRORS =
+    STDC_ERRORS + POSIX_ERRORS + LINUX_ERRORS;
+
+} // namespace __llvm_libc
+
+#endif // LLVM_LIBC_SRC_SUPPORT_STRING_UTIL_TABLES_LINUX_PLATFORM_ERRORS_H

diff  --git a/libc/src/__support/StringUtil/tables/linux_platform_signals.h b/libc/src/__support/StringUtil/tables/linux_platform_signals.h
new file mode 100644
index 0000000000000..7f98a241f9c40
--- /dev/null
+++ b/libc/src/__support/StringUtil/tables/linux_platform_signals.h
@@ -0,0 +1,23 @@
+//===-- Map of error numbers to strings for the Linux platform --*- 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_SUPPORT_STRING_UTIL_TABLES_LINUX_PLATFORM_SIGNALS_H
+#define LLVM_LIBC_SRC_SUPPORT_STRING_UTIL_TABLES_LINUX_PLATFORM_SIGNALS_H
+
+#include "linux_extension_signals.h"
+#include "posix_signals.h"
+#include "stdc_signals.h"
+
+namespace __llvm_libc {
+
+inline constexpr auto PLATFORM_SIGNALS =
+    STDC_SIGNALS + POSIX_SIGNALS + LINUX_SIGNALS;
+
+} // namespace __llvm_libc
+
+#endif // LLVM_LIBC_SRC_SUPPORT_STRING_UTIL_TABLES_LINUX_PLATFORM_SIGNALS_H

diff  --git a/libc/src/__support/StringUtil/tables/minimal_platform_errors.h b/libc/src/__support/StringUtil/tables/minimal_platform_errors.h
new file mode 100644
index 0000000000000..9fa75d5c9a76a
--- /dev/null
+++ b/libc/src/__support/StringUtil/tables/minimal_platform_errors.h
@@ -0,0 +1,20 @@
+//===-- Map of error numbers to strings for a stdc platform -----*- 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_SUPPORT_STRING_UTIL_TABLES_MINIMAL_PLATFORM_ERRORS_H
+#define LLVM_LIBC_SRC_SUPPORT_STRING_UTIL_TABLES_MINIMAL_PLATFORM_ERRORS_H
+
+#include "stdc_errors.h"
+
+namespace __llvm_libc {
+
+inline constexpr auto PLATFORM_ERRORS = STDC_ERRORS;
+
+} // namespace __llvm_libc
+
+#endif // LLVM_LIBC_SRC_SUPPORT_STRING_UTIL_TABLES_MINIMAL_PLATFORM_ERRORS_H

diff  --git a/libc/src/__support/StringUtil/tables/minimal_platform_signals.h b/libc/src/__support/StringUtil/tables/minimal_platform_signals.h
new file mode 100644
index 0000000000000..758dfc8263da2
--- /dev/null
+++ b/libc/src/__support/StringUtil/tables/minimal_platform_signals.h
@@ -0,0 +1,20 @@
+//===-- Map of error numbers to strings for a stdc platform -----*- 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_SUPPORT_STRING_UTIL_TABLES_MINIMAL_PLATFORM_SIGNALS_H
+#define LLVM_LIBC_SRC_SUPPORT_STRING_UTIL_TABLES_MINIMAL_PLATFORM_SIGNALS_H
+
+#include "stdc_signals.h"
+
+namespace __llvm_libc {
+
+inline constexpr auto PLATFORM_SIGNALS = STDC_SIGNALS;
+
+} // namespace __llvm_libc
+
+#endif // LLVM_LIBC_SRC_SUPPORT_STRING_UTIL_TABLES_MINIMAL_PLATFORM_SIGNALS_H

diff  --git a/libc/src/__support/StringUtil/tables/posix_error_table.h b/libc/src/__support/StringUtil/tables/posix_errors.h
similarity index 90%
rename from libc/src/__support/StringUtil/tables/posix_error_table.h
rename to libc/src/__support/StringUtil/tables/posix_errors.h
index 1778eb9439df9..43b1d9dec562e 100644
--- a/libc/src/__support/StringUtil/tables/posix_error_table.h
+++ b/libc/src/__support/StringUtil/tables/posix_errors.h
@@ -1,4 +1,4 @@
-//===-- Map from error numbers to strings in posix --------------*- C++ -*-===//
+//===-- Map of POSIX error numbers to strings -------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -6,15 +6,14 @@
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef LLVM_LIBC_SRC_SUPPORT_STRING_UTIL_TABLES_POSIX_ERROR_TABLE_H
-#define LLVM_LIBC_SRC_SUPPORT_STRING_UTIL_TABLES_POSIX_ERROR_TABLE_H
+#ifndef LLVM_LIBC_SRC_SUPPORT_STRING_UTIL_TABLES_POSIX_ERRORS_H
+#define LLVM_LIBC_SRC_SUPPORT_STRING_UTIL_TABLES_POSIX_ERRORS_H
 
-#include "src/errno/libc_errno.h" // For error macros
-
-#include "src/__support/CPP/array.h"
 #include "src/__support/StringUtil/message_mapper.h"
 
-namespace __llvm_libc::internal {
+#include <errno.h> // For error macros
+
+namespace __llvm_libc {
 
 inline constexpr MsgTable<76> POSIX_ERRORS = {
     MsgMapping(EPERM, "Operation not permitted"),
@@ -95,6 +94,6 @@ inline constexpr MsgTable<76> POSIX_ERRORS = {
     MsgMapping(ENOTRECOVERABLE, "State not recoverable"),
 };
 
-} // namespace __llvm_libc::internal
+} // namespace __llvm_libc
 
-#endif // LLVM_LIBC_SRC_SUPPORT_STRING_UTIL_TABLES_POSIX_ERROR_TABLE_H
+#endif // LLVM_LIBC_SRC_SUPPORT_STRING_UTIL_TABLES_POSIX_ERRORS_H

diff  --git a/libc/src/__support/StringUtil/tables/posix_signal_table.h b/libc/src/__support/StringUtil/tables/posix_signals.h
similarity index 79%
rename from libc/src/__support/StringUtil/tables/posix_signal_table.h
rename to libc/src/__support/StringUtil/tables/posix_signals.h
index aae0884424b74..b34035d367e88 100644
--- a/libc/src/__support/StringUtil/tables/posix_signal_table.h
+++ b/libc/src/__support/StringUtil/tables/posix_signals.h
@@ -1,4 +1,4 @@
-//===-- Map from signal numbers to strings in posix -------------*- C++ -*-===//
+//===-- Map of POSIX signal numbers to strings ------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -6,15 +6,15 @@
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef LLVM_LIBC_SRC_SUPPORT_STRING_UTIL_TABLES_POSIX_SIGNAL_TABLE_H
-#define LLVM_LIBC_SRC_SUPPORT_STRING_UTIL_TABLES_POSIX_SIGNAL_TABLE_H
-
-#include <signal.h>
+#ifndef LLVM_LIBC_SRC_SUPPORT_STRING_UTIL_TABLES_POSIX_SIGNALS_H
+#define LLVM_LIBC_SRC_SUPPORT_STRING_UTIL_TABLES_POSIX_SIGNALS_H
 
 #include "src/__support/CPP/array.h"
 #include "src/__support/StringUtil/message_mapper.h"
 
-namespace __llvm_libc::internal {
+#include <signal.h> // For signal numbers
+
+namespace __llvm_libc {
 
 inline constexpr MsgTable<22> POSIX_SIGNALS = {
     MsgMapping(SIGHUP, "Hangup"),
@@ -41,6 +41,6 @@ inline constexpr MsgTable<22> POSIX_SIGNALS = {
     MsgMapping(SIGSYS, "Bad system call"),
 };
 
-} // namespace __llvm_libc::internal
+} // namespace __llvm_libc
 
-#endif // LLVM_LIBC_SRC_SUPPORT_STRING_UTIL_TABLES_POSIX_SIGNAL_TABLE_H
+#endif // LLVM_LIBC_SRC_SUPPORT_STRING_UTIL_TABLES_POSIX_SIGNALS_H

diff  --git a/libc/src/__support/StringUtil/tables/stdc_error_table.h b/libc/src/__support/StringUtil/tables/stdc_errors.h
similarity index 61%
rename from libc/src/__support/StringUtil/tables/stdc_error_table.h
rename to libc/src/__support/StringUtil/tables/stdc_errors.h
index 5a2a883d34f91..42b934f1ba9c3 100644
--- a/libc/src/__support/StringUtil/tables/stdc_error_table.h
+++ b/libc/src/__support/StringUtil/tables/stdc_errors.h
@@ -1,4 +1,4 @@
-//===-- Map from error numbers to strings in the c std ----------*- C++ -*-===//
+//===-- Map of C standard error numbers to strings --------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -6,14 +6,14 @@
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef LLVM_LIBC_SRC_SUPPORT_STRING_UTIL_TABLES_STDC_ERROR_TABLE_H
-#define LLVM_LIBC_SRC_SUPPORT_STRING_UTIL_TABLES_STDC_ERROR_TABLE_H
-
-#include "src/errno/libc_errno.h" // For error macros
+#ifndef LLVM_LIBC_SRC_SUPPORT_STRING_UTIL_TABLES_STDC_ERRORS_H
+#define LLVM_LIBC_SRC_SUPPORT_STRING_UTIL_TABLES_STDC_ERRORS_H
 
 #include "src/__support/StringUtil/message_mapper.h"
 
-namespace __llvm_libc::internal {
+#include <errno.h> // For error macros
+
+namespace __llvm_libc {
 
 inline constexpr const MsgTable<4> STDC_ERRORS = {
     MsgMapping(0, "Success"),
@@ -22,6 +22,6 @@ inline constexpr const MsgTable<4> STDC_ERRORS = {
     MsgMapping(EILSEQ, "Invalid or incomplete multibyte or wide character"),
 };
 
-} // namespace __llvm_libc::internal
+} // namespace __llvm_libc
 
-#endif // LLVM_LIBC_SRC_SUPPORT_STRING_UTIL_TABLES_LINUX_ERROR_TABLE_H
+#endif // LLVM_LIBC_SRC_SUPPORT_STRING_UTIL_TABLES_LINUX_ERRORS_H

diff  --git a/libc/src/__support/StringUtil/tables/stdc_signal_table.h b/libc/src/__support/StringUtil/tables/stdc_signals.h
similarity index 65%
rename from libc/src/__support/StringUtil/tables/stdc_signal_table.h
rename to libc/src/__support/StringUtil/tables/stdc_signals.h
index 10cae1e022394..3de4318ed8f6f 100644
--- a/libc/src/__support/StringUtil/tables/stdc_signal_table.h
+++ b/libc/src/__support/StringUtil/tables/stdc_signals.h
@@ -1,4 +1,4 @@
-//===-- Map from signal numbers to strings in the c std ---------*- C++ -*-===//
+//===-- Map of C standard signal numbers to strings -------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -6,14 +6,14 @@
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef LLVM_LIBC_SRC_SUPPORT_STRING_UTIL_TABLES_STDC_SIGNAL_TABLE_H
-#define LLVM_LIBC_SRC_SUPPORT_STRING_UTIL_TABLES_STDC_SIGNAL_TABLE_H
+#ifndef LLVM_LIBC_SRC_SUPPORT_STRING_UTIL_TABLES_STDC_SIGNALS_H
+#define LLVM_LIBC_SRC_SUPPORT_STRING_UTIL_TABLES_STDC_SIGNALS_H
 
-#include <signal.h>
+#include <signal.h> // For signal numbers
 
 #include "src/__support/StringUtil/message_mapper.h"
 
-namespace __llvm_libc::internal {
+namespace __llvm_libc {
 
 inline constexpr const MsgTable<6> STDC_SIGNALS = {
     MsgMapping(SIGINT, "Interrupt"),
@@ -24,6 +24,6 @@ inline constexpr const MsgTable<6> STDC_SIGNALS = {
     MsgMapping(SIGTERM, "Terminated"),
 };
 
-} // namespace __llvm_libc::internal
+} // namespace __llvm_libc
 
-#endif // LLVM_LIBC_SRC_SUPPORT_STRING_UTIL_TABLES_LINUX_SIGNAL_TABLE_H
+#endif // LLVM_LIBC_SRC_SUPPORT_STRING_UTIL_TABLES_LINUX_SIGNALS_H


        


More information about the libc-commits mailing list