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/Support/DataTypes.h"
14 #include "llvm/Support/Format.h"
22 class MCSubtargetInfo;
32 /// \brief This is an instance of a target assembly language printer that
33 /// converts an MCInst to valid target assembly syntax.
36 /// \brief A stream that comments can be emitted to if desired. Each comment
37 /// must end with a newline. This will be null if verbose assembly emission
39 raw_ostream *CommentStream;
41 const MCInstrInfo &MII;
42 const MCRegisterInfo &MRI;
44 /// True if we are printing marked up assembly.
47 /// True if we are printing immediates as hex.
50 /// Which style to use for printing hexadecimal values.
51 HexStyle::Style PrintHexStyle;
53 /// Utility function for printing annotations.
54 void printAnnotation(raw_ostream &OS, StringRef Annot);
56 MCInstPrinter(const MCAsmInfo &mai, const MCInstrInfo &mii,
57 const MCRegisterInfo &mri)
58 : CommentStream(nullptr), MAI(mai), MII(mii), MRI(mri),
59 UseMarkup(0), PrintImmHex(0),
60 PrintHexStyle(HexStyle::C) {}
62 virtual ~MCInstPrinter();
64 /// \brief Specify a stream to emit comments to.
65 void setCommentStream(raw_ostream &OS) { CommentStream = &OS; }
67 /// \brief Print the specified MCInst to the specified raw_ostream.
68 virtual void printInst(const MCInst *MI, raw_ostream &OS,
69 StringRef Annot, const MCSubtargetInfo &STI) = 0;
71 /// \brief Return the name of the specified opcode enum (e.g. "MOV32ri") or
72 /// empty if we can't resolve it.
73 StringRef getOpcodeName(unsigned Opcode) const;
75 /// \brief Print the assembler register name.
76 virtual void printRegName(raw_ostream &OS, unsigned RegNo) const;
78 bool getUseMarkup() const { return UseMarkup; }
79 void setUseMarkup(bool Value) { UseMarkup = Value; }
81 /// Utility functions to make adding mark ups simpler.
82 StringRef markup(StringRef s) const;
83 StringRef markup(StringRef a, StringRef b) const;
85 bool getPrintImmHex() const { return PrintImmHex; }
86 void setPrintImmHex(bool Value) { PrintImmHex = Value; }
88 HexStyle::Style getPrintHexStyleHex() const { return PrintHexStyle; }
89 void setPrintImmHex(HexStyle::Style Value) { PrintHexStyle = Value; }
91 /// Utility function to print immediates in decimal or hex.
92 format_object<int64_t> formatImm(int64_t Value) const {
93 return PrintImmHex ? formatHex(Value) : formatDec(Value);
96 /// Utility functions to print decimal/hexadecimal values.
97 format_object<int64_t> formatDec(int64_t Value) const;
98 format_object<int64_t> formatHex(int64_t Value) const;
99 format_object<uint64_t> formatHex(uint64_t Value) const;