Skip to content

Commit f3fe14f

Browse files
authored
[libc] puts implementation for baremetal (#98051)
This is a simple baremetal implementation of puts akin to putchar.
1 parent 9acaccb commit f3fe14f

File tree

4 files changed

+38
-0
lines changed

4 files changed

+38
-0
lines changed

libc/config/baremetal/arm/entrypoints.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ set(TARGET_LIBC_ENTRYPOINTS
8585
# stdio.h entrypoints
8686
libc.src.stdio.printf
8787
libc.src.stdio.putchar
88+
libc.src.stdio.puts
8889
libc.src.stdio.remove
8990
libc.src.stdio.snprintf
9091
libc.src.stdio.sprintf

libc/config/baremetal/riscv/entrypoints.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ set(TARGET_LIBC_ENTRYPOINTS
8181
# stdio.h entrypoints
8282
libc.src.stdio.printf
8383
libc.src.stdio.putchar
84+
libc.src.stdio.puts
8485
libc.src.stdio.remove
8586
libc.src.stdio.snprintf
8687
libc.src.stdio.sprintf

libc/src/stdio/baremetal/CMakeLists.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,17 @@ add_entrypoint_object(
3232
libc.src.__support.CPP.string_view
3333
)
3434

35+
add_entrypoint_object(
36+
puts
37+
SRCS
38+
puts.cpp
39+
HDRS
40+
../puts.h
41+
DEPENDS
42+
libc.src.__support.OSUtil.osutil
43+
libc.src.__support.CPP.string_view
44+
)
45+
3546
add_entrypoint_object(
3647
vprintf
3748
SRCS

libc/src/stdio/baremetal/puts.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//===-- Implementation of puts for baremetal-------------------------------===//
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+
#include "src/stdio/puts.h"
10+
#include "src/__support/CPP/string_view.h"
11+
#include "src/__support/OSUtil/io.h"
12+
13+
namespace LIBC_NAMESPACE {
14+
15+
LLVM_LIBC_FUNCTION(int, puts, (const char *__restrict str)) {
16+
cpp::string_view str_view(str);
17+
18+
// TODO: Can we combine these to avoid needing two writes?
19+
write_to_stderr(str_view);
20+
write_to_stderr("\n");
21+
22+
return 0;
23+
}
24+
25+
} // namespace LIBC_NAMESPACE

0 commit comments

Comments
 (0)