MCAssembler.h revision 337055e62f28f18a9a8c4a090633cae1c2256ae1
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 MCFragment(const MCFragment&); // DO NOT IMPLEMENT 61 void operator=(const MCFragment&); // DO NOT IMPLEMENT 62 63public: 64 enum FragmentType { 65 FT_Align, 66 FT_Data, 67 FT_Fill, 68 FT_Inst, 69 FT_Org, 70 FT_ZeroFill 71 }; 72 73private: 74 FragmentType Kind; 75 76 /// Parent - The data for the section this fragment is in. 77 MCSectionData *Parent; 78 79 /// @name Assembler Backend Data 80 /// @{ 81 // 82 // FIXME: This could all be kept private to the assembler implementation. 83 84 /// Offset - The offset of this fragment in its section. This is ~0 until 85 /// initialized. 86 uint64_t Offset; 87 88 /// FileSize - The file size of this section. This is ~0 until initialized. 89 uint64_t FileSize; 90 91 /// @} 92 93protected: 94 MCFragment(FragmentType _Kind, MCSectionData *_Parent = 0); 95 96public: 97 // Only for sentinel. 98 MCFragment(); 99 virtual ~MCFragment(); 100 101 FragmentType getKind() const { return Kind; } 102 103 MCSectionData *getParent() const { return Parent; } 104 void setParent(MCSectionData *Value) { Parent = Value; } 105 106 /// @name Assembler Backend Support 107 /// @{ 108 // 109 // FIXME: This could all be kept private to the assembler implementation. 110 111 uint64_t getAddress() const; 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 MCSectionData(const MCSectionData&); // DO NOT IMPLEMENT 394 void operator=(const MCSectionData&); // DO NOT IMPLEMENT 395 396public: 397 typedef iplist<MCFragment> FragmentListType; 398 399 typedef FragmentListType::const_iterator const_iterator; 400 typedef FragmentListType::iterator iterator; 401 402 typedef FragmentListType::const_reverse_iterator const_reverse_iterator; 403 typedef FragmentListType::reverse_iterator reverse_iterator; 404 405private: 406 iplist<MCFragment> Fragments; 407 const MCSection *Section; 408 409 /// Alignment - The maximum alignment seen in this section. 410 unsigned Alignment; 411 412 /// @name Assembler Backend Data 413 /// @{ 414 // 415 // FIXME: This could all be kept private to the assembler implementation. 416 417 /// Address - The computed address of this section. This is ~0 until 418 /// initialized. 419 uint64_t Address; 420 421 /// Size - The content size of this section. This is ~0 until initialized. 422 uint64_t Size; 423 424 /// FileSize - The size of this section in the object file. This is ~0 until 425 /// initialized. 426 uint64_t FileSize; 427 428 /// HasInstructions - Whether this section has had instructions emitted into 429 /// it. 430 unsigned HasInstructions : 1; 431 432 /// @} 433 434public: 435 // Only for use as sentinel. 436 MCSectionData(); 437 MCSectionData(const MCSection &Section, MCAssembler *A = 0); 438 439 const MCSection &getSection() const { return *Section; } 440 441 unsigned getAlignment() const { return Alignment; } 442 void setAlignment(unsigned Value) { Alignment = 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 /// @} 467 /// @name Assembler Backend Support 468 /// @{ 469 // 470 // FIXME: This could all be kept private to the assembler implementation. 471 472 uint64_t getAddress() const { 473 assert(Address != ~UINT64_C(0) && "Address not set!"); 474 return Address; 475 } 476 void setAddress(uint64_t Value) { Address = Value; } 477 478 uint64_t getSize() const { 479 assert(Size != ~UINT64_C(0) && "File size not set!"); 480 return Size; 481 } 482 void setSize(uint64_t Value) { Size = Value; } 483 484 uint64_t getFileSize() const { 485 assert(FileSize != ~UINT64_C(0) && "File size not set!"); 486 return FileSize; 487 } 488 void setFileSize(uint64_t Value) { FileSize = Value; } 489 490 bool hasInstructions() const { return HasInstructions; } 491 void setHasInstructions(bool Value) { HasInstructions = Value; } 492 493 /// @} 494 495 void dump(); 496}; 497 498// FIXME: Same concerns as with SectionData. 499class MCSymbolData : public ilist_node<MCSymbolData> { 500public: 501 const MCSymbol *Symbol; 502 503 /// Fragment - The fragment this symbol's value is relative to, if any. 504 MCFragment *Fragment; 505 506 /// Offset - The offset to apply to the fragment address to form this symbol's 507 /// value. 508 uint64_t Offset; 509 510 /// IsExternal - True if this symbol is visible outside this translation 511 /// unit. 512 unsigned IsExternal : 1; 513 514 /// IsPrivateExtern - True if this symbol is private extern. 515 unsigned IsPrivateExtern : 1; 516 517 /// CommonSize - The size of the symbol, if it is 'common', or 0. 518 // 519 // FIXME: Pack this in with other fields? We could put it in offset, since a 520 // common symbol can never get a definition. 521 uint64_t CommonSize; 522 523 /// CommonAlign - The alignment of the symbol, if it is 'common'. 524 // 525 // FIXME: Pack this in with other fields? 526 unsigned CommonAlign; 527 528 /// Flags - The Flags field is used by object file implementations to store 529 /// additional per symbol information which is not easily classified. 530 uint32_t Flags; 531 532 /// Index - Index field, for use by the object file implementation. 533 uint64_t Index; 534 535public: 536 // Only for use as sentinel. 537 MCSymbolData(); 538 MCSymbolData(const MCSymbol &_Symbol, MCFragment *_Fragment, uint64_t _Offset, 539 MCAssembler *A = 0); 540 541 /// @name Accessors 542 /// @{ 543 544 const MCSymbol &getSymbol() const { return *Symbol; } 545 546 MCFragment *getFragment() const { return Fragment; } 547 void setFragment(MCFragment *Value) { Fragment = Value; } 548 549 uint64_t getOffset() const { return Offset; } 550 void setOffset(uint64_t Value) { Offset = Value; } 551 552 uint64_t getAddress() const { 553 assert(getFragment() && "Invalid getAddress() on undefined symbol!"); 554 return getFragment()->getAddress() + getOffset(); 555 } 556 557 /// @} 558 /// @name Symbol Attributes 559 /// @{ 560 561 bool isExternal() const { return IsExternal; } 562 void setExternal(bool Value) { IsExternal = Value; } 563 564 bool isPrivateExtern() const { return IsPrivateExtern; } 565 void setPrivateExtern(bool Value) { IsPrivateExtern = Value; } 566 567 /// isCommon - Is this a 'common' symbol. 568 bool isCommon() const { return CommonSize != 0; } 569 570 /// setCommon - Mark this symbol as being 'common'. 571 /// 572 /// \param Size - The size of the symbol. 573 /// \param Align - The alignment of the symbol. 574 void setCommon(uint64_t Size, unsigned Align) { 575 CommonSize = Size; 576 CommonAlign = Align; 577 } 578 579 /// getCommonSize - Return the size of a 'common' symbol. 580 uint64_t getCommonSize() const { 581 assert(isCommon() && "Not a 'common' symbol!"); 582 return CommonSize; 583 } 584 585 /// getCommonAlignment - Return the alignment of a 'common' symbol. 586 unsigned getCommonAlignment() const { 587 assert(isCommon() && "Not a 'common' symbol!"); 588 return CommonAlign; 589 } 590 591 /// getFlags - Get the (implementation defined) symbol flags. 592 uint32_t getFlags() const { return Flags; } 593 594 /// setFlags - Set the (implementation defined) symbol flags. 595 void setFlags(uint32_t Value) { Flags = Value; } 596 597 /// getIndex - Get the (implementation defined) index. 598 uint64_t getIndex() const { return Index; } 599 600 /// setIndex - Set the (implementation defined) index. 601 void setIndex(uint64_t Value) { Index = Value; } 602 603 /// @} 604 605 void dump(); 606}; 607 608// FIXME: This really doesn't belong here. See comments below. 609struct IndirectSymbolData { 610 MCSymbol *Symbol; 611 MCSectionData *SectionData; 612}; 613 614class MCAssembler { 615public: 616 typedef iplist<MCSectionData> SectionDataListType; 617 typedef iplist<MCSymbolData> SymbolDataListType; 618 619 typedef SectionDataListType::const_iterator const_iterator; 620 typedef SectionDataListType::iterator iterator; 621 622 typedef SymbolDataListType::const_iterator const_symbol_iterator; 623 typedef SymbolDataListType::iterator symbol_iterator; 624 625 typedef std::vector<IndirectSymbolData>::const_iterator 626 const_indirect_symbol_iterator; 627 typedef std::vector<IndirectSymbolData>::iterator indirect_symbol_iterator; 628 629private: 630 MCAssembler(const MCAssembler&); // DO NOT IMPLEMENT 631 void operator=(const MCAssembler&); // DO NOT IMPLEMENT 632 633 MCContext &Context; 634 635 TargetAsmBackend &Backend; 636 637 MCCodeEmitter &Emitter; 638 639 raw_ostream &OS; 640 641 iplist<MCSectionData> Sections; 642 643 iplist<MCSymbolData> Symbols; 644 645 /// The map of sections to their associated assembler backend data. 646 // 647 // FIXME: Avoid this indirection? 648 DenseMap<const MCSection*, MCSectionData*> SectionMap; 649 650 /// The map of symbols to their associated assembler backend data. 651 // 652 // FIXME: Avoid this indirection? 653 DenseMap<const MCSymbol*, MCSymbolData*> SymbolMap; 654 655 std::vector<IndirectSymbolData> IndirectSymbols; 656 657 unsigned SubsectionsViaSymbols : 1; 658 659private: 660 /// Evaluate a fixup to a relocatable expression and the value which should be 661 /// placed into the fixup. 662 /// 663 /// \param Layout The layout to use for evaluation. 664 /// \param Fixup The fixup to evaluate. 665 /// \param DF The fragment the fixup is inside. 666 /// \param Target [out] On return, the relocatable expression the fixup 667 /// evaluates to. 668 /// \param Value [out] On return, the value of the fixup as currently layed 669 /// out. 670 /// \return Whether the fixup value was fully resolved. This is true if the 671 /// \arg Value result is fixed, otherwise the value may change due to 672 /// relocation. 673 bool EvaluateFixup(const MCAsmLayout &Layout, 674 const MCAsmFixup &Fixup, const MCFragment *DF, 675 MCValue &Target, uint64_t &Value) const; 676 677 /// Check whether a fixup can be satisfied, or whether it needs to be relaxed 678 /// (increased in size, in order to hold its value correctly). 679 bool FixupNeedsRelaxation(const MCAsmFixup &Fixup, const MCFragment *DF, 680 const MCAsmLayout &Layout) const; 681 682 /// Check whether the given fragment needs relaxation. 683 bool FragmentNeedsRelaxation(const MCInstFragment *IF, 684 const MCAsmLayout &Layout) const; 685 686 /// LayoutSection - Assign offsets and sizes to the fragments in the section 687 /// \arg SD, and update the section size. The section file offset should 688 /// already have been computed. 689 void LayoutSection(MCSectionData &SD, MCAsmLayout &Layout); 690 691 /// LayoutOnce - Perform one layout iteration and return true if any offsets 692 /// were adjusted. 693 bool LayoutOnce(MCAsmLayout &Layout); 694 695 /// FinishLayout - Finalize a layout, including fragment lowering. 696 void FinishLayout(MCAsmLayout &Layout); 697 698public: 699 /// Find the symbol which defines the atom containing given address, inside 700 /// the given section, or null if there is no such symbol. 701 // 702 // FIXME: Eliminate this, it is very slow. 703 const MCSymbolData *getAtomForAddress(const MCSectionData *Section, 704 uint64_t Address) const; 705 706 /// Find the symbol which defines the atom containing the given symbol, or 707 /// null if there is no such symbol. 708 // 709 // FIXME: Eliminate this, it is very slow. 710 const MCSymbolData *getAtom(const MCSymbolData *Symbol) const; 711 712 /// Check whether a particular symbol is visible to the linker and is required 713 /// in the symbol table, or whether it can be discarded by the assembler. This 714 /// also effects whether the assembler treats the label as potentially 715 /// defining a separate atom. 716 bool isSymbolLinkerVisible(const MCSymbolData *SD) const; 717 718 /// Emit the section contents using the given object writer. 719 // 720 // FIXME: Should MCAssembler always have a reference to the object writer? 721 void WriteSectionData(const MCSectionData *Section, MCObjectWriter *OW) const; 722 723public: 724 /// Construct a new assembler instance. 725 /// 726 /// \arg OS - The stream to output to. 727 // 728 // FIXME: How are we going to parameterize this? Two obvious options are stay 729 // concrete and require clients to pass in a target like object. The other 730 // option is to make this abstract, and have targets provide concrete 731 // implementations as we do with AsmParser. 732 MCAssembler(MCContext &_Context, TargetAsmBackend &_Backend, 733 MCCodeEmitter &_Emitter, raw_ostream &OS); 734 ~MCAssembler(); 735 736 MCContext &getContext() const { return Context; } 737 738 TargetAsmBackend &getBackend() const { return Backend; } 739 740 MCCodeEmitter &getEmitter() const { return Emitter; } 741 742 /// Finish - Do final processing and write the object to the output stream. 743 void Finish(); 744 745 // FIXME: This does not belong here. 746 bool getSubsectionsViaSymbols() const { 747 return SubsectionsViaSymbols; 748 } 749 void setSubsectionsViaSymbols(bool Value) { 750 SubsectionsViaSymbols = Value; 751 } 752 753 /// @name Section List Access 754 /// @{ 755 756 const SectionDataListType &getSectionList() const { return Sections; } 757 SectionDataListType &getSectionList() { return Sections; } 758 759 iterator begin() { return Sections.begin(); } 760 const_iterator begin() const { return Sections.begin(); } 761 762 iterator end() { return Sections.end(); } 763 const_iterator end() const { return Sections.end(); } 764 765 size_t size() const { return Sections.size(); } 766 767 /// @} 768 /// @name Symbol List Access 769 /// @{ 770 771 const SymbolDataListType &getSymbolList() const { return Symbols; } 772 SymbolDataListType &getSymbolList() { return Symbols; } 773 774 symbol_iterator symbol_begin() { return Symbols.begin(); } 775 const_symbol_iterator symbol_begin() const { return Symbols.begin(); } 776 777 symbol_iterator symbol_end() { return Symbols.end(); } 778 const_symbol_iterator symbol_end() const { return Symbols.end(); } 779 780 size_t symbol_size() const { return Symbols.size(); } 781 782 /// @} 783 /// @name Indirect Symbol List Access 784 /// @{ 785 786 // FIXME: This is a total hack, this should not be here. Once things are 787 // factored so that the streamer has direct access to the .o writer, it can 788 // disappear. 789 std::vector<IndirectSymbolData> &getIndirectSymbols() { 790 return IndirectSymbols; 791 } 792 793 indirect_symbol_iterator indirect_symbol_begin() { 794 return IndirectSymbols.begin(); 795 } 796 const_indirect_symbol_iterator indirect_symbol_begin() const { 797 return IndirectSymbols.begin(); 798 } 799 800 indirect_symbol_iterator indirect_symbol_end() { 801 return IndirectSymbols.end(); 802 } 803 const_indirect_symbol_iterator indirect_symbol_end() const { 804 return IndirectSymbols.end(); 805 } 806 807 size_t indirect_symbol_size() const { return IndirectSymbols.size(); } 808 809 /// @} 810 /// @name Backend Data Access 811 /// @{ 812 813 MCSectionData &getSectionData(const MCSection &Section) const { 814 MCSectionData *Entry = SectionMap.lookup(&Section); 815 assert(Entry && "Missing section data!"); 816 return *Entry; 817 } 818 819 MCSectionData &getOrCreateSectionData(const MCSection &Section, 820 bool *Created = 0) { 821 MCSectionData *&Entry = SectionMap[&Section]; 822 823 if (Created) *Created = !Entry; 824 if (!Entry) 825 Entry = new MCSectionData(Section, this); 826 827 return *Entry; 828 } 829 830 MCSymbolData &getSymbolData(const MCSymbol &Symbol) const { 831 MCSymbolData *Entry = SymbolMap.lookup(&Symbol); 832 assert(Entry && "Missing symbol data!"); 833 return *Entry; 834 } 835 836 MCSymbolData &getOrCreateSymbolData(const MCSymbol &Symbol, 837 bool *Created = 0) { 838 MCSymbolData *&Entry = SymbolMap[&Symbol]; 839 840 if (Created) *Created = !Entry; 841 if (!Entry) 842 Entry = new MCSymbolData(Symbol, 0, 0, this); 843 844 return *Entry; 845 } 846 847 /// @} 848 849 void dump(); 850}; 851 852} // end namespace llvm 853 854#endif 855