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