[OptTable] Fix typo VALUE => VALUES (NFCI) (#121523)
[llvm-project.git] / llvm / tools / llvm-mca / Views / InstructionView.cpp
blob3b174a0649852f8ea95b8defa0c2f9bdbfee1e18
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-exception
6 //
7 //===----------------------------------------------------------------------===//
8 /// \file
9 ///
10 /// This file defines the member functions of the class InstructionView.
11 ///
12 //===----------------------------------------------------------------------===//
14 #include "Views/InstructionView.h"
15 #include "llvm/MC/MCInst.h"
16 #include "llvm/MC/MCInstPrinter.h"
17 #include "llvm/MC/MCSubtargetInfo.h"
19 namespace llvm {
20 namespace mca {
22 InstructionView::~InstructionView() = default;
24 StringRef
25 InstructionView::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();
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());
39 return SourceInfo;
42 } // namespace mca
43 } // namespace llvm