MCInst.cpp 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. //===- lib/MC/MCInst.cpp - MCInst implementation --------------------------===//
  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. #include "llvm/MC/MCInst.h"
  10. #include "llvm/MC/MCExpr.h"
  11. #include "llvm/MC/MCInstPrinter.h"
  12. #include "llvm/Support/Debug.h"
  13. #include "llvm/Support/raw_ostream.h"
  14. using namespace llvm;
  15. void MCOperand::print(raw_ostream &OS) const {
  16. OS << "<MCOperand ";
  17. if (!isValid())
  18. OS << "INVALID";
  19. else if (isReg())
  20. OS << "Reg:" << getReg();
  21. else if (isImm())
  22. OS << "Imm:" << getImm();
  23. else if (isExpr()) {
  24. OS << "Expr:(" << *getExpr() << ")";
  25. } else if (isInst()) {
  26. OS << "Inst:(" << *getInst() << ")";
  27. } else
  28. OS << "UNDEFINED";
  29. OS << ">";
  30. }
  31. #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
  32. void MCOperand::dump() const {
  33. print(dbgs());
  34. dbgs() << "\n";
  35. }
  36. #endif
  37. void MCInst::print(raw_ostream &OS) const {
  38. OS << "<MCInst " << getOpcode();
  39. for (unsigned i = 0, e = getNumOperands(); i != e; ++i) {
  40. OS << " ";
  41. getOperand(i).print(OS);
  42. }
  43. OS << ">";
  44. }
  45. void MCInst::dump_pretty(raw_ostream &OS, const MCInstPrinter *Printer,
  46. StringRef Separator) const {
  47. OS << "<MCInst #" << getOpcode();
  48. // Show the instruction opcode name if we have access to a printer.
  49. if (Printer)
  50. OS << ' ' << Printer->getOpcodeName(getOpcode());
  51. for (unsigned i = 0, e = getNumOperands(); i != e; ++i) {
  52. OS << Separator;
  53. getOperand(i).print(OS);
  54. }
  55. OS << ">";
  56. }
  57. #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
  58. void MCInst::dump() const {
  59. print(dbgs());
  60. dbgs() << "\n";
  61. }
  62. #endif