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 /// * 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();
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();
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 /// MCStreamer - Streaming machine code generation interface. This interface
167 /// is intended to provide a programatic interface that is very similar to the
168 /// level that an assembler .s file provides. It has callbacks to emit bytes,
169 /// handle directives, etc. The implementation of this interface retains
170 /// state to know what the current section is etc.
172 /// There are multiple implementations of this interface: one for writing out
173 /// a .s file, and implementations that write out .o files of various formats.
177 std::unique_ptr<MCTargetStreamer> TargetStreamer;
179 MCStreamer(const MCStreamer &) = delete;
180 MCStreamer &operator=(const MCStreamer &) = delete;
182 std::vector<MCDwarfFrameInfo> DwarfFrameInfos;
183 MCDwarfFrameInfo *getCurrentDwarfFrameInfo();
184 void EnsureValidDwarfFrame();
186 MCSymbol *EmitCFICommon();
188 std::vector<WinEH::FrameInfo *> WinFrameInfos;
189 WinEH::FrameInfo *CurrentWinFrameInfo;
190 void EnsureValidWinFrameInfo();
192 // SymbolOrdering - Tracks an index to represent the order
193 // a symbol was emitted in. Zero means we did not emit that symbol.
194 DenseMap<const MCSymbol *, unsigned> SymbolOrdering;
196 /// SectionStack - This is stack of current and previous section
197 /// values saved by PushSection.
198 SmallVector<std::pair<MCSectionSubPair, MCSectionSubPair>, 4> SectionStack;
201 MCStreamer(MCContext &Ctx);
203 virtual void EmitCFIStartProcImpl(MCDwarfFrameInfo &Frame);
204 virtual void EmitCFIEndProcImpl(MCDwarfFrameInfo &CurFrame);
206 WinEH::FrameInfo *getCurrentWinFrameInfo() {
207 return CurrentWinFrameInfo;
210 virtual void EmitWindowsUnwindTables();
212 virtual void EmitRawTextImpl(StringRef String);
215 virtual ~MCStreamer();
217 void visitUsedExpr(const MCExpr &Expr);
218 virtual void visitUsedSymbol(const MCSymbol &Sym);
220 void setTargetStreamer(MCTargetStreamer *TS) {
221 TargetStreamer.reset(TS);
226 virtual void reset();
228 MCContext &getContext() const { return Context; }
230 MCTargetStreamer *getTargetStreamer() {
231 return TargetStreamer.get();
234 unsigned getNumFrameInfos() { return DwarfFrameInfos.size(); }
235 ArrayRef<MCDwarfFrameInfo> getDwarfFrameInfos() const {
236 return DwarfFrameInfos;
239 unsigned getNumWinFrameInfos() { return WinFrameInfos.size(); }
240 ArrayRef<WinEH::FrameInfo *> getWinFrameInfos() const {
241 return WinFrameInfos;
244 void generateCompactUnwindEncodings(MCAsmBackend *MAB);
246 /// @name Assembly File Formatting.
249 /// isVerboseAsm - Return true if this streamer supports verbose assembly
250 /// and if it is enabled.
251 virtual bool isVerboseAsm() const { return false; }
253 /// hasRawTextSupport - Return true if this asm streamer supports emitting
254 /// unformatted text to the .s file with EmitRawText.
255 virtual bool hasRawTextSupport() const { return false; }
257 /// Is the integrated assembler required for this streamer to function
259 virtual bool isIntegratedAssemblerRequired() const { return false; }
261 /// AddComment - Add a comment that can be emitted to the generated .s
262 /// file if applicable as a QoI issue to make the output of the compiler
263 /// more readable. This only affects the MCAsmStreamer, and only when
264 /// verbose assembly output is enabled.
266 /// If the comment includes embedded \n's, they will each get the comment
267 /// prefix as appropriate. The added comment should not end with a \n.
268 virtual void AddComment(const Twine &T) {}
270 /// GetCommentOS - Return a raw_ostream that comments can be written to.
271 /// Unlike AddComment, you are required to terminate comments with \n if you
273 virtual raw_ostream &GetCommentOS();
275 /// Print T and prefix it with the comment string (normally #) and optionally
276 /// a tab. This prints the comment immediately, not at the end of the
277 /// current line. It is basically a safe version of EmitRawText: since it
278 /// only prints comments, the object streamer ignores it instead of asserting.
279 virtual void emitRawComment(const Twine &T, bool TabPrefix = true);
281 /// AddBlankLine - Emit a blank line to a .s file to pretty it up.
282 virtual void AddBlankLine() {}
286 /// @name Symbol & Section Management
289 /// getCurrentSection - Return the current section that the streamer is
290 /// emitting code to.
291 MCSectionSubPair getCurrentSection() const {
292 if (!SectionStack.empty())
293 return SectionStack.back().first;
294 return MCSectionSubPair();
297 /// getPreviousSection - Return the previous section that the streamer is
298 /// emitting code to.
299 MCSectionSubPair getPreviousSection() const {
300 if (!SectionStack.empty())
301 return SectionStack.back().second;
302 return MCSectionSubPair();
305 /// GetSymbolOrder - Returns an index to represent the order
306 /// a symbol was emitted in. (zero if we did not emit that symbol)
307 unsigned GetSymbolOrder(const MCSymbol *Sym) const {
308 return SymbolOrdering.lookup(Sym);
311 /// ChangeSection - Update streamer for a new active section.
313 /// This is called by PopSection and SwitchSection, if the current
315 virtual void ChangeSection(const MCSection *, const MCExpr *);
317 /// pushSection - Save the current and previous section on the
320 SectionStack.push_back(
321 std::make_pair(getCurrentSection(), getPreviousSection()));
324 /// popSection - Restore the current and previous section from
325 /// the section stack. 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 /// SwitchSection - Set the current section where code is being emitted to
348 /// @p Section. This 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) {
353 assert(Section && "Cannot switch to a null section!");
354 MCSectionSubPair curSection = SectionStack.back().first;
355 SectionStack.back().second = curSection;
356 if (MCSectionSubPair(Section, Subsection) != curSection) {
357 SectionStack.back().first = MCSectionSubPair(Section, Subsection);
358 ChangeSection(Section, Subsection);
362 /// SwitchSectionNoChange - Set the current section where code is being
363 /// emitted to @p Section. This is required to update CurSection. This
364 /// version does not call ChangeSection.
365 void SwitchSectionNoChange(const MCSection *Section,
366 const MCExpr *Subsection = nullptr) {
367 assert(Section && "Cannot switch to a null section!");
368 MCSectionSubPair curSection = SectionStack.back().first;
369 SectionStack.back().second = curSection;
370 if (MCSectionSubPair(Section, Subsection) != curSection)
371 SectionStack.back().first = MCSectionSubPair(Section, Subsection);
374 /// Create the default sections and set the initial one.
375 virtual void InitSections(bool NoExecStack);
377 /// AssignSection - Sets the symbol's section.
379 /// Each emitted symbol will be tracked in the ordering table,
380 /// so we can sort on them later.
381 void AssignSection(MCSymbol *Symbol, const MCSection *Section);
383 /// EmitLabel - Emit a label for @p Symbol into the current section.
385 /// This corresponds to an assembler statement such as:
388 /// @param Symbol - The symbol to emit. A given symbol should only be
389 /// emitted as a label once, and symbols emitted as a label should never be
390 /// used in an assignment.
391 // FIXME: These emission are non-const because we mutate the symbol to
392 // add the section we're emitting it to later.
393 virtual void EmitLabel(MCSymbol *Symbol);
395 virtual void EmitEHSymAttributes(const MCSymbol *Symbol, MCSymbol *EHSymbol);
397 /// EmitAssemblerFlag - Note in the output the specified @p Flag.
398 virtual void EmitAssemblerFlag(MCAssemblerFlag Flag);
400 /// EmitLinkerOptions - Emit the given list @p Options of strings as linker
401 /// options into the output.
402 virtual void EmitLinkerOptions(ArrayRef<std::string> Kind) {}
404 /// EmitDataRegion - Note in the output the specified region @p Kind.
405 virtual void EmitDataRegion(MCDataRegionType Kind) {}
407 /// EmitVersionMin - Specify the MachO minimum deployment target version.
408 virtual void EmitVersionMin(MCVersionMinType, unsigned Major, unsigned Minor,
411 /// EmitThumbFunc - Note in the output that the specified @p Func is
412 /// a Thumb mode function (ARM target only).
413 virtual void EmitThumbFunc(MCSymbol *Func);
415 /// EmitAssignment - Emit an assignment of @p Value to @p Symbol.
417 /// This corresponds to an assembler statement such as:
420 /// The assignment generates no code, but has the side effect of binding the
421 /// value in the current context. For the assembly streamer, this prints the
422 /// binding into the .s file.
424 /// @param Symbol - The symbol being assigned to.
425 /// @param Value - The value for the symbol.
426 virtual void EmitAssignment(MCSymbol *Symbol, const MCExpr *Value);
428 /// EmitWeakReference - Emit an weak reference from @p Alias to @p Symbol.
430 /// This corresponds to an assembler statement such as:
431 /// .weakref alias, symbol
433 /// @param Alias - The alias that is being created.
434 /// @param Symbol - The symbol being aliased.
435 virtual void EmitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol);
437 /// EmitSymbolAttribute - Add the given @p Attribute to @p Symbol.
438 virtual bool EmitSymbolAttribute(MCSymbol *Symbol,
439 MCSymbolAttr Attribute) = 0;
441 /// EmitSymbolDesc - Set the @p DescValue for the @p Symbol.
443 /// @param Symbol - The symbol to have its n_desc field set.
444 /// @param DescValue - The value to set into the n_desc field.
445 virtual void EmitSymbolDesc(MCSymbol *Symbol, unsigned DescValue);
447 /// BeginCOFFSymbolDef - Start emitting COFF symbol definition
449 /// @param Symbol - The symbol to have its External & Type fields set.
450 virtual void BeginCOFFSymbolDef(const MCSymbol *Symbol);
452 /// EmitCOFFSymbolStorageClass - Emit the storage class of the symbol.
454 /// @param StorageClass - The storage class the symbol should have.
455 virtual void EmitCOFFSymbolStorageClass(int StorageClass);
457 /// EmitCOFFSymbolType - Emit the type of the symbol.
459 /// @param Type - A COFF type identifier (see COFF::SymbolType in X86COFF.h)
460 virtual void EmitCOFFSymbolType(int Type);
462 /// EndCOFFSymbolDef - Marks the end of the symbol definition.
463 virtual void EndCOFFSymbolDef();
465 /// EmitCOFFSectionIndex - Emits a COFF section index.
467 /// @param Symbol - Symbol the section number relocation should point to.
468 virtual void EmitCOFFSectionIndex(MCSymbol const *Symbol);
470 /// EmitCOFFSecRel32 - Emits a COFF section relative relocation.
472 /// @param Symbol - Symbol the section relative relocation should point to.
473 virtual void EmitCOFFSecRel32(MCSymbol const *Symbol);
475 /// EmitELFSize - Emit an ELF .size directive.
477 /// This corresponds to an assembler statement such as:
478 /// .size symbol, expression
480 virtual void EmitELFSize(MCSymbol *Symbol, const MCExpr *Value);
482 /// \brief Emit a Linker Optimization Hint (LOH) directive.
483 /// \param Args - Arguments of the LOH.
484 virtual void EmitLOHDirective(MCLOHType Kind, const MCLOHArgs &Args) {}
486 /// EmitCommonSymbol - Emit a common symbol.
488 /// @param Symbol - The common symbol to emit.
489 /// @param Size - The size of the common symbol.
490 /// @param ByteAlignment - The alignment of the symbol if
491 /// non-zero. This must be a power of 2.
492 virtual void EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
493 unsigned ByteAlignment) = 0;
495 /// EmitLocalCommonSymbol - Emit a local common (.lcomm) symbol.
497 /// @param Symbol - The common symbol to emit.
498 /// @param Size - The size of the common symbol.
499 /// @param ByteAlignment - The alignment of the common symbol in bytes.
500 virtual void EmitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size,
501 unsigned ByteAlignment);
503 /// EmitZerofill - Emit the zerofill section and an optional symbol.
505 /// @param Section - The zerofill section to create and or to put the symbol
506 /// @param Symbol - The zerofill symbol to emit, if non-NULL.
507 /// @param Size - The size of the zerofill symbol.
508 /// @param ByteAlignment - The alignment of the zerofill symbol if
509 /// non-zero. This must be a power of 2 on some targets.
510 virtual void EmitZerofill(const MCSection *Section,
511 MCSymbol *Symbol = nullptr, uint64_t Size = 0,
512 unsigned ByteAlignment = 0) = 0;
514 /// EmitTBSSSymbol - Emit a thread local bss (.tbss) symbol.
516 /// @param Section - The thread local common section.
517 /// @param Symbol - The thread local common symbol to emit.
518 /// @param Size - The size of the symbol.
519 /// @param ByteAlignment - The alignment of the thread local common symbol
520 /// if non-zero. This must be a power of 2 on some targets.
521 virtual void EmitTBSSSymbol(const MCSection *Section, MCSymbol *Symbol,
522 uint64_t Size, unsigned ByteAlignment = 0);
525 /// @name Generating Data
528 /// EmitBytes - Emit the bytes in \p Data into the output.
530 /// This is used to implement assembler directives such as .byte, .ascii,
532 virtual void EmitBytes(StringRef Data);
534 /// EmitValue - Emit the expression @p Value into the output as a native
535 /// integer of the given @p Size bytes.
537 /// This is used to implement assembler directives such as .word, .quad,
540 /// @param Value - The value to emit.
541 /// @param Size - The size of the integer (in bytes) to emit. This must
542 /// match a native machine width.
543 /// @param Loc - The location of the expression for error reporting.
544 virtual void EmitValueImpl(const MCExpr *Value, unsigned Size,
545 const SMLoc &Loc = SMLoc());
547 void EmitValue(const MCExpr *Value, unsigned Size,
548 const SMLoc &Loc = SMLoc());
550 /// EmitIntValue - Special case of EmitValue that avoids the client having
551 /// to pass in a MCExpr for constant integers.
552 virtual void EmitIntValue(uint64_t Value, unsigned Size);
554 virtual void EmitULEB128Value(const MCExpr *Value);
556 virtual void EmitSLEB128Value(const MCExpr *Value);
558 /// EmitULEB128Value - Special case of EmitULEB128Value that avoids the
559 /// client having to pass in a MCExpr for constant integers.
560 void EmitULEB128IntValue(uint64_t Value, unsigned Padding = 0);
562 /// EmitSLEB128Value - Special case of EmitSLEB128Value that avoids the
563 /// client having to pass in a MCExpr for constant integers.
564 void EmitSLEB128IntValue(int64_t Value);
566 /// EmitSymbolValue - Special case of EmitValue that avoids the client
567 /// having to pass in a MCExpr for MCSymbols.
568 void EmitSymbolValue(const MCSymbol *Sym, unsigned Size,
569 bool IsSectionRelative = false);
571 /// EmitGPRel64Value - Emit the expression @p Value into the output as a
572 /// gprel64 (64-bit GP relative) value.
574 /// This is used to implement assembler directives such as .gpdword on
575 /// targets that support them.
576 virtual void EmitGPRel64Value(const MCExpr *Value);
578 /// EmitGPRel32Value - Emit the expression @p Value into the output as a
579 /// gprel32 (32-bit GP relative) value.
581 /// This is used to implement assembler directives such as .gprel32 on
582 /// targets that support them.
583 virtual void EmitGPRel32Value(const MCExpr *Value);
585 /// EmitFill - Emit NumBytes bytes worth of the value specified by
586 /// FillValue. This implements directives such as '.space'.
587 virtual void EmitFill(uint64_t NumBytes, uint8_t FillValue);
589 /// \brief Emit NumBytes worth of zeros.
590 /// This function properly handles data in virtual sections.
591 virtual void EmitZeros(uint64_t NumBytes);
593 /// EmitValueToAlignment - Emit some number of copies of @p Value until
594 /// the byte alignment @p ByteAlignment is reached.
596 /// If the number of bytes need to emit for the alignment is not a multiple
597 /// of @p ValueSize, then the contents of the emitted fill bytes is
600 /// This used to implement the .align assembler directive.
602 /// @param ByteAlignment - The alignment to reach. This must be a power of
603 /// two on some targets.
604 /// @param Value - The value to use when filling bytes.
605 /// @param ValueSize - The size of the integer (in bytes) to emit for
606 /// @p Value. This must match a native machine width.
607 /// @param MaxBytesToEmit - The maximum numbers of bytes to emit, or 0. If
608 /// the alignment cannot be reached in this many bytes, no bytes are
610 virtual void EmitValueToAlignment(unsigned ByteAlignment, int64_t Value = 0,
611 unsigned ValueSize = 1,
612 unsigned MaxBytesToEmit = 0);
614 /// EmitCodeAlignment - Emit nops until the byte alignment @p ByteAlignment
617 /// This used to align code where the alignment bytes may be executed. This
618 /// can emit different bytes for different sizes to optimize execution.
620 /// @param ByteAlignment - The alignment to reach. This must be a power of
621 /// two on some targets.
622 /// @param MaxBytesToEmit - The maximum numbers of bytes to emit, or 0. If
623 /// the alignment cannot be reached in this many bytes, no bytes are
625 virtual void EmitCodeAlignment(unsigned ByteAlignment,
626 unsigned MaxBytesToEmit = 0);
628 /// EmitValueToOffset - Emit some number of copies of @p Value until the
629 /// byte offset @p Offset is reached.
631 /// This is used to implement assembler directives such as .org.
633 /// @param Offset - The offset to reach. This may be an expression, but the
634 /// expression must be associated with the current section.
635 /// @param Value - The value to use when filling bytes.
636 /// @return false on success, true if the offset was invalid.
637 virtual bool EmitValueToOffset(const MCExpr *Offset,
638 unsigned char Value = 0);
642 /// EmitFileDirective - Switch to a new logical file. This is used to
643 /// implement the '.file "foo.c"' assembler directive.
644 virtual void EmitFileDirective(StringRef Filename);
646 /// Emit the "identifiers" directive. This implements the
647 /// '.ident "version foo"' assembler directive.
648 virtual void EmitIdent(StringRef IdentString) {}
650 /// EmitDwarfFileDirective - Associate a filename with a specified logical
651 /// file number. This implements the DWARF2 '.file 4 "foo.c"' assembler
653 virtual unsigned EmitDwarfFileDirective(unsigned FileNo, StringRef Directory,
657 /// EmitDwarfLocDirective - This implements the DWARF2
658 // '.loc fileno lineno ...' assembler directive.
659 virtual void EmitDwarfLocDirective(unsigned FileNo, unsigned Line,
660 unsigned Column, unsigned Flags,
661 unsigned Isa, unsigned Discriminator,
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 /// EmitInstruction - Emit the given @p Instruction into the current
703 virtual void EmitInstruction(const MCInst &Inst, const MCSubtargetInfo &STI);
705 /// \brief Set the bundle alignment mode from now on in the section.
706 /// The argument is the power of 2 to which the alignment is set. The
707 /// value 0 means turn the bundle alignment off.
708 virtual void EmitBundleAlignMode(unsigned AlignPow2);
710 /// \brief The following instructions are a bundle-locked group.
712 /// \param AlignToEnd - If true, the bundle-locked group will be aligned to
713 /// the end of a bundle.
714 virtual void EmitBundleLock(bool AlignToEnd);
716 /// \brief Ends a bundle-locked group.
717 virtual void EmitBundleUnlock();
719 /// EmitRawText - If this file is backed by a assembly streamer, this dumps
720 /// the specified string in the output .s file. This capability is
721 /// indicated by the hasRawTextSupport() predicate. By default this aborts.
722 void EmitRawText(const Twine &String);
724 /// Flush - Causes any cached state to be written out.
725 virtual void Flush() {}
727 /// FinishImpl - Streamer specific finalization.
728 virtual void FinishImpl();
729 /// Finish - Finish emission of machine code.
732 virtual bool mayHaveInstructions() const { return true; }
735 /// createNullStreamer - Create a dummy machine code streamer, which does
736 /// nothing. This is useful for timing the assembler front end.
737 MCStreamer *createNullStreamer(MCContext &Ctx);
739 /// createAsmStreamer - Create a machine code streamer which will print out
740 /// assembly for the native target, suitable for compiling with a native
743 /// \param InstPrint - If given, the instruction printer to use. If not given
744 /// the MCInst representation will be printed. This method takes ownership of
747 /// \param CE - If given, a code emitter to use to show the instruction
748 /// encoding inline with the assembly. This method takes ownership of \p CE.
750 /// \param TAB - If given, a target asm backend to use to show the fixup
751 /// information in conjunction with encoding information. This method takes
752 /// ownership of \p TAB.
754 /// \param ShowInst - Whether to show the MCInst representation inline with
756 MCStreamer *createAsmStreamer(MCContext &Ctx, formatted_raw_ostream &OS,
757 bool isVerboseAsm, bool useDwarfDirectory,
758 MCInstPrinter *InstPrint, MCCodeEmitter *CE,
759 MCAsmBackend *TAB, bool ShowInst);
761 /// createMachOStreamer - Create a machine code streamer which will generate
762 /// Mach-O format object files.
764 /// Takes ownership of \p TAB and \p CE.
765 MCStreamer *createMachOStreamer(MCContext &Ctx, MCAsmBackend &TAB,
766 raw_ostream &OS, MCCodeEmitter *CE,
767 bool RelaxAll = false,
768 bool LabelSections = false);
770 /// createELFStreamer - Create a machine code streamer which will generate
771 /// ELF format object files.
772 MCStreamer *createELFStreamer(MCContext &Ctx, MCAsmBackend &TAB,
773 raw_ostream &OS, MCCodeEmitter *CE,
776 } // end namespace llvm