MCAssembler.h revision 2661f11e4602ad017fa155f6fdcee0a4f2d1ae86
1//===- MCAssembler.h - Object File Generation -------------------*- C++ -*-===// 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 10#ifndef LLVM_MC_MCASSEMBLER_H 11#define LLVM_MC_MCASSEMBLER_H 12 13#include "llvm/ADT/DenseMap.h" 14#include "llvm/ADT/SmallString.h" 15#include "llvm/ADT/ilist.h" 16#include "llvm/ADT/ilist_node.h" 17#include "llvm/Support/Casting.h" 18#include "llvm/MC/MCFixup.h" 19#include "llvm/MC/MCInst.h" 20#include "llvm/System/DataTypes.h" 21#include <vector> // FIXME: Shouldn't be needed. 22 23namespace llvm { 24class raw_ostream; 25class MCAsmLayout; 26class MCAssembler; 27class MCContext; 28class MCCodeEmitter; 29class MCExpr; 30class MCFragment; 31class MCObjectWriter; 32class MCSection; 33class MCSectionData; 34class MCSymbol; 35class MCSymbolData; 36class MCValue; 37class TargetAsmBackend; 38 39/// MCAsmFixup - Represent a fixed size region of bytes inside some fragment 40/// which needs to be rewritten. This region will either be rewritten by the 41/// assembler or cause a relocation entry to be generated. 42// 43// FIXME: This should probably just be merged with MCFixup. 44class MCAsmFixup { 45public: 46 /// Offset - The offset inside the fragment which needs to be rewritten. 47 uint64_t Offset; 48 49 /// Value - The expression to eventually write into the fragment. 50 const MCExpr *Value; 51 52 /// Kind - The fixup kind. 53 MCFixupKind Kind; 54 55public: 56 MCAsmFixup(uint64_t _Offset, const MCExpr &_Value, MCFixupKind _Kind) 57 : Offset(_Offset), Value(&_Value), Kind(_Kind) {} 58}; 59 60class MCFragment : public ilist_node<MCFragment> { 61 friend class MCAsmLayout; 62 63 MCFragment(const MCFragment&); // DO NOT IMPLEMENT 64 void operator=(const MCFragment&); // DO NOT IMPLEMENT 65 66public: 67 enum FragmentType { 68 FT_Align, 69 FT_Data, 70 FT_Fill, 71 FT_Inst, 72 FT_Org 73 }; 74 75private: 76 FragmentType Kind; 77 78 /// Parent - The data for the section this fragment is in. 79 MCSectionData *Parent; 80 81 /// Atom - The atom this fragment is in, as represented by it's defining 82 /// symbol. Atom's are only used by backends which set 83 /// \see MCAsmBackend::hasReliableSymbolDifference(). 84 MCSymbolData *Atom; 85 86 /// @name Assembler Backend Data 87 /// @{ 88 // 89 // FIXME: This could all be kept private to the assembler implementation. 90 91 /// Offset - The offset of this fragment in its section. This is ~0 until 92 /// initialized. 93 uint64_t Offset; 94 95 /// EffectiveSize - The compute size of this section. This is ~0 until 96 /// initialized. 97 uint64_t EffectiveSize; 98 99 /// Ordinal - The global index of this fragment. This is the index across all 100 /// sections, not just the parent section. 101 unsigned Ordinal; 102 103 /// @} 104 105protected: 106 MCFragment(FragmentType _Kind, MCSectionData *_Parent = 0); 107 108public: 109 // Only for sentinel. 110 MCFragment(); 111 virtual ~MCFragment(); 112 113 FragmentType getKind() const { return Kind; } 114 115 MCSectionData *getParent() const { return Parent; } 116 void setParent(MCSectionData *Value) { Parent = Value; } 117 118 MCSymbolData *getAtom() const { return Atom; } 119 void setAtom(MCSymbolData *Value) { Atom = Value; } 120 121 unsigned getOrdinal() const { return Ordinal; } 122 void setOrdinal(unsigned Value) { Ordinal = Value; } 123 124 static bool classof(const MCFragment *O) { return true; } 125 126 virtual void dump(); 127}; 128 129class MCDataFragment : public MCFragment { 130 SmallString<32> Contents; 131 132 /// Fixups - The list of fixups in this fragment. 133 std::vector<MCAsmFixup> Fixups; 134 135public: 136 typedef std::vector<MCAsmFixup>::const_iterator const_fixup_iterator; 137 typedef std::vector<MCAsmFixup>::iterator fixup_iterator; 138 139public: 140 MCDataFragment(MCSectionData *SD = 0) : MCFragment(FT_Data, SD) {} 141 142 /// @name Accessors 143 /// @{ 144 145 SmallString<32> &getContents() { return Contents; } 146 const SmallString<32> &getContents() const { return Contents; } 147 148 /// @} 149 /// @name Fixup Access 150 /// @{ 151 152 void addFixup(MCAsmFixup Fixup) { 153 // Enforce invariant that fixups are in offset order. 154 assert((Fixups.empty() || Fixup.Offset > Fixups.back().Offset) && 155 "Fixups must be added in order!"); 156 Fixups.push_back(Fixup); 157 } 158 159 std::vector<MCAsmFixup> &getFixups() { return Fixups; } 160 const std::vector<MCAsmFixup> &getFixups() const { return Fixups; } 161 162 fixup_iterator fixup_begin() { return Fixups.begin(); } 163 const_fixup_iterator fixup_begin() const { return Fixups.begin(); } 164 165 fixup_iterator fixup_end() {return Fixups.end();} 166 const_fixup_iterator fixup_end() const {return Fixups.end();} 167 168 size_t fixup_size() const { return Fixups.size(); } 169 170 /// @} 171 172 static bool classof(const MCFragment *F) { 173 return F->getKind() == MCFragment::FT_Data; 174 } 175 static bool classof(const MCDataFragment *) { return true; } 176 177 virtual void dump(); 178}; 179 180// FIXME: This current incarnation of MCInstFragment doesn't make much sense, as 181// it is almost entirely a duplicate of MCDataFragment. If we decide to stick 182// with this approach (as opposed to making MCInstFragment a very light weight 183// object with just the MCInst and a code size, then we should just change 184// MCDataFragment to have an optional MCInst at its end. 185class MCInstFragment : public MCFragment { 186 /// Inst - The instruction this is a fragment for. 187 MCInst Inst; 188 189 /// InstSize - The size of the currently encoded instruction. 190 SmallString<8> Code; 191 192 /// Fixups - The list of fixups in this fragment. 193 SmallVector<MCAsmFixup, 1> Fixups; 194 195public: 196 typedef SmallVectorImpl<MCAsmFixup>::const_iterator const_fixup_iterator; 197 typedef SmallVectorImpl<MCAsmFixup>::iterator fixup_iterator; 198 199public: 200 MCInstFragment(MCInst _Inst, MCSectionData *SD = 0) 201 : MCFragment(FT_Inst, SD), Inst(_Inst) { 202 } 203 204 /// @name Accessors 205 /// @{ 206 207 SmallVectorImpl<char> &getCode() { return Code; } 208 const SmallVectorImpl<char> &getCode() const { return Code; } 209 210 unsigned getInstSize() const { return Code.size(); } 211 212 MCInst &getInst() { return Inst; } 213 const MCInst &getInst() const { return Inst; } 214 215 void setInst(MCInst Value) { Inst = Value; } 216 217 /// @} 218 /// @name Fixup Access 219 /// @{ 220 221 SmallVectorImpl<MCAsmFixup> &getFixups() { return Fixups; } 222 const SmallVectorImpl<MCAsmFixup> &getFixups() const { return Fixups; } 223 224 fixup_iterator fixup_begin() { return Fixups.begin(); } 225 const_fixup_iterator fixup_begin() const { return Fixups.begin(); } 226 227 fixup_iterator fixup_end() {return Fixups.end();} 228 const_fixup_iterator fixup_end() const {return Fixups.end();} 229 230 size_t fixup_size() const { return Fixups.size(); } 231 232 /// @} 233 234 static bool classof(const MCFragment *F) { 235 return F->getKind() == MCFragment::FT_Inst; 236 } 237 static bool classof(const MCInstFragment *) { return true; } 238 239 virtual void dump(); 240}; 241 242class MCAlignFragment : public MCFragment { 243 /// Alignment - The alignment to ensure, in bytes. 244 unsigned Alignment; 245 246 /// Value - Value to use for filling padding bytes. 247 int64_t Value; 248 249 /// ValueSize - The size of the integer (in bytes) of \arg Value. 250 unsigned ValueSize; 251 252 /// MaxBytesToEmit - The maximum number of bytes to emit; if the alignment 253 /// cannot be satisfied in this width then this fragment is ignored. 254 unsigned MaxBytesToEmit; 255 256 /// EmitNops - Flag to indicate that (optimal) NOPs should be emitted instead 257 /// of using the provided value. The exact interpretation of this flag is 258 /// target dependent. 259 bool EmitNops : 1; 260 261 /// OnlyAlignAddress - Flag to indicate that this align is only used to adjust 262 /// the address space size of a section and that it should not be included as 263 /// part of the section size. This flag can only be used on the last fragment 264 /// in a section. 265 bool OnlyAlignAddress : 1; 266 267public: 268 MCAlignFragment(unsigned _Alignment, int64_t _Value, unsigned _ValueSize, 269 unsigned _MaxBytesToEmit, MCSectionData *SD = 0) 270 : MCFragment(FT_Align, SD), Alignment(_Alignment), 271 Value(_Value),ValueSize(_ValueSize), 272 MaxBytesToEmit(_MaxBytesToEmit), EmitNops(false), 273 OnlyAlignAddress(false) {} 274 275 /// @name Accessors 276 /// @{ 277 278 unsigned getAlignment() const { return Alignment; } 279 280 int64_t getValue() const { return Value; } 281 282 unsigned getValueSize() const { return ValueSize; } 283 284 unsigned getMaxBytesToEmit() const { return MaxBytesToEmit; } 285 286 bool hasEmitNops() const { return EmitNops; } 287 void setEmitNops(bool Value) { EmitNops = Value; } 288 289 bool hasOnlyAlignAddress() const { return OnlyAlignAddress; } 290 void setOnlyAlignAddress(bool Value) { OnlyAlignAddress = Value; } 291 292 /// @} 293 294 static bool classof(const MCFragment *F) { 295 return F->getKind() == MCFragment::FT_Align; 296 } 297 static bool classof(const MCAlignFragment *) { return true; } 298 299 virtual void dump(); 300}; 301 302class MCFillFragment : public MCFragment { 303 /// Value - Value to use for filling bytes. 304 int64_t Value; 305 306 /// ValueSize - The size (in bytes) of \arg Value to use when filling, or 0 if 307 /// this is a virtual fill fragment. 308 unsigned ValueSize; 309 310 /// Size - The number of bytes to insert. 311 uint64_t Size; 312 313public: 314 MCFillFragment(int64_t _Value, unsigned _ValueSize, uint64_t _Size, 315 MCSectionData *SD = 0) 316 : MCFragment(FT_Fill, SD), 317 Value(_Value), ValueSize(_ValueSize), Size(_Size) { 318 assert((!ValueSize || (Size % ValueSize) == 0) && 319 "Fill size must be a multiple of the value size!"); 320 } 321 322 /// @name Accessors 323 /// @{ 324 325 int64_t getValue() const { return Value; } 326 327 unsigned getValueSize() const { return ValueSize; } 328 329 uint64_t getSize() const { return Size; } 330 331 /// @} 332 333 static bool classof(const MCFragment *F) { 334 return F->getKind() == MCFragment::FT_Fill; 335 } 336 static bool classof(const MCFillFragment *) { return true; } 337 338 virtual void dump(); 339}; 340 341class MCOrgFragment : public MCFragment { 342 /// Offset - The offset this fragment should start at. 343 const MCExpr *Offset; 344 345 /// Value - Value to use for filling bytes. 346 int8_t Value; 347 348public: 349 MCOrgFragment(const MCExpr &_Offset, int8_t _Value, MCSectionData *SD = 0) 350 : MCFragment(FT_Org, SD), 351 Offset(&_Offset), Value(_Value) {} 352 353 /// @name Accessors 354 /// @{ 355 356 const MCExpr &getOffset() const { return *Offset; } 357 358 uint8_t getValue() const { return Value; } 359 360 /// @} 361 362 static bool classof(const MCFragment *F) { 363 return F->getKind() == MCFragment::FT_Org; 364 } 365 static bool classof(const MCOrgFragment *) { return true; } 366 367 virtual void dump(); 368}; 369 370// FIXME: Should this be a separate class, or just merged into MCSection? Since 371// we anticipate the fast path being through an MCAssembler, the only reason to 372// keep it out is for API abstraction. 373class MCSectionData : public ilist_node<MCSectionData> { 374 friend class MCAsmLayout; 375 376 MCSectionData(const MCSectionData&); // DO NOT IMPLEMENT 377 void operator=(const MCSectionData&); // DO NOT IMPLEMENT 378 379public: 380 typedef iplist<MCFragment> FragmentListType; 381 382 typedef FragmentListType::const_iterator const_iterator; 383 typedef FragmentListType::iterator iterator; 384 385 typedef FragmentListType::const_reverse_iterator const_reverse_iterator; 386 typedef FragmentListType::reverse_iterator reverse_iterator; 387 388private: 389 iplist<MCFragment> Fragments; 390 const MCSection *Section; 391 392 /// Ordinal - The section index in the assemblers section list. 393 unsigned Ordinal; 394 395 /// Alignment - The maximum alignment seen in this section. 396 unsigned Alignment; 397 398 /// @name Assembler Backend Data 399 /// @{ 400 // 401 // FIXME: This could all be kept private to the assembler implementation. 402 403 /// Address - The computed address of this section. This is ~0 until 404 /// initialized. 405 uint64_t Address; 406 407 /// HasInstructions - Whether this section has had instructions emitted into 408 /// it. 409 unsigned HasInstructions : 1; 410 411 /// @} 412 413public: 414 // Only for use as sentinel. 415 MCSectionData(); 416 MCSectionData(const MCSection &Section, MCAssembler *A = 0); 417 418 const MCSection &getSection() const { return *Section; } 419 420 unsigned getAlignment() const { return Alignment; } 421 void setAlignment(unsigned Value) { Alignment = Value; } 422 423 bool hasInstructions() const { return HasInstructions; } 424 void setHasInstructions(bool Value) { HasInstructions = Value; } 425 426 unsigned getOrdinal() const { return Ordinal; } 427 void setOrdinal(unsigned Value) { Ordinal = Value; } 428 429 /// @name Fragment Access 430 /// @{ 431 432 const FragmentListType &getFragmentList() const { return Fragments; } 433 FragmentListType &getFragmentList() { return Fragments; } 434 435 iterator begin() { return Fragments.begin(); } 436 const_iterator begin() const { return Fragments.begin(); } 437 438 iterator end() { return Fragments.end(); } 439 const_iterator end() const { return Fragments.end(); } 440 441 reverse_iterator rbegin() { return Fragments.rbegin(); } 442 const_reverse_iterator rbegin() const { return Fragments.rbegin(); } 443 444 reverse_iterator rend() { return Fragments.rend(); } 445 const_reverse_iterator rend() const { return Fragments.rend(); } 446 447 size_t size() const { return Fragments.size(); } 448 449 bool empty() const { return Fragments.empty(); } 450 451 void dump(); 452 453 /// @} 454}; 455 456// FIXME: Same concerns as with SectionData. 457class MCSymbolData : public ilist_node<MCSymbolData> { 458public: 459 const MCSymbol *Symbol; 460 461 /// Fragment - The fragment this symbol's value is relative to, if any. 462 MCFragment *Fragment; 463 464 /// Offset - The offset to apply to the fragment address to form this symbol's 465 /// value. 466 uint64_t Offset; 467 468 /// IsExternal - True if this symbol is visible outside this translation 469 /// unit. 470 unsigned IsExternal : 1; 471 472 /// IsPrivateExtern - True if this symbol is private extern. 473 unsigned IsPrivateExtern : 1; 474 475 /// CommonSize - The size of the symbol, if it is 'common', or 0. 476 // 477 // FIXME: Pack this in with other fields? We could put it in offset, since a 478 // common symbol can never get a definition. 479 uint64_t CommonSize; 480 481 /// CommonAlign - The alignment of the symbol, if it is 'common'. 482 // 483 // FIXME: Pack this in with other fields? 484 unsigned CommonAlign; 485 486 /// Flags - The Flags field is used by object file implementations to store 487 /// additional per symbol information which is not easily classified. 488 uint32_t Flags; 489 490 /// Index - Index field, for use by the object file implementation. 491 uint64_t Index; 492 493public: 494 // Only for use as sentinel. 495 MCSymbolData(); 496 MCSymbolData(const MCSymbol &_Symbol, MCFragment *_Fragment, uint64_t _Offset, 497 MCAssembler *A = 0); 498 499 /// @name Accessors 500 /// @{ 501 502 const MCSymbol &getSymbol() const { return *Symbol; } 503 504 MCFragment *getFragment() const { return Fragment; } 505 void setFragment(MCFragment *Value) { Fragment = Value; } 506 507 uint64_t getOffset() const { return Offset; } 508 void setOffset(uint64_t Value) { Offset = Value; } 509 510 /// @} 511 /// @name Symbol Attributes 512 /// @{ 513 514 bool isExternal() const { return IsExternal; } 515 void setExternal(bool Value) { IsExternal = Value; } 516 517 bool isPrivateExtern() const { return IsPrivateExtern; } 518 void setPrivateExtern(bool Value) { IsPrivateExtern = Value; } 519 520 /// isCommon - Is this a 'common' symbol. 521 bool isCommon() const { return CommonSize != 0; } 522 523 /// setCommon - Mark this symbol as being 'common'. 524 /// 525 /// \param Size - The size of the symbol. 526 /// \param Align - The alignment of the symbol. 527 void setCommon(uint64_t Size, unsigned Align) { 528 CommonSize = Size; 529 CommonAlign = Align; 530 } 531 532 /// getCommonSize - Return the size of a 'common' symbol. 533 uint64_t getCommonSize() const { 534 assert(isCommon() && "Not a 'common' symbol!"); 535 return CommonSize; 536 } 537 538 /// getCommonAlignment - Return the alignment of a 'common' symbol. 539 unsigned getCommonAlignment() const { 540 assert(isCommon() && "Not a 'common' symbol!"); 541 return CommonAlign; 542 } 543 544 /// getFlags - Get the (implementation defined) symbol flags. 545 uint32_t getFlags() const { return Flags; } 546 547 /// setFlags - Set the (implementation defined) symbol flags. 548 void setFlags(uint32_t Value) { Flags = Value; } 549 550 /// modifyFlags - Modify the flags via a mask 551 void modifyFlags(uint32_t Value, uint32_t Mask) { 552 Flags = (Flags & ~Mask) | Value; 553 } 554 555 /// getIndex - Get the (implementation defined) index. 556 uint64_t getIndex() const { return Index; } 557 558 /// setIndex - Set the (implementation defined) index. 559 void setIndex(uint64_t Value) { Index = Value; } 560 561 /// @} 562 563 void dump(); 564}; 565 566// FIXME: This really doesn't belong here. See comments below. 567struct IndirectSymbolData { 568 MCSymbol *Symbol; 569 MCSectionData *SectionData; 570}; 571 572class MCAssembler { 573 friend class MCAsmLayout; 574 575public: 576 typedef iplist<MCSectionData> SectionDataListType; 577 typedef iplist<MCSymbolData> SymbolDataListType; 578 579 typedef SectionDataListType::const_iterator const_iterator; 580 typedef SectionDataListType::iterator iterator; 581 582 typedef SymbolDataListType::const_iterator const_symbol_iterator; 583 typedef SymbolDataListType::iterator symbol_iterator; 584 585 typedef std::vector<IndirectSymbolData>::const_iterator 586 const_indirect_symbol_iterator; 587 typedef std::vector<IndirectSymbolData>::iterator indirect_symbol_iterator; 588 589private: 590 MCAssembler(const MCAssembler&); // DO NOT IMPLEMENT 591 void operator=(const MCAssembler&); // DO NOT IMPLEMENT 592 593 MCContext &Context; 594 595 TargetAsmBackend &Backend; 596 597 MCCodeEmitter &Emitter; 598 599 raw_ostream &OS; 600 601 iplist<MCSectionData> Sections; 602 603 iplist<MCSymbolData> Symbols; 604 605 /// The map of sections to their associated assembler backend data. 606 // 607 // FIXME: Avoid this indirection? 608 DenseMap<const MCSection*, MCSectionData*> SectionMap; 609 610 /// The map of symbols to their associated assembler backend data. 611 // 612 // FIXME: Avoid this indirection? 613 DenseMap<const MCSymbol*, MCSymbolData*> SymbolMap; 614 615 std::vector<IndirectSymbolData> IndirectSymbols; 616 617 unsigned RelaxAll : 1; 618 unsigned SubsectionsViaSymbols : 1; 619 620private: 621 /// Evaluate a fixup to a relocatable expression and the value which should be 622 /// placed into the fixup. 623 /// 624 /// \param Layout The layout to use for evaluation. 625 /// \param Fixup The fixup to evaluate. 626 /// \param DF The fragment the fixup is inside. 627 /// \param Target [out] On return, the relocatable expression the fixup 628 /// evaluates to. 629 /// \param Value [out] On return, the value of the fixup as currently layed 630 /// out. 631 /// \return Whether the fixup value was fully resolved. This is true if the 632 /// \arg Value result is fixed, otherwise the value may change due to 633 /// relocation. 634 bool EvaluateFixup(const MCAsmLayout &Layout, 635 const MCAsmFixup &Fixup, const MCFragment *DF, 636 MCValue &Target, uint64_t &Value) const; 637 638 /// Check whether a fixup can be satisfied, or whether it needs to be relaxed 639 /// (increased in size, in order to hold its value correctly). 640 bool FixupNeedsRelaxation(const MCAsmFixup &Fixup, const MCFragment *DF, 641 const MCAsmLayout &Layout) const; 642 643 /// Check whether the given fragment needs relaxation. 644 bool FragmentNeedsRelaxation(const MCInstFragment *IF, 645 const MCAsmLayout &Layout) const; 646 647 /// LayoutFragment - Performs layout of the given \arg Fragment; assuming that 648 /// the previous fragment has already been layed out correctly, and the parent 649 /// section has been initialized. 650 void LayoutFragment(MCAsmLayout &Layout, MCFragment &Fragment); 651 652 /// LayoutSection - Performs layout of the section referenced by the given 653 /// \arg SectionOrderIndex. The layout assumes that the previous section has 654 /// already been layed out correctly. 655 void LayoutSection(MCAsmLayout &Layout, unsigned SectionOrderIndex); 656 657 /// LayoutOnce - Perform one layout iteration and return true if any offsets 658 /// were adjusted. 659 bool LayoutOnce(MCAsmLayout &Layout); 660 661 /// FinishLayout - Finalize a layout, including fragment lowering. 662 void FinishLayout(MCAsmLayout &Layout); 663 664public: 665 /// Find the symbol which defines the atom containing the given symbol, or 666 /// null if there is no such symbol. 667 const MCSymbolData *getAtom(const MCAsmLayout &Layout, 668 const MCSymbolData *Symbol) const; 669 670 /// Check whether a particular symbol is visible to the linker and is required 671 /// in the symbol table, or whether it can be discarded by the assembler. This 672 /// also effects whether the assembler treats the label as potentially 673 /// defining a separate atom. 674 bool isSymbolLinkerVisible(const MCSymbolData *SD) const; 675 676 /// Emit the section contents using the given object writer. 677 // 678 // FIXME: Should MCAssembler always have a reference to the object writer? 679 void WriteSectionData(const MCSectionData *Section, const MCAsmLayout &Layout, 680 MCObjectWriter *OW) const; 681 682public: 683 /// Construct a new assembler instance. 684 /// 685 /// \arg OS - The stream to output to. 686 // 687 // FIXME: How are we going to parameterize this? Two obvious options are stay 688 // concrete and require clients to pass in a target like object. The other 689 // option is to make this abstract, and have targets provide concrete 690 // implementations as we do with AsmParser. 691 MCAssembler(MCContext &_Context, TargetAsmBackend &_Backend, 692 MCCodeEmitter &_Emitter, raw_ostream &OS); 693 ~MCAssembler(); 694 695 MCContext &getContext() const { return Context; } 696 697 TargetAsmBackend &getBackend() const { return Backend; } 698 699 MCCodeEmitter &getEmitter() const { return Emitter; } 700 701 /// Finish - Do final processing and write the object to the output stream. 702 void Finish(); 703 704 // FIXME: This does not belong here. 705 bool getSubsectionsViaSymbols() const { 706 return SubsectionsViaSymbols; 707 } 708 void setSubsectionsViaSymbols(bool Value) { 709 SubsectionsViaSymbols = Value; 710 } 711 712 bool getRelaxAll() const { return RelaxAll; } 713 void setRelaxAll(bool Value) { RelaxAll = Value; } 714 715 /// @name Section List Access 716 /// @{ 717 718 const SectionDataListType &getSectionList() const { return Sections; } 719 SectionDataListType &getSectionList() { return Sections; } 720 721 iterator begin() { return Sections.begin(); } 722 const_iterator begin() const { return Sections.begin(); } 723 724 iterator end() { return Sections.end(); } 725 const_iterator end() const { return Sections.end(); } 726 727 size_t size() const { return Sections.size(); } 728 729 /// @} 730 /// @name Symbol List Access 731 /// @{ 732 733 const SymbolDataListType &getSymbolList() const { return Symbols; } 734 SymbolDataListType &getSymbolList() { return Symbols; } 735 736 symbol_iterator symbol_begin() { return Symbols.begin(); } 737 const_symbol_iterator symbol_begin() const { return Symbols.begin(); } 738 739 symbol_iterator symbol_end() { return Symbols.end(); } 740 const_symbol_iterator symbol_end() const { return Symbols.end(); } 741 742 size_t symbol_size() const { return Symbols.size(); } 743 744 /// @} 745 /// @name Indirect Symbol List Access 746 /// @{ 747 748 // FIXME: This is a total hack, this should not be here. Once things are 749 // factored so that the streamer has direct access to the .o writer, it can 750 // disappear. 751 std::vector<IndirectSymbolData> &getIndirectSymbols() { 752 return IndirectSymbols; 753 } 754 755 indirect_symbol_iterator indirect_symbol_begin() { 756 return IndirectSymbols.begin(); 757 } 758 const_indirect_symbol_iterator indirect_symbol_begin() const { 759 return IndirectSymbols.begin(); 760 } 761 762 indirect_symbol_iterator indirect_symbol_end() { 763 return IndirectSymbols.end(); 764 } 765 const_indirect_symbol_iterator indirect_symbol_end() const { 766 return IndirectSymbols.end(); 767 } 768 769 size_t indirect_symbol_size() const { return IndirectSymbols.size(); } 770 771 /// @} 772 /// @name Backend Data Access 773 /// @{ 774 775 MCSectionData &getSectionData(const MCSection &Section) const { 776 MCSectionData *Entry = SectionMap.lookup(&Section); 777 assert(Entry && "Missing section data!"); 778 return *Entry; 779 } 780 781 MCSectionData &getOrCreateSectionData(const MCSection &Section, 782 bool *Created = 0) { 783 MCSectionData *&Entry = SectionMap[&Section]; 784 785 if (Created) *Created = !Entry; 786 if (!Entry) 787 Entry = new MCSectionData(Section, this); 788 789 return *Entry; 790 } 791 792 MCSymbolData &getSymbolData(const MCSymbol &Symbol) const { 793 MCSymbolData *Entry = SymbolMap.lookup(&Symbol); 794 assert(Entry && "Missing symbol data!"); 795 return *Entry; 796 } 797 798 MCSymbolData &getOrCreateSymbolData(const MCSymbol &Symbol, 799 bool *Created = 0) { 800 MCSymbolData *&Entry = SymbolMap[&Symbol]; 801 802 if (Created) *Created = !Entry; 803 if (!Entry) 804 Entry = new MCSymbolData(Symbol, 0, 0, this); 805 806 return *Entry; 807 } 808 809 /// @} 810 811 void dump(); 812}; 813 814} // end namespace llvm 815 816#endif 817