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;
654 // FIXME: Ditto this. Purely so the Streamer and the ObjectWriter can talk
656 struct DataRegionData {
657 // This enum should be kept in sync w/ the mach-o definition in
658 // llvm/Object/MachOFormat.h.
659 enum KindTy { Data = 1, JumpTable8, JumpTable16, JumpTable32 } Kind;
665 friend class MCAsmLayout;
668 typedef iplist<MCSectionData> SectionDataListType;
669 typedef iplist<MCSymbolData> SymbolDataListType;
671 typedef SectionDataListType::const_iterator const_iterator;
672 typedef SectionDataListType::iterator iterator;
674 typedef SymbolDataListType::const_iterator const_symbol_iterator;
675 typedef SymbolDataListType::iterator symbol_iterator;
677 typedef std::vector<IndirectSymbolData>::const_iterator
678 const_indirect_symbol_iterator;
679 typedef std::vector<IndirectSymbolData>::iterator indirect_symbol_iterator;
681 typedef std::vector<DataRegionData>::const_iterator
682 const_data_region_iterator;
683 typedef std::vector<DataRegionData>::iterator data_region_iterator;
686 MCAssembler(const MCAssembler&); // DO NOT IMPLEMENT
687 void operator=(const MCAssembler&); // DO NOT IMPLEMENT
691 MCAsmBackend &Backend;
693 MCCodeEmitter &Emitter;
695 MCObjectWriter &Writer;
699 iplist<MCSectionData> Sections;
701 iplist<MCSymbolData> Symbols;
703 /// The map of sections to their associated assembler backend data.
705 // FIXME: Avoid this indirection?
706 DenseMap<const MCSection*, MCSectionData*> SectionMap;
708 /// The map of symbols to their associated assembler backend data.
710 // FIXME: Avoid this indirection?
711 DenseMap<const MCSymbol*, MCSymbolData*> SymbolMap;
713 std::vector<IndirectSymbolData> IndirectSymbols;
715 std::vector<DataRegionData> DataRegions;
716 /// The set of function symbols for which a .thumb_func directive has
719 // FIXME: We really would like this in target specific code rather than
720 // here. Maybe when the relocation stuff moves to target specific,
721 // this can go with it? The streamer would need some target specific
723 SmallPtrSet<const MCSymbol*, 64> ThumbFuncs;
725 unsigned RelaxAll : 1;
726 unsigned NoExecStack : 1;
727 unsigned SubsectionsViaSymbols : 1;
730 /// Evaluate a fixup to a relocatable expression and the value which should be
731 /// placed into the fixup.
733 /// \param Layout The layout to use for evaluation.
734 /// \param Fixup The fixup to evaluate.
735 /// \param DF The fragment the fixup is inside.
736 /// \param Target [out] On return, the relocatable expression the fixup
738 /// \param Value [out] On return, the value of the fixup as currently laid
740 /// \return Whether the fixup value was fully resolved. This is true if the
741 /// \arg Value result is fixed, otherwise the value may change due to
743 bool evaluateFixup(const MCAsmLayout &Layout,
744 const MCFixup &Fixup, const MCFragment *DF,
745 MCValue &Target, uint64_t &Value) const;
747 /// Check whether a fixup can be satisfied, or whether it needs to be relaxed
748 /// (increased in size, in order to hold its value correctly).
749 bool fixupNeedsRelaxation(const MCFixup &Fixup, const MCInstFragment *DF,
750 const MCAsmLayout &Layout) const;
752 /// Check whether the given fragment needs relaxation.
753 bool fragmentNeedsRelaxation(const MCInstFragment *IF,
754 const MCAsmLayout &Layout) const;
756 /// layoutOnce - Perform one layout iteration and return true if any offsets
758 bool layoutOnce(MCAsmLayout &Layout);
760 bool layoutSectionOnce(MCAsmLayout &Layout, MCSectionData &SD);
762 bool relaxInstruction(MCAsmLayout &Layout, MCInstFragment &IF);
764 bool relaxLEB(MCAsmLayout &Layout, MCLEBFragment &IF);
766 bool relaxDwarfLineAddr(MCAsmLayout &Layout, MCDwarfLineAddrFragment &DF);
767 bool relaxDwarfCallFrameFragment(MCAsmLayout &Layout,
768 MCDwarfCallFrameFragment &DF);
770 /// finishLayout - Finalize a layout, including fragment lowering.
771 void finishLayout(MCAsmLayout &Layout);
773 uint64_t handleFixup(const MCAsmLayout &Layout,
774 MCFragment &F, const MCFixup &Fixup);
777 /// Compute the effective fragment size assuming it is laid out at the given
778 /// \arg SectionAddress and \arg FragmentOffset.
779 uint64_t computeFragmentSize(const MCAsmLayout &Layout,
780 const MCFragment &F) const;
782 /// Find the symbol which defines the atom containing the given symbol, or
783 /// null if there is no such symbol.
784 const MCSymbolData *getAtom(const MCSymbolData *Symbol) const;
786 /// Check whether a particular symbol is visible to the linker and is required
787 /// in the symbol table, or whether it can be discarded by the assembler. This
788 /// also effects whether the assembler treats the label as potentially
789 /// defining a separate atom.
790 bool isSymbolLinkerVisible(const MCSymbol &SD) const;
792 /// Emit the section contents using the given object writer.
793 void writeSectionData(const MCSectionData *Section,
794 const MCAsmLayout &Layout) const;
796 /// Check whether a given symbol has been flagged with .thumb_func.
797 bool isThumbFunc(const MCSymbol *Func) const {
798 return ThumbFuncs.count(Func);
801 /// Flag a function symbol as the target of a .thumb_func directive.
802 void setIsThumbFunc(const MCSymbol *Func) { ThumbFuncs.insert(Func); }
805 /// Construct a new assembler instance.
807 /// \arg OS - The stream to output to.
809 // FIXME: How are we going to parameterize this? Two obvious options are stay
810 // concrete and require clients to pass in a target like object. The other
811 // option is to make this abstract, and have targets provide concrete
812 // implementations as we do with AsmParser.
813 MCAssembler(MCContext &Context_, MCAsmBackend &Backend_,
814 MCCodeEmitter &Emitter_, MCObjectWriter &Writer_,
818 MCContext &getContext() const { return Context; }
820 MCAsmBackend &getBackend() const { return Backend; }
822 MCCodeEmitter &getEmitter() const { return Emitter; }
824 MCObjectWriter &getWriter() const { return Writer; }
826 /// Finish - Do final processing and write the object to the output stream.
827 /// \arg Writer is used for custom object writer (as the MCJIT does),
828 /// if not specified it is automatically created from backend.
831 // FIXME: This does not belong here.
832 bool getSubsectionsViaSymbols() const {
833 return SubsectionsViaSymbols;
835 void setSubsectionsViaSymbols(bool Value) {
836 SubsectionsViaSymbols = Value;
839 bool getRelaxAll() const { return RelaxAll; }
840 void setRelaxAll(bool Value) { RelaxAll = Value; }
842 bool getNoExecStack() const { return NoExecStack; }
843 void setNoExecStack(bool Value) { NoExecStack = Value; }
845 /// @name Section List Access
848 const SectionDataListType &getSectionList() const { return Sections; }
849 SectionDataListType &getSectionList() { return Sections; }
851 iterator begin() { return Sections.begin(); }
852 const_iterator begin() const { return Sections.begin(); }
854 iterator end() { return Sections.end(); }
855 const_iterator end() const { return Sections.end(); }
857 size_t size() const { return Sections.size(); }
860 /// @name Symbol List Access
863 const SymbolDataListType &getSymbolList() const { return Symbols; }
864 SymbolDataListType &getSymbolList() { return Symbols; }
866 symbol_iterator symbol_begin() { return Symbols.begin(); }
867 const_symbol_iterator symbol_begin() const { return Symbols.begin(); }
869 symbol_iterator symbol_end() { return Symbols.end(); }
870 const_symbol_iterator symbol_end() const { return Symbols.end(); }
872 size_t symbol_size() const { return Symbols.size(); }
875 /// @name Indirect Symbol List Access
878 // FIXME: This is a total hack, this should not be here. Once things are
879 // factored so that the streamer has direct access to the .o writer, it can
881 std::vector<IndirectSymbolData> &getIndirectSymbols() {
882 return IndirectSymbols;
885 indirect_symbol_iterator indirect_symbol_begin() {
886 return IndirectSymbols.begin();
888 const_indirect_symbol_iterator indirect_symbol_begin() const {
889 return IndirectSymbols.begin();
892 indirect_symbol_iterator indirect_symbol_end() {
893 return IndirectSymbols.end();
895 const_indirect_symbol_iterator indirect_symbol_end() const {
896 return IndirectSymbols.end();
899 size_t indirect_symbol_size() const { return IndirectSymbols.size(); }
902 /// @name Data Region List Access
905 // FIXME: This is a total hack, this should not be here. Once things are
906 // factored so that the streamer has direct access to the .o writer, it can
908 std::vector<DataRegionData> &getDataRegions() {
912 data_region_iterator data_region_begin() {
913 return DataRegions.begin();
915 const_data_region_iterator data_region_begin() const {
916 return DataRegions.begin();
919 data_region_iterator data_region_end() {
920 return DataRegions.end();
922 const_data_region_iterator data_region_end() const {
923 return DataRegions.end();
926 size_t data_region_size() const { return DataRegions.size(); }
929 /// @name Backend Data Access
932 MCSectionData &getSectionData(const MCSection &Section) const {
933 MCSectionData *Entry = SectionMap.lookup(&Section);
934 assert(Entry && "Missing section data!");
938 MCSectionData &getOrCreateSectionData(const MCSection &Section,
940 MCSectionData *&Entry = SectionMap[&Section];
942 if (Created) *Created = !Entry;
944 Entry = new MCSectionData(Section, this);
949 MCSymbolData &getSymbolData(const MCSymbol &Symbol) const {
950 MCSymbolData *Entry = SymbolMap.lookup(&Symbol);
951 assert(Entry && "Missing symbol data!");
955 MCSymbolData &getOrCreateSymbolData(const MCSymbol &Symbol,
957 MCSymbolData *&Entry = SymbolMap[&Symbol];
959 if (Created) *Created = !Entry;
961 Entry = new MCSymbolData(Symbol, 0, 0, this);
971 } // end namespace llvm