Skip to content

Commit 9abcca5

Browse files
authored
[libc] Move hdrgen into utils/ subdirectory (#121256)
1 parent 0897373 commit 9abcca5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+95
-98
lines changed

libc/CMakeLists.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,6 @@ if(LIBC_BUILD_GPU_LOADER OR ((NOT LLVM_RUNTIMES_BUILD) AND LLVM_LIBC_GPU_BUILD))
6464
return()
6565
endif()
6666

67-
add_subdirectory(hdrgen)
68-
6967
option(LIBC_CMAKE_VERBOSE_LOGGING
7068
"Log details warnings and notifications during CMake configuration." OFF)
7169

libc/cmake/modules/LLVMLibCHeaderRules.cmake

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,10 @@ function(add_gen_header target_name)
110110
set(entry_points "${TARGET_ENTRYPOINT_NAME_LIST}")
111111
list(TRANSFORM entry_points PREPEND "--e=")
112112

113+
set(LIBC_HDRGEN "${LIBC_SOURCE_DIR}/utils/hdrgen/yaml_to_classes.py")
113114
add_custom_command(
114115
OUTPUT ${out_file}
115-
COMMAND ${Python3_EXECUTABLE} ${LIBC_SOURCE_DIR}/hdrgen/yaml_to_classes.py
116+
COMMAND ${Python3_EXECUTABLE} ${LIBC_HDRGEN}
116117
${yaml_file}
117118
--h_def_file ${def_file}
118119
${entry_points}
@@ -126,7 +127,7 @@ function(add_gen_header target_name)
126127
set(decl_out_file ${LIBC_INCLUDE_DIR}/llvm-libc-decls/${relative_path})
127128
add_custom_command(
128129
OUTPUT ${decl_out_file}
129-
COMMAND ${Python3_EXECUTABLE} ${LIBC_SOURCE_DIR}/hdrgen/yaml_to_classes.py
130+
COMMAND ${Python3_EXECUTABLE} ${LIBC_HDRGEN}
130131
${yaml_file}
131132
--export-decls
132133
${entry_points}

libc/docs/dev/header_generation.rst

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,15 @@ To add through the command line:
4444

4545
.. code-block:: none
4646
47-
python3 libc/hdrgen/yaml_to_classes.py
48-
libc/hdrgen/yaml/[yaml_file.yaml] --add_function "<return_type>" <function_name> "<function_arg1, function_arg2>" <standard> <guard> <attribute>
47+
python3 libc/utils/hdrgen/yaml_to_classes.py
48+
libc/utils/hdrgen/yaml/[yaml_file.yaml] --add_function "<return_type>" <function_name> "<function_arg1, function_arg2>" <standard> <guard> <attribute>
4949
5050
Example:
5151

5252
.. code-block:: none
5353
54-
python3 libc/hdrgen/yaml_to_classes.py
55-
libc/hdrgen/yaml/ctype.yaml --add_function "char" example_function
54+
python3 libc/utils/hdrgen/yaml_to_classes.py
55+
libc/utils/hdrgen/yaml/ctype.yaml --add_function "char" example_function
5656
"int, void, const void" stdc example_float example_attribute
5757
5858
Keep in mind only the return_type and arguments have quotes around them. If
@@ -62,7 +62,8 @@ To add through the command line:
6262
generated header file with the new addition in the hdrgen directory to
6363
examine.
6464

65-
If you want to sort the functions alphabetically you can check out libc/hdrgen/yaml_functions_sorted.py.
65+
If you want to sort the functions alphabetically you can check out
66+
libc/utils/hdrgen/yaml_functions_sorted.py.
6667

6768

6869
Testing
@@ -75,10 +76,10 @@ ensures the process of YAML to classes to generate headers works properly. If
7576
there are any new additions on formatting headers, make sure the test is
7677
updated with the specific addition.
7778

78-
Integration Test can be found in: ``libc/hdrgen/tests/test_integration.py``
79+
Integration Test can be found in: ``libc/utils/hdrgen/tests/test_integration.py``
7980

8081
File to modify if adding something to formatting:
81-
``libc/hdrgen/tests/expected_output/test_header.h``
82+
``libc/utils/hdrgen/tests/expected_output/test_header.h``
8283

8384

8485
Common Errors
@@ -89,7 +90,7 @@ Common Errors
8990

9091
.. code-block:: none
9192
92-
"/llvm-project/libc/hdrgen/yaml_to_classes.py", line 67, in yaml_to_classes function_data["return_type"]
93+
"/llvm-project/libc/utils/hdrgen/yaml_to_classes.py", line 67, in yaml_to_classes function_data["return_type"]
9394
9495
If you receive this error or any error pertaining to
9596
``function_data[function_specific_component]`` while building the headers
@@ -117,7 +118,7 @@ Common Errors
117118
missing. Ensure the correct style and required files are present:
118119

119120
| ``[header_name]``
120-
| ``[../libc/hdrgen/yaml/[yaml_file.yaml]``
121+
| ``[../libc/utils/hdrgen/yaml/[yaml_file.yaml]``
121122
| ``[header_name.h.def]``
122123
| ``[header_name.h]``
123124
| ``DEPENDS``
@@ -147,13 +148,13 @@ Common Errors
147148

148149
.. code-block:: none
149150
150-
File "/llvm-project/libc/hdrgen/header.py", line 60, in __str__ for
151+
File "/llvm-project/libc/utils/hdrgen/header.py", line 60, in __str__ for
151152
function in self.functions: AttributeError: 'HeaderFile' object has no
152153
attribute 'functions'
153154
154155
When running ``ninja libc`` in the build directory to generate headers you
155156
may receive the error above. Essentially this means that in
156-
``libc/hdrgen/header.py`` there is a missing attribute named functions.
157+
``libc/utils/hdrgen/header.py`` there is a missing attribute named functions.
157158
Make sure all function components are defined within this file and there are
158159
no missing functions to add these components.
159160

@@ -184,12 +185,12 @@ Common Errors
184185
Sometimes the integration test will fail but that
185186
still means the process is working unless the comparison between the output
186187
and expected_output is not showing. If that is the case make sure in
187-
``libc/hdrgen/tests/test_integration.py`` there are no missing arguments
188+
``libc/utils/hdrgen/tests/test_integration.py`` there are no missing arguments
188189
that run through the script.
189190

190191
If the integration tests are failing due to mismatching of lines or small
191192
errors in spacing that is nothing to worry about. If this is happening while
192193
you are making a new change to the formatting of the headers, then
193194
ensure the expected output file
194-
``libc/hdrgen/tests/expected_output/test_header.h`` has the changes you
195+
``libc/utils/hdrgen/tests/expected_output/test_header.h`` has the changes you
195196
are applying.

libc/docs/dev/source_tree_layout.rst

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ directories::
1515
- examples
1616
- fuzzing
1717
- hdr
18-
- hdrgen
1918
- include
2019
- lib
2120
- src
@@ -88,15 +87,6 @@ The ``lib`` directory
8887
This directory contains a ``CMakeLists.txt`` file listing the targets for the
8988
public libraries ``libc.a``, ``libm.a`` etc.
9089

91-
The ``hdrgen`` directory
92-
---------------------------
93-
94-
This directory contains the sources and specifications for the types, macros
95-
and entrypoint functions. These definitions are organized in the ``yaml``
96-
subdirectory and match the organization of the ``*.h.def`` files. This folder
97-
also contains the python sources for headergen, which is what generates the
98-
headers.
99-
10090
The ``src`` directory
10191
---------------------
10292

libc/docs/full_cross_build.rst

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Full Cross Build
88
:depth: 1
99
:local:
1010

11-
.. note::
11+
.. note::
1212
Fullbuild requires running headergen, which is a python program that depends on
1313
pyyaml. The minimum versions are listed on the :ref:`header_generation`
1414
page, as well as additional information.
@@ -95,8 +95,8 @@ configure step.
9595
Bootstrap cross build
9696
=====================
9797

98-
In this recipe, the clang compiler and the ``libc-hdrgen`` binary, both are
99-
built automatically before building the libc for the target.
98+
In this recipe, the clang compiler is built automatically before building
99+
the libc for the target.
100100

101101
CMake configure step
102102
--------------------
@@ -151,8 +151,8 @@ built using any of the three recipes described above.
151151
Building for the GPU
152152
====================
153153

154-
To build for a GPU architecture, it should only be necessary to specify the
155-
target triple as one of the supported GPU targets. Currently, this is either
156-
``nvptx64-nvidia-cuda`` for NVIDIA GPUs or ``amdgcn-amd-amdhsa`` for AMD GPUs.
157-
More detailed information is provided in the :ref:`GPU
154+
To build for a GPU architecture, it should only be necessary to specify the
155+
target triple as one of the supported GPU targets. Currently, this is either
156+
``nvptx64-nvidia-cuda`` for NVIDIA GPUs or ``amdgcn-amd-amdhsa`` for AMD GPUs.
157+
More detailed information is provided in the :ref:`GPU
158158
documentation<libc_gpu_building>`.

0 commit comments

Comments
 (0)