File tree Expand file tree Collapse file tree 6 files changed +49
-0
lines changed
__support/OSUtil/baremetal Expand file tree Collapse file tree 6 files changed +49
-0
lines changed Original file line number Diff line number Diff line change @@ -83,6 +83,7 @@ set(TARGET_LIBC_ENTRYPOINTS
83
83
libc.src.inttypes.strtoumax
84
84
85
85
# stdio.h entrypoints
86
+ libc.src.stdio.getchar
86
87
libc.src.stdio.printf
87
88
libc.src.stdio.putchar
88
89
libc.src.stdio.puts
Original file line number Diff line number Diff line change @@ -79,6 +79,7 @@ set(TARGET_LIBC_ENTRYPOINTS
79
79
libc.src.inttypes.strtoumax
80
80
81
81
# stdio.h entrypoints
82
+ libc.src.stdio.getchar
82
83
libc.src.stdio.printf
83
84
libc.src.stdio.putchar
84
85
libc.src.stdio.puts
Original file line number Diff line number Diff line change 11
11
#include " src/__support/CPP/string_view.h"
12
12
13
13
// This is intended to be provided by the vendor.
14
+
15
+ extern struct __llvm_libc_stdin __llvm_libc_stdin;
16
+ extern " C" ssize_t __llvm_libc_stdin_read (void *cookie, char *buf, size_t size);
17
+
14
18
extern " C" void __llvm_libc_log_write (const char *msg, size_t len);
15
19
16
20
namespace LIBC_NAMESPACE {
17
21
22
+ ssize_t read_from_stdin (char *buf, size_t size) {
23
+ return __llvm_libc_stdin_read (reinterpret_cast <void *>(&__llvm_libc_stdin),
24
+ buf, size);
25
+ }
26
+
18
27
void write_to_stderr (cpp::string_view msg) {
19
28
__llvm_libc_log_write (msg.data (), msg.size ());
20
29
}
Original file line number Diff line number Diff line change 9
9
#ifndef LLVM_LIBC_SRC___SUPPORT_OSUTIL_BAREMETAL_IO_H
10
10
#define LLVM_LIBC_SRC___SUPPORT_OSUTIL_BAREMETAL_IO_H
11
11
12
+ #include " include/llvm-libc-types/size_t.h"
13
+ #include " include/llvm-libc-types/ssize_t.h"
12
14
#include " src/__support/CPP/string_view.h"
13
15
14
16
namespace LIBC_NAMESPACE {
15
17
18
+ ssize_t read_from_stdin (char *buf, size_t size);
16
19
void write_to_stderr (cpp::string_view msg);
17
20
18
21
} // namespace LIBC_NAMESPACE
Original file line number Diff line number Diff line change
1
+ add_entrypoint_object (
2
+ getchar
3
+ SRCS
4
+ getchar.cpp
5
+ HDRS
6
+ ../getchar.h
7
+ DEPENDS
8
+ libc.src.__support.OSUtil.osutil
9
+ libc.src.__support.CPP.string_view
10
+ )
11
+
1
12
add_entrypoint_object (
2
13
remove
3
14
SRCS
Original file line number Diff line number Diff line change
1
+ // ===-- Baremetal implementation of getchar -------------------------------===//
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/getchar.h"
10
+ #include " src/__support/OSUtil/io.h"
11
+
12
+ #include < stdio.h>
13
+
14
+ namespace LIBC_NAMESPACE {
15
+
16
+ LLVM_LIBC_FUNCTION (int , getchar, ()) {
17
+ char buf[1 ];
18
+ auto result = read_from_stdin (buf, sizeof (buf));
19
+ if (result < 0 )
20
+ return EOF;
21
+ return buf[0 ];
22
+ }
23
+
24
+ } // namespace LIBC_NAMESPACE
You can’t perform that action at this time.
0 commit comments