Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions libc/config/linux/x86_64/entrypoints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,12 @@ set(TARGET_LIBC_ENTRYPOINTS
libc.src.stdio.vsprintf
libc.src.stdio.vasprintf

# stdio.h hidden entrypoints
libc.src.stdio.iprintf
libc.src.stdio.fiprintf
libc.src.stdio.siprintf
libc.src.stdio.sniprintf

# sys/epoll.h entrypoints
libc.src.sys.epoll.epoll_create
libc.src.sys.epoll.epoll_create1
Expand Down
26 changes: 26 additions & 0 deletions libc/src/stdio/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,30 @@ add_entrypoint_object(
libc.src.stdio.printf_core.writer
)

add_entrypoint_object(
siprintf
SRCS
siprintf.cpp
HDRS
siprintf.h
DEPENDS
libc.src.stdio.printf_core.printf_main_nofloat
libc.src.stdio.printf_core.writer
)

# technically clang doesn't yet support sniprintf, so I could rename it to the
# objectively cooler (and more accurate) sinprintf. Alas I chose not to.
add_entrypoint_object(
sniprintf
SRCS
sniprintf.cpp
HDRS
sniprintf.h
DEPENDS
libc.src.stdio.printf_core.printf_main_nofloat
libc.src.stdio.printf_core.writer
)

add_entrypoint_object(
asprintf
SRCS
Expand Down Expand Up @@ -286,7 +310,9 @@ add_stdio_entrypoint_object(fputc)
add_stdio_entrypoint_object(putc)
add_stdio_entrypoint_object(putchar)
add_stdio_entrypoint_object(printf)
add_stdio_entrypoint_object(iprintf)
add_stdio_entrypoint_object(fprintf)
add_stdio_entrypoint_object(fiprintf)
add_stdio_entrypoint_object(fgetc)
add_stdio_entrypoint_object(fgetc_unlocked)
add_stdio_entrypoint_object(getc)
Expand Down
21 changes: 21 additions & 0 deletions libc/src/stdio/fiprintf.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//===-- Implementation header of fiprintf -----------------------*- 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_SRC_STDIO_FIPRINTF_H
#define LLVM_LIBC_SRC_STDIO_FIPRINTF_H

#include "hdr/types/FILE.h"
#include "src/__support/macros/config.h"

namespace LIBC_NAMESPACE_DECL {

int fiprintf(::FILE *__restrict stream, const char *__restrict format, ...);

} // namespace LIBC_NAMESPACE_DECL

#endif // LLVM_LIBC_SRC_STDIO_FIPRINTF_H
40 changes: 39 additions & 1 deletion libc/src/stdio/generic/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,6 @@ add_entrypoint_object(
list(APPEND fprintf_deps
libc.hdr.types.FILE
libc.src.__support.arg_list
libc.src.stdio.printf_core.vfprintf_internal
)

if(LLVM_LIBC_FULL_BUILD)
Expand All @@ -376,13 +375,28 @@ if(LLVM_LIBC_FULL_BUILD)
)
endif()

# Copy the deps for fiprintf_deps
set(fiprintf_deps ${fprintf_deps})

list(APPEND fprintf_deps
libc.src.stdio.printf_core.vfprintf_internal
)

list(APPEND fiprintf_deps
libc.src.stdio.printf_core.vfprintf_internal_nofloat
)

# Copy the deps for printf_deps
set(printf_deps ${fprintf_deps})
set(iprintf_deps ${fiprintf_deps})

if(LLVM_LIBC_FULL_BUILD)
list(APPEND printf_deps
libc.src.__support.File.platform_stdout
)
list(APPEND iprintf_deps
libc.src.__support.File.platform_stdout
)
endif()

add_entrypoint_object(
Expand Down Expand Up @@ -425,6 +439,30 @@ add_entrypoint_object(
${fprintf_deps}
)

# the printf variant with no floats is called iprintf for some reason. Idk ask XMOS
add_entrypoint_object(
iprintf
SRCS
iprintf.cpp
HDRS
../iprintf.h
DEPENDS
${iprintf_deps}
)

# Similarly I'm unclear why the "i" modifier goes after the target modifier but w/e.
# Oldest commit I could find mentioning it dates from 2011:
# https://github.com/llvm/llvm-project/commit/2dfb888392d4d82f467dfc8c9c4d2192cd71afb6
add_entrypoint_object(
fiprintf
SRCS
fiprintf.cpp
HDRS
../fiprintf.h
DEPENDS
${fiprintf_deps}
)

add_entrypoint_object(
fgets
SRCS
Expand Down
34 changes: 34 additions & 0 deletions libc/src/stdio/generic/fiprintf.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//===-- Implementation of fiprintf ------------------------------*- 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
//
//===----------------------------------------------------------------------===//

#include "src/stdio/fiprintf.h"

#include "src/__support/File/file.h"
#include "src/__support/arg_list.h"
#include "src/__support/macros/config.h"
#include "src/stdio/printf_core/vfprintf_internal.h"

#include "hdr/types/FILE.h"
#include <stdarg.h>

namespace LIBC_NAMESPACE_DECL {

LLVM_LIBC_FUNCTION(int, fiprintf,
(::FILE *__restrict stream, const char *__restrict format,
...)) {
va_list vlist;
va_start(vlist, format);
internal::ArgList args(vlist); // This holder class allows for easier copying
// and pointer semantics, as well as handling
// destruction automatically.
va_end(vlist);
int ret_val = printf_core::vfprintf_internal(stream, format, args);
return ret_val;
}

} // namespace LIBC_NAMESPACE_DECL
39 changes: 39 additions & 0 deletions libc/src/stdio/generic/iprintf.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
//===-- Implementation of iprintf -------------------------------*- 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
//
//===----------------------------------------------------------------------===//

#include "src/stdio/iprintf.h"

#include "src/__support/File/file.h"
#include "src/__support/arg_list.h"
#include "src/__support/macros/config.h"
#include "src/stdio/printf_core/vfprintf_internal.h"

#include "hdr/types/FILE.h"
#include <stdarg.h>

#ifndef LIBC_COPT_STDIO_USE_SYSTEM_FILE
#define PRINTF_STDOUT LIBC_NAMESPACE::stdout
#else // LIBC_COPT_STDIO_USE_SYSTEM_FILE
#define PRINTF_STDOUT ::stdout
#endif // LIBC_COPT_STDIO_USE_SYSTEM_FILE

namespace LIBC_NAMESPACE_DECL {

LLVM_LIBC_FUNCTION(int, iprintf, (const char *__restrict format, ...)) {
va_list vlist;
va_start(vlist, format);
internal::ArgList args(vlist); // This holder class allows for easier copying
// and pointer semantics, as well as handling
// destruction automatically.
va_end(vlist);
int ret_val = printf_core::vfprintf_internal(
reinterpret_cast<::FILE *>(PRINTF_STDOUT), format, args);
return ret_val;
}

} // namespace LIBC_NAMESPACE_DECL
21 changes: 21 additions & 0 deletions libc/src/stdio/iprintf.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//===-- Implementation header of iprintf ------------------------*- 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_SRC_STDIO_IPRINTF_H
#define LLVM_LIBC_SRC_STDIO_IPRINTF_H

#include "hdr/types/FILE.h"
#include "src/__support/macros/config.h"

namespace LIBC_NAMESPACE_DECL {

int iprintf(const char *__restrict format, ...);

} // namespace LIBC_NAMESPACE_DECL

#endif // LLVM_LIBC_SRC_STDIO_IPRINTF_H
Loading