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/ADT/DenseMap.h"
14 #include "llvm/ADT/SmallPtrSet.h"
15 #include "llvm/ADT/SmallString.h"
16 #include "llvm/ADT/ilist.h"
17 #include "llvm/ADT/ilist_node.h"
18 #include "llvm/MC/MCFixup.h"
19 #include "llvm/MC/MCInst.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&) LLVM_DELETED_FUNCTION;
44 void operator=(const MCFragment&) LLVM_DELETED_FUNCTION;
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; }
105 class MCDataFragment : public MCFragment {
106 virtual void anchor();
107 SmallString<32> Contents;
109 /// Fixups - The list of fixups in this fragment.
110 SmallVector<MCFixup, 4> Fixups;
113 typedef SmallVectorImpl<MCFixup>::const_iterator const_fixup_iterator;
114 typedef SmallVectorImpl<MCFixup>::iterator fixup_iterator;
117 MCDataFragment(MCSectionData *SD = 0) : MCFragment(FT_Data, SD) {}
122 SmallString<32> &getContents() { return Contents; }
123 const SmallString<32> &getContents() const { return Contents; }
126 /// @name Fixup Access
129 void addFixup(MCFixup Fixup) {
130 // Enforce invariant that fixups are in offset order.
131 assert((Fixups.empty() || Fixup.getOffset() >= Fixups.back().getOffset()) &&
132 "Fixups must be added in order!");
133 Fixups.push_back(Fixup);
136 fixup_iterator fixup_begin() { return Fixups.begin(); }
137 const_fixup_iterator fixup_begin() const { return Fixups.begin(); }
139 fixup_iterator fixup_end() {return Fixups.end();}
140 const_fixup_iterator fixup_end() const {return Fixups.end();}
144 static bool classof(const MCFragment *F) {
145 return F->getKind() == MCFragment::FT_Data;
149 // FIXME: This current incarnation of MCInstFragment doesn't make much sense, as
150 // it is almost entirely a duplicate of MCDataFragment. If we decide to stick
151 // with this approach (as opposed to making MCInstFragment a very light weight
152 // object with just the MCInst and a code size, then we should just change
153 // MCDataFragment to have an optional MCInst at its end.
154 class MCInstFragment : public MCFragment {
155 virtual void anchor();
157 /// Inst - The instruction this is a fragment for.
160 /// Code - Binary data for the currently encoded instruction.
163 /// Fixups - The list of fixups in this fragment.
164 SmallVector<MCFixup, 1> Fixups;
167 typedef SmallVectorImpl<MCFixup>::const_iterator const_fixup_iterator;
168 typedef SmallVectorImpl<MCFixup>::iterator fixup_iterator;
171 MCInstFragment(const MCInst &_Inst, MCSectionData *SD = 0)
172 : MCFragment(FT_Inst, SD), Inst(_Inst) {
178 SmallVectorImpl<char> &getCode() { return Code; }
179 const SmallVectorImpl<char> &getCode() const { return Code; }
181 unsigned getInstSize() const { return Code.size(); }
182 const MCInst &getInst() const { return Inst; }
183 void setInst(const MCInst& Value) { Inst = Value; }
186 /// @name Fixup Access
189 SmallVectorImpl<MCFixup> &getFixups() { return Fixups; }
190 const SmallVectorImpl<MCFixup> &getFixups() const { return Fixups; }
192 fixup_iterator fixup_begin() { return Fixups.begin(); }
193 const_fixup_iterator fixup_begin() const { return Fixups.begin(); }
195 fixup_iterator fixup_end() {return Fixups.end();}
196 const_fixup_iterator fixup_end() const {return Fixups.end();}
200 static bool classof(const MCFragment *F) {
201 return F->getKind() == MCFragment::FT_Inst;
205 class MCAlignFragment : public MCFragment {
206 virtual void anchor();
208 /// Alignment - The alignment to ensure, in bytes.
211 /// Value - Value to use for filling padding bytes.
214 /// ValueSize - The size of the integer (in bytes) of \p Value.
217 /// MaxBytesToEmit - The maximum number of bytes to emit; if the alignment
218 /// cannot be satisfied in this width then this fragment is ignored.
219 unsigned MaxBytesToEmit;
221 /// EmitNops - Flag to indicate that (optimal) NOPs should be emitted instead
222 /// of using the provided value. The exact interpretation of this flag is
223 /// target dependent.
227 MCAlignFragment(unsigned _Alignment, int64_t _Value, unsigned _ValueSize,
228 unsigned _MaxBytesToEmit, MCSectionData *SD = 0)
229 : MCFragment(FT_Align, SD), Alignment(_Alignment),
230 Value(_Value),ValueSize(_ValueSize),
231 MaxBytesToEmit(_MaxBytesToEmit), EmitNops(false) {}
236 unsigned getAlignment() const { return Alignment; }
238 int64_t getValue() const { return Value; }
240 unsigned getValueSize() const { return ValueSize; }
242 unsigned getMaxBytesToEmit() const { return MaxBytesToEmit; }
244 bool hasEmitNops() const { return EmitNops; }
245 void setEmitNops(bool Value) { EmitNops = Value; }
249 static bool classof(const MCFragment *F) {
250 return F->getKind() == MCFragment::FT_Align;
254 class MCFillFragment : public MCFragment {
255 virtual void anchor();
257 /// Value - Value to use for filling bytes.
260 /// ValueSize - The size (in bytes) of \p Value to use when filling, or 0 if
261 /// this is a virtual fill fragment.
264 /// Size - The number of bytes to insert.
268 MCFillFragment(int64_t _Value, unsigned _ValueSize, uint64_t _Size,
269 MCSectionData *SD = 0)
270 : MCFragment(FT_Fill, SD),
271 Value(_Value), ValueSize(_ValueSize), Size(_Size) {
272 assert((!ValueSize || (Size % ValueSize) == 0) &&
273 "Fill size must be a multiple of the value size!");
279 int64_t getValue() const { return Value; }
281 unsigned getValueSize() const { return ValueSize; }
283 uint64_t getSize() const { return Size; }
287 static bool classof(const MCFragment *F) {
288 return F->getKind() == MCFragment::FT_Fill;
292 class MCOrgFragment : public MCFragment {
293 virtual void anchor();
295 /// Offset - The offset this fragment should start at.
296 const MCExpr *Offset;
298 /// Value - Value to use for filling bytes.
302 MCOrgFragment(const MCExpr &_Offset, int8_t _Value, MCSectionData *SD = 0)
303 : MCFragment(FT_Org, SD),
304 Offset(&_Offset), Value(_Value) {}
309 const MCExpr &getOffset() const { return *Offset; }
311 uint8_t getValue() const { return Value; }
315 static bool classof(const MCFragment *F) {
316 return F->getKind() == MCFragment::FT_Org;
320 class MCLEBFragment : public MCFragment {
321 virtual void anchor();
323 /// Value - The value this fragment should contain.
326 /// IsSigned - True if this is a sleb128, false if uleb128.
329 SmallString<8> Contents;
331 MCLEBFragment(const MCExpr &Value_, bool IsSigned_, MCSectionData *SD)
332 : MCFragment(FT_LEB, SD),
333 Value(&Value_), IsSigned(IsSigned_) { Contents.push_back(0); }
338 const MCExpr &getValue() const { return *Value; }
340 bool isSigned() const { return IsSigned; }
342 SmallString<8> &getContents() { return Contents; }
343 const SmallString<8> &getContents() const { return Contents; }
347 static bool classof(const MCFragment *F) {
348 return F->getKind() == MCFragment::FT_LEB;
352 class MCDwarfLineAddrFragment : public MCFragment {
353 virtual void anchor();
355 /// LineDelta - the value of the difference between the two line numbers
356 /// between two .loc dwarf directives.
359 /// AddrDelta - The expression for the difference of the two symbols that
360 /// make up the address delta between two .loc dwarf directives.
361 const MCExpr *AddrDelta;
363 SmallString<8> Contents;
366 MCDwarfLineAddrFragment(int64_t _LineDelta, const MCExpr &_AddrDelta,
368 : MCFragment(FT_Dwarf, SD),
369 LineDelta(_LineDelta), AddrDelta(&_AddrDelta) { Contents.push_back(0); }
374 int64_t getLineDelta() const { return LineDelta; }
376 const MCExpr &getAddrDelta() const { return *AddrDelta; }
378 SmallString<8> &getContents() { return Contents; }
379 const SmallString<8> &getContents() const { return Contents; }
383 static bool classof(const MCFragment *F) {
384 return F->getKind() == MCFragment::FT_Dwarf;
388 class MCDwarfCallFrameFragment : public MCFragment {
389 virtual void anchor();
391 /// AddrDelta - The expression for the difference of the two symbols that
392 /// make up the address delta between two .cfi_* dwarf directives.
393 const MCExpr *AddrDelta;
395 SmallString<8> Contents;
398 MCDwarfCallFrameFragment(const MCExpr &_AddrDelta, MCSectionData *SD)
399 : MCFragment(FT_DwarfFrame, SD),
400 AddrDelta(&_AddrDelta) { Contents.push_back(0); }
405 const MCExpr &getAddrDelta() const { return *AddrDelta; }
407 SmallString<8> &getContents() { return Contents; }
408 const SmallString<8> &getContents() const { return Contents; }
412 static bool classof(const MCFragment *F) {
413 return F->getKind() == MCFragment::FT_DwarfFrame;
417 // FIXME: Should this be a separate class, or just merged into MCSection? Since
418 // we anticipate the fast path being through an MCAssembler, the only reason to
419 // keep it out is for API abstraction.
420 class MCSectionData : public ilist_node<MCSectionData> {
421 friend class MCAsmLayout;
423 MCSectionData(const MCSectionData&) LLVM_DELETED_FUNCTION;
424 void operator=(const MCSectionData&) LLVM_DELETED_FUNCTION;
427 typedef iplist<MCFragment> FragmentListType;
429 typedef FragmentListType::const_iterator const_iterator;
430 typedef FragmentListType::iterator iterator;
432 typedef FragmentListType::const_reverse_iterator const_reverse_iterator;
433 typedef FragmentListType::reverse_iterator reverse_iterator;
436 FragmentListType Fragments;
437 const MCSection *Section;
439 /// Ordinal - The section index in the assemblers section list.
442 /// LayoutOrder - The index of this section in the layout order.
443 unsigned LayoutOrder;
445 /// Alignment - The maximum alignment seen in this section.
448 /// @name Assembler Backend Data
451 // FIXME: This could all be kept private to the assembler implementation.
453 /// HasInstructions - Whether this section has had instructions emitted into
455 unsigned HasInstructions : 1;
460 // Only for use as sentinel.
462 MCSectionData(const MCSection &Section, MCAssembler *A = 0);
464 const MCSection &getSection() const { return *Section; }
466 unsigned getAlignment() const { return Alignment; }
467 void setAlignment(unsigned Value) { Alignment = Value; }
469 bool hasInstructions() const { return HasInstructions; }
470 void setHasInstructions(bool Value) { HasInstructions = Value; }
472 unsigned getOrdinal() const { return Ordinal; }
473 void setOrdinal(unsigned Value) { Ordinal = Value; }
475 unsigned getLayoutOrder() const { return LayoutOrder; }
476 void setLayoutOrder(unsigned Value) { LayoutOrder = Value; }
478 /// @name Fragment Access
481 const FragmentListType &getFragmentList() const { return Fragments; }
482 FragmentListType &getFragmentList() { return Fragments; }
484 iterator begin() { return Fragments.begin(); }
485 const_iterator begin() const { return Fragments.begin(); }
487 iterator end() { return Fragments.end(); }
488 const_iterator end() const { return Fragments.end(); }
490 reverse_iterator rbegin() { return Fragments.rbegin(); }
491 const_reverse_iterator rbegin() const { return Fragments.rbegin(); }
493 reverse_iterator rend() { return Fragments.rend(); }
494 const_reverse_iterator rend() const { return Fragments.rend(); }
496 size_t size() const { return Fragments.size(); }
498 bool empty() const { return Fragments.empty(); }
505 // FIXME: Same concerns as with SectionData.
506 class MCSymbolData : public ilist_node<MCSymbolData> {
508 const MCSymbol *Symbol;
510 /// Fragment - The fragment this symbol's value is relative to, if any.
511 MCFragment *Fragment;
513 /// Offset - The offset to apply to the fragment address to form this symbol's
517 /// IsExternal - True if this symbol is visible outside this translation
519 unsigned IsExternal : 1;
521 /// IsPrivateExtern - True if this symbol is private extern.
522 unsigned IsPrivateExtern : 1;
524 /// CommonSize - The size of the symbol, if it is 'common', or 0.
526 // FIXME: Pack this in with other fields? We could put it in offset, since a
527 // common symbol can never get a definition.
530 /// SymbolSize - An expression describing how to calculate the size of
531 /// a symbol. If a symbol has no size this field will be NULL.
532 const MCExpr *SymbolSize;
534 /// CommonAlign - The alignment of the symbol, if it is 'common'.
536 // FIXME: Pack this in with other fields?
537 unsigned CommonAlign;
539 /// Flags - The Flags field is used by object file implementations to store
540 /// additional per symbol information which is not easily classified.
543 /// Index - Index field, for use by the object file implementation.
547 // Only for use as sentinel.
549 MCSymbolData(const MCSymbol &_Symbol, MCFragment *_Fragment, uint64_t _Offset,
555 const MCSymbol &getSymbol() const { return *Symbol; }
557 MCFragment *getFragment() const { return Fragment; }
558 void setFragment(MCFragment *Value) { Fragment = Value; }
560 uint64_t getOffset() const { return Offset; }
561 void setOffset(uint64_t Value) { Offset = Value; }
564 /// @name Symbol Attributes
567 bool isExternal() const { return IsExternal; }
568 void setExternal(bool Value) { IsExternal = Value; }
570 bool isPrivateExtern() const { return IsPrivateExtern; }
571 void setPrivateExtern(bool Value) { IsPrivateExtern = Value; }
573 /// isCommon - Is this a 'common' symbol.
574 bool isCommon() const { return CommonSize != 0; }
576 /// setCommon - Mark this symbol as being 'common'.
578 /// \param Size - The size of the symbol.
579 /// \param Align - The alignment of the symbol.
580 void setCommon(uint64_t Size, unsigned Align) {
585 /// getCommonSize - Return the size of a 'common' symbol.
586 uint64_t getCommonSize() const {
587 assert(isCommon() && "Not a 'common' symbol!");
591 void setSize(const MCExpr *SS) {
595 const MCExpr *getSize() const {
600 /// getCommonAlignment - Return the alignment of a 'common' symbol.
601 unsigned getCommonAlignment() const {
602 assert(isCommon() && "Not a 'common' symbol!");
606 /// getFlags - Get the (implementation defined) symbol flags.
607 uint32_t getFlags() const { return Flags; }
609 /// setFlags - Set the (implementation defined) symbol flags.
610 void setFlags(uint32_t Value) { Flags = Value; }
612 /// modifyFlags - Modify the flags via a mask
613 void modifyFlags(uint32_t Value, uint32_t Mask) {
614 Flags = (Flags & ~Mask) | Value;
617 /// getIndex - Get the (implementation defined) index.
618 uint64_t getIndex() const { return Index; }
620 /// setIndex - Set the (implementation defined) index.
621 void setIndex(uint64_t Value) { Index = Value; }
628 // FIXME: This really doesn't belong here. See comments below.
629 struct IndirectSymbolData {
631 MCSectionData *SectionData;
634 // FIXME: Ditto this. Purely so the Streamer and the ObjectWriter can talk
636 struct DataRegionData {
637 // This enum should be kept in sync w/ the mach-o definition in
638 // llvm/Object/MachOFormat.h.
639 enum KindTy { Data = 1, JumpTable8, JumpTable16, JumpTable32 } Kind;
645 friend class MCAsmLayout;
648 typedef iplist<MCSectionData> SectionDataListType;
649 typedef iplist<MCSymbolData> SymbolDataListType;
651 typedef SectionDataListType::const_iterator const_iterator;
652 typedef SectionDataListType::iterator iterator;
654 typedef SymbolDataListType::const_iterator const_symbol_iterator;
655 typedef SymbolDataListType::iterator symbol_iterator;
657 typedef std::vector<IndirectSymbolData>::const_iterator
658 const_indirect_symbol_iterator;
659 typedef std::vector<IndirectSymbolData>::iterator indirect_symbol_iterator;
661 typedef std::vector<DataRegionData>::const_iterator
662 const_data_region_iterator;
663 typedef std::vector<DataRegionData>::iterator data_region_iterator;
666 MCAssembler(const MCAssembler&) LLVM_DELETED_FUNCTION;
667 void operator=(const MCAssembler&) LLVM_DELETED_FUNCTION;
671 MCAsmBackend &Backend;
673 MCCodeEmitter &Emitter;
675 MCObjectWriter &Writer;
679 iplist<MCSectionData> Sections;
681 iplist<MCSymbolData> Symbols;
683 /// The map of sections to their associated assembler backend data.
685 // FIXME: Avoid this indirection?
686 DenseMap<const MCSection*, MCSectionData*> SectionMap;
688 /// The map of symbols to their associated assembler backend data.
690 // FIXME: Avoid this indirection?
691 DenseMap<const MCSymbol*, MCSymbolData*> SymbolMap;
693 std::vector<IndirectSymbolData> IndirectSymbols;
695 std::vector<DataRegionData> DataRegions;
696 /// The set of function symbols for which a .thumb_func directive has
699 // FIXME: We really would like this in target specific code rather than
700 // here. Maybe when the relocation stuff moves to target specific,
701 // this can go with it? The streamer would need some target specific
703 SmallPtrSet<const MCSymbol*, 64> ThumbFuncs;
705 unsigned RelaxAll : 1;
706 unsigned NoExecStack : 1;
707 unsigned SubsectionsViaSymbols : 1;
710 /// Evaluate a fixup to a relocatable expression and the value which should be
711 /// placed into the fixup.
713 /// \param Layout The layout to use for evaluation.
714 /// \param Fixup The fixup to evaluate.
715 /// \param DF The fragment the fixup is inside.
716 /// \param Target [out] On return, the relocatable expression the fixup
718 /// \param Value [out] On return, the value of the fixup as currently laid
720 /// \return Whether the fixup value was fully resolved. This is true if the
721 /// \p Value result is fixed, otherwise the value may change due to
723 bool evaluateFixup(const MCAsmLayout &Layout,
724 const MCFixup &Fixup, const MCFragment *DF,
725 MCValue &Target, uint64_t &Value) const;
727 /// Check whether a fixup can be satisfied, or whether it needs to be relaxed
728 /// (increased in size, in order to hold its value correctly).
729 bool fixupNeedsRelaxation(const MCFixup &Fixup, const MCInstFragment *DF,
730 const MCAsmLayout &Layout) const;
732 /// Check whether the given fragment needs relaxation.
733 bool fragmentNeedsRelaxation(const MCInstFragment *IF,
734 const MCAsmLayout &Layout) const;
736 /// layoutOnce - Perform one layout iteration and return true if any offsets
738 bool layoutOnce(MCAsmLayout &Layout);
740 bool layoutSectionOnce(MCAsmLayout &Layout, MCSectionData &SD);
742 bool relaxInstruction(MCAsmLayout &Layout, MCInstFragment &IF);
744 bool relaxLEB(MCAsmLayout &Layout, MCLEBFragment &IF);
746 bool relaxDwarfLineAddr(MCAsmLayout &Layout, MCDwarfLineAddrFragment &DF);
747 bool relaxDwarfCallFrameFragment(MCAsmLayout &Layout,
748 MCDwarfCallFrameFragment &DF);
750 /// finishLayout - Finalize a layout, including fragment lowering.
751 void finishLayout(MCAsmLayout &Layout);
753 uint64_t handleFixup(const MCAsmLayout &Layout,
754 MCFragment &F, const MCFixup &Fixup);
757 /// Compute the effective fragment size assuming it is laid out at the given
758 /// \p SectionAddress and \p FragmentOffset.
759 uint64_t computeFragmentSize(const MCAsmLayout &Layout,
760 const MCFragment &F) const;
762 /// Find the symbol which defines the atom containing the given symbol, or
763 /// null if there is no such symbol.
764 const MCSymbolData *getAtom(const MCSymbolData *Symbol) const;
766 /// Check whether a particular symbol is visible to the linker and is required
767 /// in the symbol table, or whether it can be discarded by the assembler. This
768 /// also effects whether the assembler treats the label as potentially
769 /// defining a separate atom.
770 bool isSymbolLinkerVisible(const MCSymbol &SD) const;
772 /// Emit the section contents using the given object writer.
773 void writeSectionData(const MCSectionData *Section,
774 const MCAsmLayout &Layout) const;
776 /// Check whether a given symbol has been flagged with .thumb_func.
777 bool isThumbFunc(const MCSymbol *Func) const {
778 return ThumbFuncs.count(Func);
781 /// Flag a function symbol as the target of a .thumb_func directive.
782 void setIsThumbFunc(const MCSymbol *Func) { ThumbFuncs.insert(Func); }
785 /// Construct a new assembler instance.
787 /// \param OS The stream to output to.
789 // FIXME: How are we going to parameterize this? Two obvious options are stay
790 // concrete and require clients to pass in a target like object. The other
791 // option is to make this abstract, and have targets provide concrete
792 // implementations as we do with AsmParser.
793 MCAssembler(MCContext &Context_, MCAsmBackend &Backend_,
794 MCCodeEmitter &Emitter_, MCObjectWriter &Writer_,
798 MCContext &getContext() const { return Context; }
800 MCAsmBackend &getBackend() const { return Backend; }
802 MCCodeEmitter &getEmitter() const { return Emitter; }
804 MCObjectWriter &getWriter() const { return Writer; }
806 /// Finish - Do final processing and write the object to the output stream.
807 /// \p Writer is used for custom object writer (as the MCJIT does),
808 /// if not specified it is automatically created from backend.
811 // FIXME: This does not belong here.
812 bool getSubsectionsViaSymbols() const {
813 return SubsectionsViaSymbols;
815 void setSubsectionsViaSymbols(bool Value) {
816 SubsectionsViaSymbols = Value;
819 bool getRelaxAll() const { return RelaxAll; }
820 void setRelaxAll(bool Value) { RelaxAll = Value; }
822 bool getNoExecStack() const { return NoExecStack; }
823 void setNoExecStack(bool Value) { NoExecStack = Value; }
825 /// @name Section List Access
828 const SectionDataListType &getSectionList() const { return Sections; }
829 SectionDataListType &getSectionList() { return Sections; }
831 iterator begin() { return Sections.begin(); }
832 const_iterator begin() const { return Sections.begin(); }
834 iterator end() { return Sections.end(); }
835 const_iterator end() const { return Sections.end(); }
837 size_t size() const { return Sections.size(); }
840 /// @name Symbol List Access
843 const SymbolDataListType &getSymbolList() const { return Symbols; }
844 SymbolDataListType &getSymbolList() { return Symbols; }
846 symbol_iterator symbol_begin() { return Symbols.begin(); }
847 const_symbol_iterator symbol_begin() const { return Symbols.begin(); }
849 symbol_iterator symbol_end() { return Symbols.end(); }
850 const_symbol_iterator symbol_end() const { return Symbols.end(); }
852 size_t symbol_size() const { return Symbols.size(); }
855 /// @name Indirect Symbol List Access
858 // FIXME: This is a total hack, this should not be here. Once things are
859 // factored so that the streamer has direct access to the .o writer, it can
861 std::vector<IndirectSymbolData> &getIndirectSymbols() {
862 return IndirectSymbols;
865 indirect_symbol_iterator indirect_symbol_begin() {
866 return IndirectSymbols.begin();
868 const_indirect_symbol_iterator indirect_symbol_begin() const {
869 return IndirectSymbols.begin();
872 indirect_symbol_iterator indirect_symbol_end() {
873 return IndirectSymbols.end();
875 const_indirect_symbol_iterator indirect_symbol_end() const {
876 return IndirectSymbols.end();
879 size_t indirect_symbol_size() const { return IndirectSymbols.size(); }
882 /// @name Data Region List Access
885 // FIXME: This is a total hack, this should not be here. Once things are
886 // factored so that the streamer has direct access to the .o writer, it can
888 std::vector<DataRegionData> &getDataRegions() {
892 data_region_iterator data_region_begin() {
893 return DataRegions.begin();
895 const_data_region_iterator data_region_begin() const {
896 return DataRegions.begin();
899 data_region_iterator data_region_end() {
900 return DataRegions.end();
902 const_data_region_iterator data_region_end() const {
903 return DataRegions.end();
906 size_t data_region_size() const { return DataRegions.size(); }
909 /// @name Backend Data Access
912 MCSectionData &getSectionData(const MCSection &Section) const {
913 MCSectionData *Entry = SectionMap.lookup(&Section);
914 assert(Entry && "Missing section data!");
918 MCSectionData &getOrCreateSectionData(const MCSection &Section,
920 MCSectionData *&Entry = SectionMap[&Section];
922 if (Created) *Created = !Entry;
924 Entry = new MCSectionData(Section, this);
929 MCSymbolData &getSymbolData(const MCSymbol &Symbol) const {
930 MCSymbolData *Entry = SymbolMap.lookup(&Symbol);
931 assert(Entry && "Missing symbol data!");
935 MCSymbolData &getOrCreateSymbolData(const MCSymbol &Symbol,
937 MCSymbolData *&Entry = SymbolMap[&Symbol];
939 if (Created) *Created = !Entry;
941 Entry = new MCSymbolData(Symbol, 0, 0, this);
951 } // end namespace llvm