1//===- raw_ostream.h ------------------------------------------------------===//
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#ifndef MCLD_SUPPORT_RAWOSTREAM_H
10#define MCLD_SUPPORT_RAWOSTREAM_H
11#include <string>
12#include <llvm/Support/FileSystem.h>
13#include <llvm/Support/raw_ostream.h>
14
15namespace mcld {
16
17class raw_fd_ostream : public llvm::raw_fd_ostream
18{
19public:
20  /// raw_fd_ostream - Open the specified file for writing. If an error occurs,
21  /// information about the error is put into ErrorInfo, and the stream should
22  /// be immediately destroyed; the string will be empty if no error occurred.
23  /// This allows optional flags to control how the file will be opened.
24  ///
25  /// As a special case, if Filename is "-", then the stream will use
26  /// STDOUT_FILENO instead of opening a file. Note that it will still consider
27  /// itself to own the file descriptor. In particular, it will close the
28  /// file descriptor when it is done (this is necessary to detect
29  /// output errors).
30  raw_fd_ostream(const char *pFilename,
31                 std::string &pErrorInfo,
32                 llvm::sys::fs::OpenFlags pFlags = llvm::sys::fs::F_None);
33
34  /// raw_fd_ostream ctor - FD is the file descriptor that this writes to.  If
35  /// ShouldClose is true, this closes the file when the stream is destroyed.
36  raw_fd_ostream(int pFD, bool pShouldClose, bool pUnbuffered=false);
37
38  virtual ~raw_fd_ostream();
39
40  void setColor(bool pEnable = true);
41
42
43  llvm::raw_ostream &changeColor(enum llvm::raw_ostream::Colors pColors,
44                                 bool pBold=false,
45                                 bool pBackground=false);
46
47  llvm::raw_ostream &resetColor();
48
49  llvm::raw_ostream &reverseColor();
50
51  bool is_displayed() const;
52
53private:
54  bool m_bConfigColor : 1;
55  bool m_bSetColor : 1;
56
57};
58
59/// outs() - This returns a reference to a raw_ostream for standard output.
60/// Use it like: outs() << "foo" << "bar";
61mcld::raw_fd_ostream &outs();
62
63/// errs() - This returns a reference to a raw_ostream for standard error.
64/// Use it like: errs() << "foo" << "bar";
65mcld::raw_fd_ostream &errs();
66
67} // namespace of mcld
68
69#endif
70
71