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; }
102 /// \brief Does this fragment have instructions emitted into it? By default
103 /// this is false, but specific fragment types may set it to true.
104 virtual bool hasInstructions() const { return false; }
106 /// \brief Get the padding size that must be inserted before this fragment.
107 /// Used for bundling. By default, no padding is inserted.
108 /// Note that padding size is restricted to 8 bits. This is an optimization
109 /// to reduce the amount of space used for each fragment. In practice, larger
110 /// padding should never be required.
111 virtual uint8_t getBundlePadding() const {
115 /// \brief Set the padding size for this fragment. By default it's a no-op,
116 /// and only some fragments have a meaningful implementation.
117 virtual void setBundlePadding(uint8_t N) {
123 class MCEncodedFragment : public MCFragment {
124 virtual void anchor();
126 uint8_t BundlePadding;
128 MCEncodedFragment(MCFragment::FragmentType FType, MCSectionData *SD = 0)
129 : MCFragment(FType, SD), BundlePadding(0)
132 virtual ~MCEncodedFragment();
134 typedef SmallVectorImpl<MCFixup>::const_iterator const_fixup_iterator;
135 typedef SmallVectorImpl<MCFixup>::iterator fixup_iterator;
137 virtual SmallVectorImpl<char> &getContents() = 0;
138 virtual const SmallVectorImpl<char> &getContents() const = 0;
140 virtual SmallVectorImpl<MCFixup> &getFixups() = 0;
141 virtual const SmallVectorImpl<MCFixup> &getFixups() const = 0;
143 virtual fixup_iterator fixup_begin() = 0;
144 virtual const_fixup_iterator fixup_begin() const = 0;
145 virtual fixup_iterator fixup_end() = 0;
146 virtual const_fixup_iterator fixup_end() const = 0;
148 virtual uint8_t getBundlePadding() const {
149 return BundlePadding;
152 virtual void setBundlePadding(uint8_t N) {
156 static bool classof(const MCFragment *F) {
157 MCFragment::FragmentType Kind = F->getKind();
158 return Kind == MCFragment::FT_Inst || Kind == MCFragment::FT_Data;
162 class MCDataFragment : public MCEncodedFragment {
163 virtual void anchor();
165 /// \brief Does this fragment contain encoded instructions anywhere in it?
166 bool HasInstructions;
168 SmallVector<char, 32> Contents;
170 /// Fixups - The list of fixups in this fragment.
171 SmallVector<MCFixup, 4> Fixups;
173 MCDataFragment(MCSectionData *SD = 0)
174 : MCEncodedFragment(FT_Data, SD),
175 HasInstructions(false)
179 virtual SmallVectorImpl<char> &getContents() { return Contents; }
180 virtual const SmallVectorImpl<char> &getContents() const { return Contents; }
182 SmallVectorImpl<MCFixup> &getFixups() {
186 const SmallVectorImpl<MCFixup> &getFixups() const {
190 virtual bool hasInstructions() const { return HasInstructions; }
191 virtual void setHasInstructions(bool V) { HasInstructions = V; }
193 fixup_iterator fixup_begin() { return Fixups.begin(); }
194 const_fixup_iterator fixup_begin() const { return Fixups.begin(); }
196 fixup_iterator fixup_end() {return Fixups.end();}
197 const_fixup_iterator fixup_end() const {return Fixups.end();}
199 static bool classof(const MCFragment *F) {
200 return F->getKind() == MCFragment::FT_Data;
204 class MCInstFragment : public MCEncodedFragment {
205 virtual void anchor();
207 /// Inst - The instruction this is a fragment for.
210 /// Contents - Binary data for the currently encoded instruction.
211 SmallVector<char, 8> Contents;
213 /// Fixups - The list of fixups in this fragment.
214 SmallVector<MCFixup, 1> Fixups;
217 MCInstFragment(const MCInst &_Inst, MCSectionData *SD = 0)
218 : MCEncodedFragment(FT_Inst, SD), Inst(_Inst) {
221 virtual SmallVectorImpl<char> &getContents() { return Contents; }
222 virtual const SmallVectorImpl<char> &getContents() const { return Contents; }
224 unsigned getInstSize() const { return Contents.size(); }
225 const MCInst &getInst() const { return Inst; }
226 void setInst(const MCInst& Value) { Inst = Value; }
228 SmallVectorImpl<MCFixup> &getFixups() {
232 const SmallVectorImpl<MCFixup> &getFixups() const {
236 virtual bool hasInstructions() const { return true; }
238 fixup_iterator fixup_begin() { return Fixups.begin(); }
239 const_fixup_iterator fixup_begin() const { return Fixups.begin(); }
241 fixup_iterator fixup_end() {return Fixups.end();}
242 const_fixup_iterator fixup_end() const {return Fixups.end();}
244 static bool classof(const MCFragment *F) {
245 return F->getKind() == MCFragment::FT_Inst;
249 class MCAlignFragment : public MCFragment {
250 virtual void anchor();
252 /// Alignment - The alignment to ensure, in bytes.
255 /// Value - Value to use for filling padding bytes.
258 /// ValueSize - The size of the integer (in bytes) of \p Value.
261 /// MaxBytesToEmit - The maximum number of bytes to emit; if the alignment
262 /// cannot be satisfied in this width then this fragment is ignored.
263 unsigned MaxBytesToEmit;
265 /// EmitNops - Flag to indicate that (optimal) NOPs should be emitted instead
266 /// of using the provided value. The exact interpretation of this flag is
267 /// target dependent.
271 MCAlignFragment(unsigned _Alignment, int64_t _Value, unsigned _ValueSize,
272 unsigned _MaxBytesToEmit, MCSectionData *SD = 0)
273 : MCFragment(FT_Align, SD), Alignment(_Alignment),
274 Value(_Value),ValueSize(_ValueSize),
275 MaxBytesToEmit(_MaxBytesToEmit), EmitNops(false) {}
280 unsigned getAlignment() const { return Alignment; }
282 int64_t getValue() const { return Value; }
284 unsigned getValueSize() const { return ValueSize; }
286 unsigned getMaxBytesToEmit() const { return MaxBytesToEmit; }
288 bool hasEmitNops() const { return EmitNops; }
289 void setEmitNops(bool Value) { EmitNops = Value; }
293 static bool classof(const MCFragment *F) {
294 return F->getKind() == MCFragment::FT_Align;
298 class MCFillFragment : public MCFragment {
299 virtual void anchor();
301 /// Value - Value to use for filling bytes.
304 /// ValueSize - The size (in bytes) of \p Value to use when filling, or 0 if
305 /// this is a virtual fill fragment.
308 /// Size - The number of bytes to insert.
312 MCFillFragment(int64_t _Value, unsigned _ValueSize, uint64_t _Size,
313 MCSectionData *SD = 0)
314 : MCFragment(FT_Fill, SD),
315 Value(_Value), ValueSize(_ValueSize), Size(_Size) {
316 assert((!ValueSize || (Size % ValueSize) == 0) &&
317 "Fill size must be a multiple of the value size!");
323 int64_t getValue() const { return Value; }
325 unsigned getValueSize() const { return ValueSize; }
327 uint64_t getSize() const { return Size; }
331 static bool classof(const MCFragment *F) {
332 return F->getKind() == MCFragment::FT_Fill;
336 class MCOrgFragment : public MCFragment {
337 virtual void anchor();
339 /// Offset - The offset this fragment should start at.
340 const MCExpr *Offset;
342 /// Value - Value to use for filling bytes.
346 MCOrgFragment(const MCExpr &_Offset, int8_t _Value, MCSectionData *SD = 0)
347 : MCFragment(FT_Org, SD),
348 Offset(&_Offset), Value(_Value) {}
353 const MCExpr &getOffset() const { return *Offset; }
355 uint8_t getValue() const { return Value; }
359 static bool classof(const MCFragment *F) {
360 return F->getKind() == MCFragment::FT_Org;
364 class MCLEBFragment : public MCFragment {
365 virtual void anchor();
367 /// Value - The value this fragment should contain.
370 /// IsSigned - True if this is a sleb128, false if uleb128.
373 SmallString<8> Contents;
375 MCLEBFragment(const MCExpr &Value_, bool IsSigned_, MCSectionData *SD)
376 : MCFragment(FT_LEB, SD),
377 Value(&Value_), IsSigned(IsSigned_) { Contents.push_back(0); }
382 const MCExpr &getValue() const { return *Value; }
384 bool isSigned() const { return IsSigned; }
386 SmallString<8> &getContents() { return Contents; }
387 const SmallString<8> &getContents() const { return Contents; }
391 static bool classof(const MCFragment *F) {
392 return F->getKind() == MCFragment::FT_LEB;
396 class MCDwarfLineAddrFragment : public MCFragment {
397 virtual void anchor();
399 /// LineDelta - the value of the difference between the two line numbers
400 /// between two .loc dwarf directives.
403 /// AddrDelta - The expression for the difference of the two symbols that
404 /// make up the address delta between two .loc dwarf directives.
405 const MCExpr *AddrDelta;
407 SmallString<8> Contents;
410 MCDwarfLineAddrFragment(int64_t _LineDelta, const MCExpr &_AddrDelta,
412 : MCFragment(FT_Dwarf, SD),
413 LineDelta(_LineDelta), AddrDelta(&_AddrDelta) { Contents.push_back(0); }
418 int64_t getLineDelta() const { return LineDelta; }
420 const MCExpr &getAddrDelta() const { return *AddrDelta; }
422 SmallString<8> &getContents() { return Contents; }
423 const SmallString<8> &getContents() const { return Contents; }
427 static bool classof(const MCFragment *F) {
428 return F->getKind() == MCFragment::FT_Dwarf;
432 class MCDwarfCallFrameFragment : public MCFragment {
433 virtual void anchor();
435 /// AddrDelta - The expression for the difference of the two symbols that
436 /// make up the address delta between two .cfi_* dwarf directives.
437 const MCExpr *AddrDelta;
439 SmallString<8> Contents;
442 MCDwarfCallFrameFragment(const MCExpr &_AddrDelta, MCSectionData *SD)
443 : MCFragment(FT_DwarfFrame, SD),
444 AddrDelta(&_AddrDelta) { Contents.push_back(0); }
449 const MCExpr &getAddrDelta() const { return *AddrDelta; }
451 SmallString<8> &getContents() { return Contents; }
452 const SmallString<8> &getContents() const { return Contents; }
456 static bool classof(const MCFragment *F) {
457 return F->getKind() == MCFragment::FT_DwarfFrame;
461 // FIXME: Should this be a separate class, or just merged into MCSection? Since
462 // we anticipate the fast path being through an MCAssembler, the only reason to
463 // keep it out is for API abstraction.
464 class MCSectionData : public ilist_node<MCSectionData> {
465 friend class MCAsmLayout;
467 MCSectionData(const MCSectionData&) LLVM_DELETED_FUNCTION;
468 void operator=(const MCSectionData&) LLVM_DELETED_FUNCTION;
471 typedef iplist<MCFragment> FragmentListType;
473 typedef FragmentListType::const_iterator const_iterator;
474 typedef FragmentListType::iterator iterator;
476 typedef FragmentListType::const_reverse_iterator const_reverse_iterator;
477 typedef FragmentListType::reverse_iterator reverse_iterator;
480 FragmentListType Fragments;
481 const MCSection *Section;
483 /// Ordinal - The section index in the assemblers section list.
486 /// LayoutOrder - The index of this section in the layout order.
487 unsigned LayoutOrder;
489 /// Alignment - The maximum alignment seen in this section.
492 /// \brief We're currently inside a bundle-locked group.
495 /// \brief We've seen a bundle_lock directive but not its first instruction
497 bool BundleGroupBeforeFirstInst;
499 /// @name Assembler Backend Data
502 // FIXME: This could all be kept private to the assembler implementation.
504 /// HasInstructions - Whether this section has had instructions emitted into
506 unsigned HasInstructions : 1;
511 // Only for use as sentinel.
513 MCSectionData(const MCSection &Section, MCAssembler *A = 0);
515 const MCSection &getSection() const { return *Section; }
517 unsigned getAlignment() const { return Alignment; }
518 void setAlignment(unsigned Value) { Alignment = Value; }
520 bool hasInstructions() const { return HasInstructions; }
521 void setHasInstructions(bool Value) { HasInstructions = Value; }
523 unsigned getOrdinal() const { return Ordinal; }
524 void setOrdinal(unsigned Value) { Ordinal = Value; }
526 unsigned getLayoutOrder() const { return LayoutOrder; }
527 void setLayoutOrder(unsigned Value) { LayoutOrder = Value; }
529 /// @name Fragment Access
532 const FragmentListType &getFragmentList() const { return Fragments; }
533 FragmentListType &getFragmentList() { return Fragments; }
535 iterator begin() { return Fragments.begin(); }
536 const_iterator begin() const { return Fragments.begin(); }
538 iterator end() { return Fragments.end(); }
539 const_iterator end() const { return Fragments.end(); }
541 reverse_iterator rbegin() { return Fragments.rbegin(); }
542 const_reverse_iterator rbegin() const { return Fragments.rbegin(); }
544 reverse_iterator rend() { return Fragments.rend(); }
545 const_reverse_iterator rend() const { return Fragments.rend(); }
547 size_t size() const { return Fragments.size(); }
549 bool empty() const { return Fragments.empty(); }
551 bool isBundleLocked() const {
555 void setBundleLocked(bool IsLocked) {
556 BundleLocked = IsLocked;
559 bool isBundleGroupBeforeFirstInst() const {
560 return BundleGroupBeforeFirstInst;
563 void setBundleGroupBeforeFirstInst(bool IsFirst) {
564 BundleGroupBeforeFirstInst = IsFirst;
572 // FIXME: Same concerns as with SectionData.
573 class MCSymbolData : public ilist_node<MCSymbolData> {
575 const MCSymbol *Symbol;
577 /// Fragment - The fragment this symbol's value is relative to, if any.
578 MCFragment *Fragment;
580 /// Offset - The offset to apply to the fragment address to form this symbol's
584 /// IsExternal - True if this symbol is visible outside this translation
586 unsigned IsExternal : 1;
588 /// IsPrivateExtern - True if this symbol is private extern.
589 unsigned IsPrivateExtern : 1;
591 /// CommonSize - The size of the symbol, if it is 'common', or 0.
593 // FIXME: Pack this in with other fields? We could put it in offset, since a
594 // common symbol can never get a definition.
597 /// SymbolSize - An expression describing how to calculate the size of
598 /// a symbol. If a symbol has no size this field will be NULL.
599 const MCExpr *SymbolSize;
601 /// CommonAlign - The alignment of the symbol, if it is 'common'.
603 // FIXME: Pack this in with other fields?
604 unsigned CommonAlign;
606 /// Flags - The Flags field is used by object file implementations to store
607 /// additional per symbol information which is not easily classified.
610 /// Index - Index field, for use by the object file implementation.
614 // Only for use as sentinel.
616 MCSymbolData(const MCSymbol &_Symbol, MCFragment *_Fragment, uint64_t _Offset,
622 const MCSymbol &getSymbol() const { return *Symbol; }
624 MCFragment *getFragment() const { return Fragment; }
625 void setFragment(MCFragment *Value) { Fragment = Value; }
627 uint64_t getOffset() const { return Offset; }
628 void setOffset(uint64_t Value) { Offset = Value; }
631 /// @name Symbol Attributes
634 bool isExternal() const { return IsExternal; }
635 void setExternal(bool Value) { IsExternal = Value; }
637 bool isPrivateExtern() const { return IsPrivateExtern; }
638 void setPrivateExtern(bool Value) { IsPrivateExtern = Value; }
640 /// isCommon - Is this a 'common' symbol.
641 bool isCommon() const { return CommonSize != 0; }
643 /// setCommon - Mark this symbol as being 'common'.
645 /// \param Size - The size of the symbol.
646 /// \param Align - The alignment of the symbol.
647 void setCommon(uint64_t Size, unsigned Align) {
652 /// getCommonSize - Return the size of a 'common' symbol.
653 uint64_t getCommonSize() const {
654 assert(isCommon() && "Not a 'common' symbol!");
658 void setSize(const MCExpr *SS) {
662 const MCExpr *getSize() const {
667 /// getCommonAlignment - Return the alignment of a 'common' symbol.
668 unsigned getCommonAlignment() const {
669 assert(isCommon() && "Not a 'common' symbol!");
673 /// getFlags - Get the (implementation defined) symbol flags.
674 uint32_t getFlags() const { return Flags; }
676 /// setFlags - Set the (implementation defined) symbol flags.
677 void setFlags(uint32_t Value) { Flags = Value; }
679 /// modifyFlags - Modify the flags via a mask
680 void modifyFlags(uint32_t Value, uint32_t Mask) {
681 Flags = (Flags & ~Mask) | Value;
684 /// getIndex - Get the (implementation defined) index.
685 uint64_t getIndex() const { return Index; }
687 /// setIndex - Set the (implementation defined) index.
688 void setIndex(uint64_t Value) { Index = Value; }
695 // FIXME: This really doesn't belong here. See comments below.
696 struct IndirectSymbolData {
698 MCSectionData *SectionData;
701 // FIXME: Ditto this. Purely so the Streamer and the ObjectWriter can talk
703 struct DataRegionData {
704 // This enum should be kept in sync w/ the mach-o definition in
705 // llvm/Object/MachOFormat.h.
706 enum KindTy { Data = 1, JumpTable8, JumpTable16, JumpTable32 } Kind;
712 friend class MCAsmLayout;
715 typedef iplist<MCSectionData> SectionDataListType;
716 typedef iplist<MCSymbolData> SymbolDataListType;
718 typedef SectionDataListType::const_iterator const_iterator;
719 typedef SectionDataListType::iterator iterator;
721 typedef SymbolDataListType::const_iterator const_symbol_iterator;
722 typedef SymbolDataListType::iterator symbol_iterator;
724 typedef std::vector<IndirectSymbolData>::const_iterator
725 const_indirect_symbol_iterator;
726 typedef std::vector<IndirectSymbolData>::iterator indirect_symbol_iterator;
728 typedef std::vector<DataRegionData>::const_iterator
729 const_data_region_iterator;
730 typedef std::vector<DataRegionData>::iterator data_region_iterator;
733 MCAssembler(const MCAssembler&) LLVM_DELETED_FUNCTION;
734 void operator=(const MCAssembler&) LLVM_DELETED_FUNCTION;
738 MCAsmBackend &Backend;
740 MCCodeEmitter &Emitter;
742 MCObjectWriter &Writer;
746 iplist<MCSectionData> Sections;
748 iplist<MCSymbolData> Symbols;
750 /// The map of sections to their associated assembler backend data.
752 // FIXME: Avoid this indirection?
753 DenseMap<const MCSection*, MCSectionData*> SectionMap;
755 /// The map of symbols to their associated assembler backend data.
757 // FIXME: Avoid this indirection?
758 DenseMap<const MCSymbol*, MCSymbolData*> SymbolMap;
760 std::vector<IndirectSymbolData> IndirectSymbols;
762 std::vector<DataRegionData> DataRegions;
763 /// The set of function symbols for which a .thumb_func directive has
766 // FIXME: We really would like this in target specific code rather than
767 // here. Maybe when the relocation stuff moves to target specific,
768 // this can go with it? The streamer would need some target specific
770 SmallPtrSet<const MCSymbol*, 64> ThumbFuncs;
772 /// \brief The bundle alignment size currently set in the assembler.
774 /// By default it's 0, which means bundling is disabled.
775 unsigned BundleAlignSize;
777 unsigned RelaxAll : 1;
778 unsigned NoExecStack : 1;
779 unsigned SubsectionsViaSymbols : 1;
782 /// Evaluate a fixup to a relocatable expression and the value which should be
783 /// placed into the fixup.
785 /// \param Layout The layout to use for evaluation.
786 /// \param Fixup The fixup to evaluate.
787 /// \param DF The fragment the fixup is inside.
788 /// \param Target [out] On return, the relocatable expression the fixup
790 /// \param Value [out] On return, the value of the fixup as currently laid
792 /// \return Whether the fixup value was fully resolved. This is true if the
793 /// \p Value result is fixed, otherwise the value may change due to
795 bool evaluateFixup(const MCAsmLayout &Layout,
796 const MCFixup &Fixup, const MCFragment *DF,
797 MCValue &Target, uint64_t &Value) const;
799 /// Check whether a fixup can be satisfied, or whether it needs to be relaxed
800 /// (increased in size, in order to hold its value correctly).
801 bool fixupNeedsRelaxation(const MCFixup &Fixup, const MCInstFragment *DF,
802 const MCAsmLayout &Layout) const;
804 /// Check whether the given fragment needs relaxation.
805 bool fragmentNeedsRelaxation(const MCInstFragment *IF,
806 const MCAsmLayout &Layout) const;
808 /// \brief Perform one layout iteration and return true if any offsets
810 bool layoutOnce(MCAsmLayout &Layout);
812 /// \brief Perform one layout iteration of the given section and return true
813 /// if any offsets were adjusted.
814 bool layoutSectionOnce(MCAsmLayout &Layout, MCSectionData &SD);
816 bool relaxInstruction(MCAsmLayout &Layout, MCInstFragment &IF);
818 bool relaxLEB(MCAsmLayout &Layout, MCLEBFragment &IF);
820 bool relaxDwarfLineAddr(MCAsmLayout &Layout, MCDwarfLineAddrFragment &DF);
821 bool relaxDwarfCallFrameFragment(MCAsmLayout &Layout,
822 MCDwarfCallFrameFragment &DF);
824 /// finishLayout - Finalize a layout, including fragment lowering.
825 void finishLayout(MCAsmLayout &Layout);
827 uint64_t handleFixup(const MCAsmLayout &Layout,
828 MCFragment &F, const MCFixup &Fixup);
831 /// Compute the effective fragment size assuming it is laid out at the given
832 /// \p SectionAddress and \p FragmentOffset.
833 uint64_t computeFragmentSize(const MCAsmLayout &Layout,
834 const MCFragment &F) const;
836 /// Find the symbol which defines the atom containing the given symbol, or
837 /// null if there is no such symbol.
838 const MCSymbolData *getAtom(const MCSymbolData *Symbol) const;
840 /// Check whether a particular symbol is visible to the linker and is required
841 /// in the symbol table, or whether it can be discarded by the assembler. This
842 /// also effects whether the assembler treats the label as potentially
843 /// defining a separate atom.
844 bool isSymbolLinkerVisible(const MCSymbol &SD) const;
846 /// Emit the section contents using the given object writer.
847 void writeSectionData(const MCSectionData *Section,
848 const MCAsmLayout &Layout) const;
850 /// Check whether a given symbol has been flagged with .thumb_func.
851 bool isThumbFunc(const MCSymbol *Func) const {
852 return ThumbFuncs.count(Func);
855 /// Flag a function symbol as the target of a .thumb_func directive.
856 void setIsThumbFunc(const MCSymbol *Func) { ThumbFuncs.insert(Func); }
859 /// Construct a new assembler instance.
861 /// \param OS The stream to output to.
863 // FIXME: How are we going to parameterize this? Two obvious options are stay
864 // concrete and require clients to pass in a target like object. The other
865 // option is to make this abstract, and have targets provide concrete
866 // implementations as we do with AsmParser.
867 MCAssembler(MCContext &Context_, MCAsmBackend &Backend_,
868 MCCodeEmitter &Emitter_, MCObjectWriter &Writer_,
872 /// Reuse an assembler instance
876 MCContext &getContext() const { return Context; }
878 MCAsmBackend &getBackend() const { return Backend; }
880 MCCodeEmitter &getEmitter() const { return Emitter; }
882 MCObjectWriter &getWriter() const { return Writer; }
884 /// Finish - Do final processing and write the object to the output stream.
885 /// \p Writer is used for custom object writer (as the MCJIT does),
886 /// if not specified it is automatically created from backend.
889 // FIXME: This does not belong here.
890 bool getSubsectionsViaSymbols() const {
891 return SubsectionsViaSymbols;
893 void setSubsectionsViaSymbols(bool Value) {
894 SubsectionsViaSymbols = Value;
897 bool getRelaxAll() const { return RelaxAll; }
898 void setRelaxAll(bool Value) { RelaxAll = Value; }
900 bool getNoExecStack() const { return NoExecStack; }
901 void setNoExecStack(bool Value) { NoExecStack = Value; }
903 bool isBundlingEnabled() const {
904 return BundleAlignSize != 0;
907 unsigned getBundleAlignSize() const {
908 return BundleAlignSize;
911 void setBundleAlignSize(unsigned Size) {
912 assert((Size == 0 || !(Size & (Size - 1))) &&
913 "Expect a power-of-two bundle align size");
914 BundleAlignSize = Size;
917 /// @name Section List Access
920 const SectionDataListType &getSectionList() const { return Sections; }
921 SectionDataListType &getSectionList() { return Sections; }
923 iterator begin() { return Sections.begin(); }
924 const_iterator begin() const { return Sections.begin(); }
926 iterator end() { return Sections.end(); }
927 const_iterator end() const { return Sections.end(); }
929 size_t size() const { return Sections.size(); }
932 /// @name Symbol List Access
935 const SymbolDataListType &getSymbolList() const { return Symbols; }
936 SymbolDataListType &getSymbolList() { return Symbols; }
938 symbol_iterator symbol_begin() { return Symbols.begin(); }
939 const_symbol_iterator symbol_begin() const { return Symbols.begin(); }
941 symbol_iterator symbol_end() { return Symbols.end(); }
942 const_symbol_iterator symbol_end() const { return Symbols.end(); }
944 size_t symbol_size() const { return Symbols.size(); }
947 /// @name Indirect Symbol List Access
950 // FIXME: This is a total hack, this should not be here. Once things are
951 // factored so that the streamer has direct access to the .o writer, it can
953 std::vector<IndirectSymbolData> &getIndirectSymbols() {
954 return IndirectSymbols;
957 indirect_symbol_iterator indirect_symbol_begin() {
958 return IndirectSymbols.begin();
960 const_indirect_symbol_iterator indirect_symbol_begin() const {
961 return IndirectSymbols.begin();
964 indirect_symbol_iterator indirect_symbol_end() {
965 return IndirectSymbols.end();
967 const_indirect_symbol_iterator indirect_symbol_end() const {
968 return IndirectSymbols.end();
971 size_t indirect_symbol_size() const { return IndirectSymbols.size(); }
974 /// @name Data Region List Access
977 // FIXME: This is a total hack, this should not be here. Once things are
978 // factored so that the streamer has direct access to the .o writer, it can
980 std::vector<DataRegionData> &getDataRegions() {
984 data_region_iterator data_region_begin() {
985 return DataRegions.begin();
987 const_data_region_iterator data_region_begin() const {
988 return DataRegions.begin();
991 data_region_iterator data_region_end() {
992 return DataRegions.end();
994 const_data_region_iterator data_region_end() const {
995 return DataRegions.end();
998 size_t data_region_size() const { return DataRegions.size(); }
1001 /// @name Backend Data Access
1004 MCSectionData &getSectionData(const MCSection &Section) const {
1005 MCSectionData *Entry = SectionMap.lookup(&Section);
1006 assert(Entry && "Missing section data!");
1010 MCSectionData &getOrCreateSectionData(const MCSection &Section,
1011 bool *Created = 0) {
1012 MCSectionData *&Entry = SectionMap[&Section];
1014 if (Created) *Created = !Entry;
1016 Entry = new MCSectionData(Section, this);
1021 MCSymbolData &getSymbolData(const MCSymbol &Symbol) const {
1022 MCSymbolData *Entry = SymbolMap.lookup(&Symbol);
1023 assert(Entry && "Missing symbol data!");
1027 MCSymbolData &getOrCreateSymbolData(const MCSymbol &Symbol,
1028 bool *Created = 0) {
1029 MCSymbolData *&Entry = SymbolMap[&Symbol];
1031 if (Created) *Created = !Entry;
1033 Entry = new MCSymbolData(Symbol, 0, 0, this);
1043 } // end namespace llvm