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