MCObjectStreamer.h revision ef76b273f96d99a4a260f3dcadde8fbb96256cf3
1bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant//===- MCObjectStreamer.h - MCStreamer Object File Interface ----*- C++ -*-===//
2bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant//
3f5256e16dfc425c1d466f6308d4026d529ce9e0bHoward Hinnant//                     The LLVM Compiler Infrastructure
4bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant//
5b64f8b07c104c6cc986570ac8ee0ed16a9f23976Howard Hinnant// This file is distributed under the University of Illinois Open Source
6b64f8b07c104c6cc986570ac8ee0ed16a9f23976Howard Hinnant// License. See LICENSE.TXT for details.
7bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant//
8bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant//===----------------------------------------------------------------------===//
9bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant
10bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant#ifndef LLVM_MC_MCOBJECTSTREAMER_H
11bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant#define LLVM_MC_MCOBJECTSTREAMER_H
12bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant
13#include "llvm/MC/MCStreamer.h"
14
15namespace llvm {
16class MCAssembler;
17class MCCodeEmitter;
18class MCSectionData;
19class MCExpr;
20class MCFragment;
21class MCDataFragment;
22class MCAsmBackend;
23class raw_ostream;
24
25/// \brief Streaming object file generation interface.
26///
27/// This class provides an implementation of the MCStreamer interface which is
28/// suitable for use with the assembler backend. Specific object file formats
29/// are expected to subclass this interface to implement directives specific
30/// to that file format or custom semantics expected by the object writer
31/// implementation.
32class MCObjectStreamer : public MCStreamer {
33  MCAssembler *Assembler;
34  MCSectionData *CurSectionData;
35
36  virtual void EmitInstToData(const MCInst &Inst) = 0;
37  virtual void EmitCFIStartProcImpl(MCDwarfFrameInfo &Frame);
38  virtual void EmitCFIEndProcImpl(MCDwarfFrameInfo &Frame);
39
40protected:
41  MCObjectStreamer(MCContext &Context, MCAsmBackend &TAB,
42                   raw_ostream &_OS, MCCodeEmitter *_Emitter);
43  MCObjectStreamer(MCContext &Context, MCAsmBackend &TAB,
44                   raw_ostream &_OS, MCCodeEmitter *_Emitter,
45                   MCAssembler *_Assembler);
46  ~MCObjectStreamer();
47
48  MCSectionData *getCurrentSectionData() const {
49    return CurSectionData;
50  }
51
52  MCFragment *getCurrentFragment() const;
53
54  /// Get a data fragment to write into, creating a new one if the current
55  /// fragment is not a data fragment.
56  MCDataFragment *getOrCreateDataFragment() const;
57
58  const MCExpr *AddValueSymbols(const MCExpr *Value);
59
60public:
61  MCAssembler &getAssembler() { return *Assembler; }
62
63  /// @name MCStreamer Interface
64  /// @{
65
66  virtual void EmitLabel(MCSymbol *Symbol);
67  virtual void EmitAssignment(MCSymbol *Symbol, const MCExpr *Value);
68  virtual void EmitValueImpl(const MCExpr *Value, unsigned Size,
69                             unsigned AddrSpace);
70  virtual void EmitULEB128Value(const MCExpr *Value);
71  virtual void EmitSLEB128Value(const MCExpr *Value);
72  virtual void EmitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol);
73  virtual void ChangeSection(const MCSection *Section);
74  virtual void EmitInstruction(const MCInst &Inst);
75  virtual void EmitInstToFragment(const MCInst &Inst);
76  virtual void EmitBytes(StringRef Data, unsigned AddrSpace);
77  virtual void EmitValueToAlignment(unsigned ByteAlignment,
78                                    int64_t Value = 0,
79                                    unsigned ValueSize = 1,
80                                    unsigned MaxBytesToEmit = 0);
81  virtual void EmitCodeAlignment(unsigned ByteAlignment,
82                                 unsigned MaxBytesToEmit = 0);
83  virtual bool EmitValueToOffset(const MCExpr *Offset, unsigned char Value);
84  virtual void EmitDwarfAdvanceLineAddr(int64_t LineDelta,
85                                        const MCSymbol *LastLabel,
86                                        const MCSymbol *Label,
87                                        unsigned PointerSize);
88  virtual void EmitDwarfAdvanceFrameAddr(const MCSymbol *LastLabel,
89                                         const MCSymbol *Label);
90  virtual void EmitGPRel32Value(const MCExpr *Value);
91  virtual void EmitGPRel64Value(const MCExpr *Value);
92  virtual void EmitFill(uint64_t NumBytes, uint8_t FillValue,
93                        unsigned AddrSpace);
94  virtual void FinishImpl();
95
96  /// @}
97};
98
99} // end namespace llvm
100
101#endif
102