1198090Srdivacky//===-- MCInstPrinter.h - Convert an MCInst to target assembly syntax -----===//
2198090Srdivacky//
3198090Srdivacky//                     The LLVM Compiler Infrastructure
4198090Srdivacky//
5198090Srdivacky// This file is distributed under the University of Illinois Open Source
6198090Srdivacky// License. See LICENSE.TXT for details.
7198090Srdivacky//
8198090Srdivacky//===----------------------------------------------------------------------===//
9198090Srdivacky
10198090Srdivacky#ifndef LLVM_MC_MCINSTPRINTER_H
11198090Srdivacky#define LLVM_MC_MCINSTPRINTER_H
12198090Srdivacky
13249423Sdim#include "llvm/Support/DataTypes.h"
14249423Sdim#include "llvm/Support/Format.h"
15249423Sdim
16198090Srdivackynamespace llvm {
17198090Srdivackyclass MCInst;
18198090Srdivackyclass raw_ostream;
19198090Srdivackyclass MCAsmInfo;
20234353Sdimclass MCInstrInfo;
21234353Sdimclass MCRegisterInfo;
22203954Srdivackyclass StringRef;
23198090Srdivacky
24254790Semastenamespace HexStyle {
25254790Semaste    enum Style {
26254790Semaste        C,          ///< 0xff
27254790Semaste        Asm         ///< 0ffh
28254790Semaste    };
29254790Semaste}
30254790Semaste
31198090Srdivacky/// MCInstPrinter - This is an instance of a target assembly language printer
32198090Srdivacky/// that converts an MCInst to valid target assembly syntax.
33198090Srdivackyclass MCInstPrinter {
34198090Srdivackyprotected:
35203954Srdivacky  /// CommentStream - a stream that comments can be emitted to if desired.
36203954Srdivacky  /// Each comment must end with a newline.  This will be null if verbose
37203954Srdivacky  /// assembly emission is disable.
38203954Srdivacky  raw_ostream *CommentStream;
39198090Srdivacky  const MCAsmInfo &MAI;
40234353Sdim  const MCInstrInfo &MII;
41234353Sdim  const MCRegisterInfo &MRI;
42221345Sdim
43221345Sdim  /// The current set of available features.
44263508Sdim  uint64_t AvailableFeatures;
45226633Sdim
46243830Sdim  /// True if we are printing marked up assembly.
47243830Sdim  bool UseMarkup;
48243830Sdim
49249423Sdim  /// True if we are printing immediates as hex.
50249423Sdim  bool PrintImmHex;
51249423Sdim
52254790Semaste  /// Which style to use for printing hexadecimal values.
53254790Semaste  HexStyle::Style PrintHexStyle;
54254790Semaste
55226633Sdim  /// Utility function for printing annotations.
56226633Sdim  void printAnnotation(raw_ostream &OS, StringRef Annot);
57198090Srdivackypublic:
58234353Sdim  MCInstPrinter(const MCAsmInfo &mai, const MCInstrInfo &mii,
59234353Sdim                const MCRegisterInfo &mri)
60243830Sdim    : CommentStream(0), MAI(mai), MII(mii), MRI(mri), AvailableFeatures(0),
61254790Semaste      UseMarkup(0), PrintImmHex(0), PrintHexStyle(HexStyle::C) {}
62218893Sdim
63198090Srdivacky  virtual ~MCInstPrinter();
64203954Srdivacky
65203954Srdivacky  /// setCommentStream - Specify a stream to emit comments to.
66203954Srdivacky  void setCommentStream(raw_ostream &OS) { CommentStream = &OS; }
67218893Sdim
68206274Srdivacky  /// printInst - Print the specified MCInst to the specified raw_ostream.
69198090Srdivacky  ///
70226633Sdim  virtual void printInst(const MCInst *MI, raw_ostream &OS,
71226633Sdim                         StringRef Annot) = 0;
72218893Sdim
73203954Srdivacky  /// getOpcodeName - Return the name of the specified opcode enum (e.g.
74203954Srdivacky  /// "MOV32ri") or empty if we can't resolve it.
75234353Sdim  StringRef getOpcodeName(unsigned Opcode) const;
76221345Sdim
77223017Sdim  /// printRegName - Print the assembler register name.
78223017Sdim  virtual void printRegName(raw_ostream &OS, unsigned RegNo) const;
79221345Sdim
80263508Sdim  uint64_t getAvailableFeatures() const { return AvailableFeatures; }
81263508Sdim  void setAvailableFeatures(uint64_t Value) { AvailableFeatures = Value; }
82243830Sdim
83243830Sdim  bool getUseMarkup() const { return UseMarkup; }
84243830Sdim  void setUseMarkup(bool Value) { UseMarkup = Value; }
85243830Sdim
86243830Sdim  /// Utility functions to make adding mark ups simpler.
87243830Sdim  StringRef markup(StringRef s) const;
88243830Sdim  StringRef markup(StringRef a, StringRef b) const;
89249423Sdim
90249423Sdim  bool getPrintImmHex() const { return PrintImmHex; }
91249423Sdim  void setPrintImmHex(bool Value) { PrintImmHex = Value; }
92249423Sdim
93254790Semaste  HexStyle::Style getPrintHexStyleHex() const { return PrintHexStyle; }
94254790Semaste  void setPrintImmHex(HexStyle::Style Value) { PrintHexStyle = Value; }
95254790Semaste
96249423Sdim  /// Utility function to print immediates in decimal or hex.
97254790Semaste  format_object1<int64_t> formatImm(const int64_t Value) const { return PrintImmHex ? formatHex(Value) : formatDec(Value); }
98254790Semaste
99254790Semaste  /// Utility functions to print decimal/hexadecimal values.
100254790Semaste  format_object1<int64_t> formatDec(const int64_t Value) const;
101254790Semaste  format_object1<int64_t> formatHex(const int64_t Value) const;
102254790Semaste  format_object1<uint64_t> formatHex(const uint64_t Value) const;
103198090Srdivacky};
104218893Sdim
105198090Srdivacky} // namespace llvm
106198090Srdivacky
107198090Srdivacky#endif
108