1 //===- MCInstPrinter.h - MCInst to target assembly syntax -------*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #ifndef LLVM_MC_MCINSTPRINTER_H
10 #define LLVM_MC_MCINSTPRINTER_H
12 #include "llvm/Support/Format.h"
21 class MCSubtargetInfo
;
25 /// Convert `Bytes' to a hex string and output to `OS'
26 void dumpBytes(ArrayRef
<uint8_t> Bytes
, raw_ostream
&OS
);
35 } // end namespace HexStyle
37 /// This is an instance of a target assembly language printer that
38 /// converts an MCInst to valid target assembly syntax.
41 /// A stream that comments can be emitted to if desired. Each comment
42 /// must end with a newline. This will be null if verbose assembly emission
44 raw_ostream
*CommentStream
= nullptr;
46 const MCInstrInfo
&MII
;
47 const MCRegisterInfo
&MRI
;
49 /// True if we are printing marked up assembly.
50 bool UseMarkup
= false;
52 /// True if we are printing immediates as hex.
53 bool PrintImmHex
= false;
55 /// Which style to use for printing hexadecimal values.
56 HexStyle::Style PrintHexStyle
= HexStyle::C
;
58 /// Utility function for printing annotations.
59 void printAnnotation(raw_ostream
&OS
, StringRef Annot
);
62 MCInstPrinter(const MCAsmInfo
&mai
, const MCInstrInfo
&mii
,
63 const MCRegisterInfo
&mri
) : MAI(mai
), MII(mii
), MRI(mri
) {}
65 virtual ~MCInstPrinter();
67 /// Customize the printer according to a command line option.
68 /// @return true if the option is recognized and applied.
69 virtual bool applyTargetSpecificCLOption(StringRef Opt
) { return false; }
71 /// Specify a stream to emit comments to.
72 void setCommentStream(raw_ostream
&OS
) { CommentStream
= &OS
; }
74 /// Print the specified MCInst to the specified raw_ostream.
75 virtual void printInst(const MCInst
*MI
, raw_ostream
&OS
, StringRef Annot
,
76 const MCSubtargetInfo
&STI
) = 0;
78 /// Return the name of the specified opcode enum (e.g. "MOV32ri") or
79 /// empty if we can't resolve it.
80 StringRef
getOpcodeName(unsigned Opcode
) const;
82 /// Print the assembler register name.
83 virtual void printRegName(raw_ostream
&OS
, unsigned RegNo
) const;
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;
91 bool getPrintImmHex() const { return PrintImmHex
; }
92 void setPrintImmHex(bool Value
) { PrintImmHex
= Value
; }
94 void setPrintHexStyle(HexStyle::Style Value
) { PrintHexStyle
= Value
; }
96 /// Utility function to print immediates in decimal or hex.
97 format_object
<int64_t> formatImm(int64_t Value
) const {
98 return PrintImmHex
? formatHex(Value
) : formatDec(Value
);
101 /// Utility functions to print decimal/hexadecimal values.
102 format_object
<int64_t> formatDec(int64_t Value
) const;
103 format_object
<int64_t> formatHex(int64_t Value
) const;
104 format_object
<uint64_t> formatHex(uint64_t Value
) const;
107 } // end namespace llvm
109 #endif // LLVM_MC_MCINSTPRINTER_H