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