Files
TheRock/compiler/amd-llvm/libc/docs/dev/implementing_a_function.rst
T
derek.holloway 7502bf64a4
CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
Flatten subprojects into a single base monorepo
2026-09-02 16:34:47 -07:00

70 lines
2.3 KiB
ReStructuredText

.. _implementing_a_function:
===========================
Implementing a New Function
===========================
This guide provides a step-by-step walkthrough for adding a new function to LLVM-libc.
Overview
========
Adding a new function involves several steps, from updating the public specification to implementing and testing the code. Below is the standard checklist for contributors.
Step-by-Step Checklist
======================
1. Header Entry
---------------
Update the standard YAML file that describes the public header to ensure the function is included in the generated public header.
* **File**: ``libc/include/<header>.yaml`` (or ``libc/include/sys/<header>.yaml`` for system headers)
* Add the new function to the ``functions`` list.
* Specify its name, return type, and arguments.
* List the standards it complies with (e.g., ``stdc``, ``POSIX``).
2. Header Declaration
---------------------
Declare the function in the internal implementation header file. This file is used by other internal code.
* **File**: ``libc/src/<header>/<func>.h``
* Follow the structure defined in :ref:`implementation_standard`.
* Ensure the declaration is inside the ``LIBC_NAMESPACE_DECL`` namespace.
3. Implementation
-----------------
Write the actual code for the function.
* **File**: ``libc/src/<header>/<func>.cpp`` (or ``libc/src/<header>/<os>/<func>.cpp`` for platform-specific implementations)
* Use the ``LLVM_LIBC_FUNCTION`` macro.
* Refer to :ref:`code_style` for naming and layout conventions.
4. CMake Rule
-------------
Add a CMake target for the new function so it can be compiled.
* **File**: ``libc/src/<header>/CMakeLists.txt``
* Add an ``add_entrypoint_object`` rule for the new file.
* List all internal dependencies correctly to ensure proper build order.
5. Platform Registration
------------------------
Register the new entrypoint for the target platforms to include it in the build.
* **File**: ``libc/config/<os>/<arch>/entrypoints.txt``
* Add the new function to the list of active entrypoints.
6. Testing
----------
Create tests to verify the implementation.
* **File**: ``libc/test/src/<header>/<func>_test.cpp``
* Add corresponding tests using the internal testing framework.
* Update the ``CMakeLists.txt`` in the test directory (``libc/test/src/<header>/CMakeLists.txt``) to include the new test target.