Skip to content

Commit e17d2b5

Browse files
[libc][docgen] support non-top-level headers (#119621)
such as arpa/inet, sys/*
1 parent 4cce107 commit e17d2b5

File tree

7 files changed

+328
-5
lines changed

7 files changed

+328
-5
lines changed

libc/docs/headers/arpa/inet.rst

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
.. include:: ../../check.rst
2+
3+
===========
4+
arpa/inet.h
5+
===========
6+
7+
Functions
8+
=========
9+
10+
.. list-table::
11+
:widths: auto
12+
:align: center
13+
:header-rows: 1
14+
15+
* - Function
16+
- Implemented
17+
- C23 Standard Section
18+
- POSIX.1-2024 Standard Section
19+
* - htonl
20+
- |check|
21+
-
22+
-
23+
* - htons
24+
- |check|
25+
-
26+
-
27+
* - inet_addr
28+
-
29+
-
30+
-
31+
* - inet_ntoa
32+
-
33+
-
34+
-
35+
* - inet_ntop
36+
-
37+
-
38+
-
39+
* - inet_pton
40+
-
41+
-
42+
-
43+
* - ntohl
44+
- |check|
45+
-
46+
-
47+
* - ntohs
48+
- |check|
49+
-
50+
-

libc/docs/headers/index.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Implementation Status
44
.. toctree::
55
:maxdepth: 1
66

7+
arpa/inet
78
assert
89
complex
910
ctype
@@ -21,6 +22,7 @@ Implementation Status
2122
stdlib
2223
string
2324
strings
25+
sys/mman
2426
threads
2527
time
2628
uchar

libc/docs/headers/sys/mman.rst

Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
.. include:: ../../check.rst
2+
3+
==========
4+
sys/mman.h
5+
==========
6+
7+
Macros
8+
======
9+
10+
.. list-table::
11+
:widths: auto
12+
:align: center
13+
:header-rows: 1
14+
15+
* - Macro
16+
- Implemented
17+
- C23 Standard Section
18+
- POSIX.1-2024 Standard Section
19+
* - MAP_ANON
20+
-
21+
-
22+
-
23+
* - MAP_ANONYMOUS
24+
-
25+
-
26+
-
27+
* - MAP_FAILED
28+
- |check|
29+
-
30+
-
31+
* - MAP_FIXED
32+
-
33+
-
34+
-
35+
* - MAP_PRIVATE
36+
-
37+
-
38+
-
39+
* - MAP_SHARED
40+
-
41+
-
42+
-
43+
* - MCL_CURRENT
44+
-
45+
-
46+
-
47+
* - MCL_FUTURE
48+
-
49+
-
50+
-
51+
* - MS_ASYNC
52+
-
53+
-
54+
-
55+
* - MS_INVALIDATE
56+
-
57+
-
58+
-
59+
* - MS_SYNC
60+
-
61+
-
62+
-
63+
* - POSIX_MADV_DONTNEED
64+
- |check|
65+
-
66+
-
67+
* - POSIX_MADV_NORMAL
68+
- |check|
69+
-
70+
-
71+
* - POSIX_MADV_RANDOM
72+
- |check|
73+
-
74+
-
75+
* - POSIX_MADV_SEQUENTIAL
76+
- |check|
77+
-
78+
-
79+
* - POSIX_MADV_WILLNEED
80+
- |check|
81+
-
82+
-
83+
* - POSIX_TYPED_MEM_ALLOCATE
84+
-
85+
-
86+
-
87+
* - POSIX_TYPED_MEM_ALLOCATE_CONTIG
88+
-
89+
-
90+
-
91+
* - POSIX_TYPED_MEM_MAP_ALLOCATABLE
92+
-
93+
-
94+
-
95+
* - PROT_EXEC
96+
-
97+
-
98+
-
99+
* - PROT_NONE
100+
-
101+
-
102+
-
103+
* - PROT_READ
104+
-
105+
-
106+
-
107+
* - PROT_WRITE
108+
-
109+
-
110+
-
111+
112+
Functions
113+
=========
114+
115+
.. list-table::
116+
:widths: auto
117+
:align: center
118+
:header-rows: 1
119+
120+
* - Function
121+
- Implemented
122+
- C23 Standard Section
123+
- POSIX.1-2024 Standard Section
124+
* - mlock
125+
- |check|
126+
-
127+
-
128+
* - mlockall
129+
- |check|
130+
-
131+
-
132+
* - mmap
133+
- |check|
134+
-
135+
-
136+
* - mprotect
137+
- |check|
138+
-
139+
-
140+
* - msync
141+
- |check|
142+
-
143+
-
144+
* - munlock
145+
- |check|
146+
-
147+
-
148+
* - munlockall
149+
- |check|
150+
-
151+
-
152+
* - munmap
153+
- |check|
154+
-
155+
-
156+
* - posix_madvise
157+
- |check|
158+
-
159+
-
160+
* - posix_mem_offset
161+
-
162+
-
163+
-
164+
* - posix_typed_mem_get_info
165+
-
166+
-
167+
-
168+
* - posix_typed_mem_open
169+
-
170+
-
171+
-
172+
* - shm_open
173+
- |check|
174+
-
175+
-
176+
* - shm_unlink
177+
- |check|
178+
-
179+
-

libc/utils/docgen/arpa/inet.json

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"functions": {
3+
"htonl" : {
4+
"posix-definition": ""
5+
},
6+
"htons": {
7+
"posix-definition": ""
8+
},
9+
"ntohl": {
10+
"posix-definition": ""
11+
},
12+
"ntohs": {
13+
"posix-definition": ""
14+
},
15+
"inet_addr": {
16+
"posix-definition": ""
17+
},
18+
"inet_ntoa": {
19+
"posix-definition": ""
20+
},
21+
"inet_ntop": {
22+
"posix-definition": ""
23+
},
24+
"inet_pton": {
25+
"posix-definition": ""
26+
}
27+
}
28+
}

libc/utils/docgen/docgen.py

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@
1010
from argparse import ArgumentParser, Namespace
1111
from pathlib import Path
1212
from typing import Dict
13-
import sys
1413
import json
14+
import os
15+
import sys
1516

1617
from header import Header
1718

@@ -161,7 +162,10 @@ def print_macros_rst(header: Header, macros: Dict):
161162

162163

163164
def print_impl_status_rst(header: Header, api: Dict):
164-
print(".. include:: ../check.rst\n")
165+
if os.sep in header.name:
166+
print(".. include:: ../../check.rst\n")
167+
else:
168+
print(".. include:: ../check.rst\n")
165169

166170
print("=" * len(header.name))
167171
print(header.name)
@@ -176,10 +180,22 @@ def print_impl_status_rst(header: Header, api: Dict):
176180
print_functions_rst(header, api["functions"])
177181

178182

183+
# This code implicitly relies on docgen.py being in the same dir as the json
184+
# files and is likely to need to be fixed when re-integrating docgen into
185+
# hdrgen.
186+
def get_choices() -> List:
187+
choices = []
188+
for path in Path(__file__).parent.rglob("*.json"):
189+
fname = path.with_suffix(".h").name
190+
if path.parent != Path(__file__).parent:
191+
fname = path.parent.name + os.sep + fname
192+
choices.append(fname)
193+
return choices
194+
195+
179196
def parse_args() -> Namespace:
180197
parser = ArgumentParser()
181-
choices = [p.with_suffix(".h").name for p in Path(__file__).parent.glob("*.json")]
182-
parser.add_argument("header_name", choices=choices)
198+
parser.add_argument("header_name", choices=get_choices())
183199
return parser.parse_args()
184200

185201

libc/utils/docgen/header.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,5 +83,10 @@ def __get_macro_files(self) -> Generator[Path, None, None]:
8383
macro file might be located in a subdirectory:
8484
libc/include/llvm-libc-macros/fcntl-macros.h
8585
libc/include/llvm-libc-macros/linux/fcntl-macros.h
86+
87+
When a header would be nested in a dir (such as arpa/, sys/, etc) we
88+
instead use a hyphen in the name.
89+
libc/include/llvm-libc-macros/sys-mman-macros.h
8690
"""
87-
return self.macros_dir.glob(f"**/{self.stem}-macros.h")
91+
stem = self.stem.replace("/", "-")
92+
return self.macros_dir.glob(f"**/{stem}-macros.h")

libc/utils/docgen/sys/mman.json

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
{
2+
"macros": {
3+
"PROT_EXEC": { "posix-definition": "" },
4+
"PROT_NONE": { "posix-definition": "" },
5+
"PROT_READ": { "posix-definition": "" },
6+
"PROT_WRITE": { "posix-definition": "" },
7+
"MAP_ANON": { "posix-definition": "" },
8+
"MAP_ANONYMOUS": { "posix-definition": "" },
9+
"MAP_FIXED": { "posix-definition": "" },
10+
"MAP_PRIVATE": { "posix-definition": "" },
11+
"MAP_SHARED": { "posix-definition": "" },
12+
"MS_ASYNC": { "posix-definition": "" },
13+
"MS_INVALIDATE": { "posix-definition": "" },
14+
"MS_SYNC": { "posix-definition": "" },
15+
"MCL_CURRENT": { "posix-definition": "" },
16+
"MCL_FUTURE": { "posix-definition": "" },
17+
"MAP_FAILED": { "posix-definition": "" },
18+
"POSIX_MADV_DONTNEED": { "posix-definition": "" },
19+
"POSIX_MADV_NORMAL": { "posix-definition": "" },
20+
"POSIX_MADV_RANDOM": { "posix-definition": "" },
21+
"POSIX_MADV_SEQUENTIAL": { "posix-definition": "" },
22+
"POSIX_MADV_WILLNEED": { "posix-definition": "" },
23+
"POSIX_TYPED_MEM_ALLOCATE": { "posix-definition": "" },
24+
"POSIX_TYPED_MEM_ALLOCATE_CONTIG": { "posix-definition": "" },
25+
"POSIX_TYPED_MEM_MAP_ALLOCATABLE": { "posix-definition": "" }
26+
},
27+
"functions": {
28+
"mlock": { "posix-definition": "" },
29+
"mlockall": { "posix-definition": "" },
30+
"mmap": { "posix-definition": "" },
31+
"mprotect": { "posix-definition": "" },
32+
"msync": { "posix-definition": "" },
33+
"munlock": { "posix-definition": "" },
34+
"munlockall": { "posix-definition": "" },
35+
"munmap": { "posix-definition": "" },
36+
"posix_madvise": { "posix-definition": "" },
37+
"posix_mem_offset": { "posix-definition": "" },
38+
"posix_typed_mem_get_info": { "posix-definition": "" },
39+
"posix_typed_mem_open": { "posix-definition": "" },
40+
"shm_open": { "posix-definition": "" },
41+
"shm_unlink": { "posix-definition": "" }
42+
}
43+
}

0 commit comments

Comments
 (0)