2014-09-29 17:55:18 +02:00
|
|
|
//===- MCInstPrinter.h - MCInst to target assembly syntax -------*- C++ -*-===//
|
2009-09-14 03:43:38 +02:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_MC_MCINSTPRINTER_H
|
|
|
|
#define LLVM_MC_MCINSTPRINTER_H
|
|
|
|
|
2012-12-05 19:13:19 +01:00
|
|
|
#include "llvm/Support/Format.h"
|
2016-08-18 19:56:27 +02:00
|
|
|
#include <cstdint>
|
2012-12-05 19:13:19 +01:00
|
|
|
|
2009-09-14 03:43:38 +02:00
|
|
|
namespace llvm {
|
2016-08-18 19:56:27 +02:00
|
|
|
|
2016-04-18 11:17:29 +02:00
|
|
|
template <typename T> class ArrayRef;
|
2009-09-14 03:49:26 +02:00
|
|
|
class MCAsmInfo;
|
2017-02-11 01:27:28 +01:00
|
|
|
class MCInst;
|
2012-04-02 08:09:36 +02:00
|
|
|
class MCInstrInfo;
|
2012-03-05 20:33:20 +01:00
|
|
|
class MCRegisterInfo;
|
2015-03-27 21:36:02 +01:00
|
|
|
class MCSubtargetInfo;
|
2017-02-11 01:27:28 +01:00
|
|
|
class raw_ostream;
|
2010-02-11 23:39:10 +01:00
|
|
|
class StringRef;
|
2009-09-14 03:49:26 +02:00
|
|
|
|
2015-05-28 20:39:50 +02:00
|
|
|
/// Convert `Bytes' to a hex string and output to `OS'
|
|
|
|
void dumpBytes(ArrayRef<uint8_t> Bytes, raw_ostream &OS);
|
|
|
|
|
2013-08-01 23:18:16 +02:00
|
|
|
namespace HexStyle {
|
2016-08-18 19:56:27 +02:00
|
|
|
|
2015-06-02 01:55:02 +02:00
|
|
|
enum Style {
|
|
|
|
C, ///< 0xff
|
|
|
|
Asm ///< 0ffh
|
|
|
|
};
|
2016-08-18 19:56:27 +02:00
|
|
|
|
|
|
|
} // end namespace HexStyle
|
2013-08-01 23:18:16 +02:00
|
|
|
|
2015-05-02 02:44:14 +02:00
|
|
|
/// \brief This is an instance of a target assembly language printer that
|
|
|
|
/// converts an MCInst to valid target assembly syntax.
|
2009-09-14 03:43:38 +02:00
|
|
|
class MCInstPrinter {
|
2009-09-14 03:49:26 +02:00
|
|
|
protected:
|
2015-05-02 02:44:14 +02:00
|
|
|
/// \brief A stream that comments can be emitted to if desired. Each comment
|
|
|
|
/// must end with a newline. This will be null if verbose assembly emission
|
|
|
|
/// is disable.
|
2017-02-11 01:27:28 +01:00
|
|
|
raw_ostream *CommentStream = nullptr;
|
2009-09-14 03:49:26 +02:00
|
|
|
const MCAsmInfo &MAI;
|
2012-04-02 08:09:36 +02:00
|
|
|
const MCInstrInfo &MII;
|
2012-03-05 20:33:20 +01:00
|
|
|
const MCRegisterInfo &MRI;
|
2011-04-07 23:20:06 +02:00
|
|
|
|
2012-10-23 00:31:46 +02:00
|
|
|
/// True if we are printing marked up assembly.
|
2017-02-11 01:27:28 +01:00
|
|
|
bool UseMarkup = false;
|
2012-10-23 00:31:46 +02:00
|
|
|
|
2012-12-05 19:13:19 +01:00
|
|
|
/// True if we are printing immediates as hex.
|
2017-02-11 01:27:28 +01:00
|
|
|
bool PrintImmHex = false;
|
2012-12-05 19:13:19 +01:00
|
|
|
|
2013-08-01 23:18:16 +02:00
|
|
|
/// Which style to use for printing hexadecimal values.
|
2017-02-11 01:27:28 +01:00
|
|
|
HexStyle::Style PrintHexStyle = HexStyle::C;
|
2013-08-01 23:18:16 +02:00
|
|
|
|
2011-09-16 01:38:46 +02:00
|
|
|
/// Utility function for printing annotations.
|
|
|
|
void printAnnotation(raw_ostream &OS, StringRef Annot);
|
2015-06-02 01:55:02 +02:00
|
|
|
|
2009-09-14 03:43:38 +02:00
|
|
|
public:
|
2012-04-02 08:09:36 +02:00
|
|
|
MCInstPrinter(const MCAsmInfo &mai, const MCInstrInfo &mii,
|
2017-02-11 01:27:28 +01:00
|
|
|
const MCRegisterInfo &mri) : MAI(mai), MII(mii), MRI(mri) {}
|
2010-09-17 23:23:56 +02:00
|
|
|
|
2009-09-14 03:43:38 +02:00
|
|
|
virtual ~MCInstPrinter();
|
2010-02-10 01:10:18 +01:00
|
|
|
|
2015-05-02 02:44:14 +02:00
|
|
|
/// \brief Specify a stream to emit comments to.
|
2010-02-10 01:10:18 +01:00
|
|
|
void setCommentStream(raw_ostream &OS) { CommentStream = &OS; }
|
2010-09-17 23:23:56 +02:00
|
|
|
|
2015-05-02 02:44:14 +02:00
|
|
|
/// \brief Print the specified MCInst to the specified raw_ostream.
|
2015-06-02 01:55:02 +02:00
|
|
|
virtual void printInst(const MCInst *MI, raw_ostream &OS, StringRef Annot,
|
|
|
|
const MCSubtargetInfo &STI) = 0;
|
2011-09-15 20:36:29 +02:00
|
|
|
|
2015-05-02 02:44:14 +02:00
|
|
|
/// \brief Return the name of the specified opcode enum (e.g. "MOV32ri") or
|
|
|
|
/// empty if we can't resolve it.
|
2012-04-02 10:32:38 +02:00
|
|
|
StringRef getOpcodeName(unsigned Opcode) const;
|
2011-03-05 19:43:32 +01:00
|
|
|
|
2015-05-02 02:44:14 +02:00
|
|
|
/// \brief Print the assembler register name.
|
2011-06-02 04:34:55 +02:00
|
|
|
virtual void printRegName(raw_ostream &OS, unsigned RegNo) const;
|
2011-04-07 23:20:06 +02:00
|
|
|
|
2012-10-23 00:31:46 +02:00
|
|
|
bool getUseMarkup() const { return UseMarkup; }
|
|
|
|
void setUseMarkup(bool Value) { UseMarkup = Value; }
|
2012-10-24 00:52:52 +02:00
|
|
|
|
|
|
|
/// Utility functions to make adding mark ups simpler.
|
|
|
|
StringRef markup(StringRef s) const;
|
|
|
|
StringRef markup(StringRef a, StringRef b) const;
|
2012-12-05 19:13:19 +01:00
|
|
|
|
|
|
|
bool getPrintImmHex() const { return PrintImmHex; }
|
|
|
|
void setPrintImmHex(bool Value) { PrintImmHex = Value; }
|
|
|
|
|
2015-06-07 22:29:37 +02:00
|
|
|
HexStyle::Style getPrintHexStyle() const { return PrintHexStyle; }
|
|
|
|
void setPrintHexStyle(HexStyle::Style Value) { PrintHexStyle = Value; }
|
2013-08-01 23:18:16 +02:00
|
|
|
|
2012-12-05 19:13:19 +01:00
|
|
|
/// Utility function to print immediates in decimal or hex.
|
2015-02-15 23:15:41 +01:00
|
|
|
format_object<int64_t> formatImm(int64_t Value) const {
|
2015-01-23 07:18:35 +01:00
|
|
|
return PrintImmHex ? formatHex(Value) : formatDec(Value);
|
|
|
|
}
|
2013-08-01 23:18:16 +02:00
|
|
|
|
|
|
|
/// Utility functions to print decimal/hexadecimal values.
|
2015-02-15 23:15:41 +01:00
|
|
|
format_object<int64_t> formatDec(int64_t Value) const;
|
|
|
|
format_object<int64_t> formatHex(int64_t Value) const;
|
|
|
|
format_object<uint64_t> formatHex(uint64_t Value) const;
|
2009-09-14 03:43:38 +02:00
|
|
|
};
|
2010-09-17 23:23:56 +02:00
|
|
|
|
2016-08-18 19:56:27 +02:00
|
|
|
} // end namespace llvm
|
2009-09-14 03:43:38 +02:00
|
|
|
|
2016-08-18 19:56:27 +02:00
|
|
|
#endif // LLVM_MC_MCINSTPRINTER_H
|