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