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