Chandler Carruth | 8d73623 | 2015-12-29 09:06:16 +0000 | [diff] [blame] | 1 | //===- lib/MC/MCFragment.cpp - Assembler Fragment Implementation ----------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
Chandler Carruth | 6bda14b | 2017-06-06 11:49:48 +0000 | [diff] [blame] | 10 | #include "llvm/MC/MCFragment.h" |
Eugene Zelenko | 1d43552 | 2017-02-07 23:02:00 +0000 | [diff] [blame] | 11 | #include "llvm/ADT/SmallVector.h" |
Chandler Carruth | 8d73623 | 2015-12-29 09:06:16 +0000 | [diff] [blame] | 12 | #include "llvm/ADT/StringExtras.h" |
| 13 | #include "llvm/ADT/Twine.h" |
Chandler Carruth | 8d73623 | 2015-12-29 09:06:16 +0000 | [diff] [blame] | 14 | #include "llvm/MC/MCAsmLayout.h" |
Chandler Carruth | 6bda14b | 2017-06-06 11:49:48 +0000 | [diff] [blame] | 15 | #include "llvm/MC/MCAssembler.h" |
Chandler Carruth | 8d73623 | 2015-12-29 09:06:16 +0000 | [diff] [blame] | 16 | #include "llvm/MC/MCContext.h" |
Chandler Carruth | 8d73623 | 2015-12-29 09:06:16 +0000 | [diff] [blame] | 17 | #include "llvm/MC/MCExpr.h" |
Eugene Zelenko | 1d43552 | 2017-02-07 23:02:00 +0000 | [diff] [blame] | 18 | #include "llvm/MC/MCFixup.h" |
Chandler Carruth | 8d73623 | 2015-12-29 09:06:16 +0000 | [diff] [blame] | 19 | #include "llvm/MC/MCSection.h" |
Chandler Carruth | 8d73623 | 2015-12-29 09:06:16 +0000 | [diff] [blame] | 20 | #include "llvm/MC/MCSymbol.h" |
| 21 | #include "llvm/MC/MCValue.h" |
Eugene Zelenko | 1d43552 | 2017-02-07 23:02:00 +0000 | [diff] [blame] | 22 | #include "llvm/Support/Casting.h" |
| 23 | #include "llvm/Support/Compiler.h" |
Chandler Carruth | 8d73623 | 2015-12-29 09:06:16 +0000 | [diff] [blame] | 24 | #include "llvm/Support/ErrorHandling.h" |
Chandler Carruth | 8d73623 | 2015-12-29 09:06:16 +0000 | [diff] [blame] | 25 | #include "llvm/Support/raw_ostream.h" |
Eugene Zelenko | 1d43552 | 2017-02-07 23:02:00 +0000 | [diff] [blame] | 26 | #include <cassert> |
| 27 | #include <cstdint> |
| 28 | #include <utility> |
| 29 | |
Chandler Carruth | 8d73623 | 2015-12-29 09:06:16 +0000 | [diff] [blame] | 30 | using namespace llvm; |
| 31 | |
Eugene Zelenko | 1d43552 | 2017-02-07 23:02:00 +0000 | [diff] [blame] | 32 | MCAsmLayout::MCAsmLayout(MCAssembler &Asm) : Assembler(Asm) { |
Chandler Carruth | 8d73623 | 2015-12-29 09:06:16 +0000 | [diff] [blame] | 33 | // Compute the section layout order. Virtual sections must go last. |
| 34 | for (MCSection &Sec : Asm) |
| 35 | if (!Sec.isVirtualSection()) |
| 36 | SectionOrder.push_back(&Sec); |
| 37 | for (MCSection &Sec : Asm) |
| 38 | if (Sec.isVirtualSection()) |
| 39 | SectionOrder.push_back(&Sec); |
| 40 | } |
| 41 | |
| 42 | bool MCAsmLayout::isFragmentValid(const MCFragment *F) const { |
| 43 | const MCSection *Sec = F->getParent(); |
| 44 | const MCFragment *LastValid = LastValidFragment.lookup(Sec); |
| 45 | if (!LastValid) |
| 46 | return false; |
| 47 | assert(LastValid->getParent() == Sec); |
| 48 | return F->getLayoutOrder() <= LastValid->getLayoutOrder(); |
| 49 | } |
| 50 | |
| 51 | void MCAsmLayout::invalidateFragmentsFrom(MCFragment *F) { |
| 52 | // If this fragment wasn't already valid, we don't need to do anything. |
| 53 | if (!isFragmentValid(F)) |
| 54 | return; |
| 55 | |
| 56 | // Otherwise, reset the last valid fragment to the previous fragment |
| 57 | // (if this is the first fragment, it will be NULL). |
| 58 | LastValidFragment[F->getParent()] = F->getPrevNode(); |
| 59 | } |
| 60 | |
| 61 | void MCAsmLayout::ensureValid(const MCFragment *F) const { |
| 62 | MCSection *Sec = F->getParent(); |
| 63 | MCSection::iterator I; |
| 64 | if (MCFragment *Cur = LastValidFragment[Sec]) |
| 65 | I = ++MCSection::iterator(Cur); |
| 66 | else |
| 67 | I = Sec->begin(); |
| 68 | |
| 69 | // Advance the layout position until the fragment is valid. |
| 70 | while (!isFragmentValid(F)) { |
| 71 | assert(I != Sec->end() && "Layout bookkeeping error"); |
| 72 | const_cast<MCAsmLayout *>(this)->layoutFragment(&*I); |
| 73 | ++I; |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | uint64_t MCAsmLayout::getFragmentOffset(const MCFragment *F) const { |
| 78 | ensureValid(F); |
| 79 | assert(F->Offset != ~UINT64_C(0) && "Address not set!"); |
| 80 | return F->Offset; |
| 81 | } |
| 82 | |
Mandeep Singh Grang | 1be19e6 | 2017-09-15 20:01:43 +0000 | [diff] [blame] | 83 | // Simple getSymbolOffset helper for the non-variable case. |
Chandler Carruth | 8d73623 | 2015-12-29 09:06:16 +0000 | [diff] [blame] | 84 | static bool getLabelOffset(const MCAsmLayout &Layout, const MCSymbol &S, |
| 85 | bool ReportError, uint64_t &Val) { |
| 86 | if (!S.getFragment()) { |
| 87 | if (ReportError) |
| 88 | report_fatal_error("unable to evaluate offset to undefined symbol '" + |
| 89 | S.getName() + "'"); |
| 90 | return false; |
| 91 | } |
| 92 | Val = Layout.getFragmentOffset(S.getFragment()) + S.getOffset(); |
| 93 | return true; |
| 94 | } |
| 95 | |
| 96 | static bool getSymbolOffsetImpl(const MCAsmLayout &Layout, const MCSymbol &S, |
| 97 | bool ReportError, uint64_t &Val) { |
| 98 | if (!S.isVariable()) |
| 99 | return getLabelOffset(Layout, S, ReportError, Val); |
| 100 | |
| 101 | // If SD is a variable, evaluate it. |
| 102 | MCValue Target; |
| 103 | if (!S.getVariableValue()->evaluateAsValue(Target, Layout)) |
| 104 | report_fatal_error("unable to evaluate offset for variable '" + |
| 105 | S.getName() + "'"); |
| 106 | |
| 107 | uint64_t Offset = Target.getConstant(); |
| 108 | |
| 109 | const MCSymbolRefExpr *A = Target.getSymA(); |
| 110 | if (A) { |
| 111 | uint64_t ValA; |
| 112 | if (!getLabelOffset(Layout, A->getSymbol(), ReportError, ValA)) |
| 113 | return false; |
| 114 | Offset += ValA; |
| 115 | } |
| 116 | |
| 117 | const MCSymbolRefExpr *B = Target.getSymB(); |
| 118 | if (B) { |
| 119 | uint64_t ValB; |
| 120 | if (!getLabelOffset(Layout, B->getSymbol(), ReportError, ValB)) |
| 121 | return false; |
| 122 | Offset -= ValB; |
| 123 | } |
| 124 | |
| 125 | Val = Offset; |
| 126 | return true; |
| 127 | } |
| 128 | |
| 129 | bool MCAsmLayout::getSymbolOffset(const MCSymbol &S, uint64_t &Val) const { |
| 130 | return getSymbolOffsetImpl(*this, S, false, Val); |
| 131 | } |
| 132 | |
| 133 | uint64_t MCAsmLayout::getSymbolOffset(const MCSymbol &S) const { |
| 134 | uint64_t Val; |
| 135 | getSymbolOffsetImpl(*this, S, true, Val); |
| 136 | return Val; |
| 137 | } |
| 138 | |
| 139 | const MCSymbol *MCAsmLayout::getBaseSymbol(const MCSymbol &Symbol) const { |
| 140 | if (!Symbol.isVariable()) |
| 141 | return &Symbol; |
| 142 | |
| 143 | const MCExpr *Expr = Symbol.getVariableValue(); |
| 144 | MCValue Value; |
| 145 | if (!Expr->evaluateAsValue(Value, *this)) { |
| 146 | Assembler.getContext().reportError( |
Chad Rosier | 9245e12 | 2017-01-19 20:06:32 +0000 | [diff] [blame] | 147 | Expr->getLoc(), "expression could not be evaluated"); |
Chandler Carruth | 8d73623 | 2015-12-29 09:06:16 +0000 | [diff] [blame] | 148 | return nullptr; |
| 149 | } |
| 150 | |
| 151 | const MCSymbolRefExpr *RefB = Value.getSymB(); |
| 152 | if (RefB) { |
| 153 | Assembler.getContext().reportError( |
Chad Rosier | 9245e12 | 2017-01-19 20:06:32 +0000 | [diff] [blame] | 154 | Expr->getLoc(), Twine("symbol '") + RefB->getSymbol().getName() + |
Chandler Carruth | 8d73623 | 2015-12-29 09:06:16 +0000 | [diff] [blame] | 155 | "' could not be evaluated in a subtraction expression"); |
| 156 | return nullptr; |
| 157 | } |
| 158 | |
| 159 | const MCSymbolRefExpr *A = Value.getSymA(); |
| 160 | if (!A) |
| 161 | return nullptr; |
| 162 | |
| 163 | const MCSymbol &ASym = A->getSymbol(); |
| 164 | const MCAssembler &Asm = getAssembler(); |
| 165 | if (ASym.isCommon()) { |
Chad Rosier | 9245e12 | 2017-01-19 20:06:32 +0000 | [diff] [blame] | 166 | Asm.getContext().reportError(Expr->getLoc(), |
Chandler Carruth | 8d73623 | 2015-12-29 09:06:16 +0000 | [diff] [blame] | 167 | "Common symbol '" + ASym.getName() + |
| 168 | "' cannot be used in assignment expr"); |
| 169 | return nullptr; |
| 170 | } |
| 171 | |
| 172 | return &ASym; |
| 173 | } |
| 174 | |
| 175 | uint64_t MCAsmLayout::getSectionAddressSize(const MCSection *Sec) const { |
| 176 | // The size is the last fragment's end offset. |
| 177 | const MCFragment &F = Sec->getFragmentList().back(); |
| 178 | return getFragmentOffset(&F) + getAssembler().computeFragmentSize(*this, F); |
| 179 | } |
| 180 | |
| 181 | uint64_t MCAsmLayout::getSectionFileSize(const MCSection *Sec) const { |
| 182 | // Virtual sections have no file size. |
| 183 | if (Sec->isVirtualSection()) |
| 184 | return 0; |
| 185 | |
| 186 | // Otherwise, the file size is the same as the address space size. |
| 187 | return getSectionAddressSize(Sec); |
| 188 | } |
| 189 | |
| 190 | uint64_t llvm::computeBundlePadding(const MCAssembler &Assembler, |
| 191 | const MCFragment *F, |
| 192 | uint64_t FOffset, uint64_t FSize) { |
| 193 | uint64_t BundleSize = Assembler.getBundleAlignSize(); |
| 194 | assert(BundleSize > 0 && |
| 195 | "computeBundlePadding should only be called if bundling is enabled"); |
| 196 | uint64_t BundleMask = BundleSize - 1; |
| 197 | uint64_t OffsetInBundle = FOffset & BundleMask; |
| 198 | uint64_t EndOfFragment = OffsetInBundle + FSize; |
| 199 | |
| 200 | // There are two kinds of bundling restrictions: |
| 201 | // |
| 202 | // 1) For alignToBundleEnd(), add padding to ensure that the fragment will |
| 203 | // *end* on a bundle boundary. |
| 204 | // 2) Otherwise, check if the fragment would cross a bundle boundary. If it |
| 205 | // would, add padding until the end of the bundle so that the fragment |
| 206 | // will start in a new one. |
| 207 | if (F->alignToBundleEnd()) { |
| 208 | // Three possibilities here: |
| 209 | // |
| 210 | // A) The fragment just happens to end at a bundle boundary, so we're good. |
| 211 | // B) The fragment ends before the current bundle boundary: pad it just |
| 212 | // enough to reach the boundary. |
| 213 | // C) The fragment ends after the current bundle boundary: pad it until it |
| 214 | // reaches the end of the next bundle boundary. |
| 215 | // |
| 216 | // Note: this code could be made shorter with some modulo trickery, but it's |
| 217 | // intentionally kept in its more explicit form for simplicity. |
| 218 | if (EndOfFragment == BundleSize) |
| 219 | return 0; |
| 220 | else if (EndOfFragment < BundleSize) |
| 221 | return BundleSize - EndOfFragment; |
| 222 | else { // EndOfFragment > BundleSize |
| 223 | return 2 * BundleSize - EndOfFragment; |
| 224 | } |
| 225 | } else if (OffsetInBundle > 0 && EndOfFragment > BundleSize) |
| 226 | return BundleSize - OffsetInBundle; |
| 227 | else |
| 228 | return 0; |
| 229 | } |
| 230 | |
| 231 | /* *** */ |
| 232 | |
Duncan P. N. Exon Smith | f947c3a | 2016-08-30 18:40:47 +0000 | [diff] [blame] | 233 | void ilist_alloc_traits<MCFragment>::deleteNode(MCFragment *V) { V->destroy(); } |
Chandler Carruth | 8d73623 | 2015-12-29 09:06:16 +0000 | [diff] [blame] | 234 | |
Eugene Zelenko | 1d43552 | 2017-02-07 23:02:00 +0000 | [diff] [blame] | 235 | MCFragment::~MCFragment() = default; |
Chandler Carruth | 8d73623 | 2015-12-29 09:06:16 +0000 | [diff] [blame] | 236 | |
| 237 | MCFragment::MCFragment(FragmentType Kind, bool HasInstructions, |
| 238 | uint8_t BundlePadding, MCSection *Parent) |
| 239 | : Kind(Kind), HasInstructions(HasInstructions), AlignToBundleEnd(false), |
| 240 | BundlePadding(BundlePadding), Parent(Parent), Atom(nullptr), |
| 241 | Offset(~UINT64_C(0)) { |
| 242 | if (Parent && !isDummy()) |
| 243 | Parent->getFragmentList().push_back(this); |
| 244 | } |
| 245 | |
| 246 | void MCFragment::destroy() { |
| 247 | // First check if we are the sentinal. |
| 248 | if (Kind == FragmentType(~0)) { |
| 249 | delete this; |
| 250 | return; |
| 251 | } |
| 252 | |
| 253 | switch (Kind) { |
| 254 | case FT_Align: |
| 255 | delete cast<MCAlignFragment>(this); |
| 256 | return; |
| 257 | case FT_Data: |
| 258 | delete cast<MCDataFragment>(this); |
| 259 | return; |
| 260 | case FT_CompactEncodedInst: |
| 261 | delete cast<MCCompactEncodedInstFragment>(this); |
| 262 | return; |
| 263 | case FT_Fill: |
| 264 | delete cast<MCFillFragment>(this); |
| 265 | return; |
| 266 | case FT_Relaxable: |
| 267 | delete cast<MCRelaxableFragment>(this); |
| 268 | return; |
| 269 | case FT_Org: |
| 270 | delete cast<MCOrgFragment>(this); |
| 271 | return; |
| 272 | case FT_Dwarf: |
| 273 | delete cast<MCDwarfLineAddrFragment>(this); |
| 274 | return; |
| 275 | case FT_DwarfFrame: |
| 276 | delete cast<MCDwarfCallFrameFragment>(this); |
| 277 | return; |
| 278 | case FT_LEB: |
| 279 | delete cast<MCLEBFragment>(this); |
| 280 | return; |
| 281 | case FT_SafeSEH: |
| 282 | delete cast<MCSafeSEHFragment>(this); |
| 283 | return; |
Reid Kleckner | 1fcd610 | 2016-02-02 17:41:18 +0000 | [diff] [blame] | 284 | case FT_CVInlineLines: |
| 285 | delete cast<MCCVInlineLineTableFragment>(this); |
| 286 | return; |
David Majnemer | 408b5e6 | 2016-02-05 01:55:49 +0000 | [diff] [blame] | 287 | case FT_CVDefRange: |
| 288 | delete cast<MCCVDefRangeFragment>(this); |
| 289 | return; |
Chandler Carruth | 8d73623 | 2015-12-29 09:06:16 +0000 | [diff] [blame] | 290 | case FT_Dummy: |
| 291 | delete cast<MCDummyFragment>(this); |
| 292 | return; |
| 293 | } |
| 294 | } |
| 295 | |
Chandler Carruth | 8d73623 | 2015-12-29 09:06:16 +0000 | [diff] [blame] | 296 | // Debugging methods |
| 297 | |
| 298 | namespace llvm { |
| 299 | |
| 300 | raw_ostream &operator<<(raw_ostream &OS, const MCFixup &AF) { |
| 301 | OS << "<MCFixup" << " Offset:" << AF.getOffset() |
| 302 | << " Value:" << *AF.getValue() |
| 303 | << " Kind:" << AF.getKind() << ">"; |
| 304 | return OS; |
| 305 | } |
| 306 | |
Eugene Zelenko | 1d43552 | 2017-02-07 23:02:00 +0000 | [diff] [blame] | 307 | } // end namespace llvm |
Chandler Carruth | 8d73623 | 2015-12-29 09:06:16 +0000 | [diff] [blame] | 308 | |
Matthias Braun | 8c209aa | 2017-01-28 02:02:38 +0000 | [diff] [blame] | 309 | #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) |
Sam Clegg | 705f798 | 2017-06-21 22:19:17 +0000 | [diff] [blame] | 310 | LLVM_DUMP_METHOD void MCFragment::dump() const { |
Eugene Zelenko | 1d43552 | 2017-02-07 23:02:00 +0000 | [diff] [blame] | 311 | raw_ostream &OS = errs(); |
Chandler Carruth | 8d73623 | 2015-12-29 09:06:16 +0000 | [diff] [blame] | 312 | |
| 313 | OS << "<"; |
| 314 | switch (getKind()) { |
| 315 | case MCFragment::FT_Align: OS << "MCAlignFragment"; break; |
| 316 | case MCFragment::FT_Data: OS << "MCDataFragment"; break; |
| 317 | case MCFragment::FT_CompactEncodedInst: |
| 318 | OS << "MCCompactEncodedInstFragment"; break; |
| 319 | case MCFragment::FT_Fill: OS << "MCFillFragment"; break; |
| 320 | case MCFragment::FT_Relaxable: OS << "MCRelaxableFragment"; break; |
| 321 | case MCFragment::FT_Org: OS << "MCOrgFragment"; break; |
| 322 | case MCFragment::FT_Dwarf: OS << "MCDwarfFragment"; break; |
| 323 | case MCFragment::FT_DwarfFrame: OS << "MCDwarfCallFrameFragment"; break; |
| 324 | case MCFragment::FT_LEB: OS << "MCLEBFragment"; break; |
| 325 | case MCFragment::FT_SafeSEH: OS << "MCSafeSEHFragment"; break; |
Reid Kleckner | 1fcd610 | 2016-02-02 17:41:18 +0000 | [diff] [blame] | 326 | case MCFragment::FT_CVInlineLines: OS << "MCCVInlineLineTableFragment"; break; |
David Majnemer | 408b5e6 | 2016-02-05 01:55:49 +0000 | [diff] [blame] | 327 | case MCFragment::FT_CVDefRange: OS << "MCCVDefRangeTableFragment"; break; |
Reid Kleckner | 1fcd610 | 2016-02-02 17:41:18 +0000 | [diff] [blame] | 328 | case MCFragment::FT_Dummy: OS << "MCDummyFragment"; break; |
Chandler Carruth | 8d73623 | 2015-12-29 09:06:16 +0000 | [diff] [blame] | 329 | } |
| 330 | |
Ekaterina Vaartis | c4a6322 | 2017-06-22 19:08:30 +0000 | [diff] [blame] | 331 | OS << "<MCFragment " << (const void*) this << " LayoutOrder:" << LayoutOrder |
Chandler Carruth | 8d73623 | 2015-12-29 09:06:16 +0000 | [diff] [blame] | 332 | << " Offset:" << Offset |
Ekaterina Vaartis | c4a6322 | 2017-06-22 19:08:30 +0000 | [diff] [blame] | 333 | << " HasInstructions:" << hasInstructions() |
Chandler Carruth | 8d73623 | 2015-12-29 09:06:16 +0000 | [diff] [blame] | 334 | << " BundlePadding:" << static_cast<unsigned>(getBundlePadding()) << ">"; |
| 335 | |
| 336 | switch (getKind()) { |
| 337 | case MCFragment::FT_Align: { |
| 338 | const MCAlignFragment *AF = cast<MCAlignFragment>(this); |
| 339 | if (AF->hasEmitNops()) |
| 340 | OS << " (emit nops)"; |
| 341 | OS << "\n "; |
| 342 | OS << " Alignment:" << AF->getAlignment() |
| 343 | << " Value:" << AF->getValue() << " ValueSize:" << AF->getValueSize() |
| 344 | << " MaxBytesToEmit:" << AF->getMaxBytesToEmit() << ">"; |
| 345 | break; |
| 346 | } |
| 347 | case MCFragment::FT_Data: { |
| 348 | const MCDataFragment *DF = cast<MCDataFragment>(this); |
| 349 | OS << "\n "; |
| 350 | OS << " Contents:["; |
| 351 | const SmallVectorImpl<char> &Contents = DF->getContents(); |
| 352 | for (unsigned i = 0, e = Contents.size(); i != e; ++i) { |
| 353 | if (i) OS << ","; |
| 354 | OS << hexdigit((Contents[i] >> 4) & 0xF) << hexdigit(Contents[i] & 0xF); |
| 355 | } |
| 356 | OS << "] (" << Contents.size() << " bytes)"; |
| 357 | |
| 358 | if (DF->fixup_begin() != DF->fixup_end()) { |
| 359 | OS << ",\n "; |
| 360 | OS << " Fixups:["; |
| 361 | for (MCDataFragment::const_fixup_iterator it = DF->fixup_begin(), |
| 362 | ie = DF->fixup_end(); it != ie; ++it) { |
| 363 | if (it != DF->fixup_begin()) OS << ",\n "; |
| 364 | OS << *it; |
| 365 | } |
| 366 | OS << "]"; |
| 367 | } |
| 368 | break; |
| 369 | } |
| 370 | case MCFragment::FT_CompactEncodedInst: { |
| 371 | const MCCompactEncodedInstFragment *CEIF = |
| 372 | cast<MCCompactEncodedInstFragment>(this); |
| 373 | OS << "\n "; |
| 374 | OS << " Contents:["; |
| 375 | const SmallVectorImpl<char> &Contents = CEIF->getContents(); |
| 376 | for (unsigned i = 0, e = Contents.size(); i != e; ++i) { |
| 377 | if (i) OS << ","; |
| 378 | OS << hexdigit((Contents[i] >> 4) & 0xF) << hexdigit(Contents[i] & 0xF); |
| 379 | } |
| 380 | OS << "] (" << Contents.size() << " bytes)"; |
| 381 | break; |
| 382 | } |
| 383 | case MCFragment::FT_Fill: { |
| 384 | const MCFillFragment *FF = cast<MCFillFragment>(this); |
Sam Clegg | 58ad080e | 2017-06-22 17:57:01 +0000 | [diff] [blame] | 385 | OS << " Value:" << static_cast<unsigned>(FF->getValue()) |
| 386 | << " Size:" << FF->getSize(); |
Chandler Carruth | 8d73623 | 2015-12-29 09:06:16 +0000 | [diff] [blame] | 387 | break; |
| 388 | } |
| 389 | case MCFragment::FT_Relaxable: { |
| 390 | const MCRelaxableFragment *F = cast<MCRelaxableFragment>(this); |
| 391 | OS << "\n "; |
| 392 | OS << " Inst:"; |
| 393 | F->getInst().dump_pretty(OS); |
| 394 | break; |
| 395 | } |
| 396 | case MCFragment::FT_Org: { |
| 397 | const MCOrgFragment *OF = cast<MCOrgFragment>(this); |
| 398 | OS << "\n "; |
Sam Clegg | 58ad080e | 2017-06-22 17:57:01 +0000 | [diff] [blame] | 399 | OS << " Offset:" << OF->getOffset() |
| 400 | << " Value:" << static_cast<unsigned>(OF->getValue()); |
Chandler Carruth | 8d73623 | 2015-12-29 09:06:16 +0000 | [diff] [blame] | 401 | break; |
| 402 | } |
| 403 | case MCFragment::FT_Dwarf: { |
| 404 | const MCDwarfLineAddrFragment *OF = cast<MCDwarfLineAddrFragment>(this); |
| 405 | OS << "\n "; |
| 406 | OS << " AddrDelta:" << OF->getAddrDelta() |
| 407 | << " LineDelta:" << OF->getLineDelta(); |
| 408 | break; |
| 409 | } |
| 410 | case MCFragment::FT_DwarfFrame: { |
| 411 | const MCDwarfCallFrameFragment *CF = cast<MCDwarfCallFrameFragment>(this); |
| 412 | OS << "\n "; |
| 413 | OS << " AddrDelta:" << CF->getAddrDelta(); |
| 414 | break; |
| 415 | } |
| 416 | case MCFragment::FT_LEB: { |
| 417 | const MCLEBFragment *LF = cast<MCLEBFragment>(this); |
| 418 | OS << "\n "; |
| 419 | OS << " Value:" << LF->getValue() << " Signed:" << LF->isSigned(); |
| 420 | break; |
| 421 | } |
| 422 | case MCFragment::FT_SafeSEH: { |
| 423 | const MCSafeSEHFragment *F = cast<MCSafeSEHFragment>(this); |
| 424 | OS << "\n "; |
| 425 | OS << " Sym:" << F->getSymbol(); |
| 426 | break; |
| 427 | } |
Reid Kleckner | 1fcd610 | 2016-02-02 17:41:18 +0000 | [diff] [blame] | 428 | case MCFragment::FT_CVInlineLines: { |
| 429 | const auto *F = cast<MCCVInlineLineTableFragment>(this); |
| 430 | OS << "\n "; |
| 431 | OS << " Sym:" << *F->getFnStartSym(); |
| 432 | break; |
| 433 | } |
David Majnemer | 408b5e6 | 2016-02-05 01:55:49 +0000 | [diff] [blame] | 434 | case MCFragment::FT_CVDefRange: { |
| 435 | const auto *F = cast<MCCVDefRangeFragment>(this); |
| 436 | OS << "\n "; |
| 437 | for (std::pair<const MCSymbol *, const MCSymbol *> RangeStartEnd : |
| 438 | F->getRanges()) { |
| 439 | OS << " RangeStart:" << RangeStartEnd.first; |
| 440 | OS << " RangeEnd:" << RangeStartEnd.second; |
| 441 | } |
| 442 | break; |
| 443 | } |
Chandler Carruth | 8d73623 | 2015-12-29 09:06:16 +0000 | [diff] [blame] | 444 | case MCFragment::FT_Dummy: |
| 445 | break; |
| 446 | } |
| 447 | OS << ">"; |
| 448 | } |
| 449 | |
Sam Clegg | 705f798 | 2017-06-21 22:19:17 +0000 | [diff] [blame] | 450 | LLVM_DUMP_METHOD void MCAssembler::dump() const{ |
Eugene Zelenko | 1d43552 | 2017-02-07 23:02:00 +0000 | [diff] [blame] | 451 | raw_ostream &OS = errs(); |
Chandler Carruth | 8d73623 | 2015-12-29 09:06:16 +0000 | [diff] [blame] | 452 | |
| 453 | OS << "<MCAssembler\n"; |
| 454 | OS << " Sections:[\n "; |
Sam Clegg | 705f798 | 2017-06-21 22:19:17 +0000 | [diff] [blame] | 455 | for (const_iterator it = begin(), ie = end(); it != ie; ++it) { |
Chandler Carruth | 8d73623 | 2015-12-29 09:06:16 +0000 | [diff] [blame] | 456 | if (it != begin()) OS << ",\n "; |
| 457 | it->dump(); |
| 458 | } |
| 459 | OS << "],\n"; |
| 460 | OS << " Symbols:["; |
| 461 | |
Sam Clegg | 705f798 | 2017-06-21 22:19:17 +0000 | [diff] [blame] | 462 | for (const_symbol_iterator it = symbol_begin(), ie = symbol_end(); it != ie; ++it) { |
Chandler Carruth | 8d73623 | 2015-12-29 09:06:16 +0000 | [diff] [blame] | 463 | if (it != symbol_begin()) OS << ",\n "; |
| 464 | OS << "("; |
| 465 | it->dump(); |
| 466 | OS << ", Index:" << it->getIndex() << ", "; |
| 467 | OS << ")"; |
| 468 | } |
| 469 | OS << "]>\n"; |
| 470 | } |
Matthias Braun | 8c209aa | 2017-01-28 02:02:38 +0000 | [diff] [blame] | 471 | #endif |