Construct the MCStreamer before constructing the MCTargetStreamer.
[oota-llvm.git] / include / llvm / MC / MCObjectStreamer.h
1 //===- MCObjectStreamer.h - MCStreamer Object File Interface ----*- 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_MCOBJECTSTREAMER_H
11 #define LLVM_MC_MCOBJECTSTREAMER_H
12
13 #include "llvm/MC/MCAssembler.h"
14 #include "llvm/MC/MCStreamer.h"
15
16 namespace llvm {
17 class MCAssembler;
18 class MCCodeEmitter;
19 class MCSectionData;
20 class MCExpr;
21 class MCFragment;
22 class MCDataFragment;
23 class MCAsmBackend;
24 class raw_ostream;
25
26 /// \brief Streaming object file generation interface.
27 ///
28 /// This class provides an implementation of the MCStreamer interface which is
29 /// suitable for use with the assembler backend. Specific object file formats
30 /// are expected to subclass this interface to implement directives specific
31 /// to that file format or custom semantics expected by the object writer
32 /// implementation.
33 class MCObjectStreamer : public MCStreamer {
34   MCAssembler *Assembler;
35   MCSectionData *CurSectionData;
36   MCSectionData::iterator CurInsertionPoint;
37
38   virtual void EmitInstToData(const MCInst &Inst) = 0;
39   virtual void EmitCFIStartProcImpl(MCDwarfFrameInfo &Frame);
40   virtual void EmitCFIEndProcImpl(MCDwarfFrameInfo &Frame);
41
42 protected:
43   MCObjectStreamer(MCContext &Context, MCAsmBackend &TAB, raw_ostream &_OS,
44                    MCCodeEmitter *_Emitter);
45   MCObjectStreamer(MCContext &Context, MCAsmBackend &TAB, raw_ostream &_OS,
46                    MCCodeEmitter *_Emitter, MCAssembler *_Assembler);
47   ~MCObjectStreamer();
48
49 public:
50   /// state management
51   virtual void reset();
52
53 protected:
54   MCSectionData *getCurrentSectionData() const {
55     return CurSectionData;
56   }
57
58   MCFragment *getCurrentFragment() const;
59
60   void insert(MCFragment *F) const {
61     CurSectionData->getFragmentList().insert(CurInsertionPoint, F);
62     F->setParent(CurSectionData);
63   }
64
65   /// Get a data fragment to write into, creating a new one if the current
66   /// fragment is not a data fragment.
67   MCDataFragment *getOrCreateDataFragment() const;
68
69   const MCExpr *AddValueSymbols(const MCExpr *Value);
70
71 public:
72   MCAssembler &getAssembler() { return *Assembler; }
73
74   /// @name MCStreamer Interface
75   /// @{
76
77   virtual void EmitLabel(MCSymbol *Symbol);
78   virtual void EmitDebugLabel(MCSymbol *Symbol);
79   virtual void EmitAssignment(MCSymbol *Symbol, const MCExpr *Value);
80   virtual void EmitValueImpl(const MCExpr *Value, unsigned Size);
81   virtual void EmitULEB128Value(const MCExpr *Value);
82   virtual void EmitSLEB128Value(const MCExpr *Value);
83   virtual void EmitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol);
84   virtual void ChangeSection(const MCSection *Section,
85                              const MCExpr *Subsection);
86   virtual void EmitInstruction(const MCInst &Inst);
87
88   /// \brief Emit an instruction to a special fragment, because this instruction
89   /// can change its size during relaxation.
90   virtual void EmitInstToFragment(const MCInst &Inst);
91
92   virtual void EmitBundleAlignMode(unsigned AlignPow2);
93   virtual void EmitBundleLock(bool AlignToEnd);
94   virtual void EmitBundleUnlock();
95   virtual void EmitBytes(StringRef Data);
96   virtual void EmitValueToAlignment(unsigned ByteAlignment,
97                                     int64_t Value = 0,
98                                     unsigned ValueSize = 1,
99                                     unsigned MaxBytesToEmit = 0);
100   virtual void EmitCodeAlignment(unsigned ByteAlignment,
101                                  unsigned MaxBytesToEmit = 0);
102   virtual bool EmitValueToOffset(const MCExpr *Offset, unsigned char Value);
103   virtual void EmitDwarfLocDirective(unsigned FileNo, unsigned Line,
104                                      unsigned Column, unsigned Flags,
105                                      unsigned Isa, unsigned Discriminator,
106                                      StringRef FileName);
107   virtual void EmitDwarfAdvanceLineAddr(int64_t LineDelta,
108                                         const MCSymbol *LastLabel,
109                                         const MCSymbol *Label,
110                                         unsigned PointerSize);
111   virtual void EmitDwarfAdvanceFrameAddr(const MCSymbol *LastLabel,
112                                          const MCSymbol *Label);
113   virtual void EmitGPRel32Value(const MCExpr *Value);
114   virtual void EmitGPRel64Value(const MCExpr *Value);
115   virtual void EmitFill(uint64_t NumBytes, uint8_t FillValue);
116   virtual void EmitZeros(uint64_t NumBytes);
117   virtual void FinishImpl();
118 };
119
120 } // end namespace llvm
121
122 #endif