-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
[libc] Support for scanf on baremetal #131043
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
dee8274
[libc] Support for scanf on baremetal
petrhosek 4ebcb48
Merge remote-tracking branch 'origin/main' into libc-baremetal-scanf
petrhosek cdad78e
Update the implementation
petrhosek c9d8ccc
Remove the unnecessary file_deps
petrhosek 8f461ff
Reintroduce an accidentally dropped asprintf and vasprinf
petrhosek 3cffce6
Extract `StdinReader` into a shared header
petrhosek 062804f
Include `scanf_internal.h`
petrhosek File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
//===-- Implementation of scanf ---------------------------------*- 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/scanf.h" | ||
|
||
#include "hdr/stdio_macros.h" | ||
#include "src/__support/OSUtil/io.h" | ||
#include "src/__support/arg_list.h" | ||
#include "src/__support/macros/config.h" | ||
#include "src/stdio/baremetal/scanf_internal.h" | ||
#include "src/stdio/scanf_core/scanf_main.h" | ||
|
||
#include <stdarg.h> | ||
|
||
namespace LIBC_NAMESPACE_DECL { | ||
|
||
LLVM_LIBC_FUNCTION(int, scanf, (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); | ||
|
||
scanf_core::StdinReader reader; | ||
int retval = scanf_core::scanf_main(&reader, format, args); | ||
// This is done to avoid including stdio.h in the internals. On most systems | ||
// EOF is -1, so this will be transformed into just "return retval". | ||
return (retval == -1) ? EOF : retval; | ||
} | ||
|
||
} // namespace LIBC_NAMESPACE_DECL |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
//===-- Internal implementation header of scanf -----------------*- 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/__support/OSUtil/io.h" | ||
#include "src/__support/macros/config.h" | ||
#include "src/stdio/scanf_core/reader.h" | ||
|
||
namespace LIBC_NAMESPACE_DECL { | ||
|
||
namespace scanf_core { | ||
|
||
struct StdinReader : public Reader<StdinReader> { | ||
LIBC_INLINE char getc() { | ||
char buf[1]; | ||
auto result = read_from_stdin(buf, sizeof(buf)); | ||
if (result <= 0) | ||
return EOF; | ||
return buf[0]; | ||
} | ||
LIBC_INLINE void ungetc(int) {} | ||
}; | ||
|
||
} // namespace scanf_core | ||
|
||
} // namespace LIBC_NAMESPACE_DECL |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
//===-- Implementation of vscanf --------------------------------*- 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/vscanf.h" | ||
|
||
#include "hdr/stdio_macros.h" | ||
#include "src/__support/OSUtil/io.h" | ||
#include "src/__support/arg_list.h" | ||
#include "src/__support/macros/config.h" | ||
#include "src/stdio/baremetal/scanf_internal.h" | ||
#include "src/stdio/scanf_core/scanf_main.h" | ||
|
||
#include <stdarg.h> | ||
|
||
namespace LIBC_NAMESPACE_DECL { | ||
|
||
LLVM_LIBC_FUNCTION(int, vscanf, | ||
(const char *__restrict format, va_list vlist)) { | ||
internal::ArgList args(vlist); // This holder class allows for easier copying | ||
// and pointer semantics, as well as handling | ||
// destruction automatically. | ||
va_end(vlist); | ||
|
||
scanf_core::StdinReader reader; | ||
int retval = scanf_core::scanf_main(&reader, format, args); | ||
// This is done to avoid including stdio.h in the internals. On most systems | ||
// EOF is -1, so this will be transformed into just "return retval". | ||
return (retval == -1) ? EOF : retval; | ||
} | ||
|
||
} // namespace LIBC_NAMESPACE_DECL |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Is this not needed anymore?
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.
It was moved to
libc/src/stdio/generic/CMakeLists.txt
.