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();
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();
107 std::unique_ptr<AssemblerConstantPools> ConstantPools;
110 // FIXME: declared here because it is used from
111 // lib/CodeGen/AsmPrinter/ARMException.cpp.
112 class ARMTargetStreamer : public MCTargetStreamer {
114 ARMTargetStreamer(MCStreamer &S);
115 ~ARMTargetStreamer();
117 virtual void emitFnStart();
118 virtual void emitFnEnd();
119 virtual void emitCantUnwind();
120 virtual void emitPersonality(const MCSymbol *Personality);
121 virtual void emitPersonalityIndex(unsigned Index);
122 virtual void emitHandlerData();
123 virtual void emitSetFP(unsigned FpReg, unsigned SpReg,
125 virtual void emitMovSP(unsigned Reg, int64_t Offset = 0);
126 virtual void emitPad(int64_t Offset);
127 virtual void emitRegSave(const SmallVectorImpl<unsigned> &RegList,
129 virtual void emitUnwindRaw(int64_t StackOffset,
130 const SmallVectorImpl<uint8_t> &Opcodes);
132 virtual void switchVendor(StringRef Vendor);
133 virtual void emitAttribute(unsigned Attribute, unsigned Value);
134 virtual void emitTextAttribute(unsigned Attribute, StringRef String);
135 virtual void emitIntTextAttribute(unsigned Attribute, unsigned IntValue,
136 StringRef StringValue = "");
137 virtual void emitFPU(unsigned FPU);
138 virtual void emitArch(unsigned Arch);
139 virtual void emitObjectArch(unsigned Arch);
140 virtual void finishAttributeSection();
141 virtual void emitInst(uint32_t Inst, char Suffix = '\0');
143 virtual void AnnotateTLSDescriptorSequence(const MCSymbolRefExpr *SRE);
145 virtual void emitThumbSet(MCSymbol *Symbol, const MCExpr *Value);
147 void finish() override;
149 /// Callback used to implement the ldr= pseudo.
150 /// Add a new entry to the constant pool for the current section and return an
151 /// MCExpr that can be used to refer to the constant pool location.
152 const MCExpr *addConstantPoolEntry(const MCExpr *);
154 /// Callback used to implemnt the .ltorg directive.
155 /// Emit contents of constant pool for the current section.
156 void emitCurrentConstantPool();
159 std::unique_ptr<AssemblerConstantPools> ConstantPools;
162 /// MCStreamer - Streaming machine code generation interface. This interface
163 /// is intended to provide a programatic interface that is very similar to the
164 /// level that an assembler .s file provides. It has callbacks to emit bytes,
165 /// handle directives, etc. The implementation of this interface retains
166 /// state to know what the current section is etc.
168 /// There are multiple implementations of this interface: one for writing out
169 /// a .s file, and implementations that write out .o files of various formats.
173 std::unique_ptr<MCTargetStreamer> TargetStreamer;
175 MCStreamer(const MCStreamer &) LLVM_DELETED_FUNCTION;
176 MCStreamer &operator=(const MCStreamer &) LLVM_DELETED_FUNCTION;
178 std::vector<MCDwarfFrameInfo> DwarfFrameInfos;
179 MCDwarfFrameInfo *getCurrentDwarfFrameInfo();
180 void EnsureValidDwarfFrame();
182 MCSymbol *EmitCFICommon();
184 std::vector<WinEH::FrameInfo *> WinFrameInfos;
185 WinEH::FrameInfo *CurrentWinFrameInfo;
186 void EnsureValidWinFrameInfo();
188 // SymbolOrdering - Tracks an index to represent the order
189 // a symbol was emitted in. Zero means we did not emit that symbol.
190 DenseMap<const MCSymbol *, unsigned> SymbolOrdering;
192 /// SectionStack - This is stack of current and previous section
193 /// values saved by PushSection.
194 SmallVector<std::pair<MCSectionSubPair, MCSectionSubPair>, 4> SectionStack;
197 MCStreamer(MCContext &Ctx);
199 virtual void EmitCFIStartProcImpl(MCDwarfFrameInfo &Frame);
200 virtual void EmitCFIEndProcImpl(MCDwarfFrameInfo &CurFrame);
202 WinEH::FrameInfo *getCurrentWinFrameInfo() {
203 return CurrentWinFrameInfo;
206 virtual void EmitWindowsUnwindTables();
208 virtual void EmitRawTextImpl(StringRef String);
211 virtual ~MCStreamer();
213 void visitUsedExpr(const MCExpr &Expr);
214 virtual void visitUsedSymbol(const MCSymbol &Sym);
216 void setTargetStreamer(MCTargetStreamer *TS) {
217 TargetStreamer.reset(TS);
222 virtual void reset();
224 MCContext &getContext() const { return Context; }
226 MCTargetStreamer *getTargetStreamer() {
227 return TargetStreamer.get();
230 unsigned getNumFrameInfos() { return DwarfFrameInfos.size(); }
231 ArrayRef<MCDwarfFrameInfo> getDwarfFrameInfos() const {
232 return DwarfFrameInfos;
235 unsigned getNumWinFrameInfos() { return WinFrameInfos.size(); }
236 ArrayRef<WinEH::FrameInfo *> getWinFrameInfos() const {
237 return WinFrameInfos;
240 void generateCompactUnwindEncodings(MCAsmBackend *MAB);
242 /// @name Assembly File Formatting.
245 /// isVerboseAsm - Return true if this streamer supports verbose assembly
246 /// and if it is enabled.
247 virtual bool isVerboseAsm() const { return false; }
249 /// hasRawTextSupport - Return true if this asm streamer supports emitting
250 /// unformatted text to the .s file with EmitRawText.
251 virtual bool hasRawTextSupport() const { return false; }
253 /// Is the integrated assembler required for this streamer to function
255 virtual bool isIntegratedAssemblerRequired() const { return false; }
257 /// AddComment - Add a comment that can be emitted to the generated .s
258 /// file if applicable as a QoI issue to make the output of the compiler
259 /// more readable. This only affects the MCAsmStreamer, and only when
260 /// verbose assembly output is enabled.
262 /// If the comment includes embedded \n's, they will each get the comment
263 /// prefix as appropriate. The added comment should not end with a \n.
264 virtual void AddComment(const Twine &T) {}
266 /// GetCommentOS - Return a raw_ostream that comments can be written to.
267 /// Unlike AddComment, you are required to terminate comments with \n if you
269 virtual raw_ostream &GetCommentOS();
271 /// Print T and prefix it with the comment string (normally #) and optionally
272 /// a tab. This prints the comment immediately, not at the end of the
273 /// current line. It is basically a safe version of EmitRawText: since it
274 /// only prints comments, the object streamer ignores it instead of asserting.
275 virtual void emitRawComment(const Twine &T, bool TabPrefix = true);
277 /// AddBlankLine - Emit a blank line to a .s file to pretty it up.
278 virtual void AddBlankLine() {}
282 /// @name Symbol & Section Management
285 /// getCurrentSection - Return the current section that the streamer is
286 /// emitting code to.
287 MCSectionSubPair getCurrentSection() const {
288 if (!SectionStack.empty())
289 return SectionStack.back().first;
290 return MCSectionSubPair();
293 /// getPreviousSection - Return the previous section that the streamer is
294 /// emitting code to.
295 MCSectionSubPair getPreviousSection() const {
296 if (!SectionStack.empty())
297 return SectionStack.back().second;
298 return MCSectionSubPair();
301 /// GetSymbolOrder - Returns an index to represent the order
302 /// a symbol was emitted in. (zero if we did not emit that symbol)
303 unsigned GetSymbolOrder(const MCSymbol *Sym) const {
304 return SymbolOrdering.lookup(Sym);
307 /// ChangeSection - Update streamer for a new active section.
309 /// This is called by PopSection and SwitchSection, if the current
311 virtual void ChangeSection(const MCSection *, const MCExpr *);
313 /// pushSection - Save the current and previous section on the
316 SectionStack.push_back(
317 std::make_pair(getCurrentSection(), getPreviousSection()));
320 /// popSection - Restore the current and previous section from
321 /// the section stack. Calls ChangeSection as needed.
323 /// Returns false if the stack was empty.
325 if (SectionStack.size() <= 1)
327 MCSectionSubPair oldSection = SectionStack.pop_back_val().first;
328 MCSectionSubPair curSection = SectionStack.back().first;
330 if (oldSection != curSection)
331 ChangeSection(curSection.first, curSection.second);
335 bool SubSection(const MCExpr *Subsection) {
336 if (SectionStack.empty())
339 SwitchSection(SectionStack.back().first.first, Subsection);
343 /// SwitchSection - Set the current section where code is being emitted to
344 /// @p Section. This is required to update CurSection.
346 /// This corresponds to assembler directives like .section, .text, etc.
347 void SwitchSection(const 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);
354 ChangeSection(Section, Subsection);
358 /// SwitchSectionNoChange - Set the current section where code is being
359 /// emitted to @p Section. This is required to update CurSection. This
360 /// version does not call ChangeSection.
361 void SwitchSectionNoChange(const MCSection *Section,
362 const MCExpr *Subsection = nullptr) {
363 assert(Section && "Cannot switch to a null section!");
364 MCSectionSubPair curSection = SectionStack.back().first;
365 SectionStack.back().second = curSection;
366 if (MCSectionSubPair(Section, Subsection) != curSection)
367 SectionStack.back().first = MCSectionSubPair(Section, Subsection);
370 /// Create the default sections and set the initial one.
371 virtual void InitSections();
373 /// AssignSection - Sets the symbol's section.
375 /// Each emitted symbol will be tracked in the ordering table,
376 /// so we can sort on them later.
377 void AssignSection(MCSymbol *Symbol, const MCSection *Section);
379 /// EmitLabel - Emit a label for @p Symbol into the current section.
381 /// This corresponds to an assembler statement such as:
384 /// @param Symbol - The symbol to emit. A given symbol should only be
385 /// emitted as a label once, and symbols emitted as a label should never be
386 /// used in an assignment.
387 // FIXME: These emission are non-const because we mutate the symbol to
388 // add the section we're emitting it to later.
389 virtual void EmitLabel(MCSymbol *Symbol);
391 virtual void EmitEHSymAttributes(const MCSymbol *Symbol, MCSymbol *EHSymbol);
393 /// EmitAssemblerFlag - Note in the output the specified @p Flag.
394 virtual void EmitAssemblerFlag(MCAssemblerFlag Flag);
396 /// EmitLinkerOptions - Emit the given list @p Options of strings as linker
397 /// options into the output.
398 virtual void EmitLinkerOptions(ArrayRef<std::string> Kind) {}
400 /// EmitDataRegion - Note in the output the specified region @p Kind.
401 virtual void EmitDataRegion(MCDataRegionType Kind) {}
403 /// EmitVersionMin - Specify the MachO minimum deployment target version.
404 virtual void EmitVersionMin(MCVersionMinType, unsigned Major, unsigned Minor,
407 /// EmitThumbFunc - Note in the output that the specified @p Func is
408 /// a Thumb mode function (ARM target only).
409 virtual void EmitThumbFunc(MCSymbol *Func);
411 /// EmitAssignment - Emit an assignment of @p Value to @p Symbol.
413 /// This corresponds to an assembler statement such as:
416 /// The assignment generates no code, but has the side effect of binding the
417 /// value in the current context. For the assembly streamer, this prints the
418 /// binding into the .s file.
420 /// @param Symbol - The symbol being assigned to.
421 /// @param Value - The value for the symbol.
422 virtual void EmitAssignment(MCSymbol *Symbol, const MCExpr *Value);
424 /// EmitWeakReference - Emit an weak reference from @p Alias to @p Symbol.
426 /// This corresponds to an assembler statement such as:
427 /// .weakref alias, symbol
429 /// @param Alias - The alias that is being created.
430 /// @param Symbol - The symbol being aliased.
431 virtual void EmitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol);
433 /// EmitSymbolAttribute - Add the given @p Attribute to @p Symbol.
434 virtual bool EmitSymbolAttribute(MCSymbol *Symbol,
435 MCSymbolAttr Attribute) = 0;
437 /// EmitSymbolDesc - Set the @p DescValue for the @p Symbol.
439 /// @param Symbol - The symbol to have its n_desc field set.
440 /// @param DescValue - The value to set into the n_desc field.
441 virtual void EmitSymbolDesc(MCSymbol *Symbol, unsigned DescValue);
443 /// BeginCOFFSymbolDef - Start emitting COFF symbol definition
445 /// @param Symbol - The symbol to have its External & Type fields set.
446 virtual void BeginCOFFSymbolDef(const MCSymbol *Symbol);
448 /// EmitCOFFSymbolStorageClass - Emit the storage class of the symbol.
450 /// @param StorageClass - The storage class the symbol should have.
451 virtual void EmitCOFFSymbolStorageClass(int StorageClass);
453 /// EmitCOFFSymbolType - Emit the type of the symbol.
455 /// @param Type - A COFF type identifier (see COFF::SymbolType in X86COFF.h)
456 virtual void EmitCOFFSymbolType(int Type);
458 /// EndCOFFSymbolDef - Marks the end of the symbol definition.
459 virtual void EndCOFFSymbolDef();
461 /// EmitCOFFSectionIndex - Emits a COFF section index.
463 /// @param Symbol - Symbol the section number relocation should point to.
464 virtual void EmitCOFFSectionIndex(MCSymbol const *Symbol);
466 /// EmitCOFFSecRel32 - Emits a COFF section relative relocation.
468 /// @param Symbol - Symbol the section relative relocation should point to.
469 virtual void EmitCOFFSecRel32(MCSymbol const *Symbol);
471 /// EmitELFSize - Emit an ELF .size directive.
473 /// This corresponds to an assembler statement such as:
474 /// .size symbol, expression
476 virtual void EmitELFSize(MCSymbol *Symbol, const MCExpr *Value);
478 /// \brief Emit a Linker Optimization Hint (LOH) directive.
479 /// \param Args - Arguments of the LOH.
480 virtual void EmitLOHDirective(MCLOHType Kind, const MCLOHArgs &Args) {}
482 /// EmitCommonSymbol - Emit a common symbol.
484 /// @param Symbol - The common symbol to emit.
485 /// @param Size - The size of the common symbol.
486 /// @param ByteAlignment - The alignment of the symbol if
487 /// non-zero. This must be a power of 2.
488 virtual void EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
489 unsigned ByteAlignment) = 0;
491 /// EmitLocalCommonSymbol - Emit a local common (.lcomm) symbol.
493 /// @param Symbol - The common symbol to emit.
494 /// @param Size - The size of the common symbol.
495 /// @param ByteAlignment - The alignment of the common symbol in bytes.
496 virtual void EmitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size,
497 unsigned ByteAlignment);
499 /// EmitZerofill - Emit the zerofill section and an optional symbol.
501 /// @param Section - The zerofill section to create and or to put the symbol
502 /// @param Symbol - The zerofill symbol to emit, if non-NULL.
503 /// @param Size - The size of the zerofill symbol.
504 /// @param ByteAlignment - The alignment of the zerofill symbol if
505 /// non-zero. This must be a power of 2 on some targets.
506 virtual void EmitZerofill(const MCSection *Section,
507 MCSymbol *Symbol = nullptr, uint64_t Size = 0,
508 unsigned ByteAlignment = 0) = 0;
510 /// EmitTBSSSymbol - Emit a thread local bss (.tbss) symbol.
512 /// @param Section - The thread local common section.
513 /// @param Symbol - The thread local common symbol to emit.
514 /// @param Size - The size of the symbol.
515 /// @param ByteAlignment - The alignment of the thread local common symbol
516 /// if non-zero. This must be a power of 2 on some targets.
517 virtual void EmitTBSSSymbol(const MCSection *Section, MCSymbol *Symbol,
518 uint64_t Size, unsigned ByteAlignment = 0);
521 /// @name Generating Data
524 /// EmitBytes - Emit the bytes in \p Data into the output.
526 /// This is used to implement assembler directives such as .byte, .ascii,
528 virtual void EmitBytes(StringRef Data);
530 /// EmitValue - Emit the expression @p Value into the output as a native
531 /// integer of the given @p Size bytes.
533 /// This is used to implement assembler directives such as .word, .quad,
536 /// @param Value - The value to emit.
537 /// @param Size - The size of the integer (in bytes) to emit. This must
538 /// match a native machine width.
539 /// @param Loc - The location of the expression for error reporting.
540 virtual void EmitValueImpl(const MCExpr *Value, unsigned Size,
541 const SMLoc &Loc = SMLoc());
543 void EmitValue(const MCExpr *Value, unsigned Size,
544 const SMLoc &Loc = SMLoc());
546 /// EmitIntValue - Special case of EmitValue that avoids the client having
547 /// to pass in a MCExpr for constant integers.
548 virtual void EmitIntValue(uint64_t Value, unsigned Size);
550 /// EmitAbsValue - Emit the Value, but try to avoid relocations. On MachO
551 /// this is done by producing
554 void EmitAbsValue(const MCExpr *Value, unsigned Size);
556 virtual void EmitULEB128Value(const MCExpr *Value);
558 virtual void EmitSLEB128Value(const MCExpr *Value);
560 /// EmitULEB128Value - Special case of EmitULEB128Value that avoids the
561 /// client having to pass in a MCExpr for constant integers.
562 void EmitULEB128IntValue(uint64_t Value, unsigned Padding = 0);
564 /// EmitSLEB128Value - Special case of EmitSLEB128Value that avoids the
565 /// client having to pass in a MCExpr for constant integers.
566 void EmitSLEB128IntValue(int64_t Value);
568 /// EmitSymbolValue - Special case of EmitValue that avoids the client
569 /// having to pass in a MCExpr for MCSymbols.
570 void EmitSymbolValue(const MCSymbol *Sym, unsigned Size,
571 bool IsSectionRelative = false);
573 /// EmitGPRel64Value - Emit the expression @p Value into the output as a
574 /// gprel64 (64-bit GP relative) value.
576 /// This is used to implement assembler directives such as .gpdword on
577 /// targets that support them.
578 virtual void EmitGPRel64Value(const MCExpr *Value);
580 /// EmitGPRel32Value - Emit the expression @p Value into the output as a
581 /// gprel32 (32-bit GP relative) value.
583 /// This is used to implement assembler directives such as .gprel32 on
584 /// targets that support them.
585 virtual void EmitGPRel32Value(const MCExpr *Value);
587 /// EmitFill - Emit NumBytes bytes worth of the value specified by
588 /// FillValue. This implements directives such as '.space'.
589 virtual void EmitFill(uint64_t NumBytes, uint8_t FillValue);
591 /// \brief Emit NumBytes worth of zeros.
592 /// This function properly handles data in virtual sections.
593 virtual void EmitZeros(uint64_t NumBytes);
595 /// EmitValueToAlignment - Emit some number of copies of @p Value until
596 /// the byte alignment @p ByteAlignment is reached.
598 /// If the number of bytes need to emit for the alignment is not a multiple
599 /// of @p ValueSize, then the contents of the emitted fill bytes is
602 /// This used to implement the .align assembler directive.
604 /// @param ByteAlignment - The alignment to reach. This must be a power of
605 /// two on some targets.
606 /// @param Value - The value to use when filling bytes.
607 /// @param ValueSize - The size of the integer (in bytes) to emit for
608 /// @p Value. This must match a native machine width.
609 /// @param MaxBytesToEmit - The maximum numbers of bytes to emit, or 0. If
610 /// the alignment cannot be reached in this many bytes, no bytes are
612 virtual void EmitValueToAlignment(unsigned ByteAlignment, int64_t Value = 0,
613 unsigned ValueSize = 1,
614 unsigned MaxBytesToEmit = 0);
616 /// EmitCodeAlignment - Emit nops until the byte alignment @p ByteAlignment
619 /// This used to align code where the alignment bytes may be executed. This
620 /// can emit different bytes for different sizes to optimize execution.
622 /// @param ByteAlignment - The alignment to reach. This must be a power of
623 /// two on some targets.
624 /// @param MaxBytesToEmit - The maximum numbers of bytes to emit, or 0. If
625 /// the alignment cannot be reached in this many bytes, no bytes are
627 virtual void EmitCodeAlignment(unsigned ByteAlignment,
628 unsigned MaxBytesToEmit = 0);
630 /// EmitValueToOffset - Emit some number of copies of @p Value until the
631 /// byte offset @p Offset is reached.
633 /// This is used to implement assembler directives such as .org.
635 /// @param Offset - The offset to reach. This may be an expression, but the
636 /// expression must be associated with the current section.
637 /// @param Value - The value to use when filling bytes.
638 /// @return false on success, true if the offset was invalid.
639 virtual bool EmitValueToOffset(const MCExpr *Offset,
640 unsigned char Value = 0);
644 /// EmitFileDirective - Switch to a new logical file. This is used to
645 /// implement the '.file "foo.c"' assembler directive.
646 virtual void EmitFileDirective(StringRef Filename);
648 /// Emit the "identifiers" directive. This implements the
649 /// '.ident "version foo"' assembler directive.
650 virtual void EmitIdent(StringRef IdentString) {}
652 /// EmitDwarfFileDirective - Associate a filename with a specified logical
653 /// file number. This implements the DWARF2 '.file 4 "foo.c"' assembler
655 virtual unsigned EmitDwarfFileDirective(unsigned FileNo, StringRef Directory,
659 /// EmitDwarfLocDirective - This implements the DWARF2
660 // '.loc fileno lineno ...' assembler directive.
661 virtual void EmitDwarfLocDirective(unsigned FileNo, unsigned Line,
662 unsigned Column, unsigned Flags,
663 unsigned Isa, unsigned Discriminator,
666 virtual MCSymbol *getDwarfLineTableSymbol(unsigned CUID);
667 virtual void EmitCompactUnwindEncoding(uint32_t CompactUnwindEncoding);
668 virtual void EmitCFISections(bool EH, bool Debug);
669 void EmitCFIStartProc(bool IsSimple);
670 void EmitCFIEndProc();
671 virtual void EmitCFIDefCfa(int64_t Register, int64_t Offset);
672 virtual void EmitCFIDefCfaOffset(int64_t Offset);
673 virtual void EmitCFIDefCfaRegister(int64_t Register);
674 virtual void EmitCFIOffset(int64_t Register, int64_t Offset);
675 virtual void EmitCFIPersonality(const MCSymbol *Sym, unsigned Encoding);
676 virtual void EmitCFILsda(const MCSymbol *Sym, unsigned Encoding);
677 virtual void EmitCFIRememberState();
678 virtual void EmitCFIRestoreState();
679 virtual void EmitCFISameValue(int64_t Register);
680 virtual void EmitCFIRestore(int64_t Register);
681 virtual void EmitCFIRelOffset(int64_t Register, int64_t Offset);
682 virtual void EmitCFIAdjustCfaOffset(int64_t Adjustment);
683 virtual void EmitCFIEscape(StringRef Values);
684 virtual void EmitCFISignalFrame();
685 virtual void EmitCFIUndefined(int64_t Register);
686 virtual void EmitCFIRegister(int64_t Register1, int64_t Register2);
687 virtual void EmitCFIWindowSave();
689 virtual void EmitWinCFIStartProc(const MCSymbol *Symbol);
690 virtual void EmitWinCFIEndProc();
691 virtual void EmitWinCFIStartChained();
692 virtual void EmitWinCFIEndChained();
693 virtual void EmitWinCFIPushReg(unsigned Register);
694 virtual void EmitWinCFISetFrame(unsigned Register, unsigned Offset);
695 virtual void EmitWinCFIAllocStack(unsigned Size);
696 virtual void EmitWinCFISaveReg(unsigned Register, unsigned Offset);
697 virtual void EmitWinCFISaveXMM(unsigned Register, unsigned Offset);
698 virtual void EmitWinCFIPushFrame(bool Code);
699 virtual void EmitWinCFIEndProlog();
701 virtual void EmitWinEHHandler(const MCSymbol *Sym, bool Unwind, bool Except);
702 virtual void EmitWinEHHandlerData();
704 /// EmitInstruction - Emit the given @p Instruction into the current
706 virtual void EmitInstruction(const MCInst &Inst, const MCSubtargetInfo &STI);
708 /// \brief Set the bundle alignment mode from now on in the section.
709 /// The argument is the power of 2 to which the alignment is set. The
710 /// value 0 means turn the bundle alignment off.
711 virtual void EmitBundleAlignMode(unsigned AlignPow2);
713 /// \brief The following instructions are a bundle-locked group.
715 /// \param AlignToEnd - If true, the bundle-locked group will be aligned to
716 /// the end of a bundle.
717 virtual void EmitBundleLock(bool AlignToEnd);
719 /// \brief Ends a bundle-locked group.
720 virtual void EmitBundleUnlock();
722 /// EmitRawText - If this file is backed by a assembly streamer, this dumps
723 /// the specified string in the output .s file. This capability is
724 /// indicated by the hasRawTextSupport() predicate. By default this aborts.
725 void EmitRawText(const Twine &String);
727 /// Flush - Causes any cached state to be written out.
728 virtual void Flush() {}
730 /// FinishImpl - Streamer specific finalization.
731 virtual void FinishImpl();
732 /// Finish - Finish emission of machine code.
735 virtual bool mayHaveInstructions() const { return true; }
738 /// createNullStreamer - Create a dummy machine code streamer, which does
739 /// nothing. This is useful for timing the assembler front end.
740 MCStreamer *createNullStreamer(MCContext &Ctx);
742 /// createAsmStreamer - Create a machine code streamer which will print out
743 /// assembly for the native target, suitable for compiling with a native
746 /// \param InstPrint - If given, the instruction printer to use. If not given
747 /// the MCInst representation will be printed. This method takes ownership of
750 /// \param CE - If given, a code emitter to use to show the instruction
751 /// encoding inline with the assembly. This method takes ownership of \p CE.
753 /// \param TAB - If given, a target asm backend to use to show the fixup
754 /// information in conjunction with encoding information. This method takes
755 /// ownership of \p TAB.
757 /// \param ShowInst - Whether to show the MCInst representation inline with
759 MCStreamer *createAsmStreamer(MCContext &Ctx, formatted_raw_ostream &OS,
760 bool isVerboseAsm, bool useDwarfDirectory,
761 MCInstPrinter *InstPrint, MCCodeEmitter *CE,
762 MCAsmBackend *TAB, bool ShowInst);
764 /// createMachOStreamer - Create a machine code streamer which will generate
765 /// Mach-O format object files.
767 /// Takes ownership of \p TAB and \p CE.
768 MCStreamer *createMachOStreamer(MCContext &Ctx, MCAsmBackend &TAB,
769 raw_ostream &OS, MCCodeEmitter *CE,
770 bool RelaxAll = false,
771 bool LabelSections = false);
773 /// createELFStreamer - Create a machine code streamer which will generate
774 /// ELF format object files.
775 MCStreamer *createELFStreamer(MCContext &Ctx, MCAsmBackend &TAB,
776 raw_ostream &OS, MCCodeEmitter *CE, bool RelaxAll,
779 } // end namespace llvm