LLVM  14.0.0git
MCDisassembler.cpp
Go to the documentation of this file.
1 //===- MCDisassembler.cpp - Disassembler interface ------------------------===//
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 
10 #include "llvm/ADT/ArrayRef.h"
11 #include "llvm/ADT/StringRef.h"
13 #include <algorithm>
14 
15 using namespace llvm;
16 
18 
21  ArrayRef<uint8_t> Bytes, uint64_t Address,
22  raw_ostream &CStream) const {
23  return None;
24 }
25 
27  uint64_t Address, bool IsBranch,
29  uint64_t InstSize) const {
30  if (Symbolizer)
31  return Symbolizer->tryAddingSymbolicOperand(
32  Inst, *CommentStream, Value, Address, IsBranch, Offset, InstSize);
33  return false;
34 }
35 
37  uint64_t Address) const {
38  if (Symbolizer)
39  Symbolizer->tryAddingPcLoadReferenceComment(*CommentStream, Value, Address);
40 }
41 
42 void MCDisassembler::setSymbolizer(std::unique_ptr<MCSymbolizer> Symzer) {
43  Symbolizer = std::move(Symzer);
44 }
45 
46 #define SMC_PCASE(A, P) \
47  case XCOFF::XMC_##A: \
48  return P;
49 
51  switch (SMC) {
52  SMC_PCASE(PR, 1)
53  SMC_PCASE(RO, 1)
54  SMC_PCASE(DB, 1)
55  SMC_PCASE(GL, 1)
56  SMC_PCASE(XO, 1)
57  SMC_PCASE(SV, 1)
58  SMC_PCASE(SV64, 1)
59  SMC_PCASE(SV3264, 1)
60  SMC_PCASE(TI, 1)
61  SMC_PCASE(TB, 1)
62  SMC_PCASE(RW, 1)
63  SMC_PCASE(TC0, 0)
64  SMC_PCASE(TC, 1)
65  SMC_PCASE(TD, 1)
66  SMC_PCASE(DS, 1)
67  SMC_PCASE(UA, 1)
68  SMC_PCASE(BS, 1)
69  SMC_PCASE(UC, 1)
70  SMC_PCASE(TL, 1)
71  SMC_PCASE(UL, 1)
72  SMC_PCASE(TE, 1)
73 #undef SMC_PCASE
74  }
75  return 0;
76 }
77 
78 /// The function is for symbol sorting when symbols have the same address.
79 /// The symbols in the same section are sorted in ascending order.
80 /// llvm-objdump -D will choose the highest priority symbol to display when
81 /// there are symbols with the same address.
83  // Label symbols have higher priority than non-label symbols.
84  if (IsLabel != SymInfo.IsLabel)
85  return SymInfo.IsLabel;
86 
87  // Symbols with a StorageMappingClass have higher priority than those without.
88  if (StorageMappingClass.hasValue() != SymInfo.StorageMappingClass.hasValue())
89  return SymInfo.StorageMappingClass.hasValue();
90 
91  if (StorageMappingClass.hasValue()) {
92  return getSMCPriority(StorageMappingClass.getValue()) <
93  getSMCPriority(SymInfo.StorageMappingClass.getValue());
94  }
95 
96  return false;
97 }
llvm::Check::Size
@ Size
Definition: FileCheck.h:73
llvm::XCOFFSymbolInfo
Definition: MCDisassembler.h:22
getSMCPriority
static uint8_t getSMCPriority(XCOFF::StorageMappingClass SMC)
Definition: MCDisassembler.cpp:50
llvm::SIInstrFlags::DS
@ DS
Definition: SIDefines.h:60
llvm::XCOFFSymbolInfo::operator<
bool operator<(const XCOFFSymbolInfo &SymInfo) const
The function is for symbol sorting when symbols have the same address.
Definition: MCDisassembler.cpp:82
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AllocatorList.h:23
MCDisassembler.h
llvm::SymbolInfoTy
Definition: MCDisassembler.h:33
StringRef.h
llvm::MCDisassembler::onSymbolStart
virtual Optional< DecodeStatus > onSymbolStart(SymbolInfoTy &Symbol, uint64_t &Size, ArrayRef< uint8_t > Bytes, uint64_t Address, raw_ostream &CStream) const
Used to perform separate target specific disassembly for a particular symbol.
Definition: MCDisassembler.cpp:20
llvm::Optional
Definition: APInt.h:33
Offset
uint64_t Offset
Definition: ELFObjHandler.cpp:81
llvm::MCInst
Instances of this class represent a single low-level machine instruction.
Definition: MCInst.h:184
llvm::MCDisassembler::CommentStream
raw_ostream * CommentStream
Definition: MCDisassembler.h:192
llvm::raw_ostream
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:53
llvm::MCDisassembler::setSymbolizer
void setSymbolizer(std::unique_ptr< MCSymbolizer > Symzer)
Set Symzer as the current symbolizer.
Definition: MCDisassembler.cpp:42
llvm::None
const NoneType None
Definition: None.h:23
llvm::XCOFF::StorageMappingClass
StorageMappingClass
Storage Mapping Class definitions.
Definition: XCOFF.h:59
uint64_t
llvm::MCDisassembler::~MCDisassembler
virtual ~MCDisassembler()
llvm::MCDisassembler::tryAddingPcLoadReferenceComment
void tryAddingPcLoadReferenceComment(int64_t Value, uint64_t Address) const
Definition: MCDisassembler.cpp:36
move
compiles ldr LCPI1_0 ldr ldr mov lsr tst moveq r1 ldr LCPI1_1 and r0 bx lr It would be better to do something like to fold the shift into the conditional move
Definition: README.txt:546
ArrayRef.h
llvm::HighlightColor::Address
@ Address
llvm::MCDisassembler::tryAddingSymbolicOperand
bool tryAddingSymbolicOperand(MCInst &Inst, int64_t Value, uint64_t Address, bool IsBranch, uint64_t Offset, uint64_t InstSize) const
Definition: MCDisassembler.cpp:26
llvm::ArrayRef< uint8_t >
SMC_PCASE
#define SMC_PCASE(A, P)
Definition: MCDisassembler.cpp:46
llvm::X86II::TB
@ TB
Definition: X86BaseInfo.h:805
llvm::ARMBuildAttrs::Symbol
@ Symbol
Definition: ARMBuildAttributes.h:83
llvm::XCOFFSymbolInfo::IsLabel
bool IsLabel
Definition: MCDisassembler.h:25
SymInfo
SymInfo contains information about symbol: it's address and section index which is -1LL for absolute ...
Definition: DWARFContext.cpp:1440
raw_ostream.h
llvm::Value
LLVM Value Representation.
Definition: Value.h:74
llvm::MCDisassembler::Symbolizer
std::unique_ptr< MCSymbolizer > Symbolizer
Definition: MCDisassembler.h:171