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,11 @@ #ifndef LLVM_LIBC_ARPA_INET_H #define LLVM_LIBC_ARPA_INET_H +%%begin() #include <__llvm-libc-common.h> #include +%%end() %%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,9 @@ // //===----------------------------------------------------------------------===// +%%begin() #include <__llvm-libc-common.h> +%%end() // 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,9 @@ #ifndef LLVM_LIBC_CTYPE_H #define LLVM_LIBC_CTYPE_H +%%begin() #include <__llvm-libc-common.h> +%%end() %%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,9 @@ #ifndef LLVM_LIBC_DIRENT_H #define LLVM_LIBC_DIRENT_H +%%begin() #include <__llvm-libc-common.h> +%%end() %%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,6 +9,7 @@ #ifndef LLVM_LIBC_ERRNO_H #define LLVM_LIBC_ERRNO_H +%%begin() #include <__llvm-libc-common.h> #ifdef __linux__ @@ -47,5 +48,6 @@ extern _Thread_local int __llvmlibc_errno; #define errno __llvmlibc_errno #endif +%%end() #endif // LLVM_LIBC_ERRNO_H 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,10 @@ #ifndef LLVM_LIBC_FCNTL_H #define LLVM_LIBC_FCNTL_H +%%begin() #include <__llvm-libc-common.h> #include +%%end() %%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,10 @@ #ifndef LLVM_LIBC_FENV_H #define LLVM_LIBC_FENV_H +%%begin() #include <__llvm-libc-common.h> #include +%%end() %%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,11 @@ #ifndef LLVM_LIBC_GPU_RPC_H #define LLVM_LIBC_GPU_RPC_H +%%begin() #include <__llvm-libc-common.h> #include +%%end() %%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,10 @@ #ifndef LLVM_LIBC_INTTYPES_H #define LLVM_LIBC_INTTYPES_H +%%begin() #include <__llvm-libc-common.h> #include +%%end() %%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,10 @@ #ifndef LLVM_LIBC_MATH_H #define LLVM_LIBC_MATH_H +%%begin() #include <__llvm-libc-common.h> #include +%%end() %%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,6 +9,7 @@ #ifndef LLVM_LIBC_PTHREAD_H #define LLVM_LIBC_PTHREAD_H +%%begin() #include <__llvm-libc-common.h> #define PTHREAD_STACK_MIN (1 << 14) // 16KB @@ -30,6 +31,7 @@ PTHREAD_MUTEX_STALLED = 0x0, PTHREAD_MUTEX_ROBUST = 0x1, }; +%%end() %%public_api() 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,10 @@ #ifndef LLVM_LIBC_SCHED_H #define LLVM_LIBC_SCHED_H +%%begin() #include <__llvm-libc-common.h> #include +%%end() %%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,9 @@ #ifndef LLVM_LIBC_SETJMP_H #define LLVM_LIBC_SETJMP_H +%%begin() #include <__llvm-libc-common.h> +%%end() %%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,14 @@ #ifndef LLVM_LIBC_SIGNAL_H #define LLVM_LIBC_SIGNAL_H +%%begin() #include <__llvm-libc-common.h> #define __need_size_t #include #include +%%end() %%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,9 @@ #ifndef LLVM_LIBC_SPAWN_H #define LLVM_LIBC_SPAWN_H +%%begin() #include <__llvm-libc-common.h> +%%end() %%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,11 @@ #ifndef LLVM_LIBC_STDIO_H #define LLVM_LIBC_STDIO_H +%%begin() #include <__llvm-libc-common.h> #include #include +%%end() %%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,10 @@ #ifndef LLVM_LIBC_STDLIB_H #define LLVM_LIBC_STDLIB_H +%%begin() #include <__llvm-libc-common.h> #include +%%end() %%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,11 @@ #ifndef LLVM_LIBC_STRING_H #define LLVM_LIBC_STRING_H +%%begin() #include <__llvm-libc-common.h> #include +%%end() %%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,9 @@ #ifndef LLVM_LIBC_STRINGS_H #define LLVM_LIBC_STRINGS_H +%%begin() #include <__llvm-libc-common.h> +%%end() %%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,11 @@ #ifndef LLVM_LIBC_SYS_AUXV_H #define LLVM_LIBC_SYS_AUXV_H +%%begin() #include <__llvm-libc-common.h> #include +%%end() %%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,11 @@ #ifndef LLVM_LIBC_SYS_IOCTL_H #define LLVM_LIBC_SYS_IOCTL_H +%%begin() #include <__llvm-libc-common.h> #include +%%end() %%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,11 @@ #ifndef LLVM_LIBC_SYS_MMAN_H #define LLVM_LIBC_SYS_MMAN_H +%%begin() #include <__llvm-libc-common.h> #include +%%end() %%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,6 +9,7 @@ #ifndef LLVM_LIBC_SYS_PRCTL_H #define LLVM_LIBC_SYS_PRCTL_H +%%begin() #include <__llvm-libc-common.h> // Process control is highly platform specific, so the platform usually defines @@ -16,6 +17,7 @@ #include // TODO: Define the prctl macros. +%%end() %%public_api() 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,11 @@ #ifndef LLVM_LIBC_SYS_RANDOM_H #define LLVM_LIBC_SYS_RANDOM_H +%%begin() #include <__llvm-libc-common.h> #include +%%end() %%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,11 @@ #ifndef LLVM_LIBC_SYS_RESOURCE_H #define LLVM_LIBC_SYS_RESOURCE_H +%%begin() #include <__llvm-libc-common.h> #include +%%end() %%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,11 @@ #ifndef LLVM_LIBC_SYS_SELECT_H #define LLVM_LIBC_SYS_SELECT_H +%%begin() #include <__llvm-libc-common.h> #include +%%end() %%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,9 @@ #ifndef LLVM_LIBC_SYS_SENDFILE_H #define LLVM_LIBC_SYS_SENDFILE_H +%%begin() #include <__llvm-libc-common.h> +%%end() %%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,11 @@ #ifndef LLVM_LIBC_SYS_SOCKET_H #define LLVM_LIBC_SYS_SOCKET_H +%%begin() #include <__llvm-libc-common.h> #include +%%end() %%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,11 @@ #ifndef LLVM_LIBC_SYS_STAT_H #define LLVM_LIBC_SYS_STAT_H +%%begin() #include <__llvm-libc-common.h> #include +%%end() %%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,13 @@ #ifndef LLVM_LIBC_SYS_TIME_H #define LLVM_LIBC_SYS_TIME_H +%%begin() #include <__llvm-libc-common.h> #include #include +%%end() %%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,9 @@ #ifndef LLVM_LIBC_SYS_TYPES_H #define LLVM_LIBC_SYS_TYPES_H +%%begin() #include <__llvm-libc-common.h> +%%end() %%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,9 @@ #ifndef LLVM_LIBC_SYS_UTSNAME_H #define LLVM_LIBC_SYS_UTSNAME_H +%%begin() #include <__llvm-libc-common.h> +%%end() %%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,11 @@ #ifndef LLVM_LIBC_SYS_WAIT_H #define LLVM_LIBC_SYS_WAIT_H +%%begin() #include <__llvm-libc-common.h> #include +%%end() %%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,10 @@ #ifndef LLVM_LIBC_TERMIOS_H #define LLVM_LIBC_TERMIOS_H +%%begin() #include <__llvm-libc-common.h> #include +%%end() %%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,9 @@ #ifndef LLVM_LIBC_THREADS_H #define LLVM_LIBC_THREADS_H +%%begin() #include <__llvm-libc-common.h> +%%end() %%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,10 @@ #ifndef LLVM_LIBC_TIME_H #define LLVM_LIBC_TIME_H +%%begin() #include <__llvm-libc-common.h> #include +%%end() %%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,11 @@ #ifndef LLVM_LIBC_UNISTD_H #define LLVM_LIBC_UNISTD_H +%%begin() #include <__llvm-libc-common.h> #include #include +%%end() %%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,10 @@ #ifndef LLVM_LIBC_WCHAR_H #define LLVM_LIBC_WCHAR_H +%%begin() #include <__llvm-libc-common.h> #include +%%end() %%public_api() diff --git a/libc/utils/HdrGen/BeginCommand.h b/libc/utils/HdrGen/BeginCommand.h new file mode 100644 --- /dev/null +++ b/libc/utils/HdrGen/BeginCommand.h @@ -0,0 +1,32 @@ +//===-- Class which implements the %%begin 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_BEGIN_COMMAND_H +#define LLVM_LIBC_UTILS_HDRGEN_BEGIN_COMMAND_H + +#include "Command.h" + +#include "llvm/ADT/SmallVector.h" +#include "llvm/ADT/StringRef.h" + +#include + +namespace llvm_libc { + +class BeginCommand : 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_BEGIN_COMMAND_H diff --git a/libc/utils/HdrGen/BeginCommand.cpp b/libc/utils/HdrGen/BeginCommand.cpp new file mode 100644 --- /dev/null +++ b/libc/utils/HdrGen/BeginCommand.cpp @@ -0,0 +1,27 @@ +//===-- Implementation of BeginCommand ------------------------------------===// +// +// 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 "BeginCommand.h" + +#include "llvm/Support/MemoryBuffer.h" +#include "llvm/Support/SourceMgr.h" + +#include + +namespace llvm_libc { + +const char BeginCommand::Name[] = "begin"; + +void BeginCommand::run(llvm::raw_ostream &OS, const ArgVector &Args, + llvm::StringRef StdHeader, llvm::RecordKeeper &Records, + const Command::ErrorReporter &Reporter) const { + if (Args.size() != 0) + Reporter.printFatalError("%%begin command does not take any arguments."); +} + +} // namespace llvm_libc 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 @@ -7,6 +7,10 @@ Command.cpp Generator.cpp Generator.h + BeginCommand.cpp + BeginCommand.h + EndCommand.cpp + EndCommand.h IncludeFileCommand.cpp IncludeFileCommand.h Main.cpp diff --git a/libc/utils/HdrGen/EndCommand.h b/libc/utils/HdrGen/EndCommand.h new file mode 100644 --- /dev/null +++ b/libc/utils/HdrGen/EndCommand.h @@ -0,0 +1,32 @@ +//===-- Class which implements the %%end 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_END_COMMAND_H +#define LLVM_LIBC_UTILS_HDRGEN_END_COMMAND_H + +#include "Command.h" + +#include "llvm/ADT/SmallVector.h" +#include "llvm/ADT/StringRef.h" + +#include + +namespace llvm_libc { + +class EndCommand : 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_END_COMMAND_H diff --git a/libc/utils/HdrGen/EndCommand.cpp b/libc/utils/HdrGen/EndCommand.cpp new file mode 100644 --- /dev/null +++ b/libc/utils/HdrGen/EndCommand.cpp @@ -0,0 +1,27 @@ +//===-- Implementation of EndCommand --------------------------------------===// +// +// 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 "EndCommand.h" + +#include "llvm/Support/MemoryBuffer.h" +#include "llvm/Support/SourceMgr.h" + +#include + +namespace llvm_libc { + +const char EndCommand::Name[] = "end"; + +void EndCommand::run(llvm::raw_ostream &OS, const ArgVector &Args, + llvm::StringRef StdHeader, llvm::RecordKeeper &Records, + const Command::ErrorReporter &Reporter) const { + if (Args.size() != 0) + Reporter.printFatalError("%%end command does not take any arguments."); +} + +} // namespace llvm_libc 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 @@ -35,6 +35,8 @@ llvm::StringRef StdHeader; std::unordered_map &ArgMap; + std::unique_ptr BeginCmd; + std::unique_ptr EndCmd; std::unique_ptr IncludeFileCmd; std::unique_ptr PublicAPICmd; 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 @@ -8,6 +8,8 @@ #include "Generator.h" +#include "BeginCommand.h" +#include "EndCommand.h" #include "IncludeFileCommand.h" #include "PublicAPICommand.h" @@ -34,7 +36,15 @@ namespace llvm_libc { Command *Generator::getCommandHandler(llvm::StringRef CommandName) { - if (CommandName == IncludeFileCommand::Name) { + if (CommandName == BeginCommand::Name) { + if (!BeginCmd) + BeginCmd = std::make_unique(); + return BeginCmd.get(); + } else if (CommandName == EndCommand::Name) { + if (!EndCmd) + EndCmd = std::make_unique(); + return EndCmd.get(); + } else if (CommandName == IncludeFileCommand::Name) { if (!IncludeFileCmd) IncludeFileCmd = std::make_unique(); return IncludeFileCmd.get();