MCStreamer.h revision df39be6cb4eb44011db3d3e86f8fe463f81ce127
1//===- MCStreamer.h - High-level Streaming Machine Code Output --*- C++ -*-===//
2//
3//                     The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file declares the MCStreamer class.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_MC_MCSTREAMER_H
15#define LLVM_MC_MCSTREAMER_H
16
17#include "llvm/ADT/ArrayRef.h"
18#include "llvm/ADT/SmallVector.h"
19#include "llvm/MC/MCAssembler.h"
20#include "llvm/MC/MCDirectives.h"
21#include "llvm/MC/MCDwarf.h"
22#include "llvm/MC/MCWin64EH.h"
23#include "llvm/Support/DataTypes.h"
24#include <string>
25
26namespace llvm {
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    /// EmitZeros - Emit NumBytes worth of zeros.  This is a convenience
476    /// function that just wraps EmitFill.
477    void EmitZeros(uint64_t NumBytes, unsigned AddrSpace = 0) {
478      EmitFill(NumBytes, 0, AddrSpace);
479    }
480
481    /// EmitValueToAlignment - Emit some number of copies of @p Value until
482    /// the byte alignment @p ByteAlignment is reached.
483    ///
484    /// If the number of bytes need to emit for the alignment is not a multiple
485    /// of @p ValueSize, then the contents of the emitted fill bytes is
486    /// undefined.
487    ///
488    /// This used to implement the .align assembler directive.
489    ///
490    /// @param ByteAlignment - The alignment to reach. This must be a power of
491    /// two on some targets.
492    /// @param Value - The value to use when filling bytes.
493    /// @param ValueSize - The size of the integer (in bytes) to emit for
494    /// @p Value. This must match a native machine width.
495    /// @param MaxBytesToEmit - The maximum numbers of bytes to emit, or 0. If
496    /// the alignment cannot be reached in this many bytes, no bytes are
497    /// emitted.
498    virtual void EmitValueToAlignment(unsigned ByteAlignment, int64_t Value = 0,
499                                      unsigned ValueSize = 1,
500                                      unsigned MaxBytesToEmit = 0) = 0;
501
502    /// EmitCodeAlignment - Emit nops until the byte alignment @p ByteAlignment
503    /// is reached.
504    ///
505    /// This used to align code where the alignment bytes may be executed.  This
506    /// can emit different bytes for different sizes to optimize execution.
507    ///
508    /// @param ByteAlignment - The alignment to reach. This must be a power of
509    /// two on some targets.
510    /// @param MaxBytesToEmit - The maximum numbers of bytes to emit, or 0. If
511    /// the alignment cannot be reached in this many bytes, no bytes are
512    /// emitted.
513    virtual void EmitCodeAlignment(unsigned ByteAlignment,
514                                   unsigned MaxBytesToEmit = 0) = 0;
515
516    /// EmitValueToOffset - Emit some number of copies of @p Value until the
517    /// byte offset @p Offset is reached.
518    ///
519    /// This is used to implement assembler directives such as .org.
520    ///
521    /// @param Offset - The offset to reach. This may be an expression, but the
522    /// expression must be associated with the current section.
523    /// @param Value - The value to use when filling bytes.
524    /// @return false on success, true if the offset was invalid.
525    virtual bool EmitValueToOffset(const MCExpr *Offset,
526                                   unsigned char Value = 0) = 0;
527
528    /// @}
529
530    /// EmitFileDirective - Switch to a new logical file.  This is used to
531    /// implement the '.file "foo.c"' assembler directive.
532    virtual void EmitFileDirective(StringRef Filename) = 0;
533
534    /// EmitDwarfFileDirective - Associate a filename with a specified logical
535    /// file number.  This implements the DWARF2 '.file 4 "foo.c"' assembler
536    /// directive.
537    virtual bool EmitDwarfFileDirective(unsigned FileNo, StringRef Directory,
538                                        StringRef Filename, unsigned CUID = 0);
539
540    /// EmitDwarfLocDirective - This implements the DWARF2
541    // '.loc fileno lineno ...' assembler directive.
542    virtual void EmitDwarfLocDirective(unsigned FileNo, unsigned Line,
543                                       unsigned Column, unsigned Flags,
544                                       unsigned Isa,
545                                       unsigned Discriminator,
546                                       StringRef FileName);
547
548    virtual void EmitDwarfAdvanceLineAddr(int64_t LineDelta,
549                                          const MCSymbol *LastLabel,
550                                          const MCSymbol *Label,
551                                          unsigned PointerSize) = 0;
552
553    virtual void EmitDwarfAdvanceFrameAddr(const MCSymbol *LastLabel,
554                                           const MCSymbol *Label) {
555    }
556
557    void EmitDwarfSetLineAddr(int64_t LineDelta, const MCSymbol *Label,
558                              int PointerSize);
559
560    virtual void EmitCompactUnwindEncoding(uint32_t CompactUnwindEncoding);
561    virtual void EmitCFISections(bool EH, bool Debug);
562    void EmitCFIStartProc();
563    void EmitCFIEndProc();
564    virtual void EmitCFIDefCfa(int64_t Register, int64_t Offset);
565    virtual void EmitCFIDefCfaOffset(int64_t Offset);
566    virtual void EmitCFIDefCfaRegister(int64_t Register);
567    virtual void EmitCFIOffset(int64_t Register, int64_t Offset);
568    virtual void EmitCFIPersonality(const MCSymbol *Sym, unsigned Encoding);
569    virtual void EmitCFILsda(const MCSymbol *Sym, unsigned Encoding);
570    virtual void EmitCFIRememberState();
571    virtual void EmitCFIRestoreState();
572    virtual void EmitCFISameValue(int64_t Register);
573    virtual void EmitCFIRestore(int64_t Register);
574    virtual void EmitCFIRelOffset(int64_t Register, int64_t Offset);
575    virtual void EmitCFIAdjustCfaOffset(int64_t Adjustment);
576    virtual void EmitCFIEscape(StringRef Values);
577    virtual void EmitCFISignalFrame();
578    virtual void EmitCFIUndefined(int64_t Register);
579    virtual void EmitCFIRegister(int64_t Register1, int64_t Register2);
580
581    virtual void EmitWin64EHStartProc(const MCSymbol *Symbol);
582    virtual void EmitWin64EHEndProc();
583    virtual void EmitWin64EHStartChained();
584    virtual void EmitWin64EHEndChained();
585    virtual void EmitWin64EHHandler(const MCSymbol *Sym, bool Unwind,
586                                    bool Except);
587    virtual void EmitWin64EHHandlerData();
588    virtual void EmitWin64EHPushReg(unsigned Register);
589    virtual void EmitWin64EHSetFrame(unsigned Register, unsigned Offset);
590    virtual void EmitWin64EHAllocStack(unsigned Size);
591    virtual void EmitWin64EHSaveReg(unsigned Register, unsigned Offset);
592    virtual void EmitWin64EHSaveXMM(unsigned Register, unsigned Offset);
593    virtual void EmitWin64EHPushFrame(bool Code);
594    virtual void EmitWin64EHEndProlog();
595
596    /// EmitInstruction - Emit the given @p Instruction into the current
597    /// section.
598    virtual void EmitInstruction(const MCInst &Inst) = 0;
599
600    /// \brief Set the bundle alignment mode from now on in the section.
601    /// The argument is the power of 2 to which the alignment is set. The
602    /// value 0 means turn the bundle alignment off.
603    virtual void EmitBundleAlignMode(unsigned AlignPow2) = 0;
604
605    /// \brief The following instructions are a bundle-locked group.
606    ///
607    /// \param AlignToEnd - If true, the bundle-locked group will be aligned to
608    ///                     the end of a bundle.
609    virtual void EmitBundleLock(bool AlignToEnd) = 0;
610
611    /// \brief Ends a bundle-locked group.
612    virtual void EmitBundleUnlock() = 0;
613
614    /// EmitRawText - If this file is backed by a assembly streamer, this dumps
615    /// the specified string in the output .s file.  This capability is
616    /// indicated by the hasRawTextSupport() predicate.  By default this aborts.
617    virtual void EmitRawText(StringRef String);
618    void EmitRawText(const Twine &String);
619
620    /// ARM-related methods.
621    /// FIXME: Eventually we should have some "target MC streamer" and move
622    /// these methods there.
623    virtual void EmitFnStart();
624    virtual void EmitFnEnd();
625    virtual void EmitCantUnwind();
626    virtual void EmitPersonality(const MCSymbol *Personality);
627    virtual void EmitHandlerData();
628    virtual void EmitSetFP(unsigned FpReg, unsigned SpReg, int64_t Offset = 0);
629    virtual void EmitPad(int64_t Offset);
630    virtual void EmitRegSave(const SmallVectorImpl<unsigned> &RegList,
631                             bool isVector);
632
633    /// PPC-related methods.
634    /// FIXME: Eventually replace it with some "target MC streamer" and move
635    /// these methods there.
636    virtual void EmitTCEntry(const MCSymbol &S);
637
638    /// FinishImpl - Streamer specific finalization.
639    virtual void FinishImpl() = 0;
640    /// Finish - Finish emission of machine code.
641    void Finish();
642  };
643
644  /// createNullStreamer - Create a dummy machine code streamer, which does
645  /// nothing. This is useful for timing the assembler front end.
646  MCStreamer *createNullStreamer(MCContext &Ctx);
647
648  /// createAsmStreamer - Create a machine code streamer which will print out
649  /// assembly for the native target, suitable for compiling with a native
650  /// assembler.
651  ///
652  /// \param InstPrint - If given, the instruction printer to use. If not given
653  /// the MCInst representation will be printed.  This method takes ownership of
654  /// InstPrint.
655  ///
656  /// \param CE - If given, a code emitter to use to show the instruction
657  /// encoding inline with the assembly. This method takes ownership of \p CE.
658  ///
659  /// \param TAB - If given, a target asm backend to use to show the fixup
660  /// information in conjunction with encoding information. This method takes
661  /// ownership of \p TAB.
662  ///
663  /// \param ShowInst - Whether to show the MCInst representation inline with
664  /// the assembly.
665  MCStreamer *createAsmStreamer(MCContext &Ctx, formatted_raw_ostream &OS,
666                                bool isVerboseAsm,
667                                bool useLoc,
668                                bool useCFI,
669                                bool useDwarfDirectory,
670                                MCInstPrinter *InstPrint = 0,
671                                MCCodeEmitter *CE = 0,
672                                MCAsmBackend *TAB = 0,
673                                bool ShowInst = false);
674
675  /// createMachOStreamer - Create a machine code streamer which will generate
676  /// Mach-O format object files.
677  ///
678  /// Takes ownership of \p TAB and \p CE.
679  MCStreamer *createMachOStreamer(MCContext &Ctx, MCAsmBackend &TAB,
680                                  raw_ostream &OS, MCCodeEmitter *CE,
681                                  bool RelaxAll = false);
682
683  /// createWinCOFFStreamer - Create a machine code streamer which will
684  /// generate Microsoft COFF format object files.
685  ///
686  /// Takes ownership of \p TAB and \p CE.
687  MCStreamer *createWinCOFFStreamer(MCContext &Ctx,
688                                    MCAsmBackend &TAB,
689                                    MCCodeEmitter &CE, raw_ostream &OS,
690                                    bool RelaxAll = false);
691
692  /// createELFStreamer - Create a machine code streamer which will generate
693  /// ELF format object files.
694  MCStreamer *createELFStreamer(MCContext &Ctx, MCAsmBackend &TAB,
695                                raw_ostream &OS, MCCodeEmitter *CE,
696                                bool RelaxAll, bool NoExecStack);
697
698  /// createPureStreamer - Create a machine code streamer which will generate
699  /// "pure" MC object files, for use with MC-JIT and testing tools.
700  ///
701  /// Takes ownership of \p TAB and \p CE.
702  MCStreamer *createPureStreamer(MCContext &Ctx, MCAsmBackend &TAB,
703                                 raw_ostream &OS, MCCodeEmitter *CE);
704
705} // end namespace llvm
706
707#endif
708