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