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