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