1 //===-- MCInstPrinter.h - Convert an MCInst to target assembly syntax -----===//
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"
24 /// MCInstPrinter - This is an instance of a target assembly language printer
25 /// that converts an MCInst to valid target assembly syntax.
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;
33 const MCInstrInfo &MII;
34 const MCRegisterInfo &MRI;
36 /// The current set of available features.
37 unsigned AvailableFeatures;
39 /// True if we are printing marked up assembly.
42 /// True if we are printing immediates as hex.
45 /// Utility function for printing annotations.
46 void printAnnotation(raw_ostream &OS, StringRef Annot);
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) {}
53 virtual ~MCInstPrinter();
55 /// setCommentStream - Specify a stream to emit comments to.
56 void setCommentStream(raw_ostream &OS) { CommentStream = &OS; }
58 /// printInst - Print the specified MCInst to the specified raw_ostream.
60 virtual void printInst(const MCInst *MI, raw_ostream &OS,
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;
67 /// printRegName - Print the assembler register name.
68 virtual void printRegName(raw_ostream &OS, unsigned RegNo) const;
70 unsigned getAvailableFeatures() const { return AvailableFeatures; }
71 void setAvailableFeatures(unsigned Value) { AvailableFeatures = Value; }
73 bool getUseMarkup() const { return UseMarkup; }
74 void setUseMarkup(bool Value) { UseMarkup = Value; }
76 /// Utility functions to make adding mark ups simpler.
77 StringRef markup(StringRef s) const;
78 StringRef markup(StringRef a, StringRef b) const;
80 bool getPrintImmHex() const { return PrintImmHex; }
81 void setPrintImmHex(bool Value) { PrintImmHex = Value; }
83 /// Utility function to print immediates in decimal or hex.
84 format_object1<int64_t> formatImm(const int64_t Value) const;