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