brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.3 KiB · 3b174a0 Raw
44 lines · cpp
1//===----------------------- InstructionView.cpp ----------------*- 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-exception6//7//===----------------------------------------------------------------------===//8/// \file9///10/// This file defines the member functions of the class InstructionView.11///12//===----------------------------------------------------------------------===//13 14#include "Views/InstructionView.h"15#include "llvm/MC/MCInst.h"16#include "llvm/MC/MCInstPrinter.h"17#include "llvm/MC/MCSubtargetInfo.h"18 19namespace llvm {20namespace mca {21 22InstructionView::~InstructionView() = default;23 24StringRef25InstructionView::printInstructionString(const llvm::MCInst &MCI) const {26  InstructionString = "";27  MCIP.printInst(&MCI, 0, "", STI, InstrStream);28  InstrStream.flush();29  // Remove any tabs or spaces at the beginning of the instruction.30  return StringRef(InstructionString).ltrim();31}32 33json::Value InstructionView::toJSON() const {34  json::Array SourceInfo;35  for (const auto &MCI : getSource()) {36    StringRef Instruction = printInstructionString(MCI);37    SourceInfo.push_back(Instruction.str());38  }39  return SourceInfo;40}41 42} // namespace mca43} // namespace llvm44