Skip to content

Commit 0b4dbbc

Browse files
committed
fixup! fixup! [libc] Add putc, fputc, and fprintf to stdio/baremetal
1 parent b30faff commit 0b4dbbc

File tree

11 files changed

+17
-27
lines changed

11 files changed

+17
-27
lines changed

libc/src/stdio/baremetal/CMakeLists.txt

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ add_entrypoint_object(
66
../fprintf.h
77
write_utils.h
88
DEPENDS
9-
libc.src.__support.OSUtil.osutil
109
libc.src.__support.CPP.string_view
1110
libc.src.stdio.printf_core.printf_main
1211
)
@@ -64,9 +63,7 @@ add_entrypoint_object(
6463
write_utils.h
6564
DEPENDS
6665
libc.src.stdio.printf_core.printf_main
67-
libc.src.stdio.printf_core.writer
6866
libc.src.__support.arg_list
69-
libc.src.__support.OSUtil.osutil
7067
)
7168

7269
add_entrypoint_object(
@@ -121,9 +118,7 @@ add_entrypoint_object(
121118
../vprintf.h
122119
DEPENDS
123120
libc.src.stdio.printf_core.printf_main
124-
libc.src.stdio.printf_core.writer
125121
libc.src.__support.arg_list
126-
libc.src.__support.OSUtil.osutil
127122
)
128123

129124
add_entrypoint_object(

libc/src/stdio/baremetal/fprintf.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ LLVM_LIBC_FUNCTION(int, fprintf,
3131
char buffer[BUFF_SIZE];
3232

3333
printf_core::WriteBuffer<printf_core::WriteMode::FLUSH_TO_STREAM> wb(
34-
buffer, BUFF_SIZE, get_write_hook(stream), nullptr);
34+
buffer, BUFF_SIZE, write_utils::get_write_hook(stream), nullptr);
3535
printf_core::Writer<printf_core::WriteMode::FLUSH_TO_STREAM> writer(wb);
3636

3737
int retval = printf_core::printf_main(&writer, format, args);

libc/src/stdio/baremetal/fputc.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//===-- Baremetal Implementation of fputc ---------------------------------===//
1+
//===-- Implementation of fputc for baremetal -------------------*- C++ -*-===//
22
//
33
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44
// See https://llvm.org/LICENSE.txt for license information.
@@ -17,7 +17,7 @@ namespace LIBC_NAMESPACE_DECL {
1717
LLVM_LIBC_FUNCTION(int, fputc, (int c, ::FILE *stream)) {
1818
char uc = static_cast<char>(c);
1919

20-
write(stream, cpp::string_view(&uc, 1));
20+
write_utils::write(stream, cpp::string_view(&uc, 1));
2121

2222
return 0;
2323
}

libc/src/stdio/baremetal/getchar.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//===-- Baremetal implementation of getchar -------------------------------===//
1+
//===-- Implementation of getchar for baremetal -----------------*- C++ -*-===//
22
//
33
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44
// See https://llvm.org/LICENSE.txt for license information.

libc/src/stdio/baremetal/printf.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ LLVM_LIBC_FUNCTION(int, printf, (const char *__restrict format, ...)) {
2929
char buffer[BUFF_SIZE];
3030

3131
printf_core::WriteBuffer<printf_core::WriteMode::FLUSH_TO_STREAM> wb(
32-
buffer, BUFF_SIZE, &stdout_write_hook, nullptr);
32+
buffer, BUFF_SIZE, &write_utils::stdout_write_hook, nullptr);
3333
printf_core::Writer<printf_core::WriteMode::FLUSH_TO_STREAM> writer(wb);
3434

3535
int retval = printf_core::printf_main(&writer, format, args);

libc/src/stdio/baremetal/putc.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//===-- Baremetal Implementation of putc ----------------------------------===//
1+
//===-- Implementation of putc for baremetal --------------------*- C++ -*-===//
22
//
33
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44
// See https://llvm.org/LICENSE.txt for license information.
@@ -17,7 +17,7 @@ namespace LIBC_NAMESPACE_DECL {
1717
LLVM_LIBC_FUNCTION(int, putc, (int c, ::FILE *stream)) {
1818
char uc = static_cast<char>(c);
1919

20-
write(stream, cpp::string_view(&uc, 1));
20+
write_utils::write(stream, cpp::string_view(&uc, 1));
2121

2222
return 0;
2323
}

libc/src/stdio/baremetal/putchar.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//===-- Baremetal Implementation of putchar -------------------------------===//
1+
//===-- Implementation of putchar for baremetal -----------------*- C++ -*-===//
22
//
33
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44
// See https://llvm.org/LICENSE.txt for license information.
@@ -15,7 +15,7 @@
1515
namespace LIBC_NAMESPACE_DECL {
1616

1717
LLVM_LIBC_FUNCTION(int, putchar, (int c)) {
18-
char uc = static_cast<unsigned char>(c);
18+
char uc = static_cast<char>(c);
1919

2020
write_to_stdout(cpp::string_view(&uc, 1));
2121

libc/src/stdio/baremetal/puts.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//===-- Implementation of puts for baremetal-------------------------------===//
1+
//===-- Implementation of puts for baremetal -------------------*- C++ -*-===//
22
//
33
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44
// See https://llvm.org/LICENSE.txt for license information.

libc/src/stdio/baremetal/remove.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//===-- Linux implementation of remove ------------------------------------===//
1+
//===-- Implementation of remove for baremetal -----------------*- C++ -*-===//
22
//
33
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44
// See https://llvm.org/LICENSE.txt for license information.

libc/src/stdio/baremetal/vprintf.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,10 @@
88

99
#include "src/stdio/vprintf.h"
1010

11-
#include "src/__support/OSUtil/io.h"
1211
#include "src/__support/arg_list.h"
1312
#include "src/__support/macros/config.h"
1413
#include "src/stdio/baremetal/write_utils.h"
15-
#include "src/stdio/printf_core/core_structs.h"
1614
#include "src/stdio/printf_core/printf_main.h"
17-
#include "src/stdio/printf_core/writer.h"
1815

1916
#include <stdarg.h>
2017
#include <stddef.h>
@@ -30,7 +27,7 @@ LLVM_LIBC_FUNCTION(int, vprintf,
3027
char buffer[BUFF_SIZE];
3128

3229
printf_core::WriteBuffer<printf_core::WriteMode::FLUSH_TO_STREAM> wb(
33-
buffer, BUFF_SIZE, &stdout_write_hook, nullptr);
30+
buffer, BUFF_SIZE, &write_utils::stdout_write_hook, nullptr);
3431
printf_core::Writer<printf_core::WriteMode::FLUSH_TO_STREAM> writer(wb);
3532

3633
int retval = printf_core::printf_main(&writer, format, args);

libc/src/stdio/baremetal/write_utils.h

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,8 @@
1313
#include "src/__support/macros/config.h"
1414
#include "src/stdio/printf_core/core_structs.h" // For printf_core::WRITE_OK
1515

16-
#include <stddef.h>
17-
1816
namespace LIBC_NAMESPACE_DECL {
19-
namespace {
17+
namespace write_utils {
2018

2119
LIBC_INLINE int stdout_write_hook(cpp::string_view new_str, void *) {
2220
write_to_stdout(new_str);
@@ -36,13 +34,13 @@ LIBC_INLINE void write(::FILE *f, cpp::string_view new_str) {
3634
}
3735
}
3836

39-
LIBC_INLINE decltype(&stdout_write_hook) get_write_hook(::FILE *f) {
40-
if (f == stdout) {
37+
using StreamWriter = int (*)(cpp::string_view, void *);
38+
LIBC_INLINE StreamWriter get_write_hook(::FILE *f) {
39+
if (f == stdout)
4140
return &stdout_write_hook;
42-
}
4341

4442
return &stderr_write_hook;
4543
}
4644

47-
} // namespace
45+
} // namespace write_utils
4846
} // namespace LIBC_NAMESPACE_DECL

0 commit comments

Comments
 (0)