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