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