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