Skip to content

Commit 6807164

Browse files
authored
[libc] Add the <endian.h> header. (#125168)
Closes [#124631](#124631). ref: https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/endian.h.html This patch adds the implementation of `endian.h`, which includes the header itself and three related macros. These macros in the header rely on the compiler preprocessor, similar to how https://github.com/llvm/llvm-project/blob/main/libc/src/__support/endian_internal.h does. Hopefully this will meet the requirements for compiling llvm with llvm-libc.
1 parent f5b4131 commit 6807164

File tree

10 files changed

+93
-0
lines changed

10 files changed

+93
-0
lines changed

libc/config/linux/aarch64/headers.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ set(TARGET_PUBLIC_HEADERS
44
libc.include.ctype
55
libc.include.dlfcn
66
libc.include.elf
7+
libc.include.endian
78
libc.include.errno
89
libc.include.features
910
libc.include.fenv

libc/config/linux/x86_64/headers.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ set(TARGET_PUBLIC_HEADERS
66
libc.include.dirent
77
libc.include.dlfcn
88
libc.include.elf
9+
libc.include.endian
910
libc.include.errno
1011
libc.include.fcntl
1112
libc.include.features

libc/docs/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ if (SPHINX_FOUND)
3939
assert
4040
cpio
4141
ctype
42+
endian
4243
errno
4344
fenv
4445
float

libc/docs/headers/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Implementation Status
1010
complex
1111
cpio
1212
ctype
13+
endian
1314
errno
1415
fenv
1516
float

libc/include/CMakeLists.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,15 @@ add_header_macro(
7373
.llvm_libc_common_h
7474
)
7575

76+
add_header_macro(
77+
endian
78+
../libc/include/endian.yaml
79+
endian.h
80+
DEPENDS
81+
.llvm-libc-macros.endian_macros
82+
.llvm_libc_common_h
83+
)
84+
7685
add_header_macro(
7786
features
7887
../libc/include/features.yaml

libc/include/endian.h.def

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//===-- POSIX header endian.h ---------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef LLVM_LIBC_ENDIAN_H
10+
#define LLVM_LIBC_ENDIAN_H
11+
12+
#include "__llvm-libc-common.h"
13+
#include "llvm-libc-macros/endian-macros.h"
14+
15+
%%public_api()
16+
17+
#endif // LLVM_LIBC_ENDIAN_H

libc/include/endian.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
header: endian.h
2+
header_template: endian.h.def
3+
standards:
4+
- POSIX
5+
macros: []
6+
types: []
7+
enums: []
8+
objects: []
9+
functions: []

libc/include/llvm-libc-macros/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,12 @@ add_macro_header(
310310
elf-macros.h
311311
)
312312

313+
add_macro_header(
314+
endian_macros
315+
HDR
316+
endian-macros.h
317+
)
318+
313319
add_macro_header(
314320
locale_macros
315321
HDR
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//===-- Definition of macros from endian.h --------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef LLVM_LIBC_MACROS_ENDIAN_MACROS_H
10+
#define LLVM_LIBC_MACROS_ENDIAN_MACROS_H
11+
12+
#define LITTLE_ENDIAN __ORDER_LITTLE_ENDIAN__
13+
#define BIG_ENDIAN __ORDER_BIG_ENDIAN__
14+
#define BYTE_ORDER __BYTE_ORDER__
15+
16+
#endif // LLVM_LIBC_MACROS_ENDIAN_MACROS_H

libc/utils/docgen/endian.yaml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
macros:
2+
LITTLE_ENDIAN:
3+
in-latest-posix: ''
4+
BIG_ENDIAN:
5+
in-latest-posix: ''
6+
BYTE_ORDER:
7+
in-latest-posix: ''
8+
be16toh:
9+
in-latest-posix: ''
10+
be32toh:
11+
in-latest-posix: ''
12+
be64toh:
13+
in-latest-posix: ''
14+
htobe16:
15+
in-latest-posix: ''
16+
htobe32:
17+
in-latest-posix: ''
18+
htobe64:
19+
in-latest-posix: ''
20+
htole16:
21+
in-latest-posix: ''
22+
htole32:
23+
in-latest-posix: ''
24+
htole64:
25+
in-latest-posix: ''
26+
le16toh:
27+
in-latest-posix: ''
28+
le32toh:
29+
in-latest-posix: ''
30+
le64toh:
31+
in-latest-posix: ''
32+

0 commit comments

Comments
 (0)