1 //===- MCInstPrinter.h - MCInst to target assembly syntax -------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef LLVM_MC_MCINSTPRINTER_H
11 #define LLVM_MC_MCINSTPRINTER_H
13 #include "llvm/ADT/ArrayRef.h"
14 #include "llvm/Support/DataTypes.h"
15 #include "llvm/Support/Format.h"
23 class MCSubtargetInfo;
26 /// Convert `Bytes' to a hex string and output to `OS'
27 void dumpBytes(ArrayRef<uint8_t> Bytes, raw_ostream &OS);
36 /// \brief This is an instance of a target assembly language printer that
37 /// converts an MCInst to valid target assembly syntax.
40 /// \brief A stream that comments can be emitted to if desired. Each comment
41 /// must end with a newline. This will be null if verbose assembly emission
43 raw_ostream *CommentStream;
45 const MCInstrInfo &MII;
46 const MCRegisterInfo &MRI;
48 /// True if we are printing marked up assembly.
51 /// True if we are printing immediates as hex.
54 /// Which style to use for printing hexadecimal values.
55 HexStyle::Style PrintHexStyle;
57 /// Utility function for printing annotations.
58 void printAnnotation(raw_ostream &OS, StringRef Annot);
61 MCInstPrinter(const MCAsmInfo &mai, const MCInstrInfo &mii,
62 const MCRegisterInfo &mri)
63 : CommentStream(nullptr), MAI(mai), MII(mii), MRI(mri), UseMarkup(0),
64 PrintImmHex(0), PrintHexStyle(HexStyle::C) {}
66 virtual ~MCInstPrinter();
68 /// \brief Specify a stream to emit comments to.
69 void setCommentStream(raw_ostream &OS) { CommentStream = &OS; }
71 /// \brief Print the specified MCInst to the specified raw_ostream.
72 virtual void printInst(const MCInst *MI, raw_ostream &OS, StringRef Annot,
73 const MCSubtargetInfo &STI) = 0;
75 /// \brief Return the name of the specified opcode enum (e.g. "MOV32ri") or
76 /// empty if we can't resolve it.
77 StringRef getOpcodeName(unsigned Opcode) const;
79 /// \brief Print the assembler register name.
80 virtual void printRegName(raw_ostream &OS, unsigned RegNo) const;
82 bool getUseMarkup() const { return UseMarkup; }
83 void setUseMarkup(bool Value) { UseMarkup = Value; }
85 /// Utility functions to make adding mark ups simpler.
86 StringRef markup(StringRef s) const;
87 StringRef markup(StringRef a, StringRef b) const;
89 bool getPrintImmHex() const { return PrintImmHex; }
90 void setPrintImmHex(bool Value) { PrintImmHex = Value; }
92 HexStyle::Style getPrintHexStyle() const { return PrintHexStyle; }
93 void setPrintHexStyle(HexStyle::Style Value) { PrintHexStyle = Value; }
95 /// Utility function to print immediates in decimal or hex.
96 format_object<int64_t> formatImm(int64_t Value) const {
97 return PrintImmHex ? formatHex(Value) : formatDec(Value);
100 /// Utility functions to print decimal/hexadecimal values.
101 format_object<int64_t> formatDec(int64_t Value) const;
102 format_object<int64_t> formatHex(int64_t Value) const;
103 format_object<uint64_t> formatHex(uint64_t Value) const;