aboutsummaryrefslogtreecommitdiffstats
path: root/include/llvm/CodeGen/AsmFormatter.h
blob: 7d446bcd29e64fe52f2b1cad8fa7be6bd86e7d11 (plain)
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
//===-- llvm/CodeGen/AsmFormatter.h - Formatted asm framework ---*- C++ -*-===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file contains various I/O manipulators to pretty-print asm.
//
//===----------------------------------------------------------------------===//

#include "llvm/Support/FormattedStream.h"
#include "llvm/Target/TargetAsmInfo.h"

namespace llvm 
{
  /// AsmComment - An I/O manipulator to output an end-of-line comment
  ///
  class AsmComment : public Column {
  private:
    /// CommentColumn - The column at which to output a comment
    ///
    static const int CommentColumn = 60;
    /// Text - The comment to output
    ///
    std::string Text;
    /// TAI - Target information from the code generator
    ///
    const TargetAsmInfo &TAI;
    
  public:
    AsmComment(const TargetAsmInfo &T) 
        : Column(CommentColumn), Text(""), TAI(T) {}

    AsmComment(const std::string &Cmnt,
            const TargetAsmInfo &T) 
        : Column(CommentColumn), Text(Cmnt), TAI(T) {}

    /// operator() - Store a comments tring for later processing.
    ///
    AsmComment &operator()(const std::string &Cmnt) {
      Text = Cmnt;
      return *this;
    }

    /// operator() - Make Comment a functor invoktable by a stream
    /// output operator.  This intentially hides Column's operator().
    ///
    formatted_raw_ostream &operator()(formatted_raw_ostream &Out) const {
      Column::operator()(Out);
      Out << TAI.getCommentString() << " " << Text;
      return(Out);
    }
  };

  /// operator<< - Support comment formatting in formatted streams.
  ///
  inline formatted_raw_ostream &operator<<(formatted_raw_ostream &Out,
                                           const AsmComment &Func)
  {
    return(Func(Out));
  }
}