1 //===- MCStreamer.h - High-level Streaming Machine Code Output --*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file declares the MCStreamer class.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_MC_MCSTREAMER_H
15 #define LLVM_MC_MCSTREAMER_H
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"
36 class MCSymbolRefExpr;
37 class MCSubtargetInfo;
41 class formatted_raw_ostream;
42 class AssemblerConstantPools;
44 typedef std::pair<const MCSection *, const MCExpr *> MCSectionSubPair;
46 /// Target specific streamer interface. This is used so that targets can
47 /// implement support for target specific assembly directives.
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
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;
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.
62 /// In the assembly printer and parser the target streamer can be used by
63 /// calling getTargetStreamer and casting it to FooTargetStreamer:
65 /// MCTargetStreamer &TS = OutStreamer.getTargetStreamer();
66 /// FooTargetStreamer &ATS = static_cast<FooTargetStreamer &>(TS);
68 /// The base classes FooTargetAsmSreamer and FooTargetELFStreamer should *never*
69 /// be treated differently. Callers should always talk to a FooTargetStreamer.
70 class MCTargetStreamer {
75 MCTargetStreamer(MCStreamer &S);
76 virtual ~MCTargetStreamer();
78 // Allow a target to add behavior to the EmitLabel of MCStreamer.
79 virtual void emitLabel(MCSymbol *Symbol);
81 virtual void finish();
84 // FIXME: declared here because it is used from
85 // lib/CodeGen/AsmPrinter/ARMException.cpp.
86 class ARMTargetStreamer : public MCTargetStreamer {
88 ARMTargetStreamer(MCStreamer &S);
91 virtual void emitFnStart();
92 virtual void emitFnEnd();
93 virtual void emitCantUnwind();
94 virtual void emitPersonality(const MCSymbol *Personality);
95 virtual void emitPersonalityIndex(unsigned Index);
96 virtual void emitHandlerData();
97 virtual void emitSetFP(unsigned FpReg, unsigned SpReg,
99 virtual void emitMovSP(unsigned Reg, int64_t Offset = 0);
100 virtual void emitPad(int64_t Offset);
101 virtual void emitRegSave(const SmallVectorImpl<unsigned> &RegList,
103 virtual void emitUnwindRaw(int64_t StackOffset,
104 const SmallVectorImpl<uint8_t> &Opcodes);
106 virtual void switchVendor(StringRef Vendor);
107 virtual void emitAttribute(unsigned Attribute, unsigned Value);
108 virtual void emitTextAttribute(unsigned Attribute, StringRef String);
109 virtual void emitIntTextAttribute(unsigned Attribute, unsigned IntValue,
110 StringRef StringValue = "");
111 virtual void emitFPU(unsigned FPU);
112 virtual void emitArch(unsigned Arch);
113 virtual void emitObjectArch(unsigned Arch);
114 virtual void finishAttributeSection();
115 virtual void emitInst(uint32_t Inst, char Suffix = '\0');
117 virtual void AnnotateTLSDescriptorSequence(const MCSymbolRefExpr *SRE);
119 virtual void finish();
121 /// Callback used to implement the ldr= pseudo.
122 /// Add a new entry to the constant pool for the current section and return an
123 /// MCExpr that can be used to refer to the constant pool location.
124 const MCExpr *addConstantPoolEntry(const MCExpr *);
126 /// Callback used to implemnt the .ltorg directive.
127 /// Emit contents of constant pool for the current section.
128 void emitCurrentConstantPool();
131 OwningPtr<AssemblerConstantPools> ConstantPools;
134 /// MCStreamer - Streaming machine code generation interface. This interface
135 /// is intended to provide a programatic interface that is very similar to the
136 /// level that an assembler .s file provides. It has callbacks to emit bytes,
137 /// handle directives, etc. The implementation of this interface retains
138 /// state to know what the current section is etc.
140 /// There are multiple implementations of this interface: one for writing out
141 /// a .s file, and implementations that write out .o files of various formats.
145 OwningPtr<MCTargetStreamer> TargetStreamer;
147 MCStreamer(const MCStreamer &) LLVM_DELETED_FUNCTION;
148 MCStreamer &operator=(const MCStreamer &) LLVM_DELETED_FUNCTION;
153 std::vector<MCDwarfFrameInfo> FrameInfos;
154 MCDwarfFrameInfo *getCurrentFrameInfo();
155 MCSymbol *EmitCFICommon();
156 void EnsureValidFrame();
158 std::vector<MCWin64EHUnwindInfo *> W64UnwindInfos;
159 MCWin64EHUnwindInfo *CurrentW64UnwindInfo;
160 void setCurrentW64UnwindInfo(MCWin64EHUnwindInfo *Frame);
161 void EnsureValidW64UnwindInfo();
163 MCSymbol *LastSymbol;
165 // SymbolOrdering - Tracks an index to represent the order
166 // a symbol was emitted in. Zero means we did not emit that symbol.
167 DenseMap<const MCSymbol *, unsigned> SymbolOrdering;
169 /// SectionStack - This is stack of current and previous section
170 /// values saved by PushSection.
171 SmallVector<std::pair<MCSectionSubPair, MCSectionSubPair>, 4> SectionStack;
174 MCStreamer(MCContext &Ctx);
176 const MCExpr *BuildSymbolDiff(MCContext &Context, const MCSymbol *A,
179 const MCExpr *ForceExpAbs(const MCExpr *Expr);
181 void RecordProcStart(MCDwarfFrameInfo &Frame);
182 virtual void EmitCFIStartProcImpl(MCDwarfFrameInfo &Frame);
183 void RecordProcEnd(MCDwarfFrameInfo &Frame);
184 virtual void EmitCFIEndProcImpl(MCDwarfFrameInfo &CurFrame);
185 void EmitFrames(MCAsmBackend *MAB, bool usingCFI);
187 MCWin64EHUnwindInfo *getCurrentW64UnwindInfo() {
188 return CurrentW64UnwindInfo;
190 void EmitW64Tables();
192 virtual void EmitRawTextImpl(StringRef String);
195 virtual ~MCStreamer();
197 void setTargetStreamer(MCTargetStreamer *TS) {
198 TargetStreamer.reset(TS);
203 virtual void reset();
205 MCContext &getContext() const { return Context; }
207 MCTargetStreamer *getTargetStreamer() {
208 return TargetStreamer.get();
211 unsigned getNumFrameInfos() { return FrameInfos.size(); }
213 const MCDwarfFrameInfo &getFrameInfo(unsigned i) { return FrameInfos[i]; }
215 ArrayRef<MCDwarfFrameInfo> getFrameInfos() const { return FrameInfos; }
217 unsigned getNumW64UnwindInfos() { return W64UnwindInfos.size(); }
219 MCWin64EHUnwindInfo &getW64UnwindInfo(unsigned i) {
220 return *W64UnwindInfos[i];
223 void generateCompactUnwindEncodings(MCAsmBackend *MAB);
225 /// @name Assembly File Formatting.
228 /// isVerboseAsm - Return true if this streamer supports verbose assembly
229 /// and if it is enabled.
230 virtual bool isVerboseAsm() const { return false; }
232 /// hasRawTextSupport - Return true if this asm streamer supports emitting
233 /// unformatted text to the .s file with EmitRawText.
234 virtual bool hasRawTextSupport() const { return false; }
236 /// AddComment - Add a comment that can be emitted to the generated .s
237 /// file if applicable as a QoI issue to make the output of the compiler
238 /// more readable. This only affects the MCAsmStreamer, and only when
239 /// verbose assembly output is enabled.
241 /// If the comment includes embedded \n's, they will each get the comment
242 /// prefix as appropriate. The added comment should not end with a \n.
243 virtual void AddComment(const Twine &T) {}
245 /// GetCommentOS - Return a raw_ostream that comments can be written to.
246 /// Unlike AddComment, you are required to terminate comments with \n if you
248 virtual raw_ostream &GetCommentOS();
250 /// Print T and prefix it with the comment string (normally #) and optionally
251 /// a tab. This prints the comment immediately, not at the end of the
252 /// current line. It is basically a safe version of EmitRawText: since it
253 /// only prints comments, the object streamer ignores it instead of asserting.
254 virtual void emitRawComment(const Twine &T, bool TabPrefix = true);
256 /// AddBlankLine - Emit a blank line to a .s file to pretty it up.
257 virtual void AddBlankLine() {}
261 /// @name Symbol & Section Management
264 /// getCurrentSection - Return the current section that the streamer is
265 /// emitting code to.
266 MCSectionSubPair getCurrentSection() const {
267 if (!SectionStack.empty())
268 return SectionStack.back().first;
269 return MCSectionSubPair();
272 /// getPreviousSection - Return the previous section that the streamer is
273 /// emitting code to.
274 MCSectionSubPair getPreviousSection() const {
275 if (!SectionStack.empty())
276 return SectionStack.back().second;
277 return MCSectionSubPair();
280 /// GetSymbolOrder - Returns an index to represent the order
281 /// a symbol was emitted in. (zero if we did not emit that symbol)
282 unsigned GetSymbolOrder(const MCSymbol *Sym) const {
283 return SymbolOrdering.lookup(Sym);
286 /// ChangeSection - Update streamer for a new active section.
288 /// This is called by PopSection and SwitchSection, if the current
290 virtual void ChangeSection(const MCSection *, const MCExpr *) = 0;
292 /// pushSection - Save the current and previous section on the
295 SectionStack.push_back(
296 std::make_pair(getCurrentSection(), getPreviousSection()));
299 /// popSection - Restore the current and previous section from
300 /// the section stack. Calls ChangeSection as needed.
302 /// Returns false if the stack was empty.
304 if (SectionStack.size() <= 1)
306 MCSectionSubPair oldSection = SectionStack.pop_back_val().first;
307 MCSectionSubPair curSection = SectionStack.back().first;
309 if (oldSection != curSection)
310 ChangeSection(curSection.first, curSection.second);
314 bool SubSection(const MCExpr *Subsection) {
315 if (SectionStack.empty())
318 SwitchSection(SectionStack.back().first.first, Subsection);
322 /// SwitchSection - Set the current section where code is being emitted to
323 /// @p Section. This is required to update CurSection.
325 /// This corresponds to assembler directives like .section, .text, etc.
326 void SwitchSection(const MCSection *Section, const MCExpr *Subsection = 0) {
327 assert(Section && "Cannot switch to a null section!");
328 MCSectionSubPair curSection = SectionStack.back().first;
329 SectionStack.back().second = curSection;
330 if (MCSectionSubPair(Section, Subsection) != curSection) {
331 SectionStack.back().first = MCSectionSubPair(Section, Subsection);
332 ChangeSection(Section, Subsection);
336 /// SwitchSectionNoChange - Set the current section where code is being
337 /// emitted to @p Section. This is required to update CurSection. This
338 /// version does not call ChangeSection.
339 void SwitchSectionNoChange(const MCSection *Section,
340 const MCExpr *Subsection = 0) {
341 assert(Section && "Cannot switch to a null section!");
342 MCSectionSubPair curSection = SectionStack.back().first;
343 SectionStack.back().second = curSection;
344 if (MCSectionSubPair(Section, Subsection) != curSection)
345 SectionStack.back().first = MCSectionSubPair(Section, Subsection);
348 /// Create the default sections and set the initial one.
350 /// @param Force - If false, a text streamer implementation can be a nop.
351 /// Used by CodeGen to avoid starting every file with '.text'.
352 virtual void InitSections(bool Force = true);
354 /// AssignSection - Sets the symbol's section.
356 /// Each emitted symbol will be tracked in the ordering table,
357 /// so we can sort on them later.
358 void AssignSection(MCSymbol *Symbol, const MCSection *Section);
360 /// EmitLabel - Emit a label for @p Symbol into the current section.
362 /// This corresponds to an assembler statement such as:
365 /// @param Symbol - The symbol to emit. A given symbol should only be
366 /// emitted as a label once, and symbols emitted as a label should never be
367 /// used in an assignment.
368 // FIXME: These emission are non-const because we mutate the symbol to
369 // add the section we're emitting it to later.
370 virtual void EmitLabel(MCSymbol *Symbol);
372 virtual void EmitDebugLabel(MCSymbol *Symbol);
374 virtual void EmitEHSymAttributes(const MCSymbol *Symbol, MCSymbol *EHSymbol);
376 /// EmitAssemblerFlag - Note in the output the specified @p Flag.
377 virtual void EmitAssemblerFlag(MCAssemblerFlag Flag) = 0;
379 /// EmitLinkerOptions - Emit the given list @p Options of strings as linker
380 /// options into the output.
381 virtual void EmitLinkerOptions(ArrayRef<std::string> Kind) {}
383 /// EmitDataRegion - Note in the output the specified region @p Kind.
384 virtual void EmitDataRegion(MCDataRegionType Kind) {}
386 /// EmitThumbFunc - Note in the output that the specified @p Func is
387 /// a Thumb mode function (ARM target only).
388 virtual void EmitThumbFunc(MCSymbol *Func) = 0;
390 /// getOrCreateSymbolData - Get symbol data for given symbol.
391 virtual MCSymbolData &getOrCreateSymbolData(MCSymbol *Symbol);
393 /// EmitAssignment - Emit an assignment of @p Value to @p Symbol.
395 /// This corresponds to an assembler statement such as:
398 /// The assignment generates no code, but has the side effect of binding the
399 /// value in the current context. For the assembly streamer, this prints the
400 /// binding into the .s file.
402 /// @param Symbol - The symbol being assigned to.
403 /// @param Value - The value for the symbol.
404 virtual void EmitAssignment(MCSymbol *Symbol, const MCExpr *Value) = 0;
406 /// EmitWeakReference - Emit an weak reference from @p Alias to @p Symbol.
408 /// This corresponds to an assembler statement such as:
409 /// .weakref alias, symbol
411 /// @param Alias - The alias that is being created.
412 /// @param Symbol - The symbol being aliased.
413 virtual void EmitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol) = 0;
415 /// EmitSymbolAttribute - Add the given @p Attribute to @p Symbol.
416 virtual bool EmitSymbolAttribute(MCSymbol *Symbol,
417 MCSymbolAttr Attribute) = 0;
419 /// EmitSymbolDesc - Set the @p DescValue for the @p Symbol.
421 /// @param Symbol - The symbol to have its n_desc field set.
422 /// @param DescValue - The value to set into the n_desc field.
423 virtual void EmitSymbolDesc(MCSymbol *Symbol, unsigned DescValue) = 0;
425 /// BeginCOFFSymbolDef - Start emitting COFF symbol definition
427 /// @param Symbol - The symbol to have its External & Type fields set.
428 virtual void BeginCOFFSymbolDef(const MCSymbol *Symbol) = 0;
430 /// EmitCOFFSymbolStorageClass - Emit the storage class of the symbol.
432 /// @param StorageClass - The storage class the symbol should have.
433 virtual void EmitCOFFSymbolStorageClass(int StorageClass) = 0;
435 /// EmitCOFFSymbolType - Emit the type of the symbol.
437 /// @param Type - A COFF type identifier (see COFF::SymbolType in X86COFF.h)
438 virtual void EmitCOFFSymbolType(int Type) = 0;
440 /// EndCOFFSymbolDef - Marks the end of the symbol definition.
441 virtual void EndCOFFSymbolDef() = 0;
443 /// EmitCOFFSectionIndex - Emits a COFF section index.
445 /// @param Symbol - Symbol the section number relocation should point to.
446 virtual void EmitCOFFSectionIndex(MCSymbol const *Symbol);
448 /// EmitCOFFSecRel32 - Emits a COFF section relative relocation.
450 /// @param Symbol - Symbol the section relative relocation should point to.
451 virtual void EmitCOFFSecRel32(MCSymbol const *Symbol);
453 /// EmitELFSize - Emit an ELF .size directive.
455 /// This corresponds to an assembler statement such as:
456 /// .size symbol, expression
458 virtual void EmitELFSize(MCSymbol *Symbol, const MCExpr *Value) = 0;
460 /// EmitCommonSymbol - Emit a common symbol.
462 /// @param Symbol - The common symbol to emit.
463 /// @param Size - The size of the common symbol.
464 /// @param ByteAlignment - The alignment of the symbol if
465 /// non-zero. This must be a power of 2.
466 virtual void EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
467 unsigned ByteAlignment) = 0;
469 /// EmitLocalCommonSymbol - Emit a local common (.lcomm) symbol.
471 /// @param Symbol - The common symbol to emit.
472 /// @param Size - The size of the common symbol.
473 /// @param ByteAlignment - The alignment of the common symbol in bytes.
474 virtual void EmitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size,
475 unsigned ByteAlignment) = 0;
477 /// EmitZerofill - Emit the zerofill section and an optional symbol.
479 /// @param Section - The zerofill section to create and or to put the symbol
480 /// @param Symbol - The zerofill symbol to emit, if non-NULL.
481 /// @param Size - The size of the zerofill symbol.
482 /// @param ByteAlignment - The alignment of the zerofill symbol if
483 /// non-zero. This must be a power of 2 on some targets.
484 virtual void EmitZerofill(const MCSection *Section, MCSymbol *Symbol = 0,
485 uint64_t Size = 0, unsigned ByteAlignment = 0) = 0;
487 /// EmitTBSSSymbol - Emit a thread local bss (.tbss) symbol.
489 /// @param Section - The thread local common section.
490 /// @param Symbol - The thread local common symbol to emit.
491 /// @param Size - The size of the symbol.
492 /// @param ByteAlignment - The alignment of the thread local common symbol
493 /// if non-zero. This must be a power of 2 on some targets.
494 virtual void EmitTBSSSymbol(const MCSection *Section, MCSymbol *Symbol,
495 uint64_t Size, unsigned ByteAlignment = 0) = 0;
498 /// @name Generating Data
501 /// EmitBytes - Emit the bytes in \p Data into the output.
503 /// This is used to implement assembler directives such as .byte, .ascii,
505 virtual void EmitBytes(StringRef Data) = 0;
507 /// EmitValue - Emit the expression @p Value into the output as a native
508 /// integer of the given @p Size bytes.
510 /// This is used to implement assembler directives such as .word, .quad,
513 /// @param Value - The value to emit.
514 /// @param Size - The size of the integer (in bytes) to emit. This must
515 /// match a native machine width.
516 virtual void EmitValueImpl(const MCExpr *Value, unsigned Size) = 0;
518 void EmitValue(const MCExpr *Value, unsigned Size);
520 /// EmitIntValue - Special case of EmitValue that avoids the client having
521 /// to pass in a MCExpr for constant integers.
522 virtual void EmitIntValue(uint64_t Value, unsigned Size);
524 /// EmitAbsValue - Emit the Value, but try to avoid relocations. On MachO
525 /// this is done by producing
528 void EmitAbsValue(const MCExpr *Value, unsigned Size);
530 virtual void EmitULEB128Value(const MCExpr *Value) = 0;
532 virtual void EmitSLEB128Value(const MCExpr *Value) = 0;
534 /// EmitULEB128Value - Special case of EmitULEB128Value that avoids the
535 /// client having to pass in a MCExpr for constant integers.
536 void EmitULEB128IntValue(uint64_t Value, unsigned Padding = 0);
538 /// EmitSLEB128Value - Special case of EmitSLEB128Value that avoids the
539 /// client having to pass in a MCExpr for constant integers.
540 void EmitSLEB128IntValue(int64_t Value);
542 /// EmitSymbolValue - Special case of EmitValue that avoids the client
543 /// having to pass in a MCExpr for MCSymbols.
544 void EmitSymbolValue(const MCSymbol *Sym, unsigned Size);
546 /// EmitGPRel64Value - Emit the expression @p Value into the output as a
547 /// gprel64 (64-bit GP relative) value.
549 /// This is used to implement assembler directives such as .gpdword on
550 /// targets that support them.
551 virtual void EmitGPRel64Value(const MCExpr *Value);
553 /// EmitGPRel32Value - Emit the expression @p Value into the output as a
554 /// gprel32 (32-bit GP relative) value.
556 /// This is used to implement assembler directives such as .gprel32 on
557 /// targets that support them.
558 virtual void EmitGPRel32Value(const MCExpr *Value);
560 /// EmitFill - Emit NumBytes bytes worth of the value specified by
561 /// FillValue. This implements directives such as '.space'.
562 virtual void EmitFill(uint64_t NumBytes, uint8_t FillValue);
564 /// \brief Emit NumBytes worth of zeros.
565 /// This function properly handles data in virtual sections.
566 virtual void EmitZeros(uint64_t NumBytes);
568 /// EmitValueToAlignment - Emit some number of copies of @p Value until
569 /// the byte alignment @p ByteAlignment is reached.
571 /// If the number of bytes need to emit for the alignment is not a multiple
572 /// of @p ValueSize, then the contents of the emitted fill bytes is
575 /// This used to implement the .align assembler directive.
577 /// @param ByteAlignment - The alignment to reach. This must be a power of
578 /// two on some targets.
579 /// @param Value - The value to use when filling bytes.
580 /// @param ValueSize - The size of the integer (in bytes) to emit for
581 /// @p Value. This must match a native machine width.
582 /// @param MaxBytesToEmit - The maximum numbers of bytes to emit, or 0. If
583 /// the alignment cannot be reached in this many bytes, no bytes are
585 virtual void EmitValueToAlignment(unsigned ByteAlignment, int64_t Value = 0,
586 unsigned ValueSize = 1,
587 unsigned MaxBytesToEmit = 0) = 0;
589 /// EmitCodeAlignment - Emit nops until the byte alignment @p ByteAlignment
592 /// This used to align code where the alignment bytes may be executed. This
593 /// can emit different bytes for different sizes to optimize execution.
595 /// @param ByteAlignment - The alignment to reach. This must be a power of
596 /// two on some targets.
597 /// @param MaxBytesToEmit - The maximum numbers of bytes to emit, or 0. If
598 /// the alignment cannot be reached in this many bytes, no bytes are
600 virtual void EmitCodeAlignment(unsigned ByteAlignment,
601 unsigned MaxBytesToEmit = 0) = 0;
603 /// EmitValueToOffset - Emit some number of copies of @p Value until the
604 /// byte offset @p Offset is reached.
606 /// This is used to implement assembler directives such as .org.
608 /// @param Offset - The offset to reach. This may be an expression, but the
609 /// expression must be associated with the current section.
610 /// @param Value - The value to use when filling bytes.
611 /// @return false on success, true if the offset was invalid.
612 virtual bool EmitValueToOffset(const MCExpr *Offset,
613 unsigned char Value = 0) = 0;
617 /// EmitFileDirective - Switch to a new logical file. This is used to
618 /// implement the '.file "foo.c"' assembler directive.
619 virtual void EmitFileDirective(StringRef Filename) = 0;
621 /// Emit the "identifiers" directive. This implements the
622 /// '.ident "version foo"' assembler directive.
623 virtual void EmitIdent(StringRef IdentString) {}
625 /// EmitDwarfFileDirective - Associate a filename with a specified logical
626 /// file number. This implements the DWARF2 '.file 4 "foo.c"' assembler
628 virtual bool EmitDwarfFileDirective(unsigned FileNo, StringRef Directory,
629 StringRef Filename, unsigned CUID = 0);
631 /// EmitDwarfLocDirective - This implements the DWARF2
632 // '.loc fileno lineno ...' assembler directive.
633 virtual void EmitDwarfLocDirective(unsigned FileNo, unsigned Line,
634 unsigned Column, unsigned Flags,
635 unsigned Isa, unsigned Discriminator,
638 virtual void EmitDwarfAdvanceLineAddr(int64_t LineDelta,
639 const MCSymbol *LastLabel,
640 const MCSymbol *Label,
641 unsigned PointerSize) = 0;
643 virtual void EmitDwarfAdvanceFrameAddr(const MCSymbol *LastLabel,
644 const MCSymbol *Label) {}
646 void EmitDwarfSetLineAddr(int64_t LineDelta, const MCSymbol *Label,
649 virtual void EmitCompactUnwindEncoding(uint32_t CompactUnwindEncoding);
650 virtual void EmitCFISections(bool EH, bool Debug);
651 void EmitCFIStartProc(bool IsSimple);
652 void EmitCFIEndProc();
653 virtual void EmitCFIDefCfa(int64_t Register, int64_t Offset);
654 virtual void EmitCFIDefCfaOffset(int64_t Offset);
655 virtual void EmitCFIDefCfaRegister(int64_t Register);
656 virtual void EmitCFIOffset(int64_t Register, int64_t Offset);
657 virtual void EmitCFIPersonality(const MCSymbol *Sym, unsigned Encoding);
658 virtual void EmitCFILsda(const MCSymbol *Sym, unsigned Encoding);
659 virtual void EmitCFIRememberState();
660 virtual void EmitCFIRestoreState();
661 virtual void EmitCFISameValue(int64_t Register);
662 virtual void EmitCFIRestore(int64_t Register);
663 virtual void EmitCFIRelOffset(int64_t Register, int64_t Offset);
664 virtual void EmitCFIAdjustCfaOffset(int64_t Adjustment);
665 virtual void EmitCFIEscape(StringRef Values);
666 virtual void EmitCFISignalFrame();
667 virtual void EmitCFIUndefined(int64_t Register);
668 virtual void EmitCFIRegister(int64_t Register1, int64_t Register2);
669 virtual void EmitCFIWindowSave();
671 virtual void EmitWin64EHStartProc(const MCSymbol *Symbol);
672 virtual void EmitWin64EHEndProc();
673 virtual void EmitWin64EHStartChained();
674 virtual void EmitWin64EHEndChained();
675 virtual void EmitWin64EHHandler(const MCSymbol *Sym, bool Unwind,
677 virtual void EmitWin64EHHandlerData();
678 virtual void EmitWin64EHPushReg(unsigned Register);
679 virtual void EmitWin64EHSetFrame(unsigned Register, unsigned Offset);
680 virtual void EmitWin64EHAllocStack(unsigned Size);
681 virtual void EmitWin64EHSaveReg(unsigned Register, unsigned Offset);
682 virtual void EmitWin64EHSaveXMM(unsigned Register, unsigned Offset);
683 virtual void EmitWin64EHPushFrame(bool Code);
684 virtual void EmitWin64EHEndProlog();
686 /// EmitInstruction - Emit the given @p Instruction into the current
688 virtual void EmitInstruction(const MCInst &Inst, const MCSubtargetInfo &STI) = 0;
690 /// \brief Set the bundle alignment mode from now on in the section.
691 /// The argument is the power of 2 to which the alignment is set. The
692 /// value 0 means turn the bundle alignment off.
693 virtual void EmitBundleAlignMode(unsigned AlignPow2) = 0;
695 /// \brief The following instructions are a bundle-locked group.
697 /// \param AlignToEnd - If true, the bundle-locked group will be aligned to
698 /// the end of a bundle.
699 virtual void EmitBundleLock(bool AlignToEnd) = 0;
701 /// \brief Ends a bundle-locked group.
702 virtual void EmitBundleUnlock() = 0;
704 /// EmitRawText - If this file is backed by a assembly streamer, this dumps
705 /// the specified string in the output .s file. This capability is
706 /// indicated by the hasRawTextSupport() predicate. By default this aborts.
707 void EmitRawText(const Twine &String);
709 /// Flush - Causes any cached state to be written out.
710 virtual void Flush() {}
712 /// FinishImpl - Streamer specific finalization.
713 virtual void FinishImpl() = 0;
714 /// Finish - Finish emission of machine code.
718 /// createNullStreamer - Create a dummy machine code streamer, which does
719 /// nothing. This is useful for timing the assembler front end.
720 MCStreamer *createNullStreamer(MCContext &Ctx);
722 /// createAsmStreamer - Create a machine code streamer which will print out
723 /// assembly for the native target, suitable for compiling with a native
726 /// \param InstPrint - If given, the instruction printer to use. If not given
727 /// the MCInst representation will be printed. This method takes ownership of
730 /// \param CE - If given, a code emitter to use to show the instruction
731 /// encoding inline with the assembly. This method takes ownership of \p CE.
733 /// \param TAB - If given, a target asm backend to use to show the fixup
734 /// information in conjunction with encoding information. This method takes
735 /// ownership of \p TAB.
737 /// \param ShowInst - Whether to show the MCInst representation inline with
739 MCStreamer *createAsmStreamer(MCContext &Ctx, formatted_raw_ostream &OS,
740 bool isVerboseAsm, bool useLoc, bool useCFI,
741 bool useDwarfDirectory,
742 MCInstPrinter *InstPrint = 0,
743 MCCodeEmitter *CE = 0, MCAsmBackend *TAB = 0,
744 bool ShowInst = false);
746 /// createMachOStreamer - Create a machine code streamer which will generate
747 /// Mach-O format object files.
749 /// Takes ownership of \p TAB and \p CE.
750 MCStreamer *createMachOStreamer(MCContext &Ctx, MCAsmBackend &TAB,
751 raw_ostream &OS, MCCodeEmitter *CE,
752 bool RelaxAll = false);
754 /// createWinCOFFStreamer - Create a machine code streamer which will
755 /// generate Microsoft COFF format object files.
757 /// Takes ownership of \p TAB and \p CE.
758 MCStreamer *createWinCOFFStreamer(MCContext &Ctx, MCAsmBackend &TAB,
759 MCCodeEmitter &CE, raw_ostream &OS,
760 bool RelaxAll = false);
762 /// createELFStreamer - Create a machine code streamer which will generate
763 /// ELF format object files.
764 MCStreamer *createELFStreamer(MCContext &Ctx, MCAsmBackend &TAB,
765 raw_ostream &OS, MCCodeEmitter *CE, bool RelaxAll,
768 /// createPureStreamer - Create a machine code streamer which will generate
769 /// "pure" MC object files, for use with MC-JIT and testing tools.
771 /// Takes ownership of \p TAB and \p CE.
772 MCStreamer *createPureStreamer(MCContext &Ctx, MCAsmBackend &TAB,
773 raw_ostream &OS, MCCodeEmitter *CE);
775 } // end namespace llvm