114f77576SMarcos Horro //===----------------------- InstructionView.h ------------------*- C++ -*-===// 2d38be2baSWolfgang Pieb // 3d38be2baSWolfgang Pieb // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4d38be2baSWolfgang Pieb // See https://llvm.org/LICENSE.txt for license information. 5d38be2baSWolfgang Pieb // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6d38be2baSWolfgang Pieb // 7d38be2baSWolfgang Pieb //===----------------------------------------------------------------------===// 8d38be2baSWolfgang Pieb /// \file 9d38be2baSWolfgang Pieb /// 10d38be2baSWolfgang Pieb /// This file defines the main interface for Views that examine and reference 11d38be2baSWolfgang Pieb /// a sequence of machine instructions. 12d38be2baSWolfgang Pieb /// 13d38be2baSWolfgang Pieb //===----------------------------------------------------------------------===// 14d38be2baSWolfgang Pieb 15d38be2baSWolfgang Pieb #ifndef LLVM_TOOLS_LLVM_MCA_INSTRUCTIONVIEW_H 16d38be2baSWolfgang Pieb #define LLVM_TOOLS_LLVM_MCA_INSTRUCTIONVIEW_H 17d38be2baSWolfgang Pieb 18fe01014fSPatrick Holland #include "llvm/MCA/View.h" 19d38be2baSWolfgang Pieb #include "llvm/Support/JSON.h" 20d38be2baSWolfgang Pieb 21d38be2baSWolfgang Pieb namespace llvm { 22*42c7f494SClemens Wasser class MCInstPrinter; 23*42c7f494SClemens Wasser 24d38be2baSWolfgang Pieb namespace mca { 25d38be2baSWolfgang Pieb 26d38be2baSWolfgang Pieb // The base class for views that deal with individual machine instructions. 27d38be2baSWolfgang Pieb class InstructionView : public View { 28d38be2baSWolfgang Pieb const llvm::MCSubtargetInfo &STI; 29d38be2baSWolfgang Pieb llvm::MCInstPrinter &MCIP; 30d38be2baSWolfgang Pieb llvm::ArrayRef<llvm::MCInst> Source; 31d38be2baSWolfgang Pieb 32d38be2baSWolfgang Pieb mutable std::string InstructionString; 33d38be2baSWolfgang Pieb mutable raw_string_ostream InstrStream; 34d38be2baSWolfgang Pieb 35d38be2baSWolfgang Pieb public: printView(llvm::raw_ostream &)3604af1ca2SWolfgang Pieb void printView(llvm::raw_ostream &) const override {} InstructionView(const llvm::MCSubtargetInfo & STI,llvm::MCInstPrinter & Printer,llvm::ArrayRef<llvm::MCInst> S)37d38be2baSWolfgang Pieb InstructionView(const llvm::MCSubtargetInfo &STI, 3814f77576SMarcos Horro llvm::MCInstPrinter &Printer, llvm::ArrayRef<llvm::MCInst> S) 3910cb0362SAndrea Di Biagio : STI(STI), MCIP(Printer), Source(S), InstrStream(InstructionString) {} 40d38be2baSWolfgang Pieb 4110cb0362SAndrea Di Biagio virtual ~InstructionView(); 42d38be2baSWolfgang Pieb getNameAsString()4314f77576SMarcos Horro StringRef getNameAsString() const override { return "Instructions"; } 44d919bca8SAndrea Di Biagio 45d38be2baSWolfgang Pieb // Return a reference to a string representing a given machine instruction. 46d38be2baSWolfgang Pieb // The result should be used or copied before the next call to 47d38be2baSWolfgang Pieb // printInstructionString() as it will overwrite the previous result. 48d38be2baSWolfgang Pieb StringRef printInstructionString(const llvm::MCInst &MCI) const; getSubTargetInfo()49d38be2baSWolfgang Pieb const llvm::MCSubtargetInfo &getSubTargetInfo() const { return STI; } 50d38be2baSWolfgang Pieb getInstPrinter()51d38be2baSWolfgang Pieb llvm::MCInstPrinter &getInstPrinter() const { return MCIP; } getSource()52d38be2baSWolfgang Pieb llvm::ArrayRef<llvm::MCInst> getSource() const { return Source; } 5310cb0362SAndrea Di Biagio 54d919bca8SAndrea Di Biagio json::Value toJSON() const override; 55d38be2baSWolfgang Pieb }; 56d919bca8SAndrea Di Biagio 57d38be2baSWolfgang Pieb } // namespace mca 58d38be2baSWolfgang Pieb } // namespace llvm 59d38be2baSWolfgang Pieb 60d38be2baSWolfgang Pieb #endif 61