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/MCDirectives.h"
20 #include "llvm/MC/MCDwarf.h"
21 #include "llvm/MC/MCLinkerOptimizationHint.h"
22 #include "llvm/MC/MCWinEH.h"
23 #include "llvm/Support/DataTypes.h"
24 #include "llvm/Support/SMLoc.h"
37 class MCSymbolRefExpr;
38 class MCSubtargetInfo;
42 class formatted_raw_ostream;
43 class AssemblerConstantPools;
45 typedef std::pair<const MCSection *, const MCExpr *> MCSectionSubPair;
47 /// Target specific streamer interface. This is used so that targets can
48 /// implement support for target specific assembly directives.
50 /// If target foo wants to use this, it should implement 3 classes:
51 /// * FooTargetStreamer : public MCTargetStreamer
52 /// * FooTargetAsmStreamer : public FooTargetStreamer
53 /// * FooTargetELFStreamer : public FooTargetStreamer
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;
59 /// The FooTargetAsmStreamer 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.
63 /// In the assembly printer and parser the target streamer can be used by
64 /// calling getTargetStreamer and casting it to FooTargetStreamer:
66 /// MCTargetStreamer &TS = OutStreamer.getTargetStreamer();
67 /// FooTargetStreamer &ATS = static_cast<FooTargetStreamer &>(TS);
69 /// The base classes FooTargetAsmStreamer and FooTargetELFStreamer should
70 /// *never* be treated differently. Callers should always talk to a
71 /// FooTargetStreamer.
72 class MCTargetStreamer {
77 MCTargetStreamer(MCStreamer &S);
78 virtual ~MCTargetStreamer();
80 const MCStreamer &getStreamer() { return Streamer; }
82 // Allow a target to add behavior to the EmitLabel of MCStreamer.
83 virtual void emitLabel(MCSymbol *Symbol);
84 // Allow a target to add behavior to the emitAssignment of MCStreamer.
85 virtual void emitAssignment(MCSymbol *Symbol, const MCExpr *Value);
87 virtual void finish();
90 class AArch64TargetStreamer : public MCTargetStreamer {
92 AArch64TargetStreamer(MCStreamer &S);
93 ~AArch64TargetStreamer() override;
95 void finish() override;
97 /// Callback used to implement the ldr= pseudo.
98 /// Add a new entry to the constant pool for the current section and return an
99 /// MCExpr that can be used to refer to the constant pool location.
100 const MCExpr *addConstantPoolEntry(const MCExpr *, unsigned Size);
102 /// Callback used to implemnt the .ltorg directive.
103 /// Emit contents of constant pool for the current section.
104 void emitCurrentConstantPool();
106 /// Callback used to implement the .inst directive.
107 virtual void emitInst(uint32_t Inst);
110 std::unique_ptr<AssemblerConstantPools> ConstantPools;
113 // FIXME: declared here because it is used from
114 // lib/CodeGen/AsmPrinter/ARMException.cpp.
115 class ARMTargetStreamer : public MCTargetStreamer {
117 ARMTargetStreamer(MCStreamer &S);
118 ~ARMTargetStreamer() override;
120 virtual void emitFnStart();
121 virtual void emitFnEnd();
122 virtual void emitCantUnwind();
123 virtual void emitPersonality(const MCSymbol *Personality);
124 virtual void emitPersonalityIndex(unsigned Index);
125 virtual void emitHandlerData();
126 virtual void emitSetFP(unsigned FpReg, unsigned SpReg,
128 virtual void emitMovSP(unsigned Reg, int64_t Offset = 0);
129 virtual void emitPad(int64_t Offset);
130 virtual void emitRegSave(const SmallVectorImpl<unsigned> &RegList,
132 virtual void emitUnwindRaw(int64_t StackOffset,
133 const SmallVectorImpl<uint8_t> &Opcodes);
135 virtual void switchVendor(StringRef Vendor);
136 virtual void emitAttribute(unsigned Attribute, unsigned Value);
137 virtual void emitTextAttribute(unsigned Attribute, StringRef String);
138 virtual void emitIntTextAttribute(unsigned Attribute, unsigned IntValue,
139 StringRef StringValue = "");
140 virtual void emitFPU(unsigned FPU);
141 virtual void emitArch(unsigned Arch);
142 virtual void emitArchExtension(unsigned ArchExt);
143 virtual void emitObjectArch(unsigned Arch);
144 virtual void finishAttributeSection();
145 virtual void emitInst(uint32_t Inst, char Suffix = '\0');
147 virtual void AnnotateTLSDescriptorSequence(const MCSymbolRefExpr *SRE);
149 virtual void emitThumbSet(MCSymbol *Symbol, const MCExpr *Value);
151 void finish() override;
153 /// Callback used to implement the ldr= pseudo.
154 /// Add a new entry to the constant pool for the current section and return an
155 /// MCExpr that can be used to refer to the constant pool location.
156 const MCExpr *addConstantPoolEntry(const MCExpr *);
158 /// Callback used to implemnt the .ltorg directive.
159 /// Emit contents of constant pool for the current section.
160 void emitCurrentConstantPool();
163 std::unique_ptr<AssemblerConstantPools> ConstantPools;
166 /// \brief Streaming machine code generation interface.
168 /// This interface is intended to provide a programatic interface that is very
169 /// similar to the level that an assembler .s file provides. It has callbacks
170 /// to emit bytes, handle directives, etc. The implementation of this interface
171 /// retains state to know what the current section is etc.
173 /// There are multiple implementations of this interface: one for writing out
174 /// a .s file, and implementations that write out .o files of various formats.
178 std::unique_ptr<MCTargetStreamer> TargetStreamer;
180 MCStreamer(const MCStreamer &) = delete;
181 MCStreamer &operator=(const MCStreamer &) = delete;
183 std::vector<MCDwarfFrameInfo> DwarfFrameInfos;
184 MCDwarfFrameInfo *getCurrentDwarfFrameInfo();
185 void EnsureValidDwarfFrame();
187 MCSymbol *EmitCFICommon();
189 std::vector<WinEH::FrameInfo *> WinFrameInfos;
190 WinEH::FrameInfo *CurrentWinFrameInfo;
191 void EnsureValidWinFrameInfo();
193 /// \brief Tracks an index to represent the order a symbol was emitted in.
194 /// Zero means we did not emit that symbol.
195 DenseMap<const MCSymbol *, unsigned> SymbolOrdering;
197 /// \brief This is stack of current and previous section values saved by
199 SmallVector<std::pair<MCSectionSubPair, MCSectionSubPair>, 4> SectionStack;
202 MCStreamer(MCContext &Ctx);
204 virtual void EmitCFIStartProcImpl(MCDwarfFrameInfo &Frame);
205 virtual void EmitCFIEndProcImpl(MCDwarfFrameInfo &CurFrame);
207 WinEH::FrameInfo *getCurrentWinFrameInfo() {
208 return CurrentWinFrameInfo;
211 virtual void EmitWindowsUnwindTables();
213 virtual void EmitRawTextImpl(StringRef String);
216 virtual ~MCStreamer();
218 void visitUsedExpr(const MCExpr &Expr);
219 virtual void visitUsedSymbol(const MCSymbol &Sym);
221 void setTargetStreamer(MCTargetStreamer *TS) {
222 TargetStreamer.reset(TS);
227 virtual void reset();
229 MCContext &getContext() const { return Context; }
231 MCTargetStreamer *getTargetStreamer() {
232 return TargetStreamer.get();
235 unsigned getNumFrameInfos() { return DwarfFrameInfos.size(); }
236 ArrayRef<MCDwarfFrameInfo> getDwarfFrameInfos() const {
237 return DwarfFrameInfos;
240 unsigned getNumWinFrameInfos() { return WinFrameInfos.size(); }
241 ArrayRef<WinEH::FrameInfo *> getWinFrameInfos() const {
242 return WinFrameInfos;
245 void generateCompactUnwindEncodings(MCAsmBackend *MAB);
247 /// \name Assembly File Formatting.
250 /// \brief Return true if this streamer supports verbose assembly and if it is
252 virtual bool isVerboseAsm() const { return false; }
254 /// \brief Return true if this asm streamer supports emitting unformatted text
255 /// to the .s file with EmitRawText.
256 virtual bool hasRawTextSupport() const { return false; }
258 /// \brief Is the integrated assembler required for this streamer to function
260 virtual bool isIntegratedAssemblerRequired() const { return false; }
262 /// \brief Add a textual command.
264 /// Typically for comments that can be emitted to the generated .s
265 /// file if applicable as a QoI issue to make the output of the compiler
266 /// more readable. This only affects the MCAsmStreamer, and only when
267 /// verbose assembly output is enabled.
269 /// If the comment includes embedded \n's, they will each get the comment
270 /// prefix as appropriate. The added comment should not end with a \n.
271 virtual void AddComment(const Twine &T) {}
273 /// \brief Return a raw_ostream that comments can be written to. Unlike
274 /// AddComment, you are required to terminate comments with \n if you use this
276 virtual raw_ostream &GetCommentOS();
278 /// \brief Print T and prefix it with the comment string (normally #) and
279 /// optionally a tab. This prints the comment immediately, not at the end of
280 /// the current line. It is basically a safe version of EmitRawText: since it
281 /// only prints comments, the object streamer ignores it instead of asserting.
282 virtual void emitRawComment(const Twine &T, bool TabPrefix = true);
284 /// AddBlankLine - Emit a blank line to a .s file to pretty it up.
285 virtual void AddBlankLine() {}
289 /// \name Symbol & Section Management
292 /// \brief Return the current section that the streamer is emitting code to.
293 MCSectionSubPair getCurrentSection() const {
294 if (!SectionStack.empty())
295 return SectionStack.back().first;
296 return MCSectionSubPair();
299 /// \brief Return the previous section that the streamer is emitting code to.
300 MCSectionSubPair getPreviousSection() const {
301 if (!SectionStack.empty())
302 return SectionStack.back().second;
303 return MCSectionSubPair();
306 /// \brief Returns an index to represent the order a symbol was emitted in.
307 /// (zero if we did not emit that symbol)
308 unsigned GetSymbolOrder(const MCSymbol *Sym) const {
309 return SymbolOrdering.lookup(Sym);
312 /// \brief Update streamer for a new active section.
314 /// This is called by PopSection and SwitchSection, if the current
316 virtual void ChangeSection(const MCSection *, const MCExpr *);
318 /// \brief Save the current and previous section on the section stack.
320 SectionStack.push_back(
321 std::make_pair(getCurrentSection(), getPreviousSection()));
324 /// \brief Restore the current and previous section from the section stack.
325 /// Calls ChangeSection as needed.
327 /// Returns false if the stack was empty.
329 if (SectionStack.size() <= 1)
331 MCSectionSubPair oldSection = SectionStack.pop_back_val().first;
332 MCSectionSubPair curSection = SectionStack.back().first;
334 if (oldSection != curSection)
335 ChangeSection(curSection.first, curSection.second);
339 bool SubSection(const MCExpr *Subsection) {
340 if (SectionStack.empty())
343 SwitchSection(SectionStack.back().first.first, Subsection);
347 /// Set the current section where code is being emitted to \p Section. This
348 /// is required to update CurSection.
350 /// This corresponds to assembler directives like .section, .text, etc.
351 virtual void SwitchSection(const MCSection *Section,
352 const MCExpr *Subsection = nullptr);
354 /// \brief Set the current section where code is being emitted to \p Section.
355 /// This is required to update CurSection. This version does not call
357 void SwitchSectionNoChange(const MCSection *Section,
358 const MCExpr *Subsection = nullptr) {
359 assert(Section && "Cannot switch to a null section!");
360 MCSectionSubPair curSection = SectionStack.back().first;
361 SectionStack.back().second = curSection;
362 if (MCSectionSubPair(Section, Subsection) != curSection)
363 SectionStack.back().first = MCSectionSubPair(Section, Subsection);
366 /// \brief Create the default sections and set the initial one.
367 virtual void InitSections(bool NoExecStack);
369 MCSymbol *endSection(const MCSection *Section);
371 /// \brief Sets the symbol's section.
373 /// Each emitted symbol will be tracked in the ordering table,
374 /// so we can sort on them later.
375 void AssignSection(MCSymbol *Symbol, const MCSection *Section);
377 /// \brief Emit a label for \p Symbol into the current section.
379 /// This corresponds to an assembler statement such as:
382 /// \param Symbol - The symbol to emit. A given symbol should only be
383 /// emitted as a label once, and symbols emitted as a label should never be
384 /// used in an assignment.
385 // FIXME: These emission are non-const because we mutate the symbol to
386 // add the section we're emitting it to later.
387 virtual void EmitLabel(MCSymbol *Symbol);
389 virtual void EmitEHSymAttributes(const MCSymbol *Symbol, MCSymbol *EHSymbol);
391 /// \brief Note in the output the specified \p Flag.
392 virtual void EmitAssemblerFlag(MCAssemblerFlag Flag);
394 /// \brief Emit the given list \p Options of strings as linker
395 /// options into the output.
396 virtual void EmitLinkerOptions(ArrayRef<std::string> Kind) {}
398 /// \brief Note in the output the specified region \p Kind.
399 virtual void EmitDataRegion(MCDataRegionType Kind) {}
401 /// \brief Specify the MachO minimum deployment target version.
402 virtual void EmitVersionMin(MCVersionMinType, unsigned Major, unsigned Minor,
405 /// \brief Note in the output that the specified \p Func is a Thumb mode
406 /// function (ARM target only).
407 virtual void EmitThumbFunc(MCSymbol *Func);
409 /// \brief Emit an assignment of \p Value to \p Symbol.
411 /// This corresponds to an assembler statement such as:
414 /// The assignment generates no code, but has the side effect of binding the
415 /// value in the current context. For the assembly streamer, this prints the
416 /// binding into the .s file.
418 /// \param Symbol - The symbol being assigned to.
419 /// \param Value - The value for the symbol.
420 virtual void EmitAssignment(MCSymbol *Symbol, const MCExpr *Value);
422 /// \brief Emit an weak reference from \p Alias to \p Symbol.
424 /// This corresponds to an assembler statement such as:
425 /// .weakref alias, symbol
427 /// \param Alias - The alias that is being created.
428 /// \param Symbol - The symbol being aliased.
429 virtual void EmitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol);
431 /// \brief Add the given \p Attribute to \p Symbol.
432 virtual bool EmitSymbolAttribute(MCSymbol *Symbol,
433 MCSymbolAttr Attribute) = 0;
435 /// \brief Set the \p DescValue for the \p Symbol.
437 /// \param Symbol - The symbol to have its n_desc field set.
438 /// \param DescValue - The value to set into the n_desc field.
439 virtual void EmitSymbolDesc(MCSymbol *Symbol, unsigned DescValue);
441 /// \brief Start emitting COFF symbol definition
443 /// \param Symbol - The symbol to have its External & Type fields set.
444 virtual void BeginCOFFSymbolDef(const MCSymbol *Symbol);
446 /// \brief Emit the storage class of the symbol.
448 /// \param StorageClass - The storage class the symbol should have.
449 virtual void EmitCOFFSymbolStorageClass(int StorageClass);
451 /// \brief Emit the type of the symbol.
453 /// \param Type - A COFF type identifier (see COFF::SymbolType in X86COFF.h)
454 virtual void EmitCOFFSymbolType(int Type);
456 /// \brief Marks the end of the symbol definition.
457 virtual void EndCOFFSymbolDef();
459 /// \brief Emits a COFF section index.
461 /// \param Symbol - Symbol the section number relocation should point to.
462 virtual void EmitCOFFSectionIndex(MCSymbol const *Symbol);
464 /// \brief Emits a COFF section relative relocation.
466 /// \param Symbol - Symbol the section relative relocation should point to.
467 virtual void EmitCOFFSecRel32(MCSymbol const *Symbol);
469 /// \brief Emit an ELF .size directive.
471 /// This corresponds to an assembler statement such as:
472 /// .size symbol, expression
473 virtual void EmitELFSize(MCSymbol *Symbol, const MCExpr *Value);
475 /// \brief Emit a Linker Optimization Hint (LOH) directive.
476 /// \param Args - Arguments of the LOH.
477 virtual void EmitLOHDirective(MCLOHType Kind, const MCLOHArgs &Args) {}
479 /// \brief Emit a common symbol.
481 /// \param Symbol - The common symbol to emit.
482 /// \param Size - The size of the common symbol.
483 /// \param ByteAlignment - The alignment of the symbol if
484 /// non-zero. This must be a power of 2.
485 virtual void EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
486 unsigned ByteAlignment) = 0;
488 /// \brief Emit a local common (.lcomm) symbol.
490 /// \param Symbol - The common symbol to emit.
491 /// \param Size - The size of the common symbol.
492 /// \param ByteAlignment - The alignment of the common symbol in bytes.
493 virtual void EmitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size,
494 unsigned ByteAlignment);
496 /// \brief Emit the zerofill section and an optional symbol.
498 /// \param Section - The zerofill section to create and or to put the symbol
499 /// \param Symbol - The zerofill symbol to emit, if non-NULL.
500 /// \param Size - The size of the zerofill symbol.
501 /// \param ByteAlignment - The alignment of the zerofill symbol if
502 /// non-zero. This must be a power of 2 on some targets.
503 virtual void EmitZerofill(const MCSection *Section,
504 MCSymbol *Symbol = nullptr, uint64_t Size = 0,
505 unsigned ByteAlignment = 0) = 0;
507 /// \brief Emit a thread local bss (.tbss) symbol.
509 /// \param Section - The thread local common section.
510 /// \param Symbol - The thread local common symbol to emit.
511 /// \param Size - The size of the symbol.
512 /// \param ByteAlignment - The alignment of the thread local common symbol
513 /// if non-zero. This must be a power of 2 on some targets.
514 virtual void EmitTBSSSymbol(const MCSection *Section, MCSymbol *Symbol,
515 uint64_t Size, unsigned ByteAlignment = 0);
518 /// \name Generating Data
521 /// \brief Emit the bytes in \p Data into the output.
523 /// This is used to implement assembler directives such as .byte, .ascii,
525 virtual void EmitBytes(StringRef Data);
527 /// \brief Emit the expression \p Value into the output as a native
528 /// integer of the given \p Size bytes.
530 /// This is used to implement assembler directives such as .word, .quad,
533 /// \param Value - The value to emit.
534 /// \param Size - The size of the integer (in bytes) to emit. This must
535 /// match a native machine width.
536 /// \param Loc - The location of the expression for error reporting.
537 virtual void EmitValueImpl(const MCExpr *Value, unsigned Size,
538 const SMLoc &Loc = SMLoc());
540 void EmitValue(const MCExpr *Value, unsigned Size,
541 const SMLoc &Loc = SMLoc());
543 /// \brief Special case of EmitValue that avoids the client having
544 /// to pass in a MCExpr for constant integers.
545 virtual void EmitIntValue(uint64_t Value, unsigned Size);
547 virtual void EmitULEB128Value(const MCExpr *Value);
549 virtual void EmitSLEB128Value(const MCExpr *Value);
551 /// \brief Special case of EmitULEB128Value that avoids the client having to
552 /// pass in a MCExpr for constant integers.
553 void EmitULEB128IntValue(uint64_t Value, unsigned Padding = 0);
555 /// \brief Special case of EmitSLEB128Value that avoids the client having to
556 /// pass in a MCExpr for constant integers.
557 void EmitSLEB128IntValue(int64_t Value);
559 /// \brief Special case of EmitValue that avoids the client having to pass in
560 /// a MCExpr for MCSymbols.
561 void EmitSymbolValue(const MCSymbol *Sym, unsigned Size,
562 bool IsSectionRelative = false);
564 /// \brief Emit the expression \p Value into the output as a gprel64 (64-bit
565 /// GP relative) value.
567 /// This is used to implement assembler directives such as .gpdword on
568 /// targets that support them.
569 virtual void EmitGPRel64Value(const MCExpr *Value);
571 /// \brief Emit the expression \p Value into the output as a gprel32 (32-bit
572 /// GP relative) value.
574 /// This is used to implement assembler directives such as .gprel32 on
575 /// targets that support them.
576 virtual void EmitGPRel32Value(const MCExpr *Value);
578 /// \brief Emit NumBytes bytes worth of the value specified by FillValue.
579 /// This implements directives such as '.space'.
580 virtual void EmitFill(uint64_t NumBytes, uint8_t FillValue);
582 /// \brief Emit NumBytes worth of zeros.
583 /// This function properly handles data in virtual sections.
584 virtual void EmitZeros(uint64_t NumBytes);
586 /// \brief Emit some number of copies of \p Value until the byte alignment \p
587 /// ByteAlignment is reached.
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
593 /// This used to implement the .align assembler directive.
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
603 virtual void EmitValueToAlignment(unsigned ByteAlignment, int64_t Value = 0,
604 unsigned ValueSize = 1,
605 unsigned MaxBytesToEmit = 0);
607 /// \brief Emit nops until the byte alignment \p ByteAlignment is reached.
609 /// This used to align code where the alignment bytes may be executed. This
610 /// can emit different bytes for different sizes to optimize execution.
612 /// \param ByteAlignment - The alignment to reach. This must be a power of
613 /// two on some targets.
614 /// \param MaxBytesToEmit - The maximum numbers of bytes to emit, or 0. If
615 /// the alignment cannot be reached in this many bytes, no bytes are
617 virtual void EmitCodeAlignment(unsigned ByteAlignment,
618 unsigned MaxBytesToEmit = 0);
620 /// \brief Emit some number of copies of \p Value until the byte offset \p
621 /// Offset is reached.
623 /// This is used to implement assembler directives such as .org.
625 /// \param Offset - The offset to reach. This may be an expression, but the
626 /// expression must be associated with the current section.
627 /// \param Value - The value to use when filling bytes.
628 /// \return false on success, true if the offset was invalid.
629 virtual bool EmitValueToOffset(const MCExpr *Offset,
630 unsigned char Value = 0);
634 /// \brief Switch to a new logical file. This is used to implement the '.file
635 /// "foo.c"' assembler directive.
636 virtual void EmitFileDirective(StringRef Filename);
638 /// \brief Emit the "identifiers" directive. This implements the
639 /// '.ident "version foo"' assembler directive.
640 virtual void EmitIdent(StringRef IdentString) {}
642 /// \brief Associate a filename with a specified logical file number. This
643 /// implements the DWARF2 '.file 4 "foo.c"' assembler directive.
644 virtual unsigned EmitDwarfFileDirective(unsigned FileNo, StringRef Directory,
648 /// \brief This implements the DWARF2 '.loc fileno lineno ...' assembler
650 virtual void EmitDwarfLocDirective(unsigned FileNo, unsigned Line,
651 unsigned Column, unsigned Flags,
652 unsigned Isa, unsigned Discriminator,
655 /// Emit the absolute difference between two symbols if possible.
657 /// \pre Offset of \c Hi is greater than the offset \c Lo.
658 /// \return true on success.
659 virtual bool emitAbsoluteSymbolDiff(const MCSymbol *Hi, const MCSymbol *Lo,
664 virtual MCSymbol *getDwarfLineTableSymbol(unsigned CUID);
665 virtual void EmitCFISections(bool EH, bool Debug);
666 void EmitCFIStartProc(bool IsSimple);
667 void EmitCFIEndProc();
668 virtual void EmitCFIDefCfa(int64_t Register, int64_t Offset);
669 virtual void EmitCFIDefCfaOffset(int64_t Offset);
670 virtual void EmitCFIDefCfaRegister(int64_t Register);
671 virtual void EmitCFIOffset(int64_t Register, int64_t Offset);
672 virtual void EmitCFIPersonality(const MCSymbol *Sym, unsigned Encoding);
673 virtual void EmitCFILsda(const MCSymbol *Sym, unsigned Encoding);
674 virtual void EmitCFIRememberState();
675 virtual void EmitCFIRestoreState();
676 virtual void EmitCFISameValue(int64_t Register);
677 virtual void EmitCFIRestore(int64_t Register);
678 virtual void EmitCFIRelOffset(int64_t Register, int64_t Offset);
679 virtual void EmitCFIAdjustCfaOffset(int64_t Adjustment);
680 virtual void EmitCFIEscape(StringRef Values);
681 virtual void EmitCFISignalFrame();
682 virtual void EmitCFIUndefined(int64_t Register);
683 virtual void EmitCFIRegister(int64_t Register1, int64_t Register2);
684 virtual void EmitCFIWindowSave();
686 virtual void EmitWinCFIStartProc(const MCSymbol *Symbol);
687 virtual void EmitWinCFIEndProc();
688 virtual void EmitWinCFIStartChained();
689 virtual void EmitWinCFIEndChained();
690 virtual void EmitWinCFIPushReg(unsigned Register);
691 virtual void EmitWinCFISetFrame(unsigned Register, unsigned Offset);
692 virtual void EmitWinCFIAllocStack(unsigned Size);
693 virtual void EmitWinCFISaveReg(unsigned Register, unsigned Offset);
694 virtual void EmitWinCFISaveXMM(unsigned Register, unsigned Offset);
695 virtual void EmitWinCFIPushFrame(bool Code);
696 virtual void EmitWinCFIEndProlog();
698 virtual void EmitWinEHHandler(const MCSymbol *Sym, bool Unwind, bool Except);
699 virtual void EmitWinEHHandlerData();
701 /// \brief Emit the given \p Instruction into the current section.
702 virtual void EmitInstruction(const MCInst &Inst, const MCSubtargetInfo &STI);
704 /// \brief Set the bundle alignment mode from now on in the section.
705 /// The argument is the power of 2 to which the alignment is set. The
706 /// value 0 means turn the bundle alignment off.
707 virtual void EmitBundleAlignMode(unsigned AlignPow2);
709 /// \brief The following instructions are a bundle-locked group.
711 /// \param AlignToEnd - If true, the bundle-locked group will be aligned to
712 /// the end of a bundle.
713 virtual void EmitBundleLock(bool AlignToEnd);
715 /// \brief Ends a bundle-locked group.
716 virtual void EmitBundleUnlock();
718 /// \brief If this file is backed by a assembly streamer, this dumps the
719 /// specified string in the output .s file. This capability is indicated by
720 /// the hasRawTextSupport() predicate. By default this aborts.
721 void EmitRawText(const Twine &String);
723 /// \brief Causes any cached state to be written out.
724 virtual void Flush() {}
726 /// \brief Streamer specific finalization.
727 virtual void FinishImpl();
728 /// \brief Finish emission of machine code.
731 virtual bool mayHaveInstructions(const MCSection &Sec) const { return true; }
734 /// Create a dummy machine code streamer, which does nothing. This is useful for
735 /// timing the assembler front end.
736 MCStreamer *createNullStreamer(MCContext &Ctx);
738 /// Create a machine code streamer which will print out assembly for the native
739 /// target, suitable for compiling with a native assembler.
741 /// \param InstPrint - If given, the instruction printer to use. If not given
742 /// the MCInst representation will be printed. This method takes ownership of
745 /// \param CE - If given, a code emitter to use to show the instruction
746 /// encoding inline with the assembly. This method takes ownership of \p CE.
748 /// \param TAB - If given, a target asm backend to use to show the fixup
749 /// information in conjunction with encoding information. This method takes
750 /// ownership of \p TAB.
752 /// \param ShowInst - Whether to show the MCInst representation inline with
754 MCStreamer *createAsmStreamer(MCContext &Ctx,
755 std::unique_ptr<formatted_raw_ostream> OS,
756 bool isVerboseAsm, bool useDwarfDirectory,
757 MCInstPrinter *InstPrint, MCCodeEmitter *CE,
758 MCAsmBackend *TAB, bool ShowInst);
759 } // end namespace llvm