2009-09-14 01:43:38 +00:00
|
|
|
//===-- MCInstPrinter.h - Convert an MCInst to target assembly syntax -----===//
|
|
|
|
//
|
|
|
|
// 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 18:31:11 +00:00
|
|
|
#include "llvm/Support/DataTypes.h"
|
2012-12-05 18:13:19 +00:00
|
|
|
#include "llvm/Support/Format.h"
|
|
|
|
|
2009-09-14 01:43:38 +00:00
|
|
|
namespace llvm {
|
|
|
|
class MCInst;
|
|
|
|
class raw_ostream;
|
2009-09-14 01:49:26 +00:00
|
|
|
class MCAsmInfo;
|
2012-04-02 06:09:36 +00:00
|
|
|
class MCInstrInfo;
|
2012-03-05 19:33:20 +00:00
|
|
|
class MCRegisterInfo;
|
2010-02-11 22:39:10 +00:00
|
|
|
class StringRef;
|
2009-09-14 01:49:26 +00:00
|
|
|
|
2013-08-01 21:18:16 +00:00
|
|
|
namespace HexStyle {
|
|
|
|
enum Style {
|
|
|
|
C, ///< 0xff
|
|
|
|
Asm ///< 0ffh
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2009-09-14 01:43:38 +00:00
|
|
|
/// MCInstPrinter - This is an instance of a target assembly language printer
|
|
|
|
/// that converts an MCInst to valid target assembly syntax.
|
|
|
|
class MCInstPrinter {
|
2009-09-14 01:49:26 +00:00
|
|
|
protected:
|
2010-02-10 00:10:18 +00:00
|
|
|
/// CommentStream - 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.
|
|
|
|
raw_ostream *CommentStream;
|
2009-09-14 01:49:26 +00:00
|
|
|
const MCAsmInfo &MAI;
|
2012-04-02 06:09:36 +00:00
|
|
|
const MCInstrInfo &MII;
|
2012-03-05 19:33:20 +00:00
|
|
|
const MCRegisterInfo &MRI;
|
2011-04-07 21:20:06 +00:00
|
|
|
|
|
|
|
/// The current set of available features.
|
|
|
|
unsigned AvailableFeatures;
|
2011-09-15 23:38:46 +00:00
|
|
|
|
2012-10-22 22:31:46 +00:00
|
|
|
/// True if we are printing marked up assembly.
|
|
|
|
bool UseMarkup;
|
|
|
|
|
2012-12-05 18:13:19 +00:00
|
|
|
/// True if we are printing immediates as hex.
|
|
|
|
bool PrintImmHex;
|
|
|
|
|
2013-08-01 21:18:16 +00:00
|
|
|
/// Which style to use for printing hexadecimal values.
|
|
|
|
HexStyle::Style PrintHexStyle;
|
|
|
|
|
2011-09-15 23:38:46 +00:00
|
|
|
/// Utility function for printing annotations.
|
|
|
|
void printAnnotation(raw_ostream &OS, StringRef Annot);
|
2009-09-14 01:43:38 +00:00
|
|
|
public:
|
2012-04-02 06:09:36 +00:00
|
|
|
MCInstPrinter(const MCAsmInfo &mai, const MCInstrInfo &mii,
|
|
|
|
const MCRegisterInfo &mri)
|
2012-10-22 22:31:46 +00:00
|
|
|
: CommentStream(0), MAI(mai), MII(mii), MRI(mri), AvailableFeatures(0),
|
2013-08-01 21:18:16 +00:00
|
|
|
UseMarkup(0), PrintImmHex(0), PrintHexStyle(HexStyle::C) {}
|
2010-09-17 21:23:56 +00:00
|
|
|
|
2009-09-14 01:43:38 +00:00
|
|
|
virtual ~MCInstPrinter();
|
2010-02-10 00:10:18 +00:00
|
|
|
|
|
|
|
/// setCommentStream - Specify a stream to emit comments to.
|
|
|
|
void setCommentStream(raw_ostream &OS) { CommentStream = &OS; }
|
2010-09-17 21:23:56 +00:00
|
|
|
|
2010-04-04 05:04:31 +00:00
|
|
|
/// printInst - Print the specified MCInst to the specified raw_ostream.
|
2009-09-14 01:43:38 +00:00
|
|
|
///
|
2011-09-15 23:38:46 +00:00
|
|
|
virtual void printInst(const MCInst *MI, raw_ostream &OS,
|
|
|
|
StringRef Annot) = 0;
|
2011-09-15 18:36:29 +00:00
|
|
|
|
2010-02-11 22:39:10 +00:00
|
|
|
/// getOpcodeName - Return the name of the specified opcode enum (e.g.
|
|
|
|
/// "MOV32ri") or empty if we can't resolve it.
|
2012-04-02 08:32:38 +00:00
|
|
|
StringRef getOpcodeName(unsigned Opcode) const;
|
2011-03-05 18:43:32 +00:00
|
|
|
|
2011-06-02 02:34:55 +00:00
|
|
|
/// printRegName - Print the assembler register name.
|
|
|
|
virtual void printRegName(raw_ostream &OS, unsigned RegNo) const;
|
2011-04-07 21:20:06 +00:00
|
|
|
|
|
|
|
unsigned getAvailableFeatures() const { return AvailableFeatures; }
|
|
|
|
void setAvailableFeatures(unsigned Value) { AvailableFeatures = Value; }
|
2012-10-22 22:31:46 +00:00
|
|
|
|
|
|
|
bool getUseMarkup() const { return UseMarkup; }
|
|
|
|
void setUseMarkup(bool Value) { UseMarkup = Value; }
|
2012-10-23 22:52:52 +00:00
|
|
|
|
|
|
|
/// Utility functions to make adding mark ups simpler.
|
|
|
|
StringRef markup(StringRef s) const;
|
|
|
|
StringRef markup(StringRef a, StringRef b) const;
|
2012-12-05 18:13:19 +00:00
|
|
|
|
|
|
|
bool getPrintImmHex() const { return PrintImmHex; }
|
|
|
|
void setPrintImmHex(bool Value) { PrintImmHex = Value; }
|
|
|
|
|
2013-08-01 21:18:16 +00:00
|
|
|
HexStyle::Style getPrintHexStyleHex() const { return PrintHexStyle; }
|
|
|
|
void setPrintImmHex(HexStyle::Style Value) { PrintHexStyle = Value; }
|
|
|
|
|
2012-12-05 18:13:19 +00:00
|
|
|
/// Utility function to print immediates in decimal or hex.
|
2013-08-01 21:18:16 +00:00
|
|
|
format_object1<int64_t> formatImm(const int64_t Value) const { return PrintImmHex ? formatHex(Value) : formatDec(Value); }
|
|
|
|
|
|
|
|
/// Utility functions to print decimal/hexadecimal values.
|
|
|
|
format_object1<int64_t> formatDec(const int64_t Value) const;
|
|
|
|
format_object1<int64_t> formatHex(const int64_t Value) const;
|
|
|
|
format_object1<uint64_t> formatHex(const uint64_t Value) const;
|
2009-09-14 01:43:38 +00:00
|
|
|
};
|
2010-09-17 21:23:56 +00:00
|
|
|
|
2009-09-14 01:43:38 +00:00
|
|
|
} // namespace llvm
|
|
|
|
|
|
|
|
#endif
|