Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions libc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,6 @@ if(LIBC_BUILD_GPU_LOADER OR ((NOT LLVM_RUNTIMES_BUILD) AND LLVM_LIBC_GPU_BUILD))
return()
endif()

add_subdirectory(hdrgen)

option(LIBC_CMAKE_VERBOSE_LOGGING
"Log details warnings and notifications during CMake configuration." OFF)

Expand Down
5 changes: 3 additions & 2 deletions libc/cmake/modules/LLVMLibCHeaderRules.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,10 @@ function(add_gen_header target_name)
set(entry_points "${TARGET_ENTRYPOINT_NAME_LIST}")
list(TRANSFORM entry_points PREPEND "--e=")

set(LIBC_HDRGEN "${LIBC_SOURCE_DIR}/utils/hdrgen/yaml_to_classes.py")
add_custom_command(
OUTPUT ${out_file}
COMMAND ${Python3_EXECUTABLE} ${LIBC_SOURCE_DIR}/hdrgen/yaml_to_classes.py
COMMAND ${Python3_EXECUTABLE} ${LIBC_HDRGEN}
${yaml_file}
--h_def_file ${def_file}
${entry_points}
Expand All @@ -126,7 +127,7 @@ function(add_gen_header target_name)
set(decl_out_file ${LIBC_INCLUDE_DIR}/llvm-libc-decls/${relative_path})
add_custom_command(
OUTPUT ${decl_out_file}
COMMAND ${Python3_EXECUTABLE} ${LIBC_SOURCE_DIR}/hdrgen/yaml_to_classes.py
COMMAND ${Python3_EXECUTABLE} ${LIBC_HDRGEN}
${yaml_file}
--export-decls
${entry_points}
Expand Down
27 changes: 14 additions & 13 deletions libc/docs/dev/header_generation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,15 @@ To add through the command line:

.. code-block:: none

python3 libc/hdrgen/yaml_to_classes.py
libc/hdrgen/yaml/[yaml_file.yaml] --add_function "<return_type>" <function_name> "<function_arg1, function_arg2>" <standard> <guard> <attribute>
python3 libc/utils/hdrgen/yaml_to_classes.py
libc/utils/hdrgen/yaml/[yaml_file.yaml] --add_function "<return_type>" <function_name> "<function_arg1, function_arg2>" <standard> <guard> <attribute>

Example:

.. code-block:: none

python3 libc/hdrgen/yaml_to_classes.py
libc/hdrgen/yaml/ctype.yaml --add_function "char" example_function
python3 libc/utils/hdrgen/yaml_to_classes.py
libc/utils/hdrgen/yaml/ctype.yaml --add_function "char" example_function
"int, void, const void" stdc example_float example_attribute

Keep in mind only the return_type and arguments have quotes around them. If
Expand All @@ -62,7 +62,8 @@ To add through the command line:
generated header file with the new addition in the hdrgen directory to
examine.

If you want to sort the functions alphabetically you can check out libc/hdrgen/yaml_functions_sorted.py.
If you want to sort the functions alphabetically you can check out
libc/utils/hdrgen/yaml_functions_sorted.py.


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

Integration Test can be found in: ``libc/hdrgen/tests/test_integration.py``
Integration Test can be found in: ``libc/utils/hdrgen/tests/test_integration.py``

File to modify if adding something to formatting:
``libc/hdrgen/tests/expected_output/test_header.h``
``libc/utils/hdrgen/tests/expected_output/test_header.h``


Common Errors
Expand All @@ -89,7 +90,7 @@ Common Errors

.. code-block:: none

"/llvm-project/libc/hdrgen/yaml_to_classes.py", line 67, in yaml_to_classes function_data["return_type"]
"/llvm-project/libc/utils/hdrgen/yaml_to_classes.py", line 67, in yaml_to_classes function_data["return_type"]

If you receive this error or any error pertaining to
``function_data[function_specific_component]`` while building the headers
Expand Down Expand Up @@ -117,7 +118,7 @@ Common Errors
missing. Ensure the correct style and required files are present:

| ``[header_name]``
| ``[../libc/hdrgen/yaml/[yaml_file.yaml]``
| ``[../libc/utils/hdrgen/yaml/[yaml_file.yaml]``
| ``[header_name.h.def]``
| ``[header_name.h]``
| ``DEPENDS``
Expand Down Expand Up @@ -147,13 +148,13 @@ Common Errors

.. code-block:: none

File "/llvm-project/libc/hdrgen/header.py", line 60, in __str__ for
File "/llvm-project/libc/utils/hdrgen/header.py", line 60, in __str__ for
function in self.functions: AttributeError: 'HeaderFile' object has no
attribute 'functions'

When running ``ninja libc`` in the build directory to generate headers you
may receive the error above. Essentially this means that in
``libc/hdrgen/header.py`` there is a missing attribute named functions.
``libc/utils/hdrgen/header.py`` there is a missing attribute named functions.
Make sure all function components are defined within this file and there are
no missing functions to add these components.

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

If the integration tests are failing due to mismatching of lines or small
errors in spacing that is nothing to worry about. If this is happening while
you are making a new change to the formatting of the headers, then
ensure the expected output file
``libc/hdrgen/tests/expected_output/test_header.h`` has the changes you
``libc/utils/hdrgen/tests/expected_output/test_header.h`` has the changes you
are applying.
10 changes: 0 additions & 10 deletions libc/docs/dev/source_tree_layout.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ directories::
- examples
- fuzzing
- hdr
- hdrgen
- include
- lib
- src
Expand Down Expand Up @@ -88,15 +87,6 @@ The ``lib`` directory
This directory contains a ``CMakeLists.txt`` file listing the targets for the
public libraries ``libc.a``, ``libm.a`` etc.

The ``hdrgen`` directory
---------------------------

This directory contains the sources and specifications for the types, macros
and entrypoint functions. These definitions are organized in the ``yaml``
subdirectory and match the organization of the ``*.h.def`` files. This folder
also contains the python sources for headergen, which is what generates the
headers.

The ``src`` directory
---------------------

Expand Down
14 changes: 7 additions & 7 deletions libc/docs/full_cross_build.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Full Cross Build
:depth: 1
:local:

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

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

CMake configure step
--------------------
Expand Down Expand Up @@ -151,8 +151,8 @@ built using any of the three recipes described above.
Building for the GPU
====================

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