MCObjectStreamer.h revision 547be2699c547b79a7735858a64921d8ccf180f7
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/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
39protected:
40  MCObjectStreamer(MCContext &Context, MCAsmBackend &TAB,
41                   raw_ostream &_OS, MCCodeEmitter *_Emitter);
42  MCObjectStreamer(MCContext &Context, MCAsmBackend &TAB,
43                   raw_ostream &_OS, MCCodeEmitter *_Emitter,
44                   MCAssembler *_Assembler);
45  ~MCObjectStreamer();
46
47  MCSectionData *getCurrentSectionData() const {
48    return CurSectionData;
49  }
50
51  MCFragment *getCurrentFragment() const;
52
53  /// Get a data fragment to write into, creating a new one if the current
54  /// fragment is not a data fragment.
55  MCDataFragment *getOrCreateDataFragment() const;
56
57  const MCExpr *AddValueSymbols(const MCExpr *Value);
58
59public:
60  MCAssembler &getAssembler() { return *Assembler; }
61
62  /// @name MCStreamer Interface
63  /// @{
64
65  virtual void EmitLabel(MCSymbol *Symbol);
66  virtual void EmitValueImpl(const MCExpr *Value, unsigned Size,
67                             unsigned AddrSpace);
68  virtual void EmitULEB128Value(const MCExpr *Value);
69  virtual void EmitSLEB128Value(const MCExpr *Value);
70  virtual void EmitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol);
71  virtual void ChangeSection(const MCSection *Section);
72  virtual void EmitInstruction(const MCInst &Inst);
73  virtual void EmitInstToFragment(const MCInst &Inst);
74  virtual void EmitValueToOffset(const MCExpr *Offset, unsigned char Value);
75  virtual void EmitDwarfAdvanceLineAddr(int64_t LineDelta,
76                                        const MCSymbol *LastLabel,
77                                        const MCSymbol *Label,
78                                        unsigned PointerSize);
79  virtual void EmitDwarfAdvanceFrameAddr(const MCSymbol *LastLabel,
80                                         const MCSymbol *Label);
81  virtual void EmitGPRel32Value(const MCExpr *Value);
82  virtual void FinishImpl();
83
84  /// @}
85};
86
87} // end namespace llvm
88
89#endif
90