MCStreamer.h revision 3353c592de08c4a7b7b282714b8044d7cfc4c6ad
1//===- MCStreamer.h - High-level Streaming Machine Code Output --*- 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// This file declares the MCStreamer class.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_MC_MCSTREAMER_H
15#define LLVM_MC_MCSTREAMER_H
16
17#include "llvm/ADT/ArrayRef.h"
18#include "llvm/ADT/SmallVector.h"
19#include "llvm/MC/MCAssembler.h"
20#include "llvm/MC/MCDirectives.h"
21#include "llvm/MC/MCDwarf.h"
22#include "llvm/MC/MCWin64EH.h"
23#include "llvm/Support/DataTypes.h"
24#include <string>
25
26namespace llvm {
27class MCAsmBackend;
28class MCCodeEmitter;
29class MCContext;
30class MCExpr;
31class MCInst;
32class MCInstPrinter;
33class MCSection;
34class MCStreamer;
35class MCSymbol;
36class StringRef;
37class Twine;
38class raw_ostream;
39class formatted_raw_ostream;
40
41typedef std::pair<const MCSection *, const MCExpr *> MCSectionSubPair;
42
43/// Target specific streamer interface. This is used so that targets can
44/// implement support for target specific assembly directives.
45///
46/// If target foo wants to use this, it should implement 3 classes:
47/// * FooTargetStreamer : public MCTargetStreamer
48/// * FooTargetAsmSreamer : public FooTargetStreamer
49/// * FooTargetELFStreamer : public FooTargetStreamer
50///
51/// FooTargetStreamer should have a pure virtual method for each directive. For
52/// example, for a ".bar symbol_name" directive, it should have
53/// virtual emitBar(const MCSymbol &Symbol) = 0;
54///
55/// The FooTargetAsmSreamer and FooTargetELFStreamer classes implement the
56/// method. The assembly streamer just prints ".bar symbol_name". The object
57/// streamer does whatever is needed to implement .bar in the object file.
58///
59/// In the assembly printer and parser the target streamer can be used by
60/// calling getTargetStreamer and casting it to FooTargetStreamer:
61///
62/// MCTargetStreamer &TS = OutStreamer.getTargetStreamer();
63/// FooTargetStreamer &ATS = static_cast<FooTargetStreamer &>(TS);
64///
65/// The base classes FooTargetAsmSreamer and FooTargetELFStreamer should *never*
66/// be treated differently. Callers should always talk to a FooTargetStreamer.
67class MCTargetStreamer {
68protected:
69  MCStreamer *Streamer;
70
71public:
72  virtual ~MCTargetStreamer();
73  void setStreamer(MCStreamer *S) { Streamer = S; }
74};
75
76// FIXME: declared here because it is used from
77// lib/CodeGen/AsmPrinter/ARMException.cpp.
78class ARMTargetStreamer : public MCTargetStreamer {
79public:
80  virtual void emitFnStart() = 0;
81  virtual void emitFnEnd() = 0;
82  virtual void emitCantUnwind() = 0;
83  virtual void emitPersonality(const MCSymbol *Personality) = 0;
84  virtual void emitHandlerData() = 0;
85  virtual void emitSetFP(unsigned FpReg, unsigned SpReg,
86                         int64_t Offset = 0) = 0;
87  virtual void emitPad(int64_t Offset) = 0;
88  virtual void emitRegSave(const SmallVectorImpl<unsigned> &RegList,
89                           bool isVector) = 0;
90};
91
92/// MCStreamer - Streaming machine code generation interface.  This interface
93/// is intended to provide a programatic interface that is very similar to the
94/// level that an assembler .s file provides.  It has callbacks to emit bytes,
95/// handle directives, etc.  The implementation of this interface retains
96/// state to know what the current section is etc.
97///
98/// There are multiple implementations of this interface: one for writing out
99/// a .s file, and implementations that write out .o files of various formats.
100///
101class MCStreamer {
102  MCContext &Context;
103  OwningPtr<MCTargetStreamer> TargetStreamer;
104
105  MCStreamer(const MCStreamer &) LLVM_DELETED_FUNCTION;
106  MCStreamer &operator=(const MCStreamer &) LLVM_DELETED_FUNCTION;
107
108  bool EmitEHFrame;
109  bool EmitDebugFrame;
110
111  std::vector<MCDwarfFrameInfo> FrameInfos;
112  MCDwarfFrameInfo *getCurrentFrameInfo();
113  MCSymbol *EmitCFICommon();
114  void EnsureValidFrame();
115
116  std::vector<MCWin64EHUnwindInfo *> W64UnwindInfos;
117  MCWin64EHUnwindInfo *CurrentW64UnwindInfo;
118  void setCurrentW64UnwindInfo(MCWin64EHUnwindInfo *Frame);
119  void EnsureValidW64UnwindInfo();
120
121  MCSymbol *LastSymbol;
122
123  // SymbolOrdering - Tracks an index to represent the order
124  // a symbol was emitted in. Zero means we did not emit that symbol.
125  DenseMap<const MCSymbol *, unsigned> SymbolOrdering;
126
127  /// SectionStack - This is stack of current and previous section
128  /// values saved by PushSection.
129  SmallVector<std::pair<MCSectionSubPair, MCSectionSubPair>, 4> SectionStack;
130
131  bool AutoInitSections;
132
133protected:
134  MCStreamer(MCContext &Ctx, MCTargetStreamer *TargetStreamer);
135
136  const MCExpr *BuildSymbolDiff(MCContext &Context, const MCSymbol *A,
137                                const MCSymbol *B);
138
139  const MCExpr *ForceExpAbs(const MCExpr *Expr);
140
141  void RecordProcStart(MCDwarfFrameInfo &Frame);
142  virtual void EmitCFIStartProcImpl(MCDwarfFrameInfo &Frame);
143  void RecordProcEnd(MCDwarfFrameInfo &Frame);
144  virtual void EmitCFIEndProcImpl(MCDwarfFrameInfo &CurFrame);
145  void EmitFrames(MCAsmBackend *MAB, bool usingCFI);
146
147  MCWin64EHUnwindInfo *getCurrentW64UnwindInfo() {
148    return CurrentW64UnwindInfo;
149  }
150  void EmitW64Tables();
151
152public:
153  virtual ~MCStreamer();
154
155  /// State management
156  ///
157  virtual void reset();
158
159  MCContext &getContext() const { return Context; }
160
161  MCTargetStreamer &getTargetStreamer() {
162    assert(TargetStreamer);
163    return *TargetStreamer;
164  }
165
166  unsigned getNumFrameInfos() { return FrameInfos.size(); }
167
168  const MCDwarfFrameInfo &getFrameInfo(unsigned i) { return FrameInfos[i]; }
169
170  ArrayRef<MCDwarfFrameInfo> getFrameInfos() const { return FrameInfos; }
171
172  unsigned getNumW64UnwindInfos() { return W64UnwindInfos.size(); }
173
174  MCWin64EHUnwindInfo &getW64UnwindInfo(unsigned i) {
175    return *W64UnwindInfos[i];
176  }
177
178  void generateCompactUnwindEncodings(MCAsmBackend *MAB);
179
180  /// @name Assembly File Formatting.
181  /// @{
182
183  /// isVerboseAsm - Return true if this streamer supports verbose assembly
184  /// and if it is enabled.
185  virtual bool isVerboseAsm() const { return false; }
186
187  /// hasRawTextSupport - Return true if this asm streamer supports emitting
188  /// unformatted text to the .s file with EmitRawText.
189  virtual bool hasRawTextSupport() const { return false; }
190
191  /// AddComment - Add a comment that can be emitted to the generated .s
192  /// file if applicable as a QoI issue to make the output of the compiler
193  /// more readable.  This only affects the MCAsmStreamer, and only when
194  /// verbose assembly output is enabled.
195  ///
196  /// If the comment includes embedded \n's, they will each get the comment
197  /// prefix as appropriate.  The added comment should not end with a \n.
198  virtual void AddComment(const Twine &T) {}
199
200  /// GetCommentOS - Return a raw_ostream that comments can be written to.
201  /// Unlike AddComment, you are required to terminate comments with \n if you
202  /// use this method.
203  virtual raw_ostream &GetCommentOS();
204
205  /// AddBlankLine - Emit a blank line to a .s file to pretty it up.
206  virtual void AddBlankLine() {}
207
208  /// @}
209
210  /// @name Symbol & Section Management
211  /// @{
212
213  /// getCurrentSection - Return the current section that the streamer is
214  /// emitting code to.
215  MCSectionSubPair getCurrentSection() const {
216    if (!SectionStack.empty())
217      return SectionStack.back().first;
218    return MCSectionSubPair();
219  }
220
221  /// getPreviousSection - Return the previous section that the streamer is
222  /// emitting code to.
223  MCSectionSubPair getPreviousSection() const {
224    if (!SectionStack.empty())
225      return SectionStack.back().second;
226    return MCSectionSubPair();
227  }
228
229  /// GetSymbolOrder - Returns an index to represent the order
230  /// a symbol was emitted in. (zero if we did not emit that symbol)
231  unsigned GetSymbolOrder(const MCSymbol *Sym) const {
232    return SymbolOrdering.lookup(Sym);
233  }
234
235  /// ChangeSection - Update streamer for a new active section.
236  ///
237  /// This is called by PopSection and SwitchSection, if the current
238  /// section changes.
239  virtual void ChangeSection(const MCSection *, const MCExpr *) = 0;
240
241  /// pushSection - Save the current and previous section on the
242  /// section stack.
243  void PushSection() {
244    SectionStack.push_back(
245        std::make_pair(getCurrentSection(), getPreviousSection()));
246  }
247
248  /// popSection - Restore the current and previous section from
249  /// the section stack.  Calls ChangeSection as needed.
250  ///
251  /// Returns false if the stack was empty.
252  bool PopSection() {
253    if (SectionStack.size() <= 1)
254      return false;
255    MCSectionSubPair oldSection = SectionStack.pop_back_val().first;
256    MCSectionSubPair curSection = SectionStack.back().first;
257
258    if (oldSection != curSection)
259      ChangeSection(curSection.first, curSection.second);
260    return true;
261  }
262
263  bool SubSection(const MCExpr *Subsection) {
264    if (SectionStack.empty())
265      return false;
266
267    SwitchSection(SectionStack.back().first.first, Subsection);
268    return true;
269  }
270
271  /// SwitchSection - Set the current section where code is being emitted to
272  /// @p Section.  This is required to update CurSection.
273  ///
274  /// This corresponds to assembler directives like .section, .text, etc.
275  void SwitchSection(const MCSection *Section, const MCExpr *Subsection = 0) {
276    assert(Section && "Cannot switch to a null section!");
277    MCSectionSubPair curSection = SectionStack.back().first;
278    SectionStack.back().second = curSection;
279    if (MCSectionSubPair(Section, Subsection) != curSection) {
280      SectionStack.back().first = MCSectionSubPair(Section, Subsection);
281      ChangeSection(Section, Subsection);
282    }
283  }
284
285  /// SwitchSectionNoChange - Set the current section where code is being
286  /// emitted to @p Section.  This is required to update CurSection. This
287  /// version does not call ChangeSection.
288  void SwitchSectionNoChange(const MCSection *Section,
289                             const MCExpr *Subsection = 0) {
290    assert(Section && "Cannot switch to a null section!");
291    MCSectionSubPair curSection = SectionStack.back().first;
292    SectionStack.back().second = curSection;
293    if (MCSectionSubPair(Section, Subsection) != curSection)
294      SectionStack.back().first = MCSectionSubPair(Section, Subsection);
295  }
296
297  /// Initialize the streamer.
298  void InitStreamer() {
299    if (AutoInitSections)
300      InitSections();
301  }
302
303  /// Tell this MCStreamer to call InitSections upon initialization.
304  void setAutoInitSections(bool AutoInitSections) {
305    this->AutoInitSections = AutoInitSections;
306  }
307
308  /// InitSections - Create the default sections and set the initial one.
309  virtual void InitSections() = 0;
310
311  /// InitToTextSection - Create a text section and switch the streamer to it.
312  virtual void InitToTextSection() = 0;
313
314  /// AssignSection - Sets the symbol's section.
315  ///
316  /// Each emitted symbol will be tracked in the ordering table,
317  /// so we can sort on them later.
318  void AssignSection(MCSymbol *Symbol, const MCSection *Section);
319
320  /// EmitLabel - Emit a label for @p Symbol into the current section.
321  ///
322  /// This corresponds to an assembler statement such as:
323  ///   foo:
324  ///
325  /// @param Symbol - The symbol to emit. A given symbol should only be
326  /// emitted as a label once, and symbols emitted as a label should never be
327  /// used in an assignment.
328  virtual void EmitLabel(MCSymbol *Symbol);
329
330  virtual void EmitDebugLabel(MCSymbol *Symbol);
331
332  virtual void EmitEHSymAttributes(const MCSymbol *Symbol, MCSymbol *EHSymbol);
333
334  /// EmitAssemblerFlag - Note in the output the specified @p Flag.
335  virtual void EmitAssemblerFlag(MCAssemblerFlag Flag) = 0;
336
337  /// EmitLinkerOptions - Emit the given list @p Options of strings as linker
338  /// options into the output.
339  virtual void EmitLinkerOptions(ArrayRef<std::string> Kind) {}
340
341  /// EmitDataRegion - Note in the output the specified region @p Kind.
342  virtual void EmitDataRegion(MCDataRegionType Kind) {}
343
344  /// EmitThumbFunc - Note in the output that the specified @p Func is
345  /// a Thumb mode function (ARM target only).
346  virtual void EmitThumbFunc(MCSymbol *Func) = 0;
347
348  /// getOrCreateSymbolData - Get symbol data for given symbol.
349  virtual MCSymbolData &getOrCreateSymbolData(MCSymbol *Symbol);
350
351  /// EmitAssignment - Emit an assignment of @p Value to @p Symbol.
352  ///
353  /// This corresponds to an assembler statement such as:
354  ///  symbol = value
355  ///
356  /// The assignment generates no code, but has the side effect of binding the
357  /// value in the current context. For the assembly streamer, this prints the
358  /// binding into the .s file.
359  ///
360  /// @param Symbol - The symbol being assigned to.
361  /// @param Value - The value for the symbol.
362  virtual void EmitAssignment(MCSymbol *Symbol, const MCExpr *Value) = 0;
363
364  /// EmitWeakReference - Emit an weak reference from @p Alias to @p Symbol.
365  ///
366  /// This corresponds to an assembler statement such as:
367  ///  .weakref alias, symbol
368  ///
369  /// @param Alias - The alias that is being created.
370  /// @param Symbol - The symbol being aliased.
371  virtual void EmitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol) = 0;
372
373  /// EmitSymbolAttribute - Add the given @p Attribute to @p Symbol.
374  virtual bool EmitSymbolAttribute(MCSymbol *Symbol,
375                                   MCSymbolAttr Attribute) = 0;
376
377  /// EmitSymbolDesc - Set the @p DescValue for the @p Symbol.
378  ///
379  /// @param Symbol - The symbol to have its n_desc field set.
380  /// @param DescValue - The value to set into the n_desc field.
381  virtual void EmitSymbolDesc(MCSymbol *Symbol, unsigned DescValue) = 0;
382
383  /// BeginCOFFSymbolDef - Start emitting COFF symbol definition
384  ///
385  /// @param Symbol - The symbol to have its External & Type fields set.
386  virtual void BeginCOFFSymbolDef(const MCSymbol *Symbol) = 0;
387
388  /// EmitCOFFSymbolStorageClass - Emit the storage class of the symbol.
389  ///
390  /// @param StorageClass - The storage class the symbol should have.
391  virtual void EmitCOFFSymbolStorageClass(int StorageClass) = 0;
392
393  /// EmitCOFFSymbolType - Emit the type of the symbol.
394  ///
395  /// @param Type - A COFF type identifier (see COFF::SymbolType in X86COFF.h)
396  virtual void EmitCOFFSymbolType(int Type) = 0;
397
398  /// EndCOFFSymbolDef - Marks the end of the symbol definition.
399  virtual void EndCOFFSymbolDef() = 0;
400
401  /// EmitCOFFSecRel32 - Emits a COFF section relative relocation.
402  ///
403  /// @param Symbol - Symbol the section relative realocation should point to.
404  virtual void EmitCOFFSecRel32(MCSymbol const *Symbol);
405
406  /// EmitELFSize - Emit an ELF .size directive.
407  ///
408  /// This corresponds to an assembler statement such as:
409  ///  .size symbol, expression
410  ///
411  virtual void EmitELFSize(MCSymbol *Symbol, const MCExpr *Value) = 0;
412
413  /// EmitCommonSymbol - Emit a common symbol.
414  ///
415  /// @param Symbol - The common symbol to emit.
416  /// @param Size - The size of the common symbol.
417  /// @param ByteAlignment - The alignment of the symbol if
418  /// non-zero. This must be a power of 2.
419  virtual void EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
420                                unsigned ByteAlignment) = 0;
421
422  /// EmitLocalCommonSymbol - Emit a local common (.lcomm) symbol.
423  ///
424  /// @param Symbol - The common symbol to emit.
425  /// @param Size - The size of the common symbol.
426  /// @param ByteAlignment - The alignment of the common symbol in bytes.
427  virtual void EmitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size,
428                                     unsigned ByteAlignment) = 0;
429
430  /// EmitZerofill - Emit the zerofill section and an optional symbol.
431  ///
432  /// @param Section - The zerofill section to create and or to put the symbol
433  /// @param Symbol - The zerofill symbol to emit, if non-NULL.
434  /// @param Size - The size of the zerofill symbol.
435  /// @param ByteAlignment - The alignment of the zerofill symbol if
436  /// non-zero. This must be a power of 2 on some targets.
437  virtual void EmitZerofill(const MCSection *Section, MCSymbol *Symbol = 0,
438                            uint64_t Size = 0, unsigned ByteAlignment = 0) = 0;
439
440  /// EmitTBSSSymbol - Emit a thread local bss (.tbss) symbol.
441  ///
442  /// @param Section - The thread local common section.
443  /// @param Symbol - The thread local common symbol to emit.
444  /// @param Size - The size of the symbol.
445  /// @param ByteAlignment - The alignment of the thread local common symbol
446  /// if non-zero.  This must be a power of 2 on some targets.
447  virtual void EmitTBSSSymbol(const MCSection *Section, MCSymbol *Symbol,
448                              uint64_t Size, unsigned ByteAlignment = 0) = 0;
449
450  /// @}
451  /// @name Generating Data
452  /// @{
453
454  /// EmitBytes - Emit the bytes in \p Data into the output.
455  ///
456  /// This is used to implement assembler directives such as .byte, .ascii,
457  /// etc.
458  virtual void EmitBytes(StringRef Data) = 0;
459
460  /// EmitValue - Emit the expression @p Value into the output as a native
461  /// integer of the given @p Size bytes.
462  ///
463  /// This is used to implement assembler directives such as .word, .quad,
464  /// etc.
465  ///
466  /// @param Value - The value to emit.
467  /// @param Size - The size of the integer (in bytes) to emit. This must
468  /// match a native machine width.
469  virtual void EmitValueImpl(const MCExpr *Value, unsigned Size) = 0;
470
471  void EmitValue(const MCExpr *Value, unsigned Size);
472
473  /// EmitIntValue - Special case of EmitValue that avoids the client having
474  /// to pass in a MCExpr for constant integers.
475  virtual void EmitIntValue(uint64_t Value, unsigned Size);
476
477  /// EmitAbsValue - Emit the Value, but try to avoid relocations. On MachO
478  /// this is done by producing
479  /// foo = value
480  /// .long foo
481  void EmitAbsValue(const MCExpr *Value, unsigned Size);
482
483  virtual void EmitULEB128Value(const MCExpr *Value) = 0;
484
485  virtual void EmitSLEB128Value(const MCExpr *Value) = 0;
486
487  /// EmitULEB128Value - Special case of EmitULEB128Value that avoids the
488  /// client having to pass in a MCExpr for constant integers.
489  void EmitULEB128IntValue(uint64_t Value, unsigned Padding = 0);
490
491  /// EmitSLEB128Value - Special case of EmitSLEB128Value that avoids the
492  /// client having to pass in a MCExpr for constant integers.
493  void EmitSLEB128IntValue(int64_t Value);
494
495  /// EmitSymbolValue - Special case of EmitValue that avoids the client
496  /// having to pass in a MCExpr for MCSymbols.
497  void EmitSymbolValue(const MCSymbol *Sym, unsigned Size);
498
499  /// EmitGPRel64Value - Emit the expression @p Value into the output as a
500  /// gprel64 (64-bit GP relative) value.
501  ///
502  /// This is used to implement assembler directives such as .gpdword on
503  /// targets that support them.
504  virtual void EmitGPRel64Value(const MCExpr *Value);
505
506  /// EmitGPRel32Value - Emit the expression @p Value into the output as a
507  /// gprel32 (32-bit GP relative) value.
508  ///
509  /// This is used to implement assembler directives such as .gprel32 on
510  /// targets that support them.
511  virtual void EmitGPRel32Value(const MCExpr *Value);
512
513  /// EmitFill - Emit NumBytes bytes worth of the value specified by
514  /// FillValue.  This implements directives such as '.space'.
515  virtual void EmitFill(uint64_t NumBytes, uint8_t FillValue);
516
517  /// \brief Emit NumBytes worth of zeros.
518  /// This function properly handles data in virtual sections.
519  virtual void EmitZeros(uint64_t NumBytes);
520
521  /// EmitValueToAlignment - Emit some number of copies of @p Value until
522  /// the byte alignment @p ByteAlignment is reached.
523  ///
524  /// If the number of bytes need to emit for the alignment is not a multiple
525  /// of @p ValueSize, then the contents of the emitted fill bytes is
526  /// undefined.
527  ///
528  /// This used to implement the .align assembler directive.
529  ///
530  /// @param ByteAlignment - The alignment to reach. This must be a power of
531  /// two on some targets.
532  /// @param Value - The value to use when filling bytes.
533  /// @param ValueSize - The size of the integer (in bytes) to emit for
534  /// @p Value. This must match a native machine width.
535  /// @param MaxBytesToEmit - The maximum numbers of bytes to emit, or 0. If
536  /// the alignment cannot be reached in this many bytes, no bytes are
537  /// emitted.
538  virtual void EmitValueToAlignment(unsigned ByteAlignment, int64_t Value = 0,
539                                    unsigned ValueSize = 1,
540                                    unsigned MaxBytesToEmit = 0) = 0;
541
542  /// EmitCodeAlignment - Emit nops until the byte alignment @p ByteAlignment
543  /// is reached.
544  ///
545  /// This used to align code where the alignment bytes may be executed.  This
546  /// can emit different bytes for different sizes to optimize execution.
547  ///
548  /// @param ByteAlignment - The alignment to reach. This must be a power of
549  /// two on some targets.
550  /// @param MaxBytesToEmit - The maximum numbers of bytes to emit, or 0. If
551  /// the alignment cannot be reached in this many bytes, no bytes are
552  /// emitted.
553  virtual void EmitCodeAlignment(unsigned ByteAlignment,
554                                 unsigned MaxBytesToEmit = 0) = 0;
555
556  /// EmitValueToOffset - Emit some number of copies of @p Value until the
557  /// byte offset @p Offset is reached.
558  ///
559  /// This is used to implement assembler directives such as .org.
560  ///
561  /// @param Offset - The offset to reach. This may be an expression, but the
562  /// expression must be associated with the current section.
563  /// @param Value - The value to use when filling bytes.
564  /// @return false on success, true if the offset was invalid.
565  virtual bool EmitValueToOffset(const MCExpr *Offset,
566                                 unsigned char Value = 0) = 0;
567
568  /// @}
569
570  /// EmitFileDirective - Switch to a new logical file.  This is used to
571  /// implement the '.file "foo.c"' assembler directive.
572  virtual void EmitFileDirective(StringRef Filename) = 0;
573
574  /// EmitDwarfFileDirective - Associate a filename with a specified logical
575  /// file number.  This implements the DWARF2 '.file 4 "foo.c"' assembler
576  /// directive.
577  virtual bool EmitDwarfFileDirective(unsigned FileNo, StringRef Directory,
578                                      StringRef Filename, unsigned CUID = 0);
579
580  /// EmitDwarfLocDirective - This implements the DWARF2
581  // '.loc fileno lineno ...' assembler directive.
582  virtual void EmitDwarfLocDirective(unsigned FileNo, unsigned Line,
583                                     unsigned Column, unsigned Flags,
584                                     unsigned Isa, unsigned Discriminator,
585                                     StringRef FileName);
586
587  virtual void EmitDwarfAdvanceLineAddr(int64_t LineDelta,
588                                        const MCSymbol *LastLabel,
589                                        const MCSymbol *Label,
590                                        unsigned PointerSize) = 0;
591
592  virtual void EmitDwarfAdvanceFrameAddr(const MCSymbol *LastLabel,
593                                         const MCSymbol *Label) {}
594
595  void EmitDwarfSetLineAddr(int64_t LineDelta, const MCSymbol *Label,
596                            int PointerSize);
597
598  virtual void EmitCompactUnwindEncoding(uint32_t CompactUnwindEncoding);
599  virtual void EmitCFISections(bool EH, bool Debug);
600  void EmitCFIStartProc();
601  void EmitCFIEndProc();
602  virtual void EmitCFIDefCfa(int64_t Register, int64_t Offset);
603  virtual void EmitCFIDefCfaOffset(int64_t Offset);
604  virtual void EmitCFIDefCfaRegister(int64_t Register);
605  virtual void EmitCFIOffset(int64_t Register, int64_t Offset);
606  virtual void EmitCFIPersonality(const MCSymbol *Sym, unsigned Encoding);
607  virtual void EmitCFILsda(const MCSymbol *Sym, unsigned Encoding);
608  virtual void EmitCFIRememberState();
609  virtual void EmitCFIRestoreState();
610  virtual void EmitCFISameValue(int64_t Register);
611  virtual void EmitCFIRestore(int64_t Register);
612  virtual void EmitCFIRelOffset(int64_t Register, int64_t Offset);
613  virtual void EmitCFIAdjustCfaOffset(int64_t Adjustment);
614  virtual void EmitCFIEscape(StringRef Values);
615  virtual void EmitCFISignalFrame();
616  virtual void EmitCFIUndefined(int64_t Register);
617  virtual void EmitCFIRegister(int64_t Register1, int64_t Register2);
618  virtual void EmitCFIWindowSave();
619
620  virtual void EmitWin64EHStartProc(const MCSymbol *Symbol);
621  virtual void EmitWin64EHEndProc();
622  virtual void EmitWin64EHStartChained();
623  virtual void EmitWin64EHEndChained();
624  virtual void EmitWin64EHHandler(const MCSymbol *Sym, bool Unwind,
625                                  bool Except);
626  virtual void EmitWin64EHHandlerData();
627  virtual void EmitWin64EHPushReg(unsigned Register);
628  virtual void EmitWin64EHSetFrame(unsigned Register, unsigned Offset);
629  virtual void EmitWin64EHAllocStack(unsigned Size);
630  virtual void EmitWin64EHSaveReg(unsigned Register, unsigned Offset);
631  virtual void EmitWin64EHSaveXMM(unsigned Register, unsigned Offset);
632  virtual void EmitWin64EHPushFrame(bool Code);
633  virtual void EmitWin64EHEndProlog();
634
635  /// EmitInstruction - Emit the given @p Instruction into the current
636  /// section.
637  virtual void EmitInstruction(const MCInst &Inst) = 0;
638
639  /// \brief Set the bundle alignment mode from now on in the section.
640  /// The argument is the power of 2 to which the alignment is set. The
641  /// value 0 means turn the bundle alignment off.
642  virtual void EmitBundleAlignMode(unsigned AlignPow2) = 0;
643
644  /// \brief The following instructions are a bundle-locked group.
645  ///
646  /// \param AlignToEnd - If true, the bundle-locked group will be aligned to
647  ///                     the end of a bundle.
648  virtual void EmitBundleLock(bool AlignToEnd) = 0;
649
650  /// \brief Ends a bundle-locked group.
651  virtual void EmitBundleUnlock() = 0;
652
653  /// EmitRawText - If this file is backed by a assembly streamer, this dumps
654  /// the specified string in the output .s file.  This capability is
655  /// indicated by the hasRawTextSupport() predicate.  By default this aborts.
656  virtual void EmitRawText(StringRef String);
657  void EmitRawText(const Twine &String);
658
659  /// Flush - Causes any cached state to be written out.
660  virtual void Flush() {}
661
662  /// FinishImpl - Streamer specific finalization.
663  virtual void FinishImpl() = 0;
664  /// Finish - Finish emission of machine code.
665  void Finish();
666};
667
668/// createNullStreamer - Create a dummy machine code streamer, which does
669/// nothing. This is useful for timing the assembler front end.
670MCStreamer *createNullStreamer(MCContext &Ctx);
671
672/// createAsmStreamer - Create a machine code streamer which will print out
673/// assembly for the native target, suitable for compiling with a native
674/// assembler.
675///
676/// \param InstPrint - If given, the instruction printer to use. If not given
677/// the MCInst representation will be printed.  This method takes ownership of
678/// InstPrint.
679///
680/// \param CE - If given, a code emitter to use to show the instruction
681/// encoding inline with the assembly. This method takes ownership of \p CE.
682///
683/// \param TAB - If given, a target asm backend to use to show the fixup
684/// information in conjunction with encoding information. This method takes
685/// ownership of \p TAB.
686///
687/// \param ShowInst - Whether to show the MCInst representation inline with
688/// the assembly.
689MCStreamer *createAsmStreamer(MCContext &Ctx, MCTargetStreamer *TargetStreamer,
690                              formatted_raw_ostream &OS, bool isVerboseAsm,
691                              bool useLoc, bool useCFI, bool useDwarfDirectory,
692                              MCInstPrinter *InstPrint = 0,
693                              MCCodeEmitter *CE = 0, MCAsmBackend *TAB = 0,
694                              bool ShowInst = false);
695
696/// createMachOStreamer - Create a machine code streamer which will generate
697/// Mach-O format object files.
698///
699/// Takes ownership of \p TAB and \p CE.
700MCStreamer *createMachOStreamer(MCContext &Ctx, MCAsmBackend &TAB,
701                                raw_ostream &OS, MCCodeEmitter *CE,
702                                bool RelaxAll = false);
703
704/// createWinCOFFStreamer - Create a machine code streamer which will
705/// generate Microsoft COFF format object files.
706///
707/// Takes ownership of \p TAB and \p CE.
708MCStreamer *createWinCOFFStreamer(MCContext &Ctx, MCAsmBackend &TAB,
709                                  MCCodeEmitter &CE, raw_ostream &OS,
710                                  bool RelaxAll = false);
711
712/// createELFStreamer - Create a machine code streamer which will generate
713/// ELF format object files.
714MCStreamer *createELFStreamer(MCContext &Ctx, MCTargetStreamer *TargetStreamer,
715                              MCAsmBackend &TAB, raw_ostream &OS,
716                              MCCodeEmitter *CE, bool RelaxAll,
717                              bool NoExecStack);
718
719/// createPureStreamer - Create a machine code streamer which will generate
720/// "pure" MC object files, for use with MC-JIT and testing tools.
721///
722/// Takes ownership of \p TAB and \p CE.
723MCStreamer *createPureStreamer(MCContext &Ctx, MCAsmBackend &TAB,
724                               raw_ostream &OS, MCCodeEmitter *CE);
725
726} // end namespace llvm
727
728#endif
729