1 //===----------------------- InstructionView.cpp ----------------*- C++ -*-===//
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-exception
7 //===----------------------------------------------------------------------===//
10 /// This file defines the member functions of the class InstructionView.
12 //===----------------------------------------------------------------------===//
14 #include "Views/InstructionView.h"
15 #include "llvm/MC/MCInst.h"
16 #include "llvm/MC/MCInstPrinter.h"
17 #include "llvm/MC/MCSubtargetInfo.h"
22 InstructionView::~InstructionView() = default;
25 InstructionView::printInstructionString(const llvm::MCInst
&MCI
) const {
26 InstructionString
= "";
27 MCIP
.printInst(&MCI
, 0, "", STI
, InstrStream
);
29 // Remove any tabs or spaces at the beginning of the instruction.
30 return StringRef(InstructionString
).ltrim();
33 json::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());