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 MCSubtargetInfo;
40 class formatted_raw_ostream;
42 typedef std::pair<const MCSection *, const MCExpr *> MCSectionSubPair;
44 /// Target specific streamer interface. This is used so that targets can
45 /// implement support for target specific assembly directives.
47 /// If target foo wants to use this, it should implement 3 classes:
48 /// * FooTargetStreamer : public MCTargetStreamer
49 /// * FooTargetAsmSreamer : public FooTargetStreamer
50 /// * FooTargetELFStreamer : public FooTargetStreamer
52 /// FooTargetStreamer should have a pure virtual method for each directive. For
53 /// example, for a ".bar symbol_name" directive, it should have
54 /// virtual emitBar(const MCSymbol &Symbol) = 0;
56 /// The FooTargetAsmSreamer and FooTargetELFStreamer classes implement the
57 /// method. The assembly streamer just prints ".bar symbol_name". The object
58 /// streamer does whatever is needed to implement .bar in the object file.
60 /// In the assembly printer and parser the target streamer can be used by
61 /// calling getTargetStreamer and casting it to FooTargetStreamer:
63 /// MCTargetStreamer &TS = OutStreamer.getTargetStreamer();
64 /// FooTargetStreamer &ATS = static_cast<FooTargetStreamer &>(TS);
66 /// The base classes FooTargetAsmSreamer and FooTargetELFStreamer should *never*
67 /// be treated differently. Callers should always talk to a FooTargetStreamer.
68 class MCTargetStreamer {
73 virtual ~MCTargetStreamer();
74 void setStreamer(MCStreamer *S) { Streamer = S; }
76 // Allow a target to add behavior to the EmitLabel of MCStreamer.
77 virtual void emitLabel(MCSymbol *Symbol);
79 /// Let the target do anything it needs to do after emitting inlineasm.
80 /// This callback can be used restore the original mode in case the
81 /// inlineasm contains directives to switch modes.
82 /// \p StartInfo - the original subtarget info before inline asm
83 /// \p EndInfo - the final subtarget info after parsing the inline asm,
84 // or NULL if the value is unknown.
85 virtual void emitInlineAsmEnd(const MCSubtargetInfo &StartInfo,
86 MCSubtargetInfo *EndInfo) {}
89 // FIXME: declared here because it is used from
90 // lib/CodeGen/AsmPrinter/ARMException.cpp.
91 class ARMTargetStreamer : public MCTargetStreamer {
92 virtual void anchor();
94 virtual void emitFnStart() = 0;
95 virtual void emitFnEnd() = 0;
96 virtual void emitCantUnwind() = 0;
97 virtual void emitPersonality(const MCSymbol *Personality) = 0;
98 virtual void emitPersonalityIndex(unsigned Index) = 0;
99 virtual void emitHandlerData() = 0;
100 virtual void emitSetFP(unsigned FpReg, unsigned SpReg,
101 int64_t Offset = 0) = 0;
102 virtual void emitPad(int64_t Offset) = 0;
103 virtual void emitRegSave(const SmallVectorImpl<unsigned> &RegList,
105 virtual void emitUnwindRaw(int64_t StackOffset,
106 const SmallVectorImpl<uint8_t> &Opcodes) = 0;
108 virtual void switchVendor(StringRef Vendor) = 0;
109 virtual void emitAttribute(unsigned Attribute, unsigned Value) = 0;
110 virtual void emitTextAttribute(unsigned Attribute, StringRef String) = 0;
111 virtual void emitIntTextAttribute(unsigned Attribute, unsigned IntValue,
112 StringRef StringValue = "") = 0;
113 virtual void emitFPU(unsigned FPU) = 0;
114 virtual void emitArch(unsigned Arch) = 0;
115 virtual void finishAttributeSection() = 0;
116 virtual void emitInst(uint32_t Inst, char Suffix = '\0') = 0;
117 virtual void emitInlineAsmEnd(const MCSubtargetInfo &StartInfo,
118 MCSubtargetInfo *EndInfo);
121 /// MCStreamer - Streaming machine code generation interface. This interface
122 /// is intended to provide a programatic interface that is very similar to the
123 /// level that an assembler .s file provides. It has callbacks to emit bytes,
124 /// handle directives, etc. The implementation of this interface retains
125 /// state to know what the current section is etc.
127 /// There are multiple implementations of this interface: one for writing out
128 /// a .s file, and implementations that write out .o files of various formats.
132 OwningPtr<MCTargetStreamer> TargetStreamer;
134 MCStreamer(const MCStreamer &) LLVM_DELETED_FUNCTION;
135 MCStreamer &operator=(const MCStreamer &) LLVM_DELETED_FUNCTION;
140 std::vector<MCDwarfFrameInfo> FrameInfos;
141 MCDwarfFrameInfo *getCurrentFrameInfo();
142 MCSymbol *EmitCFICommon();
143 void EnsureValidFrame();
145 std::vector<MCWin64EHUnwindInfo *> W64UnwindInfos;
146 MCWin64EHUnwindInfo *CurrentW64UnwindInfo;
147 void setCurrentW64UnwindInfo(MCWin64EHUnwindInfo *Frame);
148 void EnsureValidW64UnwindInfo();
150 MCSymbol *LastSymbol;
152 // SymbolOrdering - Tracks an index to represent the order
153 // a symbol was emitted in. Zero means we did not emit that symbol.
154 DenseMap<const MCSymbol *, unsigned> SymbolOrdering;
156 /// SectionStack - This is stack of current and previous section
157 /// values saved by PushSection.
158 SmallVector<std::pair<MCSectionSubPair, MCSectionSubPair>, 4> SectionStack;
161 MCStreamer(MCContext &Ctx, MCTargetStreamer *TargetStreamer);
163 const MCExpr *BuildSymbolDiff(MCContext &Context, const MCSymbol *A,
166 const MCExpr *ForceExpAbs(const MCExpr *Expr);
168 void RecordProcStart(MCDwarfFrameInfo &Frame);
169 virtual void EmitCFIStartProcImpl(MCDwarfFrameInfo &Frame);
170 void RecordProcEnd(MCDwarfFrameInfo &Frame);
171 virtual void EmitCFIEndProcImpl(MCDwarfFrameInfo &CurFrame);
172 void EmitFrames(MCAsmBackend *MAB, bool usingCFI);
174 MCWin64EHUnwindInfo *getCurrentW64UnwindInfo() {
175 return CurrentW64UnwindInfo;
177 void EmitW64Tables();
179 virtual void EmitRawTextImpl(StringRef String);
182 virtual ~MCStreamer();
186 virtual void reset();
188 MCContext &getContext() const { return Context; }
190 MCTargetStreamer *getTargetStreamer() {
191 return TargetStreamer.get();
194 unsigned getNumFrameInfos() { return FrameInfos.size(); }
196 const MCDwarfFrameInfo &getFrameInfo(unsigned i) { return FrameInfos[i]; }
198 ArrayRef<MCDwarfFrameInfo> getFrameInfos() const { return FrameInfos; }
200 unsigned getNumW64UnwindInfos() { return W64UnwindInfos.size(); }
202 MCWin64EHUnwindInfo &getW64UnwindInfo(unsigned i) {
203 return *W64UnwindInfos[i];
206 void generateCompactUnwindEncodings(MCAsmBackend *MAB);
208 /// @name Assembly File Formatting.
211 /// isVerboseAsm - Return true if this streamer supports verbose assembly
212 /// and if it is enabled.
213 virtual bool isVerboseAsm() const { return false; }
215 /// hasRawTextSupport - Return true if this asm streamer supports emitting
216 /// unformatted text to the .s file with EmitRawText.
217 virtual bool hasRawTextSupport() const { return false; }
219 /// AddComment - Add a comment that can be emitted to the generated .s
220 /// file if applicable as a QoI issue to make the output of the compiler
221 /// more readable. This only affects the MCAsmStreamer, and only when
222 /// verbose assembly output is enabled.
224 /// If the comment includes embedded \n's, they will each get the comment
225 /// prefix as appropriate. The added comment should not end with a \n.
226 virtual void AddComment(const Twine &T) {}
228 /// GetCommentOS - Return a raw_ostream that comments can be written to.
229 /// Unlike AddComment, you are required to terminate comments with \n if you
231 virtual raw_ostream &GetCommentOS();
233 /// Print T and prefix it with the comment string (normally #) and optionally
234 /// a tab. This prints the comment immediately, not at the end of the
235 /// current line. It is basically a safe version of EmitRawText: since it
236 /// only prints comments, the object streamer ignores it instead of asserting.
237 virtual void emitRawComment(const Twine &T, bool TabPrefix = true);
239 /// AddBlankLine - Emit a blank line to a .s file to pretty it up.
240 virtual void AddBlankLine() {}
244 /// @name Symbol & Section Management
247 /// getCurrentSection - Return the current section that the streamer is
248 /// emitting code to.
249 MCSectionSubPair getCurrentSection() const {
250 if (!SectionStack.empty())
251 return SectionStack.back().first;
252 return MCSectionSubPair();
255 /// getPreviousSection - Return the previous section that the streamer is
256 /// emitting code to.
257 MCSectionSubPair getPreviousSection() const {
258 if (!SectionStack.empty())
259 return SectionStack.back().second;
260 return MCSectionSubPair();
263 /// GetSymbolOrder - Returns an index to represent the order
264 /// a symbol was emitted in. (zero if we did not emit that symbol)
265 unsigned GetSymbolOrder(const MCSymbol *Sym) const {
266 return SymbolOrdering.lookup(Sym);
269 /// ChangeSection - Update streamer for a new active section.
271 /// This is called by PopSection and SwitchSection, if the current
273 virtual void ChangeSection(const MCSection *, const MCExpr *) = 0;
275 /// pushSection - Save the current and previous section on the
278 SectionStack.push_back(
279 std::make_pair(getCurrentSection(), getPreviousSection()));
282 /// popSection - Restore the current and previous section from
283 /// the section stack. Calls ChangeSection as needed.
285 /// Returns false if the stack was empty.
287 if (SectionStack.size() <= 1)
289 MCSectionSubPair oldSection = SectionStack.pop_back_val().first;
290 MCSectionSubPair curSection = SectionStack.back().first;
292 if (oldSection != curSection)
293 ChangeSection(curSection.first, curSection.second);
297 bool SubSection(const MCExpr *Subsection) {
298 if (SectionStack.empty())
301 SwitchSection(SectionStack.back().first.first, Subsection);
305 /// SwitchSection - Set the current section where code is being emitted to
306 /// @p Section. This is required to update CurSection.
308 /// This corresponds to assembler directives like .section, .text, etc.
309 void SwitchSection(const MCSection *Section, const MCExpr *Subsection = 0) {
310 assert(Section && "Cannot switch to a null section!");
311 MCSectionSubPair curSection = SectionStack.back().first;
312 SectionStack.back().second = curSection;
313 if (MCSectionSubPair(Section, Subsection) != curSection) {
314 SectionStack.back().first = MCSectionSubPair(Section, Subsection);
315 ChangeSection(Section, Subsection);
319 /// SwitchSectionNoChange - Set the current section where code is being
320 /// emitted to @p Section. This is required to update CurSection. This
321 /// version does not call ChangeSection.
322 void SwitchSectionNoChange(const MCSection *Section,
323 const MCExpr *Subsection = 0) {
324 assert(Section && "Cannot switch to a null section!");
325 MCSectionSubPair curSection = SectionStack.back().first;
326 SectionStack.back().second = curSection;
327 if (MCSectionSubPair(Section, Subsection) != curSection)
328 SectionStack.back().first = MCSectionSubPair(Section, Subsection);
331 /// Create the default sections and set the initial one.
333 /// @param Force - If false, a text streamer implementation can be a nop.
334 /// Used by CodeGen to avoid starting every file with '.text'.
335 virtual void InitSections(bool Force = true);
337 /// AssignSection - Sets the symbol's section.
339 /// Each emitted symbol will be tracked in the ordering table,
340 /// so we can sort on them later.
341 void AssignSection(MCSymbol *Symbol, const MCSection *Section);
343 /// EmitLabel - Emit a label for @p Symbol into the current section.
345 /// This corresponds to an assembler statement such as:
348 /// @param Symbol - The symbol to emit. A given symbol should only be
349 /// emitted as a label once, and symbols emitted as a label should never be
350 /// used in an assignment.
351 // FIXME: These emission are non-const because we mutate the symbol to
352 // add the section we're emitting it to later.
353 virtual void EmitLabel(MCSymbol *Symbol);
355 virtual void EmitDebugLabel(MCSymbol *Symbol);
357 virtual void EmitEHSymAttributes(const MCSymbol *Symbol, MCSymbol *EHSymbol);
359 /// EmitAssemblerFlag - Note in the output the specified @p Flag.
360 virtual void EmitAssemblerFlag(MCAssemblerFlag Flag) = 0;
362 /// EmitLinkerOptions - Emit the given list @p Options of strings as linker
363 /// options into the output.
364 virtual void EmitLinkerOptions(ArrayRef<std::string> Kind) {}
366 /// EmitDataRegion - Note in the output the specified region @p Kind.
367 virtual void EmitDataRegion(MCDataRegionType Kind) {}
369 /// EmitThumbFunc - Note in the output that the specified @p Func is
370 /// a Thumb mode function (ARM target only).
371 virtual void EmitThumbFunc(MCSymbol *Func) = 0;
373 /// getOrCreateSymbolData - Get symbol data for given symbol.
374 virtual MCSymbolData &getOrCreateSymbolData(MCSymbol *Symbol);
376 /// EmitAssignment - Emit an assignment of @p Value to @p Symbol.
378 /// This corresponds to an assembler statement such as:
381 /// The assignment generates no code, but has the side effect of binding the
382 /// value in the current context. For the assembly streamer, this prints the
383 /// binding into the .s file.
385 /// @param Symbol - The symbol being assigned to.
386 /// @param Value - The value for the symbol.
387 virtual void EmitAssignment(MCSymbol *Symbol, const MCExpr *Value) = 0;
389 /// EmitWeakReference - Emit an weak reference from @p Alias to @p Symbol.
391 /// This corresponds to an assembler statement such as:
392 /// .weakref alias, symbol
394 /// @param Alias - The alias that is being created.
395 /// @param Symbol - The symbol being aliased.
396 virtual void EmitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol) = 0;
398 /// EmitSymbolAttribute - Add the given @p Attribute to @p Symbol.
399 virtual bool EmitSymbolAttribute(MCSymbol *Symbol,
400 MCSymbolAttr Attribute) = 0;
402 /// EmitSymbolDesc - Set the @p DescValue for the @p Symbol.
404 /// @param Symbol - The symbol to have its n_desc field set.
405 /// @param DescValue - The value to set into the n_desc field.
406 virtual void EmitSymbolDesc(MCSymbol *Symbol, unsigned DescValue) = 0;
408 /// BeginCOFFSymbolDef - Start emitting COFF symbol definition
410 /// @param Symbol - The symbol to have its External & Type fields set.
411 virtual void BeginCOFFSymbolDef(const MCSymbol *Symbol) = 0;
413 /// EmitCOFFSymbolStorageClass - Emit the storage class of the symbol.
415 /// @param StorageClass - The storage class the symbol should have.
416 virtual void EmitCOFFSymbolStorageClass(int StorageClass) = 0;
418 /// EmitCOFFSymbolType - Emit the type of the symbol.
420 /// @param Type - A COFF type identifier (see COFF::SymbolType in X86COFF.h)
421 virtual void EmitCOFFSymbolType(int Type) = 0;
423 /// EndCOFFSymbolDef - Marks the end of the symbol definition.
424 virtual void EndCOFFSymbolDef() = 0;
426 /// EmitCOFFSectionIndex - Emits a COFF section index.
428 /// @param Symbol - Symbol the section number relocation should point to.
429 virtual void EmitCOFFSectionIndex(MCSymbol const *Symbol);
431 /// EmitCOFFSecRel32 - Emits a COFF section relative relocation.
433 /// @param Symbol - Symbol the section relative relocation should point to.
434 virtual void EmitCOFFSecRel32(MCSymbol const *Symbol);
436 /// EmitELFSize - Emit an ELF .size directive.
438 /// This corresponds to an assembler statement such as:
439 /// .size symbol, expression
441 virtual void EmitELFSize(MCSymbol *Symbol, const MCExpr *Value) = 0;
443 /// EmitCommonSymbol - Emit a common symbol.
445 /// @param Symbol - The common symbol to emit.
446 /// @param Size - The size of the common symbol.
447 /// @param ByteAlignment - The alignment of the symbol if
448 /// non-zero. This must be a power of 2.
449 virtual void EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
450 unsigned ByteAlignment) = 0;
452 /// EmitLocalCommonSymbol - Emit a local common (.lcomm) symbol.
454 /// @param Symbol - The common symbol to emit.
455 /// @param Size - The size of the common symbol.
456 /// @param ByteAlignment - The alignment of the common symbol in bytes.
457 virtual void EmitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size,
458 unsigned ByteAlignment) = 0;
460 /// EmitZerofill - Emit the zerofill section and an optional symbol.
462 /// @param Section - The zerofill section to create and or to put the symbol
463 /// @param Symbol - The zerofill symbol to emit, if non-NULL.
464 /// @param Size - The size of the zerofill symbol.
465 /// @param ByteAlignment - The alignment of the zerofill symbol if
466 /// non-zero. This must be a power of 2 on some targets.
467 virtual void EmitZerofill(const MCSection *Section, MCSymbol *Symbol = 0,
468 uint64_t Size = 0, unsigned ByteAlignment = 0) = 0;
470 /// EmitTBSSSymbol - Emit a thread local bss (.tbss) symbol.
472 /// @param Section - The thread local common section.
473 /// @param Symbol - The thread local common symbol to emit.
474 /// @param Size - The size of the symbol.
475 /// @param ByteAlignment - The alignment of the thread local common symbol
476 /// if non-zero. This must be a power of 2 on some targets.
477 virtual void EmitTBSSSymbol(const MCSection *Section, MCSymbol *Symbol,
478 uint64_t Size, unsigned ByteAlignment = 0) = 0;
481 /// @name Generating Data
484 /// EmitBytes - Emit the bytes in \p Data into the output.
486 /// This is used to implement assembler directives such as .byte, .ascii,
488 virtual void EmitBytes(StringRef Data) = 0;
490 /// EmitValue - Emit the expression @p Value into the output as a native
491 /// integer of the given @p Size bytes.
493 /// This is used to implement assembler directives such as .word, .quad,
496 /// @param Value - The value to emit.
497 /// @param Size - The size of the integer (in bytes) to emit. This must
498 /// match a native machine width.
499 virtual void EmitValueImpl(const MCExpr *Value, unsigned Size) = 0;
501 void EmitValue(const MCExpr *Value, unsigned Size);
503 /// EmitIntValue - Special case of EmitValue that avoids the client having
504 /// to pass in a MCExpr for constant integers.
505 virtual void EmitIntValue(uint64_t Value, unsigned Size);
507 /// EmitAbsValue - Emit the Value, but try to avoid relocations. On MachO
508 /// this is done by producing
511 void EmitAbsValue(const MCExpr *Value, unsigned Size);
513 virtual void EmitULEB128Value(const MCExpr *Value) = 0;
515 virtual void EmitSLEB128Value(const MCExpr *Value) = 0;
517 /// EmitULEB128Value - Special case of EmitULEB128Value that avoids the
518 /// client having to pass in a MCExpr for constant integers.
519 void EmitULEB128IntValue(uint64_t Value, unsigned Padding = 0);
521 /// EmitSLEB128Value - Special case of EmitSLEB128Value that avoids the
522 /// client having to pass in a MCExpr for constant integers.
523 void EmitSLEB128IntValue(int64_t Value);
525 /// EmitSymbolValue - Special case of EmitValue that avoids the client
526 /// having to pass in a MCExpr for MCSymbols.
527 void EmitSymbolValue(const MCSymbol *Sym, unsigned Size);
529 /// EmitGPRel64Value - Emit the expression @p Value into the output as a
530 /// gprel64 (64-bit GP relative) value.
532 /// This is used to implement assembler directives such as .gpdword on
533 /// targets that support them.
534 virtual void EmitGPRel64Value(const MCExpr *Value);
536 /// EmitGPRel32Value - Emit the expression @p Value into the output as a
537 /// gprel32 (32-bit GP relative) value.
539 /// This is used to implement assembler directives such as .gprel32 on
540 /// targets that support them.
541 virtual void EmitGPRel32Value(const MCExpr *Value);
543 /// EmitFill - Emit NumBytes bytes worth of the value specified by
544 /// FillValue. This implements directives such as '.space'.
545 virtual void EmitFill(uint64_t NumBytes, uint8_t FillValue);
547 /// \brief Emit NumBytes worth of zeros.
548 /// This function properly handles data in virtual sections.
549 virtual void EmitZeros(uint64_t NumBytes);
551 /// EmitValueToAlignment - Emit some number of copies of @p Value until
552 /// the byte alignment @p ByteAlignment is reached.
554 /// If the number of bytes need to emit for the alignment is not a multiple
555 /// of @p ValueSize, then the contents of the emitted fill bytes is
558 /// This used to implement the .align assembler directive.
560 /// @param ByteAlignment - The alignment to reach. This must be a power of
561 /// two on some targets.
562 /// @param Value - The value to use when filling bytes.
563 /// @param ValueSize - The size of the integer (in bytes) to emit for
564 /// @p Value. This must match a native machine width.
565 /// @param MaxBytesToEmit - The maximum numbers of bytes to emit, or 0. If
566 /// the alignment cannot be reached in this many bytes, no bytes are
568 virtual void EmitValueToAlignment(unsigned ByteAlignment, int64_t Value = 0,
569 unsigned ValueSize = 1,
570 unsigned MaxBytesToEmit = 0) = 0;
572 /// EmitCodeAlignment - Emit nops until the byte alignment @p ByteAlignment
575 /// This used to align code where the alignment bytes may be executed. This
576 /// can emit different bytes for different sizes to optimize execution.
578 /// @param ByteAlignment - The alignment to reach. This must be a power of
579 /// two on some targets.
580 /// @param MaxBytesToEmit - The maximum numbers of bytes to emit, or 0. If
581 /// the alignment cannot be reached in this many bytes, no bytes are
583 virtual void EmitCodeAlignment(unsigned ByteAlignment,
584 unsigned MaxBytesToEmit = 0) = 0;
586 /// EmitValueToOffset - Emit some number of copies of @p Value until the
587 /// byte offset @p Offset is reached.
589 /// This is used to implement assembler directives such as .org.
591 /// @param Offset - The offset to reach. This may be an expression, but the
592 /// expression must be associated with the current section.
593 /// @param Value - The value to use when filling bytes.
594 /// @return false on success, true if the offset was invalid.
595 virtual bool EmitValueToOffset(const MCExpr *Offset,
596 unsigned char Value = 0) = 0;
600 /// EmitFileDirective - Switch to a new logical file. This is used to
601 /// implement the '.file "foo.c"' assembler directive.
602 virtual void EmitFileDirective(StringRef Filename) = 0;
604 /// Emit the "identifiers" directive. This implements the
605 /// '.ident "version foo"' assembler directive.
606 virtual void EmitIdent(StringRef IdentString) {}
608 /// EmitDwarfFileDirective - Associate a filename with a specified logical
609 /// file number. This implements the DWARF2 '.file 4 "foo.c"' assembler
611 virtual bool EmitDwarfFileDirective(unsigned FileNo, StringRef Directory,
612 StringRef Filename, unsigned CUID = 0);
614 /// EmitDwarfLocDirective - This implements the DWARF2
615 // '.loc fileno lineno ...' assembler directive.
616 virtual void EmitDwarfLocDirective(unsigned FileNo, unsigned Line,
617 unsigned Column, unsigned Flags,
618 unsigned Isa, unsigned Discriminator,
621 virtual void EmitDwarfAdvanceLineAddr(int64_t LineDelta,
622 const MCSymbol *LastLabel,
623 const MCSymbol *Label,
624 unsigned PointerSize) = 0;
626 virtual void EmitDwarfAdvanceFrameAddr(const MCSymbol *LastLabel,
627 const MCSymbol *Label) {}
629 void EmitDwarfSetLineAddr(int64_t LineDelta, const MCSymbol *Label,
632 virtual void EmitCompactUnwindEncoding(uint32_t CompactUnwindEncoding);
633 virtual void EmitCFISections(bool EH, bool Debug);
634 void EmitCFIStartProc();
635 void EmitCFIEndProc();
636 virtual void EmitCFIDefCfa(int64_t Register, int64_t Offset);
637 virtual void EmitCFIDefCfaOffset(int64_t Offset);
638 virtual void EmitCFIDefCfaRegister(int64_t Register);
639 virtual void EmitCFIOffset(int64_t Register, int64_t Offset);
640 virtual void EmitCFIPersonality(const MCSymbol *Sym, unsigned Encoding);
641 virtual void EmitCFILsda(const MCSymbol *Sym, unsigned Encoding);
642 virtual void EmitCFIRememberState();
643 virtual void EmitCFIRestoreState();
644 virtual void EmitCFISameValue(int64_t Register);
645 virtual void EmitCFIRestore(int64_t Register);
646 virtual void EmitCFIRelOffset(int64_t Register, int64_t Offset);
647 virtual void EmitCFIAdjustCfaOffset(int64_t Adjustment);
648 virtual void EmitCFIEscape(StringRef Values);
649 virtual void EmitCFISignalFrame();
650 virtual void EmitCFIUndefined(int64_t Register);
651 virtual void EmitCFIRegister(int64_t Register1, int64_t Register2);
652 virtual void EmitCFIWindowSave();
654 virtual void EmitWin64EHStartProc(const MCSymbol *Symbol);
655 virtual void EmitWin64EHEndProc();
656 virtual void EmitWin64EHStartChained();
657 virtual void EmitWin64EHEndChained();
658 virtual void EmitWin64EHHandler(const MCSymbol *Sym, bool Unwind,
660 virtual void EmitWin64EHHandlerData();
661 virtual void EmitWin64EHPushReg(unsigned Register);
662 virtual void EmitWin64EHSetFrame(unsigned Register, unsigned Offset);
663 virtual void EmitWin64EHAllocStack(unsigned Size);
664 virtual void EmitWin64EHSaveReg(unsigned Register, unsigned Offset);
665 virtual void EmitWin64EHSaveXMM(unsigned Register, unsigned Offset);
666 virtual void EmitWin64EHPushFrame(bool Code);
667 virtual void EmitWin64EHEndProlog();
669 /// EmitInstruction - Emit the given @p Instruction into the current
671 virtual void EmitInstruction(const MCInst &Inst) = 0;
673 /// \brief Set the bundle alignment mode from now on in the section.
674 /// The argument is the power of 2 to which the alignment is set. The
675 /// value 0 means turn the bundle alignment off.
676 virtual void EmitBundleAlignMode(unsigned AlignPow2) = 0;
678 /// \brief The following instructions are a bundle-locked group.
680 /// \param AlignToEnd - If true, the bundle-locked group will be aligned to
681 /// the end of a bundle.
682 virtual void EmitBundleLock(bool AlignToEnd) = 0;
684 /// \brief Ends a bundle-locked group.
685 virtual void EmitBundleUnlock() = 0;
687 /// EmitRawText - If this file is backed by a assembly streamer, this dumps
688 /// the specified string in the output .s file. This capability is
689 /// indicated by the hasRawTextSupport() predicate. By default this aborts.
690 void EmitRawText(const Twine &String);
692 /// EmitInlineAsmEnd - Used to perform any cleanup needed after emitting
693 /// inline assembly. Provides the start and end subtarget info values.
694 /// The end subtarget info may be NULL if it is not know, for example, when
695 /// emitting the inline assembly as raw text.
696 virtual void EmitInlineAsmEnd(const MCSubtargetInfo &StartInfo,
697 MCSubtargetInfo *EndInfo) {
699 TargetStreamer->emitInlineAsmEnd(StartInfo, EndInfo);
702 /// Flush - Causes any cached state to be written out.
703 virtual void Flush() {}
705 /// FinishImpl - Streamer specific finalization.
706 virtual void FinishImpl() = 0;
707 /// Finish - Finish emission of machine code.
711 /// createNullStreamer - Create a dummy machine code streamer, which does
712 /// nothing. This is useful for timing the assembler front end.
713 MCStreamer *createNullStreamer(MCContext &Ctx);
715 /// createAsmStreamer - Create a machine code streamer which will print out
716 /// assembly for the native target, suitable for compiling with a native
719 /// \param InstPrint - If given, the instruction printer to use. If not given
720 /// the MCInst representation will be printed. This method takes ownership of
723 /// \param CE - If given, a code emitter to use to show the instruction
724 /// encoding inline with the assembly. This method takes ownership of \p CE.
726 /// \param TAB - If given, a target asm backend to use to show the fixup
727 /// information in conjunction with encoding information. This method takes
728 /// ownership of \p TAB.
730 /// \param ShowInst - Whether to show the MCInst representation inline with
732 MCStreamer *createAsmStreamer(MCContext &Ctx, MCTargetStreamer *TargetStreamer,
733 formatted_raw_ostream &OS, bool isVerboseAsm,
734 bool useLoc, bool useCFI, bool useDwarfDirectory,
735 MCInstPrinter *InstPrint = 0,
736 MCCodeEmitter *CE = 0, MCAsmBackend *TAB = 0,
737 bool ShowInst = false);
739 /// createMachOStreamer - Create a machine code streamer which will generate
740 /// Mach-O format object files.
742 /// Takes ownership of \p TAB and \p CE.
743 MCStreamer *createMachOStreamer(MCContext &Ctx, MCAsmBackend &TAB,
744 raw_ostream &OS, MCCodeEmitter *CE,
745 bool RelaxAll = false);
747 /// createWinCOFFStreamer - Create a machine code streamer which will
748 /// generate Microsoft COFF format object files.
750 /// Takes ownership of \p TAB and \p CE.
751 MCStreamer *createWinCOFFStreamer(MCContext &Ctx, MCAsmBackend &TAB,
752 MCCodeEmitter &CE, raw_ostream &OS,
753 bool RelaxAll = false);
755 /// createELFStreamer - Create a machine code streamer which will generate
756 /// ELF format object files.
757 MCStreamer *createELFStreamer(MCContext &Ctx, MCTargetStreamer *TargetStreamer,
758 MCAsmBackend &TAB, raw_ostream &OS,
759 MCCodeEmitter *CE, bool RelaxAll,
762 /// createPureStreamer - Create a machine code streamer which will generate
763 /// "pure" MC object files, for use with MC-JIT and testing tools.
765 /// Takes ownership of \p TAB and \p CE.
766 MCStreamer *createPureStreamer(MCContext &Ctx, MCAsmBackend &TAB,
767 raw_ostream &OS, MCCodeEmitter *CE);
769 } // end namespace llvm