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
77 lines
2.8 KiB
ReStructuredText
77 lines
2.8 KiB
ReStructuredText
.. _implementation_standard:
|
|
|
|
Convention for implementing entrypoints
|
|
=======================================
|
|
|
|
The implementations of LLVM-libc entrypoints live in the ``src/`` directory,
|
|
organized by the public header they belong to. Some entrypoints are platform-
|
|
specific, and so their implementations are in a subdirectory with the name of
|
|
the platform (e.g., ``stdio/linux/remove.cpp``).
|
|
|
|
For a complete overview of what an entrypoint is and how it is managed in the
|
|
build system, see the :ref:`entrypoints` documentation.
|
|
|
|
|
|
Implementation of entrypoints can span multiple ``.cpp`` and ``.h`` files, but
|
|
there will be at least one header file with name of the form
|
|
``<entrypoint name>.h`` for every entrypoint. This header file is called the
|
|
implementation header file. For the ``isalpha`` function, the path to the
|
|
implementation header file is ``src/ctype/isalpha.h``.
|
|
|
|
Implementation Header File Structure
|
|
------------------------------------
|
|
|
|
We will use the ``isalpha`` function from the public ``ctype.h`` header file as an
|
|
example. The ``isalpha`` function will be declared in an internal header file
|
|
``src/ctype/isalpha.h`` as follows::
|
|
|
|
// --- isalpha.h --- //
|
|
#ifndef LLVM_LIBC_SRC_CTYPE_ISALPHA_H
|
|
#define LLVM_LIBC_SRC_CTYPE_ISALPHA_H
|
|
|
|
namespace LIBC_NAMESPACE_DECL {
|
|
|
|
int isalpha(int c);
|
|
|
|
} // namespace LIBC_NAMESPACE_DECL
|
|
|
|
#endif LLVM_LIBC_SRC_CTYPE_ISALPHA_H
|
|
|
|
All LLVM-libc implementation constructs must be enclosed in the
|
|
``LIBC_NAMESPACE_DECL`` namespace. See :ref:`code_style` for the full technical
|
|
rationale and macro definitions.
|
|
|
|
``.cpp`` File Structure
|
|
-----------------------
|
|
|
|
The main ``.cpp`` file is named ``<entrypoint name>.cpp`` and is usually in the
|
|
same folder as the header. It contains the signature of the entrypoint function,
|
|
which must be defined with the ``LLVM_LIBC_FUNCTION`` macro. For example, the
|
|
``isalpha`` function from ``ctype.h`` is defined as follows, in the file
|
|
``src/ctype/isalpha.cpp``::
|
|
|
|
// --- isalpha.cpp --- //
|
|
|
|
namespace LIBC_NAMESPACE_DECL {
|
|
|
|
LLVM_LIBC_FUNCTION(int, isalpha, (int c)) {
|
|
// ... implementation goes here.
|
|
}
|
|
|
|
} // namespace LIBC_NAMESPACE_DECL
|
|
|
|
Notice the use of the macro ``LLVM_LIBC_FUNCTION``. This macro helps us define
|
|
a C alias symbol for the C++ implementation. For example, for a library build,
|
|
the macro is defined as follows::
|
|
|
|
#define LLVM_LIBC_FUNCTION(type, name, arglist)
|
|
LLVM_LIBC_FUNCTION_IMPL(type, name, arglist)
|
|
#define LLVM_LIBC_FUNCTION_IMPL(type, name, arglist)
|
|
LLVM_LIBC_FUNCTION_ATTR decltype(LIBC_NAMESPACE::name)
|
|
__##name##_impl__ __asm__(#name);
|
|
decltype(LIBC_NAMESPACE::name) name [[gnu::alias(#name)]];
|
|
type __##name##_impl__ arglist
|
|
|
|
The LLVM_LIBC_FUNCTION_ATTR macro is normally defined to nothing, but can be
|
|
defined by vendors who want to set their own attributes.
|