summaryrefslogtreecommitdiff
path: root/libc/utils
diff options
context:
space:
mode:
authorMichael Kruse <llvm-project@meinersbur.de>2025-01-03 10:22:51 +0100
committerMichael Kruse <llvm-project@meinersbur.de>2025-01-03 10:22:51 +0100
commit38500d63e14ce340236840f60d356cdefb56a52c (patch)
tree17edbec446ce9b50d2f215a483b83afb293a635d /libc/utils
parent1a3d5daaef7a6a63448a497da3eff7fc9e23df26 (diff)
parent27f30029741ecf023baece7b3dde1ff9011ffefc (diff)
Merge branch 'main' into users/meinersbur/flang_runtime_split-headersusers/meinersbur/flang_runtime_split-headers
Diffstat (limited to 'libc/utils')
-rw-r--r--libc/utils/CMakeLists.txt2
-rw-r--r--libc/utils/MPFRWrapper/MPFRUtils.cpp102
-rw-r--r--libc/utils/docgen/arpa/inet.yaml18
-rw-r--r--libc/utils/docgen/assert.yaml7
-rw-r--r--libc/utils/docgen/ctype.json47
-rw-r--r--libc/utils/docgen/ctype.yaml72
-rwxr-xr-xlibc/utils/docgen/docgen.py70
-rw-r--r--libc/utils/docgen/errno.yaml14
-rw-r--r--libc/utils/docgen/fenv.json114
-rw-r--r--libc/utils/docgen/fenv.yaml97
-rw-r--r--libc/utils/docgen/float.yaml143
-rw-r--r--libc/utils/docgen/header.py11
-rw-r--r--libc/utils/docgen/inttypes.yaml20
-rw-r--r--libc/utils/docgen/locale.yaml37
-rw-r--r--libc/utils/docgen/setjmp.json15
-rw-r--r--libc/utils/docgen/setjmp.yaml15
-rw-r--r--libc/utils/docgen/signal.json152
-rw-r--r--libc/utils/docgen/signal.yaml102
-rw-r--r--libc/utils/docgen/stdbit.json270
-rw-r--r--libc/utils/docgen/stdbit.yaml179
-rw-r--r--libc/utils/docgen/stdio.yaml226
-rw-r--r--libc/utils/docgen/stdlib.yaml158
-rw-r--r--libc/utils/docgen/string.yaml94
-rw-r--r--libc/utils/docgen/sys/mman.yaml77
-rw-r--r--libc/utils/docgen/threads.json87
-rw-r--r--libc/utils/docgen/threads.yaml88
-rw-r--r--libc/utils/docgen/uchar.yaml21
-rw-r--r--libc/utils/docgen/wchar.yaml131
-rw-r--r--libc/utils/docgen/wctype.yaml36
-rw-r--r--libc/utils/gpu/loader/Loader.h4
-rw-r--r--libc/utils/gpu/server/CMakeLists.txt5
-rw-r--r--libc/utils/gpu/server/rpc_server.cpp6
-rw-r--r--libc/utils/hdrgen/CMakeLists.txt17
-rw-r--r--libc/utils/hdrgen/README.rst5
-rw-r--r--libc/utils/hdrgen/enumeration.py19
-rw-r--r--libc/utils/hdrgen/function.py30
-rw-r--r--libc/utils/hdrgen/gpu_headers.py53
-rw-r--r--libc/utils/hdrgen/header.py85
-rw-r--r--libc/utils/hdrgen/macro.py19
-rw-r--r--libc/utils/hdrgen/object.py16
-rw-r--r--libc/utils/hdrgen/tests/expected_output/test_header.h52
-rw-r--r--libc/utils/hdrgen/tests/input/test_small.h.def19
-rw-r--r--libc/utils/hdrgen/tests/input/test_small.yaml66
-rw-r--r--libc/utils/hdrgen/tests/test_integration.py81
-rw-r--r--libc/utils/hdrgen/type.py15
-rw-r--r--libc/utils/hdrgen/yaml_functions_sorted.py39
-rw-r--r--libc/utils/hdrgen/yaml_to_classes.py283
47 files changed, 2499 insertions, 720 deletions
diff --git a/libc/utils/CMakeLists.txt b/libc/utils/CMakeLists.txt
index 11f25503cc13..a33c13a045a8 100644
--- a/libc/utils/CMakeLists.txt
+++ b/libc/utils/CMakeLists.txt
@@ -1,3 +1,5 @@
+add_subdirectory(hdrgen)
+
if(LLVM_INCLUDE_TESTS)
add_subdirectory(MPFRWrapper)
endif()
diff --git a/libc/utils/MPFRWrapper/MPFRUtils.cpp b/libc/utils/MPFRWrapper/MPFRUtils.cpp
index 00592c5cb15f..0dac497bb779 100644
--- a/libc/utils/MPFRWrapper/MPFRUtils.cpp
+++ b/libc/utils/MPFRWrapper/MPFRUtils.cpp
@@ -22,6 +22,13 @@
#include "mpfr_inc.h"
+#ifdef LIBC_TYPES_FLOAT128_IS_NOT_LONG_DOUBLE
+extern "C" {
+int mpfr_set_float128(mpfr_ptr, float128, mpfr_rnd_t);
+float128 mpfr_get_float128(mpfr_srcptr, mpfr_rnd_t);
+}
+#endif
+
template <typename T> using FPBits = LIBC_NAMESPACE::fputil::FPBits<T>;
namespace LIBC_NAMESPACE_DECL {
@@ -47,8 +54,18 @@ template <> struct ExtraPrecision<double> {
};
template <> struct ExtraPrecision<long double> {
+#ifdef LIBC_TYPES_LONG_DOUBLE_IS_FLOAT128
+ static constexpr unsigned int VALUE = 512;
+#else
static constexpr unsigned int VALUE = 256;
+#endif
+};
+
+#if defined(LIBC_TYPES_FLOAT128_IS_NOT_LONG_DOUBLE)
+template <> struct ExtraPrecision<float128> {
+ static constexpr unsigned int VALUE = 512;
};
+#endif // LIBC_TYPES_FLOAT128_IS_NOT_LONG_DOUBLE
// If the ulp tolerance is less than or equal to 0.5, we would check that the
// result is rounded correctly with respect to the rounding mode by using the
@@ -134,6 +151,19 @@ public:
mpfr_set_ld(value, x, mpfr_rounding);
}
+#ifdef LIBC_TYPES_FLOAT128_IS_NOT_LONG_DOUBLE
+ template <typename XType,
+ cpp::enable_if_t<cpp::is_same_v<float128, XType>, int> = 0>
+ explicit MPFRNumber(XType x,
+ unsigned int precision = ExtraPrecision<XType>::VALUE,
+ RoundingMode rounding = RoundingMode::Nearest)
+ : mpfr_precision(precision),
+ mpfr_rounding(get_mpfr_rounding_mode(rounding)) {
+ mpfr_init2(value, mpfr_precision);
+ mpfr_set_float128(value, x, mpfr_rounding);
+ }
+#endif // LIBC_TYPES_FLOAT128_IS_NOT_LONG_DOUBLE
+
template <typename XType,
cpp::enable_if_t<cpp::is_integral_v<XType>, int> = 0>
explicit MPFRNumber(XType x,
@@ -647,7 +677,7 @@ public:
// These functions are useful for debugging.
template <typename T> T as() const;
- void dump(const char *msg) const { mpfr_printf("%s%.128Rf\n", msg, value); }
+ void dump(const char *msg) const { mpfr_printf("%s%.128g\n", msg, value); }
// Return the ULP (units-in-the-last-place) difference between the
// stored MPFR and a floating point number.
@@ -770,6 +800,13 @@ template <> float16 MPFRNumber::as<float16>() const {
}
#endif
+#ifdef LIBC_TYPES_FLOAT128_IS_NOT_LONG_DOUBLE
+template <> float128 MPFRNumber::as<float128>() const {
+ return mpfr_get_float128(value, mpfr_rounding);
+}
+
+#endif // LIBC_TYPES_FLOAT128_IS_NOT_LONG_DOUBLE
+
namespace internal {
template <typename InputType>
@@ -997,7 +1034,27 @@ template void explain_unary_operation_single_output_error(Operation op, double,
template void explain_unary_operation_single_output_error(Operation op,
long double, float16,
double, RoundingMode);
-#endif
+#ifdef LIBC_TYPES_FLOAT128_IS_NOT_LONG_DOUBLE
+template void explain_unary_operation_single_output_error(Operation op,
+ float128, float16,
+ double, RoundingMode);
+#endif // LIBC_TYPES_FLOAT128_IS_NOT_LONG_DOUBLE
+#endif // LIBC_TYPES_HAS_FLOAT16
+
+#ifdef LIBC_TYPES_FLOAT128_IS_NOT_LONG_DOUBLE
+template void explain_unary_operation_single_output_error(Operation op,
+ float128, float128,
+ double, RoundingMode);
+template void explain_unary_operation_single_output_error(Operation op,
+ float128, float,
+ double, RoundingMode);
+template void explain_unary_operation_single_output_error(Operation op,
+ float128, double,
+ double, RoundingMode);
+template void explain_unary_operation_single_output_error(Operation op,
+ float128, long double,
+ double, RoundingMode);
+#endif // LIBC_TYPES_FLOAT128_IS_NOT_LONG_DOUBLE
template <typename T>
void explain_unary_operation_two_outputs_error(
@@ -1228,7 +1285,25 @@ template bool compare_unary_operation_single_output(Operation, double, float16,
template bool compare_unary_operation_single_output(Operation, long double,
float16, double,
RoundingMode);
-#endif
+#ifdef LIBC_TYPES_FLOAT128_IS_NOT_LONG_DOUBLE
+template bool compare_unary_operation_single_output(Operation, float128,
+ float16, double,
+ RoundingMode);
+#endif // LIBC_TYPES_FLOAT128_IS_NOT_LONG_DOUBLE
+#endif // LIBC_TYPES_HAS_FLOAT16
+
+#ifdef LIBC_TYPES_FLOAT128_IS_NOT_LONG_DOUBLE
+template bool compare_unary_operation_single_output(Operation, float128,
+ float128, double,
+ RoundingMode);
+template bool compare_unary_operation_single_output(Operation, float128, float,
+ double, RoundingMode);
+template bool compare_unary_operation_single_output(Operation, float128, double,
+ double, RoundingMode);
+template bool compare_unary_operation_single_output(Operation, float128,
+ long double, double,
+ RoundingMode);
+#endif // LIBC_TYPES_FLOAT128_IS_NOT_LONG_DOUBLE
template <typename T>
bool compare_unary_operation_two_outputs(Operation op, T input,
@@ -1398,9 +1473,14 @@ template <typename T> bool round_to_long(T x, long &result) {
template bool round_to_long<float>(float, long &);
template bool round_to_long<double>(double, long &);
template bool round_to_long<long double>(long double, long &);
+
#ifdef LIBC_TYPES_HAS_FLOAT16
template bool round_to_long<float16>(float16, long &);
-#endif
+#endif // LIBC_TYPES_HAS_FLOAT16
+
+#ifdef LIBC_TYPES_FLOAT128_IS_NOT_LONG_DOUBLE
+template bool round_to_long<float128>(float128, long &);
+#endif // LIBC_TYPES_FLOAT128_IS_NOT_LONG_DOUBLE
template <typename T> bool round_to_long(T x, RoundingMode mode, long &result) {
MPFRNumber mpfr(x);
@@ -1410,9 +1490,14 @@ template <typename T> bool round_to_long(T x, RoundingMode mode, long &result) {
template bool round_to_long<float>(float, RoundingMode, long &);
template bool round_to_long<double>(double, RoundingMode, long &);
template bool round_to_long<long double>(long double, RoundingMode, long &);
+
#ifdef LIBC_TYPES_HAS_FLOAT16
template bool round_to_long<float16>(float16, RoundingMode, long &);
-#endif
+#endif // LIBC_TYPES_HAS_FLOAT16
+
+#ifdef LIBC_TYPES_FLOAT128_IS_NOT_LONG_DOUBLE
+template bool round_to_long<float128>(float128, RoundingMode, long &);
+#endif // LIBC_TYPES_FLOAT128_IS_NOT_LONG_DOUBLE
template <typename T> T round(T x, RoundingMode mode) {
MPFRNumber mpfr(x);
@@ -1423,9 +1508,14 @@ template <typename T> T round(T x, RoundingMode mode) {
template float round<float>(float, RoundingMode);
template double round<double>(double, RoundingMode);
template long double round<long double>(long double, RoundingMode);
+
#ifdef LIBC_TYPES_HAS_FLOAT16
template float16 round<float16>(float16, RoundingMode);
-#endif
+#endif // LIBC_TYPES_HAS_FLOAT16
+
+#ifdef LIBC_TYPES_FLOAT128_IS_NOT_LONG_DOUBLE
+template float128 round<float128>(float128, RoundingMode);
+#endif // LIBC_TYPES_FLOAT128_IS_NOT_LONG_DOUBLE
} // namespace mpfr
} // namespace testing
diff --git a/libc/utils/docgen/arpa/inet.yaml b/libc/utils/docgen/arpa/inet.yaml
new file mode 100644
index 000000000000..7f388cbbd020
--- /dev/null
+++ b/libc/utils/docgen/arpa/inet.yaml
@@ -0,0 +1,18 @@
+functions:
+ htonl:
+ posix-definition: ''
+ htons:
+ posix-definition: ''
+ inet_addr:
+ posix-definition: ''
+ inet_ntoa:
+ posix-definition: ''
+ inet_ntop:
+ posix-definition: ''
+ inet_pton:
+ posix-definition: ''
+ ntohl:
+ posix-definition: ''
+ ntohs:
+ posix-definition: ''
+
diff --git a/libc/utils/docgen/assert.yaml b/libc/utils/docgen/assert.yaml
new file mode 100644
index 000000000000..0afd4e2d3c06
--- /dev/null
+++ b/libc/utils/docgen/assert.yaml
@@ -0,0 +1,7 @@
+macros:
+ __STDC_VERSION_ASSERT_H__:
+ c-definition: 7.2.1
+ assert:
+ c-definition: 7.2.1
+ in-latest-posix: ''
+
diff --git a/libc/utils/docgen/ctype.json b/libc/utils/docgen/ctype.json
deleted file mode 100644
index af97e4bbbc0a..000000000000
--- a/libc/utils/docgen/ctype.json
+++ /dev/null
@@ -1,47 +0,0 @@
-{
- "functions": {
- "isalnum": {
- "c-definition": "7.4.1.1"
- },
- "isalpha": {
- "c-definition": "7.4.1.2"
- },
- "isblank": {
- "c-definition": "7.4.1.3"
- },
- "iscntrl": {
- "c-definition": "7.4.1.4"
- },
- "isdigit": {
- "c-definition": "7.4.1.5"
- },
- "isgraph": {
- "c-definition": "7.4.1.6"
- },
- "islower": {
- "c-definition": "7.4.1.7"
- },
- "isprint": {
- "c-definition": "7.4.1.8"
- },
- "ispunct": {
- "c-definition": "7.4.1.9"
- },
- "isspace": {
- "c-definition": "7.4.1.10"
- },
- "isupper": {
- "c-definition": "7.4.1.11"
- },
- "isxdigit": {
- "c-definition": "7.4.1.12"
- },
- "tolower" : {
- "c-definition": "7.4.2.1"
- },
- "toupper": {
- "c-definition": "7.4.2.2"
- }
- }
-}
-
diff --git a/libc/utils/docgen/ctype.yaml b/libc/utils/docgen/ctype.yaml
new file mode 100644
index 000000000000..027d8f38c71f
--- /dev/null
+++ b/libc/utils/docgen/ctype.yaml
@@ -0,0 +1,72 @@
+functions:
+ isalnum:
+ c-definition: 7.4.1.1
+ in-latest-posix: ''
+ isalnum_l:
+ in-latest-posix: ''
+ isalpha:
+ c-definition: 7.4.1.2
+ in-latest-posix: ''
+ isalpha_l:
+ in-latest-posix: ''
+ isblank:
+ c-definition: 7.4.1.3
+ in-latest-posix: ''
+ isblank_l:
+ in-latest-posix: ''
+ iscntrl:
+ c-definition: 7.4.1.4
+ in-latest-posix: ''
+ iscntrl_l:
+ in-latest-posix: ''
+ isdigit:
+ c-definition: 7.4.1.5
+ in-latest-posix: ''
+ isdigit_l:
+ in-latest-posix: ''
+ isgraph:
+ c-definition: 7.4.1.6
+ in-latest-posix: ''
+ isgraph_l:
+ in-latest-posix: ''
+ islower:
+ c-definition: 7.4.1.7
+ in-latest-posix: ''
+ islower_l:
+ in-latest-posix: ''
+ isprint:
+ c-definition: 7.4.1.8
+ in-latest-posix: ''
+ isprint_l:
+ in-latest-posix: ''
+ ispunct:
+ c-definition: 7.4.1.9
+ in-latest-posix: ''
+ ispunct_l:
+ in-latest-posix: ''
+ isspace:
+ c-definition: 7.4.1.10
+ in-latest-posix: ''
+ isspace_l:
+ in-latest-posix: ''
+ isupper:
+ c-definition: 7.4.1.11
+ in-latest-posix: ''
+ isupper_l:
+ in-latest-posix: ''
+ isxdigit:
+ c-definition: 7.4.1.12
+ in-latest-posix: ''
+ isxdigit_l:
+ in-latest-posix: ''
+ tolower:
+ c-definition: 7.4.2.1
+ in-latest-posix: ''
+ tolower_l:
+ in-latest-posix: ''
+ toupper:
+ c-definition: 7.4.2.2
+ in-latest-posix: ''
+ toupper_l:
+ in-latest-posix: ''
+
diff --git a/libc/utils/docgen/docgen.py b/libc/utils/docgen/docgen.py
index af5d00a5cbf8..09db284ef928 100755
--- a/libc/utils/docgen/docgen.py
+++ b/libc/utils/docgen/docgen.py
@@ -10,8 +10,9 @@
from argparse import ArgumentParser, Namespace
from pathlib import Path
from typing import Dict
+import os
import sys
-import json
+import yaml
from header import Header
@@ -22,14 +23,14 @@ class DocgenAPIFormatError(Exception):
def check_api(header: Header, api: Dict):
"""
- Checks that docgen json files are properly formatted. If there are any
+ Checks that docgen yaml files are properly formatted. If there are any
fatal formatting errors, raises exceptions with error messages useful for
fixing formatting. Warnings are printed to stderr on non-fatal formatting
errors. The code that runs after ``check_api(api)`` is called expects that
- ``check_api`` executed without raising formatting exceptions so the json
+ ``check_api`` executed without raising formatting exceptions so the yaml
matches the formatting specified here.
- The json file may contain:
+ The yaml file may contain:
* an optional macros object
* an optional functions object
@@ -48,11 +49,15 @@ def check_api(header: Header, api: Dict):
this should be a C standard section number. For the ``"posix-definition"`` property,
this should be a link to the definition.
- :param api: docgen json file contents parsed into a dict
+ :param api: docgen yaml file contents parsed into a dict
"""
errors = []
- cdef = "c-definition"
- pdef = "posix-definition"
+ # We require entries to have at least one of these.
+ possible_keys = [
+ "c-definition",
+ "in-latest-posix",
+ "removed-in-posix-2008",
+ ]
# Validate macros
if "macros" in api:
@@ -65,8 +70,8 @@ def check_api(header: Header, api: Dict):
macros = api["macros"]
for name, obj in macros.items():
- if not (cdef in obj or pdef in obj):
- err = f'error: Macro {name} does not contain at least one required property: "{cdef}" or "{pdef}"'
+ if not any(k in obj for k in possible_keys):
+ err = f"error: Macro {name} does not contain at least one required property: {possible_keys}"
errors.append(err)
# Validate functions
@@ -79,8 +84,8 @@ def check_api(header: Header, api: Dict):
fns = api["functions"]
for name, obj in fns.items():
- if not (cdef in obj or pdef in obj):
- err = f'error: function {name} does not contain at least one required property: "{cdef}" or "{pdef}"'
+ if not any(k in obj for k in possible_keys):
+ err = f"error: function {name} does not contain at least one required property: {possible_keys}"
errors.append(err)
if errors:
@@ -88,8 +93,8 @@ def check_api(header: Header, api: Dict):
def load_api(header: Header) -> Dict:
- api = header.docgen_json.read_text(encoding="utf-8")
- return json.loads(api)
+ api = header.docgen_yaml.read_text(encoding="utf-8")
+ return yaml.safe_load(api)
def print_tbl_dir(name):
@@ -103,7 +108,7 @@ def print_tbl_dir(name):
* - {name}
- Implemented
- C23 Standard Section
- - POSIX.1-2017 Standard Section"""
+ - POSIX Docs"""
)
@@ -127,8 +132,14 @@ def print_functions_rst(header: Header, functions: Dict):
else:
print(" -")
- if "posix-definition" in functions[name]:
- print(f' - {functions[name]["posix-definition"]}')
+ if "in-latest-posix" in functions[name]:
+ print(
+ f" - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/{name}.html>`__"
+ )
+ elif "removed-in-posix-2008" in functions[name]:
+ print(
+ f" - `removed in POSIX.1-2008 <https://pubs.opengroup.org/onlinepubs/007904875/functions/{name}.html>`__"
+ )
else:
print(" -")
@@ -153,15 +164,20 @@ def print_macros_rst(header: Header, macros: Dict):
else:
print(" -")
- if "posix-definition" in macros[name]:
- print(f' - {macros[name]["posix-definition"]}')
+ if "in-latest-posix" in macros[name]:
+ print(
+ f" - `POSIX.1-2024 <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/{header.name}.html>`__"
+ )
else:
print(" -")
print()
def print_impl_status_rst(header: Header, api: Dict):
- print(".. include:: check.rst\n")
+ if os.sep in header.name:
+ print(".. include:: ../../check.rst\n")
+ else:
+ print(".. include:: ../check.rst\n")
print("=" * len(header.name))
print(header.name)
@@ -176,10 +192,22 @@ def print_impl_status_rst(header: Header, api: Dict):
print_functions_rst(header, api["functions"])
+# This code implicitly relies on docgen.py being in the same dir as the yaml
+# files and is likely to need to be fixed when re-integrating docgen into
+# hdrgen.
+def get_choices() -> list:
+ choices = []
+ for path in Path(__file__).parent.rglob("*.yaml"):
+ fname = path.with_suffix(".h").name
+ if path.parent != Path(__file__).parent:
+ fname = path.parent.name + os.sep + fname
+ choices.append(fname)
+ return choices
+
+
def parse_args() -> Namespace:
parser = ArgumentParser()
- choices = [p.with_suffix(".h").name for p in Path(__file__).parent.glob("*.json")]
- parser.add_argument("header_name", choices=choices)
+ parser.add_argument("header_name", choices=get_choices())
return parser.parse_args()
diff --git a/libc/utils/docgen/errno.yaml b/libc/utils/docgen/errno.yaml
new file mode 100644
index 000000000000..da41552bc3a1
--- /dev/null
+++ b/libc/utils/docgen/errno.yaml
@@ -0,0 +1,14 @@
+macros:
+ EDOM:
+ c-definition: '7.5'
+ in-latest-posix: ''
+ EILSEQ:
+ c-definition: '7.5'
+ in-latest-posix: ''
+ ERANGE:
+ c-definition: '7.5'
+ in-latest-posix: ''
+ errno:
+ c-definition: '7.5'
+ in-latest-posix: ''
+
diff --git a/libc/utils/docgen/fenv.json b/libc/utils/docgen/fenv.json
deleted file mode 100644
index 788b196c053b..000000000000
--- a/libc/utils/docgen/fenv.json
+++ /dev/null
@@ -1,114 +0,0 @@
-{
- "macros": {
- "__STDC_VERSION_FENV_H__": {
- "c-definition": "7.6.5"
- },
- "FE_DIVBYZERO": {
- "c-definition": "7.6.9"
- },
- "FE_INEXACT": {
- "c-definition": "7.6.9"
- },
- "FE_INVALID": {
- "c-definition": "7.6.9"
- },
- "FE_OVERFLOW": {
- "c-definition": "7.6.9"
- },
- "FE_UNDERFLOW": {
- "c-definition": "7.6.9"
- },
- "FE_ALL_EXCEPT": {
- "c-definition": "7.6.12"
- },
- "FE_DFL_MODE": {
- "c-definition": "7.6.11"
- },
- "FE_DOWNARD": {
- "c-definition": "7.6.13"
- },
- "FE_TONEAREST": {
- "c-definition": "7.6.13"
- },
- "FE_TONEARESTFROMZERO": {
- "c-definition": "7.6.13"
- },
- "FE_TOWARDZERO": {
- "c-definition": "7.6.13"
- },
- "FE_UPWARD": {
- "c-definition": "7.6.13"
- },
- "FE_DEC_DOWNWARD": {
- "c-definition": "7.6.14"
- },
- "FE_DEC_TONEAREST": {
- "c-definition": "7.6.14"
- },
- "FE_DEC_TONEARESTFROMZERO": {
- "c-definition": "7.6.14"
- },
- "FE_DEC_TOWARDZERO": {
- "c-definition": "7.6.14"
- },
- "FE_DEC_UPWARD": {
- "c-definition": "7.6.14"
- },
- "FE_DFL_ENV": {
- "c-definition": "7.6.17"
- }
- },
- "functions": {
- "feclearexcept": {
- "c-definition": "7.6.4.1"
- },
- "fegetexceptflag": {
- "c-definition": "7.6.4.2"
- },
- "feraiseexcept": {
- "c-definition": "7.6.4.3"
- },
- "fesetexcept": {
- "c-definition": "7.6.4.4"
- },
- "fesetexceptflag": {
- "c-definition": "7.6.4.5"
- },
- "fetestexceptflag": {
- "c-definition": "7.6.4.6"
- },
- "fetestexcept": {
- "c-definition": "7.6.4.7"
- },
- "fegetmode": {
- "c-definition": "7.6.5.1"
- },
- "fegetround": {
- "c-definition": "7.6.5.2"
- },
- "fe_dec_getround": {
- "c-definition": "7.6.5.3"
- },
- "fesetmode": {
- "c-definition": "7.6.5.4"
- },
- "fesetround": {
- "c-definition": "7.6.5.5"
- },
- "fe_dec_setround": {
- "c-definition": "7.6.5.6"
- },
- "fegetenv": {
- "c-definition": "7.6.6.1"
- },
- "feholdexcept": {
- "c-definition": "7.6.6.2"
- },
- "fesetenv": {
- "c-definition": "7.6.6.3"
- },
- "feupdateenv": {
- "c-definition": "7.6.6.4"
- }
- }
-}
diff --git a/libc/utils/docgen/fenv.yaml b/libc/utils/docgen/fenv.yaml
new file mode 100644
index 000000000000..1d73697f36be
--- /dev/null
+++ b/libc/utils/docgen/fenv.yaml
@@ -0,0 +1,97 @@
+functions:
+ fe_dec_getround:
+ c-definition: 7.6.5.3
+ fe_dec_setround:
+ c-definition: 7.6.5.6
+ feclearexcept:
+ c-definition: 7.6.4.1
+ in-latest-posix: ''
+ fegetenv:
+ c-definition: 7.6.6.1
+ in-latest-posix: ''
+ fegetexceptflag:
+ c-definition: 7.6.4.2
+ in-latest-posix: ''
+ fegetmode:
+ c-definition: 7.6.5.1
+ fegetround:
+ c-definition: 7.6.5.2
+ in-latest-posix: ''
+ feholdexcept:
+ c-definition: 7.6.6.2
+ in-latest-posix: ''
+ feraiseexcept:
+ c-definition: 7.6.4.3
+ in-latest-posix: ''
+ fesetenv:
+ c-definition: 7.6.6.3
+ in-latest-posix: ''
+ fesetexcept:
+ c-definition: 7.6.4.4
+ fesetexceptflag:
+ c-definition: 7.6.4.5
+ in-latest-posix: ''
+ fesetmode:
+ c-definition: 7.6.5.4
+ fesetround:
+ c-definition: 7.6.5.5
+ in-latest-posix: ''
+ fetestexcept:
+ c-definition: 7.6.4.7
+ in-latest-posix: ''
+ fetestexceptflag:
+ c-definition: 7.6.4.6
+ feupdateenv:
+ c-definition: 7.6.6.4
+ in-latest-posix: ''
+macros:
+ FE_ALL_EXCEPT:
+ c-definition: 7.6.12
+ in-latest-posix: ''
+ FE_DEC_DOWNWARD:
+ c-definition: 7.6.14
+ FE_DEC_TONEAREST:
+ c-definition: 7.6.14
+ FE_DEC_TONEARESTFROMZERO:
+ c-definition: 7.6.14
+ FE_DEC_TOWARDZERO:
+ c-definition: 7.6.14
+ FE_DEC_UPWARD:
+ c-definition: 7.6.14
+ FE_DFL_ENV:
+ c-definition: 7.6.17
+ in-latest-posix: ''
+ FE_DFL_MODE:
+ c-definition: 7.6.11
+ FE_DIVBYZERO:
+ c-definition: 7.6.9
+ in-latest-posix: ''
+ FE_DOWNWARD:
+ c-definition: 7.6.13
+ in-latest-posix: ''
+ FE_INEXACT:
+ c-definition: 7.6.9
+ in-latest-posix: ''
+ FE_INVALID:
+ c-definition: 7.6.9
+ in-latest-posix: ''
+ FE_OVERFLOW:
+ c-definition: 7.6.9
+ in-latest-posix: ''
+ FE_TONEAREST:
+ c-definition: 7.6.13
+ in-latest-posix: ''
+ FE_TONEARESTFROMZERO:
+ c-definition: 7.6.13
+ FE_TOWARDZERO:
+ c-definition: 7.6.13
+ in-latest-posix: ''
+ FE_UNDERFLOW:
+ c-definition: 7.6.9
+ in-latest-posix: ''
+ FE_UPWARD:
+ c-definition: 7.6.13
+ in-latest-posix: ''
+ __STDC_VERSION_FENV_H__:
+ c-definition: 7.6.5
+
diff --git a/libc/utils/docgen/float.yaml b/libc/utils/docgen/float.yaml
new file mode 100644
index 000000000000..a8840b91be55
--- /dev/null
+++ b/libc/utils/docgen/float.yaml
@@ -0,0 +1,143 @@
+macros:
+ DBL_DECIMAL_DIG:
+ c-definition: 5.3.5.3.3
+ in-latest-posix: ''
+ DBL_DIG:
+ c-definition: 5.3.5.3.3
+ in-latest-posix: ''
+ DBL_EPSILON:
+ c-definition: 5.3.5.3.3
+ in-latest-posix: ''
+ DBL_HAS_SUBNORM:
+ c-definition: 5.3.5.3.3
+ in-latest-posix: ''
+ DBL_IS_IEC_60559:
+ c-definition: 5.3.5.3.3
+ DBL_MANT_DIG:
+ c-definition: 5.3.5.3.3
+ DBL_MAX:
+ c-definition: 5.3.5.3.3
+ in-latest-posix: ''
+ DBL_MAX_10_EXP:
+ c-definition: 5.3.5.3.3
+ in-latest-posix: ''
+ DBL_MAX_EXP:
+ c-definition: 5.3.5.3.3
+ in-latest-posix: ''
+ DBL_MIN:
+ c-definition: 5.3.5.3.3
+ in-latest-posix: ''
+ DBL_MIN_10_EXP:
+ c-definition: 5.3.5.3.3
+ in-latest-posix: ''
+ DBL_MIN_EXP:
+ c-definition: 5.3.5.3.3
+ in-latest-posix: ''
+ DBL_NORM_MAX:
+ c-definition: 5.3.5.3.3
+ DBL_SNAN:
+ c-definition: 5.3.5.3.3
+ DBL_TRUE_MIN:
+ c-definition: 5.3.5.3.3
+ in-latest-posix: ''
+ DECIMAL_DIG:
+ c-definition: 5.3.5.3.3
+ in-latest-posix: ''
+ FLT_DECIMAL_DIG:
+ c-definition: 5.3.5.3.3
+ in-latest-posix: ''
+ FLT_DIG:
+ c-definition: 5.3.5.3.3
+ in-latest-posix: ''
+ FLT_EPSILON:
+ c-definition: 5.3.5.3.3
+ in-latest-posix: ''
+ FLT_EVAL_METHOD:
+ c-definition: 5.3.5.3.3
+ in-latest-posix: ''
+ FLT_HAS_SUBNORM:
+ c-definition: 5.3.5.3.3
+ in-latest-posix: ''
+ FLT_IS_IEC_60559:
+ c-definition: 5.3.5.3.3
+ FLT_MANT_DIG:
+ c-definition: 5.3.5.3.3
+ FLT_MAX:
+ c-definition: 5.3.5.3.3
+ in-latest-posix: ''
+ FLT_MAX_10_EXP:
+ c-definition: 5.3.5.3.3
+ in-latest-posix: ''
+ FLT_MAX_EXP:
+ c-definition: 5.3.5.3.3
+ in-latest-posix: ''
+ FLT_MIN:
+ c-definition: 5.3.5.3.3
+ in-latest-posix: ''
+ FLT_MIN_10_EXP:
+ c-definition: 5.3.5.3.3
+ in-latest-posix: ''
+ FLT_MIN_EXP:
+ c-definition: 5.3.5.3.3
+ in-latest-posix: ''
+ FLT_NORM_MAX:
+ c-definition: 5.3.5.3.3
+ FLT_RADIX:
+ c-definition: 5.3.5.3.3
+ in-latest-posix: ''
+ FLT_ROUNDS:
+ c-definition: 5.3.5.3.3
+ in-latest-posix: ''
+ FLT_SNAN:
+ c-definition: 5.3.5.3.3
+ FLT_TRUE_MIN:
+ c-definition: 5.3.5.3.3
+ in-latest-posix: ''
+ INFINITY:
+ c-definition: 5.3.5.3.3
+ LDBL_DECIMAL_DIG:
+ c-definition: 5.3.5.3.3
+ in-latest-posix: ''
+ LDBL_DIG:
+ c-definition: 5.3.5.3.3
+ in-latest-posix: ''
+ LDBL_EPSILON:
+ c-definition: 5.3.5.3.3
+ in-latest-posix: ''
+ LDBL_HAS_SUBNORM:
+ c-definition: 5.3.5.3.3
+ in-latest-posix: ''
+ LDBL_IS_IEC_60559:
+ c-definition: 5.3.5.3.3
+ LDBL_MANT_DIG:
+ c-definition: 5.3.5.3.3
+ LDBL_MAX:
+ c-definition: 5.3.5.3.3
+ in-latest-posix: ''
+ LDBL_MAX_10_EXP:
+ c-definition: 5.3.5.3.3
+ in-latest-posix: ''
+ LDBL_MAX_EXP:
+ c-definition: 5.3.5.3.3
+ in-latest-posix: ''
+ LDBL_MIN:
+ c-definition: 5.3.5.3.3
+ in-latest-posix: ''
+ LDBL_MIN_10_EXP:
+ c-definition: 5.3.5.3.3
+ in-latest-posix: ''
+ LDBL_MIN_EXP:
+ c-definition: 5.3.5.3.3
+ in-latest-posix: ''
+ LDBL_NORM_MAX:
+ c-definition: 5.3.5.3.3
+ LDBL_SNAN:
+ c-definition: 5.3.5.3.3
+ LDBL_TRUE_MIN:
+ c-definition: 5.3.5.3.3
+ in-latest-posix: ''
+ NAN:
+ c-definition: 5.3.5.3.3
+ __STDC_VERSION_FLOAT_H__:
+ c-definition: '7.7'
+
diff --git a/libc/utils/docgen/header.py b/libc/utils/docgen/header.py
index dde210078db2..5bf524a64b69 100644
--- a/libc/utils/docgen/header.py
+++ b/libc/utils/docgen/header.py
@@ -14,7 +14,7 @@ class Header:
Maintains implementation information about a standard header file:
* where does its implementation dir live
* where is its macros file
- * where is its docgen json file
+ * where is its docgen yaml file
By convention, the macro-only part of a header file is in a header-specific
file somewhere in the directory tree with root at
@@ -42,7 +42,7 @@ class Header:
self.stem = header_name.rstrip(".h")
self.docgen_root = Path(__file__).parent
self.libc_root = self.docgen_root.parent.parent
- self.docgen_json = self.docgen_root / Path(header_name).with_suffix(".json")
+ self.docgen_yaml = self.docgen_root / Path(header_name).with_suffix(".yaml")
self.fns_dir = Path(self.libc_root, "src", self.stem)
self.macros_dir = Path(self.libc_root, "include", "llvm-libc-macros")
@@ -83,5 +83,10 @@ class Header:
macro file might be located in a subdirectory:
libc/include/llvm-libc-macros/fcntl-macros.h
libc/include/llvm-libc-macros/linux/fcntl-macros.h
+
+ When a header would be nested in a dir (such as arpa/, sys/, etc) we
+ instead use a hyphen in the name.
+ libc/include/llvm-libc-macros/sys-mman-macros.h
"""
- return self.macros_dir.glob(f"**/{self.stem}-macros.h")
+ stem = self.stem.replace("/", "-")
+ return self.macros_dir.glob(f"**/{stem}-macros.h")
diff --git a/libc/utils/docgen/inttypes.yaml b/libc/utils/docgen/inttypes.yaml
new file mode 100644
index 000000000000..cbf50592ef07
--- /dev/null
+++ b/libc/utils/docgen/inttypes.yaml
@@ -0,0 +1,20 @@
+functions:
+ imaxabs:
+ c-definition: 7.8.2.1
+ in-latest-posix: ''
+ imaxdiv:
+ c-definition: 7.8.2.2
+ in-latest-posix: ''
+ strtoimax:
+ c-definition: 7.8.2.3
+ in-latest-posix: ''
+ strtoumax:
+ c-definition: 7.8.2.3
+ in-latest-posix: ''
+ wcstoimax:
+ c-definition: 7.8.2.4
+ in-latest-posix: ''
+ wcstoumax:
+ c-definition: 7.8.2.4
+ in-latest-posix: ''
+
diff --git a/libc/utils/docgen/locale.yaml b/libc/utils/docgen/locale.yaml
new file mode 100644
index 000000000000..eea91a885ff4
--- /dev/null
+++ b/libc/utils/docgen/locale.yaml
@@ -0,0 +1,37 @@
+functions:
+ duplocale:
+ in-latest-posix: ''
+ freelocale:
+ in-latest-posix: ''
+ getlocalename_l:
+ in-latest-posix: ''
+ localeconv:
+ c-definition: 7.11.2.1
+ in-latest-posix: ''
+ newlocale:
+ in-latest-posix: ''
+ setlocale:
+ c-definition: 7.11.1.1
+ in-latest-posix: ''
+ uselocale:
+ in-latest-posix: ''
+macros:
+ LC_ALL:
+ c-definition: '7.11'
+ in-latest-posix: ''
+ LC_COLLATE:
+ c-definition: '7.11'
+ in-latest-posix: ''
+ LC_CTYPE:
+ c-definition: '7.11'
+ in-latest-posix: ''
+ LC_MONETARY:
+ c-definition: '7.11'
+ in-latest-posix: ''
+ LC_NUMERIC:
+ c-definition: '7.11'
+ in-latest-posix: ''
+ LC_TIME:
+ c-definition: '7.11'
+ in-latest-posix: ''
+
diff --git a/libc/utils/docgen/setjmp.json b/libc/utils/docgen/setjmp.json
deleted file mode 100644
index 0b9a4e65da4f..000000000000
--- a/libc/utils/docgen/setjmp.json
+++ /dev/null
@@ -1,15 +0,0 @@
-{
- "macros": {
- "__STDC_VERSION_SETJMP_H__": {
- "c-definition": "7.13.2"
- }
- },
- "functions": {
- "setjmp": {
- "c-definition": "7.13.1.1"
- },
- "longjmp": {
- "c-definition": "7.13.2.1"
- }
- }
-}
diff --git a/libc/utils/docgen/setjmp.yaml b/libc/utils/docgen/setjmp.yaml
new file mode 100644
index 000000000000..123739d1a6ce
--- /dev/null
+++ b/libc/utils/docgen/setjmp.yaml
@@ -0,0 +1,15 @@
+functions:
+ longjmp:
+ c-definition: 7.13.2.1
+ in-latest-posix: ''
+ setjmp:
+ c-definition: 7.13.1.1
+ in-latest-posix: ''
+ siglongjmp:
+ in-latest-posix: ''
+ sigsetjmp:
+ in-latest-posix: ''
+macros:
+ __STDC_VERSION_SETJMP_H__:
+ c-definition: 7.13.2
+
diff --git a/libc/utils/docgen/signal.json b/libc/utils/docgen/signal.json
deleted file mode 100644
index 337b0c19717b..000000000000
--- a/libc/utils/docgen/signal.json
+++ /dev/null
@@ -1,152 +0,0 @@
-{
- "macros": {
- "SIG_DFL": {
- "c-definition": "7.14.3",
- "posix-definition": "https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/signal.h.html"
- },
- "SIG_ERR": {
- "c-definition": "7.14.3",
- "posix-definition": "https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/signal.h.html"
- },
- "SIG_HOLD": {
- "posix-definition": "https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/signal.h.html"
- },
- "SIG_IGN": {
- "c-definition": "7.14.3",
- "posix-definition": "https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/signal.h.html"
- },
- "SIGRTMIN": {
- "posix-definition": "https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/signal.h.html"
- },
- "SIGRTMAX": {
- "posix-definition": "https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/signal.h.html"
- },
- "SIGABRT": {
- "c-definition": "7.14.3",
- "posix-definition": "https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/signal.h.html"
- },
- "SIGALRM": {
- "posix-definition": "https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/signal.h.html"
- },
- "SIGBUS": {
- "posix-definition": "https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/signal.h.html"
- },
- "SIGCHLD": {
- "posix-definition": "https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/signal.h.html"
- },
- "SIGCONT": {
- "posix-definition": "https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/signal.h.html"
- },
- "SIGFPE": {
- "c-definition": "7.14.3",
- "posix-definition": "https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/signal.h.html"
- },
- "SIGHUP": {
- "posix-definition": "https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/signal.h.html"
- },
- "SIGILL": {
- "c-definition": "7.14.3",
- "posix-definition": "https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/signal.h.html"
- },
- "SIGINT": {
- "c-definition": "7.14.3",
- "posix-definition": "https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/signal.h.html"
- },
- "SIGKILL": {
- "posix-definition": "https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/signal.h.html"
- },
- "SIGPIPE": {
- "posix-definition": "https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/signal.h.html"
- },
- "SIGPIPE": {
- "posix-definition": "https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/signal.h.html"
- },
- "SIGQUIT": {
- "posix-definition": "https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/signal.h.html"
- },
- "SIGSEGV": {
- "c-definition": "7.14.3",
- "posix-definition": "https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/signal.h.html"
- },
- "SIGSTOP": {
- "posix-definition": "https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/signal.h.html"
- },
- "SIGTERM": {
- "c-definition": "7.14.3",
- "posix-definition": "https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/signal.h.html"
- },
- "SIGTSTP": {
- "posix-definition": "https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/signal.h.html"
- },
- "SIGTTIN": {
- "posix-definition": "https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/signal.h.html"
- },
- "SIGTTOU": {
- "posix-definition": "https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/signal.h.html"
- },
- "SIGUSR1": {
- "posix-definition": "https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/signal.h.html"
- },
- "SIGUSR2": {
- "posix-definition": "https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/signal.h.html"
- },
- "SIGPOLL": {
- "posix-definition": "https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/signal.h.html"
- },
- "SIGPROF": {
- "posix-definition": "https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/signal.h.html"
- },
- "SIGSYS": {
- "posix-definition": "https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/signal.h.html"
- },
- "SIGTRAP": {
- "posix-definition": "https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/signal.h.html"
- },
- "SIGURG": {
- "posix-definition": "https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/signal.h.html"
- },
- "SIGVTALRM": {
- "posix-definition": "https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/signal.h.html"
- },
- "SIGXCPU": {
- "posix-definition": "https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/signal.h.html"
- },
- "SIGXFSZ": {
- "posix-definition": "https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/signal.h.html"
- }
- },
- "functions": {
- "signal": {
- "c-definition": "7.14.1.1",
- "posix-definition": "https://pubs.opengroup.org/onlinepubs/9699919799/functions/signal.html"
- },
- "raise": {
- "c-definition": "7.14.2.1",
- "posix-definition": "https://pubs.opengroup.org/onlinepubs/9699919799/functions/raise.html"
- },
- "kill": {
- "posix-definition": "https://pubs.opengroup.org/onlinepubs/9699919799/functions/kill.html"
- },
- "sigaction": {
- "posix-definition": "https://pubs.opengroup.org/onlinepubs/9699919799/functions/sigaction.html"
- },
- "sigaddset": {
- "posix-definition": "https://pubs.opengroup.org/onlinepubs/9699919799/functions/sigaddset.html"
- },
- "sigaltstack": {
- "posix-definition": "https://pubs.opengroup.org/onlinepubs/9699919799/functions/sigaltstack.html"
- },
- "sigdelset": {
- "posix-definition": "https://pubs.opengroup.org/onlinepubs/9699919799/functions/sigdelset.html"
- },
- "sigemptyset": {
- "posix-definition": "https://pubs.opengroup.org/onlinepubs/9699919799/functions/sigemptyset.html"
- },
- "sigfillset": {
- "posix-definition": "https://pubs.opengroup.org/onlinepubs/9699919799/functions/sigfillset.html"
- },
- "sigprocmask": {
- "posix-definition": "https://pubs.opengroup.org/onlinepubs/9699919799/functions/sigprocmask.html"
- }
- }
-}
diff --git a/libc/utils/docgen/signal.yaml b/libc/utils/docgen/signal.yaml
new file mode 100644
index 000000000000..da31a86b00eb
--- /dev/null
+++ b/libc/utils/docgen/signal.yaml
@@ -0,0 +1,102 @@
+functions:
+ kill:
+ in-latest-posix: ''
+ raise:
+ c-definition: 7.14.2.1
+ in-latest-posix: ''
+ sigaction:
+ in-latest-posix: ''
+ sigaddset:
+ in-latest-posix: ''
+ sigaltstack:
+ in-latest-posix: ''
+ sigdelset:
+ in-latest-posix: ''
+ sigemptyset:
+ in-latest-posix: ''
+ sigfillset:
+ in-latest-posix: ''
+ signal:
+ c-definition: 7.14.1.1
+ in-latest-posix: ''
+ sigprocmask:
+ in-latest-posix: ''
+macros:
+ SIGABRT:
+ c-definition: 7.14.3
+ in-latest-posix: ''
+ SIGALRM:
+ in-latest-posix: ''
+ SIGBUS:
+ in-latest-posix: ''
+ SIGCHLD:
+ in-latest-posix: ''
+ SIGCONT:
+ in-latest-posix: ''
+ SIGFPE:
+ c-definition: 7.14.3
+ in-latest-posix: ''
+ SIGHUP:
+ in-latest-posix: ''
+ SIGILL:
+ c-definition: 7.14.3
+ in-latest-posix: ''
+ SIGINT:
+ c-definition: 7.14.3
+ in-latest-posix: ''
+ SIGKILL:
+ in-latest-posix: ''
+ SIGPIPE:
+ in-latest-posix: ''
+ SIGPOLL:
+ in-latest-posix: ''
+ SIGPROF:
+ in-latest-posix: ''
+ SIGQUIT:
+ in-latest-posix: ''
+ SIGRTMAX:
+ in-latest-posix: ''
+ SIGRTMIN:
+ in-latest-posix: ''
+ SIGSEGV:
+ c-definition: 7.14.3
+ in-latest-posix: ''
+ SIGSTOP:
+ in-latest-posix: ''
+ SIGSYS:
+ in-latest-posix: ''
+ SIGTERM:
+ c-definition: 7.14.3
+ in-latest-posix: ''
+ SIGTRAP:
+ in-latest-posix: ''
+ SIGTSTP:
+ in-latest-posix: ''
+ SIGTTIN:
+ in-latest-posix: ''
+ SIGTTOU:
+ in-latest-posix: ''
+ SIGURG:
+ in-latest-posix: ''
+ SIGUSR1:
+ in-latest-posix: ''
+ SIGUSR2:
+ in-latest-posix: ''
+ SIGVTALRM:
+ in-latest-posix: ''
+ SIGXCPU:
+ in-latest-posix: ''
+ SIGXFSZ:
+ in-latest-posix: ''
+ SIG_DFL:
+ c-definition: 7.14.3
+ in-latest-posix: ''
+ SIG_ERR:
+ c-definition: 7.14.3
+ in-latest-posix: ''
+ SIG_HOLD:
+ in-latest-posix: ''
+ SIG_IGN:
+ c-definition: 7.14.3
+ in-latest-posix: ''
+
diff --git a/libc/utils/docgen/stdbit.json b/libc/utils/docgen/stdbit.json
deleted file mode 100644
index 25060c1ff9fd..000000000000
--- a/libc/utils/docgen/stdbit.json
+++ /dev/null
@@ -1,270 +0,0 @@
-{
- "macros": {
- "__STDC_VERSION_STDBIT_H__": {
- "c-definition": "7.18.1.2"
- },
- "__STDC_ENDIAN_LITTLE__": {
- "c-definition": "7.18.2.2"
- },
- "__STDC_ENDIAN_BIG__": {
- "c-definition": "7.18.2.2"
- },
- "__STDC_ENDIAN_NATIVE__": {
- "c-definition": "7.18.2.2"
- },
- "stdc_leading_zeros": {
- "c-definition": "7.18.3.1"
- },
- "stdc_leading_ones": {
- "c-definition": "7.18.4.1"
- },
- "stdc_trailing_zeros": {
- "c-definition": "7.18.5.1"
- },
- "stdc_trailing_ones": {
- "c-definition": "7.18.6.1"
- },
- "stdc_first_leading_zero": {
- "c-definition": "7.18.7.1"
- },
- "stdc_first_leading_one": {
- "c-definition": "7.18.8.1"
- },
- "stdc_first_trailing_zero": {
- "c-definition": "7.18.9.1"
- },
- "stdc_first_trailing_one": {
- "c-definition": "7.18.10.1"
- },
- "stdc_count_zeros": {
- "c-definition": "7.18.11.1"
- },
- "stdc_count_ones": {
- "c-definition": "7.18.12.1"
- },
- "stdc_has_single_bit": {
- "c-definition": "7.18.13.1"
- },
- "stdc_bit_width": {
- "c-definition": "7.18.14.1"
- },
- "stdc_bit_floor": {
- "c-definition": "7.18.15.1"
- },
- "stdc_bit_ceil": {
- "c-definition": "7.18.16.1"
- }
- },
- "functions": {
- "stdc_leading_zeros_uc": {
- "c-definition": "7.18.3"
- },
- "stdc_leading_zeros_us": {
- "c-definition": "7.18.3"
- },
- "stdc_leading_zeros_ui": {
- "c-definition": "7.18.3"
- },
- "stdc_leading_zeros_ul": {
- "c-definition": "7.18.3"
- },
- "stdc_leading_zeros_ull": {
- "c-definition": "7.18.3"
- },
- "stdc_leading_ones_uc": {
- "c-definition": "7.18.4"
- },
- "stdc_leading_ones_us": {
- "c-definition": "7.18.4"
- },
- "stdc_leading_ones_ui": {
- "c-definition": "7.18.4"
- },
- "stdc_leading_ones_ul": {
- "c-definition": "7.18.4"
- },
- "stdc_leading_ones_ull": {
- "c-definition": "7.18.4"
- },
- "stdc_trailing_zeros_uc": {
- "c-definition": "7.18.5"
- },
- "stdc_trailing_zeros_us": {
- "c-definition": "7.18.5"
- },
- "stdc_trailing_zeros_ui": {
- "c-definition": "7.18.5"
- },
- "stdc_trailing_zeros_ul": {
- "c-definition": "7.18.5"
- },
- "stdc_trailing_zeros_ull": {
- "c-definition": "7.18.5"
- },
- "stdc_trailing_ones_uc": {
- "c-definition": "7.18.6"
- },
- "stdc_trailing_ones_us": {
- "c-definition": "7.18.6"
- },
- "stdc_trailing_ones_ui": {
- "c-definition": "7.18.6"
- },
- "stdc_trailing_ones_ul": {
- "c-definition": "7.18.6"
- },
- "stdc_trailing_ones_ull": {
- "c-definition": "7.18.6"
- },
- "stdc_first_leading_zero_uc": {
- "c-definition": "7.18.7"
- },
- "stdc_first_leading_zero_us": {
- "c-definition": "7.18.7"
- },
- "stdc_first_leading_zero_ui": {
- "c-definition": "7.18.7"
- },
- "stdc_first_leading_zero_ul": {
- "c-definition": "7.18.7"
- },
- "stdc_first_leading_zero_ull": {
- "c-definition": "7.18.7"
- },
- "stdc_first_leading_one_uc": {
- "c-definition": "7.18.8"
- },
- "stdc_first_leading_one_us": {
- "c-definition": "7.18.8"
- },
- "stdc_first_leading_one_ui": {
- "c-definition": "7.18.8"
- },
- "stdc_first_leading_one_ul": {
- "c-definition": "7.18.8"
- },
- "stdc_first_leading_one_ull": {
- "c-definition": "7.18.8"
- },
- "stdc_first_trailing_zero_uc": {
- "c-definition": "7.18.9"
- },
- "stdc_first_trailing_zero_us": {
- "c-definition": "7.18.9"
- },
- "stdc_first_trailing_zero_ui": {
- "c-definition": "7.18.9"
- },
- "stdc_first_trailing_zero_ul": {
- "c-definition": "7.18.9"
- },
- "stdc_first_trailing_zero_ull": {
- "c-definition": "7.18.9"
- },
- "stdc_first_trailing_one_uc": {
- "c-definition": "7.18.10"
- },
- "stdc_first_trailing_one_us": {
- "c-definition": "7.18.10"
- },
- "stdc_first_trailing_one_ui": {
- "c-definition": "7.18.10"
- },
- "stdc_first_trailing_one_ul": {
- "c-definition": "7.18.10"
- },
- "stdc_first_trailing_one_ull": {
- "c-definition": "7.18.10"
- },
- "stdc_count_zeros_uc": {
- "c-definition": "7.18.11"
- },
- "stdc_count_zeros_us": {
- "c-definition": "7.18.11"
- },
- "stdc_count_zeros_ui": {
- "c-definition": "7.18.11"
- },
- "stdc_count_zeros_ul": {
- "c-definition": "7.18.11"
- },
- "stdc_count_zeros_ull": {
- "c-definition": "7.18.11"
- },
- "stdc_count_ones_uc": {
- "c-definition": "7.18.12"
- },
- "stdc_count_ones_us": {
- "c-definition": "7.18.12"
- },
- "stdc_count_ones_ui": {
- "c-definition": "7.18.12"
- },
- "stdc_count_ones_ul": {
- "c-definition": "7.18.12"
- },
- "stdc_count_ones_ull": {
- "c-definition": "7.18.12"
- },
- "stdc_has_single_bit_uc": {
- "c-definition": "7.18.13"
- },
- "stdc_has_single_bit_us": {
- "c-definition": "7.18.13"
- },
- "stdc_has_single_bit_ui": {
- "c-definition": "7.18.13"
- },
- "stdc_has_single_bit_ul": {
- "c-definition": "7.18.13"
- },
- "stdc_has_single_bit_ull": {
- "c-definition": "7.18.13"
- },
- "stdc_bit_width_uc": {
- "c-definition": "7.18.14"
- },
- "stdc_bit_width_us": {
- "c-definition": "7.18.14"
- },
- "stdc_bit_width_ui": {
- "c-definition": "7.18.14"
- },
- "stdc_bit_width_ul": {
- "c-definition": "7.18.14"
- },
- "stdc_bit_width_ull": {
- "c-definition": "7.18.14"
- },
- "stdc_bit_floor_uc": {
- "c-definition": "7.18.15"
- },
- "stdc_bit_floor_us": {
- "c-definition": "7.18.15"
- },
- "stdc_bit_floor_ui": {
- "c-definition": "7.18.15"
- },
- "stdc_bit_floor_ul": {
- "c-definition": "7.18.15"
- },
- "stdc_bit_floor_ull": {
- "c-definition": "7.18.15"
- },
- "stdc_bit_ceil_uc": {
- "c-definition": "7.18.16"
- },
- "stdc_bit_ceil_us": {
- "c-definition": "7.18.16"
- },
- "stdc_bit_ceil_ui": {
- "c-definition": "7.18.16"
- },
- "stdc_bit_ceil_ul": {
- "c-definition": "7.18.16"
- },
- "stdc_bit_ceil_ull": {
- "c-definition": "7.18.16"
- }
- }
-}
diff --git a/libc/utils/docgen/stdbit.yaml b/libc/utils/docgen/stdbit.yaml
new file mode 100644
index 000000000000..976221601e9c
--- /dev/null
+++ b/libc/utils/docgen/stdbit.yaml
@@ -0,0 +1,179 @@
+functions:
+ stdc_bit_ceil_uc:
+ c-definition: 7.18.16
+ stdc_bit_ceil_ui:
+ c-definition: 7.18.16
+ stdc_bit_ceil_ul:
+ c-definition: 7.18.16
+ stdc_bit_ceil_ull:
+ c-definition: 7.18.16
+ stdc_bit_ceil_us:
+ c-definition: 7.18.16
+ stdc_bit_floor_uc:
+ c-definition: 7.18.15
+ stdc_bit_floor_ui:
+ c-definition: 7.18.15
+ stdc_bit_floor_ul:
+ c-definition: 7.18.15
+ stdc_bit_floor_ull:
+ c-definition: 7.18.15
+ stdc_bit_floor_us:
+ c-definition: 7.18.15
+ stdc_bit_width_uc:
+ c-definition: 7.18.14
+ stdc_bit_width_ui:
+ c-definition: 7.18.14
+ stdc_bit_width_ul:
+ c-definition: 7.18.14
+ stdc_bit_width_ull:
+ c-definition: 7.18.14
+ stdc_bit_width_us:
+ c-definition: 7.18.14
+ stdc_count_ones_uc:
+ c-definition: 7.18.12
+ stdc_count_ones_ui:
+ c-definition: 7.18.12
+ stdc_count_ones_ul:
+ c-definition: 7.18.12
+ stdc_count_ones_ull:
+ c-definition: 7.18.12
+ stdc_count_ones_us:
+ c-definition: 7.18.12
+ stdc_count_zeros_uc:
+ c-definition: 7.18.11
+ stdc_count_zeros_ui:
+ c-definition: 7.18.11
+ stdc_count_zeros_ul:
+ c-definition: 7.18.11
+ stdc_count_zeros_ull:
+ c-definition: 7.18.11
+ stdc_count_zeros_us:
+ c-definition: 7.18.11
+ stdc_first_leading_one_uc:
+ c-definition: 7.18.8
+ stdc_first_leading_one_ui:
+ c-definition: 7.18.8
+ stdc_first_leading_one_ul:
+ c-definition: 7.18.8
+ stdc_first_leading_one_ull:
+ c-definition: 7.18.8
+ stdc_first_leading_one_us:
+ c-definition: 7.18.8
+ stdc_first_leading_zero_uc:
+ c-definition: 7.18.7
+ stdc_first_leading_zero_ui:
+ c-definition: 7.18.7
+ stdc_first_leading_zero_ul:
+ c-definition: 7.18.7
+ stdc_first_leading_zero_ull:
+ c-definition: 7.18.7
+ stdc_first_leading_zero_us:
+ c-definition: 7.18.7
+ stdc_first_trailing_one_uc:
+ c-definition: 7.18.10
+ stdc_first_trailing_one_ui:
+ c-definition: 7.18.10
+ stdc_first_trailing_one_ul:
+ c-definition: 7.18.10
+ stdc_first_trailing_one_ull:
+ c-definition: 7.18.10
+ stdc_first_trailing_one_us:
+ c-definition: 7.18.10
+ stdc_first_trailing_zero_uc:
+ c-definition: 7.18.9
+ stdc_first_trailing_zero_ui:
+ c-definition: 7.18.9
+ stdc_first_trailing_zero_ul:
+ c-definition: 7.18.9
+ stdc_first_trailing_zero_ull:
+ c-definition: 7.18.9
+ stdc_first_trailing_zero_us:
+ c-definition: 7.18.9
+ stdc_has_single_bit_uc:
+ c-definition: 7.18.13
+ stdc_has_single_bit_ui:
+ c-definition: 7.18.13
+ stdc_has_single_bit_ul:
+ c-definition: 7.18.13
+ stdc_has_single_bit_ull:
+ c-definition: 7.18.13
+ stdc_has_single_bit_us:
+ c-definition: 7.18.13
+ stdc_leading_ones_uc:
+ c-definition: 7.18.4
+ stdc_leading_ones_ui:
+ c-definition: 7.18.4
+ stdc_leading_ones_ul:
+ c-definition: 7.18.4
+ stdc_leading_ones_ull:
+ c-definition: 7.18.4
+ stdc_leading_ones_us:
+ c-definition: 7.18.4
+ stdc_leading_zeros_uc:
+ c-definition: 7.18.3
+ stdc_leading_zeros_ui:
+ c-definition: 7.18.3
+ stdc_leading_zeros_ul:
+ c-definition: 7.18.3
+ stdc_leading_zeros_ull:
+ c-definition: 7.18.3
+ stdc_leading_zeros_us:
+ c-definition: 7.18.3
+ stdc_trailing_ones_uc:
+ c-definition: 7.18.6
+ stdc_trailing_ones_ui:
+ c-definition: 7.18.6
+ stdc_trailing_ones_ul:
+ c-definition: 7.18.6
+ stdc_trailing_ones_ull:
+ c-definition: 7.18.6
+ stdc_trailing_ones_us:
+ c-definition: 7.18.6
+ stdc_trailing_zeros_uc:
+ c-definition: 7.18.5
+ stdc_trailing_zeros_ui:
+ c-definition: 7.18.5
+ stdc_trailing_zeros_ul:
+ c-definition: 7.18.5
+ stdc_trailing_zeros_ull:
+ c-definition: 7.18.5
+ stdc_trailing_zeros_us:
+ c-definition: 7.18.5
+macros:
+ __STDC_ENDIAN_BIG__:
+ c-definition: 7.18.2.2
+ __STDC_ENDIAN_LITTLE__:
+ c-definition: 7.18.2.2
+ __STDC_ENDIAN_NATIVE__:
+ c-definition: 7.18.2.2
+ __STDC_VERSION_STDBIT_H__:
+ c-definition: 7.18.1.2
+ stdc_bit_ceil:
+ c-definition: 7.18.16.1
+ stdc_bit_floor:
+ c-definition: 7.18.15.1
+ stdc_bit_width:
+ c-definition: 7.18.14.1
+ stdc_count_ones:
+ c-definition: 7.18.12.1
+ stdc_count_zeros:
+ c-definition: 7.18.11.1
+ stdc_first_leading_one:
+ c-definition: 7.18.8.1
+ stdc_first_leading_zero:
+ c-definition: 7.18.7.1
+ stdc_first_trailing_one:
+ c-definition: 7.18.10.1
+ stdc_first_trailing_zero:
+ c-definition: 7.18.9.1
+ stdc_has_single_bit:
+ c-definition: 7.18.13.1
+ stdc_leading_ones:
+ c-definition: 7.18.4.1
+ stdc_leading_zeros:
+ c-definition: 7.18.3.1
+ stdc_trailing_ones:
+ c-definition: 7.18.6.1
+ stdc_trailing_zeros:
+ c-definition: 7.18.5.1
+
diff --git a/libc/utils/docgen/stdio.yaml b/libc/utils/docgen/stdio.yaml
new file mode 100644
index 000000000000..9dabee44a51c
--- /dev/null
+++ b/libc/utils/docgen/stdio.yaml
@@ -0,0 +1,226 @@
+macros:
+ __STDC_VERSION_STDIO_H__:
+ c-definition: '7.23.1'
+ _IOFBF:
+ c-definition: '7.23.1'
+ in-latest-posix: ''
+ _IOLBF:
+ c-definition: '7.23.1'
+ in-latest-posix: ''
+ _IONBF:
+ c-definition: '7.23.1'
+ in-latest-posix: ''
+ BUFSIZ:
+ c-definition: '7.23.1'
+ in-latest-posix: ''
+ EOF:
+ c-definition: '7.23.1'
+ in-latest-posix: ''
+ FOPEN_MAX:
+ c-definition: '7.23.1'
+ in-latest-posix: ''
+ FILENAME_MAX:
+ c-definition: '7.23.1'
+ in-latest-posix: ''
+ _PRINTF_NAN_LEN_MAX:
+ c-definition: '7.23.1'
+ L_tmpnam:
+ c-definition: '7.23.1'
+ in-latest-posix: ''
+ L_ctermid:
+ in-latest-posix: ''
+ SEEK_CUR:
+ c-definition: '7.23.1'
+ in-latest-posix: ''
+ SEEK_END:
+ c-definition: '7.23.1'
+ in-latest-posix: ''
+ SEEK_SET:
+ c-definition: '7.23.1'
+ in-latest-posix: ''
+ TMP_MAX:
+ c-definition: '7.23.1'
+ in-latest-posix: ''
+ stderr:
+ c-definition: '7.23.1'
+ in-latest-posix: ''
+ stdin:
+ c-definition: '7.23.1'
+ in-latest-posix: ''
+ stdout:
+ c-definition: '7.23.1'
+ in-latest-posix: ''
+functions:
+ remove:
+ c-definition: '7.23.4.1'
+ in-latest-posix: ''
+ rename:
+ c-definition: '7.23.4.2'
+ in-latest-posix: ''
+ tmpfile:
+ c-definition: '7.23.4.3'
+ in-latest-posix: ''
+ tmpnam:
+ c-definition: '7.23.4.4'
+ in-latest-posix: ''
+ fclose:
+ c-definition: '7.23.5.1'
+ in-latest-posix: ''
+ fflush:
+ c-definition: '7.23.5.2'
+ in-latest-posix: ''
+ fopen:
+ c-definition: '7.23.5.3'
+ in-latest-posix: ''
+ freopen:
+ c-definition: '7.23.5.4'
+ in-latest-posix: ''
+ setbuf:
+ c-definition: '7.23.5.5'
+ in-latest-posix: ''
+ setvbuf:
+ c-definition: '7.23.5.6'
+ in-latest-posix: ''
+ fprintf:
+ c-definition: '7.23.6.1'
+ in-latest-posix: ''
+ fscanf:
+ c-definition: '7.23.6.2'
+ in-latest-posix: ''
+ printf:
+ c-definition: '7.23.6.3'
+ in-latest-posix: ''
+ scanf:
+ c-definition: '7.23.6.4'
+ in-latest-posix: ''
+ snprintf:
+ c-definition: '7.23.6.5'
+ in-latest-posix: ''
+ sprintf:
+ c-definition: '7.23.6.6'
+ in-latest-posix: ''
+ sscanf:
+ c-definition: '7.23.6.7'
+ in-latest-posix: ''
+ vfprintf:
+ c-definition: '7.23.6.8'
+ in-latest-posix: ''
+ vfscanf:
+ c-definition: '7.23.6.9'
+ in-latest-posix: ''
+ vprintf:
+ c-definition: '7.23.6.10'
+ in-latest-posix: ''
+ vscanf:
+ c-definition: '7.23.6.11'
+ in-latest-posix: ''
+ vsnprintf:
+ c-definition: '7.23.6.12'
+ in-latest-posix: ''
+ vsprintf:
+ c-definition: '7.23.6.13'
+ in-latest-posix: ''
+ vsscanf:
+ c-definition: '7.23.6.14'
+ in-latest-posix: ''
+ fgetc:
+ c-definition: '7.23.7.1'
+ in-latest-posix: ''
+ fgets:
+ c-definition: '7.23.7.2'
+ in-latest-posix: ''
+ fputc:
+ c-definition: '7.23.7.3'
+ in-latest-posix: ''
+ fputs:
+ c-definition: '7.23.7.4'
+ in-latest-posix: ''
+ getc:
+ c-definition: '7.23.7.5'
+ in-latest-posix: ''
+ getchar:
+ c-definition: '7.23.7.6'
+ in-latest-posix: ''
+ putc:
+ c-definition: '7.23.7.7'
+ in-latest-posix: ''
+ putchar:
+ c-definition: '7.23.7.8'
+ in-latest-posix: ''
+ puts:
+ c-definition: '7.23.7.9'
+ in-latest-posix: ''
+ ungetc:
+ c-definition: '7.23.7.10'
+ in-latest-posix: ''
+ fread:
+ c-definition: '7.23.8.1'
+ in-latest-posix: ''
+ fwrite:
+ c-definition: '7.23.8.2'
+ in-latest-posix: ''
+ fgetpos:
+ c-definition: '7.23.9.1'
+ in-latest-posix: ''
+ fseek:
+ c-definition: '7.23.9.2'
+ in-latest-posix: ''
+ fsetpos:
+ c-definition: '7.23.9.3'
+ in-latest-posix: ''
+ ftell:
+ c-definition: '7.23.9.4'
+ in-latest-posix: ''
+ rewind:
+ c-definition: '7.23.9.5'
+ in-latest-posix: ''
+ clearerr:
+ c-definition: '7.23.10.1'
+ in-latest-posix: ''
+ feof:
+ c-definition: '7.23.10.2'
+ in-latest-posix: ''
+ ferror:
+ c-definition: '7.23.10.3'
+ in-latest-posix: ''
+ perror:
+ c-definition: '7.23.10.4'
+ in-latest-posix: ''
+ ctermid:
+ in-latest-posix: ''
+ dprintf:
+ in-latest-posix: ''
+ fdopen:
+ in-latest-posix: ''
+ fileno:
+ in-latest-posix: ''
+ flockfile:
+ in-latest-posix: ''
+ fmemopen:
+ in-latest-posix: ''
+ fseeko:
+ in-latest-posix: ''
+ ftello:
+ in-latest-posix: ''
+ ftrylockfile:
+ in-latest-posix: ''
+ funlockfile:
+ in-latest-posix: ''
+ getdelim:
+ in-latest-posix: ''
+ getline:
+ in-latest-posix: ''
+ open_memstream:
+ in-latest-posix: ''
+ pclose:
+ in-latest-posix: ''
+ popen:
+ in-latest-posix: ''
+ putc_unlocked:
+ in-latest-posix: ''
+ putchar_unlocked:
+ in-latest-posix: ''
+ renameat:
+ in-latest-posix: ''
+ vdprintf:
+ in-latest-posix: ''
diff --git a/libc/utils/docgen/stdlib.yaml b/libc/utils/docgen/stdlib.yaml
new file mode 100644
index 000000000000..526ddefbe1ce
--- /dev/null
+++ b/libc/utils/docgen/stdlib.yaml
@@ -0,0 +1,158 @@
+functions:
+ _Exit:
+ c-definition: 7.24.4.5
+ in-latest-posix: ''
+ abort:
+ c-definition: 7.24.4.1
+ in-latest-posix: ''
+ abs:
+ c-definition: 7.24.6.1
+ in-latest-posix: ''
+ aligned_alloc:
+ c-definition: 7.24.3.1
+ in-latest-posix: ''
+ at_quick_exit:
+ c-definition: 7.24.4.3
+ in-latest-posix: ''
+ atexit:
+ c-definition: 7.24.4.2
+ in-latest-posix: ''
+ atof:
+ c-definition: 7.24.1.1
+ in-latest-posix: ''
+ atoi:
+ c-definition: 7.24.1.2
+ in-latest-posix: ''
+ atol:
+ c-definition: 7.24.1.2
+ in-latest-posix: ''
+ atoll:
+ c-definition: 7.24.1.2
+ in-latest-posix: ''
+ bsearch:
+ c-definition: 7.24.5.1
+ in-latest-posix: ''
+ calloc:
+ c-definition: 7.24.3.2
+ in-latest-posix: ''
+ div:
+ c-definition: 7.24.6.2
+ in-latest-posix: ''
+ exit:
+ c-definition: 7.24.4.4
+ in-latest-posix: ''
+ free:
+ c-definition: 7.24.3.3
+ in-latest-posix: ''
+ free_aligned_sized:
+ c-definition: 7.24.3.5
+ free_sized:
+ c-definition: 7.24.3.4
+ getenv:
+ c-definition: 7.24.4.6
+ in-latest-posix: ''
+ labs:
+ c-definition: 7.24.6.1
+ in-latest-posix: ''
+ ldiv:
+ c-definition: 7.24.6.2
+ in-latest-posix: ''
+ llabs:
+ c-definition: 7.24.6.1
+ in-latest-posix: ''
+ lldiv:
+ c-definition: 7.24.6.2
+ in-latest-posix: ''
+ malloc:
+ c-definition: 7.24.3.6
+ in-latest-posix: ''
+ mblen:
+ c-definition: 7.24.7.1
+ in-latest-posix: ''
+ mbstowcs:
+ c-definition: 7.24.8.1
+ in-latest-posix: ''
+ mbtowc:
+ c-definition: 7.24.7.2
+ in-latest-posix: ''
+ memalignment:
+ c-definition: 7.24.9.1
+ qsort:
+ c-definition: 7.24.5.2
+ in-latest-posix: ''
+ quick_exit:
+ c-definition: 7.24.4.7
+ in-latest-posix: ''
+ rand:
+ c-definition: 7.24.2.1
+ in-latest-posix: ''
+ realloc:
+ c-definition: 7.24.3.7
+ in-latest-posix: ''
+ srand:
+ c-definition: 7.24.2.2
+ in-latest-posix: ''
+ strfromd:
+ c-definition: 7.24.1.3
+ strfromd128:
+ c-definition: 7.24.1.4
+ strfromd32:
+ c-definition: 7.24.1.4
+ strfromd64:
+ c-definition: 7.24.1.4
+ strfromf:
+ c-definition: 7.24.1.3
+ strfroml:
+ c-definition: 7.24.1.3
+ strtod:
+ c-definition: 7.24.1.5
+ in-latest-posix: ''
+ strtod128:
+ c-definition: 7.24.1.6
+ strtod32:
+ c-definition: 7.24.1.6
+ strtod64:
+ c-definition: 7.24.1.6
+ strtof:
+ c-definition: 7.24.1.5
+ in-latest-posix: ''
+ strtol:
+ c-definition: 7.24.1.7
+ in-latest-posix: ''
+ strtold:
+ c-definition: 7.24.1.5
+ in-latest-posix: ''
+ strtoll:
+ c-definition: 7.24.1.7
+ in-latest-posix: ''
+ strtoul:
+ c-definition: 7.24.1.7
+ in-latest-posix: ''
+ strtoull:
+ c-definition: 7.24.1.7
+ in-latest-posix: ''
+ system:
+ c-definition: 7.24.4.8
+ in-latest-posix: ''
+ wcstombs:
+ c-definition: 7.24.8.2
+ in-latest-posix: ''
+ wctomb:
+ c-definition: 7.24.7.3
+ in-latest-posix: ''
+macros:
+ EXIT_FAILURE:
+ c-definition: '7.24'
+ in-latest-posix: ''
+ EXIT_SUCCESS:
+ c-definition: '7.24'
+ in-latest-posix: ''
+ MB_CUR_MAX:
+ c-definition: '7.24'
+ in-latest-posix: ''
+ RAND_MAX:
+ c-definition: '7.24'
+ in-latest-posix: ''
+ __STDC_VERSION_STDLIB_H__:
+ c-definition: '7.24'
+
diff --git a/libc/utils/docgen/string.yaml b/libc/utils/docgen/string.yaml
new file mode 100644
index 000000000000..d703a8e3593e
--- /dev/null
+++ b/libc/utils/docgen/string.yaml
@@ -0,0 +1,94 @@
+functions:
+ memccpy:
+ c-definition: 7.26.2.2
+ in-latest-posix: ''
+ memchr:
+ c-definition: 7.26.5.2
+ in-latest-posix: ''
+ memcmp:
+ c-definition: 7.26.4.1
+ in-latest-posix: ''
+ memcpy:
+ c-definition: 7.26.2.1
+ in-latest-posix: ''
+ memmove:
+ c-definition: 7.26.2.3
+ in-latest-posix: ''
+ mempcpy:
+ c-definition: 'TODO: glibc extension'
+ memset:
+ c-definition: 7.26.6.1
+ in-latest-posix: ''
+ memset_explicit:
+ c-definition: 7.26.6.2
+ stpcpy:
+ in-latest-posix: ''
+ stpncpy:
+ in-latest-posix: ''
+ strcat:
+ c-definition: 7.26.3.1
+ in-latest-posix: ''
+ strchr:
+ c-definition: 7.26.5.3
+ in-latest-posix: ''
+ strcmp:
+ c-definition: 7.26.4.2
+ in-latest-posix: ''
+ strcoll:
+ c-definition: 7.26.4.3
+ in-latest-posix: ''
+ strcoll_l:
+ in-latest-posix: ''
+ strcpy:
+ c-definition: 7.26.2.4
+ in-latest-posix: ''
+ strcspn:
+ c-definition: 7.26.5.4
+ in-latest-posix: ''
+ strdup:
+ c-definition: 7.26.2.6
+ in-latest-posix: ''
+ strerror:
+ c-definition: 7.26.6.3
+ in-latest-posix: ''
+ strlen:
+ c-definition: 7.26.6.4
+ in-latest-posix: ''
+ strncat:
+ c-definition: 7.26.3.2
+ in-latest-posix: ''
+ strncmp:
+ c-definition: 7.26.4.4
+ in-latest-posix: ''
+ strncpy:
+ c-definition: 7.26.2.5
+ in-latest-posix: ''
+ strndup:
+ c-definition: 7.26.2.7
+ in-latest-posix: ''
+ strpbrk:
+ c-definition: 7.26.5.5
+ in-latest-posix: ''
+ strrchr:
+ c-definition: 7.26.5.6
+ in-latest-posix: ''
+ strspn:
+ c-definition: 7.26.5.7
+ in-latest-posix: ''
+ strstr:
+ c-definition: 7.26.5.8
+ in-latest-posix: ''
+ strtok:
+ c-definition: 7.26.5.9
+ in-latest-posix: ''
+ strtok_r:
+ in-latest-posix: ''
+ strxfrm:
+ c-definition: 7.26.4.5
+ in-latest-posix: ''
+ strxfrm_l:
+ in-latest-posix: ''
+macros:
+ __STDC_VERSION_STRING_H__:
+ c-definition: 7.26.1
+
diff --git a/libc/utils/docgen/sys/mman.yaml b/libc/utils/docgen/sys/mman.yaml
new file mode 100644
index 000000000000..dba26cabc662
--- /dev/null
+++ b/libc/utils/docgen/sys/mman.yaml
@@ -0,0 +1,77 @@
+functions:
+ mlock:
+ posix-definition: ''
+ mlockall:
+ posix-definition: ''
+ mmap:
+ posix-definition: ''
+ mprotect:
+ posix-definition: ''
+ msync:
+ posix-definition: ''
+ munlock:
+ posix-definition: ''
+ munlockall:
+ posix-definition: ''
+ munmap:
+ posix-definition: ''
+ posix_madvise:
+ posix-definition: ''
+ posix_mem_offset:
+ posix-definition: ''
+ posix_typed_mem_get_info:
+ posix-definition: ''
+ posix_typed_mem_open:
+ posix-definition: ''
+ shm_open:
+ posix-definition: ''
+ shm_unlink:
+ posix-definition: ''
+macros:
+ MAP_ANON:
+ posix-definition: ''
+ MAP_ANONYMOUS:
+ posix-definition: ''
+ MAP_FAILED:
+ posix-definition: ''
+ MAP_FIXED:
+ posix-definition: ''
+ MAP_PRIVATE:
+ posix-definition: ''
+ MAP_SHARED:
+ posix-definition: ''
+ MCL_CURRENT:
+ posix-definition: ''
+ MCL_FUTURE:
+ posix-definition: ''
+ MS_ASYNC:
+ posix-definition: ''
+ MS_INVALIDATE:
+ posix-definition: ''
+ MS_SYNC:
+ posix-definition: ''
+ POSIX_MADV_DONTNEED:
+ posix-definition: ''
+ POSIX_MADV_NORMAL:
+ posix-definition: ''
+ POSIX_MADV_RANDOM:
+ posix-definition: ''
+ POSIX_MADV_SEQUENTIAL:
+ posix-definition: ''
+ POSIX_MADV_WILLNEED:
+ posix-definition: ''
+ POSIX_TYPED_MEM_ALLOCATE:
+ posix-definition: ''
+ POSIX_TYPED_MEM_ALLOCATE_CONTIG:
+ posix-definition: ''
+ POSIX_TYPED_MEM_MAP_ALLOCATABLE:
+ posix-definition: ''
+ PROT_EXEC:
+ posix-definition: ''
+ PROT_NONE:
+ posix-definition: ''
+ PROT_READ:
+ posix-definition: ''
+ PROT_WRITE:
+ posix-definition: ''
+
diff --git a/libc/utils/docgen/threads.json b/libc/utils/docgen/threads.json
deleted file mode 100644
index 8591cbde55a4..000000000000
--- a/libc/utils/docgen/threads.json
+++ /dev/null
@@ -1,87 +0,0 @@
-{
- "macros": {
- "ONCE_FLAG_INIT": {
- "c-definition": "7.28.1.3"
- },
- "TSS_DTOR_ITERATIONS": {
- "c-definition": "7.28.1.3"
- }
- },
- "functions": {
- "call_once": {
- "c-definition": "7.28.2.1"
- },
- "cnd_broadcast": {
- "c-definition": "7.28.3.1"
- },
- "cnd_destroy": {
- "c-definition": "7.28.3.2"
- },
- "cnd_init": {
- "c-definition": "7.28.3.3"
- },
- "cnd_signal": {
- "c-definition": "7.28.3.4"
- },
- "cnd_timedwait": {
- "c-definition": "7.28.3.5"
- },
- "cnd_wait": {
- "c-definition": "7.28.3.6"
- },
- "mtx_destroy": {
- "c-definition": "7.28.4.1"
- },
- "mtx_init": {
- "c-definition": "7.28.4.2"
- },
- "mtx_lock": {
- "c-definition": "7.28.4.3"
- },
- "mtx_timedlock": {
- "c-definition": "7.28.4.4"
- },
- "mtx_trylock": {
- "c-definition": "7.28.4.5"
- },
- "mtx_unlock": {
- "c-definition": "7.28.4.6"
- },
- "thrd_create": {
- "c-definition": "7.28.5.1"
- },
- "thrd_current": {
- "c-definition": "7.28.5.2"
- },
- "thrd_detach": {
- "c-definition": "7.28.5.3"
- },
- "thrd_equal": {
- "c-definition": "7.28.5.4"
- },
- "thrd_exit": {
- "c-definition": "7.28.5.5"
- },
- "thrd_join": {
- "c-definition": "7.28.5.6"
- },
- "thrd_sleep": {
- "c-definition": "7.28.5.7"
- },
- "thrd_yield": {
- "c-definition": "7.28.5.8"
- },
- "tss_create": {
- "c-definition": "7.28.6.1"
- },
- "tss_delete": {
- "c-definition": "7.28.6.2"
- },
- "tss_get": {
- "c-definition": "7.28.6.3"
- },
- "tss_set": {
- "c-definition": "7.28.6.4"
- }
- }
-}
diff --git a/libc/utils/docgen/threads.yaml b/libc/utils/docgen/threads.yaml
new file mode 100644
index 000000000000..83db0992dc45
--- /dev/null
+++ b/libc/utils/docgen/threads.yaml
@@ -0,0 +1,88 @@
+functions:
+ call_once:
+ c-definition: 7.28.2.1
+ in-latest-posix: ''
+ cnd_broadcast:
+ c-definition: 7.28.3.1
+ in-latest-posix: ''
+ cnd_destroy:
+ c-definition: 7.28.3.2
+ in-latest-posix: ''
+ cnd_init:
+ c-definition: 7.28.3.3
+ in-latest-posix: ''
+ cnd_signal:
+ c-definition: 7.28.3.4
+ in-latest-posix: ''
+ cnd_timedwait:
+ c-definition: 7.28.3.5
+ in-latest-posix: ''
+ cnd_wait:
+ c-definition: 7.28.3.6
+ in-latest-posix: ''
+ mtx_destroy:
+ c-definition: 7.28.4.2
+ in-latest-posix: ''
+ mtx_init:
+ c-definition: 7.28.4.3
+ in-latest-posix: ''
+ mtx_lock:
+ c-definition: 7.28.4.4
+ in-latest-posix: ''
+ mtx_timedlock:
+ c-definition: 7.28.4.5
+ in-latest-posix: ''
+ mtx_trylock:
+ c-definition: 7.28.4.6
+ in-latest-posix: ''
+ mtx_unlock:
+ c-definition: 7.28.4.7
+ in-latest-posix: ''
+ thrd_create:
+ c-definition: 7.28.5.1
+ in-latest-posix: ''
+ thrd_current:
+ c-definition: 7.28.5.2
+ in-latest-posix: ''
+ thrd_detach:
+ c-definition: 7.28.5.3
+ in-latest-posix: ''
+ thrd_equal:
+ c-definition: 7.28.5.4
+ in-latest-posix: ''
+ thrd_exit:
+ c-definition: 7.28.5.5
+ in-latest-posix: ''
+ thrd_join:
+ c-definition: 7.28.5.6
+ in-latest-posix: ''
+ thrd_sleep:
+ c-definition: 7.28.5.7
+ in-latest-posix: ''
+ thrd_yield:
+ c-definition: 7.28.5.8
+ in-latest-posix: ''
+ tss_create:
+ c-definition: 7.28.6.1
+ in-latest-posix: ''
+ tss_delete:
+ c-definition: 7.28.6.2
+ in-latest-posix: ''
+ tss_get:
+ c-definition: 7.28.6.3
+ in-latest-posix: ''
+ tss_set:
+ c-definition: 7.28.6.4
+ in-latest-posix: ''
+macros:
+ ONCE_FLAG_INIT:
+ c-definition: 7.28.1
+ in-latest-posix: ''
+ TSS_DTOR_ITERATIONS:
+ c-definition: 7.28.1
+ in-latest-posix: ''
+ __STDC_NO_THREADS__:
+ c-definition: 7.28.1
+ thread_local:
+ in-latest-posix: ''
+
diff --git a/libc/utils/docgen/uchar.yaml b/libc/utils/docgen/uchar.yaml
new file mode 100644
index 000000000000..580af0f54833
--- /dev/null
+++ b/libc/utils/docgen/uchar.yaml
@@ -0,0 +1,21 @@
+functions:
+ c16rtomb:
+ c-definition: 7.30.2.5
+ in-latest-posix: ''
+ c32rtomb:
+ c-definition: 7.30.2.7
+ in-latest-posix: ''
+ c8rtomb:
+ c-definition: 7.30.2.3
+ mbrtoc16:
+ c-definition: 7.30.2.4
+ in-latest-posix: ''
+ mbrtoc32:
+ c-definition: 7.30.2.6
+ in-latest-posix: ''
+ mbrtoc8:
+ c-definition: 7.30.2.2
+macros:
+ __STDC_VERSION_UCHAR_H__:
+ c-definition: 7.30.1
+
diff --git a/libc/utils/docgen/wchar.yaml b/libc/utils/docgen/wchar.yaml
new file mode 100644
index 000000000000..dcc8963efdd3
--- /dev/null
+++ b/libc/utils/docgen/wchar.yaml
@@ -0,0 +1,131 @@
+functions:
+ btowc:
+ c-definition: 7.31.6.2.1
+ fgetwc:
+ c-definition: 7.31.3.1
+ fgetws:
+ c-definition: 7.31.3.2
+ fputwc:
+ c-definition: 7.31.3.3
+ fputws:
+ c-definition: 7.31.3.4
+ fwide:
+ c-definition: 7.31.3.5
+ fwprintf:
+ c-definition: 7.31.2.2
+ fwscanf:
+ c-definition: 7.31.2.3
+ getwc:
+ c-definition: 7.31.3.6
+ getwchar:
+ c-definition: 7.31.3.7
+ mbrlen:
+ c-definition: 7.31.6.4.2
+ mbrtowc:
+ c-definition: 7.31.6.4.3
+ mbsinit:
+ c-definition: 7.31.6.3.1
+ mbsrtowcs:
+ c-definition: 7.31.6.5.2
+ putwc:
+ c-definition: 7.31.3.8
+ putwchar:
+ c-definition: 7.31.3.9
+ swprintf:
+ c-definition: 7.31.2.4
+ swscanf:
+ c-definition: 7.31.2.5
+ ungetwc:
+ c-definition: 7.31.3.10
+ vfwprintf:
+ c-definition: 7.31.2.6
+ vfwscanf:
+ c-definition: 7.31.2.7
+ vswprintf:
+ c-definition: 7.31.2.8
+ vswscanf:
+ c-definition: 7.31.2.9
+ vwprintf:
+ c-definition: 7.31.2.10
+ vwscanf:
+ c-definition: 7.31.2.11
+ wcrtomb:
+ c-definition: 7.31.6.4.4
+ wcscat:
+ c-definition: 7.31.4.4.1
+ wcschr:
+ c-definition: 7.31.4.6.2
+ wcscmp:
+ c-definition: 7.31.4.5.2
+ wcscoll:
+ c-definition: 7.31.4.5.3
+ wcscpy:
+ c-definition: 7.31.4.3.1
+ wcscspn:
+ c-definition: 7.31.4.6.3
+ wcsftime:
+ c-definition: 7.31.5.1
+ wcslen:
+ c-definition: 7.31.4.7.1
+ wcsncat:
+ c-definition: 7.31.4.4.2
+ wcsncmp:
+ c-definition: 7.31.4.5.4
+ wcsncpy:
+ c-definition: 7.31.4.3.2
+ wcspbrk:
+ c-definition: 7.31.4.6.4
+ wcsrchr:
+ c-definition: 7.31.4.6.5
+ wcsrtombs:
+ c-definition: 7.31.6.5.3
+ wcsspn:
+ c-definition: 7.31.4.6.6
+ wcsstr:
+ c-definition: 7.31.4.6.7
+ wcstod:
+ c-definition: 7.31.4.2.2
+ wcstod128:
+ c-definition: 7.31.4.2.3
+ wcstod32:
+ c-definition: 7.31.4.2.3
+ wcstod64:
+ c-definition: 7.31.4.2.3
+ wcstof:
+ c-definition: 7.31.4.2.2
+ wcstok:
+ c-definition: 7.31.4.6.8
+ wcstol:
+ c-definition: 7.31.4.2.4
+ wcstold:
+ c-definition: 7.31.4.2.2
+ wcstoll:
+ c-definition: 7.31.4.2.4
+ wcstoul:
+ c-definition: 7.31.4.2.4
+ wcstoull:
+ c-definition: 7.31.4.2.4
+ wcsxfrm:
+ c-definition: 7.31.4.5.5
+ wctob:
+ c-definition: 7.31.6.2.2
+ wmemchr:
+ c-definition: 7.31.4.6.9
+ wmemcmp:
+ c-definition: 7.31.4.5.6
+ wmemcpy:
+ c-definition: 7.31.4.3.3
+ wmemmove:
+ c-definition: 7.31.4.3.4
+ wmemset:
+ c-definition: 7.31.4.7.2
+ wprintf:
+ c-definition: 7.31.2.12
+ wscanf:
+ c-definition: 7.31.2.13
+macros:
+ WEOF:
+ c-definition: 7.31.1
+ __STDC_VERSION_WCHAR_H__:
+ c-definition: 7.31.1
+
diff --git a/libc/utils/docgen/wctype.yaml b/libc/utils/docgen/wctype.yaml
new file mode 100644
index 000000000000..8675cbe500da
--- /dev/null
+++ b/libc/utils/docgen/wctype.yaml
@@ -0,0 +1,36 @@
+functions:
+ iswalnum:
+ c-definition: 7.32.2.1.1
+ iswalpha:
+ c-definition: 7.32.2.1.2
+ iswblank:
+ c-definition: 7.32.2.1.4
+ iswctype:
+ c-definition: 7.32.2.2.1
+ iswdigit:
+ c-definition: 7.32.2.1.5
+ iswgraph:
+ c-definition: 7.32.2.1.6
+ iswlower:
+ c-definition: 7.32.2.1.7
+ iswprint:
+ c-definition: 7.32.2.1.8
+ iswpunct:
+ c-definition: 7.32.2.1.9
+ iswspace:
+ c-definition: 7.32.2.1.10
+ iswupper:
+ c-definition: 7.32.2.1.11
+ iswxdigit:
+ c-definition: 7.32.2.1.12
+ towctrans:
+ c-definition: 7.32.3.2.1
+ towlower:
+ c-definition: 7.32.3.1.1
+ towupper:
+ c-definition: 7.32.3.1.2
+ wctrans:
+ c-definition: 7.32.3.2.2
+ wctype:
+ c-definition: 7.32.2.2.2
+
diff --git a/libc/utils/gpu/loader/Loader.h b/libc/utils/gpu/loader/Loader.h
index 0d683832855e..8e86f6396932 100644
--- a/libc/utils/gpu/loader/Loader.h
+++ b/libc/utils/gpu/loader/Loader.h
@@ -113,7 +113,7 @@ inline uint32_t handle_server(rpc::Server &server, uint32_t index,
return 0;
index = port->get_index() + 1;
- int status = rpc::SUCCESS;
+ int status = rpc::RPC_SUCCESS;
switch (port->get_opcode()) {
case RPC_TEST_INCREMENT: {
port->recv_and_send([](rpc::Buffer *buffer, uint32_t) {
@@ -186,7 +186,7 @@ inline uint32_t handle_server(rpc::Server &server, uint32_t index,
}
// Handle all of the `libc` specific opcodes.
- if (status != rpc::SUCCESS)
+ if (status != rpc::RPC_SUCCESS)
handle_error("Error handling RPC server");
port->close();
diff --git a/libc/utils/gpu/server/CMakeLists.txt b/libc/utils/gpu/server/CMakeLists.txt
index b1cada44cd32..a109d603318b 100644
--- a/libc/utils/gpu/server/CMakeLists.txt
+++ b/libc/utils/gpu/server/CMakeLists.txt
@@ -23,6 +23,11 @@ target_compile_definitions(llvmlibc_rpc_server PUBLIC
LIBC_NAMESPACE=${LIBC_NAMESPACE})
# Install the server and associated header.
+install(FILES ${LIBC_SOURCE_DIR}/shared/rpc.h
+ ${LIBC_SOURCE_DIR}/shared/rpc_util.h
+ ${LIBC_SOURCE_DIR}/shared/rpc_opcodes.h
+ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/shared
+ COMPONENT libc-headers)
install(TARGETS llvmlibc_rpc_server
ARCHIVE DESTINATION "lib${LLVM_LIBDIR_SUFFIX}"
COMPONENT libc)
diff --git a/libc/utils/gpu/server/rpc_server.cpp b/libc/utils/gpu/server/rpc_server.cpp
index f724c5c82c42..1faee531fa20 100644
--- a/libc/utils/gpu/server/rpc_server.cpp
+++ b/libc/utils/gpu/server/rpc_server.cpp
@@ -437,10 +437,10 @@ rpc::Status handle_port_impl(rpc::Server::Port &port) {
break;
}
default:
- return rpc::UNHANDLED_OPCODE;
+ return rpc::RPC_UNHANDLED_OPCODE;
}
- return rpc::SUCCESS;
+ return rpc::RPC_SUCCESS;
}
namespace rpc {
@@ -455,7 +455,7 @@ rpc::Status handle_libc_opcodes(rpc::Server::Port &port, uint32_t num_lanes) {
case 64:
return handle_port_impl<64>(port);
default:
- return rpc::ERROR;
+ return rpc::RPC_ERROR;
}
}
} // namespace rpc
diff --git a/libc/utils/hdrgen/CMakeLists.txt b/libc/utils/hdrgen/CMakeLists.txt
new file mode 100644
index 000000000000..c6827da21505
--- /dev/null
+++ b/libc/utils/hdrgen/CMakeLists.txt
@@ -0,0 +1,17 @@
+if(LLVM_LIBC_FULL_BUILD)
+ enable_testing()
+
+ set(HDRGEN_TESTS_DIR ${CMAKE_CURRENT_SOURCE_DIR}/tests)
+ set(TEST_OUTPUT_DIR ${CMAKE_BINARY_DIR}/hdrgen/output)
+
+ add_test(
+ NAME hdrgen_integration_test
+ COMMAND python3 ${HDRGEN_TESTS_DIR}/test_integration.py --output_dir ${TEST_OUTPUT_DIR}
+ )
+
+ add_custom_target(check-hdrgen
+ COMMAND ${CMAKE_CTEST_COMMAND} -R hdrgen_integration_test --output-on-failure
+ )
+
+ message(STATUS "Integration test for hdrgen added.")
+endif()
diff --git a/libc/utils/hdrgen/README.rst b/libc/utils/hdrgen/README.rst
new file mode 100644
index 000000000000..d16e6c5ccaec
--- /dev/null
+++ b/libc/utils/hdrgen/README.rst
@@ -0,0 +1,5 @@
+This directory contains the sources and specifications for the types,
+macros and entrypoint functions. These definitions are organized in the
+``yaml`` subdirectory and match the organization of the ``*.h.def``
+files. This directory also contains the Python sources for hdrgen, which is
+what generates the headers.
diff --git a/libc/utils/hdrgen/enumeration.py b/libc/utils/hdrgen/enumeration.py
new file mode 100644
index 000000000000..b9848c04ee63
--- /dev/null
+++ b/libc/utils/hdrgen/enumeration.py
@@ -0,0 +1,19 @@
+# ====-- Enumeration class for libc function headers ----------*- python -*--==#
+#
+# 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
+#
+# ==-------------------------------------------------------------------------==#
+
+
+class Enumeration:
+ def __init__(self, name, value):
+ self.name = name
+ self.value = value
+
+ def __str__(self):
+ if self.value != None:
+ return f"{self.name} = {self.value}"
+ else:
+ return f"{self.name}"
diff --git a/libc/utils/hdrgen/function.py b/libc/utils/hdrgen/function.py
new file mode 100644
index 000000000000..d97df7f8a50e
--- /dev/null
+++ b/libc/utils/hdrgen/function.py
@@ -0,0 +1,30 @@
+# ====-- Function class for libc function headers -------------*- python -*--==#
+#
+# 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
+#
+# ==-------------------------------------------------------------------------==#
+
+
+class Function:
+ def __init__(
+ self, return_type, name, arguments, standards, guard=None, attributes=[]
+ ):
+ self.return_type = return_type
+ self.name = name
+ self.arguments = [
+ arg if isinstance(arg, str) else arg["type"] for arg in arguments
+ ]
+ self.standards = standards
+ self.guard = guard
+ self.attributes = attributes or ""
+
+ def __str__(self):
+ attributes_str = " ".join(self.attributes)
+ arguments_str = ", ".join(self.arguments)
+ if attributes_str == "":
+ result = f"{self.return_type} {self.name}({arguments_str})"
+ else:
+ result = f"{attributes_str} {self.return_type} {self.name}({arguments_str})"
+ return result
diff --git a/libc/utils/hdrgen/gpu_headers.py b/libc/utils/hdrgen/gpu_headers.py
new file mode 100644
index 000000000000..8c4ff6e08b11
--- /dev/null
+++ b/libc/utils/hdrgen/gpu_headers.py
@@ -0,0 +1,53 @@
+# ===- GPU HeaderFile Class for --export-decls version --------*- python -*--==#
+#
+# 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
+#
+# ==-------------------------------------------------------------------------==#
+
+from header import HeaderFile
+
+class GpuHeaderFile(HeaderFile):
+ def __str__(self):
+ content = []
+
+ content.append(
+ f"//===-- C standard declarations for {self.name} ------------------------------===//"
+ )
+ content.append("//")
+ content.append(
+ "// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions."
+ )
+ content.append("// See https://llvm.org/LICENSE.txt for license information.")
+ content.append("// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception")
+ content.append("//")
+ content.append(
+ "//===----------------------------------------------------------------------===//\n"
+ )
+
+ header_guard = f"__LLVM_LIBC_DECLARATIONS_{self.name.upper()[:-2]}_H"
+ content.append(f"#ifndef {header_guard}")
+ content.append(f"#define {header_guard}\n")
+
+ content.append("#ifndef __LIBC_ATTRS")
+ content.append("#define __LIBC_ATTRS")
+ content.append("#endif\n")
+
+ content.append("#ifdef __cplusplus")
+ content.append('extern "C" {')
+ content.append("#endif\n")
+
+ for function in self.functions:
+ content.append(f"{function} __LIBC_ATTRS;\n")
+
+ for object in self.objects:
+ content.append(f"{object} __LIBC_ATTRS;\n")
+
+ content.append("#ifdef __cplusplus")
+ content.append("}")
+ content.append("#endif\n")
+
+ content.append(f"#endif")
+
+ return "\n".join(content)
diff --git a/libc/utils/hdrgen/header.py b/libc/utils/hdrgen/header.py
new file mode 100644
index 000000000000..df8ce613bd0f
--- /dev/null
+++ b/libc/utils/hdrgen/header.py
@@ -0,0 +1,85 @@
+# ====- HeaderFile Class for libc function headers -----------*- python -*--==#
+#
+# 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
+#
+# ==-------------------------------------------------------------------------==#
+
+
+class HeaderFile:
+ def __init__(self, name):
+ self.name = name
+ self.macros = []
+ self.types = []
+ self.enumerations = []
+ self.objects = []
+ self.functions = []
+
+ def add_macro(self, macro):
+ self.macros.append(macro)
+
+ def add_type(self, type_):
+ self.types.append(type_)
+
+ def add_enumeration(self, enumeration):
+ self.enumerations.append(enumeration)
+
+ def add_object(self, object):
+ self.objects.append(object)
+
+ def add_function(self, function):
+ self.functions.append(function)
+
+ def __str__(self):
+ content = [""]
+
+ for macro in self.macros:
+ content.append(f"{macro}\n")
+
+ for type_ in self.types:
+ content.append(f"{type_}")
+
+ if self.enumerations:
+ combined_enum_content = ",\n ".join(
+ str(enum) for enum in self.enumerations
+ )
+ content.append(f"\nenum {{\n {combined_enum_content},\n}};")
+
+ content.append("\n__BEGIN_C_DECLS\n")
+
+ current_guard = None
+ for function in self.functions:
+ if function.guard == None:
+ content.append(str(function) + " __NOEXCEPT;")
+ content.append("")
+ else:
+ if current_guard == None:
+ current_guard = function.guard
+ content.append(f"#ifdef {current_guard}")
+ content.append(str(function) + " __NOEXCEPT;")
+ content.append("")
+ elif current_guard == function.guard:
+ content.append(str(function) + " __NOEXCEPT;")
+ content.append("")
+ else:
+ content.pop()
+ content.append(f"#endif // {current_guard}")
+ content.append("")
+ current_guard = function.guard
+ content.append(f"#ifdef {current_guard}")
+ content.append(str(function) + " __NOEXCEPT;")
+ content.append("")
+ if current_guard != None:
+ content.pop()
+ content.append(f"#endif // {current_guard}")
+ content.append("")
+
+ for object in self.objects:
+ content.append(str(object))
+ if self.objects:
+ content.append("\n__END_C_DECLS")
+ else:
+ content.append("__END_C_DECLS")
+
+ return "\n".join(content)
diff --git a/libc/utils/hdrgen/macro.py b/libc/utils/hdrgen/macro.py
new file mode 100644
index 000000000000..9a712f2a1c74
--- /dev/null
+++ b/libc/utils/hdrgen/macro.py
@@ -0,0 +1,19 @@
+# ====-- Macro class for libc function headers ----------------*- python -*--==#
+#
+# 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
+#
+# ==-------------------------------------------------------------------------==#
+
+
+class Macro:
+ def __init__(self, name, value=None):
+ self.name = name
+ self.value = value
+
+ def __str__(self):
+ if self.value != None:
+ return f"#define {self.name} {self.value}"
+ else:
+ return f"#define {self.name}"
diff --git a/libc/utils/hdrgen/object.py b/libc/utils/hdrgen/object.py
new file mode 100644
index 000000000000..f5214452f034
--- /dev/null
+++ b/libc/utils/hdrgen/object.py
@@ -0,0 +1,16 @@
+# ====-- Object class for libc function headers ---------------*- python -*--==#
+#
+# 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
+#
+# ==-------------------------------------------------------------------------==#
+
+
+class Object:
+ def __init__(self, name, type):
+ self.name = name
+ self.type = type
+
+ def __str__(self):
+ return f"extern {self.type} {self.name};"
diff --git a/libc/utils/hdrgen/tests/expected_output/test_header.h b/libc/utils/hdrgen/tests/expected_output/test_header.h
new file mode 100644
index 000000000000..a777976134b0
--- /dev/null
+++ b/libc/utils/hdrgen/tests/expected_output/test_header.h
@@ -0,0 +1,52 @@
+//===-- C standard library header test_small-------------------------------===//
+//
+// 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_TEST_SMALL_H
+#define LLVM_LIBC_TEST_SMALL_H
+
+#include "__llvm-libc-common.h"
+#include "llvm-libc-macros/float16-macros.h"
+#include "llvm-libc-macros/test_small-macros.h"
+#include "llvm-libc-types/float128.h"
+
+#define MACRO_A 1
+
+#define MACRO_B 2
+
+#include <llvm-libc-types/type_a.h>
+#include <llvm-libc-types/type_b.h>
+
+enum {
+ enum_a = value_1,
+ enum_b = value_2,
+};
+
+__BEGIN_C_DECLS
+
+CONST_FUNC_A void func_a() __NOEXCEPT;
+
+#ifdef LIBC_TYPES_HAS_FLOAT128
+float128 func_b() __NOEXCEPT;
+#endif // LIBC_TYPES_HAS_FLOAT128
+
+#ifdef LIBC_TYPES_HAS_FLOAT16
+_Float16 func_c(int, float) __NOEXCEPT;
+
+_Float16 func_d(int, float) __NOEXCEPT;
+#endif // LIBC_TYPES_HAS_FLOAT16
+
+#ifdef LIBC_TYPES_HAS_FLOAT16_AND_FLOAT128
+_Float16 func_e(float128) __NOEXCEPT;
+#endif // LIBC_TYPES_HAS_FLOAT16_AND_FLOAT128
+
+extern obj object_1;
+extern obj object_2;
+
+__END_C_DECLS
+
+#endif // LLVM_LIBC_TEST_SMALL_H
diff --git a/libc/utils/hdrgen/tests/input/test_small.h.def b/libc/utils/hdrgen/tests/input/test_small.h.def
new file mode 100644
index 000000000000..075be957b813
--- /dev/null
+++ b/libc/utils/hdrgen/tests/input/test_small.h.def
@@ -0,0 +1,19 @@
+//===-- C standard library header test_small-------------------------------===//
+//
+// 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_TEST_SMALL_H
+#define LLVM_LIBC_TEST_SMALL_H
+
+#include "__llvm-libc-common.h"
+#include "llvm-libc-macros/float16-macros.h"
+#include "llvm-libc-macros/test_small-macros.h"
+#include "llvm-libc-types/float128.h"
+
+%%public_api()
+
+#endif // LLVM_LIBC_TEST_SMALL_H
diff --git a/libc/utils/hdrgen/tests/input/test_small.yaml b/libc/utils/hdrgen/tests/input/test_small.yaml
new file mode 100644
index 000000000000..772552faf81d
--- /dev/null
+++ b/libc/utils/hdrgen/tests/input/test_small.yaml
@@ -0,0 +1,66 @@
+header: test_header.h
+macros:
+ - macro_name: MACRO_A
+ macro_value: 1
+ - macro_name: MACRO_B
+ macro_value: 2
+types:
+ - type_name: type_a
+ - type_name: type_b
+enums:
+ - name: enum_a
+ value: value_1
+ - name: enum_b
+ value: value_2
+objects:
+ - object_name: object_1
+ object_type: obj
+ - object_name: object_2
+ object_type: obj
+functions:
+ - name: func_a
+ return_type: void
+ arguments: []
+ standards:
+ - stdc
+ attributes:
+ - CONST_FUNC_A
+ - name: func_b
+ return_type: float128
+ arguments: []
+ standards:
+ - stdc
+ guard: LIBC_TYPES_HAS_FLOAT128
+ - name: func_c
+ return_type: _Float16
+ arguments:
+ - type: int
+ - type: float
+ standards:
+ - stdc
+ guard: LIBC_TYPES_HAS_FLOAT16
+ - name: func_d
+ return_type: _Float16
+ arguments:
+ - type: int
+ - type: float
+ standards:
+ - stdc
+ guard: LIBC_TYPES_HAS_FLOAT16
+ - name: func_e
+ return_type: _Float16
+ arguments:
+ - type: float128
+ standards:
+ - stdc
+ guard: LIBC_TYPES_HAS_FLOAT16_AND_FLOAT128
+ - name: func_f
+ return_type: _Float16
+ arguments:
+ - type: int
+ - type: double
+ - type: float
+ standards:
+ - stdc
+
+
diff --git a/libc/utils/hdrgen/tests/test_integration.py b/libc/utils/hdrgen/tests/test_integration.py
new file mode 100644
index 000000000000..ce80026e7bcc
--- /dev/null
+++ b/libc/utils/hdrgen/tests/test_integration.py
@@ -0,0 +1,81 @@
+import subprocess
+import unittest
+from pathlib import Path
+import os
+import argparse
+import sys
+
+
+class TestHeaderGenIntegration(unittest.TestCase):
+ def setUp(self):
+ self.output_dir = Path(
+ args.output_dir if args.output_dir else "libc/utils/hdrgen/tests/output"
+ )
+
+ self.maxDiff = None
+
+ self.source_dir = Path(__file__).resolve().parent.parent.parent.parent.parent
+
+ def run_script(self, yaml_file, h_def_file, output_dir, entry_points):
+ yaml_file = self.source_dir / yaml_file
+ h_def_file = self.source_dir / h_def_file
+ command = [
+ "python3",
+ str(self.source_dir / "libc/utils/hdrgen/yaml_to_classes.py"),
+ str(yaml_file),
+ "--h_def_file",
+ str(h_def_file),
+ "--output_dir",
+ str(output_dir),
+ ]
+
+ for entry_point in entry_points:
+ command.extend(["--e", entry_point])
+
+ result = subprocess.run(
+ command,
+ capture_output=True,
+ text=True,
+ )
+
+ print("STDOUT:", result.stdout)
+ print("STDERR:", result.stderr)
+ result.check_returncode()
+
+ def compare_files(self, generated_file, expected_file):
+ with generated_file.open("r") as gen_file:
+ gen_content = gen_file.read()
+ with expected_file.open("r") as exp_file:
+ exp_content = exp_file.read()
+
+ self.assertEqual(gen_content, exp_content)
+
+ def test_generate_header(self):
+ yaml_file = "libc/utils/hdrgen/tests/input/test_small.yaml"
+ h_def_file = "libc/utils/hdrgen/tests/input/test_small.h.def"
+ expected_output_file = (
+ self.source_dir / "libc/utils/hdrgen/tests/expected_output/test_header.h"
+ )
+ output_file = self.output_dir / "test_small.h"
+ entry_points = {"func_b", "func_a", "func_c", "func_d", "func_e"}
+
+ if not self.output_dir.exists():
+ self.output_dir.mkdir(parents=True)
+
+ self.run_script(yaml_file, h_def_file, self.output_dir, entry_points)
+
+ self.compare_files(output_file, expected_output_file)
+
+
+if __name__ == "__main__":
+ parser = argparse.ArgumentParser(description="TestHeaderGenIntegration arguments")
+ parser.add_argument(
+ "--output_dir", type=str, help="Output directory for generated headers"
+ )
+ args, remaining_argv = parser.parse_known_args()
+
+ TestHeaderGenIntegration.output_dir = args.output_dir
+
+ sys.argv[1:] = remaining_argv
+
+ unittest.main()
diff --git a/libc/utils/hdrgen/type.py b/libc/utils/hdrgen/type.py
new file mode 100644
index 000000000000..4ebf8034a454
--- /dev/null
+++ b/libc/utils/hdrgen/type.py
@@ -0,0 +1,15 @@
+# ====-- Type class for libc function headers -----------------*- python -*--==#
+#
+# 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
+#
+# ==-------------------------------------------------------------------------==#
+
+
+class Type:
+ def __init__(self, type_name):
+ self.type_name = type_name
+
+ def __str__(self):
+ return f"#include <llvm-libc-types/{self.type_name}.h>"
diff --git a/libc/utils/hdrgen/yaml_functions_sorted.py b/libc/utils/hdrgen/yaml_functions_sorted.py
new file mode 100644
index 000000000000..b960ecaf973f
--- /dev/null
+++ b/libc/utils/hdrgen/yaml_functions_sorted.py
@@ -0,0 +1,39 @@
+# ex: python3 sort_yaml_functions.py
+# ex: must be within yaml directory
+import yaml
+import os
+
+
+def sort_yaml_functions(yaml_file):
+ with open(yaml_file, "r") as f:
+ yaml_data = yaml.safe_load(f)
+
+ if "functions" in yaml_data:
+ yaml_data["functions"].sort(key=lambda x: x["name"])
+
+ class IndentYamlListDumper(yaml.Dumper):
+ def increase_indent(self, flow=False, indentless=False):
+ return super(IndentYamlListDumper, self).increase_indent(flow, False)
+
+ with open(yaml_file, "w") as f:
+ yaml.dump(
+ yaml_data,
+ f,
+ Dumper=IndentYamlListDumper,
+ default_flow_style=False,
+ sort_keys=False,
+ )
+
+
+def main():
+ current_directory = os.getcwd()
+ yaml_files = [
+ file for file in os.listdir(current_directory) if file.endswith(".yaml")
+ ]
+
+ for yaml_file in yaml_files:
+ sort_yaml_functions(yaml_file)
+
+
+if __name__ == "__main__":
+ main()
diff --git a/libc/utils/hdrgen/yaml_to_classes.py b/libc/utils/hdrgen/yaml_to_classes.py
new file mode 100644
index 000000000000..ec2441b78aee
--- /dev/null
+++ b/libc/utils/hdrgen/yaml_to_classes.py
@@ -0,0 +1,283 @@
+#!/usr/bin/env python3
+#
+# ===- Generate headers for libc functions -------------------*- python -*--==#
+#
+# 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
+#
+# ==-------------------------------------------------------------------------==#
+
+import yaml
+import argparse
+from pathlib import Path
+
+from enumeration import Enumeration
+from function import Function
+from gpu_headers import GpuHeaderFile as GpuHeader
+from header import HeaderFile
+from macro import Macro
+from object import Object
+from type import Type
+
+
+def yaml_to_classes(yaml_data, header_class, entry_points=None):
+ """
+ Convert YAML data to header classes.
+
+ Args:
+ yaml_data: The YAML data containing header specifications.
+ header_class: The class to use for creating the header.
+ entry_points: A list of specific function names to include in the header.
+
+ Returns:
+ HeaderFile: An instance of HeaderFile populated with the data.
+ """
+ header_name = yaml_data.get("header")
+ header = header_class(header_name)
+
+ for macro_data in yaml_data.get("macros", []):
+ header.add_macro(Macro(macro_data["macro_name"], macro_data["macro_value"]))
+
+ types = yaml_data.get("types", [])
+ sorted_types = sorted(types, key=lambda x: x["type_name"])
+ for type_data in sorted_types:
+ header.add_type(Type(type_data["type_name"]))
+
+ for enum_data in yaml_data.get("enums", []):
+ header.add_enumeration(
+ Enumeration(enum_data["name"], enum_data.get("value", None))
+ )
+
+ functions = yaml_data.get("functions", [])
+ if entry_points:
+ entry_points_set = set(entry_points)
+ functions = [f for f in functions if f["name"] in entry_points_set]
+ sorted_functions = sorted(functions, key=lambda x: x["name"])
+ guards = []
+ guarded_function_dict = {}
+ for function_data in sorted_functions:
+ guard = function_data.get("guard", None)
+ if guard is None:
+ arguments = [arg["type"] for arg in function_data["arguments"]]
+ attributes = function_data.get("attributes", None)
+ standards = function_data.get("standards", None)
+ header.add_function(
+ Function(
+ function_data["return_type"],
+ function_data["name"],
+ arguments,
+ standards,
+ guard,
+ attributes,
+ )
+ )
+ else:
+ if guard not in guards:
+ guards.append(guard)
+ guarded_function_dict[guard] = []
+ guarded_function_dict[guard].append(function_data)
+ else:
+ guarded_function_dict[guard].append(function_data)
+ sorted_guards = sorted(guards)
+ for guard in sorted_guards:
+ for function_data in guarded_function_dict[guard]:
+ arguments = [arg["type"] for arg in function_data["arguments"]]
+ attributes = function_data.get("attributes", None)
+ standards = function_data.get("standards", None)
+ header.add_function(
+ Function(
+ function_data["return_type"],
+ function_data["name"],
+ arguments,
+ standards,
+ guard,
+ attributes,
+ )
+ )
+
+ objects = yaml_data.get("objects", [])
+ sorted_objects = sorted(objects, key=lambda x: x["object_name"])
+ for object_data in sorted_objects:
+ header.add_object(
+ Object(object_data["object_name"], object_data["object_type"])
+ )
+
+ return header
+
+
+def load_yaml_file(yaml_file, header_class, entry_points):
+ """
+ Load YAML file and convert it to header classes.
+
+ Args:
+ yaml_file: Path to the YAML file.
+ header_class: The class to use for creating the header (HeaderFile or GpuHeader).
+ entry_points: A list of specific function names to include in the header.
+
+ Returns:
+ HeaderFile: An instance of HeaderFile populated with the data.
+ """
+ with open(yaml_file, "r") as f:
+ yaml_data = yaml.safe_load(f)
+ return yaml_to_classes(yaml_data, header_class, entry_points)
+
+
+def fill_public_api(header_str, h_def_content):
+ """
+ Replace the %%public_api() placeholder in the .h.def content with the generated header content.
+
+ Args:
+ header_str: The generated header string.
+ h_def_content: The content of the .h.def file.
+
+ Returns:
+ The final header content with the public API filled in.
+ """
+ header_str = header_str.strip()
+ return h_def_content.replace("%%public_api()", header_str, 1)
+
+
+def parse_function_details(details):
+ """
+ Parse function details from a list of strings and return a Function object.
+
+ Args:
+ details: A list containing function details
+
+ Returns:
+ Function: An instance of Function initialized with the details.
+ """
+ return_type, name, arguments, standards, guard, attributes = details
+ standards = standards.split(",") if standards != "null" else []
+ arguments = [arg.strip() for arg in arguments.split(",")]
+ attributes = attributes.split(",") if attributes != "null" else []
+
+ return Function(
+ return_type=return_type,
+ name=name,
+ arguments=arguments,
+ standards=standards,
+ guard=guard if guard != "null" else None,
+ attributes=attributes if attributes else [],
+ )
+
+
+def add_function_to_yaml(yaml_file, function_details):
+ """
+ Add a function to the YAML file.
+
+ Args:
+ yaml_file: The path to the YAML file.
+ function_details: A list containing function details (return_type, name, arguments, standards, guard, attributes).
+ """
+ new_function = parse_function_details(function_details)
+
+ with open(yaml_file, "r") as f:
+ yaml_data = yaml.safe_load(f)
+ if "functions" not in yaml_data:
+ yaml_data["functions"] = []
+
+ function_dict = {
+ "name": new_function.name,
+ "standards": new_function.standards,
+ "return_type": new_function.return_type,
+ "arguments": [{"type": arg} for arg in new_function.arguments],
+ }
+
+ if new_function.guard:
+ function_dict["guard"] = new_function.guard
+
+ if new_function.attributes:
+ function_dict["attributes"] = new_function.attributes
+
+ insert_index = 0
+ for i, func in enumerate(yaml_data["functions"]):
+ if func["name"] > new_function.name:
+ insert_index = i
+ break
+ else:
+ insert_index = len(yaml_data["functions"])
+
+ yaml_data["functions"].insert(insert_index, function_dict)
+
+ class IndentYamlListDumper(yaml.Dumper):
+ def increase_indent(self, flow=False, indentless=False):
+ return super(IndentYamlListDumper, self).increase_indent(flow, False)
+
+ with open(yaml_file, "w") as f:
+ yaml.dump(
+ yaml_data,
+ f,
+ Dumper=IndentYamlListDumper,
+ default_flow_style=False,
+ sort_keys=False,
+ )
+
+ print(f"Added function {new_function.name} to {yaml_file}")
+
+
+def main():
+ parser = argparse.ArgumentParser(description="Generate header files from YAML")
+ parser.add_argument(
+ "yaml_file", help="Path to the YAML file containing header specification"
+ )
+ parser.add_argument(
+ "--output_dir",
+ help="Directory to output the generated header file",
+ )
+ parser.add_argument(
+ "--h_def_file",
+ help="Path to the .h.def template file (required if not using --export_decls)",
+ )
+ parser.add_argument(
+ "--add_function",
+ nargs=6,
+ metavar=(
+ "RETURN_TYPE",
+ "NAME",
+ "ARGUMENTS",
+ "STANDARDS",
+ "GUARD",
+ "ATTRIBUTES",
+ ),
+ help="Add a function to the YAML file",
+ )
+ parser.add_argument(
+ "--e", action="append", help="Entry point to include", dest="entry_points"
+ )
+ parser.add_argument(
+ "--export-decls",
+ action="store_true",
+ help="Flag to use GpuHeader for exporting declarations",
+ )
+ args = parser.parse_args()
+
+ if args.add_function:
+ add_function_to_yaml(args.yaml_file, args.add_function)
+
+ header_class = GpuHeader if args.export_decls else HeaderFile
+ header = load_yaml_file(args.yaml_file, header_class, args.entry_points)
+
+ header_str = str(header)
+
+ if args.output_dir:
+ output_file_path = Path(args.output_dir)
+ if output_file_path.is_dir():
+ output_file_path /= f"{Path(args.yaml_file).stem}.h"
+ else:
+ output_file_path = Path(f"{Path(args.yaml_file).stem}.h")
+
+ if not args.export_decls and args.h_def_file:
+ with open(args.h_def_file, "r") as f:
+ h_def_content = f.read()
+ final_header_content = fill_public_api(header_str, h_def_content)
+ with open(output_file_path, "w") as f:
+ f.write(final_header_content)
+ else:
+ with open(output_file_path, "w") as f:
+ f.write(header_str)
+
+
+if __name__ == "__main__":
+ main()