]> CyberLeo.Net >> Repos - FreeBSD/releng/10.2.git/blob - contrib/llvm/include/llvm/MC/MCObjectStreamer.h
- Copy stable/10@285827 to releng/10.2 in preparation for 10.2-RC1
[FreeBSD/releng/10.2.git] / contrib / llvm / 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, MCTargetStreamer *TargetStreamer,
44                    MCAsmBackend &TAB, raw_ostream &_OS,
45                    MCCodeEmitter *_Emitter);
46   MCObjectStreamer(MCContext &Context, MCTargetStreamer *TargetStreamer,
47                    MCAsmBackend &TAB, raw_ostream &_OS, MCCodeEmitter *_Emitter,
48                    MCAssembler *_Assembler);
49   ~MCObjectStreamer();
50
51 public:
52   /// state management
53   virtual void reset();
54
55 protected:
56   MCSectionData *getCurrentSectionData() const {
57     return CurSectionData;
58   }
59
60   MCFragment *getCurrentFragment() const;
61
62   void insert(MCFragment *F) const {
63     CurSectionData->getFragmentList().insert(CurInsertionPoint, F);
64     F->setParent(CurSectionData);
65   }
66
67   /// Get a data fragment to write into, creating a new one if the current
68   /// fragment is not a data fragment.
69   MCDataFragment *getOrCreateDataFragment() const;
70
71   const MCExpr *AddValueSymbols(const MCExpr *Value);
72
73 public:
74   MCAssembler &getAssembler() { return *Assembler; }
75
76   /// @name MCStreamer Interface
77   /// @{
78
79   virtual void EmitLabel(MCSymbol *Symbol);
80   virtual void EmitDebugLabel(MCSymbol *Symbol);
81   virtual void EmitAssignment(MCSymbol *Symbol, const MCExpr *Value);
82   virtual void EmitValueImpl(const MCExpr *Value, unsigned Size);
83   virtual void EmitULEB128Value(const MCExpr *Value);
84   virtual void EmitSLEB128Value(const MCExpr *Value);
85   virtual void EmitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol);
86   virtual void ChangeSection(const MCSection *Section,
87                              const MCExpr *Subsection);
88   virtual void EmitInstruction(const MCInst &Inst);
89
90   /// \brief Emit an instruction to a special fragment, because this instruction
91   /// can change its size during relaxation.
92   virtual void EmitInstToFragment(const MCInst &Inst);
93
94   virtual void EmitBundleAlignMode(unsigned AlignPow2);
95   virtual void EmitBundleLock(bool AlignToEnd);
96   virtual void EmitBundleUnlock();
97   virtual void EmitBytes(StringRef Data);
98   virtual void EmitValueToAlignment(unsigned ByteAlignment,
99                                     int64_t Value = 0,
100                                     unsigned ValueSize = 1,
101                                     unsigned MaxBytesToEmit = 0);
102   virtual void EmitCodeAlignment(unsigned ByteAlignment,
103                                  unsigned MaxBytesToEmit = 0);
104   virtual bool EmitValueToOffset(const MCExpr *Offset, unsigned char Value);
105   virtual void EmitDwarfLocDirective(unsigned FileNo, unsigned Line,
106                                      unsigned Column, unsigned Flags,
107                                      unsigned Isa, unsigned Discriminator,
108                                      StringRef FileName);
109   virtual void EmitDwarfAdvanceLineAddr(int64_t LineDelta,
110                                         const MCSymbol *LastLabel,
111                                         const MCSymbol *Label,
112                                         unsigned PointerSize);
113   virtual void EmitDwarfAdvanceFrameAddr(const MCSymbol *LastLabel,
114                                          const MCSymbol *Label);
115   virtual void EmitGPRel32Value(const MCExpr *Value);
116   virtual void EmitGPRel64Value(const MCExpr *Value);
117   virtual void EmitFill(uint64_t NumBytes, uint8_t FillValue);
118   virtual void EmitZeros(uint64_t NumBytes);
119   virtual void FinishImpl();
120 };
121
122 } // end namespace llvm
123
124 #endif