1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
|
/*========================== begin_copyright_notice ============================
Copyright (C) 2017-2021 Intel Corporation
SPDX-License-Identifier: MIT
============================= end_copyright_notice ===========================*/
#include "common/debug/TeeOutputStream.hpp"
#include "common/debug/Debug.hpp"
#include "Probe/Assertion.h"
namespace IGC
{
namespace Debug
{
TeeOutputStream::TeeOutputStream(llvm::raw_ostream& lhs, llvm::raw_ostream& rhs)
: raw_ostream( true /* unbuffered */ )
, m_LHS(&lhs)
, m_RHS(&rhs)
, m_deleteLHS(false)
, m_deleteRHS(false)
{
}
TeeOutputStream::TeeOutputStream(
llvm::raw_ostream* pLHS,
bool shouldDeleteLHS,
llvm::raw_ostream* pRHS,
bool shouldDeleteRHS)
: raw_ostream( true /* unbuffered */ )
, m_LHS(pLHS)
, m_RHS(pRHS)
, m_deleteLHS(shouldDeleteLHS)
, m_deleteRHS(shouldDeleteRHS)
{
IGC_ASSERT_MESSAGE((nullptr != pLHS), "LHS must not be null");
IGC_ASSERT_MESSAGE((nullptr != pRHS), "RHS must not be null");
}
TeeOutputStream::~TeeOutputStream()
{
if (m_deleteLHS)
{
delete m_LHS;
}
if (m_deleteRHS)
{
delete m_RHS;
}
}
size_t TeeOutputStream::preferred_buffer_size() const
{
return m_LHS->GetBufferSize();
}
llvm::raw_ostream& TeeOutputStream::changeColor(
enum llvm::raw_ostream::Colors colors,
bool bold,
bool bg)
{
if (m_LHS->has_colors()) m_LHS->changeColor(colors, bold, bg);
if (m_RHS->has_colors()) m_RHS->changeColor(colors, bold, bg);
return *this;
}
llvm::raw_ostream& TeeOutputStream::resetColor()
{
if (m_LHS->has_colors()) m_LHS->resetColor();
if (m_RHS->has_colors()) m_RHS->resetColor();
return *this;
}
llvm::raw_ostream& TeeOutputStream::reverseColor()
{
if (m_LHS->has_colors()) m_LHS->reverseColor();
if (m_RHS->has_colors()) m_RHS->reverseColor();
return *this;
}
void TeeOutputStream::write_impl(const char *Ptr, size_t Size)
{
m_LHS->write(Ptr, Size);
m_RHS->write(Ptr, Size);
}
uint64_t TeeOutputStream::current_pos() const
{
return m_LHS->tell() - m_LHS->GetNumBytesInBuffer();
}
} // namespace Debug
} // namespace IGC
|