1*fe6060f1SDimitry Andric //===----------------------- InstructionView.cpp ----------------*- C++ -*-===// 2e8d8bef9SDimitry Andric // 3e8d8bef9SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4e8d8bef9SDimitry Andric // See https://llvm.org/LICENSE.txt for license information. 5e8d8bef9SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6e8d8bef9SDimitry Andric // 7e8d8bef9SDimitry Andric //===----------------------------------------------------------------------===// 8e8d8bef9SDimitry Andric /// \file 9e8d8bef9SDimitry Andric /// 10e8d8bef9SDimitry Andric /// This file defines the member functions of the class InstructionView. 11e8d8bef9SDimitry Andric /// 12e8d8bef9SDimitry Andric //===----------------------------------------------------------------------===// 13e8d8bef9SDimitry Andric 14e8d8bef9SDimitry Andric #include "Views/InstructionView.h" 15e8d8bef9SDimitry Andric #include "llvm/MC/MCInst.h" 16*fe6060f1SDimitry Andric #include "llvm/MC/MCInstPrinter.h" 17e8d8bef9SDimitry Andric #include "llvm/MC/MCSubtargetInfo.h" 18e8d8bef9SDimitry Andric 19e8d8bef9SDimitry Andric namespace llvm { 20e8d8bef9SDimitry Andric namespace mca { 21e8d8bef9SDimitry Andric 22*fe6060f1SDimitry Andric InstructionView::~InstructionView() = default; 23*fe6060f1SDimitry Andric 24*fe6060f1SDimitry Andric StringRef printInstructionString(const llvm::MCInst & MCI) const25*fe6060f1SDimitry AndricInstructionView::printInstructionString(const llvm::MCInst &MCI) const { 26e8d8bef9SDimitry Andric InstructionString = ""; 27e8d8bef9SDimitry Andric MCIP.printInst(&MCI, 0, "", STI, InstrStream); 28e8d8bef9SDimitry Andric InstrStream.flush(); 29e8d8bef9SDimitry Andric // Remove any tabs or spaces at the beginning of the instruction. 30e8d8bef9SDimitry Andric return StringRef(InstructionString).ltrim(); 31e8d8bef9SDimitry Andric } 32e8d8bef9SDimitry Andric toJSON() const33e8d8bef9SDimitry Andricjson::Value InstructionView::toJSON() const { 34e8d8bef9SDimitry Andric json::Array SourceInfo; 35e8d8bef9SDimitry Andric for (const auto &MCI : getSource()) { 36e8d8bef9SDimitry Andric StringRef Instruction = printInstructionString(MCI); 37e8d8bef9SDimitry Andric SourceInfo.push_back(Instruction.str()); 38e8d8bef9SDimitry Andric } 39*fe6060f1SDimitry Andric return SourceInfo; 40*fe6060f1SDimitry Andric } 41e8d8bef9SDimitry Andric 42e8d8bef9SDimitry Andric } // namespace mca 43e8d8bef9SDimitry Andric } // namespace llvm 44