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