[libc-commits] [libc] e17d2b5 - [libc][docgen] support non-top-level headers (#119621)

via libc-commits libc-commits at lists.llvm.org
Thu Dec 12 09:21:08 PST 2024


Author: Nick Desaulniers
Date: 2024-12-12T09:21:04-08:00
New Revision: e17d2b585b4d35b9cab0673cf77a35fa933dd030

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

LOG: [libc][docgen] support non-top-level headers (#119621)

such as arpa/inet, sys/*

Added: 
    libc/docs/headers/arpa/inet.rst
    libc/docs/headers/sys/mman.rst
    libc/utils/docgen/arpa/inet.json
    libc/utils/docgen/sys/mman.json

Modified: 
    libc/docs/headers/index.rst
    libc/utils/docgen/docgen.py
    libc/utils/docgen/header.py

Removed: 
    


################################################################################
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..e3404205c07aca
--- /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
+    - |check|
+    -
+    - 
+  * - MAP_FIXED
+    -
+    -
+    - 
+  * - MAP_PRIVATE
+    -
+    -
+    - 
+  * - MAP_SHARED
+    -
+    -
+    - 
+  * - MCL_CURRENT
+    -
+    -
+    - 
+  * - MCL_FUTURE
+    -
+    -
+    - 
+  * - MS_ASYNC
+    -
+    -
+    - 
+  * - MS_INVALIDATE
+    -
+    -
+    - 
+  * - MS_SYNC
+    -
+    -
+    - 
+  * - POSIX_MADV_DONTNEED
+    - |check|
+    -
+    - 
+  * - POSIX_MADV_NORMAL
+    - |check|
+    -
+    - 
+  * - POSIX_MADV_RANDOM
+    - |check|
+    -
+    - 
+  * - POSIX_MADV_SEQUENTIAL
+    - |check|
+    -
+    - 
+  * - POSIX_MADV_WILLNEED
+    - |check|
+    -
+    - 
+  * - 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..3c8b33a9b8fb2d 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() -> List:
+    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/header.py b/libc/utils/docgen/header.py
index dde210078db278..7728a0f1d5b44c 100644
--- a/libc/utils/docgen/header.py
+++ b/libc/utils/docgen/header.py
@@ -83,5 +83,10 @@ def __get_macro_files(self) -> Generator[Path, None, None]:
         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/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": "" }
+  }
+}


        


More information about the libc-commits mailing list