1 //===- MCAssembler.h - Object File Generation -------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef LLVM_MC_MCASSEMBLER_H
11 #define LLVM_MC_MCASSEMBLER_H
13 #include "llvm/MC/MCFixup.h"
14 #include "llvm/MC/MCInst.h"
15 #include "llvm/ADT/DenseMap.h"
16 #include "llvm/ADT/SmallPtrSet.h"
17 #include "llvm/ADT/SmallString.h"
18 #include "llvm/ADT/ilist.h"
19 #include "llvm/ADT/ilist_node.h"
20 #include "llvm/Support/Casting.h"
21 #include "llvm/Support/DataTypes.h"
22 #include <vector> // FIXME: Shouldn't be needed.
40 class MCFragment : public ilist_node<MCFragment> {
41 friend class MCAsmLayout;
43 MCFragment(const MCFragment&); // DO NOT IMPLEMENT
44 void operator=(const MCFragment&); // DO NOT IMPLEMENT
61 /// Parent - The data for the section this fragment is in.
62 MCSectionData *Parent;
64 /// Atom - The atom this fragment is in, as represented by it's defining
65 /// symbol. Atom's are only used by backends which set
66 /// \see MCAsmBackend::hasReliableSymbolDifference().
69 /// @name Assembler Backend Data
72 // FIXME: This could all be kept private to the assembler implementation.
74 /// Offset - The offset of this fragment in its section. This is ~0 until
78 /// LayoutOrder - The layout order of this fragment.
84 MCFragment(FragmentType _Kind, MCSectionData *_Parent = 0);
89 virtual ~MCFragment();
91 FragmentType getKind() const { return Kind; }
93 MCSectionData *getParent() const { return Parent; }
94 void setParent(MCSectionData *Value) { Parent = Value; }
96 MCSymbolData *getAtom() const { return Atom; }
97 void setAtom(MCSymbolData *Value) { Atom = Value; }
99 unsigned getLayoutOrder() const { return LayoutOrder; }
100 void setLayoutOrder(unsigned Value) { LayoutOrder = Value; }
102 static bool classof(const MCFragment *O) { return true; }
107 class MCDataFragment : public MCFragment {
108 virtual void anchor();
109 SmallString<32> Contents;
111 /// Fixups - The list of fixups in this fragment.
112 std::vector<MCFixup> Fixups;
115 typedef std::vector<MCFixup>::const_iterator const_fixup_iterator;
116 typedef std::vector<MCFixup>::iterator fixup_iterator;
119 MCDataFragment(MCSectionData *SD = 0) : MCFragment(FT_Data, SD) {}
124 SmallString<32> &getContents() { return Contents; }
125 const SmallString<32> &getContents() const { return Contents; }
128 /// @name Fixup Access
131 void addFixup(MCFixup Fixup) {
132 // Enforce invariant that fixups are in offset order.
133 assert((Fixups.empty() || Fixup.getOffset() > Fixups.back().getOffset()) &&
134 "Fixups must be added in order!");
135 Fixups.push_back(Fixup);
138 std::vector<MCFixup> &getFixups() { return Fixups; }
139 const std::vector<MCFixup> &getFixups() const { return Fixups; }
141 fixup_iterator fixup_begin() { return Fixups.begin(); }
142 const_fixup_iterator fixup_begin() const { return Fixups.begin(); }
144 fixup_iterator fixup_end() {return Fixups.end();}
145 const_fixup_iterator fixup_end() const {return Fixups.end();}
147 size_t fixup_size() const { return Fixups.size(); }
151 static bool classof(const MCFragment *F) {
152 return F->getKind() == MCFragment::FT_Data;
154 static bool classof(const MCDataFragment *) { return true; }
157 // FIXME: This current incarnation of MCInstFragment doesn't make much sense, as
158 // it is almost entirely a duplicate of MCDataFragment. If we decide to stick
159 // with this approach (as opposed to making MCInstFragment a very light weight
160 // object with just the MCInst and a code size, then we should just change
161 // MCDataFragment to have an optional MCInst at its end.
162 class MCInstFragment : public MCFragment {
163 virtual void anchor();
165 /// Inst - The instruction this is a fragment for.
168 /// Code - Binary data for the currently encoded instruction.
171 /// Fixups - The list of fixups in this fragment.
172 SmallVector<MCFixup, 1> Fixups;
175 typedef SmallVectorImpl<MCFixup>::const_iterator const_fixup_iterator;
176 typedef SmallVectorImpl<MCFixup>::iterator fixup_iterator;
179 MCInstFragment(MCInst _Inst, MCSectionData *SD = 0)
180 : MCFragment(FT_Inst, SD), Inst(_Inst) {
186 SmallVectorImpl<char> &getCode() { return Code; }
187 const SmallVectorImpl<char> &getCode() const { return Code; }
189 unsigned getInstSize() const { return Code.size(); }
191 MCInst &getInst() { return Inst; }
192 const MCInst &getInst() const { return Inst; }
194 void setInst(MCInst Value) { Inst = Value; }
197 /// @name Fixup Access
200 SmallVectorImpl<MCFixup> &getFixups() { return Fixups; }
201 const SmallVectorImpl<MCFixup> &getFixups() const { return Fixups; }
203 fixup_iterator fixup_begin() { return Fixups.begin(); }
204 const_fixup_iterator fixup_begin() const { return Fixups.begin(); }
206 fixup_iterator fixup_end() {return Fixups.end();}
207 const_fixup_iterator fixup_end() const {return Fixups.end();}
209 size_t fixup_size() const { return Fixups.size(); }
213 static bool classof(const MCFragment *F) {
214 return F->getKind() == MCFragment::FT_Inst;
216 static bool classof(const MCInstFragment *) { return true; }
219 class MCAlignFragment : public MCFragment {
220 virtual void anchor();
222 /// Alignment - The alignment to ensure, in bytes.
225 /// Value - Value to use for filling padding bytes.
228 /// ValueSize - The size of the integer (in bytes) of \arg Value.
231 /// MaxBytesToEmit - The maximum number of bytes to emit; if the alignment
232 /// cannot be satisfied in this width then this fragment is ignored.
233 unsigned MaxBytesToEmit;
235 /// EmitNops - Flag to indicate that (optimal) NOPs should be emitted instead
236 /// of using the provided value. The exact interpretation of this flag is
237 /// target dependent.
241 MCAlignFragment(unsigned _Alignment, int64_t _Value, unsigned _ValueSize,
242 unsigned _MaxBytesToEmit, MCSectionData *SD = 0)
243 : MCFragment(FT_Align, SD), Alignment(_Alignment),
244 Value(_Value),ValueSize(_ValueSize),
245 MaxBytesToEmit(_MaxBytesToEmit), EmitNops(false) {}
250 unsigned getAlignment() const { return Alignment; }
252 int64_t getValue() const { return Value; }
254 unsigned getValueSize() const { return ValueSize; }
256 unsigned getMaxBytesToEmit() const { return MaxBytesToEmit; }
258 bool hasEmitNops() const { return EmitNops; }
259 void setEmitNops(bool Value) { EmitNops = Value; }
263 static bool classof(const MCFragment *F) {
264 return F->getKind() == MCFragment::FT_Align;
266 static bool classof(const MCAlignFragment *) { return true; }
269 class MCFillFragment : public MCFragment {
270 virtual void anchor();
272 /// Value - Value to use for filling bytes.
275 /// ValueSize - The size (in bytes) of \arg Value to use when filling, or 0 if
276 /// this is a virtual fill fragment.
279 /// Size - The number of bytes to insert.
283 MCFillFragment(int64_t _Value, unsigned _ValueSize, uint64_t _Size,
284 MCSectionData *SD = 0)
285 : MCFragment(FT_Fill, SD),
286 Value(_Value), ValueSize(_ValueSize), Size(_Size) {
287 assert((!ValueSize || (Size % ValueSize) == 0) &&
288 "Fill size must be a multiple of the value size!");
294 int64_t getValue() const { return Value; }
296 unsigned getValueSize() const { return ValueSize; }
298 uint64_t getSize() const { return Size; }
302 static bool classof(const MCFragment *F) {
303 return F->getKind() == MCFragment::FT_Fill;
305 static bool classof(const MCFillFragment *) { return true; }
308 class MCOrgFragment : public MCFragment {
309 virtual void anchor();
311 /// Offset - The offset this fragment should start at.
312 const MCExpr *Offset;
314 /// Value - Value to use for filling bytes.
318 MCOrgFragment(const MCExpr &_Offset, int8_t _Value, MCSectionData *SD = 0)
319 : MCFragment(FT_Org, SD),
320 Offset(&_Offset), Value(_Value) {}
325 const MCExpr &getOffset() const { return *Offset; }
327 uint8_t getValue() const { return Value; }
331 static bool classof(const MCFragment *F) {
332 return F->getKind() == MCFragment::FT_Org;
334 static bool classof(const MCOrgFragment *) { return true; }
337 class MCLEBFragment : public MCFragment {
338 virtual void anchor();
340 /// Value - The value this fragment should contain.
343 /// IsSigned - True if this is a sleb128, false if uleb128.
346 SmallString<8> Contents;
348 MCLEBFragment(const MCExpr &Value_, bool IsSigned_, MCSectionData *SD)
349 : MCFragment(FT_LEB, SD),
350 Value(&Value_), IsSigned(IsSigned_) { Contents.push_back(0); }
355 const MCExpr &getValue() const { return *Value; }
357 bool isSigned() const { return IsSigned; }
359 SmallString<8> &getContents() { return Contents; }
360 const SmallString<8> &getContents() const { return Contents; }
364 static bool classof(const MCFragment *F) {
365 return F->getKind() == MCFragment::FT_LEB;
367 static bool classof(const MCLEBFragment *) { return true; }
370 class MCDwarfLineAddrFragment : public MCFragment {
371 virtual void anchor();
373 /// LineDelta - the value of the difference between the two line numbers
374 /// between two .loc dwarf directives.
377 /// AddrDelta - The expression for the difference of the two symbols that
378 /// make up the address delta between two .loc dwarf directives.
379 const MCExpr *AddrDelta;
381 SmallString<8> Contents;
384 MCDwarfLineAddrFragment(int64_t _LineDelta, const MCExpr &_AddrDelta,
386 : MCFragment(FT_Dwarf, SD),
387 LineDelta(_LineDelta), AddrDelta(&_AddrDelta) { Contents.push_back(0); }
392 int64_t getLineDelta() const { return LineDelta; }
394 const MCExpr &getAddrDelta() const { return *AddrDelta; }
396 SmallString<8> &getContents() { return Contents; }
397 const SmallString<8> &getContents() const { return Contents; }
401 static bool classof(const MCFragment *F) {
402 return F->getKind() == MCFragment::FT_Dwarf;
404 static bool classof(const MCDwarfLineAddrFragment *) { return true; }
407 class MCDwarfCallFrameFragment : public MCFragment {
408 virtual void anchor();
410 /// AddrDelta - The expression for the difference of the two symbols that
411 /// make up the address delta between two .cfi_* dwarf directives.
412 const MCExpr *AddrDelta;
414 SmallString<8> Contents;
417 MCDwarfCallFrameFragment(const MCExpr &_AddrDelta, MCSectionData *SD)
418 : MCFragment(FT_DwarfFrame, SD),
419 AddrDelta(&_AddrDelta) { Contents.push_back(0); }
424 const MCExpr &getAddrDelta() const { return *AddrDelta; }
426 SmallString<8> &getContents() { return Contents; }
427 const SmallString<8> &getContents() const { return Contents; }
431 static bool classof(const MCFragment *F) {
432 return F->getKind() == MCFragment::FT_DwarfFrame;
434 static bool classof(const MCDwarfCallFrameFragment *) { return true; }
437 // FIXME: Should this be a separate class, or just merged into MCSection? Since
438 // we anticipate the fast path being through an MCAssembler, the only reason to
439 // keep it out is for API abstraction.
440 class MCSectionData : public ilist_node<MCSectionData> {
441 friend class MCAsmLayout;
443 MCSectionData(const MCSectionData&); // DO NOT IMPLEMENT
444 void operator=(const MCSectionData&); // DO NOT IMPLEMENT
447 typedef iplist<MCFragment> FragmentListType;
449 typedef FragmentListType::const_iterator const_iterator;
450 typedef FragmentListType::iterator iterator;
452 typedef FragmentListType::const_reverse_iterator const_reverse_iterator;
453 typedef FragmentListType::reverse_iterator reverse_iterator;
456 FragmentListType Fragments;
457 const MCSection *Section;
459 /// Ordinal - The section index in the assemblers section list.
462 /// LayoutOrder - The index of this section in the layout order.
463 unsigned LayoutOrder;
465 /// Alignment - The maximum alignment seen in this section.
468 /// @name Assembler Backend Data
471 // FIXME: This could all be kept private to the assembler implementation.
473 /// HasInstructions - Whether this section has had instructions emitted into
475 unsigned HasInstructions : 1;
480 // Only for use as sentinel.
482 MCSectionData(const MCSection &Section, MCAssembler *A = 0);
484 const MCSection &getSection() const { return *Section; }
486 unsigned getAlignment() const { return Alignment; }
487 void setAlignment(unsigned Value) { Alignment = Value; }
489 bool hasInstructions() const { return HasInstructions; }
490 void setHasInstructions(bool Value) { HasInstructions = Value; }
492 unsigned getOrdinal() const { return Ordinal; }
493 void setOrdinal(unsigned Value) { Ordinal = Value; }
495 unsigned getLayoutOrder() const { return LayoutOrder; }
496 void setLayoutOrder(unsigned Value) { LayoutOrder = Value; }
498 /// @name Fragment Access
501 const FragmentListType &getFragmentList() const { return Fragments; }
502 FragmentListType &getFragmentList() { return Fragments; }
504 iterator begin() { return Fragments.begin(); }
505 const_iterator begin() const { return Fragments.begin(); }
507 iterator end() { return Fragments.end(); }
508 const_iterator end() const { return Fragments.end(); }
510 reverse_iterator rbegin() { return Fragments.rbegin(); }
511 const_reverse_iterator rbegin() const { return Fragments.rbegin(); }
513 reverse_iterator rend() { return Fragments.rend(); }
514 const_reverse_iterator rend() const { return Fragments.rend(); }
516 size_t size() const { return Fragments.size(); }
518 bool empty() const { return Fragments.empty(); }
525 // FIXME: Same concerns as with SectionData.
526 class MCSymbolData : public ilist_node<MCSymbolData> {
528 const MCSymbol *Symbol;
530 /// Fragment - The fragment this symbol's value is relative to, if any.
531 MCFragment *Fragment;
533 /// Offset - The offset to apply to the fragment address to form this symbol's
537 /// IsExternal - True if this symbol is visible outside this translation
539 unsigned IsExternal : 1;
541 /// IsPrivateExtern - True if this symbol is private extern.
542 unsigned IsPrivateExtern : 1;
544 /// CommonSize - The size of the symbol, if it is 'common', or 0.
546 // FIXME: Pack this in with other fields? We could put it in offset, since a
547 // common symbol can never get a definition.
550 /// SymbolSize - An expression describing how to calculate the size of
551 /// a symbol. If a symbol has no size this field will be NULL.
552 const MCExpr *SymbolSize;
554 /// CommonAlign - The alignment of the symbol, if it is 'common'.
556 // FIXME: Pack this in with other fields?
557 unsigned CommonAlign;
559 /// Flags - The Flags field is used by object file implementations to store
560 /// additional per symbol information which is not easily classified.
563 /// Index - Index field, for use by the object file implementation.
567 // Only for use as sentinel.
569 MCSymbolData(const MCSymbol &_Symbol, MCFragment *_Fragment, uint64_t _Offset,
575 const MCSymbol &getSymbol() const { return *Symbol; }
577 MCFragment *getFragment() const { return Fragment; }
578 void setFragment(MCFragment *Value) { Fragment = Value; }
580 uint64_t getOffset() const { return Offset; }
581 void setOffset(uint64_t Value) { Offset = Value; }
584 /// @name Symbol Attributes
587 bool isExternal() const { return IsExternal; }
588 void setExternal(bool Value) { IsExternal = Value; }
590 bool isPrivateExtern() const { return IsPrivateExtern; }
591 void setPrivateExtern(bool Value) { IsPrivateExtern = Value; }
593 /// isCommon - Is this a 'common' symbol.
594 bool isCommon() const { return CommonSize != 0; }
596 /// setCommon - Mark this symbol as being 'common'.
598 /// \param Size - The size of the symbol.
599 /// \param Align - The alignment of the symbol.
600 void setCommon(uint64_t Size, unsigned Align) {
605 /// getCommonSize - Return the size of a 'common' symbol.
606 uint64_t getCommonSize() const {
607 assert(isCommon() && "Not a 'common' symbol!");
611 void setSize(const MCExpr *SS) {
615 const MCExpr *getSize() const {
620 /// getCommonAlignment - Return the alignment of a 'common' symbol.
621 unsigned getCommonAlignment() const {
622 assert(isCommon() && "Not a 'common' symbol!");
626 /// getFlags - Get the (implementation defined) symbol flags.
627 uint32_t getFlags() const { return Flags; }
629 /// setFlags - Set the (implementation defined) symbol flags.
630 void setFlags(uint32_t Value) { Flags = Value; }
632 /// modifyFlags - Modify the flags via a mask
633 void modifyFlags(uint32_t Value, uint32_t Mask) {
634 Flags = (Flags & ~Mask) | Value;
637 /// getIndex - Get the (implementation defined) index.
638 uint64_t getIndex() const { return Index; }
640 /// setIndex - Set the (implementation defined) index.
641 void setIndex(uint64_t Value) { Index = Value; }
648 // FIXME: This really doesn't belong here. See comments below.
649 struct IndirectSymbolData {
651 MCSectionData *SectionData;
655 friend class MCAsmLayout;
658 typedef iplist<MCSectionData> SectionDataListType;
659 typedef iplist<MCSymbolData> SymbolDataListType;
661 typedef SectionDataListType::const_iterator const_iterator;
662 typedef SectionDataListType::iterator iterator;
664 typedef SymbolDataListType::const_iterator const_symbol_iterator;
665 typedef SymbolDataListType::iterator symbol_iterator;
667 typedef std::vector<IndirectSymbolData>::const_iterator
668 const_indirect_symbol_iterator;
669 typedef std::vector<IndirectSymbolData>::iterator indirect_symbol_iterator;
672 MCAssembler(const MCAssembler&); // DO NOT IMPLEMENT
673 void operator=(const MCAssembler&); // DO NOT IMPLEMENT
677 MCAsmBackend &Backend;
679 MCCodeEmitter &Emitter;
681 MCObjectWriter &Writer;
685 iplist<MCSectionData> Sections;
687 iplist<MCSymbolData> Symbols;
689 /// The map of sections to their associated assembler backend data.
691 // FIXME: Avoid this indirection?
692 DenseMap<const MCSection*, MCSectionData*> SectionMap;
694 /// The map of symbols to their associated assembler backend data.
696 // FIXME: Avoid this indirection?
697 DenseMap<const MCSymbol*, MCSymbolData*> SymbolMap;
699 std::vector<IndirectSymbolData> IndirectSymbols;
701 /// The set of function symbols for which a .thumb_func directive has
704 // FIXME: We really would like this in target specific code rather than
705 // here. Maybe when the relocation stuff moves to target specific,
706 // this can go with it? The streamer would need some target specific
708 SmallPtrSet<const MCSymbol*, 64> ThumbFuncs;
710 unsigned RelaxAll : 1;
711 unsigned NoExecStack : 1;
712 unsigned SubsectionsViaSymbols : 1;
715 /// Evaluate a fixup to a relocatable expression and the value which should be
716 /// placed into the fixup.
718 /// \param Layout The layout to use for evaluation.
719 /// \param Fixup The fixup to evaluate.
720 /// \param DF The fragment the fixup is inside.
721 /// \param Target [out] On return, the relocatable expression the fixup
723 /// \param Value [out] On return, the value of the fixup as currently laid
725 /// \return Whether the fixup value was fully resolved. This is true if the
726 /// \arg Value result is fixed, otherwise the value may change due to
728 bool evaluateFixup(const MCAsmLayout &Layout,
729 const MCFixup &Fixup, const MCFragment *DF,
730 MCValue &Target, uint64_t &Value) const;
732 /// Check whether a fixup can be satisfied, or whether it needs to be relaxed
733 /// (increased in size, in order to hold its value correctly).
734 bool fixupNeedsRelaxation(const MCFixup &Fixup, const MCInstFragment *DF,
735 const MCAsmLayout &Layout) const;
737 /// Check whether the given fragment needs relaxation.
738 bool fragmentNeedsRelaxation(const MCInstFragment *IF,
739 const MCAsmLayout &Layout) const;
741 /// layoutOnce - Perform one layout iteration and return true if any offsets
743 bool layoutOnce(MCAsmLayout &Layout);
745 bool layoutSectionOnce(MCAsmLayout &Layout, MCSectionData &SD);
747 bool relaxInstruction(MCAsmLayout &Layout, MCInstFragment &IF);
749 bool relaxLEB(MCAsmLayout &Layout, MCLEBFragment &IF);
751 bool relaxDwarfLineAddr(MCAsmLayout &Layout, MCDwarfLineAddrFragment &DF);
752 bool relaxDwarfCallFrameFragment(MCAsmLayout &Layout,
753 MCDwarfCallFrameFragment &DF);
755 /// finishLayout - Finalize a layout, including fragment lowering.
756 void finishLayout(MCAsmLayout &Layout);
758 uint64_t handleFixup(const MCAsmLayout &Layout,
759 MCFragment &F, const MCFixup &Fixup);
762 /// Compute the effective fragment size assuming it is laid out at the given
763 /// \arg SectionAddress and \arg FragmentOffset.
764 uint64_t computeFragmentSize(const MCAsmLayout &Layout,
765 const MCFragment &F) const;
767 /// Find the symbol which defines the atom containing the given symbol, or
768 /// null if there is no such symbol.
769 const MCSymbolData *getAtom(const MCSymbolData *Symbol) const;
771 /// Check whether a particular symbol is visible to the linker and is required
772 /// in the symbol table, or whether it can be discarded by the assembler. This
773 /// also effects whether the assembler treats the label as potentially
774 /// defining a separate atom.
775 bool isSymbolLinkerVisible(const MCSymbol &SD) const;
777 /// Emit the section contents using the given object writer.
778 void writeSectionData(const MCSectionData *Section,
779 const MCAsmLayout &Layout) const;
781 /// Check whether a given symbol has been flagged with .thumb_func.
782 bool isThumbFunc(const MCSymbol *Func) const {
783 return ThumbFuncs.count(Func);
786 /// Flag a function symbol as the target of a .thumb_func directive.
787 void setIsThumbFunc(const MCSymbol *Func) { ThumbFuncs.insert(Func); }
790 /// Construct a new assembler instance.
792 /// \arg OS - The stream to output to.
794 // FIXME: How are we going to parameterize this? Two obvious options are stay
795 // concrete and require clients to pass in a target like object. The other
796 // option is to make this abstract, and have targets provide concrete
797 // implementations as we do with AsmParser.
798 MCAssembler(MCContext &Context_, MCAsmBackend &Backend_,
799 MCCodeEmitter &Emitter_, MCObjectWriter &Writer_,
803 MCContext &getContext() const { return Context; }
805 MCAsmBackend &getBackend() const { return Backend; }
807 MCCodeEmitter &getEmitter() const { return Emitter; }
809 MCObjectWriter &getWriter() const { return Writer; }
811 /// Finish - Do final processing and write the object to the output stream.
812 /// \arg Writer is used for custom object writer (as the MCJIT does),
813 /// if not specified it is automatically created from backend.
816 // FIXME: This does not belong here.
817 bool getSubsectionsViaSymbols() const {
818 return SubsectionsViaSymbols;
820 void setSubsectionsViaSymbols(bool Value) {
821 SubsectionsViaSymbols = Value;
824 bool getRelaxAll() const { return RelaxAll; }
825 void setRelaxAll(bool Value) { RelaxAll = Value; }
827 bool getNoExecStack() const { return NoExecStack; }
828 void setNoExecStack(bool Value) { NoExecStack = Value; }
830 /// @name Section List Access
833 const SectionDataListType &getSectionList() const { return Sections; }
834 SectionDataListType &getSectionList() { return Sections; }
836 iterator begin() { return Sections.begin(); }
837 const_iterator begin() const { return Sections.begin(); }
839 iterator end() { return Sections.end(); }
840 const_iterator end() const { return Sections.end(); }
842 size_t size() const { return Sections.size(); }
845 /// @name Symbol List Access
848 const SymbolDataListType &getSymbolList() const { return Symbols; }
849 SymbolDataListType &getSymbolList() { return Symbols; }
851 symbol_iterator symbol_begin() { return Symbols.begin(); }
852 const_symbol_iterator symbol_begin() const { return Symbols.begin(); }
854 symbol_iterator symbol_end() { return Symbols.end(); }
855 const_symbol_iterator symbol_end() const { return Symbols.end(); }
857 size_t symbol_size() const { return Symbols.size(); }
860 /// @name Indirect Symbol List Access
863 // FIXME: This is a total hack, this should not be here. Once things are
864 // factored so that the streamer has direct access to the .o writer, it can
866 std::vector<IndirectSymbolData> &getIndirectSymbols() {
867 return IndirectSymbols;
870 indirect_symbol_iterator indirect_symbol_begin() {
871 return IndirectSymbols.begin();
873 const_indirect_symbol_iterator indirect_symbol_begin() const {
874 return IndirectSymbols.begin();
877 indirect_symbol_iterator indirect_symbol_end() {
878 return IndirectSymbols.end();
880 const_indirect_symbol_iterator indirect_symbol_end() const {
881 return IndirectSymbols.end();
884 size_t indirect_symbol_size() const { return IndirectSymbols.size(); }
887 /// @name Backend Data Access
890 MCSectionData &getSectionData(const MCSection &Section) const {
891 MCSectionData *Entry = SectionMap.lookup(&Section);
892 assert(Entry && "Missing section data!");
896 MCSectionData &getOrCreateSectionData(const MCSection &Section,
898 MCSectionData *&Entry = SectionMap[&Section];
900 if (Created) *Created = !Entry;
902 Entry = new MCSectionData(Section, this);
907 MCSymbolData &getSymbolData(const MCSymbol &Symbol) const {
908 MCSymbolData *Entry = SymbolMap.lookup(&Symbol);
909 assert(Entry && "Missing symbol data!");
913 MCSymbolData &getOrCreateSymbolData(const MCSymbol &Symbol,
915 MCSymbolData *&Entry = SymbolMap[&Symbol];
917 if (Created) *Created = !Entry;
919 Entry = new MCSymbolData(Symbol, 0, 0, this);
929 } // end namespace llvm