Skip to content

Commit 2517497

Browse files
author
Siva Chandra Reddy
committed
[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
1 parent bcb698b commit 2517497

19 files changed

+277
-141
lines changed

libc/src/__support/StringUtil/CMakeLists.txt

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,38 @@ add_header_library(
33
HDRS
44
message_mapper.h
55
DEPENDS
6+
libc.src.__support.CPP.array
67
libc.src.__support.CPP.string_view
78
libc.src.__support.CPP.optional
89
)
910

1011
# The table maps depend on message_mapper.
1112
add_subdirectory(tables)
1213

14+
add_header_library(
15+
platform_errors
16+
HDRS
17+
platform_errors.h
18+
DEPENDS
19+
# To avoid complicated conditionals, we will unconditionally add dependency
20+
# on all platform errors which are included in platform_error_table.h.
21+
# Ultimately, only the relevent error table will be used.
22+
.tables.linux_platform_errors
23+
.tables.minimal_platform_errors
24+
)
25+
26+
add_header_library(
27+
platform_signals
28+
HDRS
29+
platform_signals.h
30+
DEPENDS
31+
# To avoid complicated conditionals, we will unconditionally add dependency
32+
# on all platform signals which are included in platform_signal_table.h.
33+
# Ultimately, only the relevent signal table will be used.
34+
.tables.linux_platform_signals
35+
.tables.minimal_platform_signals
36+
)
37+
1338
add_object_library(
1439
error_to_string
1540
HDRS
@@ -18,12 +43,11 @@ add_object_library(
1843
error_to_string.cpp
1944
DEPENDS
2045
.message_mapper
21-
libc.src.errno.errno
46+
.platform_errors
2247
libc.src.__support.CPP.span
2348
libc.src.__support.CPP.string_view
2449
libc.src.__support.CPP.stringstream
2550
libc.src.__support.integer_to_string
26-
libc.src.__support.StringUtil.tables.error_table
2751
)
2852

2953
add_object_library(
@@ -34,10 +58,10 @@ add_object_library(
3458
signal_to_string.cpp
3559
DEPENDS
3660
.message_mapper
61+
.platform_signals
3762
libc.include.signal
3863
libc.src.__support.CPP.span
3964
libc.src.__support.CPP.string_view
4065
libc.src.__support.CPP.stringstream
4166
libc.src.__support.integer_to_string
42-
libc.src.__support.StringUtil.tables.signal_table
4367
)

libc/src/__support/StringUtil/error_to_string.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,15 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
#include "src/__support/StringUtil/error_to_string.h"
9+
#include "error_to_string.h"
10+
#include "platform_errors.h"
1011

11-
#include "src/errno/libc_errno.h" // For error macros
12-
13-
#include "src/__support/CPP/array.h"
1412
#include "src/__support/CPP/span.h"
1513
#include "src/__support/CPP/string_view.h"
1614
#include "src/__support/CPP/stringstream.h"
1715
#include "src/__support/StringUtil/message_mapper.h"
1816
#include "src/__support/integer_to_string.h"
1917

20-
#include "src/__support/StringUtil/tables/error_table.h"
21-
2218
#include <stddef.h>
2319

2420
namespace __llvm_libc {

libc/src/__support/StringUtil/message_mapper.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
#include <stddef.h>
1616

1717
namespace __llvm_libc {
18-
namespace internal {
1918

2019
struct MsgMapping {
2120
int num;
@@ -99,7 +98,6 @@ constexpr MsgTable<N1 + N2> operator+(const MsgTable<N1> &t1,
9998
return res;
10099
}
101100

102-
} // namespace internal
103101
} // namespace __llvm_libc
104102

105103
#endif // LLVM_LIBC_SRC_SUPPORT_STRING_UTIL_MESSAGE_MAPPER_H
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//===-- The error table for the current platform ----------------*- C++ -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef LLVM_LIBC_SRC_SUPPORT_STRING_UTIL_PLATFORM_ERROR_TABLE_H
10+
#define LLVM_LIBC_SRC_SUPPORT_STRING_UTIL_PLATFORM_ERROR_TABLE_H
11+
12+
#if defined(__linux__) || defined(__Fuchsia__)
13+
#include "tables/linux_platform_errors.h"
14+
#else
15+
#include "tables/minimal_platform_errors.h"
16+
#endif
17+
18+
#endif // LLVM_LIBC_SRC_SUPPORT_STRING_UTIL_PLATFORM_ERROR_TABLE_H
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//===-- The signal table for the current platform ---------------*- C++ -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef LLVM_LIBC_SRC_SUPPORT_STRING_UTIL_PLATFORM_SIGNAL_TABLE_H
10+
#define LLVM_LIBC_SRC_SUPPORT_STRING_UTIL_PLATFORM_SIGNAL_TABLE_H
11+
12+
#if defined(__linux__) || defined(__Fuchsia__)
13+
#include "tables/linux_platform_signals.h"
14+
#else
15+
#include "tables/minimal_platform_signals.h"
16+
#endif
17+
18+
#endif // LLVM_LIBC_SRC_SUPPORT_STRING_UTIL_PLATFORM_SIGNAL_TABLE_H

libc/src/__support/StringUtil/signal_to_string.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
#include "src/__support/StringUtil/signal_to_string.h"
9+
#include "signal_to_string.h"
10+
#include "platform_signals.h"
1011

1112
#include "src/__support/CPP/span.h"
1213
#include "src/__support/CPP/string_view.h"
1314
#include "src/__support/CPP/stringstream.h"
1415
#include "src/__support/StringUtil/message_mapper.h"
15-
#include "src/__support/StringUtil/tables/signal_table.h"
1616
#include "src/__support/integer_to_string.h"
1717

1818
#include <signal.h>
Lines changed: 77 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,89 @@
1-
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${LIBC_TARGET_OS})
2-
add_subdirectory(${LIBC_TARGET_OS})
3-
endif()
1+
add_header_library(
2+
stdc_errors
3+
HDRS
4+
stdc_errors.h
5+
DEPENDS
6+
libc.include.errno
7+
libc.src.__support.StringUtil.message_mapper
8+
)
49

5-
set(error_to_string_platform_dep "")
6-
if(TARGET libc.src.__support.StringUtil.tables.${LIBC_TARGET_OS}.error_table)
7-
set(error_to_string_platform_dep
8-
libc.src.__support.StringUtil.tables.${LIBC_TARGET_OS}.error_table)
9-
endif()
10+
add_header_library(
11+
posix_errors
12+
HDRS
13+
posix_errors.h
14+
DEPENDS
15+
libc.include.errno
16+
libc.src.__support.StringUtil.message_mapper
17+
)
1018

1119
add_header_library(
12-
error_table
20+
linux_extension_errors
1321
HDRS
14-
error_table.h
15-
stdc_error_table.h
16-
posix_error_table.h
22+
linux_extension_errors.h
1723
DEPENDS
18-
${error_to_string_platform_dep}
24+
libc.include.errno
25+
libc.src.__support.StringUtil.message_mapper
1926
)
2027

21-
set(signal_to_string_platform_dep "")
22-
if(TARGET libc.src.__support.StringUtil.tables.${LIBC_TARGET_OS}.signal_table)
23-
set(signal_to_string_platform_dep
24-
libc.src.__support.StringUtil.tables.${LIBC_TARGET_OS}.signal_table)
25-
endif()
28+
add_header_library(
29+
linux_platform_errors
30+
HDRS
31+
linux_platform_errors
32+
DEPENDS
33+
.linux_extension_errors
34+
.posix_errors
35+
.stdc_errors
36+
)
37+
38+
add_header_library(
39+
minimal_platform_errors
40+
HDRS
41+
minimal_platform_errors
42+
DEPENDS
43+
.stdc_errors
44+
)
45+
46+
add_header_library(
47+
stdc_signals
48+
HDRS
49+
stdc_signals.h
50+
DEPENDS
51+
libc.include.signal
52+
libc.src.__support.StringUtil.message_mapper
53+
)
54+
55+
add_header_library(
56+
posix_signals
57+
HDRS
58+
posix_signals.h
59+
DEPENDS
60+
libc.include.signal
61+
libc.src.__support.StringUtil.message_mapper
62+
)
63+
64+
add_header_library(
65+
linux_extension_signals
66+
HDRS
67+
linux_extension_signals.h
68+
DEPENDS
69+
libc.include.signal
70+
libc.src.__support.StringUtil.message_mapper
71+
)
72+
73+
add_header_library(
74+
linux_platform_signals
75+
HDRS
76+
linux_platform_signals
77+
DEPENDS
78+
.linux_extension_signals
79+
.posix_signals
80+
.stdc_signals
81+
)
2682

2783
add_header_library(
28-
signal_table
84+
minimal_platform_signals
2985
HDRS
30-
signal_table.h
31-
stdc_signal_table.h
32-
posix_signal_table.h
86+
minimal_platform_signals
3387
DEPENDS
34-
${signal_to_string_platform_dep}
88+
.stdc_signals
3589
)

libc/src/__support/StringUtil/tables/error_table.h

Lines changed: 0 additions & 39 deletions
This file was deleted.

libc/src/__support/StringUtil/tables/linux/CMakeLists.txt

Lines changed: 0 additions & 17 deletions
This file was deleted.

libc/src/__support/StringUtil/tables/linux/error_table.h renamed to libc/src/__support/StringUtil/tables/linux_extension_errors.h

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
1-
//===-- Map from error numbers to strings on linux --------------*- C++ -*-===//
1+
//===-- Map of Linux extension error numbers to strings ---------*- C++ -*-===//
22
//
33
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44
// See https://llvm.org/LICENSE.txt for license information.
55
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
66
//
77
//===----------------------------------------------------------------------===//
88

9-
#ifndef LLVM_LIBC_SRC_SUPPORT_STRING_UTIL_TABLES_LINUX_ERROR_TABLE_H
10-
#define LLVM_LIBC_SRC_SUPPORT_STRING_UTIL_TABLES_LINUX_ERROR_TABLE_H
9+
#ifndef LLVM_LIBC_SRC_SUPPORT_STRING_UTIL_TABLES_LINUX_EXTENSION_ERRORS_H
10+
#define LLVM_LIBC_SRC_SUPPORT_STRING_UTIL_TABLES_LINUX_EXTENSION_ERRORS_H
1111

12-
#include "src/errno/libc_errno.h" // For error macros
13-
14-
#include "src/__support/CPP/array.h"
1512
#include "src/__support/StringUtil/message_mapper.h"
1613

17-
namespace __llvm_libc::internal {
14+
#include <errno.h> // For error macros
15+
16+
namespace __llvm_libc {
1817

1918
constexpr MsgTable<52> LINUX_ERRORS = {
2019
MsgMapping(ENOTBLK, "Block device required"),
@@ -71,6 +70,6 @@ constexpr MsgTable<52> LINUX_ERRORS = {
7170
MsgMapping(EHWPOISON, "Memory page has hardware error"),
7271
};
7372

74-
} // namespace __llvm_libc::internal
73+
} // namespace __llvm_libc
7574

76-
#endif // LLVM_LIBC_SRC_SUPPORT_STRING_UTIL_TABLES_LINUX_ERROR_TABLE_H
75+
#endif // LLVM_LIBC_SRC_SUPPORT_STRING_UTIL_TABLES_LINUX_EXTENSION_ERRORS_H
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
//===-- Map from signal numbers to strings on linux -------------*- C++ -*-===//
1+
//===-- Map of Linux extension signal numbers to strings --------*- C++ -*-===//
22
//
33
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44
// See https://llvm.org/LICENSE.txt for license information.
55
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
66
//
77
//===----------------------------------------------------------------------===//
88

9-
#ifndef LLVM_LIBC_SRC_SUPPORT_STRING_UTIL_TABLES_LINUX_SIGNAL_TABLE_H
10-
#define LLVM_LIBC_SRC_SUPPORT_STRING_UTIL_TABLES_LINUX_SIGNAL_TABLE_H
11-
12-
#include <signal.h>
9+
#ifndef LLVM_LIBC_SRC_SUPPORT_STRING_UTIL_TABLES_LINUX_EXTENSION_SIGNALS_H
10+
#define LLVM_LIBC_SRC_SUPPORT_STRING_UTIL_TABLES_LINUX_EXTENSION_SIGNALS_H
1311

1412
#include "src/__support/StringUtil/message_mapper.h"
1513

16-
namespace __llvm_libc::internal {
14+
#include <signal.h> // For signal numbers
15+
16+
namespace __llvm_libc {
1717

1818
// The array being larger than necessary isn't a problem. The MsgMappings will
1919
// 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 = {
2828
#endif
2929
};
3030

31-
} // namespace __llvm_libc::internal
31+
} // namespace __llvm_libc
3232

33-
#endif // LLVM_LIBC_SRC_SUPPORT_STRING_UTIL_TABLES_LINUX_SIGNAL_TABLE_H
33+
#endif // LLVM_LIBC_SRC_SUPPORT_STRING_UTIL_TABLES_LINUX_EXTENSION_SIGNALS_H

0 commit comments

Comments
 (0)