File: TeeOutputStream.cpp

package info (click to toggle)
intel-graphics-compiler2 2.28.4-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 792,744 kB
  • sloc: cpp: 5,761,745; ansic: 466,928; lisp: 312,143; python: 114,790; asm: 44,736; pascal: 10,930; sh: 8,033; perl: 7,914; ml: 3,625; awk: 3,523; yacc: 2,747; javascript: 2,667; lex: 1,898; f90: 1,028; cs: 573; xml: 474; makefile: 344; objc: 162
file content (70 lines) | stat: -rw-r--r-- 2,103 bytes parent folder | download
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
/*========================== 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