-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[libc] puts implementation for baremetal #98051
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
This is a simple baremetal implementation of puts akin to putchar.
@llvm/pr-subscribers-libc Author: Petr Hosek (petrhosek) ChangesThis is a simple baremetal implementation of puts akin to putchar. Full diff: https://github.com/llvm/llvm-project/pull/98051.diff 4 Files Affected:
diff --git a/libc/config/baremetal/arm/entrypoints.txt b/libc/config/baremetal/arm/entrypoints.txt
index 11f560ed2b90f7..ad41267626664d 100644
--- a/libc/config/baremetal/arm/entrypoints.txt
+++ b/libc/config/baremetal/arm/entrypoints.txt
@@ -85,6 +85,7 @@ set(TARGET_LIBC_ENTRYPOINTS
# stdio.h entrypoints
libc.src.stdio.printf
libc.src.stdio.putchar
+ libc.src.stdio.puts
libc.src.stdio.remove
libc.src.stdio.snprintf
libc.src.stdio.sprintf
diff --git a/libc/config/baremetal/riscv/entrypoints.txt b/libc/config/baremetal/riscv/entrypoints.txt
index f203317e2839d5..6ed6732918b42a 100644
--- a/libc/config/baremetal/riscv/entrypoints.txt
+++ b/libc/config/baremetal/riscv/entrypoints.txt
@@ -81,6 +81,7 @@ set(TARGET_LIBC_ENTRYPOINTS
# stdio.h entrypoints
libc.src.stdio.printf
libc.src.stdio.putchar
+ libc.src.stdio.puts
libc.src.stdio.remove
libc.src.stdio.snprintf
libc.src.stdio.sprintf
diff --git a/libc/src/stdio/baremetal/CMakeLists.txt b/libc/src/stdio/baremetal/CMakeLists.txt
index 45196ffc9de248..4acd8873ab753f 100644
--- a/libc/src/stdio/baremetal/CMakeLists.txt
+++ b/libc/src/stdio/baremetal/CMakeLists.txt
@@ -32,6 +32,17 @@ add_entrypoint_object(
libc.src.__support.CPP.string_view
)
+add_entrypoint_object(
+ puts
+ SRCS
+ puts.cpp
+ HDRS
+ ../puts.h
+ DEPENDS
+ libc.src.__support.OSUtil.osutil
+ libc.src.__support.CPP.string_view
+)
+
add_entrypoint_object(
vprintf
SRCS
diff --git a/libc/src/stdio/baremetal/puts.cpp b/libc/src/stdio/baremetal/puts.cpp
new file mode 100644
index 00000000000000..136cdb8acf8000
--- /dev/null
+++ b/libc/src/stdio/baremetal/puts.cpp
@@ -0,0 +1,25 @@
+//===-- Implementation of puts for baremetal-------------------------------===//
+//
+// 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/puts.h"
+#include "src/__support/CPP/string_view.h"
+#include "src/__support/OSUtil/io.h"
+
+namespace LIBC_NAMESPACE {
+
+LLVM_LIBC_FUNCTION(int, puts, (const char *__restrict str)) {
+ cpp::string_view str_view(str);
+
+ // TODO: Can we combine these to avoid needing two writes?
+ write_to_stderr(str_view);
+ write_to_stderr("\n");
+
+ return 0;
+}
+
+} // namespace LIBC_NAMESPACE
|
LLVM_LIBC_FUNCTION(int, puts, (const char *__restrict str)) { | ||
cpp::string_view str_view(str); | ||
|
||
// TODO: Can we combine these to avoid needing two writes? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it's possible to combine these without malloc
ing, unfortunately.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The alternative I was thinking about would be to have a writev
style API where you can provide a vector of strings but I'm not sure if it's worth it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
up to you if you want to implement that
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not now, maybe as a future improvement.
This is a simple baremetal implementation of puts akin to putchar.
This is a simple baremetal implementation of puts akin to putchar.