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