diff options
author | Siva Chandra Reddy <sivachandra@google.com> | 2023-04-14 22:11:33 +0000 |
---|---|---|
committer | Siva Chandra Reddy <sivachandra@google.com> | 2023-04-17 15:48:18 +0000 |
commit | dcf296b54134cfa4c59d91ef0e143c951194feef (patch) | |
tree | bbd98b94b9643966e1d7ce1808770e636f61badf /libc/utils | |
parent | 21b68422c84087719ec0f6c216e506d177ac64fd (diff) | |
download | llvm-dcf296b54134cfa4c59d91ef0e143c951194feef.tar.gz |
[libc][NFC] Remove the StreamWrapper class and use the new test logger.
Reviewed By: lntue
Differential Revision: https://reviews.llvm.org/D148452
Diffstat (limited to 'libc/utils')
-rw-r--r-- | libc/utils/MPFRWrapper/MPFRUtils.cpp | 237 | ||||
-rw-r--r-- | libc/utils/MPFRWrapper/MPFRUtils.h | 55 | ||||
-rw-r--r-- | libc/utils/testutils/CMakeLists.txt | 2 | ||||
-rw-r--r-- | libc/utils/testutils/StreamWrapper.cpp | 59 | ||||
-rw-r--r-- | libc/utils/testutils/StreamWrapper.h | 39 |
5 files changed, 141 insertions, 251 deletions
diff --git a/libc/utils/MPFRWrapper/MPFRUtils.cpp b/libc/utils/MPFRWrapper/MPFRUtils.cpp index 53b95344361b..e2a273b6aa98 100644 --- a/libc/utils/MPFRWrapper/MPFRUtils.cpp +++ b/libc/utils/MPFRWrapper/MPFRUtils.cpp @@ -8,6 +8,7 @@ #include "MPFRUtils.h" +#include "src/__support/CPP/string.h" #include "src/__support/CPP/string_view.h" #include "src/__support/FPUtil/FPBits.h" #include "src/__support/FPUtil/PlatformDefs.h" @@ -16,9 +17,7 @@ #include <cmath> #include <fenv.h> #include <memory> -#include <sstream> #include <stdint.h> -#include <string> #ifdef CUSTOM_MPFR_INCLUDER // Some downstream repos are monoliths carrying MPFR sources in their third @@ -417,7 +416,7 @@ public: return result; } - std::string str() const { + cpp::string str() const { // 200 bytes should be more than sufficient to hold a 100-digit number // plus additional bytes for the decimal point, '-' sign etc. constexpr size_t printBufSize = 200; @@ -430,7 +429,7 @@ public: view.remove_prefix(1); while (!view.empty() && view.back() == whitespace) view.remove_suffix(1); - return std::string(view.data()); + return cpp::string(view.data()); } // These functions are useful for debugging. @@ -463,15 +462,16 @@ public: // of N between this number and [input]. // 4. A values of +0.0 and -0.0 are treated as equal. template <typename T> - cpp::enable_if_t<cpp::is_floating_point_v<T>, double> ulp(T input) { + cpp::enable_if_t<cpp::is_floating_point_v<T>, MPFRNumber> + ulp_as_mpfr_number(T input) { T thisAsT = as<T>(); if (thisAsT == input) - return T(0.0); + return MPFRNumber(0.0); if (is_nan()) { if (fputil::FPBits<T>(input).is_nan()) - return T(0.0); - return T(fputil::FPBits<T>::inf()); + return MPFRNumber(0.0); + return MPFRNumber(static_cast<T>(fputil::FPBits<T>::inf())); } int thisExponent = fputil::FPBits<T>(thisAsT).get_exponent(); @@ -489,7 +489,7 @@ public: mpfr_mul_2si(inputMPFR.value, inputMPFR.value, -thisExponent + int(fputil::MantissaWidth<T>::VALUE), MPFR_RNDN); - return inputMPFR.as<double>(); + return inputMPFR; } // If the control reaches here, it means that this number and input are @@ -524,7 +524,20 @@ public: MPFR_RNDN); mpfr_add(minMPFR.value, minMPFR.value, maxMPFR.value, MPFR_RNDN); - return minMPFR.as<double>(); + return minMPFR; + } + + template <typename T> + cpp::enable_if_t<cpp::is_floating_point_v<T>, cpp::string> + ulp_as_string(T input) { + MPFRNumber num = ulp_as_mpfr_number(input); + return num.str(); + } + + template <typename T> + cpp::enable_if_t<cpp::is_floating_point_v<T>, double> ulp(T input) { + MPFRNumber num = ulp_as_mpfr_number(input); + return num.as<double>(); } }; @@ -682,93 +695,84 @@ template <typename T> void explain_unary_operation_single_output_error(Operation op, T input, T matchValue, double ulp_tolerance, - RoundingMode rounding, - testutils::StreamWrapper &OS) { + RoundingMode rounding) { unsigned int precision = get_precision<T>(ulp_tolerance); MPFRNumber mpfrInput(input, precision); MPFRNumber mpfr_result; mpfr_result = unary_operation(op, input, precision, rounding); MPFRNumber mpfrMatchValue(matchValue); - std::stringstream ss; - ss << "Match value not within tolerance value of MPFR result:\n" - << " Input decimal: " << mpfrInput.str() << '\n'; - __llvm_libc::fputil::testing::describeValue(" Input bits: ", input, ss); - ss << '\n' << " Match decimal: " << mpfrMatchValue.str() << '\n'; - __llvm_libc::fputil::testing::describeValue(" Match bits: ", matchValue, - ss); - ss << '\n' << " MPFR result: " << mpfr_result.str() << '\n'; - __llvm_libc::fputil::testing::describeValue( - " MPFR rounded: ", mpfr_result.as<T>(), ss); - ss << '\n'; - ss << " ULP error: " << std::to_string(mpfr_result.ulp(matchValue)) - << '\n'; - OS << ss.str(); + tlog << "Match value not within tolerance value of MPFR result:\n" + << " Input decimal: " << mpfrInput.str() << '\n'; + __llvm_libc::fputil::testing::describeValue(" Input bits: ", input); + tlog << '\n' << " Match decimal: " << mpfrMatchValue.str() << '\n'; + __llvm_libc::fputil::testing::describeValue(" Match bits: ", matchValue); + tlog << '\n' << " MPFR result: " << mpfr_result.str() << '\n'; + __llvm_libc::fputil::testing::describeValue(" MPFR rounded: ", + mpfr_result.as<T>()); + tlog << '\n'; + tlog << " ULP error: " + << mpfr_result.ulp_as_mpfr_number(matchValue).str() << '\n'; } -template void -explain_unary_operation_single_output_error<float>(Operation op, float, float, - double, RoundingMode, - testutils::StreamWrapper &); +template void explain_unary_operation_single_output_error<float>(Operation op, + float, float, + double, + RoundingMode); template void explain_unary_operation_single_output_error<double>( - Operation op, double, double, double, RoundingMode, - testutils::StreamWrapper &); + Operation op, double, double, double, RoundingMode); template void explain_unary_operation_single_output_error<long double>( - Operation op, long double, long double, double, RoundingMode, - testutils::StreamWrapper &); + Operation op, long double, long double, double, RoundingMode); template <typename T> void explain_unary_operation_two_outputs_error( Operation op, T input, const BinaryOutput<T> &libc_result, - double ulp_tolerance, RoundingMode rounding, testutils::StreamWrapper &OS) { + double ulp_tolerance, RoundingMode rounding) { unsigned int precision = get_precision<T>(ulp_tolerance); MPFRNumber mpfrInput(input, precision); int mpfrIntResult; MPFRNumber mpfr_result = unary_operation_two_outputs(op, input, mpfrIntResult, precision, rounding); - std::stringstream ss; if (mpfrIntResult != libc_result.i) { - ss << "MPFR integral result: " << mpfrIntResult << '\n' - << "Libc integral result: " << libc_result.i << '\n'; + tlog << "MPFR integral result: " << mpfrIntResult << '\n' + << "Libc integral result: " << libc_result.i << '\n'; } else { - ss << "Integral result from libc matches integral result from MPFR.\n"; + tlog << "Integral result from libc matches integral result from MPFR.\n"; } MPFRNumber mpfrMatchValue(libc_result.f); - ss << "Libc floating point result is not within tolerance value of the MPFR " - << "result.\n\n"; - - ss << " Input decimal: " << mpfrInput.str() << "\n\n"; - - ss << "Libc floating point value: " << mpfrMatchValue.str() << '\n'; - __llvm_libc::fputil::testing::describeValue( - " Libc floating point bits: ", libc_result.f, ss); - ss << "\n\n"; - - ss << " MPFR result: " << mpfr_result.str() << '\n'; - __llvm_libc::fputil::testing::describeValue( - " MPFR rounded: ", mpfr_result.as<T>(), ss); - ss << '\n' - << " ULP error: " - << std::to_string(mpfr_result.ulp(libc_result.f)) << '\n'; - OS << ss.str(); + tlog + << "Libc floating point result is not within tolerance value of the MPFR " + << "result.\n\n"; + + tlog << " Input decimal: " << mpfrInput.str() << "\n\n"; + + tlog << "Libc floating point value: " << mpfrMatchValue.str() << '\n'; + __llvm_libc::fputil::testing::describeValue(" Libc floating point bits: ", + libc_result.f); + tlog << "\n\n"; + + tlog << " MPFR result: " << mpfr_result.str() << '\n'; + __llvm_libc::fputil::testing::describeValue(" MPFR rounded: ", + mpfr_result.as<T>()); + tlog << '\n' + << " ULP error: " + << mpfr_result.ulp_as_mpfr_number(libc_result.f).str() << '\n'; } template void explain_unary_operation_two_outputs_error<float>( - Operation, float, const BinaryOutput<float> &, double, RoundingMode, - testutils::StreamWrapper &); + Operation, float, const BinaryOutput<float> &, double, RoundingMode); template void explain_unary_operation_two_outputs_error<double>( - Operation, double, const BinaryOutput<double> &, double, RoundingMode, - testutils::StreamWrapper &); + Operation, double, const BinaryOutput<double> &, double, RoundingMode); template void explain_unary_operation_two_outputs_error<long double>( Operation, long double, const BinaryOutput<long double> &, double, - RoundingMode, testutils::StreamWrapper &); + RoundingMode); template <typename T> void explain_binary_operation_two_outputs_error( Operation op, const BinaryInput<T> &input, const BinaryOutput<T> &libc_result, double ulp_tolerance, - RoundingMode rounding, testutils::StreamWrapper &OS) { + RoundingMode rounding) { unsigned int precision = get_precision<T>(ulp_tolerance); MPFRNumber mpfrX(input.x, precision); MPFRNumber mpfrY(input.y, precision); @@ -776,36 +780,36 @@ void explain_binary_operation_two_outputs_error( MPFRNumber mpfr_result = binary_operation_two_outputs( op, input.x, input.y, mpfrIntResult, precision, rounding); MPFRNumber mpfrMatchValue(libc_result.f); - std::stringstream ss; - ss << "Input decimal: x: " << mpfrX.str() << " y: " << mpfrY.str() << '\n' - << "MPFR integral result: " << mpfrIntResult << '\n' - << "Libc integral result: " << libc_result.i << '\n' - << "Libc floating point result: " << mpfrMatchValue.str() << '\n' - << " MPFR result: " << mpfr_result.str() << '\n'; + tlog << "Input decimal: x: " << mpfrX.str() << " y: " << mpfrY.str() << '\n' + << "MPFR integral result: " << mpfrIntResult << '\n' + << "Libc integral result: " << libc_result.i << '\n' + << "Libc floating point result: " << mpfrMatchValue.str() << '\n' + << " MPFR result: " << mpfr_result.str() << '\n'; __llvm_libc::fputil::testing::describeValue( - "Libc floating point result bits: ", libc_result.f, ss); + "Libc floating point result bits: ", libc_result.f); __llvm_libc::fputil::testing::describeValue( - " MPFR rounded bits: ", mpfr_result.as<T>(), ss); - ss << "ULP error: " << std::to_string(mpfr_result.ulp(libc_result.f)) << '\n'; - OS << ss.str(); + " MPFR rounded bits: ", mpfr_result.as<T>()); + tlog << "ULP error: " << mpfr_result.ulp_as_mpfr_number(libc_result.f).str() + << '\n'; } template void explain_binary_operation_two_outputs_error<float>( Operation, const BinaryInput<float> &, const BinaryOutput<float> &, double, - RoundingMode, testutils::StreamWrapper &); + RoundingMode); template void explain_binary_operation_two_outputs_error<double>( Operation, const BinaryInput<double> &, const BinaryOutput<double> &, - double, RoundingMode, testutils::StreamWrapper &); + double, RoundingMode); template void explain_binary_operation_two_outputs_error<long double>( Operation, const BinaryInput<long double> &, - const BinaryOutput<long double> &, double, RoundingMode, - testutils::StreamWrapper &); + const BinaryOutput<long double> &, double, RoundingMode); template <typename T> -void explain_binary_operation_one_output_error( - Operation op, const BinaryInput<T> &input, T libc_result, - double ulp_tolerance, RoundingMode rounding, testutils::StreamWrapper &OS) { +void explain_binary_operation_one_output_error(Operation op, + const BinaryInput<T> &input, + T libc_result, + double ulp_tolerance, + RoundingMode rounding) { unsigned int precision = get_precision<T>(ulp_tolerance); MPFRNumber mpfrX(input.x, precision); MPFRNumber mpfrY(input.y, precision); @@ -814,38 +818,35 @@ void explain_binary_operation_one_output_error( MPFRNumber mpfr_result = binary_operation_one_output(op, input.x, input.y, precision, rounding); MPFRNumber mpfrMatchValue(libc_result); - std::stringstream ss; - ss << "Input decimal: x: " << mpfrX.str() << " y: " << mpfrY.str() << '\n'; - __llvm_libc::fputil::testing::describeValue("First input bits: ", input.x, - ss); - __llvm_libc::fputil::testing::describeValue("Second input bits: ", input.y, - ss); + tlog << "Input decimal: x: " << mpfrX.str() << " y: " << mpfrY.str() << '\n'; + __llvm_libc::fputil::testing::describeValue("First input bits: ", input.x); + __llvm_libc::fputil::testing::describeValue("Second input bits: ", input.y); - ss << "Libc result: " << mpfrMatchValue.str() << '\n' - << "MPFR result: " << mpfr_result.str() << '\n'; + tlog << "Libc result: " << mpfrMatchValue.str() << '\n' + << "MPFR result: " << mpfr_result.str() << '\n'; __llvm_libc::fputil::testing::describeValue( - "Libc floating point result bits: ", libc_result, ss); + "Libc floating point result bits: ", libc_result); __llvm_libc::fputil::testing::describeValue( - " MPFR rounded bits: ", mpfr_result.as<T>(), ss); - ss << "ULP error: " << std::to_string(mpfr_result.ulp(libc_result)) << '\n'; - OS << ss.str(); + " MPFR rounded bits: ", mpfr_result.as<T>()); + tlog << "ULP error: " << mpfr_result.ulp_as_mpfr_number(libc_result).str() + << '\n'; } template void explain_binary_operation_one_output_error<float>( - Operation, const BinaryInput<float> &, float, double, RoundingMode, - testutils::StreamWrapper &); + Operation, const BinaryInput<float> &, float, double, RoundingMode); template void explain_binary_operation_one_output_error<double>( - Operation, const BinaryInput<double> &, double, double, RoundingMode, - testutils::StreamWrapper &); + Operation, const BinaryInput<double> &, double, double, RoundingMode); template void explain_binary_operation_one_output_error<long double>( Operation, const BinaryInput<long double> &, long double, double, - RoundingMode, testutils::StreamWrapper &); + RoundingMode); template <typename T> -void explain_ternary_operation_one_output_error( - Operation op, const TernaryInput<T> &input, T libc_result, - double ulp_tolerance, RoundingMode rounding, testutils::StreamWrapper &OS) { +void explain_ternary_operation_one_output_error(Operation op, + const TernaryInput<T> &input, + T libc_result, + double ulp_tolerance, + RoundingMode rounding) { unsigned int precision = get_precision<T>(ulp_tolerance); MPFRNumber mpfrX(input.x, precision); MPFRNumber mpfrY(input.y, precision); @@ -856,36 +857,30 @@ void explain_ternary_operation_one_output_error( MPFRNumber mpfr_result = ternary_operation_one_output( op, input.x, input.y, input.z, precision, rounding); MPFRNumber mpfrMatchValue(libc_result); - std::stringstream ss; - - ss << "Input decimal: x: " << mpfrX.str() << " y: " << mpfrY.str() - << " z: " << mpfrZ.str() << '\n'; - __llvm_libc::fputil::testing::describeValue("First input bits: ", input.x, - ss); - __llvm_libc::fputil::testing::describeValue("Second input bits: ", input.y, - ss); - __llvm_libc::fputil::testing::describeValue("Third input bits: ", input.z, - ss); - - ss << "Libc result: " << mpfrMatchValue.str() << '\n' - << "MPFR result: " << mpfr_result.str() << '\n'; + + tlog << "Input decimal: x: " << mpfrX.str() << " y: " << mpfrY.str() + << " z: " << mpfrZ.str() << '\n'; + __llvm_libc::fputil::testing::describeValue("First input bits: ", input.x); + __llvm_libc::fputil::testing::describeValue("Second input bits: ", input.y); + __llvm_libc::fputil::testing::describeValue("Third input bits: ", input.z); + + tlog << "Libc result: " << mpfrMatchValue.str() << '\n' + << "MPFR result: " << mpfr_result.str() << '\n'; __llvm_libc::fputil::testing::describeValue( - "Libc floating point result bits: ", libc_result, ss); + "Libc floating point result bits: ", libc_result); __llvm_libc::fputil::testing::describeValue( - " MPFR rounded bits: ", mpfr_result.as<T>(), ss); - ss << "ULP error: " << std::to_string(mpfr_result.ulp(libc_result)) << '\n'; - OS << ss.str(); + " MPFR rounded bits: ", mpfr_result.as<T>()); + tlog << "ULP error: " << mpfr_result.ulp_as_mpfr_number(libc_result).str() + << '\n'; } template void explain_ternary_operation_one_output_error<float>( - Operation, const TernaryInput<float> &, float, double, RoundingMode, - testutils::StreamWrapper &); + Operation, const TernaryInput<float> &, float, double, RoundingMode); template void explain_ternary_operation_one_output_error<double>( - Operation, const TernaryInput<double> &, double, double, RoundingMode, - testutils::StreamWrapper &); + Operation, const TernaryInput<double> &, double, double, RoundingMode); template void explain_ternary_operation_one_output_error<long double>( Operation, const TernaryInput<long double> &, long double, double, - RoundingMode, testutils::StreamWrapper &); + RoundingMode); template <typename T> bool compare_unary_operation_single_output(Operation op, T input, T libc_result, diff --git a/libc/utils/MPFRWrapper/MPFRUtils.h b/libc/utils/MPFRWrapper/MPFRUtils.h index a202003764aa..450b31ae8c5c 100644 --- a/libc/utils/MPFRWrapper/MPFRUtils.h +++ b/libc/utils/MPFRWrapper/MPFRUtils.h @@ -156,27 +156,30 @@ template <typename T> void explain_unary_operation_single_output_error(Operation op, T input, T match_value, double ulp_tolerance, - RoundingMode rounding, - testutils::StreamWrapper &OS); + RoundingMode rounding); template <typename T> void explain_unary_operation_two_outputs_error( Operation op, T input, const BinaryOutput<T> &match_value, - double ulp_tolerance, RoundingMode rounding, testutils::StreamWrapper &OS); + double ulp_tolerance, RoundingMode rounding); template <typename T> void explain_binary_operation_two_outputs_error( Operation op, const BinaryInput<T> &input, const BinaryOutput<T> &match_value, double ulp_tolerance, - RoundingMode rounding, testutils::StreamWrapper &OS); + RoundingMode rounding); template <typename T> -void explain_binary_operation_one_output_error( - Operation op, const BinaryInput<T> &input, T match_value, - double ulp_tolerance, RoundingMode rounding, testutils::StreamWrapper &OS); +void explain_binary_operation_one_output_error(Operation op, + const BinaryInput<T> &input, + T match_value, + double ulp_tolerance, + RoundingMode rounding); template <typename T> -void explain_ternary_operation_one_output_error( - Operation op, const TernaryInput<T> &input, T match_value, - double ulp_tolerance, RoundingMode rounding, testutils::StreamWrapper &OS); +void explain_ternary_operation_one_output_error(Operation op, + const TernaryInput<T> &input, + T match_value, + double ulp_tolerance, + RoundingMode rounding); template <Operation op, bool silent, typename InputType, typename OutputType> class MPFRMatcher : public testing::Matcher<OutputType> { @@ -196,8 +199,8 @@ public: // This method is marked with NOLINT because it the name `explainError` // does not confirm to the coding style. - void explainError(testutils::StreamWrapper &OS) override { // NOLINT - explain_error(input, match_value, OS); + void explainError() override { // NOLINT + explain_error(input, match_value); } // Whether the `explainError` step is skipped or not. @@ -230,38 +233,30 @@ private: rounding); } - template <typename T> - void explain_error(T in, T out, testutils::StreamWrapper &OS) { + template <typename T> void explain_error(T in, T out) { explain_unary_operation_single_output_error(op, in, out, ulp_tolerance, - rounding, OS); + rounding); } - template <typename T> - void explain_error(T in, const BinaryOutput<T> &out, - testutils::StreamWrapper &OS) { + template <typename T> void explain_error(T in, const BinaryOutput<T> &out) { explain_unary_operation_two_outputs_error(op, in, out, ulp_tolerance, - rounding, OS); + rounding); } template <typename T> - void explain_error(const BinaryInput<T> &in, const BinaryOutput<T> &out, - testutils::StreamWrapper &OS) { + void explain_error(const BinaryInput<T> &in, const BinaryOutput<T> &out) { explain_binary_operation_two_outputs_error(op, in, out, ulp_tolerance, - rounding, OS); + rounding); } - template <typename T> - void explain_error(const BinaryInput<T> &in, T out, - testutils::StreamWrapper &OS) { + template <typename T> void explain_error(const BinaryInput<T> &in, T out) { explain_binary_operation_one_output_error(op, in, out, ulp_tolerance, - rounding, OS); + rounding); } - template <typename T> - void explain_error(const TernaryInput<T> &in, T out, - testutils::StreamWrapper &OS) { + template <typename T> void explain_error(const TernaryInput<T> &in, T out) { explain_ternary_operation_one_output_error(op, in, out, ulp_tolerance, - rounding, OS); + rounding); } }; diff --git a/libc/utils/testutils/CMakeLists.txt b/libc/utils/testutils/CMakeLists.txt index be1e5a177754..9ec358f3839c 100644 --- a/libc/utils/testutils/CMakeLists.txt +++ b/libc/utils/testutils/CMakeLists.txt @@ -5,8 +5,6 @@ endif() add_library( libc_test_utils - StreamWrapper.cpp - StreamWrapper.h ${EFFile} ExecuteFunction.h ${FDReaderFile} diff --git a/libc/utils/testutils/StreamWrapper.cpp b/libc/utils/testutils/StreamWrapper.cpp deleted file mode 100644 index f65c9c3055ce..000000000000 --- a/libc/utils/testutils/StreamWrapper.cpp +++ /dev/null @@ -1,59 +0,0 @@ -//===-- StreamWrapper.cpp -------------------------------------------------===// -// -// 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 "StreamWrapper.h" -#include <cassert> -#include <fstream> -#include <iostream> -#include <memory> -#include <string> - -namespace __llvm_libc { -namespace testutils { - -StreamWrapper outs() { return {std::addressof(std::cout)}; } - -template <typename T> StreamWrapper &StreamWrapper::operator<<(T t) { - assert(os); - std::ostream &Stream = *reinterpret_cast<std::ostream *>(os); - Stream << t; - Stream.flush(); - return *this; -} - -template StreamWrapper &StreamWrapper::operator<<<void *>(void *t); -template StreamWrapper &StreamWrapper::operator<<<const char *>(const char *t); -template StreamWrapper &StreamWrapper::operator<<<char *>(char *t); -template StreamWrapper &StreamWrapper::operator<<<char>(char t); -template StreamWrapper &StreamWrapper::operator<<<short>(short t); -template StreamWrapper &StreamWrapper::operator<<<int>(int t); -template StreamWrapper &StreamWrapper::operator<<<long>(long t); -template StreamWrapper &StreamWrapper::operator<<<long long>(long long t); -template StreamWrapper & - StreamWrapper::operator<<<unsigned char>(unsigned char t); -template StreamWrapper & - StreamWrapper::operator<<<unsigned short>(unsigned short t); -template StreamWrapper &StreamWrapper::operator<<<unsigned int>(unsigned int t); -template StreamWrapper & - StreamWrapper::operator<<<unsigned long>(unsigned long t); -template StreamWrapper & - StreamWrapper::operator<<<unsigned long long>(unsigned long long t); -template StreamWrapper &StreamWrapper::operator<<<bool>(bool t); -template StreamWrapper &StreamWrapper::operator<<<std::string>(std::string t); -template StreamWrapper &StreamWrapper::operator<<<float>(float t); -template StreamWrapper &StreamWrapper::operator<<<double>(double t); - -OutputFileStream::OutputFileStream(const char *FN) - : StreamWrapper(new std::ofstream(FN)) {} - -OutputFileStream::~OutputFileStream() { - delete reinterpret_cast<std::ofstream *>(os); -} - -} // namespace testutils -} // namespace __llvm_libc diff --git a/libc/utils/testutils/StreamWrapper.h b/libc/utils/testutils/StreamWrapper.h deleted file mode 100644 index f4309abdedef..000000000000 --- a/libc/utils/testutils/StreamWrapper.h +++ /dev/null @@ -1,39 +0,0 @@ -//===-- StreamWrapper.h -----------------------------------------*- 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_UTILS_TESTUTILS_STREAMWRAPPER_H -#define LLVM_LIBC_UTILS_TESTUTILS_STREAMWRAPPER_H - -namespace __llvm_libc { -namespace testutils { - -// StreamWrapper is necessary because llvm/Support/raw_ostream.h includes -// standard headers so we must provide streams through indirection to not -// expose the system libc headers. -class StreamWrapper { -protected: - void *os; - -public: - StreamWrapper(void *OS) : os(OS) {} - - template <typename T> StreamWrapper &operator<<(T t); -}; - -StreamWrapper outs(); - -class OutputFileStream : public StreamWrapper { -public: - explicit OutputFileStream(const char *FN); - ~OutputFileStream(); -}; - -} // namespace testutils -} // namespace __llvm_libc - -#endif // LLVM_LIBC_UTILS_TESTUTILS_STREAMWRAPPER_H |