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