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/MCWin64EH.h"
23 #include "llvm/Support/DataTypes.h"
36 class MCSymbolRefExpr;
37 class MCSubtargetInfo;
41 class formatted_raw_ostream;
42 class AssemblerConstantPools;
44 typedef std::pair<const MCSection *, const MCExpr *> MCSectionSubPair;
46 /// Target specific streamer interface. This is used so that targets can
47 /// implement support for target specific assembly directives.
49 /// If target foo wants to use this, it should implement 3 classes:
50 /// * FooTargetStreamer : public MCTargetStreamer
51 /// * FooTargetAsmSreamer : public FooTargetStreamer
52 /// * FooTargetELFStreamer : public FooTargetStreamer
54 /// FooTargetStreamer should have a pure virtual method for each directive. For
55 /// example, for a ".bar symbol_name" directive, it should have
56 /// virtual emitBar(const MCSymbol &Symbol) = 0;
58 /// The FooTargetAsmSreamer and FooTargetELFStreamer classes implement the
59 /// method. The assembly streamer just prints ".bar symbol_name". The object
60 /// streamer does whatever is needed to implement .bar in the object file.
62 /// In the assembly printer and parser the target streamer can be used by
63 /// calling getTargetStreamer and casting it to FooTargetStreamer:
65 /// MCTargetStreamer &TS = OutStreamer.getTargetStreamer();
66 /// FooTargetStreamer &ATS = static_cast<FooTargetStreamer &>(TS);
68 /// The base classes FooTargetAsmSreamer and FooTargetELFStreamer should *never*
69 /// be treated differently. Callers should always talk to a FooTargetStreamer.
70 class MCTargetStreamer {
75 MCTargetStreamer(MCStreamer &S);
76 virtual ~MCTargetStreamer();
78 const MCStreamer &getStreamer() { return Streamer; }
80 // Allow a target to add behavior to the EmitLabel of MCStreamer.
81 virtual void emitLabel(MCSymbol *Symbol);
82 // Allow a target to add behavior to the emitAssignment of MCStreamer.
83 virtual void emitAssignment(MCSymbol *Symbol, const MCExpr *Value);
85 virtual void finish();
88 // FIXME: declared here because it is used from
89 // lib/CodeGen/AsmPrinter/ARMException.cpp.
90 class ARMTargetStreamer : public MCTargetStreamer {
92 ARMTargetStreamer(MCStreamer &S);
95 virtual void emitFnStart();
96 virtual void emitFnEnd();
97 virtual void emitCantUnwind();
98 virtual void emitPersonality(const MCSymbol *Personality);
99 virtual void emitPersonalityIndex(unsigned Index);
100 virtual void emitHandlerData();
101 virtual void emitSetFP(unsigned FpReg, unsigned SpReg,
103 virtual void emitMovSP(unsigned Reg, int64_t Offset = 0);
104 virtual void emitPad(int64_t Offset);
105 virtual void emitRegSave(const SmallVectorImpl<unsigned> &RegList,
107 virtual void emitUnwindRaw(int64_t StackOffset,
108 const SmallVectorImpl<uint8_t> &Opcodes);
110 virtual void switchVendor(StringRef Vendor);
111 virtual void emitAttribute(unsigned Attribute, unsigned Value);
112 virtual void emitTextAttribute(unsigned Attribute, StringRef String);
113 virtual void emitIntTextAttribute(unsigned Attribute, unsigned IntValue,
114 StringRef StringValue = "");
115 virtual void emitFPU(unsigned FPU);
116 virtual void emitArch(unsigned Arch);
117 virtual void emitObjectArch(unsigned Arch);
118 virtual void finishAttributeSection();
119 virtual void emitInst(uint32_t Inst, char Suffix = '\0');
121 virtual void AnnotateTLSDescriptorSequence(const MCSymbolRefExpr *SRE);
123 void finish() override;
125 /// Callback used to implement the ldr= pseudo.
126 /// Add a new entry to the constant pool for the current section and return an
127 /// MCExpr that can be used to refer to the constant pool location.
128 const MCExpr *addConstantPoolEntry(const MCExpr *);
130 /// Callback used to implemnt the .ltorg directive.
131 /// Emit contents of constant pool for the current section.
132 void emitCurrentConstantPool();
135 std::unique_ptr<AssemblerConstantPools> ConstantPools;
138 /// MCStreamer - Streaming machine code generation interface. This interface
139 /// is intended to provide a programatic interface that is very similar to the
140 /// level that an assembler .s file provides. It has callbacks to emit bytes,
141 /// handle directives, etc. The implementation of this interface retains
142 /// state to know what the current section is etc.
144 /// There are multiple implementations of this interface: one for writing out
145 /// a .s file, and implementations that write out .o files of various formats.
149 std::unique_ptr<MCTargetStreamer> TargetStreamer;
151 MCStreamer(const MCStreamer &) LLVM_DELETED_FUNCTION;
152 MCStreamer &operator=(const MCStreamer &) LLVM_DELETED_FUNCTION;
157 std::vector<MCDwarfFrameInfo> FrameInfos;
158 MCDwarfFrameInfo *getCurrentFrameInfo();
159 MCSymbol *EmitCFICommon();
160 void EnsureValidFrame();
162 std::vector<MCWin64EHUnwindInfo *> W64UnwindInfos;
163 MCWin64EHUnwindInfo *CurrentW64UnwindInfo;
164 void setCurrentW64UnwindInfo(MCWin64EHUnwindInfo *Frame);
165 void EnsureValidW64UnwindInfo();
167 MCSymbol *LastSymbol;
169 // SymbolOrdering - Tracks an index to represent the order
170 // a symbol was emitted in. Zero means we did not emit that symbol.
171 DenseMap<const MCSymbol *, unsigned> SymbolOrdering;
173 /// SectionStack - This is stack of current and previous section
174 /// values saved by PushSection.
175 SmallVector<std::pair<MCSectionSubPair, MCSectionSubPair>, 4> SectionStack;
178 MCStreamer(MCContext &Ctx);
180 const MCExpr *BuildSymbolDiff(MCContext &Context, const MCSymbol *A,
183 const MCExpr *ForceExpAbs(const MCExpr *Expr);
185 void RecordProcStart(MCDwarfFrameInfo &Frame);
186 virtual void EmitCFIStartProcImpl(MCDwarfFrameInfo &Frame);
187 void RecordProcEnd(MCDwarfFrameInfo &Frame);
188 virtual void EmitCFIEndProcImpl(MCDwarfFrameInfo &CurFrame);
189 void EmitFrames(MCAsmBackend *MAB, bool usingCFI);
191 MCWin64EHUnwindInfo *getCurrentW64UnwindInfo() {
192 return CurrentW64UnwindInfo;
194 void EmitW64Tables();
196 virtual void EmitRawTextImpl(StringRef String);
199 virtual ~MCStreamer();
201 void setTargetStreamer(MCTargetStreamer *TS) {
202 TargetStreamer.reset(TS);
207 virtual void reset();
209 MCContext &getContext() const { return Context; }
211 MCTargetStreamer *getTargetStreamer() {
212 return TargetStreamer.get();
215 unsigned getNumFrameInfos() { return FrameInfos.size(); }
217 const MCDwarfFrameInfo &getFrameInfo(unsigned i) { return FrameInfos[i]; }
219 ArrayRef<MCDwarfFrameInfo> getFrameInfos() const { return FrameInfos; }
221 unsigned getNumW64UnwindInfos() { return W64UnwindInfos.size(); }
223 MCWin64EHUnwindInfo &getW64UnwindInfo(unsigned i) {
224 return *W64UnwindInfos[i];
227 void generateCompactUnwindEncodings(MCAsmBackend *MAB);
229 /// @name Assembly File Formatting.
232 /// isVerboseAsm - Return true if this streamer supports verbose assembly
233 /// and if it is enabled.
234 virtual bool isVerboseAsm() const { return false; }
236 /// hasRawTextSupport - Return true if this asm streamer supports emitting
237 /// unformatted text to the .s file with EmitRawText.
238 virtual bool hasRawTextSupport() const { return false; }
240 /// Is the integrated assembler required for this streamer to function
242 virtual bool isIntegratedAssemblerRequired() const { return false; }
244 /// AddComment - Add a comment that can be emitted to the generated .s
245 /// file if applicable as a QoI issue to make the output of the compiler
246 /// more readable. This only affects the MCAsmStreamer, and only when
247 /// verbose assembly output is enabled.
249 /// If the comment includes embedded \n's, they will each get the comment
250 /// prefix as appropriate. The added comment should not end with a \n.
251 virtual void AddComment(const Twine &T) {}
253 /// GetCommentOS - Return a raw_ostream that comments can be written to.
254 /// Unlike AddComment, you are required to terminate comments with \n if you
256 virtual raw_ostream &GetCommentOS();
258 /// Print T and prefix it with the comment string (normally #) and optionally
259 /// a tab. This prints the comment immediately, not at the end of the
260 /// current line. It is basically a safe version of EmitRawText: since it
261 /// only prints comments, the object streamer ignores it instead of asserting.
262 virtual void emitRawComment(const Twine &T, bool TabPrefix = true);
264 /// AddBlankLine - Emit a blank line to a .s file to pretty it up.
265 virtual void AddBlankLine() {}
269 /// @name Symbol & Section Management
272 /// getCurrentSection - Return the current section that the streamer is
273 /// emitting code to.
274 MCSectionSubPair getCurrentSection() const {
275 if (!SectionStack.empty())
276 return SectionStack.back().first;
277 return MCSectionSubPair();
280 /// getPreviousSection - Return the previous section that the streamer is
281 /// emitting code to.
282 MCSectionSubPair getPreviousSection() const {
283 if (!SectionStack.empty())
284 return SectionStack.back().second;
285 return MCSectionSubPair();
288 /// GetSymbolOrder - Returns an index to represent the order
289 /// a symbol was emitted in. (zero if we did not emit that symbol)
290 unsigned GetSymbolOrder(const MCSymbol *Sym) const {
291 return SymbolOrdering.lookup(Sym);
294 /// ChangeSection - Update streamer for a new active section.
296 /// This is called by PopSection and SwitchSection, if the current
298 virtual void ChangeSection(const MCSection *, const MCExpr *) = 0;
300 /// pushSection - Save the current and previous section on the
303 SectionStack.push_back(
304 std::make_pair(getCurrentSection(), getPreviousSection()));
307 /// popSection - Restore the current and previous section from
308 /// the section stack. Calls ChangeSection as needed.
310 /// Returns false if the stack was empty.
312 if (SectionStack.size() <= 1)
314 MCSectionSubPair oldSection = SectionStack.pop_back_val().first;
315 MCSectionSubPair curSection = SectionStack.back().first;
317 if (oldSection != curSection)
318 ChangeSection(curSection.first, curSection.second);
322 bool SubSection(const MCExpr *Subsection) {
323 if (SectionStack.empty())
326 SwitchSection(SectionStack.back().first.first, Subsection);
330 /// SwitchSection - Set the current section where code is being emitted to
331 /// @p Section. This is required to update CurSection.
333 /// This corresponds to assembler directives like .section, .text, etc.
334 void SwitchSection(const MCSection *Section, const MCExpr *Subsection = 0) {
335 assert(Section && "Cannot switch to a null section!");
336 MCSectionSubPair curSection = SectionStack.back().first;
337 SectionStack.back().second = curSection;
338 if (MCSectionSubPair(Section, Subsection) != curSection) {
339 SectionStack.back().first = MCSectionSubPair(Section, Subsection);
340 ChangeSection(Section, Subsection);
344 /// SwitchSectionNoChange - Set the current section where code is being
345 /// emitted to @p Section. This is required to update CurSection. This
346 /// version does not call ChangeSection.
347 void SwitchSectionNoChange(const MCSection *Section,
348 const MCExpr *Subsection = 0) {
349 assert(Section && "Cannot switch to a null section!");
350 MCSectionSubPair curSection = SectionStack.back().first;
351 SectionStack.back().second = curSection;
352 if (MCSectionSubPair(Section, Subsection) != curSection)
353 SectionStack.back().first = MCSectionSubPair(Section, Subsection);
356 /// Create the default sections and set the initial one.
357 virtual void InitSections();
359 /// AssignSection - Sets the symbol's section.
361 /// Each emitted symbol will be tracked in the ordering table,
362 /// so we can sort on them later.
363 void AssignSection(MCSymbol *Symbol, const MCSection *Section);
365 /// EmitLabel - Emit a label for @p Symbol into the current section.
367 /// This corresponds to an assembler statement such as:
370 /// @param Symbol - The symbol to emit. A given symbol should only be
371 /// emitted as a label once, and symbols emitted as a label should never be
372 /// used in an assignment.
373 // FIXME: These emission are non-const because we mutate the symbol to
374 // add the section we're emitting it to later.
375 virtual void EmitLabel(MCSymbol *Symbol);
377 virtual void EmitDebugLabel(MCSymbol *Symbol);
379 virtual void EmitEHSymAttributes(const MCSymbol *Symbol, MCSymbol *EHSymbol);
381 /// EmitAssemblerFlag - Note in the output the specified @p Flag.
382 virtual void EmitAssemblerFlag(MCAssemblerFlag Flag) = 0;
384 /// EmitLinkerOptions - Emit the given list @p Options of strings as linker
385 /// options into the output.
386 virtual void EmitLinkerOptions(ArrayRef<std::string> Kind) {}
388 /// EmitDataRegion - Note in the output the specified region @p Kind.
389 virtual void EmitDataRegion(MCDataRegionType Kind) {}
391 /// EmitVersionMin - Specify the MachO minimum deployment target version.
392 virtual void EmitVersionMin(MCVersionMinType, unsigned Major, unsigned Minor,
395 /// EmitThumbFunc - Note in the output that the specified @p Func is
396 /// a Thumb mode function (ARM target only).
397 virtual void EmitThumbFunc(MCSymbol *Func) = 0;
399 /// getOrCreateSymbolData - Get symbol data for given symbol.
400 virtual MCSymbolData &getOrCreateSymbolData(const MCSymbol *Symbol);
402 /// EmitAssignment - Emit an assignment of @p Value to @p Symbol.
404 /// This corresponds to an assembler statement such as:
407 /// The assignment generates no code, but has the side effect of binding the
408 /// value in the current context. For the assembly streamer, this prints the
409 /// binding into the .s file.
411 /// @param Symbol - The symbol being assigned to.
412 /// @param Value - The value for the symbol.
413 virtual void EmitAssignment(MCSymbol *Symbol, const MCExpr *Value);
415 /// EmitWeakReference - Emit an weak reference from @p Alias to @p Symbol.
417 /// This corresponds to an assembler statement such as:
418 /// .weakref alias, symbol
420 /// @param Alias - The alias that is being created.
421 /// @param Symbol - The symbol being aliased.
422 virtual void EmitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol) = 0;
424 /// EmitSymbolAttribute - Add the given @p Attribute to @p Symbol.
425 virtual bool EmitSymbolAttribute(MCSymbol *Symbol,
426 MCSymbolAttr Attribute) = 0;
428 /// EmitSymbolDesc - Set the @p DescValue for the @p Symbol.
430 /// @param Symbol - The symbol to have its n_desc field set.
431 /// @param DescValue - The value to set into the n_desc field.
432 virtual void EmitSymbolDesc(MCSymbol *Symbol, unsigned DescValue) = 0;
434 /// BeginCOFFSymbolDef - Start emitting COFF symbol definition
436 /// @param Symbol - The symbol to have its External & Type fields set.
437 virtual void BeginCOFFSymbolDef(const MCSymbol *Symbol) = 0;
439 /// EmitCOFFSymbolStorageClass - Emit the storage class of the symbol.
441 /// @param StorageClass - The storage class the symbol should have.
442 virtual void EmitCOFFSymbolStorageClass(int StorageClass) = 0;
444 /// EmitCOFFSymbolType - Emit the type of the symbol.
446 /// @param Type - A COFF type identifier (see COFF::SymbolType in X86COFF.h)
447 virtual void EmitCOFFSymbolType(int Type) = 0;
449 /// EndCOFFSymbolDef - Marks the end of the symbol definition.
450 virtual void EndCOFFSymbolDef() = 0;
452 /// EmitCOFFSectionIndex - Emits a COFF section index.
454 /// @param Symbol - Symbol the section number relocation should point to.
455 virtual void EmitCOFFSectionIndex(MCSymbol const *Symbol);
457 /// EmitCOFFSecRel32 - Emits a COFF section relative relocation.
459 /// @param Symbol - Symbol the section relative relocation should point to.
460 virtual void EmitCOFFSecRel32(MCSymbol const *Symbol);
462 /// EmitELFSize - Emit an ELF .size directive.
464 /// This corresponds to an assembler statement such as:
465 /// .size symbol, expression
467 virtual void EmitELFSize(MCSymbol *Symbol, const MCExpr *Value) = 0;
469 /// EmitCommonSymbol - Emit a common symbol.
471 /// @param Symbol - The common symbol to emit.
472 /// @param Size - The size of the common symbol.
473 /// @param ByteAlignment - The alignment of the symbol if
474 /// non-zero. This must be a power of 2.
475 virtual void EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
476 unsigned ByteAlignment) = 0;
478 /// EmitLocalCommonSymbol - Emit a local common (.lcomm) symbol.
480 /// @param Symbol - The common symbol to emit.
481 /// @param Size - The size of the common symbol.
482 /// @param ByteAlignment - The alignment of the common symbol in bytes.
483 virtual void EmitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size,
484 unsigned ByteAlignment) = 0;
486 /// EmitZerofill - Emit the zerofill section and an optional symbol.
488 /// @param Section - The zerofill section to create and or to put the symbol
489 /// @param Symbol - The zerofill symbol to emit, if non-NULL.
490 /// @param Size - The size of the zerofill symbol.
491 /// @param ByteAlignment - The alignment of the zerofill symbol if
492 /// non-zero. This must be a power of 2 on some targets.
493 virtual void EmitZerofill(const MCSection *Section, MCSymbol *Symbol = 0,
494 uint64_t Size = 0, unsigned ByteAlignment = 0) = 0;
496 /// EmitTBSSSymbol - Emit a thread local bss (.tbss) symbol.
498 /// @param Section - The thread local common section.
499 /// @param Symbol - The thread local common symbol to emit.
500 /// @param Size - The size of the symbol.
501 /// @param ByteAlignment - The alignment of the thread local common symbol
502 /// if non-zero. This must be a power of 2 on some targets.
503 virtual void EmitTBSSSymbol(const MCSection *Section, MCSymbol *Symbol,
504 uint64_t Size, unsigned ByteAlignment = 0) = 0;
507 /// @name Generating Data
510 /// EmitBytes - Emit the bytes in \p Data into the output.
512 /// This is used to implement assembler directives such as .byte, .ascii,
514 virtual void EmitBytes(StringRef Data) = 0;
516 /// EmitValue - Emit the expression @p Value into the output as a native
517 /// integer of the given @p Size bytes.
519 /// This is used to implement assembler directives such as .word, .quad,
522 /// @param Value - The value to emit.
523 /// @param Size - The size of the integer (in bytes) to emit. This must
524 /// match a native machine width.
525 virtual void EmitValueImpl(const MCExpr *Value, unsigned Size) = 0;
527 void EmitValue(const MCExpr *Value, unsigned Size);
529 /// EmitIntValue - Special case of EmitValue that avoids the client having
530 /// to pass in a MCExpr for constant integers.
531 virtual void EmitIntValue(uint64_t Value, unsigned Size);
533 /// EmitAbsValue - Emit the Value, but try to avoid relocations. On MachO
534 /// this is done by producing
537 void EmitAbsValue(const MCExpr *Value, unsigned Size);
539 virtual void EmitULEB128Value(const MCExpr *Value) = 0;
541 virtual void EmitSLEB128Value(const MCExpr *Value) = 0;
543 /// EmitULEB128Value - Special case of EmitULEB128Value that avoids the
544 /// client having to pass in a MCExpr for constant integers.
545 void EmitULEB128IntValue(uint64_t Value, unsigned Padding = 0);
547 /// EmitSLEB128Value - Special case of EmitSLEB128Value that avoids the
548 /// client having to pass in a MCExpr for constant integers.
549 void EmitSLEB128IntValue(int64_t Value);
551 /// EmitSymbolValue - Special case of EmitValue that avoids the client
552 /// having to pass in a MCExpr for MCSymbols.
553 void EmitSymbolValue(const MCSymbol *Sym, unsigned Size);
555 /// EmitGPRel64Value - Emit the expression @p Value into the output as a
556 /// gprel64 (64-bit GP relative) value.
558 /// This is used to implement assembler directives such as .gpdword on
559 /// targets that support them.
560 virtual void EmitGPRel64Value(const MCExpr *Value);
562 /// EmitGPRel32Value - Emit the expression @p Value into the output as a
563 /// gprel32 (32-bit GP relative) value.
565 /// This is used to implement assembler directives such as .gprel32 on
566 /// targets that support them.
567 virtual void EmitGPRel32Value(const MCExpr *Value);
569 /// EmitFill - Emit NumBytes bytes worth of the value specified by
570 /// FillValue. This implements directives such as '.space'.
571 virtual void EmitFill(uint64_t NumBytes, uint8_t FillValue);
573 /// \brief Emit NumBytes worth of zeros.
574 /// This function properly handles data in virtual sections.
575 virtual void EmitZeros(uint64_t NumBytes);
577 /// EmitValueToAlignment - Emit some number of copies of @p Value until
578 /// the byte alignment @p ByteAlignment is reached.
580 /// If the number of bytes need to emit for the alignment is not a multiple
581 /// of @p ValueSize, then the contents of the emitted fill bytes is
584 /// This used to implement the .align assembler directive.
586 /// @param ByteAlignment - The alignment to reach. This must be a power of
587 /// two on some targets.
588 /// @param Value - The value to use when filling bytes.
589 /// @param ValueSize - The size of the integer (in bytes) to emit for
590 /// @p Value. This must match a native machine width.
591 /// @param MaxBytesToEmit - The maximum numbers of bytes to emit, or 0. If
592 /// the alignment cannot be reached in this many bytes, no bytes are
594 virtual void EmitValueToAlignment(unsigned ByteAlignment, int64_t Value = 0,
595 unsigned ValueSize = 1,
596 unsigned MaxBytesToEmit = 0) = 0;
598 /// EmitCodeAlignment - Emit nops until the byte alignment @p ByteAlignment
601 /// This used to align code where the alignment bytes may be executed. This
602 /// can emit different bytes for different sizes to optimize execution.
604 /// @param ByteAlignment - The alignment to reach. This must be a power of
605 /// two on some targets.
606 /// @param MaxBytesToEmit - The maximum numbers of bytes to emit, or 0. If
607 /// the alignment cannot be reached in this many bytes, no bytes are
609 virtual void EmitCodeAlignment(unsigned ByteAlignment,
610 unsigned MaxBytesToEmit = 0) = 0;
612 /// EmitValueToOffset - Emit some number of copies of @p Value until the
613 /// byte offset @p Offset is reached.
615 /// This is used to implement assembler directives such as .org.
617 /// @param Offset - The offset to reach. This may be an expression, but the
618 /// expression must be associated with the current section.
619 /// @param Value - The value to use when filling bytes.
620 /// @return false on success, true if the offset was invalid.
621 virtual bool EmitValueToOffset(const MCExpr *Offset,
622 unsigned char Value = 0) = 0;
626 /// EmitFileDirective - Switch to a new logical file. This is used to
627 /// implement the '.file "foo.c"' assembler directive.
628 virtual void EmitFileDirective(StringRef Filename) = 0;
630 /// Emit the "identifiers" directive. This implements the
631 /// '.ident "version foo"' assembler directive.
632 virtual void EmitIdent(StringRef IdentString) {}
634 /// EmitDwarfFileDirective - Associate a filename with a specified logical
635 /// file number. This implements the DWARF2 '.file 4 "foo.c"' assembler
637 virtual unsigned EmitDwarfFileDirective(unsigned FileNo, StringRef Directory,
641 /// EmitDwarfLocDirective - This implements the DWARF2
642 // '.loc fileno lineno ...' assembler directive.
643 virtual void EmitDwarfLocDirective(unsigned FileNo, unsigned Line,
644 unsigned Column, unsigned Flags,
645 unsigned Isa, unsigned Discriminator,
648 virtual void EmitDwarfAdvanceLineAddr(int64_t LineDelta,
649 const MCSymbol *LastLabel,
650 const MCSymbol *Label,
651 unsigned PointerSize) = 0;
653 virtual void EmitDwarfAdvanceFrameAddr(const MCSymbol *LastLabel,
654 const MCSymbol *Label) {}
656 void EmitDwarfSetLineAddr(int64_t LineDelta, const MCSymbol *Label,
659 virtual void EmitCompactUnwindEncoding(uint32_t CompactUnwindEncoding);
660 virtual void EmitCFISections(bool EH, bool Debug);
661 void EmitCFIStartProc(bool IsSimple);
662 void EmitCFIEndProc();
663 virtual void EmitCFIDefCfa(int64_t Register, int64_t Offset);
664 virtual void EmitCFIDefCfaOffset(int64_t Offset);
665 virtual void EmitCFIDefCfaRegister(int64_t Register);
666 virtual void EmitCFIOffset(int64_t Register, int64_t Offset);
667 virtual void EmitCFIPersonality(const MCSymbol *Sym, unsigned Encoding);
668 virtual void EmitCFILsda(const MCSymbol *Sym, unsigned Encoding);
669 virtual void EmitCFIRememberState();
670 virtual void EmitCFIRestoreState();
671 virtual void EmitCFISameValue(int64_t Register);
672 virtual void EmitCFIRestore(int64_t Register);
673 virtual void EmitCFIRelOffset(int64_t Register, int64_t Offset);
674 virtual void EmitCFIAdjustCfaOffset(int64_t Adjustment);
675 virtual void EmitCFIEscape(StringRef Values);
676 virtual void EmitCFISignalFrame();
677 virtual void EmitCFIUndefined(int64_t Register);
678 virtual void EmitCFIRegister(int64_t Register1, int64_t Register2);
679 virtual void EmitCFIWindowSave();
681 virtual void EmitWin64EHStartProc(const MCSymbol *Symbol);
682 virtual void EmitWin64EHEndProc();
683 virtual void EmitWin64EHStartChained();
684 virtual void EmitWin64EHEndChained();
685 virtual void EmitWin64EHHandler(const MCSymbol *Sym, bool Unwind,
687 virtual void EmitWin64EHHandlerData();
688 virtual void EmitWin64EHPushReg(unsigned Register);
689 virtual void EmitWin64EHSetFrame(unsigned Register, unsigned Offset);
690 virtual void EmitWin64EHAllocStack(unsigned Size);
691 virtual void EmitWin64EHSaveReg(unsigned Register, unsigned Offset);
692 virtual void EmitWin64EHSaveXMM(unsigned Register, unsigned Offset);
693 virtual void EmitWin64EHPushFrame(bool Code);
694 virtual void EmitWin64EHEndProlog();
696 /// EmitInstruction - Emit the given @p Instruction into the current
698 virtual void EmitInstruction(const MCInst &Inst, const MCSubtargetInfo &STI) = 0;
700 /// \brief Set the bundle alignment mode from now on in the section.
701 /// The argument is the power of 2 to which the alignment is set. The
702 /// value 0 means turn the bundle alignment off.
703 virtual void EmitBundleAlignMode(unsigned AlignPow2) = 0;
705 /// \brief The following instructions are a bundle-locked group.
707 /// \param AlignToEnd - If true, the bundle-locked group will be aligned to
708 /// the end of a bundle.
709 virtual void EmitBundleLock(bool AlignToEnd) = 0;
711 /// \brief Ends a bundle-locked group.
712 virtual void EmitBundleUnlock() = 0;
714 /// EmitRawText - If this file is backed by a assembly streamer, this dumps
715 /// the specified string in the output .s file. This capability is
716 /// indicated by the hasRawTextSupport() predicate. By default this aborts.
717 void EmitRawText(const Twine &String);
719 /// Flush - Causes any cached state to be written out.
720 virtual void Flush() {}
722 /// FinishImpl - Streamer specific finalization.
723 virtual void FinishImpl() = 0;
724 /// Finish - Finish emission of machine code.
728 /// createNullStreamer - Create a dummy machine code streamer, which does
729 /// nothing. This is useful for timing the assembler front end.
730 MCStreamer *createNullStreamer(MCContext &Ctx);
732 /// createAsmStreamer - Create a machine code streamer which will print out
733 /// assembly for the native target, suitable for compiling with a native
736 /// \param InstPrint - If given, the instruction printer to use. If not given
737 /// the MCInst representation will be printed. This method takes ownership of
740 /// \param CE - If given, a code emitter to use to show the instruction
741 /// encoding inline with the assembly. This method takes ownership of \p CE.
743 /// \param TAB - If given, a target asm backend to use to show the fixup
744 /// information in conjunction with encoding information. This method takes
745 /// ownership of \p TAB.
747 /// \param ShowInst - Whether to show the MCInst representation inline with
749 MCStreamer *createAsmStreamer(MCContext &Ctx, formatted_raw_ostream &OS,
750 bool isVerboseAsm, bool useCFI,
751 bool useDwarfDirectory, MCInstPrinter *InstPrint,
752 MCCodeEmitter *CE, MCAsmBackend *TAB,
755 /// createMachOStreamer - Create a machine code streamer which will generate
756 /// Mach-O format object files.
758 /// Takes ownership of \p TAB and \p CE.
759 MCStreamer *createMachOStreamer(MCContext &Ctx, MCAsmBackend &TAB,
760 raw_ostream &OS, MCCodeEmitter *CE,
761 bool RelaxAll = false,
762 bool LabelSections = false);
764 /// createWinCOFFStreamer - Create a machine code streamer which will
765 /// generate Microsoft COFF format object files.
767 /// Takes ownership of \p TAB and \p CE.
768 MCStreamer *createWinCOFFStreamer(MCContext &Ctx, MCAsmBackend &TAB,
769 MCCodeEmitter &CE, raw_ostream &OS,
770 bool RelaxAll = false);
772 /// createELFStreamer - Create a machine code streamer which will generate
773 /// ELF format object files.
774 MCStreamer *createELFStreamer(MCContext &Ctx, MCAsmBackend &TAB,
775 raw_ostream &OS, MCCodeEmitter *CE, bool RelaxAll,
778 } // end namespace llvm