InstructionView.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. //===----------------------- InstructionView.h ------------------*- 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 main interface for Views that examine and reference
  11. /// a sequence of machine instructions.
  12. ///
  13. //===----------------------------------------------------------------------===//
  14. #ifndef LLVM_TOOLS_LLVM_MCA_INSTRUCTIONVIEW_H
  15. #define LLVM_TOOLS_LLVM_MCA_INSTRUCTIONVIEW_H
  16. #include "llvm/MCA/View.h"
  17. #include "llvm/Support/JSON.h"
  18. namespace llvm {
  19. class MCInstPrinter;
  20. namespace mca {
  21. // The base class for views that deal with individual machine instructions.
  22. class InstructionView : public View {
  23. const llvm::MCSubtargetInfo &STI;
  24. llvm::MCInstPrinter &MCIP;
  25. llvm::ArrayRef<llvm::MCInst> Source;
  26. mutable std::string InstructionString;
  27. mutable raw_string_ostream InstrStream;
  28. public:
  29. void printView(llvm::raw_ostream &) const override {}
  30. InstructionView(const llvm::MCSubtargetInfo &STI,
  31. llvm::MCInstPrinter &Printer, llvm::ArrayRef<llvm::MCInst> S)
  32. : STI(STI), MCIP(Printer), Source(S), InstrStream(InstructionString) {}
  33. virtual ~InstructionView();
  34. StringRef getNameAsString() const override { return "Instructions"; }
  35. // Return a reference to a string representing a given machine instruction.
  36. // The result should be used or copied before the next call to
  37. // printInstructionString() as it will overwrite the previous result.
  38. StringRef printInstructionString(const llvm::MCInst &MCI) const;
  39. const llvm::MCSubtargetInfo &getSubTargetInfo() const { return STI; }
  40. llvm::MCInstPrinter &getInstPrinter() const { return MCIP; }
  41. llvm::ArrayRef<llvm::MCInst> getSource() const { return Source; }
  42. json::Value toJSON() const override;
  43. };
  44. } // namespace mca
  45. } // namespace llvm
  46. #endif