1//===- raw_ostream.cpp ----------------------------------------------------===// 2// 3// The MCLinker Project 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9#include <mcld/Support/raw_ostream.h> 10 11using namespace mcld; 12 13//===----------------------------------------------------------------------===// 14// raw_ostream 15mcld::raw_fd_ostream::raw_fd_ostream(const char *pFilename, 16 std::string &pErrorInfo, 17 unsigned int pFlags, 18 const MCLDInfo* pLDInfo) 19 : llvm::raw_fd_ostream(pFilename, pErrorInfo, pFlags), m_pLDInfo(pLDInfo) { 20} 21 22mcld::raw_fd_ostream::raw_fd_ostream(int pFD, 23 bool pShouldClose, 24 bool pUnbuffered, 25 const MCLDInfo* pLDInfo) 26 : llvm::raw_fd_ostream(pFD, pShouldClose, pUnbuffered), m_pLDInfo(pLDInfo) { 27} 28 29mcld::raw_fd_ostream::~raw_fd_ostream() 30{ 31} 32 33void mcld::raw_fd_ostream::setLDInfo(const MCLDInfo& pLDInfo) 34{ 35 m_pLDInfo = &pLDInfo; 36} 37 38llvm::raw_ostream & 39mcld::raw_fd_ostream::changeColor(enum llvm::raw_ostream::Colors pColor, 40 bool pBold, 41 bool pBackground) 42{ 43 if (!is_displayed()) 44 return *this; 45 return llvm::raw_fd_ostream::changeColor(pColor, pBold, pBackground); 46} 47 48llvm::raw_ostream& mcld::raw_fd_ostream::resetColor() 49{ 50 if (!is_displayed()) 51 return *this; 52 return llvm::raw_fd_ostream::resetColor(); 53} 54 55// FIXME: migrate to newer LLVM 56/** 57llvm::raw_ostream& mcld::raw_fd_ostream::reverseColor() 58{ 59 if (!is_displayed()) 60 return *this; 61 return llvm::raw_ostream::reverseColor(); 62} 63**/ 64 65bool mcld::raw_fd_ostream::is_displayed() const 66{ 67 if (NULL == m_pLDInfo) 68 return llvm::raw_fd_ostream::is_displayed(); 69 70 return m_pLDInfo->options().color(); 71} 72 73//===----------------------------------------------------------------------===// 74// outs(), errs(), nulls() 75//===----------------------------------------------------------------------===// 76mcld::raw_fd_ostream& mcld::outs() { 77 // Set buffer settings to model stdout behavior. 78 // Delete the file descriptor when the program exists, forcing error 79 // detection. If you don't want this behavior, don't use outs(). 80 static mcld::raw_fd_ostream S(STDOUT_FILENO, true, NULL); 81 return S; 82} 83 84mcld::raw_fd_ostream& mcld::errs() { 85 // Set standard error to be unbuffered by default. 86 static mcld::raw_fd_ostream S(STDERR_FILENO, false, true, NULL); 87 return S; 88} 89 90void mcld::InitializeOStreams(const MCLDInfo& pLDInfo) 91{ 92 outs().setLDInfo(pLDInfo); 93 errs().setLDInfo(pLDInfo); 94} 95 96