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_RAW_OSTREAM_H_
10 #define MCLD_SUPPORT_RAW_OSTREAM_H_
11 #include <llvm/Support/FileSystem.h>
12 #include <llvm/Support/raw_ostream.h>
13 
14 #include <string>
15 
16 namespace mcld {
17 
18 class raw_fd_ostream : public llvm::raw_fd_ostream {
19  public:
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::error_code& pErrorCode,
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   llvm::raw_ostream& changeColor(enum llvm::raw_ostream::Colors pColors,
43                                  bool pBold = false,
44                                  bool pBackground = false);
45 
46   llvm::raw_ostream& resetColor();
47 
48   llvm::raw_ostream& reverseColor();
49 
50   bool is_displayed() const;
51 
52  private:
53   bool m_bConfigColor : 1;
54   bool m_bSetColor : 1;
55 };
56 
57 /// outs() - This returns a reference to a raw_ostream for standard output.
58 /// Use it like: outs() << "foo" << "bar";
59 mcld::raw_fd_ostream& outs();
60 
61 /// errs() - This returns a reference to a raw_ostream for standard error.
62 /// Use it like: errs() << "foo" << "bar";
63 mcld::raw_fd_ostream& errs();
64 
65 }  // namespace mcld
66 
67 #endif  // MCLD_SUPPORT_RAW_OSTREAM_H_
68