diff --git a/libc/include/arpa/inet.h.def b/libc/include/arpa/inet.h.def --- a/libc/include/arpa/inet.h.def +++ b/libc/include/arpa/inet.h.def @@ -9,9 +9,9 @@ #ifndef LLVM_LIBC_ARPA_INET_H #define LLVM_LIBC_ARPA_INET_H -#include <__llvm-libc-common.h> +%%include_header(__llvm-libc-common.h) -#include +%%include_header(inttypes.h) %%public_api() diff --git a/libc/include/assert.h.def b/libc/include/assert.h.def --- a/libc/include/assert.h.def +++ b/libc/include/assert.h.def @@ -6,7 +6,7 @@ // //===----------------------------------------------------------------------===// -#include <__llvm-libc-common.h> +%%include_header(__llvm-libc-common.h) // This file may be usefully included multiple times to change assert()'s // definition based on NDEBUG. diff --git a/libc/include/ctype.h.def b/libc/include/ctype.h.def --- a/libc/include/ctype.h.def +++ b/libc/include/ctype.h.def @@ -9,7 +9,7 @@ #ifndef LLVM_LIBC_CTYPE_H #define LLVM_LIBC_CTYPE_H -#include <__llvm-libc-common.h> +%%include_header(__llvm-libc-common.h) %%public_api() diff --git a/libc/include/dirent.h.def b/libc/include/dirent.h.def --- a/libc/include/dirent.h.def +++ b/libc/include/dirent.h.def @@ -9,7 +9,7 @@ #ifndef LLVM_LIBC_DIRENT_H #define LLVM_LIBC_DIRENT_H -#include <__llvm-libc-common.h> +%%include_header(__llvm-libc-common.h) %%public_api() diff --git a/libc/include/errno.h.def b/libc/include/errno.h.def --- a/libc/include/errno.h.def +++ b/libc/include/errno.h.def @@ -9,11 +9,11 @@ #ifndef LLVM_LIBC_ERRNO_H #define LLVM_LIBC_ERRNO_H -#include <__llvm-libc-common.h> +%%include_header(__llvm-libc-common.h) #ifdef __linux__ -#include +%%include_header(linux/errno.h) #ifndef ERFKILL #define ERFKILL 132 @@ -40,7 +40,7 @@ #endif // ENOTRECOVERABLE #else // __linux__ -#include +%%include_header(llvm-libc-macros/generic-error-number-macros.h) #endif #if !defined(__AMDGPU__) && !defined(__NVPTX__) diff --git a/libc/include/fcntl.h.def b/libc/include/fcntl.h.def --- a/libc/include/fcntl.h.def +++ b/libc/include/fcntl.h.def @@ -9,8 +9,8 @@ #ifndef LLVM_LIBC_FCNTL_H #define LLVM_LIBC_FCNTL_H -#include <__llvm-libc-common.h> -#include +%%include_header(__llvm-libc-common.h) +%%include_header(llvm-libc-macros/fcntl-macros.h) %%public_api() diff --git a/libc/include/fenv.h.def b/libc/include/fenv.h.def --- a/libc/include/fenv.h.def +++ b/libc/include/fenv.h.def @@ -9,8 +9,8 @@ #ifndef LLVM_LIBC_FENV_H #define LLVM_LIBC_FENV_H -#include <__llvm-libc-common.h> -#include +%%include_header(__llvm-libc-common.h) +%%include_header(llvm-libc-macros/fenv-macros.h) %%public_api() diff --git a/libc/include/gpu/rpc.h.def b/libc/include/gpu/rpc.h.def --- a/libc/include/gpu/rpc.h.def +++ b/libc/include/gpu/rpc.h.def @@ -9,9 +9,9 @@ #ifndef LLVM_LIBC_GPU_RPC_H #define LLVM_LIBC_GPU_RPC_H -#include <__llvm-libc-common.h> +%%include_header(__llvm-libc-common.h) -#include +%%include_header(llvm-libc-types/rpc_opcodes_t.h) %%public_api() diff --git a/libc/include/inttypes.h.def b/libc/include/inttypes.h.def --- a/libc/include/inttypes.h.def +++ b/libc/include/inttypes.h.def @@ -9,8 +9,8 @@ #ifndef LLVM_LIBC_INTTYPES_H #define LLVM_LIBC_INTTYPES_H -#include <__llvm-libc-common.h> -#include +%%include_header(__llvm-libc-common.h) +%%include_header(stdint.h) %%public_api() diff --git a/libc/include/math.h.def b/libc/include/math.h.def --- a/libc/include/math.h.def +++ b/libc/include/math.h.def @@ -9,8 +9,8 @@ #ifndef LLVM_LIBC_MATH_H #define LLVM_LIBC_MATH_H -#include <__llvm-libc-common.h> -#include +%%include_header(__llvm-libc-common.h) +%%include_header(llvm-libc-macros/math-macros.h) %%public_api() diff --git a/libc/include/pthread.h.def b/libc/include/pthread.h.def --- a/libc/include/pthread.h.def +++ b/libc/include/pthread.h.def @@ -9,7 +9,7 @@ #ifndef LLVM_LIBC_PTHREAD_H #define LLVM_LIBC_PTHREAD_H -#include <__llvm-libc-common.h> +%%include_header(__llvm-libc-common.h) #define PTHREAD_STACK_MIN (1 << 14) // 16KB diff --git a/libc/include/sched.h.def b/libc/include/sched.h.def --- a/libc/include/sched.h.def +++ b/libc/include/sched.h.def @@ -9,8 +9,8 @@ #ifndef LLVM_LIBC_SCHED_H #define LLVM_LIBC_SCHED_H -#include <__llvm-libc-common.h> -#include +%%include_header(__llvm-libc-common.h) +%%include_header(llvm-libc-macros/sched-macros.h) %%public_api() diff --git a/libc/include/setjmp.h.def b/libc/include/setjmp.h.def --- a/libc/include/setjmp.h.def +++ b/libc/include/setjmp.h.def @@ -9,7 +9,7 @@ #ifndef LLVM_LIBC_SETJMP_H #define LLVM_LIBC_SETJMP_H -#include <__llvm-libc-common.h> +%%include_header(__llvm-libc-common.h) %%public_api() diff --git a/libc/include/signal.h.def b/libc/include/signal.h.def --- a/libc/include/signal.h.def +++ b/libc/include/signal.h.def @@ -9,12 +9,12 @@ #ifndef LLVM_LIBC_SIGNAL_H #define LLVM_LIBC_SIGNAL_H -#include <__llvm-libc-common.h> +%%include_header(__llvm-libc-common.h) #define __need_size_t -#include +%%include_header(stddef.h) -#include +%%include_header(llvm-libc-macros/signal-macros.h) %%public_api() diff --git a/libc/include/spawn.h.def b/libc/include/spawn.h.def --- a/libc/include/spawn.h.def +++ b/libc/include/spawn.h.def @@ -9,7 +9,7 @@ #ifndef LLVM_LIBC_SPAWN_H #define LLVM_LIBC_SPAWN_H -#include <__llvm-libc-common.h> +%%include_header(__llvm-libc-common.h) %%public_api() diff --git a/libc/include/stdio.h.def b/libc/include/stdio.h.def --- a/libc/include/stdio.h.def +++ b/libc/include/stdio.h.def @@ -9,9 +9,9 @@ #ifndef LLVM_LIBC_STDIO_H #define LLVM_LIBC_STDIO_H -#include <__llvm-libc-common.h> -#include -#include +%%include_header(__llvm-libc-common.h) +%%include_header(llvm-libc-macros/file-seek-macros.h) +%%include_header(llvm-libc-macros/stdio-macros.h) %%public_api() diff --git a/libc/include/stdlib.h.def b/libc/include/stdlib.h.def --- a/libc/include/stdlib.h.def +++ b/libc/include/stdlib.h.def @@ -9,8 +9,8 @@ #ifndef LLVM_LIBC_STDLIB_H #define LLVM_LIBC_STDLIB_H -#include <__llvm-libc-common.h> -#include +%%include_header(__llvm-libc-common.h) +%%include_header(llvm-libc-macros/stdlib-macros.h) %%public_api() diff --git a/libc/include/string.h.def b/libc/include/string.h.def --- a/libc/include/string.h.def +++ b/libc/include/string.h.def @@ -9,9 +9,9 @@ #ifndef LLVM_LIBC_STRING_H #define LLVM_LIBC_STRING_H -#include <__llvm-libc-common.h> +%%include_header(__llvm-libc-common.h) -#include +%%include_header(llvm-libc-macros/null-macro.h) %%public_api() diff --git a/libc/include/strings.h.def b/libc/include/strings.h.def --- a/libc/include/strings.h.def +++ b/libc/include/strings.h.def @@ -9,7 +9,7 @@ #ifndef LLVM_LIBC_STRINGS_H #define LLVM_LIBC_STRINGS_H -#include <__llvm-libc-common.h> +%%include_header(__llvm-libc-common.h) %%public_api() diff --git a/libc/include/sys/auxv.h.def b/libc/include/sys/auxv.h.def --- a/libc/include/sys/auxv.h.def +++ b/libc/include/sys/auxv.h.def @@ -9,9 +9,9 @@ #ifndef LLVM_LIBC_SYS_AUXV_H #define LLVM_LIBC_SYS_AUXV_H -#include <__llvm-libc-common.h> +%%include_header(__llvm-libc-common.h) -#include +%%include_header(llvm-libc-macros/sys-auxv-macros.h) %%public_api() diff --git a/libc/include/sys/ioctl.h.def b/libc/include/sys/ioctl.h.def --- a/libc/include/sys/ioctl.h.def +++ b/libc/include/sys/ioctl.h.def @@ -9,9 +9,9 @@ #ifndef LLVM_LIBC_SYS_IOCTL_H #define LLVM_LIBC_SYS_IOCTL_H -#include <__llvm-libc-common.h> +%%include_header(__llvm-libc-common.h) -#include +%%include_header(llvm-libc-macros/sys-ioctl-macros.h) %%public_api() diff --git a/libc/include/sys/mman.h.def b/libc/include/sys/mman.h.def --- a/libc/include/sys/mman.h.def +++ b/libc/include/sys/mman.h.def @@ -9,9 +9,9 @@ #ifndef LLVM_LIBC_SYS_MMAN_H #define LLVM_LIBC_SYS_MMAN_H -#include <__llvm-libc-common.h> +%%include_header(__llvm-libc-common.h) -#include +%%include_header(llvm-libc-macros/sys-mman-macros.h) %%public_api() diff --git a/libc/include/sys/prctl.h.def b/libc/include/sys/prctl.h.def --- a/libc/include/sys/prctl.h.def +++ b/libc/include/sys/prctl.h.def @@ -9,11 +9,11 @@ #ifndef LLVM_LIBC_SYS_PRCTL_H #define LLVM_LIBC_SYS_PRCTL_H -#include <__llvm-libc-common.h> +%%include_header(__llvm-libc-common.h) // Process control is highly platform specific, so the platform usually defines // the macros itself. -#include +%%include_header(linux/prctl.h) // TODO: Define the prctl macros. diff --git a/libc/include/sys/random.h.def b/libc/include/sys/random.h.def --- a/libc/include/sys/random.h.def +++ b/libc/include/sys/random.h.def @@ -9,9 +9,9 @@ #ifndef LLVM_LIBC_SYS_RANDOM_H #define LLVM_LIBC_SYS_RANDOM_H -#include <__llvm-libc-common.h> +%%include_header(__llvm-libc-common.h) -#include +%%include_header(llvm-libc-macros/sys-random-macros.h) %%public_api() diff --git a/libc/include/sys/resource.h.def b/libc/include/sys/resource.h.def --- a/libc/include/sys/resource.h.def +++ b/libc/include/sys/resource.h.def @@ -9,9 +9,9 @@ #ifndef LLVM_LIBC_SYS_RESOURCE_H #define LLVM_LIBC_SYS_RESOURCE_H -#include <__llvm-libc-common.h> +%%include_header(__llvm-libc-common.h) -#include +%%include_header(llvm-libc-macros/sys-resource-macros.h) %%public_api() diff --git a/libc/include/sys/select.h.def b/libc/include/sys/select.h.def --- a/libc/include/sys/select.h.def +++ b/libc/include/sys/select.h.def @@ -9,9 +9,9 @@ #ifndef LLVM_LIBC_SYS_SELECT_H #define LLVM_LIBC_SYS_SELECT_H -#include <__llvm-libc-common.h> +%%include_header(__llvm-libc-common.h) -#include +%%include_header(llvm-libc-macros/sys-select-macros.h) %%public_api() diff --git a/libc/include/sys/sendfile.h.def b/libc/include/sys/sendfile.h.def --- a/libc/include/sys/sendfile.h.def +++ b/libc/include/sys/sendfile.h.def @@ -9,7 +9,7 @@ #ifndef LLVM_LIBC_SYS_SENDFILE_H #define LLVM_LIBC_SYS_SENDFILE_H -#include <__llvm-libc-common.h> +%%include_header(__llvm-libc-common.h) %%public_api() diff --git a/libc/include/sys/socket.h.def b/libc/include/sys/socket.h.def --- a/libc/include/sys/socket.h.def +++ b/libc/include/sys/socket.h.def @@ -9,9 +9,9 @@ #ifndef LLVM_LIBC_SYS_SOCKET_H #define LLVM_LIBC_SYS_SOCKET_H -#include <__llvm-libc-common.h> +%%include_header(__llvm-libc-common.h) -#include +%%include_header(llvm-libc-macros/sys-socket-macros.h) %%public_api() diff --git a/libc/include/sys/stat.h.def b/libc/include/sys/stat.h.def --- a/libc/include/sys/stat.h.def +++ b/libc/include/sys/stat.h.def @@ -9,9 +9,9 @@ #ifndef LLVM_LIBC_SYS_STAT_H #define LLVM_LIBC_SYS_STAT_H -#include <__llvm-libc-common.h> +%%include_header(__llvm-libc-common.h) -#include +%%include_header(llvm-libc-macros/sys-stat-macros.h) %%public_api() diff --git a/libc/include/sys/time.h.def b/libc/include/sys/time.h.def --- a/libc/include/sys/time.h.def +++ b/libc/include/sys/time.h.def @@ -9,11 +9,11 @@ #ifndef LLVM_LIBC_SYS_TIME_H #define LLVM_LIBC_SYS_TIME_H -#include <__llvm-libc-common.h> +%%include_header(__llvm-libc-common.h) -#include +%%include_header(llvm-libc-types/struct_timeval.h) -#include +%%include_header(llvm-libc-macros/sys-time-macros.h) %%public_api() diff --git a/libc/include/sys/types.h.def b/libc/include/sys/types.h.def --- a/libc/include/sys/types.h.def +++ b/libc/include/sys/types.h.def @@ -9,7 +9,7 @@ #ifndef LLVM_LIBC_SYS_TYPES_H #define LLVM_LIBC_SYS_TYPES_H -#include <__llvm-libc-common.h> +%%include_header(__llvm-libc-common.h) %%public_api() diff --git a/libc/include/sys/utsname.h.def b/libc/include/sys/utsname.h.def --- a/libc/include/sys/utsname.h.def +++ b/libc/include/sys/utsname.h.def @@ -9,7 +9,7 @@ #ifndef LLVM_LIBC_SYS_UTSNAME_H #define LLVM_LIBC_SYS_UTSNAME_H -#include <__llvm-libc-common.h> +%%include_header(__llvm-libc-common.h) %%public_api() diff --git a/libc/include/sys/wait.h.def b/libc/include/sys/wait.h.def --- a/libc/include/sys/wait.h.def +++ b/libc/include/sys/wait.h.def @@ -9,9 +9,9 @@ #ifndef LLVM_LIBC_SYS_WAIT_H #define LLVM_LIBC_SYS_WAIT_H -#include <__llvm-libc-common.h> +%%include_header(__llvm-libc-common.h) -#include +%%include_header(llvm-libc-macros/sys-wait-macros.h) %%public_api() diff --git a/libc/include/termios.h.def b/libc/include/termios.h.def --- a/libc/include/termios.h.def +++ b/libc/include/termios.h.def @@ -9,8 +9,8 @@ #ifndef LLVM_LIBC_TERMIOS_H #define LLVM_LIBC_TERMIOS_H -#include <__llvm-libc-common.h> -#include +%%include_header(__llvm-libc-common.h) +%%include_header(llvm-libc-macros/termios-macros.h) %%public_api() diff --git a/libc/include/threads.h.def b/libc/include/threads.h.def --- a/libc/include/threads.h.def +++ b/libc/include/threads.h.def @@ -9,7 +9,7 @@ #ifndef LLVM_LIBC_THREADS_H #define LLVM_LIBC_THREADS_H -#include <__llvm-libc-common.h> +%%include_header(__llvm-libc-common.h) %%public_api() diff --git a/libc/include/time.h.def b/libc/include/time.h.def --- a/libc/include/time.h.def +++ b/libc/include/time.h.def @@ -9,8 +9,8 @@ #ifndef LLVM_LIBC_TIME_H #define LLVM_LIBC_TIME_H -#include <__llvm-libc-common.h> -#include +%%include_header(__llvm-libc-common.h) +%%include_header(llvm-libc-macros/time-macros.h) %%public_api() diff --git a/libc/include/unistd.h.def b/libc/include/unistd.h.def --- a/libc/include/unistd.h.def +++ b/libc/include/unistd.h.def @@ -9,9 +9,9 @@ #ifndef LLVM_LIBC_UNISTD_H #define LLVM_LIBC_UNISTD_H -#include <__llvm-libc-common.h> -#include -#include +%%include_header(__llvm-libc-common.h) +%%include_header(llvm-libc-macros/file-seek-macros.h) +%%include_header(llvm-libc-macros/unistd-macros.h) %%public_api() diff --git a/libc/include/wchar.h.def b/libc/include/wchar.h.def --- a/libc/include/wchar.h.def +++ b/libc/include/wchar.h.def @@ -9,8 +9,8 @@ #ifndef LLVM_LIBC_WCHAR_H #define LLVM_LIBC_WCHAR_H -#include <__llvm-libc-common.h> -#include +%%include_header(__llvm-libc-common.h) +%%include_header(llvm-libc-macros/wchar-macros.h) %%public_api() diff --git a/libc/utils/HdrGen/CMakeLists.txt b/libc/utils/HdrGen/CMakeLists.txt --- a/libc/utils/HdrGen/CMakeLists.txt +++ b/libc/utils/HdrGen/CMakeLists.txt @@ -9,6 +9,8 @@ Generator.h IncludeFileCommand.cpp IncludeFileCommand.h + IncludeHeaderCommand.cpp + IncludeHeaderCommand.h Main.cpp PublicAPICommand.cpp PublicAPICommand.h diff --git a/libc/utils/HdrGen/Generator.h b/libc/utils/HdrGen/Generator.h --- a/libc/utils/HdrGen/Generator.h +++ b/libc/utils/HdrGen/Generator.h @@ -36,6 +36,7 @@ std::unordered_map &ArgMap; std::unique_ptr IncludeFileCmd; + std::unique_ptr IncludeHeaderCmd; std::unique_ptr PublicAPICmd; Command *getCommandHandler(llvm::StringRef CommandName); diff --git a/libc/utils/HdrGen/Generator.cpp b/libc/utils/HdrGen/Generator.cpp --- a/libc/utils/HdrGen/Generator.cpp +++ b/libc/utils/HdrGen/Generator.cpp @@ -9,6 +9,7 @@ #include "Generator.h" #include "IncludeFileCommand.h" +#include "IncludeHeaderCommand.h" #include "PublicAPICommand.h" #include "llvm/ADT/StringRef.h" @@ -38,6 +39,10 @@ if (!IncludeFileCmd) IncludeFileCmd = std::make_unique(); return IncludeFileCmd.get(); + } else if (CommandName == IncludeHeaderCommand::Name) { + if (!IncludeHeaderCmd) + IncludeHeaderCmd = std::make_unique(); + return IncludeHeaderCmd.get(); } else if (CommandName == PublicAPICommand::Name) { if (!PublicAPICmd) PublicAPICmd = std::make_unique(EntrypointNameList); diff --git a/libc/utils/HdrGen/IncludeHeaderCommand.h b/libc/utils/HdrGen/IncludeHeaderCommand.h new file mode 100644 --- /dev/null +++ b/libc/utils/HdrGen/IncludeHeaderCommand.h @@ -0,0 +1,32 @@ +//===-- Class which implements the %%include_header command -----*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIBC_UTILS_HDRGEN_INCLUDE_HEADER_COMMAND_H +#define LLVM_LIBC_UTILS_HDRGEN_INCLUDE_HEADER_COMMAND_H + +#include "Command.h" + +#include "llvm/ADT/SmallVector.h" +#include "llvm/ADT/StringRef.h" + +#include + +namespace llvm_libc { + +class IncludeHeaderCommand : public Command { +public: + static const char Name[]; + + void run(llvm::raw_ostream &OS, const ArgVector &Args, + llvm::StringRef StdHeader, llvm::RecordKeeper &Records, + const Command::ErrorReporter &Reporter) const override; +}; + +} // namespace llvm_libc + +#endif // LLVM_LIBC_UTILS_HDRGEN_INCLUDE_HEADER_COMMAND_H diff --git a/libc/utils/HdrGen/IncludeHeaderCommand.cpp b/libc/utils/HdrGen/IncludeHeaderCommand.cpp new file mode 100644 --- /dev/null +++ b/libc/utils/HdrGen/IncludeHeaderCommand.cpp @@ -0,0 +1,34 @@ +//===-- Implementation of IncludeHeaderCommand ----------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "IncludeHeaderCommand.h" + +#include "llvm/Support/MemoryBuffer.h" +#include "llvm/Support/SourceMgr.h" + +#include + +namespace llvm_libc { + +const char IncludeHeaderCommand::Name[] = "include_header"; + +void IncludeHeaderCommand::run(llvm::raw_ostream &OS, const ArgVector &Args, + llvm::StringRef StdHeader, + llvm::RecordKeeper &Records, + const Command::ErrorReporter &Reporter) const { + if (Args.size() != 1) { + Reporter.printFatalError( + "%%include_header command takes exactly 1 argument."); + } + + llvm::StringRef IncludeHeader = Args[0]; + + OS << "#include <" << IncludeHeader << ">\n"; +} + +} // namespace llvm_libc