-
Notifications
You must be signed in to change notification settings - Fork 11.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[libcxx][libc] Hand in Hand PoC with from_chars
DO NOT MERGE, PROOF OF CONCEPT ONLY. This patch aims to demonstrate the utility of sharing code between libc and libc++ by using the libc float conversion code in the libc++ function from_chars. This patch adds from_chars for float and double (long double is possible but was causing errors so was skipped here), as well as a test to demonstrate that it works. This is very much just a proof of concept, not intended to be committed as-is. The from_chars code written is copied from the libc parsing code and is not functionally complete, nor does it follow the correct coding style.
- Loading branch information
Showing
36 changed files
with
2,362 additions
and
21 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
//===-- Floating point number utils -----------------------------*- 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 | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef LLVM_LIBC_SHARED_FP_BITS_H | ||
#define LLVM_LIBC_SHARED_FP_BITS_H | ||
|
||
#include "src/__support/FPUtil/FPBits.h" | ||
|
||
namespace LIBC_NAMESPACE_DECL { | ||
namespace shared { | ||
|
||
using fputil::FPBits; | ||
|
||
} // namespace shared | ||
} // namespace LIBC_NAMESPACE_DECL | ||
|
||
#endif // LLVM_LIBC_SHARED_FP_BITS_H |
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,27 @@ | ||
//===-- String to float conversion utils ------------------------*- 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 | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef LLVM_LIBC_SHARED_STR_TO_FLOAT_H | ||
#define LLVM_LIBC_SHARED_STR_TO_FLOAT_H | ||
|
||
#include "src/__support/str_to_float.h" | ||
|
||
namespace LIBC_NAMESPACE_DECL { | ||
namespace shared { | ||
|
||
using internal::ExpandedFloat; | ||
using internal::FloatConvertReturn; | ||
using internal::RoundDirection; | ||
|
||
using internal::binary_exp_to_float; | ||
using internal::decimal_exp_to_float; | ||
|
||
} // namespace shared | ||
} // namespace LIBC_NAMESPACE_DECL | ||
|
||
#endif // LLVM_LIBC_SHARED_STR_TO_FLOAT_H |
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,24 @@ | ||
//===-- String to int conversion utils --------------------------*- 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 | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef LLVM_LIBC_SHARED_STR_TO_INTEGER_H | ||
#define LLVM_LIBC_SHARED_STR_TO_INTEGER_H | ||
|
||
#include "src/__support/str_to_integer.h" | ||
|
||
namespace LIBC_NAMESPACE_DECL { | ||
namespace shared { | ||
|
||
using LIBC_NAMESPACE::StrToNumResult; | ||
|
||
using internal::strtointeger; | ||
|
||
} // namespace shared | ||
} // namespace LIBC_NAMESPACE_DECL | ||
|
||
#endif // LLVM_LIBC_SHARED_STR_TO_INTEGER_H |
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
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,73 @@ | ||
// -*- 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 | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef _LIBCPP___CHARCONV_FROM_CHARS_FLOATING_POINT_H | ||
#define _LIBCPP___CHARCONV_FROM_CHARS_FLOATING_POINT_H | ||
|
||
#include <__assert> | ||
#include <__charconv/chars_format.h> | ||
#include <__charconv/from_chars_result.h> | ||
#include <__config> | ||
#include <__system_error/errc.h> | ||
#include <cstddef> | ||
|
||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) | ||
# pragma GCC system_header | ||
#endif | ||
|
||
_LIBCPP_PUSH_MACROS | ||
#include <__undef_macros> | ||
|
||
_LIBCPP_BEGIN_NAMESPACE_STD | ||
|
||
#if _LIBCPP_STD_VER >= 17 | ||
|
||
template <class _Fp> | ||
struct __from_chars_result { | ||
_Fp __value; | ||
ptrdiff_t __n; | ||
errc __ec; | ||
}; | ||
|
||
template <class _Fp> | ||
_LIBCPP_EXPORTED_FROM_ABI __from_chars_result<_Fp> __from_chars_floating_point( | ||
[[clang::noescape]] const char* __first, [[clang::noescape]] const char* __last, chars_format __fmt); | ||
|
||
extern template __from_chars_result<float> __from_chars_floating_point( | ||
[[clang::noescape]] const char* __first, [[clang::noescape]] const char* __last, chars_format __fmt); | ||
|
||
extern template __from_chars_result<double> __from_chars_floating_point( | ||
[[clang::noescape]] const char* __first, [[clang::noescape]] const char* __last, chars_format __fmt); | ||
|
||
template <class _Fp> | ||
_LIBCPP_HIDE_FROM_ABI from_chars_result | ||
__from_chars(const char* __first, const char* __last, _Fp& __value, chars_format __fmt) { | ||
__from_chars_result<_Fp> __r = std::__from_chars_floating_point<_Fp>(__first, __last, __fmt); | ||
if (__r.__ec != errc::invalid_argument) | ||
__value = __r.__value; | ||
return {__first + __r.__n, __r.__ec}; | ||
} | ||
|
||
_LIBCPP_AVAILABILITY_FROM_CHARS_FLOATING_POINT _LIBCPP_HIDE_FROM_ABI inline from_chars_result | ||
from_chars(const char* __first, const char* __last, float& __value, chars_format __fmt = chars_format::general) { | ||
return std::__from_chars<float>(__first, __last, __value, __fmt); | ||
} | ||
|
||
_LIBCPP_AVAILABILITY_FROM_CHARS_FLOATING_POINT _LIBCPP_HIDE_FROM_ABI inline from_chars_result | ||
from_chars(const char* __first, const char* __last, double& __value, chars_format __fmt = chars_format::general) { | ||
return std::__from_chars<double>(__first, __last, __value, __fmt); | ||
} | ||
|
||
#endif // _LIBCPP_STD_VER >= 17 | ||
|
||
_LIBCPP_END_NAMESPACE_STD | ||
|
||
_LIBCPP_POP_MACROS | ||
|
||
#endif // _LIBCPP___CHARCONV_FROM_CHARS_FLOATING_POINT_H |
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
Oops, something went wrong.