//===- lib/MC/MCFragment.cpp - Assembler Fragment Implementation ----------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// #include "llvm/MC/MCFragment.h" #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/StringExtras.h" #include "llvm/ADT/Twine.h" #include "llvm/Config/llvm-config.h" #include "llvm/MC/MCContext.h" #include "llvm/MC/MCFixup.h" #include "llvm/MC/MCSection.h" #include "llvm/MC/MCSectionMachO.h" #include "llvm/MC/MCSymbol.h" #include "llvm/Support/Casting.h" #include "llvm/Support/Compiler.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/raw_ostream.h" #include #include #include using namespace llvm; MCFragment::MCFragment(FragmentType Kind, bool HasInstructions) : Kind(Kind), HasInstructions(HasInstructions), LinkerRelaxable(false) {} void MCFragment::destroy() { switch (Kind) { case FT_Align: cast(this)->~MCAlignFragment(); return; case FT_Data: cast(this)->~MCDataFragment(); return; case FT_CompactEncodedInst: cast(this)->~MCCompactEncodedInstFragment(); return; case FT_Fill: cast(this)->~MCFillFragment(); return; case FT_Nops: cast(this)->~MCNopsFragment(); return; case FT_Relaxable: cast(this)->~MCRelaxableFragment(); return; case FT_Org: cast(this)->~MCOrgFragment(); return; case FT_Dwarf: cast(this)->~MCDwarfLineAddrFragment(); return; case FT_DwarfFrame: cast(this)->~MCDwarfCallFrameFragment(); return; case FT_LEB: cast(this)->~MCLEBFragment(); return; case FT_BoundaryAlign: cast(this)->~MCBoundaryAlignFragment(); return; case FT_SymbolId: cast(this)->~MCSymbolIdFragment(); return; case FT_CVInlineLines: cast(this)->~MCCVInlineLineTableFragment(); return; case FT_CVDefRange: cast(this)->~MCCVDefRangeFragment(); return; case FT_PseudoProbe: cast(this)->~MCPseudoProbeAddrFragment(); return; case FT_Dummy: cast(this)->~MCDummyFragment(); return; } } const MCSymbol *MCFragment::getAtom() const { return cast(Parent)->getAtom(LayoutOrder); } // Debugging methods namespace llvm { raw_ostream &operator<<(raw_ostream &OS, const MCFixup &AF) { OS << ""; return OS; } } // end namespace llvm #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) LLVM_DUMP_METHOD void MCFragment::dump() const { raw_ostream &OS = errs(); OS << "<"; switch (getKind()) { case MCFragment::FT_Align: OS << "MCAlignFragment"; break; case MCFragment::FT_Data: OS << "MCDataFragment"; break; case MCFragment::FT_CompactEncodedInst: OS << "MCCompactEncodedInstFragment"; break; case MCFragment::FT_Fill: OS << "MCFillFragment"; break; case MCFragment::FT_Nops: OS << "MCFNopsFragment"; break; case MCFragment::FT_Relaxable: OS << "MCRelaxableFragment"; break; case MCFragment::FT_Org: OS << "MCOrgFragment"; break; case MCFragment::FT_Dwarf: OS << "MCDwarfFragment"; break; case MCFragment::FT_DwarfFrame: OS << "MCDwarfCallFrameFragment"; break; case MCFragment::FT_LEB: OS << "MCLEBFragment"; break; case MCFragment::FT_BoundaryAlign: OS<<"MCBoundaryAlignFragment"; break; case MCFragment::FT_SymbolId: OS << "MCSymbolIdFragment"; break; case MCFragment::FT_CVInlineLines: OS << "MCCVInlineLineTableFragment"; break; case MCFragment::FT_CVDefRange: OS << "MCCVDefRangeTableFragment"; break; case MCFragment::FT_PseudoProbe: OS << "MCPseudoProbe"; break; case MCFragment::FT_Dummy: OS << "MCDummyFragment"; break; } OS << "(this)) OS << " BundlePadding:" << static_cast(EF->getBundlePadding()); OS << ">"; switch (getKind()) { case MCFragment::FT_Align: { const auto *AF = cast(this); if (AF->hasEmitNops()) OS << " (emit nops)"; OS << "\n "; OS << " Alignment:" << AF->getAlignment().value() << " Value:" << AF->getValue() << " ValueSize:" << AF->getValueSize() << " MaxBytesToEmit:" << AF->getMaxBytesToEmit() << ">"; break; } case MCFragment::FT_Data: { const auto *DF = cast(this); OS << "\n "; OS << " Contents:["; const SmallVectorImpl &Contents = DF->getContents(); for (unsigned i = 0, e = Contents.size(); i != e; ++i) { if (i) OS << ","; OS << hexdigit((Contents[i] >> 4) & 0xF) << hexdigit(Contents[i] & 0xF); } OS << "] (" << Contents.size() << " bytes)"; if (DF->fixup_begin() != DF->fixup_end()) { OS << ",\n "; OS << " Fixups:["; for (MCDataFragment::const_fixup_iterator it = DF->fixup_begin(), ie = DF->fixup_end(); it != ie; ++it) { if (it != DF->fixup_begin()) OS << ",\n "; OS << *it; } OS << "]"; } break; } case MCFragment::FT_CompactEncodedInst: { const auto *CEIF = cast(this); OS << "\n "; OS << " Contents:["; const SmallVectorImpl &Contents = CEIF->getContents(); for (unsigned i = 0, e = Contents.size(); i != e; ++i) { if (i) OS << ","; OS << hexdigit((Contents[i] >> 4) & 0xF) << hexdigit(Contents[i] & 0xF); } OS << "] (" << Contents.size() << " bytes)"; break; } case MCFragment::FT_Fill: { const auto *FF = cast(this); OS << " Value:" << static_cast(FF->getValue()) << " ValueSize:" << static_cast(FF->getValueSize()) << " NumValues:" << FF->getNumValues(); break; } case MCFragment::FT_Nops: { const auto *NF = cast(this); OS << " NumBytes:" << NF->getNumBytes() << " ControlledNopLength:" << NF->getControlledNopLength(); break; } case MCFragment::FT_Relaxable: { const auto *F = cast(this); OS << "\n "; OS << " Inst:"; F->getInst().dump_pretty(OS); OS << " (" << F->getContents().size() << " bytes)"; break; } case MCFragment::FT_Org: { const auto *OF = cast(this); OS << "\n "; OS << " Offset:" << OF->getOffset() << " Value:" << static_cast(OF->getValue()); break; } case MCFragment::FT_Dwarf: { const auto *OF = cast(this); OS << "\n "; OS << " AddrDelta:" << OF->getAddrDelta() << " LineDelta:" << OF->getLineDelta(); break; } case MCFragment::FT_DwarfFrame: { const auto *CF = cast(this); OS << "\n "; OS << " AddrDelta:" << CF->getAddrDelta(); break; } case MCFragment::FT_LEB: { const auto *LF = cast(this); OS << "\n "; OS << " Value:" << LF->getValue() << " Signed:" << LF->isSigned(); break; } case MCFragment::FT_BoundaryAlign: { const auto *BF = cast(this); OS << "\n "; OS << " BoundarySize:" << BF->getAlignment().value() << " LastFragment:" << BF->getLastFragment() << " Size:" << BF->getSize(); break; } case MCFragment::FT_SymbolId: { const auto *F = cast(this); OS << "\n "; OS << " Sym:" << F->getSymbol(); break; } case MCFragment::FT_CVInlineLines: { const auto *F = cast(this); OS << "\n "; OS << " Sym:" << *F->getFnStartSym(); break; } case MCFragment::FT_CVDefRange: { const auto *F = cast(this); OS << "\n "; for (std::pair RangeStartEnd : F->getRanges()) { OS << " RangeStart:" << RangeStartEnd.first; OS << " RangeEnd:" << RangeStartEnd.second; } break; } case MCFragment::FT_PseudoProbe: { const auto *OF = cast(this); OS << "\n "; OS << " AddrDelta:" << OF->getAddrDelta(); break; } case MCFragment::FT_Dummy: break; } OS << ">"; } #endif