InstructionView.cpp 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. //===----------------------- InstructionView.cpp ----------------*- C++ -*-===//
  2. //
  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
  6. //
  7. //===----------------------------------------------------------------------===//
  8. /// \file
  9. ///
  10. /// This file defines the member functions of the class InstructionView.
  11. ///
  12. //===----------------------------------------------------------------------===//
  13. #include "Views/InstructionView.h"
  14. #include "llvm/MC/MCInst.h"
  15. #include "llvm/MC/MCInstPrinter.h"
  16. #include "llvm/MC/MCSubtargetInfo.h"
  17. namespace llvm {
  18. namespace mca {
  19. InstructionView::~InstructionView() = default;
  20. StringRef
  21. InstructionView::printInstructionString(const llvm::MCInst &MCI) const {
  22. InstructionString = "";
  23. MCIP.printInst(&MCI, 0, "", STI, InstrStream);
  24. InstrStream.flush();
  25. // Remove any tabs or spaces at the beginning of the instruction.
  26. return StringRef(InstructionString).ltrim();
  27. }
  28. json::Value InstructionView::toJSON() const {
  29. json::Array SourceInfo;
  30. for (const auto &MCI : getSource()) {
  31. StringRef Instruction = printInstructionString(MCI);
  32. SourceInfo.push_back(Instruction.str());
  33. }
  34. return SourceInfo;
  35. }
  36. } // namespace mca
  37. } // namespace llvm