Path: blob/main/contrib/llvm-project/llvm/tools/llvm-mca/Views/InstructionView.cpp
35290 views
//===----------------------- InstructionView.cpp ----------------*- C++ -*-===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//7/// \file8///9/// This file defines the member functions of the class InstructionView.10///11//===----------------------------------------------------------------------===//1213#include "Views/InstructionView.h"14#include "llvm/MC/MCInst.h"15#include "llvm/MC/MCInstPrinter.h"16#include "llvm/MC/MCSubtargetInfo.h"1718namespace llvm {19namespace mca {2021InstructionView::~InstructionView() = default;2223StringRef24InstructionView::printInstructionString(const llvm::MCInst &MCI) const {25InstructionString = "";26MCIP.printInst(&MCI, 0, "", STI, InstrStream);27InstrStream.flush();28// Remove any tabs or spaces at the beginning of the instruction.29return StringRef(InstructionString).ltrim();30}3132json::Value InstructionView::toJSON() const {33json::Array SourceInfo;34for (const auto &MCI : getSource()) {35StringRef Instruction = printInstructionString(MCI);36SourceInfo.push_back(Instruction.str());37}38return SourceInfo;39}4041} // namespace mca42} // namespace llvm434445