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/Format.h"
23 /// MCInstPrinter - This is an instance of a target assembly language printer
24 /// that converts an MCInst to valid target assembly syntax.
27 /// CommentStream - a stream that comments can be emitted to if desired.
28 /// Each comment must end with a newline. This will be null if verbose
29 /// assembly emission is disable.
30 raw_ostream *CommentStream;
32 const MCInstrInfo &MII;
33 const MCRegisterInfo &MRI;
35 /// The current set of available features.
36 unsigned AvailableFeatures;
38 /// True if we are printing marked up assembly.
41 /// True if we are printing immediates as hex.
44 /// Utility function for printing annotations.
45 void printAnnotation(raw_ostream &OS, StringRef Annot);
47 MCInstPrinter(const MCAsmInfo &mai, const MCInstrInfo &mii,
48 const MCRegisterInfo &mri)
49 : CommentStream(0), MAI(mai), MII(mii), MRI(mri), AvailableFeatures(0),
50 UseMarkup(0), PrintImmHex(0) {}
52 virtual ~MCInstPrinter();
54 /// setCommentStream - Specify a stream to emit comments to.
55 void setCommentStream(raw_ostream &OS) { CommentStream = &OS; }
57 /// printInst - Print the specified MCInst to the specified raw_ostream.
59 virtual void printInst(const MCInst *MI, raw_ostream &OS,
62 /// getOpcodeName - Return the name of the specified opcode enum (e.g.
63 /// "MOV32ri") or empty if we can't resolve it.
64 StringRef getOpcodeName(unsigned Opcode) const;
66 /// printRegName - Print the assembler register name.
67 virtual void printRegName(raw_ostream &OS, unsigned RegNo) const;
69 unsigned getAvailableFeatures() const { return AvailableFeatures; }
70 void setAvailableFeatures(unsigned Value) { AvailableFeatures = Value; }
72 bool getUseMarkup() const { return UseMarkup; }
73 void setUseMarkup(bool Value) { UseMarkup = Value; }
75 /// Utility functions to make adding mark ups simpler.
76 StringRef markup(StringRef s) const;
77 StringRef markup(StringRef a, StringRef b) const;
79 bool getPrintImmHex() const { return PrintImmHex; }
80 void setPrintImmHex(bool Value) { PrintImmHex = Value; }
82 /// Utility function to print immediates in decimal or hex.
83 format_object1<int64_t> formatImm(const int64_t Value) const;