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