1*14f77576SMarcos Horro //===----------------------- InstructionView.cpp ----------------*- 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 member functions of the class InstructionView. 11d38be2baSWolfgang Pieb /// 12d38be2baSWolfgang Pieb //===----------------------------------------------------------------------===// 13d38be2baSWolfgang Pieb 14d38be2baSWolfgang Pieb #include "Views/InstructionView.h" 15d38be2baSWolfgang Pieb #include "llvm/MC/MCInst.h" 16d919bca8SAndrea Di Biagio #include "llvm/MC/MCInstPrinter.h" 17d38be2baSWolfgang Pieb #include "llvm/MC/MCSubtargetInfo.h" 18d38be2baSWolfgang Pieb 19d38be2baSWolfgang Pieb namespace llvm { 20d38be2baSWolfgang Pieb namespace mca { 21d38be2baSWolfgang Pieb 2210cb0362SAndrea Di Biagio InstructionView::~InstructionView() = default; 2310cb0362SAndrea Di Biagio 24*14f77576SMarcos Horro StringRef printInstructionString(const llvm::MCInst & MCI) const25*14f77576SMarcos HorroInstructionView::printInstructionString(const llvm::MCInst &MCI) const { 26d38be2baSWolfgang Pieb InstructionString = ""; 27d38be2baSWolfgang Pieb MCIP.printInst(&MCI, 0, "", STI, InstrStream); 28d38be2baSWolfgang Pieb InstrStream.flush(); 29d38be2baSWolfgang Pieb // Remove any tabs or spaces at the beginning of the instruction. 30d38be2baSWolfgang Pieb return StringRef(InstructionString).ltrim(); 31d38be2baSWolfgang Pieb } 32d38be2baSWolfgang Pieb toJSON() const33d38be2baSWolfgang Piebjson::Value InstructionView::toJSON() const { 34d38be2baSWolfgang Pieb json::Array SourceInfo; 35d38be2baSWolfgang Pieb for (const auto &MCI : getSource()) { 36d38be2baSWolfgang Pieb StringRef Instruction = printInstructionString(MCI); 37d38be2baSWolfgang Pieb SourceInfo.push_back(Instruction.str()); 38d38be2baSWolfgang Pieb } 39b11d31ebSMarcos Horro return SourceInfo; 40b11d31ebSMarcos Horro } 41d38be2baSWolfgang Pieb 42d38be2baSWolfgang Pieb } // namespace mca 43d38be2baSWolfgang Pieb } // namespace llvm 44