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/MCWin64EH.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 // FIXME: declared here because it is used from
90 // lib/CodeGen/AsmPrinter/ARMException.cpp.
91 class ARMTargetStreamer : public MCTargetStreamer {
93 ARMTargetStreamer(MCStreamer &S);
96 virtual void emitFnStart();
97 virtual void emitFnEnd();
98 virtual void emitCantUnwind();
99 virtual void emitPersonality(const MCSymbol *Personality);
100 virtual void emitPersonalityIndex(unsigned Index);
101 virtual void emitHandlerData();
102 virtual void emitSetFP(unsigned FpReg, unsigned SpReg,
104 virtual void emitMovSP(unsigned Reg, int64_t Offset = 0);
105 virtual void emitPad(int64_t Offset);
106 virtual void emitRegSave(const SmallVectorImpl<unsigned> &RegList,
108 virtual void emitUnwindRaw(int64_t StackOffset,
109 const SmallVectorImpl<uint8_t> &Opcodes);
111 virtual void switchVendor(StringRef Vendor);
112 virtual void emitAttribute(unsigned Attribute, unsigned Value);
113 virtual void emitTextAttribute(unsigned Attribute, StringRef String);
114 virtual void emitIntTextAttribute(unsigned Attribute, unsigned IntValue,
115 StringRef StringValue = "");
116 virtual void emitFPU(unsigned FPU);
117 virtual void emitArch(unsigned Arch);
118 virtual void emitObjectArch(unsigned Arch);
119 virtual void finishAttributeSection();
120 virtual void emitInst(uint32_t Inst, char Suffix = '\0');
122 virtual void AnnotateTLSDescriptorSequence(const MCSymbolRefExpr *SRE);
124 void finish() override;
126 /// Callback used to implement the ldr= pseudo.
127 /// Add a new entry to the constant pool for the current section and return an
128 /// MCExpr that can be used to refer to the constant pool location.
129 const MCExpr *addConstantPoolEntry(const MCExpr *);
131 /// Callback used to implemnt the .ltorg directive.
132 /// Emit contents of constant pool for the current section.
133 void emitCurrentConstantPool();
136 std::unique_ptr<AssemblerConstantPools> ConstantPools;
139 /// MCStreamer - Streaming machine code generation interface. This interface
140 /// is intended to provide a programatic interface that is very similar to the
141 /// level that an assembler .s file provides. It has callbacks to emit bytes,
142 /// handle directives, etc. The implementation of this interface retains
143 /// state to know what the current section is etc.
145 /// There are multiple implementations of this interface: one for writing out
146 /// a .s file, and implementations that write out .o files of various formats.
150 std::unique_ptr<MCTargetStreamer> TargetStreamer;
152 MCStreamer(const MCStreamer &) LLVM_DELETED_FUNCTION;
153 MCStreamer &operator=(const MCStreamer &) LLVM_DELETED_FUNCTION;
158 std::vector<MCDwarfFrameInfo> FrameInfos;
159 MCDwarfFrameInfo *getCurrentFrameInfo();
160 MCSymbol *EmitCFICommon();
161 void EnsureValidFrame();
163 std::vector<MCWin64EHUnwindInfo *> W64UnwindInfos;
164 MCWin64EHUnwindInfo *CurrentW64UnwindInfo;
165 void setCurrentW64UnwindInfo(MCWin64EHUnwindInfo *Frame);
166 void EnsureValidW64UnwindInfo();
168 MCSymbol *LastSymbol;
170 // SymbolOrdering - Tracks an index to represent the order
171 // a symbol was emitted in. Zero means we did not emit that symbol.
172 DenseMap<const MCSymbol *, unsigned> SymbolOrdering;
174 /// SectionStack - This is stack of current and previous section
175 /// values saved by PushSection.
176 SmallVector<std::pair<MCSectionSubPair, MCSectionSubPair>, 4> SectionStack;
179 MCStreamer(MCContext &Ctx);
181 const MCExpr *BuildSymbolDiff(MCContext &Context, const MCSymbol *A,
184 const MCExpr *ForceExpAbs(const MCExpr *Expr);
186 void RecordProcStart(MCDwarfFrameInfo &Frame);
187 virtual void EmitCFIStartProcImpl(MCDwarfFrameInfo &Frame);
188 void RecordProcEnd(MCDwarfFrameInfo &Frame);
189 virtual void EmitCFIEndProcImpl(MCDwarfFrameInfo &CurFrame);
190 void EmitFrames(MCAsmBackend *MAB, bool usingCFI);
192 MCWin64EHUnwindInfo *getCurrentW64UnwindInfo() {
193 return CurrentW64UnwindInfo;
195 void EmitW64Tables();
197 virtual void EmitRawTextImpl(StringRef String);
200 virtual ~MCStreamer();
202 void setTargetStreamer(MCTargetStreamer *TS) {
203 TargetStreamer.reset(TS);
208 virtual void reset();
210 MCContext &getContext() const { return Context; }
212 MCTargetStreamer *getTargetStreamer() {
213 return TargetStreamer.get();
216 unsigned getNumFrameInfos() { return FrameInfos.size(); }
218 const MCDwarfFrameInfo &getFrameInfo(unsigned i) { return FrameInfos[i]; }
220 ArrayRef<MCDwarfFrameInfo> getFrameInfos() const { return FrameInfos; }
222 unsigned getNumW64UnwindInfos() { return W64UnwindInfos.size(); }
224 MCWin64EHUnwindInfo &getW64UnwindInfo(unsigned i) {
225 return *W64UnwindInfos[i];
228 void generateCompactUnwindEncodings(MCAsmBackend *MAB);
230 /// @name Assembly File Formatting.
233 /// isVerboseAsm - Return true if this streamer supports verbose assembly
234 /// and if it is enabled.
235 virtual bool isVerboseAsm() const { return false; }
237 /// hasRawTextSupport - Return true if this asm streamer supports emitting
238 /// unformatted text to the .s file with EmitRawText.
239 virtual bool hasRawTextSupport() const { return false; }
241 /// Is the integrated assembler required for this streamer to function
243 virtual bool isIntegratedAssemblerRequired() const { return false; }
245 /// AddComment - Add a comment that can be emitted to the generated .s
246 /// file if applicable as a QoI issue to make the output of the compiler
247 /// more readable. This only affects the MCAsmStreamer, and only when
248 /// verbose assembly output is enabled.
250 /// If the comment includes embedded \n's, they will each get the comment
251 /// prefix as appropriate. The added comment should not end with a \n.
252 virtual void AddComment(const Twine &T) {}
254 /// GetCommentOS - Return a raw_ostream that comments can be written to.
255 /// Unlike AddComment, you are required to terminate comments with \n if you
257 virtual raw_ostream &GetCommentOS();
259 /// Print T and prefix it with the comment string (normally #) and optionally
260 /// a tab. This prints the comment immediately, not at the end of the
261 /// current line. It is basically a safe version of EmitRawText: since it
262 /// only prints comments, the object streamer ignores it instead of asserting.
263 virtual void emitRawComment(const Twine &T, bool TabPrefix = true);
265 /// AddBlankLine - Emit a blank line to a .s file to pretty it up.
266 virtual void AddBlankLine() {}
270 /// @name Symbol & Section Management
273 /// getCurrentSection - Return the current section that the streamer is
274 /// emitting code to.
275 MCSectionSubPair getCurrentSection() const {
276 if (!SectionStack.empty())
277 return SectionStack.back().first;
278 return MCSectionSubPair();
281 /// getPreviousSection - Return the previous section that the streamer is
282 /// emitting code to.
283 MCSectionSubPair getPreviousSection() const {
284 if (!SectionStack.empty())
285 return SectionStack.back().second;
286 return MCSectionSubPair();
289 /// GetSymbolOrder - Returns an index to represent the order
290 /// a symbol was emitted in. (zero if we did not emit that symbol)
291 unsigned GetSymbolOrder(const MCSymbol *Sym) const {
292 return SymbolOrdering.lookup(Sym);
295 /// ChangeSection - Update streamer for a new active section.
297 /// This is called by PopSection and SwitchSection, if the current
299 virtual void ChangeSection(const MCSection *, const MCExpr *) = 0;
301 /// pushSection - Save the current and previous section on the
304 SectionStack.push_back(
305 std::make_pair(getCurrentSection(), getPreviousSection()));
308 /// popSection - Restore the current and previous section from
309 /// the section stack. Calls ChangeSection as needed.
311 /// Returns false if the stack was empty.
313 if (SectionStack.size() <= 1)
315 MCSectionSubPair oldSection = SectionStack.pop_back_val().first;
316 MCSectionSubPair curSection = SectionStack.back().first;
318 if (oldSection != curSection)
319 ChangeSection(curSection.first, curSection.second);
323 bool SubSection(const MCExpr *Subsection) {
324 if (SectionStack.empty())
327 SwitchSection(SectionStack.back().first.first, Subsection);
331 /// SwitchSection - Set the current section where code is being emitted to
332 /// @p Section. This is required to update CurSection.
334 /// This corresponds to assembler directives like .section, .text, etc.
335 void SwitchSection(const MCSection *Section,
336 const MCExpr *Subsection = nullptr) {
337 assert(Section && "Cannot switch to a null section!");
338 MCSectionSubPair curSection = SectionStack.back().first;
339 SectionStack.back().second = curSection;
340 if (MCSectionSubPair(Section, Subsection) != curSection) {
341 SectionStack.back().first = MCSectionSubPair(Section, Subsection);
342 ChangeSection(Section, Subsection);
346 /// SwitchSectionNoChange - Set the current section where code is being
347 /// emitted to @p Section. This is required to update CurSection. This
348 /// version does not call ChangeSection.
349 void SwitchSectionNoChange(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);
358 /// Create the default sections and set the initial one.
359 virtual void InitSections();
361 /// AssignSection - 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 AssignSection(MCSymbol *Symbol, const MCSection *Section);
367 /// EmitLabel - 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 EmitDebugLabel(MCSymbol *Symbol);
381 virtual void EmitEHSymAttributes(const MCSymbol *Symbol, MCSymbol *EHSymbol);
383 /// EmitAssemblerFlag - Note in the output the specified @p Flag.
384 virtual void EmitAssemblerFlag(MCAssemblerFlag Flag) = 0;
386 /// EmitLinkerOptions - Emit the given list @p Options of strings as linker
387 /// options into the output.
388 virtual void EmitLinkerOptions(ArrayRef<std::string> Kind) {}
390 /// EmitDataRegion - Note in the output the specified region @p Kind.
391 virtual void EmitDataRegion(MCDataRegionType Kind) {}
393 /// EmitVersionMin - Specify the MachO minimum deployment target version.
394 virtual void EmitVersionMin(MCVersionMinType, unsigned Major, unsigned Minor,
397 /// EmitThumbFunc - Note in the output that the specified @p Func is
398 /// a Thumb mode function (ARM target only).
399 virtual void EmitThumbFunc(MCSymbol *Func) = 0;
401 /// EmitAssignment - Emit an assignment of @p Value to @p Symbol.
403 /// This corresponds to an assembler statement such as:
406 /// The assignment generates no code, but has the side effect of binding the
407 /// value in the current context. For the assembly streamer, this prints the
408 /// binding into the .s file.
410 /// @param Symbol - The symbol being assigned to.
411 /// @param Value - The value for the symbol.
412 virtual void EmitAssignment(MCSymbol *Symbol, const MCExpr *Value);
414 /// EmitWeakReference - Emit an weak reference from @p Alias to @p Symbol.
416 /// This corresponds to an assembler statement such as:
417 /// .weakref alias, symbol
419 /// @param Alias - The alias that is being created.
420 /// @param Symbol - The symbol being aliased.
421 virtual void EmitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol) = 0;
423 /// EmitSymbolAttribute - Add the given @p Attribute to @p Symbol.
424 virtual bool EmitSymbolAttribute(MCSymbol *Symbol,
425 MCSymbolAttr Attribute) = 0;
427 /// EmitSymbolDesc - Set the @p DescValue for the @p Symbol.
429 /// @param Symbol - The symbol to have its n_desc field set.
430 /// @param DescValue - The value to set into the n_desc field.
431 virtual void EmitSymbolDesc(MCSymbol *Symbol, unsigned DescValue) = 0;
433 /// BeginCOFFSymbolDef - Start emitting COFF symbol definition
435 /// @param Symbol - The symbol to have its External & Type fields set.
436 virtual void BeginCOFFSymbolDef(const MCSymbol *Symbol) = 0;
438 /// EmitCOFFSymbolStorageClass - Emit the storage class of the symbol.
440 /// @param StorageClass - The storage class the symbol should have.
441 virtual void EmitCOFFSymbolStorageClass(int StorageClass) = 0;
443 /// EmitCOFFSymbolType - Emit the type of the symbol.
445 /// @param Type - A COFF type identifier (see COFF::SymbolType in X86COFF.h)
446 virtual void EmitCOFFSymbolType(int Type) = 0;
448 /// EndCOFFSymbolDef - Marks the end of the symbol definition.
449 virtual void EndCOFFSymbolDef() = 0;
451 /// EmitCOFFSectionIndex - Emits a COFF section index.
453 /// @param Symbol - Symbol the section number relocation should point to.
454 virtual void EmitCOFFSectionIndex(MCSymbol const *Symbol);
456 /// EmitCOFFSecRel32 - 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 /// EmitELFSize - Emit an ELF .size directive.
463 /// This corresponds to an assembler statement such as:
464 /// .size symbol, expression
466 virtual void EmitELFSize(MCSymbol *Symbol, const MCExpr *Value) = 0;
468 /// \brief Emit a Linker Optimization Hint (LOH) directive.
469 /// \param Args - Arguments of the LOH.
470 virtual void EmitLOHDirective(MCLOHType Kind, const MCLOHArgs &Args) {}
472 /// EmitCommonSymbol - Emit a common symbol.
474 /// @param Symbol - The common symbol to emit.
475 /// @param Size - The size of the common symbol.
476 /// @param ByteAlignment - The alignment of the symbol if
477 /// non-zero. This must be a power of 2.
478 virtual void EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
479 unsigned ByteAlignment) = 0;
481 /// EmitLocalCommonSymbol - Emit a local common (.lcomm) symbol.
483 /// @param Symbol - The common symbol to emit.
484 /// @param Size - The size of the common symbol.
485 /// @param ByteAlignment - The alignment of the common symbol in bytes.
486 virtual void EmitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size,
487 unsigned ByteAlignment) = 0;
489 /// EmitZerofill - Emit the zerofill section and an optional symbol.
491 /// @param Section - The zerofill section to create and or to put the symbol
492 /// @param Symbol - The zerofill symbol to emit, if non-NULL.
493 /// @param Size - The size of the zerofill symbol.
494 /// @param ByteAlignment - The alignment of the zerofill symbol if
495 /// non-zero. This must be a power of 2 on some targets.
496 virtual void EmitZerofill(const MCSection *Section,
497 MCSymbol *Symbol = nullptr, uint64_t Size = 0,
498 unsigned ByteAlignment = 0) = 0;
500 /// EmitTBSSSymbol - Emit a thread local bss (.tbss) symbol.
502 /// @param Section - The thread local common section.
503 /// @param Symbol - The thread local common symbol to emit.
504 /// @param Size - The size of the symbol.
505 /// @param ByteAlignment - The alignment of the thread local common symbol
506 /// if non-zero. This must be a power of 2 on some targets.
507 virtual void EmitTBSSSymbol(const MCSection *Section, MCSymbol *Symbol,
508 uint64_t Size, unsigned ByteAlignment = 0) = 0;
511 /// @name Generating Data
514 /// EmitBytes - Emit the bytes in \p Data into the output.
516 /// This is used to implement assembler directives such as .byte, .ascii,
518 virtual void EmitBytes(StringRef Data) = 0;
520 /// EmitValue - Emit the expression @p Value into the output as a native
521 /// integer of the given @p Size bytes.
523 /// This is used to implement assembler directives such as .word, .quad,
526 /// @param Value - The value to emit.
527 /// @param Size - The size of the integer (in bytes) to emit. This must
528 /// match a native machine width.
529 /// @param Loc - The location of the expression for error reporting.
530 virtual void EmitValueImpl(const MCExpr *Value, unsigned Size,
531 const SMLoc &Loc = SMLoc()) = 0;
533 void EmitValue(const MCExpr *Value, unsigned Size,
534 const SMLoc &Loc = SMLoc());
536 /// EmitIntValue - Special case of EmitValue that avoids the client having
537 /// to pass in a MCExpr for constant integers.
538 virtual void EmitIntValue(uint64_t Value, unsigned Size);
540 /// EmitAbsValue - Emit the Value, but try to avoid relocations. On MachO
541 /// this is done by producing
544 void EmitAbsValue(const MCExpr *Value, unsigned Size);
546 virtual void EmitULEB128Value(const MCExpr *Value) = 0;
548 virtual void EmitSLEB128Value(const MCExpr *Value) = 0;
550 /// EmitULEB128Value - Special case of EmitULEB128Value that avoids the
551 /// client having to pass in a MCExpr for constant integers.
552 void EmitULEB128IntValue(uint64_t Value, unsigned Padding = 0);
554 /// EmitSLEB128Value - Special case of EmitSLEB128Value that avoids the
555 /// client having to pass in a MCExpr for constant integers.
556 void EmitSLEB128IntValue(int64_t Value);
558 /// EmitSymbolValue - Special case of EmitValue that avoids the client
559 /// having to pass in a MCExpr for MCSymbols.
560 void EmitSymbolValue(const MCSymbol *Sym, unsigned Size);
562 /// EmitGPRel64Value - Emit the expression @p Value into the output as a
563 /// gprel64 (64-bit GP relative) value.
565 /// This is used to implement assembler directives such as .gpdword on
566 /// targets that support them.
567 virtual void EmitGPRel64Value(const MCExpr *Value);
569 /// EmitGPRel32Value - Emit the expression @p Value into the output as a
570 /// gprel32 (32-bit GP relative) value.
572 /// This is used to implement assembler directives such as .gprel32 on
573 /// targets that support them.
574 virtual void EmitGPRel32Value(const MCExpr *Value);
576 /// EmitFill - Emit NumBytes bytes worth of the value specified by
577 /// FillValue. This implements directives such as '.space'.
578 virtual void EmitFill(uint64_t NumBytes, uint8_t FillValue);
580 /// \brief Emit NumBytes worth of zeros.
581 /// This function properly handles data in virtual sections.
582 virtual void EmitZeros(uint64_t NumBytes);
584 /// EmitValueToAlignment - Emit some number of copies of @p Value until
585 /// the byte alignment @p ByteAlignment is reached.
587 /// If the number of bytes need to emit for the alignment is not a multiple
588 /// of @p ValueSize, then the contents of the emitted fill bytes is
591 /// This used to implement the .align assembler directive.
593 /// @param ByteAlignment - The alignment to reach. This must be a power of
594 /// two on some targets.
595 /// @param Value - The value to use when filling bytes.
596 /// @param ValueSize - The size of the integer (in bytes) to emit for
597 /// @p Value. This must match a native machine width.
598 /// @param MaxBytesToEmit - The maximum numbers of bytes to emit, or 0. If
599 /// the alignment cannot be reached in this many bytes, no bytes are
601 virtual void EmitValueToAlignment(unsigned ByteAlignment, int64_t Value = 0,
602 unsigned ValueSize = 1,
603 unsigned MaxBytesToEmit = 0) = 0;
605 /// EmitCodeAlignment - Emit nops until the byte alignment @p ByteAlignment
608 /// This used to align code where the alignment bytes may be executed. This
609 /// can emit different bytes for different sizes to optimize execution.
611 /// @param ByteAlignment - The alignment to reach. This must be a power of
612 /// two on some targets.
613 /// @param MaxBytesToEmit - The maximum numbers of bytes to emit, or 0. If
614 /// the alignment cannot be reached in this many bytes, no bytes are
616 virtual void EmitCodeAlignment(unsigned ByteAlignment,
617 unsigned MaxBytesToEmit = 0) = 0;
619 /// EmitValueToOffset - Emit some number of copies of @p Value until the
620 /// byte offset @p Offset is reached.
622 /// This is used to implement assembler directives such as .org.
624 /// @param Offset - The offset to reach. This may be an expression, but the
625 /// expression must be associated with the current section.
626 /// @param Value - The value to use when filling bytes.
627 /// @return false on success, true if the offset was invalid.
628 virtual bool EmitValueToOffset(const MCExpr *Offset,
629 unsigned char Value = 0) = 0;
633 /// EmitFileDirective - Switch to a new logical file. This is used to
634 /// implement the '.file "foo.c"' assembler directive.
635 virtual void EmitFileDirective(StringRef Filename) = 0;
637 /// Emit the "identifiers" directive. This implements the
638 /// '.ident "version foo"' assembler directive.
639 virtual void EmitIdent(StringRef IdentString) {}
641 /// EmitDwarfFileDirective - Associate a filename with a specified logical
642 /// file number. This implements the DWARF2 '.file 4 "foo.c"' assembler
644 virtual unsigned EmitDwarfFileDirective(unsigned FileNo, StringRef Directory,
648 /// EmitDwarfLocDirective - This implements the DWARF2
649 // '.loc fileno lineno ...' assembler directive.
650 virtual void EmitDwarfLocDirective(unsigned FileNo, unsigned Line,
651 unsigned Column, unsigned Flags,
652 unsigned Isa, unsigned Discriminator,
655 virtual void EmitDwarfAdvanceLineAddr(int64_t LineDelta,
656 const MCSymbol *LastLabel,
657 const MCSymbol *Label,
658 unsigned PointerSize) = 0;
660 virtual void EmitDwarfAdvanceFrameAddr(const MCSymbol *LastLabel,
661 const MCSymbol *Label) {}
663 virtual MCSymbol *getDwarfLineTableSymbol(unsigned CUID);
665 void EmitDwarfSetLineAddr(int64_t LineDelta, const MCSymbol *Label,
668 virtual void EmitCompactUnwindEncoding(uint32_t CompactUnwindEncoding);
669 virtual void EmitCFISections(bool EH, bool Debug);
670 void EmitCFIStartProc(bool IsSimple);
671 void EmitCFIEndProc();
672 virtual void EmitCFIDefCfa(int64_t Register, int64_t Offset);
673 virtual void EmitCFIDefCfaOffset(int64_t Offset);
674 virtual void EmitCFIDefCfaRegister(int64_t Register);
675 virtual void EmitCFIOffset(int64_t Register, int64_t Offset);
676 virtual void EmitCFIPersonality(const MCSymbol *Sym, unsigned Encoding);
677 virtual void EmitCFILsda(const MCSymbol *Sym, unsigned Encoding);
678 virtual void EmitCFIRememberState();
679 virtual void EmitCFIRestoreState();
680 virtual void EmitCFISameValue(int64_t Register);
681 virtual void EmitCFIRestore(int64_t Register);
682 virtual void EmitCFIRelOffset(int64_t Register, int64_t Offset);
683 virtual void EmitCFIAdjustCfaOffset(int64_t Adjustment);
684 virtual void EmitCFIEscape(StringRef Values);
685 virtual void EmitCFISignalFrame();
686 virtual void EmitCFIUndefined(int64_t Register);
687 virtual void EmitCFIRegister(int64_t Register1, int64_t Register2);
688 virtual void EmitCFIWindowSave();
690 virtual void EmitWin64EHStartProc(const MCSymbol *Symbol);
691 virtual void EmitWin64EHEndProc();
692 virtual void EmitWin64EHStartChained();
693 virtual void EmitWin64EHEndChained();
694 virtual void EmitWin64EHHandler(const MCSymbol *Sym, bool Unwind,
696 virtual void EmitWin64EHHandlerData();
697 virtual void EmitWin64EHPushReg(unsigned Register);
698 virtual void EmitWin64EHSetFrame(unsigned Register, unsigned Offset);
699 virtual void EmitWin64EHAllocStack(unsigned Size);
700 virtual void EmitWin64EHSaveReg(unsigned Register, unsigned Offset);
701 virtual void EmitWin64EHSaveXMM(unsigned Register, unsigned Offset);
702 virtual void EmitWin64EHPushFrame(bool Code);
703 virtual void EmitWin64EHEndProlog();
705 /// EmitInstruction - Emit the given @p Instruction into the current
707 virtual void EmitInstruction(const MCInst &Inst, const MCSubtargetInfo &STI) = 0;
709 /// \brief Set the bundle alignment mode from now on in the section.
710 /// The argument is the power of 2 to which the alignment is set. The
711 /// value 0 means turn the bundle alignment off.
712 virtual void EmitBundleAlignMode(unsigned AlignPow2) = 0;
714 /// \brief The following instructions are a bundle-locked group.
716 /// \param AlignToEnd - If true, the bundle-locked group will be aligned to
717 /// the end of a bundle.
718 virtual void EmitBundleLock(bool AlignToEnd) = 0;
720 /// \brief Ends a bundle-locked group.
721 virtual void EmitBundleUnlock() = 0;
723 /// EmitRawText - If this file is backed by a assembly streamer, this dumps
724 /// the specified string in the output .s file. This capability is
725 /// indicated by the hasRawTextSupport() predicate. By default this aborts.
726 void EmitRawText(const Twine &String);
728 /// Flush - Causes any cached state to be written out.
729 virtual void Flush() {}
731 /// FinishImpl - Streamer specific finalization.
732 virtual void FinishImpl() = 0;
733 /// Finish - Finish emission of machine code.
737 /// createNullStreamer - Create a dummy machine code streamer, which does
738 /// nothing. This is useful for timing the assembler front end.
739 MCStreamer *createNullStreamer(MCContext &Ctx);
741 /// createAsmStreamer - Create a machine code streamer which will print out
742 /// assembly for the native target, suitable for compiling with a native
745 /// \param InstPrint - If given, the instruction printer to use. If not given
746 /// the MCInst representation will be printed. This method takes ownership of
749 /// \param CE - If given, a code emitter to use to show the instruction
750 /// encoding inline with the assembly. This method takes ownership of \p CE.
752 /// \param TAB - If given, a target asm backend to use to show the fixup
753 /// information in conjunction with encoding information. This method takes
754 /// ownership of \p TAB.
756 /// \param ShowInst - Whether to show the MCInst representation inline with
758 MCStreamer *createAsmStreamer(MCContext &Ctx, formatted_raw_ostream &OS,
759 bool isVerboseAsm, bool useCFI,
760 bool useDwarfDirectory, MCInstPrinter *InstPrint,
761 MCCodeEmitter *CE, MCAsmBackend *TAB,
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