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