1894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman//===- MCObjectStreamer.h - MCStreamer Object File Interface ----*- C++ -*-===//
2894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman//
3894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman//                     The LLVM Compiler Infrastructure
4894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman//
5894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// This file is distributed under the University of Illinois Open Source
6894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// License. See LICENSE.TXT for details.
7894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman//
8894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman//===----------------------------------------------------------------------===//
9894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
10894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman#ifndef LLVM_MC_MCOBJECTSTREAMER_H
11894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman#define LLVM_MC_MCOBJECTSTREAMER_H
12894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
13894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman#include "llvm/MC/MCStreamer.h"
14894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
15894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumannamespace llvm {
16894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumanclass MCAssembler;
17894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumanclass MCCodeEmitter;
18894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumanclass MCSectionData;
19894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumanclass MCExpr;
20894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumanclass MCFragment;
21894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumanclass MCDataFragment;
2219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Baumanclass MCAsmBackend;
23894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumanclass raw_ostream;
24894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
25894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman/// \brief Streaming object file generation interface.
26894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman///
27894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman/// This class provides an implementation of the MCStreamer interface which is
28894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman/// suitable for use with the assembler backend. Specific object file formats
29894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman/// are expected to subclass this interface to implement directives specific
30894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman/// to that file format or custom semantics expected by the object writer
31894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman/// implementation.
32894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumanclass MCObjectStreamer : public MCStreamer {
33894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  MCAssembler *Assembler;
34894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  MCSectionData *CurSectionData;
35894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
3619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  virtual void EmitInstToData(const MCInst &Inst) = 0;
3719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
38894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumanprotected:
3919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  MCObjectStreamer(MCContext &Context, MCAsmBackend &TAB,
40894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman                   raw_ostream &_OS, MCCodeEmitter *_Emitter);
4119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  MCObjectStreamer(MCContext &Context, MCAsmBackend &TAB,
4219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman                   raw_ostream &_OS, MCCodeEmitter *_Emitter,
4319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman                   MCAssembler *_Assembler);
44894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  ~MCObjectStreamer();
45894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
46894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  MCSectionData *getCurrentSectionData() const {
47894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    return CurSectionData;
48894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  }
49894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
50894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  MCFragment *getCurrentFragment() const;
51894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
52894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// Get a data fragment to write into, creating a new one if the current
53894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// fragment is not a data fragment.
54894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  MCDataFragment *getOrCreateDataFragment() const;
55894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
56894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  const MCExpr *AddValueSymbols(const MCExpr *Value);
57894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
58894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumanpublic:
59894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  MCAssembler &getAssembler() { return *Assembler; }
60894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
61894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// @name MCStreamer Interface
62894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// @{
63894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
6419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  virtual void EmitLabel(MCSymbol *Symbol);
6519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  virtual void EmitValueImpl(const MCExpr *Value, unsigned Size,
6619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman                             unsigned AddrSpace);
6719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  virtual void EmitULEB128Value(const MCExpr *Value);
6819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  virtual void EmitSLEB128Value(const MCExpr *Value);
6919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  virtual void EmitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol);
7019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  virtual void ChangeSection(const MCSection *Section);
7119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  virtual void EmitInstruction(const MCInst &Inst);
7219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  virtual void EmitInstToFragment(const MCInst &Inst);
7319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  virtual void EmitValueToOffset(const MCExpr *Offset, unsigned char Value);
7419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  virtual void EmitDwarfAdvanceLineAddr(int64_t LineDelta,
7519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman                                        const MCSymbol *LastLabel,
7619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman                                        const MCSymbol *Label,
7719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman                                        unsigned PointerSize);
7819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  virtual void EmitDwarfAdvanceFrameAddr(const MCSymbol *LastLabel,
7919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman                                         const MCSymbol *Label);
80894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  virtual void Finish();
81894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
82894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// @}
83894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman};
84894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
85894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman} // end namespace llvm
86894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
87894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman#endif
88