MC: Factor out MCAssembler::ComputeFragmentSize.
[oota-llvm.git] / include / llvm / MC / MCAssembler.h
1 //===- MCAssembler.h - Object File Generation -------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #ifndef LLVM_MC_MCASSEMBLER_H
11 #define LLVM_MC_MCASSEMBLER_H
12
13 #include "llvm/ADT/DenseMap.h"
14 #include "llvm/ADT/SmallString.h"
15 #include "llvm/ADT/ilist.h"
16 #include "llvm/ADT/ilist_node.h"
17 #include "llvm/Support/Casting.h"
18 #include "llvm/MC/MCFixup.h"
19 #include "llvm/MC/MCInst.h"
20 #include "llvm/System/DataTypes.h"
21 #include <vector> // FIXME: Shouldn't be needed.
22
23 namespace llvm {
24 class raw_ostream;
25 class MCAsmLayout;
26 class MCAssembler;
27 class MCContext;
28 class MCCodeEmitter;
29 class MCExpr;
30 class MCFragment;
31 class MCObjectWriter;
32 class MCSection;
33 class MCSectionData;
34 class MCSymbol;
35 class MCSymbolData;
36 class MCValue;
37 class TargetAsmBackend;
38
39 /// MCAsmFixup - Represent a fixed size region of bytes inside some fragment
40 /// which needs to be rewritten. This region will either be rewritten by the
41 /// assembler or cause a relocation entry to be generated.
42 //
43 // FIXME: This should probably just be merged with MCFixup.
44 class MCAsmFixup {
45 public:
46   /// Offset - The offset inside the fragment which needs to be rewritten.
47   uint64_t Offset;
48
49   /// Value - The expression to eventually write into the fragment.
50   const MCExpr *Value;
51
52   /// Kind - The fixup kind.
53   MCFixupKind Kind;
54
55 public:
56   MCAsmFixup(uint64_t _Offset, const MCExpr &_Value, MCFixupKind _Kind)
57     : Offset(_Offset), Value(&_Value), Kind(_Kind) {}
58 };
59
60 class MCFragment : public ilist_node<MCFragment> {
61   friend class MCAsmLayout;
62
63   MCFragment(const MCFragment&);     // DO NOT IMPLEMENT
64   void operator=(const MCFragment&); // DO NOT IMPLEMENT
65
66 public:
67   enum FragmentType {
68     FT_Align,
69     FT_Data,
70     FT_Fill,
71     FT_Inst,
72     FT_Org
73   };
74
75 private:
76   FragmentType Kind;
77
78   /// Parent - The data for the section this fragment is in.
79   MCSectionData *Parent;
80
81   /// Atom - The atom this fragment is in, as represented by it's defining
82   /// symbol. Atom's are only used by backends which set
83   /// \see MCAsmBackend::hasReliableSymbolDifference().
84   MCSymbolData *Atom;
85
86   /// @name Assembler Backend Data
87   /// @{
88   //
89   // FIXME: This could all be kept private to the assembler implementation.
90
91   /// Offset - The offset of this fragment in its section. This is ~0 until
92   /// initialized.
93   uint64_t Offset;
94
95   /// EffectiveSize - The compute size of this section. This is ~0 until
96   /// initialized.
97   uint64_t EffectiveSize;
98
99   /// Ordinal - The global index of this fragment. This is the index across all
100   /// sections, not just the parent section.
101   unsigned Ordinal;
102
103   /// @}
104
105 protected:
106   MCFragment(FragmentType _Kind, MCSectionData *_Parent = 0);
107
108 public:
109   // Only for sentinel.
110   MCFragment();
111   virtual ~MCFragment();
112
113   FragmentType getKind() const { return Kind; }
114
115   MCSectionData *getParent() const { return Parent; }
116   void setParent(MCSectionData *Value) { Parent = Value; }
117
118   MCSymbolData *getAtom() const { return Atom; }
119   void setAtom(MCSymbolData *Value) { Atom = Value; }
120
121   unsigned getOrdinal() const { return Ordinal; }
122   void setOrdinal(unsigned Value) { Ordinal = Value; }
123
124   static bool classof(const MCFragment *O) { return true; }
125
126   virtual void dump();
127 };
128
129 class MCDataFragment : public MCFragment {
130   SmallString<32> Contents;
131
132   /// Fixups - The list of fixups in this fragment.
133   std::vector<MCAsmFixup> Fixups;
134
135 public:
136   typedef std::vector<MCAsmFixup>::const_iterator const_fixup_iterator;
137   typedef std::vector<MCAsmFixup>::iterator fixup_iterator;
138
139 public:
140   MCDataFragment(MCSectionData *SD = 0) : MCFragment(FT_Data, SD) {}
141
142   /// @name Accessors
143   /// @{
144
145   SmallString<32> &getContents() { return Contents; }
146   const SmallString<32> &getContents() const { return Contents; }
147
148   /// @}
149   /// @name Fixup Access
150   /// @{
151
152   void addFixup(MCAsmFixup Fixup) {
153     // Enforce invariant that fixups are in offset order.
154     assert((Fixups.empty() || Fixup.Offset > Fixups.back().Offset) &&
155            "Fixups must be added in order!");
156     Fixups.push_back(Fixup);
157   }
158
159   std::vector<MCAsmFixup> &getFixups() { return Fixups; }
160   const std::vector<MCAsmFixup> &getFixups() const { return Fixups; }
161
162   fixup_iterator fixup_begin() { return Fixups.begin(); }
163   const_fixup_iterator fixup_begin() const { return Fixups.begin(); }
164
165   fixup_iterator fixup_end() {return Fixups.end();}
166   const_fixup_iterator fixup_end() const {return Fixups.end();}
167
168   size_t fixup_size() const { return Fixups.size(); }
169
170   /// @}
171
172   static bool classof(const MCFragment *F) {
173     return F->getKind() == MCFragment::FT_Data;
174   }
175   static bool classof(const MCDataFragment *) { return true; }
176
177   virtual void dump();
178 };
179
180 // FIXME: This current incarnation of MCInstFragment doesn't make much sense, as
181 // it is almost entirely a duplicate of MCDataFragment. If we decide to stick
182 // with this approach (as opposed to making MCInstFragment a very light weight
183 // object with just the MCInst and a code size, then we should just change
184 // MCDataFragment to have an optional MCInst at its end.
185 class MCInstFragment : public MCFragment {
186   /// Inst - The instruction this is a fragment for.
187   MCInst Inst;
188
189   /// InstSize - The size of the currently encoded instruction.
190   SmallString<8> Code;
191
192   /// Fixups - The list of fixups in this fragment.
193   SmallVector<MCAsmFixup, 1> Fixups;
194
195 public:
196   typedef SmallVectorImpl<MCAsmFixup>::const_iterator const_fixup_iterator;
197   typedef SmallVectorImpl<MCAsmFixup>::iterator fixup_iterator;
198
199 public:
200   MCInstFragment(MCInst _Inst, MCSectionData *SD = 0)
201     : MCFragment(FT_Inst, SD), Inst(_Inst) {
202   }
203
204   /// @name Accessors
205   /// @{
206
207   SmallVectorImpl<char> &getCode() { return Code; }
208   const SmallVectorImpl<char> &getCode() const { return Code; }
209
210   unsigned getInstSize() const { return Code.size(); }
211
212   MCInst &getInst() { return Inst; }
213   const MCInst &getInst() const { return Inst; }
214
215   void setInst(MCInst Value) { Inst = Value; }
216
217   /// @}
218   /// @name Fixup Access
219   /// @{
220
221   SmallVectorImpl<MCAsmFixup> &getFixups() { return Fixups; }
222   const SmallVectorImpl<MCAsmFixup> &getFixups() const { return Fixups; }
223
224   fixup_iterator fixup_begin() { return Fixups.begin(); }
225   const_fixup_iterator fixup_begin() const { return Fixups.begin(); }
226
227   fixup_iterator fixup_end() {return Fixups.end();}
228   const_fixup_iterator fixup_end() const {return Fixups.end();}
229
230   size_t fixup_size() const { return Fixups.size(); }
231
232   /// @}
233
234   static bool classof(const MCFragment *F) {
235     return F->getKind() == MCFragment::FT_Inst;
236   }
237   static bool classof(const MCInstFragment *) { return true; }
238
239   virtual void dump();
240 };
241
242 class MCAlignFragment : public MCFragment {
243   /// Alignment - The alignment to ensure, in bytes.
244   unsigned Alignment;
245
246   /// Value - Value to use for filling padding bytes.
247   int64_t Value;
248
249   /// ValueSize - The size of the integer (in bytes) of \arg Value.
250   unsigned ValueSize;
251
252   /// MaxBytesToEmit - The maximum number of bytes to emit; if the alignment
253   /// cannot be satisfied in this width then this fragment is ignored.
254   unsigned MaxBytesToEmit;
255
256   /// EmitNops - Flag to indicate that (optimal) NOPs should be emitted instead
257   /// of using the provided value. The exact interpretation of this flag is
258   /// target dependent.
259   bool EmitNops : 1;
260
261   /// OnlyAlignAddress - Flag to indicate that this align is only used to adjust
262   /// the address space size of a section and that it should not be included as
263   /// part of the section size. This flag can only be used on the last fragment
264   /// in a section.
265   bool OnlyAlignAddress : 1;
266
267 public:
268   MCAlignFragment(unsigned _Alignment, int64_t _Value, unsigned _ValueSize,
269                   unsigned _MaxBytesToEmit, MCSectionData *SD = 0)
270     : MCFragment(FT_Align, SD), Alignment(_Alignment),
271       Value(_Value),ValueSize(_ValueSize),
272       MaxBytesToEmit(_MaxBytesToEmit), EmitNops(false),
273       OnlyAlignAddress(false) {}
274
275   /// @name Accessors
276   /// @{
277
278   unsigned getAlignment() const { return Alignment; }
279
280   int64_t getValue() const { return Value; }
281
282   unsigned getValueSize() const { return ValueSize; }
283
284   unsigned getMaxBytesToEmit() const { return MaxBytesToEmit; }
285
286   bool hasEmitNops() const { return EmitNops; }
287   void setEmitNops(bool Value) { EmitNops = Value; }
288
289   bool hasOnlyAlignAddress() const { return OnlyAlignAddress; }
290   void setOnlyAlignAddress(bool Value) { OnlyAlignAddress = Value; }
291
292   /// @}
293
294   static bool classof(const MCFragment *F) {
295     return F->getKind() == MCFragment::FT_Align;
296   }
297   static bool classof(const MCAlignFragment *) { return true; }
298
299   virtual void dump();
300 };
301
302 class MCFillFragment : public MCFragment {
303   /// Value - Value to use for filling bytes.
304   int64_t Value;
305
306   /// ValueSize - The size (in bytes) of \arg Value to use when filling, or 0 if
307   /// this is a virtual fill fragment.
308   unsigned ValueSize;
309
310   /// Size - The number of bytes to insert.
311   uint64_t Size;
312
313 public:
314   MCFillFragment(int64_t _Value, unsigned _ValueSize, uint64_t _Size,
315                  MCSectionData *SD = 0)
316     : MCFragment(FT_Fill, SD),
317       Value(_Value), ValueSize(_ValueSize), Size(_Size) {
318     assert((!ValueSize || (Size % ValueSize) == 0) &&
319            "Fill size must be a multiple of the value size!");
320   }
321
322   /// @name Accessors
323   /// @{
324
325   int64_t getValue() const { return Value; }
326
327   unsigned getValueSize() const { return ValueSize; }
328
329   uint64_t getSize() const { return Size; }
330
331   /// @}
332
333   static bool classof(const MCFragment *F) {
334     return F->getKind() == MCFragment::FT_Fill;
335   }
336   static bool classof(const MCFillFragment *) { return true; }
337
338   virtual void dump();
339 };
340
341 class MCOrgFragment : public MCFragment {
342   /// Offset - The offset this fragment should start at.
343   const MCExpr *Offset;
344
345   /// Value - Value to use for filling bytes.
346   int8_t Value;
347
348 public:
349   MCOrgFragment(const MCExpr &_Offset, int8_t _Value, MCSectionData *SD = 0)
350     : MCFragment(FT_Org, SD),
351       Offset(&_Offset), Value(_Value) {}
352
353   /// @name Accessors
354   /// @{
355
356   const MCExpr &getOffset() const { return *Offset; }
357
358   uint8_t getValue() const { return Value; }
359
360   /// @}
361
362   static bool classof(const MCFragment *F) {
363     return F->getKind() == MCFragment::FT_Org;
364   }
365   static bool classof(const MCOrgFragment *) { return true; }
366
367   virtual void dump();
368 };
369
370 // FIXME: Should this be a separate class, or just merged into MCSection? Since
371 // we anticipate the fast path being through an MCAssembler, the only reason to
372 // keep it out is for API abstraction.
373 class MCSectionData : public ilist_node<MCSectionData> {
374   friend class MCAsmLayout;
375
376   MCSectionData(const MCSectionData&);  // DO NOT IMPLEMENT
377   void operator=(const MCSectionData&); // DO NOT IMPLEMENT
378
379 public:
380   typedef iplist<MCFragment> FragmentListType;
381
382   typedef FragmentListType::const_iterator const_iterator;
383   typedef FragmentListType::iterator iterator;
384
385   typedef FragmentListType::const_reverse_iterator const_reverse_iterator;
386   typedef FragmentListType::reverse_iterator reverse_iterator;
387
388 private:
389   iplist<MCFragment> Fragments;
390   const MCSection *Section;
391
392   /// Ordinal - The section index in the assemblers section list.
393   unsigned Ordinal;
394
395   /// LayoutOrder - The index of this section in the layout order.
396   unsigned LayoutOrder;
397
398   /// Alignment - The maximum alignment seen in this section.
399   unsigned Alignment;
400
401   /// @name Assembler Backend Data
402   /// @{
403   //
404   // FIXME: This could all be kept private to the assembler implementation.
405
406   /// Address - The computed address of this section. This is ~0 until
407   /// initialized.
408   uint64_t Address;
409
410   /// HasInstructions - Whether this section has had instructions emitted into
411   /// it.
412   unsigned HasInstructions : 1;
413
414   /// @}
415
416 public:
417   // Only for use as sentinel.
418   MCSectionData();
419   MCSectionData(const MCSection &Section, MCAssembler *A = 0);
420
421   const MCSection &getSection() const { return *Section; }
422
423   unsigned getAlignment() const { return Alignment; }
424   void setAlignment(unsigned Value) { Alignment = Value; }
425
426   bool hasInstructions() const { return HasInstructions; }
427   void setHasInstructions(bool Value) { HasInstructions = Value; }
428
429   unsigned getOrdinal() const { return Ordinal; }
430   void setOrdinal(unsigned Value) { Ordinal = Value; }
431
432   unsigned getLayoutOrder() const { return LayoutOrder; }
433   void setLayoutOrder(unsigned Value) { LayoutOrder = Value; }
434
435   /// @name Fragment Access
436   /// @{
437
438   const FragmentListType &getFragmentList() const { return Fragments; }
439   FragmentListType &getFragmentList() { return Fragments; }
440
441   iterator begin() { return Fragments.begin(); }
442   const_iterator begin() const { return Fragments.begin(); }
443
444   iterator end() { return Fragments.end(); }
445   const_iterator end() const { return Fragments.end(); }
446
447   reverse_iterator rbegin() { return Fragments.rbegin(); }
448   const_reverse_iterator rbegin() const { return Fragments.rbegin(); }
449
450   reverse_iterator rend() { return Fragments.rend(); }
451   const_reverse_iterator rend() const { return Fragments.rend(); }
452
453   size_t size() const { return Fragments.size(); }
454
455   bool empty() const { return Fragments.empty(); }
456
457   void dump();
458
459   /// @}
460 };
461
462 // FIXME: Same concerns as with SectionData.
463 class MCSymbolData : public ilist_node<MCSymbolData> {
464 public:
465   const MCSymbol *Symbol;
466
467   /// Fragment - The fragment this symbol's value is relative to, if any.
468   MCFragment *Fragment;
469
470   /// Offset - The offset to apply to the fragment address to form this symbol's
471   /// value.
472   uint64_t Offset;
473
474   /// IsExternal - True if this symbol is visible outside this translation
475   /// unit.
476   unsigned IsExternal : 1;
477
478   /// IsPrivateExtern - True if this symbol is private extern.
479   unsigned IsPrivateExtern : 1;
480
481   /// CommonSize - The size of the symbol, if it is 'common', or 0.
482   //
483   // FIXME: Pack this in with other fields? We could put it in offset, since a
484   // common symbol can never get a definition.
485   uint64_t CommonSize;
486
487   /// CommonAlign - The alignment of the symbol, if it is 'common'.
488   //
489   // FIXME: Pack this in with other fields?
490   unsigned CommonAlign;
491
492   /// Flags - The Flags field is used by object file implementations to store
493   /// additional per symbol information which is not easily classified.
494   uint32_t Flags;
495
496   /// Index - Index field, for use by the object file implementation.
497   uint64_t Index;
498
499 public:
500   // Only for use as sentinel.
501   MCSymbolData();
502   MCSymbolData(const MCSymbol &_Symbol, MCFragment *_Fragment, uint64_t _Offset,
503                MCAssembler *A = 0);
504
505   /// @name Accessors
506   /// @{
507
508   const MCSymbol &getSymbol() const { return *Symbol; }
509
510   MCFragment *getFragment() const { return Fragment; }
511   void setFragment(MCFragment *Value) { Fragment = Value; }
512
513   uint64_t getOffset() const { return Offset; }
514   void setOffset(uint64_t Value) { Offset = Value; }
515
516   /// @}
517   /// @name Symbol Attributes
518   /// @{
519
520   bool isExternal() const { return IsExternal; }
521   void setExternal(bool Value) { IsExternal = Value; }
522
523   bool isPrivateExtern() const { return IsPrivateExtern; }
524   void setPrivateExtern(bool Value) { IsPrivateExtern = Value; }
525
526   /// isCommon - Is this a 'common' symbol.
527   bool isCommon() const { return CommonSize != 0; }
528
529   /// setCommon - Mark this symbol as being 'common'.
530   ///
531   /// \param Size - The size of the symbol.
532   /// \param Align - The alignment of the symbol.
533   void setCommon(uint64_t Size, unsigned Align) {
534     CommonSize = Size;
535     CommonAlign = Align;
536   }
537
538   /// getCommonSize - Return the size of a 'common' symbol.
539   uint64_t getCommonSize() const {
540     assert(isCommon() && "Not a 'common' symbol!");
541     return CommonSize;
542   }
543
544   /// getCommonAlignment - Return the alignment of a 'common' symbol.
545   unsigned getCommonAlignment() const {
546     assert(isCommon() && "Not a 'common' symbol!");
547     return CommonAlign;
548   }
549
550   /// getFlags - Get the (implementation defined) symbol flags.
551   uint32_t getFlags() const { return Flags; }
552
553   /// setFlags - Set the (implementation defined) symbol flags.
554   void setFlags(uint32_t Value) { Flags = Value; }
555
556   /// modifyFlags - Modify the flags via a mask
557   void modifyFlags(uint32_t Value, uint32_t Mask) {
558     Flags = (Flags & ~Mask) | Value;
559   }
560
561   /// getIndex - Get the (implementation defined) index.
562   uint64_t getIndex() const { return Index; }
563
564   /// setIndex - Set the (implementation defined) index.
565   void setIndex(uint64_t Value) { Index = Value; }
566
567   /// @}
568
569   void dump();
570 };
571
572 // FIXME: This really doesn't belong here. See comments below.
573 struct IndirectSymbolData {
574   MCSymbol *Symbol;
575   MCSectionData *SectionData;
576 };
577
578 class MCAssembler {
579   friend class MCAsmLayout;
580
581 public:
582   typedef iplist<MCSectionData> SectionDataListType;
583   typedef iplist<MCSymbolData> SymbolDataListType;
584
585   typedef SectionDataListType::const_iterator const_iterator;
586   typedef SectionDataListType::iterator iterator;
587
588   typedef SymbolDataListType::const_iterator const_symbol_iterator;
589   typedef SymbolDataListType::iterator symbol_iterator;
590
591   typedef std::vector<IndirectSymbolData>::const_iterator
592     const_indirect_symbol_iterator;
593   typedef std::vector<IndirectSymbolData>::iterator indirect_symbol_iterator;
594
595 private:
596   MCAssembler(const MCAssembler&);    // DO NOT IMPLEMENT
597   void operator=(const MCAssembler&); // DO NOT IMPLEMENT
598
599   MCContext &Context;
600
601   TargetAsmBackend &Backend;
602
603   MCCodeEmitter &Emitter;
604
605   raw_ostream &OS;
606
607   iplist<MCSectionData> Sections;
608
609   iplist<MCSymbolData> Symbols;
610
611   /// The map of sections to their associated assembler backend data.
612   //
613   // FIXME: Avoid this indirection?
614   DenseMap<const MCSection*, MCSectionData*> SectionMap;
615
616   /// The map of symbols to their associated assembler backend data.
617   //
618   // FIXME: Avoid this indirection?
619   DenseMap<const MCSymbol*, MCSymbolData*> SymbolMap;
620
621   std::vector<IndirectSymbolData> IndirectSymbols;
622
623   unsigned RelaxAll : 1;
624   unsigned SubsectionsViaSymbols : 1;
625
626 private:
627   /// Evaluate a fixup to a relocatable expression and the value which should be
628   /// placed into the fixup.
629   ///
630   /// \param Layout The layout to use for evaluation.
631   /// \param Fixup The fixup to evaluate.
632   /// \param DF The fragment the fixup is inside.
633   /// \param Target [out] On return, the relocatable expression the fixup
634   /// evaluates to.
635   /// \param Value [out] On return, the value of the fixup as currently layed
636   /// out.
637   /// \return Whether the fixup value was fully resolved. This is true if the
638   /// \arg Value result is fixed, otherwise the value may change due to
639   /// relocation.
640   bool EvaluateFixup(const MCAsmLayout &Layout,
641                      const MCAsmFixup &Fixup, const MCFragment *DF,
642                      MCValue &Target, uint64_t &Value) const;
643
644   /// Check whether a fixup can be satisfied, or whether it needs to be relaxed
645   /// (increased in size, in order to hold its value correctly).
646   bool FixupNeedsRelaxation(const MCAsmFixup &Fixup, const MCFragment *DF,
647                             const MCAsmLayout &Layout) const;
648
649   /// Check whether the given fragment needs relaxation.
650   bool FragmentNeedsRelaxation(const MCInstFragment *IF,
651                                const MCAsmLayout &Layout) const;
652
653   /// Compute the effective fragment size assuming it is layed out at the given
654   /// \arg SectionAddress and \arg FragmentOffset.
655   uint64_t ComputeFragmentSize(MCAsmLayout &Layout, const MCFragment &F,
656                                uint64_t SectionAddress,
657                                uint64_t FragmentOffset) const;
658
659   /// LayoutFragment - Performs layout of the given \arg Fragment; assuming that
660   /// the previous fragment has already been layed out correctly, and the parent
661   /// section has been initialized.
662   void LayoutFragment(MCAsmLayout &Layout, MCFragment &Fragment);
663
664   /// LayoutSection - Performs layout of the section referenced by the given
665   /// \arg SectionOrderIndex. The layout assumes that the previous section has
666   /// already been layed out correctly.
667   void LayoutSection(MCAsmLayout &Layout, unsigned SectionOrderIndex);
668
669   /// LayoutOnce - Perform one layout iteration and return true if any offsets
670   /// were adjusted.
671   bool LayoutOnce(MCAsmLayout &Layout);
672
673   /// FinishLayout - Finalize a layout, including fragment lowering.
674   void FinishLayout(MCAsmLayout &Layout);
675
676 public:
677   /// Find the symbol which defines the atom containing the given symbol, or
678   /// null if there is no such symbol.
679   const MCSymbolData *getAtom(const MCAsmLayout &Layout,
680                               const MCSymbolData *Symbol) const;
681
682   /// Check whether a particular symbol is visible to the linker and is required
683   /// in the symbol table, or whether it can be discarded by the assembler. This
684   /// also effects whether the assembler treats the label as potentially
685   /// defining a separate atom.
686   bool isSymbolLinkerVisible(const MCSymbolData *SD) const;
687
688   /// Emit the section contents using the given object writer.
689   //
690   // FIXME: Should MCAssembler always have a reference to the object writer?
691   void WriteSectionData(const MCSectionData *Section, const MCAsmLayout &Layout,
692                         MCObjectWriter *OW) const;
693
694 public:
695   /// Construct a new assembler instance.
696   ///
697   /// \arg OS - The stream to output to.
698   //
699   // FIXME: How are we going to parameterize this? Two obvious options are stay
700   // concrete and require clients to pass in a target like object. The other
701   // option is to make this abstract, and have targets provide concrete
702   // implementations as we do with AsmParser.
703   MCAssembler(MCContext &_Context, TargetAsmBackend &_Backend,
704               MCCodeEmitter &_Emitter, raw_ostream &OS);
705   ~MCAssembler();
706
707   MCContext &getContext() const { return Context; }
708
709   TargetAsmBackend &getBackend() const { return Backend; }
710
711   MCCodeEmitter &getEmitter() const { return Emitter; }
712
713   /// Finish - Do final processing and write the object to the output stream.
714   void Finish();
715
716   // FIXME: This does not belong here.
717   bool getSubsectionsViaSymbols() const {
718     return SubsectionsViaSymbols;
719   }
720   void setSubsectionsViaSymbols(bool Value) {
721     SubsectionsViaSymbols = Value;
722   }
723
724   bool getRelaxAll() const { return RelaxAll; }
725   void setRelaxAll(bool Value) { RelaxAll = Value; }
726
727   /// @name Section List Access
728   /// @{
729
730   const SectionDataListType &getSectionList() const { return Sections; }
731   SectionDataListType &getSectionList() { return Sections; }
732
733   iterator begin() { return Sections.begin(); }
734   const_iterator begin() const { return Sections.begin(); }
735
736   iterator end() { return Sections.end(); }
737   const_iterator end() const { return Sections.end(); }
738
739   size_t size() const { return Sections.size(); }
740
741   /// @}
742   /// @name Symbol List Access
743   /// @{
744
745   const SymbolDataListType &getSymbolList() const { return Symbols; }
746   SymbolDataListType &getSymbolList() { return Symbols; }
747
748   symbol_iterator symbol_begin() { return Symbols.begin(); }
749   const_symbol_iterator symbol_begin() const { return Symbols.begin(); }
750
751   symbol_iterator symbol_end() { return Symbols.end(); }
752   const_symbol_iterator symbol_end() const { return Symbols.end(); }
753
754   size_t symbol_size() const { return Symbols.size(); }
755
756   /// @}
757   /// @name Indirect Symbol List Access
758   /// @{
759
760   // FIXME: This is a total hack, this should not be here. Once things are
761   // factored so that the streamer has direct access to the .o writer, it can
762   // disappear.
763   std::vector<IndirectSymbolData> &getIndirectSymbols() {
764     return IndirectSymbols;
765   }
766
767   indirect_symbol_iterator indirect_symbol_begin() {
768     return IndirectSymbols.begin();
769   }
770   const_indirect_symbol_iterator indirect_symbol_begin() const {
771     return IndirectSymbols.begin();
772   }
773
774   indirect_symbol_iterator indirect_symbol_end() {
775     return IndirectSymbols.end();
776   }
777   const_indirect_symbol_iterator indirect_symbol_end() const {
778     return IndirectSymbols.end();
779   }
780
781   size_t indirect_symbol_size() const { return IndirectSymbols.size(); }
782
783   /// @}
784   /// @name Backend Data Access
785   /// @{
786
787   MCSectionData &getSectionData(const MCSection &Section) const {
788     MCSectionData *Entry = SectionMap.lookup(&Section);
789     assert(Entry && "Missing section data!");
790     return *Entry;
791   }
792
793   MCSectionData &getOrCreateSectionData(const MCSection &Section,
794                                         bool *Created = 0) {
795     MCSectionData *&Entry = SectionMap[&Section];
796
797     if (Created) *Created = !Entry;
798     if (!Entry)
799       Entry = new MCSectionData(Section, this);
800
801     return *Entry;
802   }
803
804   MCSymbolData &getSymbolData(const MCSymbol &Symbol) const {
805     MCSymbolData *Entry = SymbolMap.lookup(&Symbol);
806     assert(Entry && "Missing symbol data!");
807     return *Entry;
808   }
809
810   MCSymbolData &getOrCreateSymbolData(const MCSymbol &Symbol,
811                                       bool *Created = 0) {
812     MCSymbolData *&Entry = SymbolMap[&Symbol];
813
814     if (Created) *Created = !Entry;
815     if (!Entry)
816       Entry = new MCSymbolData(Symbol, 0, 0, this);
817
818     return *Entry;
819   }
820
821   /// @}
822
823   void dump();
824 };
825
826 } // end namespace llvm
827
828 #endif