1affc150dc44fab1911775a49636d0ce85333b634Zonr Chang//===- raw_ostream.h ------------------------------------------------------===//
2affc150dc44fab1911775a49636d0ce85333b634Zonr Chang//
3affc150dc44fab1911775a49636d0ce85333b634Zonr Chang//                     The MCLinker Project
4affc150dc44fab1911775a49636d0ce85333b634Zonr Chang//
5affc150dc44fab1911775a49636d0ce85333b634Zonr Chang// This file is distributed under the University of Illinois Open Source
6affc150dc44fab1911775a49636d0ce85333b634Zonr Chang// License. See LICENSE.TXT for details.
7affc150dc44fab1911775a49636d0ce85333b634Zonr Chang//
8affc150dc44fab1911775a49636d0ce85333b634Zonr Chang//===----------------------------------------------------------------------===//
9affc150dc44fab1911775a49636d0ce85333b634Zonr Chang#ifndef MCLD_RAW_OSTREAM_H
10affc150dc44fab1911775a49636d0ce85333b634Zonr Chang#define MCLD_RAW_OSTREAM_H
11affc150dc44fab1911775a49636d0ce85333b634Zonr Chang#ifdef ENABLE_UNITTEST
12affc150dc44fab1911775a49636d0ce85333b634Zonr Chang#include <gtest.h>
13affc150dc44fab1911775a49636d0ce85333b634Zonr Chang#endif
14affc150dc44fab1911775a49636d0ce85333b634Zonr Chang#include <string>
15affc150dc44fab1911775a49636d0ce85333b634Zonr Chang#include <llvm/Support/raw_ostream.h>
16affc150dc44fab1911775a49636d0ce85333b634Zonr Chang
1722add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liaonamespace mcld {
18affc150dc44fab1911775a49636d0ce85333b634Zonr Chang
19affc150dc44fab1911775a49636d0ce85333b634Zonr Changclass raw_fd_ostream : public llvm::raw_fd_ostream
20affc150dc44fab1911775a49636d0ce85333b634Zonr Chang{
21affc150dc44fab1911775a49636d0ce85333b634Zonr Changpublic:
22affc150dc44fab1911775a49636d0ce85333b634Zonr Chang  /// raw_fd_ostream - Open the specified file for writing. If an error occurs,
23affc150dc44fab1911775a49636d0ce85333b634Zonr Chang  /// information about the error is put into ErrorInfo, and the stream should
24affc150dc44fab1911775a49636d0ce85333b634Zonr Chang  /// be immediately destroyed; the string will be empty if no error occurred.
25affc150dc44fab1911775a49636d0ce85333b634Zonr Chang  /// This allows optional flags to control how the file will be opened.
26affc150dc44fab1911775a49636d0ce85333b634Zonr Chang  ///
27affc150dc44fab1911775a49636d0ce85333b634Zonr Chang  /// As a special case, if Filename is "-", then the stream will use
28affc150dc44fab1911775a49636d0ce85333b634Zonr Chang  /// STDOUT_FILENO instead of opening a file. Note that it will still consider
29affc150dc44fab1911775a49636d0ce85333b634Zonr Chang  /// itself to own the file descriptor. In particular, it will close the
30affc150dc44fab1911775a49636d0ce85333b634Zonr Chang  /// file descriptor when it is done (this is necessary to detect
31affc150dc44fab1911775a49636d0ce85333b634Zonr Chang  /// output errors).
32affc150dc44fab1911775a49636d0ce85333b634Zonr Chang  raw_fd_ostream(const char *pFilename,
33affc150dc44fab1911775a49636d0ce85333b634Zonr Chang                 std::string &pErrorInfo,
3422add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao                 unsigned int pFlags = 0);
35affc150dc44fab1911775a49636d0ce85333b634Zonr Chang
36affc150dc44fab1911775a49636d0ce85333b634Zonr Chang  /// raw_fd_ostream ctor - FD is the file descriptor that this writes to.  If
37affc150dc44fab1911775a49636d0ce85333b634Zonr Chang  /// ShouldClose is true, this closes the file when the stream is destroyed.
3822add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao  raw_fd_ostream(int pFD, bool pShouldClose, bool pUnbuffered=false);
39affc150dc44fab1911775a49636d0ce85333b634Zonr Chang
40affc150dc44fab1911775a49636d0ce85333b634Zonr Chang  virtual ~raw_fd_ostream();
41affc150dc44fab1911775a49636d0ce85333b634Zonr Chang
4222add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao  void setColor(bool pEnable = true);
43affc150dc44fab1911775a49636d0ce85333b634Zonr Chang
44affc150dc44fab1911775a49636d0ce85333b634Zonr Chang
45affc150dc44fab1911775a49636d0ce85333b634Zonr Chang  llvm::raw_ostream &changeColor(enum llvm::raw_ostream::Colors pColors,
46affc150dc44fab1911775a49636d0ce85333b634Zonr Chang                                 bool pBold=false,
47affc150dc44fab1911775a49636d0ce85333b634Zonr Chang                                 bool pBackground=false);
48affc150dc44fab1911775a49636d0ce85333b634Zonr Chang
49affc150dc44fab1911775a49636d0ce85333b634Zonr Chang  llvm::raw_ostream &resetColor();
50affc150dc44fab1911775a49636d0ce85333b634Zonr Chang
5122add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao  llvm::raw_ostream &reverseColor();
52affc150dc44fab1911775a49636d0ce85333b634Zonr Chang
53affc150dc44fab1911775a49636d0ce85333b634Zonr Chang  bool is_displayed() const;
54affc150dc44fab1911775a49636d0ce85333b634Zonr Chang
55affc150dc44fab1911775a49636d0ce85333b634Zonr Changprivate:
5622add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao  bool m_bConfigColor : 1;
5722add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao  bool m_bSetColor : 1;
58affc150dc44fab1911775a49636d0ce85333b634Zonr Chang
59affc150dc44fab1911775a49636d0ce85333b634Zonr Chang};
60affc150dc44fab1911775a49636d0ce85333b634Zonr Chang
61affc150dc44fab1911775a49636d0ce85333b634Zonr Chang/// outs() - This returns a reference to a raw_ostream for standard output.
62affc150dc44fab1911775a49636d0ce85333b634Zonr Chang/// Use it like: outs() << "foo" << "bar";
63affc150dc44fab1911775a49636d0ce85333b634Zonr Changmcld::raw_fd_ostream &outs();
64affc150dc44fab1911775a49636d0ce85333b634Zonr Chang
65affc150dc44fab1911775a49636d0ce85333b634Zonr Chang/// errs() - This returns a reference to a raw_ostream for standard error.
66affc150dc44fab1911775a49636d0ce85333b634Zonr Chang/// Use it like: errs() << "foo" << "bar";
67affc150dc44fab1911775a49636d0ce85333b634Zonr Changmcld::raw_fd_ostream &errs();
68affc150dc44fab1911775a49636d0ce85333b634Zonr Chang
69affc150dc44fab1911775a49636d0ce85333b634Zonr Chang} // namespace of mcld
70affc150dc44fab1911775a49636d0ce85333b634Zonr Chang
71affc150dc44fab1911775a49636d0ce85333b634Zonr Chang#endif
72affc150dc44fab1911775a49636d0ce85333b634Zonr Chang
73