Skip to content

Commit d6ff5e7

Browse files
authored
[libc][docs] Parse inline macro_value from YAML in docgen (#189118)
The docgen script was previously hardcoded to assume all implemented macros must be placed in a *-macros.h header. This updates docgen to read inline macro_value properties directly from the source YAML files, correctly recognizing them as implemented.
1 parent 0aba82e commit d6ff5e7

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

libc/utils/docgen/header.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,28 @@ def __init__(self, header_name: str):
4343
self.docgen_root = Path(__file__).parent
4444
self.libc_root = self.docgen_root.parent.parent
4545
self.docgen_yaml = self.docgen_root / Path(header_name).with_suffix(".yaml")
46+
# Path to libc/include/<name>.yaml
47+
self.include_yaml = Path(
48+
self.libc_root, "include", Path(header_name).with_suffix(".yaml")
49+
)
4650
self.fns_dir = Path(self.libc_root, "src", self.stem)
4751
self.macros_dir = Path(self.libc_root, "include", "llvm-libc-macros")
4852

4953
def macro_file_exists(self) -> bool:
5054
for _ in self.__get_macro_files():
5155
return True
5256

57+
if self.include_yaml.exists():
58+
import yaml
59+
60+
parsed = yaml.safe_load(self.include_yaml.read_text(encoding="utf-8"))
61+
if (
62+
parsed
63+
and "macros" in parsed
64+
and any("macro_value" in m for m in parsed["macros"])
65+
):
66+
return True
67+
5368
return False
5469

5570
def fns_dir_exists(self) -> bool:
@@ -75,6 +90,15 @@ def implements_macro(self, m_name: str) -> bool:
7590
if f"#define {m_name}" in f.read_text():
7691
return True
7792

93+
if self.include_yaml.exists():
94+
import yaml
95+
96+
parsed = yaml.safe_load(self.include_yaml.read_text(encoding="utf-8"))
97+
if parsed and "macros" in parsed:
98+
for macro in parsed["macros"]:
99+
if macro.get("macro_name") == m_name and "macro_value" in macro:
100+
return True
101+
78102
return False
79103

80104
def __get_macro_files(self) -> Generator[Path, None, None]:

0 commit comments

Comments
 (0)