[libc-commits] [libc] [libc][docgen] basic support for non-top-level headers (PR #119621)

via libc-commits libc-commits at lists.llvm.org
Wed Dec 11 14:08:02 PST 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-libc

Author: Nick Desaulniers (nickdesaulniers)

<details>
<summary>Changes</summary>

such as arpa/inet, sys/*


---
Full diff: https://github.com/llvm/llvm-project/pull/119621.diff


6 Files Affected:

- (added) libc/docs/headers/arpa/inet.rst (+50) 
- (modified) libc/docs/headers/index.rst (+2) 
- (added) libc/docs/headers/sys/mman.rst (+179) 
- (added) libc/utils/docgen/arpa/inet.json (+28) 
- (modified) libc/utils/docgen/docgen.py (+20-4) 
- (added) libc/utils/docgen/sys/mman.json (+43) 


``````````diff
diff --git a/libc/docs/headers/arpa/inet.rst b/libc/docs/headers/arpa/inet.rst
new file mode 100644
index 00000000000000..c82ca5427fbbb7
--- /dev/null
+++ b/libc/docs/headers/arpa/inet.rst
@@ -0,0 +1,50 @@
+.. include:: ../../check.rst
+
+===========
+arpa/inet.h
+===========
+
+Functions
+=========
+
+.. list-table::
+  :widths: auto
+  :align: center
+  :header-rows: 1
+
+  * - Function
+    - Implemented
+    - C23 Standard Section
+    - POSIX.1-2024 Standard Section
+  * - htonl
+    - |check|
+    -
+    - 
+  * - htons
+    - |check|
+    -
+    - 
+  * - inet_addr
+    -
+    -
+    - 
+  * - inet_ntoa
+    -
+    -
+    - 
+  * - inet_ntop
+    -
+    -
+    - 
+  * - inet_pton
+    -
+    -
+    - 
+  * - ntohl
+    - |check|
+    -
+    - 
+  * - ntohs
+    - |check|
+    -
+    - 
diff --git a/libc/docs/headers/index.rst b/libc/docs/headers/index.rst
index 9bd6396843e786..07ab6dd9b26742 100644
--- a/libc/docs/headers/index.rst
+++ b/libc/docs/headers/index.rst
@@ -4,6 +4,7 @@ Implementation Status
 .. toctree::
    :maxdepth: 1
 
+   arpa/inet
    assert
    complex
    ctype
@@ -21,6 +22,7 @@ Implementation Status
    stdlib
    string
    strings
+   sys/mman
    threads
    time
    uchar
diff --git a/libc/docs/headers/sys/mman.rst b/libc/docs/headers/sys/mman.rst
new file mode 100644
index 00000000000000..62a7b68e823582
--- /dev/null
+++ b/libc/docs/headers/sys/mman.rst
@@ -0,0 +1,179 @@
+.. include:: ../../check.rst
+
+==========
+sys/mman.h
+==========
+
+Macros
+======
+
+.. list-table::
+  :widths: auto
+  :align: center
+  :header-rows: 1
+
+  * - Macro
+    - Implemented
+    - C23 Standard Section
+    - POSIX.1-2024 Standard Section
+  * - MAP_ANON
+    -
+    -
+    - 
+  * - MAP_ANONYMOUS
+    -
+    -
+    - 
+  * - MAP_FAILED
+    -
+    -
+    - 
+  * - MAP_FIXED
+    -
+    -
+    - 
+  * - MAP_PRIVATE
+    -
+    -
+    - 
+  * - MAP_SHARED
+    -
+    -
+    - 
+  * - MCL_CURRENT
+    -
+    -
+    - 
+  * - MCL_FUTURE
+    -
+    -
+    - 
+  * - MS_ASYNC
+    -
+    -
+    - 
+  * - MS_INVALIDATE
+    -
+    -
+    - 
+  * - MS_SYNC
+    -
+    -
+    - 
+  * - POSIX_MADV_DONTNEED
+    -
+    -
+    - 
+  * - POSIX_MADV_NORMAL
+    -
+    -
+    - 
+  * - POSIX_MADV_RANDOM
+    -
+    -
+    - 
+  * - POSIX_MADV_SEQUENTIAL
+    -
+    -
+    - 
+  * - POSIX_MADV_WILLNEED
+    -
+    -
+    - 
+  * - POSIX_TYPED_MEM_ALLOCATE
+    -
+    -
+    - 
+  * - POSIX_TYPED_MEM_ALLOCATE_CONTIG
+    -
+    -
+    - 
+  * - POSIX_TYPED_MEM_MAP_ALLOCATABLE
+    -
+    -
+    - 
+  * - PROT_EXEC
+    -
+    -
+    - 
+  * - PROT_NONE
+    -
+    -
+    - 
+  * - PROT_READ
+    -
+    -
+    - 
+  * - PROT_WRITE
+    -
+    -
+    - 
+
+Functions
+=========
+
+.. list-table::
+  :widths: auto
+  :align: center
+  :header-rows: 1
+
+  * - Function
+    - Implemented
+    - C23 Standard Section
+    - POSIX.1-2024 Standard Section
+  * - mlock
+    - |check|
+    -
+    - 
+  * - mlockall
+    - |check|
+    -
+    - 
+  * - mmap
+    - |check|
+    -
+    - 
+  * - mprotect
+    - |check|
+    -
+    - 
+  * - msync
+    - |check|
+    -
+    - 
+  * - munlock
+    - |check|
+    -
+    - 
+  * - munlockall
+    - |check|
+    -
+    - 
+  * - munmap
+    - |check|
+    -
+    - 
+  * - posix_madvise
+    - |check|
+    -
+    - 
+  * - posix_mem_offset
+    -
+    -
+    - 
+  * - posix_typed_mem_get_info
+    -
+    -
+    - 
+  * - posix_typed_mem_open
+    -
+    -
+    - 
+  * - shm_open
+    - |check|
+    -
+    - 
+  * - shm_unlink
+    - |check|
+    -
+    - 
diff --git a/libc/utils/docgen/arpa/inet.json b/libc/utils/docgen/arpa/inet.json
new file mode 100644
index 00000000000000..0e788c57d5f7ae
--- /dev/null
+++ b/libc/utils/docgen/arpa/inet.json
@@ -0,0 +1,28 @@
+{
+  "functions": {
+    "htonl" : {
+      "posix-definition": ""
+    },
+    "htons": {
+      "posix-definition": ""
+    },
+    "ntohl": {
+      "posix-definition": ""
+    },
+    "ntohs": {
+      "posix-definition": ""
+    },
+    "inet_addr": {
+      "posix-definition": ""
+    },
+    "inet_ntoa": {
+      "posix-definition": ""
+    },
+    "inet_ntop": {
+      "posix-definition": ""
+    },
+    "inet_pton": {
+      "posix-definition": ""
+    }
+  }
+}
diff --git a/libc/utils/docgen/docgen.py b/libc/utils/docgen/docgen.py
index aa30a6e51ef870..3bff93be708109 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 sys
 import json
+import os
+import sys
 
 from header import Header
 
@@ -161,7 +162,10 @@ def print_macros_rst(header: Header, macros: Dict):
 
 
 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 +180,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 json
+# files and is likely to need to be fixed when re-integrating docgen into
+# hdrgen.
+def get_choices():
+    choices = []
+    for path in Path(__file__).parent.rglob("*.json"):
+        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/sys/mman.json b/libc/utils/docgen/sys/mman.json
new file mode 100644
index 00000000000000..59f904fcfea975
--- /dev/null
+++ b/libc/utils/docgen/sys/mman.json
@@ -0,0 +1,43 @@
+{
+  "macros": {
+    "PROT_EXEC": { "posix-definition": "" },
+    "PROT_NONE": { "posix-definition": "" },
+    "PROT_READ": { "posix-definition": "" },
+    "PROT_WRITE": { "posix-definition": "" },
+    "MAP_ANON": { "posix-definition": "" },
+    "MAP_ANONYMOUS": { "posix-definition": "" },
+    "MAP_FIXED": { "posix-definition": "" },
+    "MAP_PRIVATE": { "posix-definition": "" },
+    "MAP_SHARED": { "posix-definition": "" },
+    "MS_ASYNC": { "posix-definition": "" },
+    "MS_INVALIDATE": { "posix-definition": "" },
+    "MS_SYNC": { "posix-definition": "" },
+    "MCL_CURRENT": { "posix-definition": "" },
+    "MCL_FUTURE": { "posix-definition": "" },
+    "MAP_FAILED": { "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": "" }
+  },
+  "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": "" }
+  }
+}

``````````

</details>


https://github.com/llvm/llvm-project/pull/119621


More information about the libc-commits mailing list