LLVM API Documentation

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MCInstPrinter.h
Go to the documentation of this file.
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 
16 namespace llvm {
17 class MCInst;
18 class raw_ostream;
19 class MCAsmInfo;
20 class MCInstrInfo;
21 class MCRegisterInfo;
22 class StringRef;
23 
24 namespace HexStyle {
25  enum Style {
26  C, ///< 0xff
27  Asm ///< 0ffh
28  };
29 }
30 
31 /// MCInstPrinter - This is an instance of a target assembly language printer
32 /// that converts an MCInst to valid target assembly syntax.
34 protected:
35  /// CommentStream - a stream that comments can be emitted to if desired.
36  /// Each comment must end with a newline. This will be null if verbose
37  /// assembly emission is disable.
39  const MCAsmInfo &MAI;
40  const MCInstrInfo &MII;
42 
43  /// The current set of available features.
45 
46  /// True if we are printing marked up assembly.
47  bool UseMarkup;
48 
49  /// True if we are printing immediates as hex.
51 
52  /// Which style to use for printing hexadecimal values.
54 
55  /// Utility function for printing annotations.
56  void printAnnotation(raw_ostream &OS, StringRef Annot);
57 public:
58  MCInstPrinter(const MCAsmInfo &mai, const MCInstrInfo &mii,
59  const MCRegisterInfo &mri)
60  : CommentStream(0), MAI(mai), MII(mii), MRI(mri), AvailableFeatures(0),
61  UseMarkup(0), PrintImmHex(0), PrintHexStyle(HexStyle::C) {}
62 
63  virtual ~MCInstPrinter();
64 
65  /// setCommentStream - Specify a stream to emit comments to.
67 
68  /// printInst - Print the specified MCInst to the specified raw_ostream.
69  ///
70  virtual void printInst(const MCInst *MI, raw_ostream &OS,
71  StringRef Annot) = 0;
72 
73  /// getOpcodeName - Return the name of the specified opcode enum (e.g.
74  /// "MOV32ri") or empty if we can't resolve it.
75  StringRef getOpcodeName(unsigned Opcode) const;
76 
77  /// printRegName - Print the assembler register name.
78  virtual void printRegName(raw_ostream &OS, unsigned RegNo) const;
79 
80  uint64_t getAvailableFeatures() const { return AvailableFeatures; }
81  void setAvailableFeatures(uint64_t Value) { AvailableFeatures = Value; }
82 
83  bool getUseMarkup() const { return UseMarkup; }
84  void setUseMarkup(bool Value) { UseMarkup = Value; }
85 
86  /// Utility functions to make adding mark ups simpler.
87  StringRef markup(StringRef s) const;
88  StringRef markup(StringRef a, StringRef b) const;
89 
90  bool getPrintImmHex() const { return PrintImmHex; }
91  void setPrintImmHex(bool Value) { PrintImmHex = Value; }
92 
95 
96  /// Utility function to print immediates in decimal or hex.
97  format_object1<int64_t> formatImm(const int64_t Value) const { return PrintImmHex ? formatHex(Value) : formatDec(Value); }
98 
99  /// Utility functions to print decimal/hexadecimal values.
100  format_object1<int64_t> formatDec(const int64_t Value) const;
101  format_object1<int64_t> formatHex(const int64_t Value) const;
102  format_object1<uint64_t> formatHex(const uint64_t Value) const;
103 };
104 
105 } // namespace llvm
106 
107 #endif
bool PrintImmHex
True if we are printing immediates as hex.
Definition: MCInstPrinter.h:50
HexStyle::Style PrintHexStyle
Which style to use for printing hexadecimal values.
Definition: MCInstPrinter.h:53
HexStyle::Style getPrintHexStyleHex() const
Definition: MCInstPrinter.h:93
void setPrintImmHex(bool Value)
Definition: MCInstPrinter.h:91
virtual void printInst(const MCInst *MI, raw_ostream &OS, StringRef Annot)=0
format_object1< int64_t > formatImm(const int64_t Value) const
Utility function to print immediates in decimal or hex.
Definition: MCInstPrinter.h:97
uint64_t AvailableFeatures
The current set of available features.
Definition: MCInstPrinter.h:44
format_object1< int64_t > formatDec(const int64_t Value) const
Utility functions to print decimal/hexadecimal values.
virtual void printRegName(raw_ostream &OS, unsigned RegNo) const
printRegName - Print the assembler register name.
StringRef markup(StringRef s) const
Utility functions to make adding mark ups simpler.
bool getUseMarkup() const
Definition: MCInstPrinter.h:83
void setCommentStream(raw_ostream &OS)
setCommentStream - Specify a stream to emit comments to.
Definition: MCInstPrinter.h:66
format_object1< int64_t > formatHex(const int64_t Value) const
StringRef getOpcodeName(unsigned Opcode) const
raw_ostream * CommentStream
Definition: MCInstPrinter.h:38
void setUseMarkup(bool Value)
Definition: MCInstPrinter.h:84
const MCAsmInfo & MAI
Definition: MCInstPrinter.h:39
bool UseMarkup
True if we are printing marked up assembly.
Definition: MCInstPrinter.h:47
const MCInstrInfo & MII
Definition: MCInstPrinter.h:40
LLVM Value Representation.
Definition: Value.h:66
void printAnnotation(raw_ostream &OS, StringRef Annot)
Utility function for printing annotations.
void setAvailableFeatures(uint64_t Value)
Definition: MCInstPrinter.h:81
bool getPrintImmHex() const
Definition: MCInstPrinter.h:90
uint64_t getAvailableFeatures() const
Definition: MCInstPrinter.h:80
MCInstPrinter(const MCAsmInfo &mai, const MCInstrInfo &mii, const MCRegisterInfo &mri)
Definition: MCInstPrinter.h:58
void setPrintImmHex(HexStyle::Style Value)
Definition: MCInstPrinter.h:94
const MCRegisterInfo & MRI
Definition: MCInstPrinter.h:41