d20d8d2c8367e54999f9f9c979a94bde914efea3
[oota-llvm.git] / include / llvm / MC / MCInstPrinter.h
1 //===-- MCInstPrinter.h - Convert an MCInst to target assembly syntax -----===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #ifndef LLVM_MC_MCINSTPRINTER_H
11 #define LLVM_MC_MCINSTPRINTER_H
12
13 #include "llvm/Support/Format.h"
14
15 namespace llvm {
16 class MCInst;
17 class raw_ostream;
18 class MCAsmInfo;
19 class MCInstrInfo;
20 class MCRegisterInfo;
21 class StringRef;
22
23 /// MCInstPrinter - This is an instance of a target assembly language printer
24 /// that converts an MCInst to valid target assembly syntax.
25 class MCInstPrinter {
26 protected:
27   /// CommentStream - a stream that comments can be emitted to if desired.
28   /// Each comment must end with a newline.  This will be null if verbose
29   /// assembly emission is disable.
30   raw_ostream *CommentStream;
31   const MCAsmInfo &MAI;
32   const MCInstrInfo &MII;
33   const MCRegisterInfo &MRI;
34
35   /// The current set of available features.
36   unsigned AvailableFeatures;
37
38   /// True if we are printing marked up assembly.
39   bool UseMarkup;
40
41   /// True if we are printing immediates as hex.
42   bool PrintImmHex;
43
44   /// Utility function for printing annotations.
45   void printAnnotation(raw_ostream &OS, StringRef Annot);
46 public:
47   MCInstPrinter(const MCAsmInfo &mai, const MCInstrInfo &mii,
48                 const MCRegisterInfo &mri)
49     : CommentStream(0), MAI(mai), MII(mii), MRI(mri), AvailableFeatures(0),
50       UseMarkup(0), PrintImmHex(0) {}
51
52   virtual ~MCInstPrinter();
53
54   /// setCommentStream - Specify a stream to emit comments to.
55   void setCommentStream(raw_ostream &OS) { CommentStream = &OS; }
56
57   /// printInst - Print the specified MCInst to the specified raw_ostream.
58   ///
59   virtual void printInst(const MCInst *MI, raw_ostream &OS,
60                          StringRef Annot) = 0;
61
62   /// getOpcodeName - Return the name of the specified opcode enum (e.g.
63   /// "MOV32ri") or empty if we can't resolve it.
64   StringRef getOpcodeName(unsigned Opcode) const;
65
66   /// printRegName - Print the assembler register name.
67   virtual void printRegName(raw_ostream &OS, unsigned RegNo) const;
68
69   unsigned getAvailableFeatures() const { return AvailableFeatures; }
70   void setAvailableFeatures(unsigned Value) { AvailableFeatures = Value; }
71
72   bool getUseMarkup() const { return UseMarkup; }
73   void setUseMarkup(bool Value) { UseMarkup = Value; }
74
75   /// Utility functions to make adding mark ups simpler.
76   StringRef markup(StringRef s) const;
77   StringRef markup(StringRef a, StringRef b) const;
78
79   bool getPrintImmHex() const { return PrintImmHex; }
80   void setPrintImmHex(bool Value) { PrintImmHex = Value; }
81
82   /// Utility function to print immediates in decimal or hex.
83   format_object1<int64_t> formatImm(const int64_t Value) const;
84 };
85
86 } // namespace llvm
87
88 #endif