]> git.proxmox.com Git - rustc.git/blob - src/llvm/include/llvm/MC/MCInstPrinter.h
Imported Upstream version 1.0.0+dfsg1
[rustc.git] / src / llvm / include / llvm / MC / MCInstPrinter.h
1 //===- MCInstPrinter.h - MCInst to target assembly syntax -------*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #ifndef LLVM_MC_MCINSTPRINTER_H
11 #define LLVM_MC_MCINSTPRINTER_H
12
13 #include "llvm/Support/DataTypes.h"
14 #include "llvm/Support/Format.h"
15
16 namespace llvm {
17 class MCInst;
18 class raw_ostream;
19 class MCAsmInfo;
20 class MCInstrInfo;
21 class MCRegisterInfo;
22 class StringRef;
23
24 namespace HexStyle {
25 enum Style {
26 C, ///< 0xff
27 Asm ///< 0ffh
28 };
29 }
30
31 /// MCInstPrinter - This is an instance of a target assembly language printer
32 /// that converts an MCInst to valid target assembly syntax.
33 class MCInstPrinter {
34 protected:
35 /// CommentStream - a stream that comments can be emitted to if desired.
36 /// Each comment must end with a newline. This will be null if verbose
37 /// assembly emission is disable.
38 raw_ostream *CommentStream;
39 const MCAsmInfo &MAI;
40 const MCInstrInfo &MII;
41 const MCRegisterInfo &MRI;
42
43 /// The current set of available features.
44 uint64_t AvailableFeatures;
45
46 /// True if we are printing marked up assembly.
47 bool UseMarkup;
48
49 /// True if we are printing immediates as hex.
50 bool PrintImmHex;
51
52 /// Which style to use for printing hexadecimal values.
53 HexStyle::Style PrintHexStyle;
54
55 /// Utility function for printing annotations.
56 void printAnnotation(raw_ostream &OS, StringRef Annot);
57 public:
58 MCInstPrinter(const MCAsmInfo &mai, const MCInstrInfo &mii,
59 const MCRegisterInfo &mri)
60 : CommentStream(nullptr), MAI(mai), MII(mii), MRI(mri),
61 AvailableFeatures(0), UseMarkup(0), PrintImmHex(0),
62 PrintHexStyle(HexStyle::C) {}
63
64 virtual ~MCInstPrinter();
65
66 /// setCommentStream - Specify a stream to emit comments to.
67 void setCommentStream(raw_ostream &OS) { CommentStream = &OS; }
68
69 /// printInst - Print the specified MCInst to the specified raw_ostream.
70 ///
71 virtual void printInst(const MCInst *MI, raw_ostream &OS,
72 StringRef Annot) = 0;
73
74 /// getOpcodeName - Return the name of the specified opcode enum (e.g.
75 /// "MOV32ri") or empty if we can't resolve it.
76 StringRef getOpcodeName(unsigned Opcode) const;
77
78 /// printRegName - Print the assembler register name.
79 virtual void printRegName(raw_ostream &OS, unsigned RegNo) const;
80
81 uint64_t getAvailableFeatures() const { return AvailableFeatures; }
82 void setAvailableFeatures(uint64_t Value) { AvailableFeatures = Value; }
83
84 bool getUseMarkup() const { return UseMarkup; }
85 void setUseMarkup(bool Value) { UseMarkup = Value; }
86
87 /// Utility functions to make adding mark ups simpler.
88 StringRef markup(StringRef s) const;
89 StringRef markup(StringRef a, StringRef b) const;
90
91 bool getPrintImmHex() const { return PrintImmHex; }
92 void setPrintImmHex(bool Value) { PrintImmHex = Value; }
93
94 HexStyle::Style getPrintHexStyleHex() const { return PrintHexStyle; }
95 void setPrintImmHex(HexStyle::Style Value) { PrintHexStyle = Value; }
96
97 /// Utility function to print immediates in decimal or hex.
98 format_object1<int64_t> formatImm(const int64_t Value) const { return PrintImmHex ? formatHex(Value) : formatDec(Value); }
99
100 /// Utility functions to print decimal/hexadecimal values.
101 format_object1<int64_t> formatDec(const int64_t Value) const;
102 format_object1<int64_t> formatHex(const int64_t Value) const;
103 format_object1<uint64_t> formatHex(const uint64_t Value) const;
104 };
105
106 } // namespace llvm
107
108 #endif