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/MCLinkerOptimizationHint.h"
23 #include "llvm/MC/MCWinEH.h"
24 #include "llvm/Support/DataTypes.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 /// * FooTargetAsmSreamer : 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 FooTargetAsmSreamer and FooTargetELFStreamer classes implement the
60 /// method. The assembly streamer just prints ".bar symbol_name". The object
61 /// streamer does whatever is needed to implement .bar in the object file.
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 FooTargetAsmSreamer and FooTargetELFStreamer should *never*
70 /// be treated differently. Callers should always talk to a FooTargetStreamer.
71 class MCTargetStreamer {
76 MCTargetStreamer(MCStreamer &S);
77 virtual ~MCTargetStreamer();
79 const MCStreamer &getStreamer() { return Streamer; }
81 // Allow a target to add behavior to the EmitLabel of MCStreamer.
82 virtual void emitLabel(MCSymbol *Symbol);
83 // Allow a target to add behavior to the emitAssignment of MCStreamer.
84 virtual void emitAssignment(MCSymbol *Symbol, const MCExpr *Value);
86 virtual void finish();
89 class AArch64TargetStreamer : public MCTargetStreamer {
91 AArch64TargetStreamer(MCStreamer &S);
92 ~AArch64TargetStreamer();
94 void finish() override;
96 /// Callback used to implement the ldr= pseudo.
97 /// Add a new entry to the constant pool for the current section and return an
98 /// MCExpr that can be used to refer to the constant pool location.
99 const MCExpr *addConstantPoolEntry(const MCExpr *, unsigned Size);
101 /// Callback used to implemnt the .ltorg directive.
102 /// Emit contents of constant pool for the current section.
103 void emitCurrentConstantPool();
105 /// Callback used to implement the .inst directive.
106 virtual void emitInst(uint32_t Inst);
109 std::unique_ptr<AssemblerConstantPools> ConstantPools;
112 // FIXME: declared here because it is used from
113 // lib/CodeGen/AsmPrinter/ARMException.cpp.
114 class ARMTargetStreamer : public MCTargetStreamer {
116 ARMTargetStreamer(MCStreamer &S);
117 ~ARMTargetStreamer();
119 virtual void emitFnStart();
120 virtual void emitFnEnd();
121 virtual void emitCantUnwind();
122 virtual void emitPersonality(const MCSymbol *Personality);
123 virtual void emitPersonalityIndex(unsigned Index);
124 virtual void emitHandlerData();
125 virtual void emitSetFP(unsigned FpReg, unsigned SpReg,
127 virtual void emitMovSP(unsigned Reg, int64_t Offset = 0);
128 virtual void emitPad(int64_t Offset);
129 virtual void emitRegSave(const SmallVectorImpl<unsigned> &RegList,
131 virtual void emitUnwindRaw(int64_t StackOffset,
132 const SmallVectorImpl<uint8_t> &Opcodes);
134 virtual void switchVendor(StringRef Vendor);
135 virtual void emitAttribute(unsigned Attribute, unsigned Value);
136 virtual void emitTextAttribute(unsigned Attribute, StringRef String);
137 virtual void emitIntTextAttribute(unsigned Attribute, unsigned IntValue,
138 StringRef StringValue = "");
139 virtual void emitFPU(unsigned FPU);
140 virtual void emitArch(unsigned Arch);
141 virtual void emitObjectArch(unsigned Arch);
142 virtual void finishAttributeSection();
143 virtual void emitInst(uint32_t Inst, char Suffix = '\0');
145 virtual void AnnotateTLSDescriptorSequence(const MCSymbolRefExpr *SRE);
147 virtual void emitThumbSet(MCSymbol *Symbol, const MCExpr *Value);
149 void finish() override;
151 /// Callback used to implement the ldr= pseudo.
152 /// Add a new entry to the constant pool for the current section and return an
153 /// MCExpr that can be used to refer to the constant pool location.
154 const MCExpr *addConstantPoolEntry(const MCExpr *);
156 /// Callback used to implemnt the .ltorg directive.
157 /// Emit contents of constant pool for the current section.
158 void emitCurrentConstantPool();
161 std::unique_ptr<AssemblerConstantPools> ConstantPools;
164 /// MCStreamer - Streaming machine code generation interface. This interface
165 /// is intended to provide a programatic interface that is very similar to the
166 /// level that an assembler .s file provides. It has callbacks to emit bytes,
167 /// handle directives, etc. The implementation of this interface retains
168 /// state to know what the current section is etc.
170 /// There are multiple implementations of this interface: one for writing out
171 /// a .s file, and implementations that write out .o files of various formats.
175 std::unique_ptr<MCTargetStreamer> TargetStreamer;
177 MCStreamer(const MCStreamer &) LLVM_DELETED_FUNCTION;
178 MCStreamer &operator=(const MCStreamer &) LLVM_DELETED_FUNCTION;
180 std::vector<MCDwarfFrameInfo> DwarfFrameInfos;
181 MCDwarfFrameInfo *getCurrentDwarfFrameInfo();
182 void EnsureValidDwarfFrame();
184 MCSymbol *EmitCFICommon();
186 std::vector<WinEH::FrameInfo *> WinFrameInfos;
187 WinEH::FrameInfo *CurrentWinFrameInfo;
188 void EnsureValidWinFrameInfo();
190 // SymbolOrdering - Tracks an index to represent the order
191 // a symbol was emitted in. Zero means we did not emit that symbol.
192 DenseMap<const MCSymbol *, unsigned> SymbolOrdering;
194 /// SectionStack - This is stack of current and previous section
195 /// values saved by PushSection.
196 SmallVector<std::pair<MCSectionSubPair, MCSectionSubPair>, 4> SectionStack;
199 MCStreamer(MCContext &Ctx);
201 virtual void EmitCFIStartProcImpl(MCDwarfFrameInfo &Frame, MCSymbol *FuncSym);
202 virtual void EmitCFIEndProcImpl(MCDwarfFrameInfo &CurFrame);
204 WinEH::FrameInfo *getCurrentWinFrameInfo() {
205 return CurrentWinFrameInfo;
208 virtual void EmitWindowsUnwindTables();
210 virtual void EmitRawTextImpl(StringRef String);
213 virtual ~MCStreamer();
215 void visitUsedExpr(const MCExpr &Expr);
216 virtual void visitUsedSymbol(const MCSymbol &Sym);
218 void setTargetStreamer(MCTargetStreamer *TS) {
219 TargetStreamer.reset(TS);
224 virtual void reset();
226 MCContext &getContext() const { return Context; }
228 MCTargetStreamer *getTargetStreamer() {
229 return TargetStreamer.get();
232 unsigned getNumFrameInfos() { return DwarfFrameInfos.size(); }
233 ArrayRef<MCDwarfFrameInfo> getDwarfFrameInfos() const {
234 return DwarfFrameInfos;
237 unsigned getNumWinFrameInfos() { return WinFrameInfos.size(); }
238 ArrayRef<WinEH::FrameInfo *> getWinFrameInfos() const {
239 return WinFrameInfos;
242 void generateCompactUnwindEncodings(MCAsmBackend *MAB);
244 /// @name Assembly File Formatting.
247 /// isVerboseAsm - Return true if this streamer supports verbose assembly
248 /// and if it is enabled.
249 virtual bool isVerboseAsm() const { return false; }
251 /// hasRawTextSupport - Return true if this asm streamer supports emitting
252 /// unformatted text to the .s file with EmitRawText.
253 virtual bool hasRawTextSupport() const { return false; }
255 /// Is the integrated assembler required for this streamer to function
257 virtual bool isIntegratedAssemblerRequired() const { return false; }
259 /// AddComment - Add a comment that can be emitted to the generated .s
260 /// file if applicable as a QoI issue to make the output of the compiler
261 /// more readable. This only affects the MCAsmStreamer, and only when
262 /// verbose assembly output is enabled.
264 /// If the comment includes embedded \n's, they will each get the comment
265 /// prefix as appropriate. The added comment should not end with a \n.
266 virtual void AddComment(const Twine &T) {}
268 /// GetCommentOS - Return a raw_ostream that comments can be written to.
269 /// Unlike AddComment, you are required to terminate comments with \n if you
271 virtual raw_ostream &GetCommentOS();
273 /// Print T and prefix it with the comment string (normally #) and optionally
274 /// a tab. This prints the comment immediately, not at the end of the
275 /// current line. It is basically a safe version of EmitRawText: since it
276 /// only prints comments, the object streamer ignores it instead of asserting.
277 virtual void emitRawComment(const Twine &T, bool TabPrefix = true);
279 /// AddBlankLine - Emit a blank line to a .s file to pretty it up.
280 virtual void AddBlankLine() {}
284 /// @name Symbol & Section Management
287 /// getCurrentSection - Return the current section that the streamer is
288 /// emitting code to.
289 MCSectionSubPair getCurrentSection() const {
290 if (!SectionStack.empty())
291 return SectionStack.back().first;
292 return MCSectionSubPair();
295 /// getPreviousSection - Return the previous section that the streamer is
296 /// emitting code to.
297 MCSectionSubPair getPreviousSection() const {
298 if (!SectionStack.empty())
299 return SectionStack.back().second;
300 return MCSectionSubPair();
303 /// GetSymbolOrder - Returns an index to represent the order
304 /// a symbol was emitted in. (zero if we did not emit that symbol)
305 unsigned GetSymbolOrder(const MCSymbol *Sym) const {
306 return SymbolOrdering.lookup(Sym);
309 /// ChangeSection - Update streamer for a new active section.
311 /// This is called by PopSection and SwitchSection, if the current
313 virtual void ChangeSection(const MCSection *, const MCExpr *);
315 /// pushSection - Save the current and previous section on the
318 SectionStack.push_back(
319 std::make_pair(getCurrentSection(), getPreviousSection()));
322 /// popSection - Restore the current and previous section from
323 /// the section stack. Calls ChangeSection as needed.
325 /// Returns false if the stack was empty.
327 if (SectionStack.size() <= 1)
329 MCSectionSubPair oldSection = SectionStack.pop_back_val().first;
330 MCSectionSubPair curSection = SectionStack.back().first;
332 if (oldSection != curSection)
333 ChangeSection(curSection.first, curSection.second);
337 bool SubSection(const MCExpr *Subsection) {
338 if (SectionStack.empty())
341 SwitchSection(SectionStack.back().first.first, Subsection);
345 /// SwitchSection - Set the current section where code is being emitted to
346 /// @p Section. This is required to update CurSection.
348 /// This corresponds to assembler directives like .section, .text, etc.
349 void SwitchSection(const MCSection *Section,
350 const MCExpr *Subsection = nullptr) {
351 assert(Section && "Cannot switch to a null section!");
352 MCSectionSubPair curSection = SectionStack.back().first;
353 SectionStack.back().second = curSection;
354 if (MCSectionSubPair(Section, Subsection) != curSection) {
355 SectionStack.back().first = MCSectionSubPair(Section, Subsection);
356 ChangeSection(Section, Subsection);
360 /// SwitchSectionNoChange - Set the current section where code is being
361 /// emitted to @p Section. This is required to update CurSection. This
362 /// version does not call ChangeSection.
363 void SwitchSectionNoChange(const MCSection *Section,
364 const MCExpr *Subsection = nullptr) {
365 assert(Section && "Cannot switch to a null section!");
366 MCSectionSubPair curSection = SectionStack.back().first;
367 SectionStack.back().second = curSection;
368 if (MCSectionSubPair(Section, Subsection) != curSection)
369 SectionStack.back().first = MCSectionSubPair(Section, Subsection);
372 /// Create the default sections and set the initial one.
373 virtual void InitSections(bool NoExecStack);
375 /// AssignSection - Sets the symbol's section.
377 /// Each emitted symbol will be tracked in the ordering table,
378 /// so we can sort on them later.
379 void AssignSection(MCSymbol *Symbol, const MCSection *Section);
381 /// EmitLabel - Emit a label for @p Symbol into the current section.
383 /// This corresponds to an assembler statement such as:
386 /// @param Symbol - The symbol to emit. A given symbol should only be
387 /// emitted as a label once, and symbols emitted as a label should never be
388 /// used in an assignment.
389 // FIXME: These emission are non-const because we mutate the symbol to
390 // add the section we're emitting it to later.
391 virtual void EmitLabel(MCSymbol *Symbol);
393 virtual void EmitEHSymAttributes(const MCSymbol *Symbol, MCSymbol *EHSymbol);
395 /// EmitAssemblerFlag - Note in the output the specified @p Flag.
396 virtual void EmitAssemblerFlag(MCAssemblerFlag Flag);
398 /// EmitLinkerOptions - Emit the given list @p Options of strings as linker
399 /// options into the output.
400 virtual void EmitLinkerOptions(ArrayRef<std::string> Kind) {}
402 /// EmitDataRegion - Note in the output the specified region @p Kind.
403 virtual void EmitDataRegion(MCDataRegionType Kind) {}
405 /// EmitVersionMin - Specify the MachO minimum deployment target version.
406 virtual void EmitVersionMin(MCVersionMinType, unsigned Major, unsigned Minor,
409 /// EmitThumbFunc - Note in the output that the specified @p Func is
410 /// a Thumb mode function (ARM target only).
411 virtual void EmitThumbFunc(MCSymbol *Func);
413 /// EmitAssignment - Emit an assignment of @p Value to @p Symbol.
415 /// This corresponds to an assembler statement such as:
418 /// The assignment generates no code, but has the side effect of binding the
419 /// value in the current context. For the assembly streamer, this prints the
420 /// binding into the .s file.
422 /// @param Symbol - The symbol being assigned to.
423 /// @param Value - The value for the symbol.
424 virtual void EmitAssignment(MCSymbol *Symbol, const MCExpr *Value);
426 /// EmitWeakReference - Emit an weak reference from @p Alias to @p Symbol.
428 /// This corresponds to an assembler statement such as:
429 /// .weakref alias, symbol
431 /// @param Alias - The alias that is being created.
432 /// @param Symbol - The symbol being aliased.
433 virtual void EmitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol);
435 /// EmitSymbolAttribute - Add the given @p Attribute to @p Symbol.
436 virtual bool EmitSymbolAttribute(MCSymbol *Symbol,
437 MCSymbolAttr Attribute) = 0;
439 /// EmitSymbolDesc - Set the @p DescValue for the @p Symbol.
441 /// @param Symbol - The symbol to have its n_desc field set.
442 /// @param DescValue - The value to set into the n_desc field.
443 virtual void EmitSymbolDesc(MCSymbol *Symbol, unsigned DescValue);
445 /// BeginCOFFSymbolDef - Start emitting COFF symbol definition
447 /// @param Symbol - The symbol to have its External & Type fields set.
448 virtual void BeginCOFFSymbolDef(const MCSymbol *Symbol);
450 /// EmitCOFFSymbolStorageClass - Emit the storage class of the symbol.
452 /// @param StorageClass - The storage class the symbol should have.
453 virtual void EmitCOFFSymbolStorageClass(int StorageClass);
455 /// EmitCOFFSymbolType - Emit the type of the symbol.
457 /// @param Type - A COFF type identifier (see COFF::SymbolType in X86COFF.h)
458 virtual void EmitCOFFSymbolType(int Type);
460 /// EndCOFFSymbolDef - Marks the end of the symbol definition.
461 virtual void EndCOFFSymbolDef();
463 /// EmitCOFFSectionIndex - Emits a COFF section index.
465 /// @param Symbol - Symbol the section number relocation should point to.
466 virtual void EmitCOFFSectionIndex(MCSymbol const *Symbol);
468 /// EmitCOFFSecRel32 - Emits a COFF section relative relocation.
470 /// @param Symbol - Symbol the section relative relocation should point to.
471 virtual void EmitCOFFSecRel32(MCSymbol const *Symbol);
473 /// EmitELFSize - Emit an ELF .size directive.
475 /// This corresponds to an assembler statement such as:
476 /// .size symbol, expression
478 virtual void EmitELFSize(MCSymbol *Symbol, const MCExpr *Value);
480 /// \brief Emit a Linker Optimization Hint (LOH) directive.
481 /// \param Args - Arguments of the LOH.
482 virtual void EmitLOHDirective(MCLOHType Kind, const MCLOHArgs &Args) {}
484 /// EmitCommonSymbol - Emit a common symbol.
486 /// @param Symbol - The common symbol to emit.
487 /// @param Size - The size of the common symbol.
488 /// @param ByteAlignment - The alignment of the symbol if
489 /// non-zero. This must be a power of 2.
490 virtual void EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
491 unsigned ByteAlignment) = 0;
493 /// EmitLocalCommonSymbol - Emit a local common (.lcomm) symbol.
495 /// @param Symbol - The common symbol to emit.
496 /// @param Size - The size of the common symbol.
497 /// @param ByteAlignment - The alignment of the common symbol in bytes.
498 virtual void EmitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size,
499 unsigned ByteAlignment);
501 /// EmitZerofill - Emit the zerofill section and an optional symbol.
503 /// @param Section - The zerofill section to create and or to put the symbol
504 /// @param Symbol - The zerofill symbol to emit, if non-NULL.
505 /// @param Size - The size of the zerofill symbol.
506 /// @param ByteAlignment - The alignment of the zerofill symbol if
507 /// non-zero. This must be a power of 2 on some targets.
508 virtual void EmitZerofill(const MCSection *Section,
509 MCSymbol *Symbol = nullptr, uint64_t Size = 0,
510 unsigned ByteAlignment = 0) = 0;
512 /// EmitTBSSSymbol - Emit a thread local bss (.tbss) symbol.
514 /// @param Section - The thread local common section.
515 /// @param Symbol - The thread local common symbol to emit.
516 /// @param Size - The size of the symbol.
517 /// @param ByteAlignment - The alignment of the thread local common symbol
518 /// if non-zero. This must be a power of 2 on some targets.
519 virtual void EmitTBSSSymbol(const MCSection *Section, MCSymbol *Symbol,
520 uint64_t Size, unsigned ByteAlignment = 0);
523 /// @name Generating Data
526 /// EmitBytes - Emit the bytes in \p Data into the output.
528 /// This is used to implement assembler directives such as .byte, .ascii,
530 virtual void EmitBytes(StringRef Data);
532 /// EmitValue - Emit the expression @p Value into the output as a native
533 /// integer of the given @p Size bytes.
535 /// This is used to implement assembler directives such as .word, .quad,
538 /// @param Value - The value to emit.
539 /// @param Size - The size of the integer (in bytes) to emit. This must
540 /// match a native machine width.
541 /// @param Loc - The location of the expression for error reporting.
542 virtual void EmitValueImpl(const MCExpr *Value, unsigned Size,
543 const SMLoc &Loc = SMLoc());
545 void EmitValue(const MCExpr *Value, unsigned Size,
546 const SMLoc &Loc = SMLoc());
548 /// EmitIntValue - Special case of EmitValue that avoids the client having
549 /// to pass in a MCExpr for constant integers.
550 virtual void EmitIntValue(uint64_t Value, unsigned Size);
552 virtual void EmitULEB128Value(const MCExpr *Value);
554 virtual void EmitSLEB128Value(const MCExpr *Value);
556 /// EmitULEB128Value - Special case of EmitULEB128Value that avoids the
557 /// client having to pass in a MCExpr for constant integers.
558 void EmitULEB128IntValue(uint64_t Value, unsigned Padding = 0);
560 /// EmitSLEB128Value - Special case of EmitSLEB128Value that avoids the
561 /// client having to pass in a MCExpr for constant integers.
562 void EmitSLEB128IntValue(int64_t Value);
564 /// EmitSymbolValue - Special case of EmitValue that avoids the client
565 /// having to pass in a MCExpr for MCSymbols.
566 void EmitSymbolValue(const MCSymbol *Sym, unsigned Size,
567 bool IsSectionRelative = false);
569 /// EmitGPRel64Value - Emit the expression @p Value into the output as a
570 /// gprel64 (64-bit GP relative) value.
572 /// This is used to implement assembler directives such as .gpdword on
573 /// targets that support them.
574 virtual void EmitGPRel64Value(const MCExpr *Value);
576 /// EmitGPRel32Value - Emit the expression @p Value into the output as a
577 /// gprel32 (32-bit GP relative) value.
579 /// This is used to implement assembler directives such as .gprel32 on
580 /// targets that support them.
581 virtual void EmitGPRel32Value(const MCExpr *Value);
583 /// EmitFill - Emit NumBytes bytes worth of the value specified by
584 /// FillValue. This implements directives such as '.space'.
585 virtual void EmitFill(uint64_t NumBytes, uint8_t FillValue);
587 /// \brief Emit NumBytes worth of zeros.
588 /// This function properly handles data in virtual sections.
589 virtual void EmitZeros(uint64_t NumBytes);
591 /// EmitValueToAlignment - Emit some number of copies of @p Value until
592 /// the byte alignment @p ByteAlignment is reached.
594 /// If the number of bytes need to emit for the alignment is not a multiple
595 /// of @p ValueSize, then the contents of the emitted fill bytes is
598 /// This used to implement the .align assembler directive.
600 /// @param ByteAlignment - The alignment to reach. This must be a power of
601 /// two on some targets.
602 /// @param Value - The value to use when filling bytes.
603 /// @param ValueSize - The size of the integer (in bytes) to emit for
604 /// @p Value. This must match a native machine width.
605 /// @param MaxBytesToEmit - The maximum numbers of bytes to emit, or 0. If
606 /// the alignment cannot be reached in this many bytes, no bytes are
608 virtual void EmitValueToAlignment(unsigned ByteAlignment, int64_t Value = 0,
609 unsigned ValueSize = 1,
610 unsigned MaxBytesToEmit = 0);
612 /// EmitCodeAlignment - Emit nops until the byte alignment @p ByteAlignment
615 /// This used to align code where the alignment bytes may be executed. This
616 /// can emit different bytes for different sizes to optimize execution.
618 /// @param ByteAlignment - The alignment to reach. This must be a power of
619 /// two on some targets.
620 /// @param MaxBytesToEmit - The maximum numbers of bytes to emit, or 0. If
621 /// the alignment cannot be reached in this many bytes, no bytes are
623 virtual void EmitCodeAlignment(unsigned ByteAlignment,
624 unsigned MaxBytesToEmit = 0);
626 /// EmitValueToOffset - Emit some number of copies of @p Value until the
627 /// byte offset @p Offset is reached.
629 /// This is used to implement assembler directives such as .org.
631 /// @param Offset - The offset to reach. This may be an expression, but the
632 /// expression must be associated with the current section.
633 /// @param Value - The value to use when filling bytes.
634 /// @return false on success, true if the offset was invalid.
635 virtual bool EmitValueToOffset(const MCExpr *Offset,
636 unsigned char Value = 0);
640 /// EmitFileDirective - Switch to a new logical file. This is used to
641 /// implement the '.file "foo.c"' assembler directive.
642 virtual void EmitFileDirective(StringRef Filename);
644 /// Emit the "identifiers" directive. This implements the
645 /// '.ident "version foo"' assembler directive.
646 virtual void EmitIdent(StringRef IdentString) {}
648 /// EmitDwarfFileDirective - Associate a filename with a specified logical
649 /// file number. This implements the DWARF2 '.file 4 "foo.c"' assembler
651 virtual unsigned EmitDwarfFileDirective(unsigned FileNo, StringRef Directory,
655 /// EmitDwarfLocDirective - This implements the DWARF2
656 // '.loc fileno lineno ...' assembler directive.
657 virtual void EmitDwarfLocDirective(unsigned FileNo, unsigned Line,
658 unsigned Column, unsigned Flags,
659 unsigned Isa, unsigned Discriminator,
662 virtual MCSymbol *getDwarfLineTableSymbol(unsigned CUID);
663 virtual void EmitCFISections(bool EH, bool Debug);
664 void EmitCFIStartProc(bool IsSimple, MCSymbol *FuncSym);
665 void EmitCFIEndProc();
666 virtual void EmitCFIDefCfa(int64_t Register, int64_t Offset);
667 virtual void EmitCFIDefCfaOffset(int64_t Offset);
668 virtual void EmitCFIDefCfaRegister(int64_t Register);
669 virtual void EmitCFIOffset(int64_t Register, int64_t Offset);
670 virtual void EmitCFIPersonality(const MCSymbol *Sym, unsigned Encoding);
671 virtual void EmitCFILsda(const MCSymbol *Sym, unsigned Encoding);
672 virtual void EmitCFIRememberState();
673 virtual void EmitCFIRestoreState();
674 virtual void EmitCFISameValue(int64_t Register);
675 virtual void EmitCFIRestore(int64_t Register);
676 virtual void EmitCFIRelOffset(int64_t Register, int64_t Offset);
677 virtual void EmitCFIAdjustCfaOffset(int64_t Adjustment);
678 virtual void EmitCFIEscape(StringRef Values);
679 virtual void EmitCFISignalFrame();
680 virtual void EmitCFIUndefined(int64_t Register);
681 virtual void EmitCFIRegister(int64_t Register1, int64_t Register2);
682 virtual void EmitCFIWindowSave();
684 virtual void EmitWinCFIStartProc(const MCSymbol *Symbol);
685 virtual void EmitWinCFIEndProc();
686 virtual void EmitWinCFIStartChained();
687 virtual void EmitWinCFIEndChained();
688 virtual void EmitWinCFIPushReg(unsigned Register);
689 virtual void EmitWinCFISetFrame(unsigned Register, unsigned Offset);
690 virtual void EmitWinCFIAllocStack(unsigned Size);
691 virtual void EmitWinCFISaveReg(unsigned Register, unsigned Offset);
692 virtual void EmitWinCFISaveXMM(unsigned Register, unsigned Offset);
693 virtual void EmitWinCFIPushFrame(bool Code);
694 virtual void EmitWinCFIEndProlog();
696 virtual void EmitWinEHHandler(const MCSymbol *Sym, bool Unwind, bool Except);
697 virtual void EmitWinEHHandlerData();
699 /// EmitInstruction - Emit the given @p Instruction into the current
701 virtual void EmitInstruction(const MCInst &Inst, const MCSubtargetInfo &STI);
703 /// \brief Set the bundle alignment mode from now on in the section.
704 /// The argument is the power of 2 to which the alignment is set. The
705 /// value 0 means turn the bundle alignment off.
706 virtual void EmitBundleAlignMode(unsigned AlignPow2);
708 /// \brief The following instructions are a bundle-locked group.
710 /// \param AlignToEnd - If true, the bundle-locked group will be aligned to
711 /// the end of a bundle.
712 virtual void EmitBundleLock(bool AlignToEnd);
714 /// \brief Ends a bundle-locked group.
715 virtual void EmitBundleUnlock();
717 /// EmitRawText - If this file is backed by a assembly streamer, this dumps
718 /// the specified string in the output .s file. This capability is
719 /// indicated by the hasRawTextSupport() predicate. By default this aborts.
720 void EmitRawText(const Twine &String);
722 /// Flush - Causes any cached state to be written out.
723 virtual void Flush() {}
725 /// FinishImpl - Streamer specific finalization.
726 virtual void FinishImpl();
727 /// Finish - Finish emission of machine code.
730 virtual bool mayHaveInstructions() const { return true; }
733 /// createNullStreamer - Create a dummy machine code streamer, which does
734 /// nothing. This is useful for timing the assembler front end.
735 MCStreamer *createNullStreamer(MCContext &Ctx);
737 /// createAsmStreamer - Create a machine code streamer which will print out
738 /// assembly for the native target, suitable for compiling with a native
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, formatted_raw_ostream &OS,
755 bool isVerboseAsm, bool useDwarfDirectory,
756 MCInstPrinter *InstPrint, MCCodeEmitter *CE,
757 MCAsmBackend *TAB, bool ShowInst);
759 /// createMachOStreamer - Create a machine code streamer which will generate
760 /// Mach-O format object files.
762 /// Takes ownership of \p TAB and \p CE.
763 MCStreamer *createMachOStreamer(MCContext &Ctx, MCAsmBackend &TAB,
764 raw_ostream &OS, MCCodeEmitter *CE,
765 bool RelaxAll = false,
766 bool LabelSections = false);
768 /// createELFStreamer - Create a machine code streamer which will generate
769 /// ELF format object files.
770 MCStreamer *createELFStreamer(MCContext &Ctx, MCAsmBackend &TAB,
771 raw_ostream &OS, MCCodeEmitter *CE,
774 } // end namespace llvm