MCAssembler.h revision b69fc044db8c193348b6611f46432bb21b3cbe90
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 /// LayoutOrder - The index of this section in the layout order. 396 unsigned LayoutOrder; 397 398 /// Alignment - The maximum alignment seen in this section. 399 unsigned Alignment; 400 401 /// @name Assembler Backend Data 402 /// @{ 403 // 404 // FIXME: This could all be kept private to the assembler implementation. 405 406 /// Address - The computed address of this section. This is ~0 until 407 /// initialized. 408 uint64_t Address; 409 410 /// HasInstructions - Whether this section has had instructions emitted into 411 /// it. 412 unsigned HasInstructions : 1; 413 414 /// @} 415 416public: 417 // Only for use as sentinel. 418 MCSectionData(); 419 MCSectionData(const MCSection &Section, MCAssembler *A = 0); 420 421 const MCSection &getSection() const { return *Section; } 422 423 unsigned getAlignment() const { return Alignment; } 424 void setAlignment(unsigned Value) { Alignment = Value; } 425 426 bool hasInstructions() const { return HasInstructions; } 427 void setHasInstructions(bool Value) { HasInstructions = Value; } 428 429 unsigned getOrdinal() const { return Ordinal; } 430 void setOrdinal(unsigned Value) { Ordinal = Value; } 431 432 unsigned getLayoutOrder() const { return LayoutOrder; } 433 void setLayoutOrder(unsigned Value) { LayoutOrder = Value; } 434 435 /// @name Fragment Access 436 /// @{ 437 438 const FragmentListType &getFragmentList() const { return Fragments; } 439 FragmentListType &getFragmentList() { return Fragments; } 440 441 iterator begin() { return Fragments.begin(); } 442 const_iterator begin() const { return Fragments.begin(); } 443 444 iterator end() { return Fragments.end(); } 445 const_iterator end() const { return Fragments.end(); } 446 447 reverse_iterator rbegin() { return Fragments.rbegin(); } 448 const_reverse_iterator rbegin() const { return Fragments.rbegin(); } 449 450 reverse_iterator rend() { return Fragments.rend(); } 451 const_reverse_iterator rend() const { return Fragments.rend(); } 452 453 size_t size() const { return Fragments.size(); } 454 455 bool empty() const { return Fragments.empty(); } 456 457 void dump(); 458 459 /// @} 460}; 461 462// FIXME: Same concerns as with SectionData. 463class MCSymbolData : public ilist_node<MCSymbolData> { 464public: 465 const MCSymbol *Symbol; 466 467 /// Fragment - The fragment this symbol's value is relative to, if any. 468 MCFragment *Fragment; 469 470 /// Offset - The offset to apply to the fragment address to form this symbol's 471 /// value. 472 uint64_t Offset; 473 474 /// IsExternal - True if this symbol is visible outside this translation 475 /// unit. 476 unsigned IsExternal : 1; 477 478 /// IsPrivateExtern - True if this symbol is private extern. 479 unsigned IsPrivateExtern : 1; 480 481 /// CommonSize - The size of the symbol, if it is 'common', or 0. 482 // 483 // FIXME: Pack this in with other fields? We could put it in offset, since a 484 // common symbol can never get a definition. 485 uint64_t CommonSize; 486 487 /// CommonAlign - The alignment of the symbol, if it is 'common'. 488 // 489 // FIXME: Pack this in with other fields? 490 unsigned CommonAlign; 491 492 /// Flags - The Flags field is used by object file implementations to store 493 /// additional per symbol information which is not easily classified. 494 uint32_t Flags; 495 496 /// Index - Index field, for use by the object file implementation. 497 uint64_t Index; 498 499public: 500 // Only for use as sentinel. 501 MCSymbolData(); 502 MCSymbolData(const MCSymbol &_Symbol, MCFragment *_Fragment, uint64_t _Offset, 503 MCAssembler *A = 0); 504 505 /// @name Accessors 506 /// @{ 507 508 const MCSymbol &getSymbol() const { return *Symbol; } 509 510 MCFragment *getFragment() const { return Fragment; } 511 void setFragment(MCFragment *Value) { Fragment = Value; } 512 513 uint64_t getOffset() const { return Offset; } 514 void setOffset(uint64_t Value) { Offset = Value; } 515 516 /// @} 517 /// @name Symbol Attributes 518 /// @{ 519 520 bool isExternal() const { return IsExternal; } 521 void setExternal(bool Value) { IsExternal = Value; } 522 523 bool isPrivateExtern() const { return IsPrivateExtern; } 524 void setPrivateExtern(bool Value) { IsPrivateExtern = Value; } 525 526 /// isCommon - Is this a 'common' symbol. 527 bool isCommon() const { return CommonSize != 0; } 528 529 /// setCommon - Mark this symbol as being 'common'. 530 /// 531 /// \param Size - The size of the symbol. 532 /// \param Align - The alignment of the symbol. 533 void setCommon(uint64_t Size, unsigned Align) { 534 CommonSize = Size; 535 CommonAlign = Align; 536 } 537 538 /// getCommonSize - Return the size of a 'common' symbol. 539 uint64_t getCommonSize() const { 540 assert(isCommon() && "Not a 'common' symbol!"); 541 return CommonSize; 542 } 543 544 /// getCommonAlignment - Return the alignment of a 'common' symbol. 545 unsigned getCommonAlignment() const { 546 assert(isCommon() && "Not a 'common' symbol!"); 547 return CommonAlign; 548 } 549 550 /// getFlags - Get the (implementation defined) symbol flags. 551 uint32_t getFlags() const { return Flags; } 552 553 /// setFlags - Set the (implementation defined) symbol flags. 554 void setFlags(uint32_t Value) { Flags = Value; } 555 556 /// modifyFlags - Modify the flags via a mask 557 void modifyFlags(uint32_t Value, uint32_t Mask) { 558 Flags = (Flags & ~Mask) | Value; 559 } 560 561 /// getIndex - Get the (implementation defined) index. 562 uint64_t getIndex() const { return Index; } 563 564 /// setIndex - Set the (implementation defined) index. 565 void setIndex(uint64_t Value) { Index = Value; } 566 567 /// @} 568 569 void dump(); 570}; 571 572// FIXME: This really doesn't belong here. See comments below. 573struct IndirectSymbolData { 574 MCSymbol *Symbol; 575 MCSectionData *SectionData; 576}; 577 578class MCAssembler { 579 friend class MCAsmLayout; 580 581public: 582 typedef iplist<MCSectionData> SectionDataListType; 583 typedef iplist<MCSymbolData> SymbolDataListType; 584 585 typedef SectionDataListType::const_iterator const_iterator; 586 typedef SectionDataListType::iterator iterator; 587 588 typedef SymbolDataListType::const_iterator const_symbol_iterator; 589 typedef SymbolDataListType::iterator symbol_iterator; 590 591 typedef std::vector<IndirectSymbolData>::const_iterator 592 const_indirect_symbol_iterator; 593 typedef std::vector<IndirectSymbolData>::iterator indirect_symbol_iterator; 594 595private: 596 MCAssembler(const MCAssembler&); // DO NOT IMPLEMENT 597 void operator=(const MCAssembler&); // DO NOT IMPLEMENT 598 599 MCContext &Context; 600 601 TargetAsmBackend &Backend; 602 603 MCCodeEmitter &Emitter; 604 605 raw_ostream &OS; 606 607 iplist<MCSectionData> Sections; 608 609 iplist<MCSymbolData> Symbols; 610 611 /// The map of sections to their associated assembler backend data. 612 // 613 // FIXME: Avoid this indirection? 614 DenseMap<const MCSection*, MCSectionData*> SectionMap; 615 616 /// The map of symbols to their associated assembler backend data. 617 // 618 // FIXME: Avoid this indirection? 619 DenseMap<const MCSymbol*, MCSymbolData*> SymbolMap; 620 621 std::vector<IndirectSymbolData> IndirectSymbols; 622 623 unsigned RelaxAll : 1; 624 unsigned SubsectionsViaSymbols : 1; 625 626private: 627 /// Evaluate a fixup to a relocatable expression and the value which should be 628 /// placed into the fixup. 629 /// 630 /// \param Layout The layout to use for evaluation. 631 /// \param Fixup The fixup to evaluate. 632 /// \param DF The fragment the fixup is inside. 633 /// \param Target [out] On return, the relocatable expression the fixup 634 /// evaluates to. 635 /// \param Value [out] On return, the value of the fixup as currently layed 636 /// out. 637 /// \return Whether the fixup value was fully resolved. This is true if the 638 /// \arg Value result is fixed, otherwise the value may change due to 639 /// relocation. 640 bool EvaluateFixup(const MCAsmLayout &Layout, 641 const MCAsmFixup &Fixup, const MCFragment *DF, 642 MCValue &Target, uint64_t &Value) const; 643 644 /// Check whether a fixup can be satisfied, or whether it needs to be relaxed 645 /// (increased in size, in order to hold its value correctly). 646 bool FixupNeedsRelaxation(const MCAsmFixup &Fixup, const MCFragment *DF, 647 const MCAsmLayout &Layout) const; 648 649 /// Check whether the given fragment needs relaxation. 650 bool FragmentNeedsRelaxation(const MCInstFragment *IF, 651 const MCAsmLayout &Layout) const; 652 653 /// Compute the effective fragment size assuming it is layed out at the given 654 /// \arg SectionAddress and \arg FragmentOffset. 655 uint64_t ComputeFragmentSize(MCAsmLayout &Layout, const MCFragment &F, 656 uint64_t SectionAddress, 657 uint64_t FragmentOffset) const; 658 659 /// LayoutOnce - Perform one layout iteration and return true if any offsets 660 /// were adjusted. 661 bool LayoutOnce(MCAsmLayout &Layout); 662 663 /// FinishLayout - Finalize a layout, including fragment lowering. 664 void FinishLayout(MCAsmLayout &Layout); 665 666public: 667 /// Find the symbol which defines the atom containing the given symbol, or 668 /// null if there is no such symbol. 669 const MCSymbolData *getAtom(const MCAsmLayout &Layout, 670 const MCSymbolData *Symbol) const; 671 672 /// Check whether a particular symbol is visible to the linker and is required 673 /// in the symbol table, or whether it can be discarded by the assembler. This 674 /// also effects whether the assembler treats the label as potentially 675 /// defining a separate atom. 676 bool isSymbolLinkerVisible(const MCSymbolData *SD) const; 677 678 /// Emit the section contents using the given object writer. 679 // 680 // FIXME: Should MCAssembler always have a reference to the object writer? 681 void WriteSectionData(const MCSectionData *Section, const MCAsmLayout &Layout, 682 MCObjectWriter *OW) const; 683 684public: 685 /// Construct a new assembler instance. 686 /// 687 /// \arg OS - The stream to output to. 688 // 689 // FIXME: How are we going to parameterize this? Two obvious options are stay 690 // concrete and require clients to pass in a target like object. The other 691 // option is to make this abstract, and have targets provide concrete 692 // implementations as we do with AsmParser. 693 MCAssembler(MCContext &_Context, TargetAsmBackend &_Backend, 694 MCCodeEmitter &_Emitter, raw_ostream &OS); 695 ~MCAssembler(); 696 697 MCContext &getContext() const { return Context; } 698 699 TargetAsmBackend &getBackend() const { return Backend; } 700 701 MCCodeEmitter &getEmitter() const { return Emitter; } 702 703 /// Finish - Do final processing and write the object to the output stream. 704 void Finish(); 705 706 // FIXME: This does not belong here. 707 bool getSubsectionsViaSymbols() const { 708 return SubsectionsViaSymbols; 709 } 710 void setSubsectionsViaSymbols(bool Value) { 711 SubsectionsViaSymbols = Value; 712 } 713 714 bool getRelaxAll() const { return RelaxAll; } 715 void setRelaxAll(bool Value) { RelaxAll = Value; } 716 717 /// @name Section List Access 718 /// @{ 719 720 const SectionDataListType &getSectionList() const { return Sections; } 721 SectionDataListType &getSectionList() { return Sections; } 722 723 iterator begin() { return Sections.begin(); } 724 const_iterator begin() const { return Sections.begin(); } 725 726 iterator end() { return Sections.end(); } 727 const_iterator end() const { return Sections.end(); } 728 729 size_t size() const { return Sections.size(); } 730 731 /// @} 732 /// @name Symbol List Access 733 /// @{ 734 735 const SymbolDataListType &getSymbolList() const { return Symbols; } 736 SymbolDataListType &getSymbolList() { return Symbols; } 737 738 symbol_iterator symbol_begin() { return Symbols.begin(); } 739 const_symbol_iterator symbol_begin() const { return Symbols.begin(); } 740 741 symbol_iterator symbol_end() { return Symbols.end(); } 742 const_symbol_iterator symbol_end() const { return Symbols.end(); } 743 744 size_t symbol_size() const { return Symbols.size(); } 745 746 /// @} 747 /// @name Indirect Symbol List Access 748 /// @{ 749 750 // FIXME: This is a total hack, this should not be here. Once things are 751 // factored so that the streamer has direct access to the .o writer, it can 752 // disappear. 753 std::vector<IndirectSymbolData> &getIndirectSymbols() { 754 return IndirectSymbols; 755 } 756 757 indirect_symbol_iterator indirect_symbol_begin() { 758 return IndirectSymbols.begin(); 759 } 760 const_indirect_symbol_iterator indirect_symbol_begin() const { 761 return IndirectSymbols.begin(); 762 } 763 764 indirect_symbol_iterator indirect_symbol_end() { 765 return IndirectSymbols.end(); 766 } 767 const_indirect_symbol_iterator indirect_symbol_end() const { 768 return IndirectSymbols.end(); 769 } 770 771 size_t indirect_symbol_size() const { return IndirectSymbols.size(); } 772 773 /// @} 774 /// @name Backend Data Access 775 /// @{ 776 777 MCSectionData &getSectionData(const MCSection &Section) const { 778 MCSectionData *Entry = SectionMap.lookup(&Section); 779 assert(Entry && "Missing section data!"); 780 return *Entry; 781 } 782 783 MCSectionData &getOrCreateSectionData(const MCSection &Section, 784 bool *Created = 0) { 785 MCSectionData *&Entry = SectionMap[&Section]; 786 787 if (Created) *Created = !Entry; 788 if (!Entry) 789 Entry = new MCSectionData(Section, this); 790 791 return *Entry; 792 } 793 794 MCSymbolData &getSymbolData(const MCSymbol &Symbol) const { 795 MCSymbolData *Entry = SymbolMap.lookup(&Symbol); 796 assert(Entry && "Missing symbol data!"); 797 return *Entry; 798 } 799 800 MCSymbolData &getOrCreateSymbolData(const MCSymbol &Symbol, 801 bool *Created = 0) { 802 MCSymbolData *&Entry = SymbolMap[&Symbol]; 803 804 if (Created) *Created = !Entry; 805 if (!Entry) 806 Entry = new MCSymbolData(Symbol, 0, 0, this); 807 808 return *Entry; 809 } 810 811 /// @} 812 813 void dump(); 814}; 815 816} // end namespace llvm 817 818#endif 819