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.
41 class MCFragment : public ilist_node<MCFragment> {
42 friend class MCAsmLayout;
44 MCFragment(const MCFragment&); // DO NOT IMPLEMENT
45 void operator=(const MCFragment&); // DO NOT IMPLEMENT
62 /// Parent - The data for the section this fragment is in.
63 MCSectionData *Parent;
65 /// Atom - The atom this fragment is in, as represented by it's defining
66 /// symbol. Atom's are only used by backends which set
67 /// \see MCAsmBackend::hasReliableSymbolDifference().
70 /// @name Assembler Backend Data
73 // FIXME: This could all be kept private to the assembler implementation.
75 /// Offset - The offset of this fragment in its section. This is ~0 until
79 /// LayoutOrder - The layout order of this fragment.
85 MCFragment(FragmentType _Kind, MCSectionData *_Parent = 0);
90 virtual ~MCFragment();
92 FragmentType getKind() const { return Kind; }
94 MCSectionData *getParent() const { return Parent; }
95 void setParent(MCSectionData *Value) { Parent = Value; }
97 MCSymbolData *getAtom() const { return Atom; }
98 void setAtom(MCSymbolData *Value) { Atom = Value; }
100 unsigned getLayoutOrder() const { return LayoutOrder; }
101 void setLayoutOrder(unsigned Value) { LayoutOrder = Value; }
103 static bool classof(const MCFragment *O) { return true; }
108 class MCDataFragment : public MCFragment {
109 virtual void anchor();
110 SmallString<32> Contents;
112 /// Fixups - The list of fixups in this fragment.
113 std::vector<MCFixup> Fixups;
116 typedef std::vector<MCFixup>::const_iterator const_fixup_iterator;
117 typedef std::vector<MCFixup>::iterator fixup_iterator;
120 MCDataFragment(MCSectionData *SD = 0) : MCFragment(FT_Data, SD) {}
125 SmallString<32> &getContents() { return Contents; }
126 const SmallString<32> &getContents() const { return Contents; }
129 /// @name Fixup Access
132 void addFixup(MCFixup Fixup) {
133 // Enforce invariant that fixups are in offset order.
134 assert((Fixups.empty() || Fixup.getOffset() > Fixups.back().getOffset()) &&
135 "Fixups must be added in order!");
136 Fixups.push_back(Fixup);
139 std::vector<MCFixup> &getFixups() { return Fixups; }
140 const std::vector<MCFixup> &getFixups() const { return Fixups; }
142 fixup_iterator fixup_begin() { return Fixups.begin(); }
143 const_fixup_iterator fixup_begin() const { return Fixups.begin(); }
145 fixup_iterator fixup_end() {return Fixups.end();}
146 const_fixup_iterator fixup_end() const {return Fixups.end();}
148 size_t fixup_size() const { return Fixups.size(); }
152 static bool classof(const MCFragment *F) {
153 return F->getKind() == MCFragment::FT_Data;
155 static bool classof(const MCDataFragment *) { return true; }
158 // FIXME: This current incarnation of MCInstFragment doesn't make much sense, as
159 // it is almost entirely a duplicate of MCDataFragment. If we decide to stick
160 // with this approach (as opposed to making MCInstFragment a very light weight
161 // object with just the MCInst and a code size, then we should just change
162 // MCDataFragment to have an optional MCInst at its end.
163 class MCInstFragment : public MCFragment {
164 virtual void anchor();
166 /// Inst - The instruction this is a fragment for.
169 /// Code - Binary data for the currently encoded instruction.
172 /// Fixups - The list of fixups in this fragment.
173 SmallVector<MCFixup, 1> Fixups;
176 typedef SmallVectorImpl<MCFixup>::const_iterator const_fixup_iterator;
177 typedef SmallVectorImpl<MCFixup>::iterator fixup_iterator;
180 MCInstFragment(MCInst _Inst, MCSectionData *SD = 0)
181 : MCFragment(FT_Inst, SD), Inst(_Inst) {
187 SmallVectorImpl<char> &getCode() { return Code; }
188 const SmallVectorImpl<char> &getCode() const { return Code; }
190 unsigned getInstSize() const { return Code.size(); }
192 MCInst &getInst() { return Inst; }
193 const MCInst &getInst() const { return Inst; }
195 void setInst(MCInst Value) { Inst = Value; }
198 /// @name Fixup Access
201 SmallVectorImpl<MCFixup> &getFixups() { return Fixups; }
202 const SmallVectorImpl<MCFixup> &getFixups() const { return Fixups; }
204 fixup_iterator fixup_begin() { return Fixups.begin(); }
205 const_fixup_iterator fixup_begin() const { return Fixups.begin(); }
207 fixup_iterator fixup_end() {return Fixups.end();}
208 const_fixup_iterator fixup_end() const {return Fixups.end();}
210 size_t fixup_size() const { return Fixups.size(); }
214 static bool classof(const MCFragment *F) {
215 return F->getKind() == MCFragment::FT_Inst;
217 static bool classof(const MCInstFragment *) { return true; }
220 class MCAlignFragment : public MCFragment {
221 virtual void anchor();
223 /// Alignment - The alignment to ensure, in bytes.
226 /// Value - Value to use for filling padding bytes.
229 /// ValueSize - The size of the integer (in bytes) of \arg Value.
232 /// MaxBytesToEmit - The maximum number of bytes to emit; if the alignment
233 /// cannot be satisfied in this width then this fragment is ignored.
234 unsigned MaxBytesToEmit;
236 /// EmitNops - Flag to indicate that (optimal) NOPs should be emitted instead
237 /// of using the provided value. The exact interpretation of this flag is
238 /// target dependent.
242 MCAlignFragment(unsigned _Alignment, int64_t _Value, unsigned _ValueSize,
243 unsigned _MaxBytesToEmit, MCSectionData *SD = 0)
244 : MCFragment(FT_Align, SD), Alignment(_Alignment),
245 Value(_Value),ValueSize(_ValueSize),
246 MaxBytesToEmit(_MaxBytesToEmit), EmitNops(false) {}
251 unsigned getAlignment() const { return Alignment; }
253 int64_t getValue() const { return Value; }
255 unsigned getValueSize() const { return ValueSize; }
257 unsigned getMaxBytesToEmit() const { return MaxBytesToEmit; }
259 bool hasEmitNops() const { return EmitNops; }
260 void setEmitNops(bool Value) { EmitNops = Value; }
264 static bool classof(const MCFragment *F) {
265 return F->getKind() == MCFragment::FT_Align;
267 static bool classof(const MCAlignFragment *) { return true; }
270 class MCFillFragment : public MCFragment {
271 virtual void anchor();
273 /// Value - Value to use for filling bytes.
276 /// ValueSize - The size (in bytes) of \arg Value to use when filling, or 0 if
277 /// this is a virtual fill fragment.
280 /// Size - The number of bytes to insert.
284 MCFillFragment(int64_t _Value, unsigned _ValueSize, uint64_t _Size,
285 MCSectionData *SD = 0)
286 : MCFragment(FT_Fill, SD),
287 Value(_Value), ValueSize(_ValueSize), Size(_Size) {
288 assert((!ValueSize || (Size % ValueSize) == 0) &&
289 "Fill size must be a multiple of the value size!");
295 int64_t getValue() const { return Value; }
297 unsigned getValueSize() const { return ValueSize; }
299 uint64_t getSize() const { return Size; }
303 static bool classof(const MCFragment *F) {
304 return F->getKind() == MCFragment::FT_Fill;
306 static bool classof(const MCFillFragment *) { return true; }
309 class MCOrgFragment : public MCFragment {
310 virtual void anchor();
312 /// Offset - The offset this fragment should start at.
313 const MCExpr *Offset;
315 /// Value - Value to use for filling bytes.
319 MCOrgFragment(const MCExpr &_Offset, int8_t _Value, MCSectionData *SD = 0)
320 : MCFragment(FT_Org, SD),
321 Offset(&_Offset), Value(_Value) {}
326 const MCExpr &getOffset() const { return *Offset; }
328 uint8_t getValue() const { return Value; }
332 static bool classof(const MCFragment *F) {
333 return F->getKind() == MCFragment::FT_Org;
335 static bool classof(const MCOrgFragment *) { return true; }
338 class MCLEBFragment : public MCFragment {
339 virtual void anchor();
341 /// Value - The value this fragment should contain.
344 /// IsSigned - True if this is a sleb128, false if uleb128.
347 SmallString<8> Contents;
349 MCLEBFragment(const MCExpr &Value_, bool IsSigned_, MCSectionData *SD)
350 : MCFragment(FT_LEB, SD),
351 Value(&Value_), IsSigned(IsSigned_) { Contents.push_back(0); }
356 const MCExpr &getValue() const { return *Value; }
358 bool isSigned() const { return IsSigned; }
360 SmallString<8> &getContents() { return Contents; }
361 const SmallString<8> &getContents() const { return Contents; }
365 static bool classof(const MCFragment *F) {
366 return F->getKind() == MCFragment::FT_LEB;
368 static bool classof(const MCLEBFragment *) { return true; }
371 class MCDwarfLineAddrFragment : public MCFragment {
372 virtual void anchor();
374 /// LineDelta - the value of the difference between the two line numbers
375 /// between two .loc dwarf directives.
378 /// AddrDelta - The expression for the difference of the two symbols that
379 /// make up the address delta between two .loc dwarf directives.
380 const MCExpr *AddrDelta;
382 SmallString<8> Contents;
385 MCDwarfLineAddrFragment(int64_t _LineDelta, const MCExpr &_AddrDelta,
387 : MCFragment(FT_Dwarf, SD),
388 LineDelta(_LineDelta), AddrDelta(&_AddrDelta) { Contents.push_back(0); }
393 int64_t getLineDelta() const { return LineDelta; }
395 const MCExpr &getAddrDelta() const { return *AddrDelta; }
397 SmallString<8> &getContents() { return Contents; }
398 const SmallString<8> &getContents() const { return Contents; }
402 static bool classof(const MCFragment *F) {
403 return F->getKind() == MCFragment::FT_Dwarf;
405 static bool classof(const MCDwarfLineAddrFragment *) { return true; }
408 class MCDwarfCallFrameFragment : public MCFragment {
409 virtual void anchor();
411 /// AddrDelta - The expression for the difference of the two symbols that
412 /// make up the address delta between two .cfi_* dwarf directives.
413 const MCExpr *AddrDelta;
415 SmallString<8> Contents;
418 MCDwarfCallFrameFragment(const MCExpr &_AddrDelta, MCSectionData *SD)
419 : MCFragment(FT_DwarfFrame, SD),
420 AddrDelta(&_AddrDelta) { Contents.push_back(0); }
425 const MCExpr &getAddrDelta() const { return *AddrDelta; }
427 SmallString<8> &getContents() { return Contents; }
428 const SmallString<8> &getContents() const { return Contents; }
432 static bool classof(const MCFragment *F) {
433 return F->getKind() == MCFragment::FT_DwarfFrame;
435 static bool classof(const MCDwarfCallFrameFragment *) { return true; }
438 // FIXME: Should this be a separate class, or just merged into MCSection? Since
439 // we anticipate the fast path being through an MCAssembler, the only reason to
440 // keep it out is for API abstraction.
441 class MCSectionData : public ilist_node<MCSectionData> {
442 friend class MCAsmLayout;
444 MCSectionData(const MCSectionData&); // DO NOT IMPLEMENT
445 void operator=(const MCSectionData&); // DO NOT IMPLEMENT
448 typedef iplist<MCFragment> FragmentListType;
450 typedef FragmentListType::const_iterator const_iterator;
451 typedef FragmentListType::iterator iterator;
453 typedef FragmentListType::const_reverse_iterator const_reverse_iterator;
454 typedef FragmentListType::reverse_iterator reverse_iterator;
457 FragmentListType Fragments;
458 const MCSection *Section;
460 /// Ordinal - The section index in the assemblers section list.
463 /// LayoutOrder - The index of this section in the layout order.
464 unsigned LayoutOrder;
466 /// Alignment - The maximum alignment seen in this section.
469 /// @name Assembler Backend Data
472 // FIXME: This could all be kept private to the assembler implementation.
474 /// HasInstructions - Whether this section has had instructions emitted into
476 unsigned HasInstructions : 1;
481 // Only for use as sentinel.
483 MCSectionData(const MCSection &Section, MCAssembler *A = 0);
485 const MCSection &getSection() const { return *Section; }
487 unsigned getAlignment() const { return Alignment; }
488 void setAlignment(unsigned Value) { Alignment = Value; }
490 bool hasInstructions() const { return HasInstructions; }
491 void setHasInstructions(bool Value) { HasInstructions = Value; }
493 unsigned getOrdinal() const { return Ordinal; }
494 void setOrdinal(unsigned Value) { Ordinal = Value; }
496 unsigned getLayoutOrder() const { return LayoutOrder; }
497 void setLayoutOrder(unsigned Value) { LayoutOrder = Value; }
499 /// @name Fragment Access
502 const FragmentListType &getFragmentList() const { return Fragments; }
503 FragmentListType &getFragmentList() { return Fragments; }
505 iterator begin() { return Fragments.begin(); }
506 const_iterator begin() const { return Fragments.begin(); }
508 iterator end() { return Fragments.end(); }
509 const_iterator end() const { return Fragments.end(); }
511 reverse_iterator rbegin() { return Fragments.rbegin(); }
512 const_reverse_iterator rbegin() const { return Fragments.rbegin(); }
514 reverse_iterator rend() { return Fragments.rend(); }
515 const_reverse_iterator rend() const { return Fragments.rend(); }
517 size_t size() const { return Fragments.size(); }
519 bool empty() const { return Fragments.empty(); }
526 // FIXME: Same concerns as with SectionData.
527 class MCSymbolData : public ilist_node<MCSymbolData> {
529 const MCSymbol *Symbol;
531 /// Fragment - The fragment this symbol's value is relative to, if any.
532 MCFragment *Fragment;
534 /// Offset - The offset to apply to the fragment address to form this symbol's
538 /// IsExternal - True if this symbol is visible outside this translation
540 unsigned IsExternal : 1;
542 /// IsPrivateExtern - True if this symbol is private extern.
543 unsigned IsPrivateExtern : 1;
545 /// CommonSize - The size of the symbol, if it is 'common', or 0.
547 // FIXME: Pack this in with other fields? We could put it in offset, since a
548 // common symbol can never get a definition.
551 /// SymbolSize - An expression describing how to calculate the size of
552 /// a symbol. If a symbol has no size this field will be NULL.
553 const MCExpr *SymbolSize;
555 /// CommonAlign - The alignment of the symbol, if it is 'common'.
557 // FIXME: Pack this in with other fields?
558 unsigned CommonAlign;
560 /// Flags - The Flags field is used by object file implementations to store
561 /// additional per symbol information which is not easily classified.
564 /// Index - Index field, for use by the object file implementation.
568 // Only for use as sentinel.
570 MCSymbolData(const MCSymbol &_Symbol, MCFragment *_Fragment, uint64_t _Offset,
576 const MCSymbol &getSymbol() const { return *Symbol; }
578 MCFragment *getFragment() const { return Fragment; }
579 void setFragment(MCFragment *Value) { Fragment = Value; }
581 uint64_t getOffset() const { return Offset; }
582 void setOffset(uint64_t Value) { Offset = Value; }
585 /// @name Symbol Attributes
588 bool isExternal() const { return IsExternal; }
589 void setExternal(bool Value) { IsExternal = Value; }
591 bool isPrivateExtern() const { return IsPrivateExtern; }
592 void setPrivateExtern(bool Value) { IsPrivateExtern = Value; }
594 /// isCommon - Is this a 'common' symbol.
595 bool isCommon() const { return CommonSize != 0; }
597 /// setCommon - Mark this symbol as being 'common'.
599 /// \param Size - The size of the symbol.
600 /// \param Align - The alignment of the symbol.
601 void setCommon(uint64_t Size, unsigned Align) {
606 /// getCommonSize - Return the size of a 'common' symbol.
607 uint64_t getCommonSize() const {
608 assert(isCommon() && "Not a 'common' symbol!");
612 void setSize(const MCExpr *SS) {
616 const MCExpr *getSize() const {
621 /// getCommonAlignment - Return the alignment of a 'common' symbol.
622 unsigned getCommonAlignment() const {
623 assert(isCommon() && "Not a 'common' symbol!");
627 /// getFlags - Get the (implementation defined) symbol flags.
628 uint32_t getFlags() const { return Flags; }
630 /// setFlags - Set the (implementation defined) symbol flags.
631 void setFlags(uint32_t Value) { Flags = Value; }
633 /// modifyFlags - Modify the flags via a mask
634 void modifyFlags(uint32_t Value, uint32_t Mask) {
635 Flags = (Flags & ~Mask) | Value;
638 /// getIndex - Get the (implementation defined) index.
639 uint64_t getIndex() const { return Index; }
641 /// setIndex - Set the (implementation defined) index.
642 void setIndex(uint64_t Value) { Index = Value; }
649 // FIXME: This really doesn't belong here. See comments below.
650 struct IndirectSymbolData {
652 MCSectionData *SectionData;
656 friend class MCAsmLayout;
659 typedef iplist<MCSectionData> SectionDataListType;
660 typedef iplist<MCSymbolData> SymbolDataListType;
662 typedef SectionDataListType::const_iterator const_iterator;
663 typedef SectionDataListType::iterator iterator;
665 typedef SymbolDataListType::const_iterator const_symbol_iterator;
666 typedef SymbolDataListType::iterator symbol_iterator;
668 typedef std::vector<IndirectSymbolData>::const_iterator
669 const_indirect_symbol_iterator;
670 typedef std::vector<IndirectSymbolData>::iterator indirect_symbol_iterator;
673 MCAssembler(const MCAssembler&); // DO NOT IMPLEMENT
674 void operator=(const MCAssembler&); // DO NOT IMPLEMENT
678 MCAsmBackend &Backend;
680 MCCodeEmitter &Emitter;
682 MCObjectWriter &Writer;
686 iplist<MCSectionData> Sections;
688 iplist<MCSymbolData> Symbols;
690 /// The map of sections to their associated assembler backend data.
692 // FIXME: Avoid this indirection?
693 DenseMap<const MCSection*, MCSectionData*> SectionMap;
695 /// The map of symbols to their associated assembler backend data.
697 // FIXME: Avoid this indirection?
698 DenseMap<const MCSymbol*, MCSymbolData*> SymbolMap;
700 std::vector<IndirectSymbolData> IndirectSymbols;
702 /// The set of function symbols for which a .thumb_func directive has
705 // FIXME: We really would like this in target specific code rather than
706 // here. Maybe when the relocation stuff moves to target specific,
707 // this can go with it? The streamer would need some target specific
709 SmallPtrSet<const MCSymbol*, 64> ThumbFuncs;
711 unsigned RelaxAll : 1;
712 unsigned NoExecStack : 1;
713 unsigned SubsectionsViaSymbols : 1;
716 /// Evaluate a fixup to a relocatable expression and the value which should be
717 /// placed into the fixup.
719 /// \param Layout The layout to use for evaluation.
720 /// \param Fixup The fixup to evaluate.
721 /// \param DF The fragment the fixup is inside.
722 /// \param Target [out] On return, the relocatable expression the fixup
724 /// \param Value [out] On return, the value of the fixup as currently laid
726 /// \return Whether the fixup value was fully resolved. This is true if the
727 /// \arg Value result is fixed, otherwise the value may change due to
729 bool evaluateFixup(const MCAsmLayout &Layout,
730 const MCFixup &Fixup, const MCFragment *DF,
731 MCValue &Target, uint64_t &Value) const;
733 /// Check whether a fixup can be satisfied, or whether it needs to be relaxed
734 /// (increased in size, in order to hold its value correctly).
735 bool fixupNeedsRelaxation(const MCFixup &Fixup, const MCInstFragment *DF,
736 const MCAsmLayout &Layout) const;
738 /// Check whether the given fragment needs relaxation.
739 bool fragmentNeedsRelaxation(const MCInstFragment *IF,
740 const MCAsmLayout &Layout) const;
742 /// layoutOnce - Perform one layout iteration and return true if any offsets
744 bool layoutOnce(MCAsmLayout &Layout);
746 bool layoutSectionOnce(MCAsmLayout &Layout, MCSectionData &SD);
748 bool relaxInstruction(MCAsmLayout &Layout, MCInstFragment &IF);
750 bool relaxLEB(MCAsmLayout &Layout, MCLEBFragment &IF);
752 bool relaxDwarfLineAddr(MCAsmLayout &Layout, MCDwarfLineAddrFragment &DF);
753 bool relaxDwarfCallFrameFragment(MCAsmLayout &Layout,
754 MCDwarfCallFrameFragment &DF);
756 /// finishLayout - Finalize a layout, including fragment lowering.
757 void finishLayout(MCAsmLayout &Layout);
759 uint64_t handleFixup(const MCAsmLayout &Layout,
760 MCFragment &F, const MCFixup &Fixup);
763 /// Compute the effective fragment size assuming it is laid out at the given
764 /// \arg SectionAddress and \arg FragmentOffset.
765 uint64_t computeFragmentSize(const MCAsmLayout &Layout,
766 const MCFragment &F) const;
768 /// Find the symbol which defines the atom containing the given symbol, or
769 /// null if there is no such symbol.
770 const MCSymbolData *getAtom(const MCSymbolData *Symbol) const;
772 /// Check whether a particular symbol is visible to the linker and is required
773 /// in the symbol table, or whether it can be discarded by the assembler. This
774 /// also effects whether the assembler treats the label as potentially
775 /// defining a separate atom.
776 bool isSymbolLinkerVisible(const MCSymbol &SD) const;
778 /// Emit the section contents using the given object writer.
779 void writeSectionData(const MCSectionData *Section,
780 const MCAsmLayout &Layout) const;
782 /// Check whether a given symbol has been flagged with .thumb_func.
783 bool isThumbFunc(const MCSymbol *Func) const {
784 return ThumbFuncs.count(Func);
787 /// Flag a function symbol as the target of a .thumb_func directive.
788 void setIsThumbFunc(const MCSymbol *Func) { ThumbFuncs.insert(Func); }
791 /// Construct a new assembler instance.
793 /// \arg OS - The stream to output to.
795 // FIXME: How are we going to parameterize this? Two obvious options are stay
796 // concrete and require clients to pass in a target like object. The other
797 // option is to make this abstract, and have targets provide concrete
798 // implementations as we do with AsmParser.
799 MCAssembler(MCContext &Context_, MCAsmBackend &Backend_,
800 MCCodeEmitter &Emitter_, MCObjectWriter &Writer_,
804 MCContext &getContext() const { return Context; }
806 MCAsmBackend &getBackend() const { return Backend; }
808 MCCodeEmitter &getEmitter() const { return Emitter; }
810 MCObjectWriter &getWriter() const { return Writer; }
812 /// Finish - Do final processing and write the object to the output stream.
813 /// \arg Writer is used for custom object writer (as the MCJIT does),
814 /// if not specified it is automatically created from backend.
817 // FIXME: This does not belong here.
818 bool getSubsectionsViaSymbols() const {
819 return SubsectionsViaSymbols;
821 void setSubsectionsViaSymbols(bool Value) {
822 SubsectionsViaSymbols = Value;
825 bool getRelaxAll() const { return RelaxAll; }
826 void setRelaxAll(bool Value) { RelaxAll = Value; }
828 bool getNoExecStack() const { return NoExecStack; }
829 void setNoExecStack(bool Value) { NoExecStack = Value; }
831 /// @name Section List Access
834 const SectionDataListType &getSectionList() const { return Sections; }
835 SectionDataListType &getSectionList() { return Sections; }
837 iterator begin() { return Sections.begin(); }
838 const_iterator begin() const { return Sections.begin(); }
840 iterator end() { return Sections.end(); }
841 const_iterator end() const { return Sections.end(); }
843 size_t size() const { return Sections.size(); }
846 /// @name Symbol List Access
849 const SymbolDataListType &getSymbolList() const { return Symbols; }
850 SymbolDataListType &getSymbolList() { return Symbols; }
852 symbol_iterator symbol_begin() { return Symbols.begin(); }
853 const_symbol_iterator symbol_begin() const { return Symbols.begin(); }
855 symbol_iterator symbol_end() { return Symbols.end(); }
856 const_symbol_iterator symbol_end() const { return Symbols.end(); }
858 size_t symbol_size() const { return Symbols.size(); }
861 /// @name Indirect Symbol List Access
864 // FIXME: This is a total hack, this should not be here. Once things are
865 // factored so that the streamer has direct access to the .o writer, it can
867 std::vector<IndirectSymbolData> &getIndirectSymbols() {
868 return IndirectSymbols;
871 indirect_symbol_iterator indirect_symbol_begin() {
872 return IndirectSymbols.begin();
874 const_indirect_symbol_iterator indirect_symbol_begin() const {
875 return IndirectSymbols.begin();
878 indirect_symbol_iterator indirect_symbol_end() {
879 return IndirectSymbols.end();
881 const_indirect_symbol_iterator indirect_symbol_end() const {
882 return IndirectSymbols.end();
885 size_t indirect_symbol_size() const { return IndirectSymbols.size(); }
888 /// @name Backend Data Access
891 MCSectionData &getSectionData(const MCSection &Section) const {
892 MCSectionData *Entry = SectionMap.lookup(&Section);
893 assert(Entry && "Missing section data!");
897 MCSectionData &getOrCreateSectionData(const MCSection &Section,
899 MCSectionData *&Entry = SectionMap[&Section];
901 if (Created) *Created = !Entry;
903 Entry = new MCSectionData(Section, this);
908 MCSymbolData &getSymbolData(const MCSymbol &Symbol) const {
909 MCSymbolData *Entry = SymbolMap.lookup(&Symbol);
910 assert(Entry && "Missing symbol data!");
914 MCSymbolData &getOrCreateSymbolData(const MCSymbol &Symbol,
916 MCSymbolData *&Entry = SymbolMap[&Symbol];
918 if (Created) *Created = !Entry;
920 Entry = new MCSymbolData(Symbol, 0, 0, this);
930 } // end namespace llvm