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/MCSymbol.h"
23 #include "llvm/MC/MCWinEH.h"
24 #include "llvm/Support/DataTypes.h"
25 #include "llvm/Support/SMLoc.h"
38 class MCSymbolRefExpr;
39 class MCSubtargetInfo;
43 class formatted_raw_ostream;
44 class AssemblerConstantPools;
46 typedef std::pair<MCSection *, const MCExpr *> MCSectionSubPair;
48 /// Target specific streamer interface. This is used so that targets can
49 /// implement support for target specific assembly directives.
51 /// If target foo wants to use this, it should implement 3 classes:
52 /// * FooTargetStreamer : public MCTargetStreamer
53 /// * FooTargetAsmStreamer : public FooTargetStreamer
54 /// * FooTargetELFStreamer : public FooTargetStreamer
56 /// FooTargetStreamer should have a pure virtual method for each directive. For
57 /// example, for a ".bar symbol_name" directive, it should have
58 /// virtual emitBar(const MCSymbol &Symbol) = 0;
60 /// The FooTargetAsmStreamer and FooTargetELFStreamer classes implement the
61 /// method. The assembly streamer just prints ".bar symbol_name". The object
62 /// streamer does whatever is needed to implement .bar in the object file.
64 /// In the assembly printer and parser the target streamer can be used by
65 /// calling getTargetStreamer and casting it to FooTargetStreamer:
67 /// MCTargetStreamer &TS = OutStreamer.getTargetStreamer();
68 /// FooTargetStreamer &ATS = static_cast<FooTargetStreamer &>(TS);
70 /// The base classes FooTargetAsmStreamer and FooTargetELFStreamer should
71 /// *never* be treated differently. Callers should always talk to a
72 /// FooTargetStreamer.
73 class MCTargetStreamer {
78 MCTargetStreamer(MCStreamer &S);
79 virtual ~MCTargetStreamer();
81 MCStreamer &getStreamer() { return Streamer; }
83 // Allow a target to add behavior to the EmitLabel of MCStreamer.
84 virtual void emitLabel(MCSymbol *Symbol);
85 // Allow a target to add behavior to the emitAssignment of MCStreamer.
86 virtual void emitAssignment(MCSymbol *Symbol, const MCExpr *Value);
88 virtual void prettyPrintAsm(MCInstPrinter &InstPrinter, raw_ostream &OS,
89 const MCInst &Inst, const MCSubtargetInfo &STI);
91 virtual void finish();
94 // FIXME: declared here because it is used from
95 // lib/CodeGen/AsmPrinter/ARMException.cpp.
96 class ARMTargetStreamer : public MCTargetStreamer {
98 ARMTargetStreamer(MCStreamer &S);
99 ~ARMTargetStreamer() override;
101 virtual void emitFnStart();
102 virtual void emitFnEnd();
103 virtual void emitCantUnwind();
104 virtual void emitPersonality(const MCSymbol *Personality);
105 virtual void emitPersonalityIndex(unsigned Index);
106 virtual void emitHandlerData();
107 virtual void emitSetFP(unsigned FpReg, unsigned SpReg,
109 virtual void emitMovSP(unsigned Reg, int64_t Offset = 0);
110 virtual void emitPad(int64_t Offset);
111 virtual void emitRegSave(const SmallVectorImpl<unsigned> &RegList,
113 virtual void emitUnwindRaw(int64_t StackOffset,
114 const SmallVectorImpl<uint8_t> &Opcodes);
116 virtual void switchVendor(StringRef Vendor);
117 virtual void emitAttribute(unsigned Attribute, unsigned Value);
118 virtual void emitTextAttribute(unsigned Attribute, StringRef String);
119 virtual void emitIntTextAttribute(unsigned Attribute, unsigned IntValue,
120 StringRef StringValue = "");
121 virtual void emitFPU(unsigned FPU);
122 virtual void emitArch(unsigned Arch);
123 virtual void emitArchExtension(unsigned ArchExt);
124 virtual void emitObjectArch(unsigned Arch);
125 virtual void finishAttributeSection();
126 virtual void emitInst(uint32_t Inst, char Suffix = '\0');
128 virtual void AnnotateTLSDescriptorSequence(const MCSymbolRefExpr *SRE);
130 virtual void emitThumbSet(MCSymbol *Symbol, const MCExpr *Value);
132 void finish() override;
134 /// Reset any state between object emissions, i.e. the equivalent of
135 /// MCStreamer's reset method.
136 virtual void reset();
138 /// Callback used to implement the ldr= pseudo.
139 /// Add a new entry to the constant pool for the current section and return an
140 /// MCExpr that can be used to refer to the constant pool location.
141 const MCExpr *addConstantPoolEntry(const MCExpr *, SMLoc Loc);
143 /// Callback used to implemnt the .ltorg directive.
144 /// Emit contents of constant pool for the current section.
145 void emitCurrentConstantPool();
148 std::unique_ptr<AssemblerConstantPools> ConstantPools;
151 /// \brief Streaming machine code generation interface.
153 /// This interface is intended to provide a programatic interface that is very
154 /// similar to the level that an assembler .s file provides. It has callbacks
155 /// to emit bytes, handle directives, etc. The implementation of this interface
156 /// retains state to know what the current section is etc.
158 /// There are multiple implementations of this interface: one for writing out
159 /// a .s file, and implementations that write out .o files of various formats.
163 std::unique_ptr<MCTargetStreamer> TargetStreamer;
165 MCStreamer(const MCStreamer &) = delete;
166 MCStreamer &operator=(const MCStreamer &) = delete;
168 std::vector<MCDwarfFrameInfo> DwarfFrameInfos;
169 MCDwarfFrameInfo *getCurrentDwarfFrameInfo();
170 void EnsureValidDwarfFrame();
172 MCSymbol *EmitCFICommon();
174 std::vector<WinEH::FrameInfo *> WinFrameInfos;
175 WinEH::FrameInfo *CurrentWinFrameInfo;
176 void EnsureValidWinFrameInfo();
178 /// \brief Tracks an index to represent the order a symbol was emitted in.
179 /// Zero means we did not emit that symbol.
180 DenseMap<const MCSymbol *, unsigned> SymbolOrdering;
182 /// \brief This is stack of current and previous section values saved by
184 SmallVector<std::pair<MCSectionSubPair, MCSectionSubPair>, 4> SectionStack;
187 MCStreamer(MCContext &Ctx);
189 virtual void EmitCFIStartProcImpl(MCDwarfFrameInfo &Frame);
190 virtual void EmitCFIEndProcImpl(MCDwarfFrameInfo &CurFrame);
192 WinEH::FrameInfo *getCurrentWinFrameInfo() {
193 return CurrentWinFrameInfo;
196 virtual void EmitWindowsUnwindTables();
198 virtual void EmitRawTextImpl(StringRef String);
201 virtual ~MCStreamer();
203 void visitUsedExpr(const MCExpr &Expr);
204 virtual void visitUsedSymbol(const MCSymbol &Sym);
206 void setTargetStreamer(MCTargetStreamer *TS) {
207 TargetStreamer.reset(TS);
212 virtual void reset();
214 MCContext &getContext() const { return Context; }
216 MCTargetStreamer *getTargetStreamer() {
217 return TargetStreamer.get();
220 unsigned getNumFrameInfos() { return DwarfFrameInfos.size(); }
221 ArrayRef<MCDwarfFrameInfo> getDwarfFrameInfos() const {
222 return DwarfFrameInfos;
225 unsigned getNumWinFrameInfos() { return WinFrameInfos.size(); }
226 ArrayRef<WinEH::FrameInfo *> getWinFrameInfos() const {
227 return WinFrameInfos;
230 void generateCompactUnwindEncodings(MCAsmBackend *MAB);
232 /// \name Assembly File Formatting.
235 /// \brief Return true if this streamer supports verbose assembly and if it is
237 virtual bool isVerboseAsm() const { return false; }
239 /// \brief Return true if this asm streamer supports emitting unformatted text
240 /// to the .s file with EmitRawText.
241 virtual bool hasRawTextSupport() const { return false; }
243 /// \brief Is the integrated assembler required for this streamer to function
245 virtual bool isIntegratedAssemblerRequired() const { return false; }
247 /// \brief Add a textual command.
249 /// Typically for comments that can be emitted to the generated .s
250 /// file if applicable as a QoI issue to make the output of the compiler
251 /// more readable. This only affects the MCAsmStreamer, and only when
252 /// verbose assembly output is enabled.
254 /// If the comment includes embedded \n's, they will each get the comment
255 /// prefix as appropriate. The added comment should not end with a \n.
256 virtual void AddComment(const Twine &T) {}
258 /// \brief Return a raw_ostream that comments can be written to. Unlike
259 /// AddComment, you are required to terminate comments with \n if you use this
261 virtual raw_ostream &GetCommentOS();
263 /// \brief Print T and prefix it with the comment string (normally #) and
264 /// optionally a tab. This prints the comment immediately, not at the end of
265 /// the current line. It is basically a safe version of EmitRawText: since it
266 /// only prints comments, the object streamer ignores it instead of asserting.
267 virtual void emitRawComment(const Twine &T, bool TabPrefix = true);
269 /// AddBlankLine - Emit a blank line to a .s file to pretty it up.
270 virtual void AddBlankLine() {}
274 /// \name Symbol & Section Management
277 /// \brief Return the current section that the streamer is emitting code to.
278 MCSectionSubPair getCurrentSection() const {
279 if (!SectionStack.empty())
280 return SectionStack.back().first;
281 return MCSectionSubPair();
283 MCSection *getCurrentSectionOnly() const { return getCurrentSection().first; }
285 /// \brief Return the previous section that the streamer is emitting code to.
286 MCSectionSubPair getPreviousSection() const {
287 if (!SectionStack.empty())
288 return SectionStack.back().second;
289 return MCSectionSubPair();
292 /// \brief Returns an index to represent the order a symbol was emitted in.
293 /// (zero if we did not emit that symbol)
294 unsigned GetSymbolOrder(const MCSymbol *Sym) const {
295 return SymbolOrdering.lookup(Sym);
298 /// \brief Update streamer for a new active section.
300 /// This is called by PopSection and SwitchSection, if the current
302 virtual void ChangeSection(MCSection *, const MCExpr *);
304 /// \brief Save the current and previous section on the section stack.
306 SectionStack.push_back(
307 std::make_pair(getCurrentSection(), getPreviousSection()));
310 /// \brief Restore the current and previous section from the section stack.
311 /// Calls ChangeSection as needed.
313 /// Returns false if the stack was empty.
315 if (SectionStack.size() <= 1)
317 auto I = SectionStack.end();
319 MCSectionSubPair OldSection = I->first;
321 MCSectionSubPair NewSection = I->first;
323 if (OldSection != NewSection)
324 ChangeSection(NewSection.first, NewSection.second);
325 SectionStack.pop_back();
329 bool SubSection(const MCExpr *Subsection) {
330 if (SectionStack.empty())
333 SwitchSection(SectionStack.back().first.first, Subsection);
337 /// Set the current section where code is being emitted to \p Section. This
338 /// is required to update CurSection.
340 /// This corresponds to assembler directives like .section, .text, etc.
341 virtual void SwitchSection(MCSection *Section,
342 const MCExpr *Subsection = nullptr);
344 /// \brief Set the current section where code is being emitted to \p Section.
345 /// This is required to update CurSection. This version does not call
347 void SwitchSectionNoChange(MCSection *Section,
348 const MCExpr *Subsection = nullptr) {
349 assert(Section && "Cannot switch to a null section!");
350 MCSectionSubPair curSection = SectionStack.back().first;
351 SectionStack.back().second = curSection;
352 if (MCSectionSubPair(Section, Subsection) != curSection)
353 SectionStack.back().first = MCSectionSubPair(Section, Subsection);
356 /// \brief Create the default sections and set the initial one.
357 virtual void InitSections(bool NoExecStack);
359 MCSymbol *endSection(MCSection *Section);
361 /// \brief Sets the symbol's section.
363 /// Each emitted symbol will be tracked in the ordering table,
364 /// so we can sort on them later.
365 void AssignFragment(MCSymbol *Symbol, MCFragment *Fragment);
367 /// \brief Emit a label for \p Symbol into the current section.
369 /// This corresponds to an assembler statement such as:
372 /// \param Symbol - The symbol to emit. A given symbol should only be
373 /// emitted as a label once, and symbols emitted as a label should never be
374 /// used in an assignment.
375 // FIXME: These emission are non-const because we mutate the symbol to
376 // add the section we're emitting it to later.
377 virtual void EmitLabel(MCSymbol *Symbol);
379 virtual void EmitEHSymAttributes(const MCSymbol *Symbol, MCSymbol *EHSymbol);
381 /// \brief Note in the output the specified \p Flag.
382 virtual void EmitAssemblerFlag(MCAssemblerFlag Flag);
384 /// \brief Emit the given list \p Options of strings as linker
385 /// options into the output.
386 virtual void EmitLinkerOptions(ArrayRef<std::string> Kind) {}
388 /// \brief Note in the output the specified region \p Kind.
389 virtual void EmitDataRegion(MCDataRegionType Kind) {}
391 /// \brief Specify the MachO minimum deployment target version.
392 virtual void EmitVersionMin(MCVersionMinType, unsigned Major, unsigned Minor,
395 /// \brief Note in the output that the specified \p Func is a Thumb mode
396 /// function (ARM target only).
397 virtual void EmitThumbFunc(MCSymbol *Func);
399 /// \brief Emit an assignment of \p Value to \p Symbol.
401 /// This corresponds to an assembler statement such as:
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.
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);
412 /// \brief Emit an weak reference from \p Alias to \p Symbol.
414 /// This corresponds to an assembler statement such as:
415 /// .weakref alias, symbol
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);
421 /// \brief Add the given \p Attribute to \p Symbol.
422 virtual bool EmitSymbolAttribute(MCSymbol *Symbol,
423 MCSymbolAttr Attribute) = 0;
425 /// \brief Set the \p DescValue for the \p Symbol.
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);
431 /// \brief Start emitting COFF symbol definition
433 /// \param Symbol - The symbol to have its External & Type fields set.
434 virtual void BeginCOFFSymbolDef(const MCSymbol *Symbol);
436 /// \brief Emit the storage class of the symbol.
438 /// \param StorageClass - The storage class the symbol should have.
439 virtual void EmitCOFFSymbolStorageClass(int StorageClass);
441 /// \brief Emit the type of the symbol.
443 /// \param Type - A COFF type identifier (see COFF::SymbolType in X86COFF.h)
444 virtual void EmitCOFFSymbolType(int Type);
446 /// \brief Marks the end of the symbol definition.
447 virtual void EndCOFFSymbolDef();
449 virtual void EmitCOFFSafeSEH(MCSymbol const *Symbol);
451 /// \brief Emits a COFF section index.
453 /// \param Symbol - Symbol the section number relocation should point to.
454 virtual void EmitCOFFSectionIndex(MCSymbol const *Symbol);
456 /// \brief Emits a COFF section relative relocation.
458 /// \param Symbol - Symbol the section relative relocation should point to.
459 virtual void EmitCOFFSecRel32(MCSymbol const *Symbol);
461 /// \brief Emit an ELF .size directive.
463 /// This corresponds to an assembler statement such as:
464 /// .size symbol, expression
465 virtual void emitELFSize(MCSymbolELF *Symbol, const MCExpr *Value);
467 /// \brief Emit a Linker Optimization Hint (LOH) directive.
468 /// \param Args - Arguments of the LOH.
469 virtual void EmitLOHDirective(MCLOHType Kind, const MCLOHArgs &Args) {}
471 /// \brief Emit a common symbol.
473 /// \param Symbol - The common symbol to emit.
474 /// \param Size - The size of the common symbol.
475 /// \param ByteAlignment - The alignment of the symbol if
476 /// non-zero. This must be a power of 2.
477 virtual void EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
478 unsigned ByteAlignment) = 0;
480 /// \brief Emit a local common (.lcomm) symbol.
482 /// \param Symbol - The common symbol to emit.
483 /// \param Size - The size of the common symbol.
484 /// \param ByteAlignment - The alignment of the common symbol in bytes.
485 virtual void EmitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size,
486 unsigned ByteAlignment);
488 /// \brief Emit the zerofill section and an optional symbol.
490 /// \param Section - The zerofill section to create and or to put the symbol
491 /// \param Symbol - The zerofill symbol to emit, if non-NULL.
492 /// \param Size - The size of the zerofill symbol.
493 /// \param ByteAlignment - The alignment of the zerofill symbol if
494 /// non-zero. This must be a power of 2 on some targets.
495 virtual void EmitZerofill(MCSection *Section, MCSymbol *Symbol = nullptr,
496 uint64_t Size = 0, unsigned ByteAlignment = 0) = 0;
498 /// \brief Emit a thread local bss (.tbss) symbol.
500 /// \param Section - The thread local common section.
501 /// \param Symbol - The thread local common symbol to emit.
502 /// \param Size - The size of the symbol.
503 /// \param ByteAlignment - The alignment of the thread local common symbol
504 /// if non-zero. This must be a power of 2 on some targets.
505 virtual void EmitTBSSSymbol(MCSection *Section, MCSymbol *Symbol,
506 uint64_t Size, unsigned ByteAlignment = 0);
509 /// \name Generating Data
512 /// \brief Emit the bytes in \p Data into the output.
514 /// This is used to implement assembler directives such as .byte, .ascii,
516 virtual void EmitBytes(StringRef Data);
518 /// \brief Emit the expression \p Value into the output as a native
519 /// integer of the given \p Size bytes.
521 /// This is used to implement assembler directives such as .word, .quad,
524 /// \param Value - The value to emit.
525 /// \param Size - The size of the integer (in bytes) to emit. This must
526 /// match a native machine width.
527 /// \param Loc - The location of the expression for error reporting.
528 virtual void EmitValueImpl(const MCExpr *Value, unsigned Size,
529 SMLoc Loc = SMLoc());
531 void EmitValue(const MCExpr *Value, unsigned Size, SMLoc Loc = SMLoc());
533 /// \brief Special case of EmitValue that avoids the client having
534 /// to pass in a MCExpr for constant integers.
535 virtual void EmitIntValue(uint64_t Value, unsigned Size);
537 virtual void EmitULEB128Value(const MCExpr *Value);
539 virtual void EmitSLEB128Value(const MCExpr *Value);
541 /// \brief Special case of EmitULEB128Value that avoids the client having to
542 /// pass in a MCExpr for constant integers.
543 void EmitULEB128IntValue(uint64_t Value, unsigned Padding = 0);
545 /// \brief Special case of EmitSLEB128Value that avoids the client having to
546 /// pass in a MCExpr for constant integers.
547 void EmitSLEB128IntValue(int64_t Value);
549 /// \brief Special case of EmitValue that avoids the client having to pass in
550 /// a MCExpr for MCSymbols.
551 void EmitSymbolValue(const MCSymbol *Sym, unsigned Size,
552 bool IsSectionRelative = false);
554 /// \brief Emit the expression \p Value into the output as a gprel64 (64-bit
555 /// GP relative) value.
557 /// This is used to implement assembler directives such as .gpdword on
558 /// targets that support them.
559 virtual void EmitGPRel64Value(const MCExpr *Value);
561 /// \brief Emit the expression \p Value into the output as a gprel32 (32-bit
562 /// GP relative) value.
564 /// This is used to implement assembler directives such as .gprel32 on
565 /// targets that support them.
566 virtual void EmitGPRel32Value(const MCExpr *Value);
568 /// \brief Emit NumBytes bytes worth of the value specified by FillValue.
569 /// This implements directives such as '.space'.
570 virtual void EmitFill(uint64_t NumBytes, uint8_t FillValue);
572 /// \brief Emit NumBytes worth of zeros.
573 /// This function properly handles data in virtual sections.
574 void EmitZeros(uint64_t NumBytes);
576 /// \brief Emit some number of copies of \p Value until the byte alignment \p
577 /// ByteAlignment is reached.
579 /// If the number of bytes need to emit for the alignment is not a multiple
580 /// of \p ValueSize, then the contents of the emitted fill bytes is
583 /// This used to implement the .align assembler directive.
585 /// \param ByteAlignment - The alignment to reach. This must be a power of
586 /// two on some targets.
587 /// \param Value - The value to use when filling bytes.
588 /// \param ValueSize - The size of the integer (in bytes) to emit for
589 /// \p Value. This must match a native machine width.
590 /// \param MaxBytesToEmit - The maximum numbers of bytes to emit, or 0. If
591 /// the alignment cannot be reached in this many bytes, no bytes are
593 virtual void EmitValueToAlignment(unsigned ByteAlignment, int64_t Value = 0,
594 unsigned ValueSize = 1,
595 unsigned MaxBytesToEmit = 0);
597 /// \brief Emit nops until the byte alignment \p ByteAlignment is reached.
599 /// This used to align code where the alignment bytes may be executed. This
600 /// can emit different bytes for different sizes to optimize execution.
602 /// \param ByteAlignment - The alignment to reach. This must be a power of
603 /// two on some targets.
604 /// \param MaxBytesToEmit - The maximum numbers of bytes to emit, or 0. If
605 /// the alignment cannot be reached in this many bytes, no bytes are
607 virtual void EmitCodeAlignment(unsigned ByteAlignment,
608 unsigned MaxBytesToEmit = 0);
610 /// \brief Emit some number of copies of \p Value until the byte offset \p
611 /// Offset is reached.
613 /// This is used to implement assembler directives such as .org.
615 /// \param Offset - The offset to reach. This may be an expression, but the
616 /// expression must be associated with the current section.
617 /// \param Value - The value to use when filling bytes.
618 virtual void emitValueToOffset(const MCExpr *Offset, unsigned char Value = 0);
622 /// \brief Switch to a new logical file. This is used to implement the '.file
623 /// "foo.c"' assembler directive.
624 virtual void EmitFileDirective(StringRef Filename);
626 /// \brief Emit the "identifiers" directive. This implements the
627 /// '.ident "version foo"' assembler directive.
628 virtual void EmitIdent(StringRef IdentString) {}
630 /// \brief Associate a filename with a specified logical file number. This
631 /// implements the DWARF2 '.file 4 "foo.c"' assembler directive.
632 virtual unsigned EmitDwarfFileDirective(unsigned FileNo, StringRef Directory,
636 /// \brief This implements the DWARF2 '.loc fileno lineno ...' assembler
638 virtual void EmitDwarfLocDirective(unsigned FileNo, unsigned Line,
639 unsigned Column, unsigned Flags,
640 unsigned Isa, unsigned Discriminator,
643 /// Emit the absolute difference between two symbols.
645 /// \pre Offset of \c Hi is greater than the offset \c Lo.
646 virtual void emitAbsoluteSymbolDiff(const MCSymbol *Hi, const MCSymbol *Lo,
649 virtual MCSymbol *getDwarfLineTableSymbol(unsigned CUID);
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 EmitCFIGnuArgsSize(int64_t Size);
667 virtual void EmitCFISignalFrame();
668 virtual void EmitCFIUndefined(int64_t Register);
669 virtual void EmitCFIRegister(int64_t Register1, int64_t Register2);
670 virtual void EmitCFIWindowSave();
672 virtual void EmitWinCFIStartProc(const MCSymbol *Symbol);
673 virtual void EmitWinCFIEndProc();
674 virtual void EmitWinCFIStartChained();
675 virtual void EmitWinCFIEndChained();
676 virtual void EmitWinCFIPushReg(unsigned Register);
677 virtual void EmitWinCFISetFrame(unsigned Register, unsigned Offset);
678 virtual void EmitWinCFIAllocStack(unsigned Size);
679 virtual void EmitWinCFISaveReg(unsigned Register, unsigned Offset);
680 virtual void EmitWinCFISaveXMM(unsigned Register, unsigned Offset);
681 virtual void EmitWinCFIPushFrame(bool Code);
682 virtual void EmitWinCFIEndProlog();
684 virtual void EmitWinEHHandler(const MCSymbol *Sym, bool Unwind, bool Except);
685 virtual void EmitWinEHHandlerData();
687 virtual void EmitSyntaxDirective();
689 /// \brief Emit a .reloc directive.
690 /// Returns true if the relocation could not be emitted because Name is not
692 virtual bool EmitRelocDirective(const MCExpr &Offset, StringRef Name,
693 const MCExpr *Expr, SMLoc Loc) {
697 /// \brief Emit the given \p Instruction into the current section.
698 virtual void EmitInstruction(const MCInst &Inst, const MCSubtargetInfo &STI);
700 /// \brief Set the bundle alignment mode from now on in the section.
701 /// The argument is the power of 2 to which the alignment is set. The
702 /// value 0 means turn the bundle alignment off.
703 virtual void EmitBundleAlignMode(unsigned AlignPow2);
705 /// \brief The following instructions are a bundle-locked group.
707 /// \param AlignToEnd - If true, the bundle-locked group will be aligned to
708 /// the end of a bundle.
709 virtual void EmitBundleLock(bool AlignToEnd);
711 /// \brief Ends a bundle-locked group.
712 virtual void EmitBundleUnlock();
714 /// \brief If this file is backed by a assembly streamer, this dumps the
715 /// specified string in the output .s file. This capability is indicated by
716 /// the hasRawTextSupport() predicate. By default this aborts.
717 void EmitRawText(const Twine &String);
719 /// \brief Streamer specific finalization.
720 virtual void FinishImpl();
721 /// \brief Finish emission of machine code.
724 virtual bool mayHaveInstructions(MCSection &Sec) const { return true; }
727 /// Create a dummy machine code streamer, which does nothing. This is useful for
728 /// timing the assembler front end.
729 MCStreamer *createNullStreamer(MCContext &Ctx);
731 /// Create a machine code streamer which will print out assembly for the native
732 /// target, suitable for compiling with a native assembler.
734 /// \param InstPrint - If given, the instruction printer to use. If not given
735 /// the MCInst representation will be printed. This method takes ownership of
738 /// \param CE - If given, a code emitter to use to show the instruction
739 /// encoding inline with the assembly. This method takes ownership of \p CE.
741 /// \param TAB - If given, a target asm backend to use to show the fixup
742 /// information in conjunction with encoding information. This method takes
743 /// ownership of \p TAB.
745 /// \param ShowInst - Whether to show the MCInst representation inline with
747 MCStreamer *createAsmStreamer(MCContext &Ctx,
748 std::unique_ptr<formatted_raw_ostream> OS,
749 bool isVerboseAsm, bool useDwarfDirectory,
750 MCInstPrinter *InstPrint, MCCodeEmitter *CE,
751 MCAsmBackend *TAB, bool ShowInst);
752 } // end namespace llvm