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;
160 bool AutoInitSections;
163 MCStreamer(MCContext &Ctx, MCTargetStreamer *TargetStreamer);
165 const MCExpr *BuildSymbolDiff(MCContext &Context, const MCSymbol *A,
168 const MCExpr *ForceExpAbs(const MCExpr *Expr);
170 void RecordProcStart(MCDwarfFrameInfo &Frame);
171 virtual void EmitCFIStartProcImpl(MCDwarfFrameInfo &Frame);
172 void RecordProcEnd(MCDwarfFrameInfo &Frame);
173 virtual void EmitCFIEndProcImpl(MCDwarfFrameInfo &CurFrame);
174 void EmitFrames(MCAsmBackend *MAB, bool usingCFI);
176 MCWin64EHUnwindInfo *getCurrentW64UnwindInfo() {
177 return CurrentW64UnwindInfo;
179 void EmitW64Tables();
181 virtual void EmitRawTextImpl(StringRef String);
184 virtual ~MCStreamer();
188 virtual void reset();
190 MCContext &getContext() const { return Context; }
192 MCTargetStreamer *getTargetStreamer() {
193 return TargetStreamer.get();
196 unsigned getNumFrameInfos() { return FrameInfos.size(); }
198 const MCDwarfFrameInfo &getFrameInfo(unsigned i) { return FrameInfos[i]; }
200 ArrayRef<MCDwarfFrameInfo> getFrameInfos() const { return FrameInfos; }
202 unsigned getNumW64UnwindInfos() { return W64UnwindInfos.size(); }
204 MCWin64EHUnwindInfo &getW64UnwindInfo(unsigned i) {
205 return *W64UnwindInfos[i];
208 void generateCompactUnwindEncodings(MCAsmBackend *MAB);
210 /// @name Assembly File Formatting.
213 /// isVerboseAsm - Return true if this streamer supports verbose assembly
214 /// and if it is enabled.
215 virtual bool isVerboseAsm() const { return false; }
217 /// hasRawTextSupport - Return true if this asm streamer supports emitting
218 /// unformatted text to the .s file with EmitRawText.
219 virtual bool hasRawTextSupport() const { return false; }
221 /// AddComment - Add a comment that can be emitted to the generated .s
222 /// file if applicable as a QoI issue to make the output of the compiler
223 /// more readable. This only affects the MCAsmStreamer, and only when
224 /// verbose assembly output is enabled.
226 /// If the comment includes embedded \n's, they will each get the comment
227 /// prefix as appropriate. The added comment should not end with a \n.
228 virtual void AddComment(const Twine &T) {}
230 /// GetCommentOS - Return a raw_ostream that comments can be written to.
231 /// Unlike AddComment, you are required to terminate comments with \n if you
233 virtual raw_ostream &GetCommentOS();
235 /// Print T and prefix it with the comment string (normally #) and optionally
236 /// a tab. This prints the comment immediately, not at the end of the
237 /// current line. It is basically a safe version of EmitRawText: since it
238 /// only prints comments, the object streamer ignores it instead of asserting.
239 virtual void emitRawComment(const Twine &T, bool TabPrefix = true);
241 /// AddBlankLine - Emit a blank line to a .s file to pretty it up.
242 virtual void AddBlankLine() {}
246 /// @name Symbol & Section Management
249 /// getCurrentSection - Return the current section that the streamer is
250 /// emitting code to.
251 MCSectionSubPair getCurrentSection() const {
252 if (!SectionStack.empty())
253 return SectionStack.back().first;
254 return MCSectionSubPair();
257 /// getPreviousSection - Return the previous section that the streamer is
258 /// emitting code to.
259 MCSectionSubPair getPreviousSection() const {
260 if (!SectionStack.empty())
261 return SectionStack.back().second;
262 return MCSectionSubPair();
265 /// GetSymbolOrder - Returns an index to represent the order
266 /// a symbol was emitted in. (zero if we did not emit that symbol)
267 unsigned GetSymbolOrder(const MCSymbol *Sym) const {
268 return SymbolOrdering.lookup(Sym);
271 /// ChangeSection - Update streamer for a new active section.
273 /// This is called by PopSection and SwitchSection, if the current
275 virtual void ChangeSection(const MCSection *, const MCExpr *) = 0;
277 /// pushSection - Save the current and previous section on the
280 SectionStack.push_back(
281 std::make_pair(getCurrentSection(), getPreviousSection()));
284 /// popSection - Restore the current and previous section from
285 /// the section stack. Calls ChangeSection as needed.
287 /// Returns false if the stack was empty.
289 if (SectionStack.size() <= 1)
291 MCSectionSubPair oldSection = SectionStack.pop_back_val().first;
292 MCSectionSubPair curSection = SectionStack.back().first;
294 if (oldSection != curSection)
295 ChangeSection(curSection.first, curSection.second);
299 bool SubSection(const MCExpr *Subsection) {
300 if (SectionStack.empty())
303 SwitchSection(SectionStack.back().first.first, Subsection);
307 /// SwitchSection - Set the current section where code is being emitted to
308 /// @p Section. This is required to update CurSection.
310 /// This corresponds to assembler directives like .section, .text, etc.
311 void SwitchSection(const MCSection *Section, const MCExpr *Subsection = 0) {
312 assert(Section && "Cannot switch to a null section!");
313 MCSectionSubPair curSection = SectionStack.back().first;
314 SectionStack.back().second = curSection;
315 if (MCSectionSubPair(Section, Subsection) != curSection) {
316 SectionStack.back().first = MCSectionSubPair(Section, Subsection);
317 ChangeSection(Section, Subsection);
321 /// SwitchSectionNoChange - Set the current section where code is being
322 /// emitted to @p Section. This is required to update CurSection. This
323 /// version does not call ChangeSection.
324 void SwitchSectionNoChange(const MCSection *Section,
325 const MCExpr *Subsection = 0) {
326 assert(Section && "Cannot switch to a null section!");
327 MCSectionSubPair curSection = SectionStack.back().first;
328 SectionStack.back().second = curSection;
329 if (MCSectionSubPair(Section, Subsection) != curSection)
330 SectionStack.back().first = MCSectionSubPair(Section, Subsection);
333 /// Initialize the streamer.
334 void InitStreamer() {
335 if (AutoInitSections)
339 /// Tell this MCStreamer to call InitSections upon initialization.
340 void setAutoInitSections(bool AutoInitSections) {
341 this->AutoInitSections = AutoInitSections;
344 /// InitSections - Create the default sections and set the initial one.
345 virtual void InitSections() = 0;
347 /// AssignSection - Sets the symbol's section.
349 /// Each emitted symbol will be tracked in the ordering table,
350 /// so we can sort on them later.
351 void AssignSection(MCSymbol *Symbol, const MCSection *Section);
353 /// EmitLabel - Emit a label for @p Symbol into the current section.
355 /// This corresponds to an assembler statement such as:
358 /// @param Symbol - The symbol to emit. A given symbol should only be
359 /// emitted as a label once, and symbols emitted as a label should never be
360 /// used in an assignment.
361 // FIXME: These emission are non-const because we mutate the symbol to
362 // add the section we're emitting it to later.
363 virtual void EmitLabel(MCSymbol *Symbol);
365 virtual void EmitDebugLabel(MCSymbol *Symbol);
367 virtual void EmitEHSymAttributes(const MCSymbol *Symbol, MCSymbol *EHSymbol);
369 /// EmitAssemblerFlag - Note in the output the specified @p Flag.
370 virtual void EmitAssemblerFlag(MCAssemblerFlag Flag) = 0;
372 /// EmitLinkerOptions - Emit the given list @p Options of strings as linker
373 /// options into the output.
374 virtual void EmitLinkerOptions(ArrayRef<std::string> Kind) {}
376 /// EmitDataRegion - Note in the output the specified region @p Kind.
377 virtual void EmitDataRegion(MCDataRegionType Kind) {}
379 /// EmitThumbFunc - Note in the output that the specified @p Func is
380 /// a Thumb mode function (ARM target only).
381 virtual void EmitThumbFunc(MCSymbol *Func) = 0;
383 /// getOrCreateSymbolData - Get symbol data for given symbol.
384 virtual MCSymbolData &getOrCreateSymbolData(MCSymbol *Symbol);
386 /// EmitAssignment - Emit an assignment of @p Value to @p Symbol.
388 /// This corresponds to an assembler statement such as:
391 /// The assignment generates no code, but has the side effect of binding the
392 /// value in the current context. For the assembly streamer, this prints the
393 /// binding into the .s file.
395 /// @param Symbol - The symbol being assigned to.
396 /// @param Value - The value for the symbol.
397 virtual void EmitAssignment(MCSymbol *Symbol, const MCExpr *Value) = 0;
399 /// EmitWeakReference - Emit an weak reference from @p Alias to @p Symbol.
401 /// This corresponds to an assembler statement such as:
402 /// .weakref alias, symbol
404 /// @param Alias - The alias that is being created.
405 /// @param Symbol - The symbol being aliased.
406 virtual void EmitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol) = 0;
408 /// EmitSymbolAttribute - Add the given @p Attribute to @p Symbol.
409 virtual bool EmitSymbolAttribute(MCSymbol *Symbol,
410 MCSymbolAttr Attribute) = 0;
412 /// EmitSymbolDesc - Set the @p DescValue for the @p Symbol.
414 /// @param Symbol - The symbol to have its n_desc field set.
415 /// @param DescValue - The value to set into the n_desc field.
416 virtual void EmitSymbolDesc(MCSymbol *Symbol, unsigned DescValue) = 0;
418 /// BeginCOFFSymbolDef - Start emitting COFF symbol definition
420 /// @param Symbol - The symbol to have its External & Type fields set.
421 virtual void BeginCOFFSymbolDef(const MCSymbol *Symbol) = 0;
423 /// EmitCOFFSymbolStorageClass - Emit the storage class of the symbol.
425 /// @param StorageClass - The storage class the symbol should have.
426 virtual void EmitCOFFSymbolStorageClass(int StorageClass) = 0;
428 /// EmitCOFFSymbolType - Emit the type of the symbol.
430 /// @param Type - A COFF type identifier (see COFF::SymbolType in X86COFF.h)
431 virtual void EmitCOFFSymbolType(int Type) = 0;
433 /// EndCOFFSymbolDef - Marks the end of the symbol definition.
434 virtual void EndCOFFSymbolDef() = 0;
436 /// EmitCOFFSectionIndex - Emits a COFF section index.
438 /// @param Symbol - Symbol the section number relocation should point to.
439 virtual void EmitCOFFSectionIndex(MCSymbol const *Symbol);
441 /// EmitCOFFSecRel32 - Emits a COFF section relative relocation.
443 /// @param Symbol - Symbol the section relative relocation should point to.
444 virtual void EmitCOFFSecRel32(MCSymbol const *Symbol);
446 /// EmitELFSize - Emit an ELF .size directive.
448 /// This corresponds to an assembler statement such as:
449 /// .size symbol, expression
451 virtual void EmitELFSize(MCSymbol *Symbol, const MCExpr *Value) = 0;
453 /// EmitCommonSymbol - Emit a common symbol.
455 /// @param Symbol - The common symbol to emit.
456 /// @param Size - The size of the common symbol.
457 /// @param ByteAlignment - The alignment of the symbol if
458 /// non-zero. This must be a power of 2.
459 virtual void EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
460 unsigned ByteAlignment) = 0;
462 /// EmitLocalCommonSymbol - Emit a local common (.lcomm) symbol.
464 /// @param Symbol - The common symbol to emit.
465 /// @param Size - The size of the common symbol.
466 /// @param ByteAlignment - The alignment of the common symbol in bytes.
467 virtual void EmitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size,
468 unsigned ByteAlignment) = 0;
470 /// EmitZerofill - Emit the zerofill section and an optional symbol.
472 /// @param Section - The zerofill section to create and or to put the symbol
473 /// @param Symbol - The zerofill symbol to emit, if non-NULL.
474 /// @param Size - The size of the zerofill symbol.
475 /// @param ByteAlignment - The alignment of the zerofill symbol if
476 /// non-zero. This must be a power of 2 on some targets.
477 virtual void EmitZerofill(const MCSection *Section, MCSymbol *Symbol = 0,
478 uint64_t Size = 0, unsigned ByteAlignment = 0) = 0;
480 /// EmitTBSSSymbol - Emit a thread local bss (.tbss) symbol.
482 /// @param Section - The thread local common section.
483 /// @param Symbol - The thread local common symbol to emit.
484 /// @param Size - The size of the symbol.
485 /// @param ByteAlignment - The alignment of the thread local common symbol
486 /// if non-zero. This must be a power of 2 on some targets.
487 virtual void EmitTBSSSymbol(const MCSection *Section, MCSymbol *Symbol,
488 uint64_t Size, unsigned ByteAlignment = 0) = 0;
491 /// @name Generating Data
494 /// EmitBytes - Emit the bytes in \p Data into the output.
496 /// This is used to implement assembler directives such as .byte, .ascii,
498 virtual void EmitBytes(StringRef Data) = 0;
500 /// EmitValue - Emit the expression @p Value into the output as a native
501 /// integer of the given @p Size bytes.
503 /// This is used to implement assembler directives such as .word, .quad,
506 /// @param Value - The value to emit.
507 /// @param Size - The size of the integer (in bytes) to emit. This must
508 /// match a native machine width.
509 virtual void EmitValueImpl(const MCExpr *Value, unsigned Size) = 0;
511 void EmitValue(const MCExpr *Value, unsigned Size);
513 /// EmitIntValue - Special case of EmitValue that avoids the client having
514 /// to pass in a MCExpr for constant integers.
515 virtual void EmitIntValue(uint64_t Value, unsigned Size);
517 /// EmitAbsValue - Emit the Value, but try to avoid relocations. On MachO
518 /// this is done by producing
521 void EmitAbsValue(const MCExpr *Value, unsigned Size);
523 virtual void EmitULEB128Value(const MCExpr *Value) = 0;
525 virtual void EmitSLEB128Value(const MCExpr *Value) = 0;
527 /// EmitULEB128Value - Special case of EmitULEB128Value that avoids the
528 /// client having to pass in a MCExpr for constant integers.
529 void EmitULEB128IntValue(uint64_t Value, unsigned Padding = 0);
531 /// EmitSLEB128Value - Special case of EmitSLEB128Value that avoids the
532 /// client having to pass in a MCExpr for constant integers.
533 void EmitSLEB128IntValue(int64_t Value);
535 /// EmitSymbolValue - Special case of EmitValue that avoids the client
536 /// having to pass in a MCExpr for MCSymbols.
537 void EmitSymbolValue(const MCSymbol *Sym, unsigned Size);
539 /// EmitGPRel64Value - Emit the expression @p Value into the output as a
540 /// gprel64 (64-bit GP relative) value.
542 /// This is used to implement assembler directives such as .gpdword on
543 /// targets that support them.
544 virtual void EmitGPRel64Value(const MCExpr *Value);
546 /// EmitGPRel32Value - Emit the expression @p Value into the output as a
547 /// gprel32 (32-bit GP relative) value.
549 /// This is used to implement assembler directives such as .gprel32 on
550 /// targets that support them.
551 virtual void EmitGPRel32Value(const MCExpr *Value);
553 /// EmitFill - Emit NumBytes bytes worth of the value specified by
554 /// FillValue. This implements directives such as '.space'.
555 virtual void EmitFill(uint64_t NumBytes, uint8_t FillValue);
557 /// \brief Emit NumBytes worth of zeros.
558 /// This function properly handles data in virtual sections.
559 virtual void EmitZeros(uint64_t NumBytes);
561 /// EmitValueToAlignment - Emit some number of copies of @p Value until
562 /// the byte alignment @p ByteAlignment is reached.
564 /// If the number of bytes need to emit for the alignment is not a multiple
565 /// of @p ValueSize, then the contents of the emitted fill bytes is
568 /// This used to implement the .align assembler directive.
570 /// @param ByteAlignment - The alignment to reach. This must be a power of
571 /// two on some targets.
572 /// @param Value - The value to use when filling bytes.
573 /// @param ValueSize - The size of the integer (in bytes) to emit for
574 /// @p Value. This must match a native machine width.
575 /// @param MaxBytesToEmit - The maximum numbers of bytes to emit, or 0. If
576 /// the alignment cannot be reached in this many bytes, no bytes are
578 virtual void EmitValueToAlignment(unsigned ByteAlignment, int64_t Value = 0,
579 unsigned ValueSize = 1,
580 unsigned MaxBytesToEmit = 0) = 0;
582 /// EmitCodeAlignment - Emit nops until the byte alignment @p ByteAlignment
585 /// This used to align code where the alignment bytes may be executed. This
586 /// can emit different bytes for different sizes to optimize execution.
588 /// @param ByteAlignment - The alignment to reach. This must be a power of
589 /// two on some targets.
590 /// @param MaxBytesToEmit - The maximum numbers of bytes to emit, or 0. If
591 /// the alignment cannot be reached in this many bytes, no bytes are
593 virtual void EmitCodeAlignment(unsigned ByteAlignment,
594 unsigned MaxBytesToEmit = 0) = 0;
596 /// EmitValueToOffset - Emit some number of copies of @p Value until the
597 /// byte offset @p Offset is reached.
599 /// This is used to implement assembler directives such as .org.
601 /// @param Offset - The offset to reach. This may be an expression, but the
602 /// expression must be associated with the current section.
603 /// @param Value - The value to use when filling bytes.
604 /// @return false on success, true if the offset was invalid.
605 virtual bool EmitValueToOffset(const MCExpr *Offset,
606 unsigned char Value = 0) = 0;
610 /// EmitFileDirective - Switch to a new logical file. This is used to
611 /// implement the '.file "foo.c"' assembler directive.
612 virtual void EmitFileDirective(StringRef Filename) = 0;
614 /// Emit the "identifiers" directive. This implements the
615 /// '.ident "version foo"' assembler directive.
616 virtual void EmitIdent(StringRef IdentString) {}
618 /// EmitDwarfFileDirective - Associate a filename with a specified logical
619 /// file number. This implements the DWARF2 '.file 4 "foo.c"' assembler
621 virtual bool EmitDwarfFileDirective(unsigned FileNo, StringRef Directory,
622 StringRef Filename, unsigned CUID = 0);
624 /// EmitDwarfLocDirective - This implements the DWARF2
625 // '.loc fileno lineno ...' assembler directive.
626 virtual void EmitDwarfLocDirective(unsigned FileNo, unsigned Line,
627 unsigned Column, unsigned Flags,
628 unsigned Isa, unsigned Discriminator,
631 virtual void EmitDwarfAdvanceLineAddr(int64_t LineDelta,
632 const MCSymbol *LastLabel,
633 const MCSymbol *Label,
634 unsigned PointerSize) = 0;
636 virtual void EmitDwarfAdvanceFrameAddr(const MCSymbol *LastLabel,
637 const MCSymbol *Label) {}
639 void EmitDwarfSetLineAddr(int64_t LineDelta, const MCSymbol *Label,
642 virtual void EmitCompactUnwindEncoding(uint32_t CompactUnwindEncoding);
643 virtual void EmitCFISections(bool EH, bool Debug);
644 void EmitCFIStartProc();
645 void EmitCFIEndProc();
646 virtual void EmitCFIDefCfa(int64_t Register, int64_t Offset);
647 virtual void EmitCFIDefCfaOffset(int64_t Offset);
648 virtual void EmitCFIDefCfaRegister(int64_t Register);
649 virtual void EmitCFIOffset(int64_t Register, int64_t Offset);
650 virtual void EmitCFIPersonality(const MCSymbol *Sym, unsigned Encoding);
651 virtual void EmitCFILsda(const MCSymbol *Sym, unsigned Encoding);
652 virtual void EmitCFIRememberState();
653 virtual void EmitCFIRestoreState();
654 virtual void EmitCFISameValue(int64_t Register);
655 virtual void EmitCFIRestore(int64_t Register);
656 virtual void EmitCFIRelOffset(int64_t Register, int64_t Offset);
657 virtual void EmitCFIAdjustCfaOffset(int64_t Adjustment);
658 virtual void EmitCFIEscape(StringRef Values);
659 virtual void EmitCFISignalFrame();
660 virtual void EmitCFIUndefined(int64_t Register);
661 virtual void EmitCFIRegister(int64_t Register1, int64_t Register2);
662 virtual void EmitCFIWindowSave();
664 virtual void EmitWin64EHStartProc(const MCSymbol *Symbol);
665 virtual void EmitWin64EHEndProc();
666 virtual void EmitWin64EHStartChained();
667 virtual void EmitWin64EHEndChained();
668 virtual void EmitWin64EHHandler(const MCSymbol *Sym, bool Unwind,
670 virtual void EmitWin64EHHandlerData();
671 virtual void EmitWin64EHPushReg(unsigned Register);
672 virtual void EmitWin64EHSetFrame(unsigned Register, unsigned Offset);
673 virtual void EmitWin64EHAllocStack(unsigned Size);
674 virtual void EmitWin64EHSaveReg(unsigned Register, unsigned Offset);
675 virtual void EmitWin64EHSaveXMM(unsigned Register, unsigned Offset);
676 virtual void EmitWin64EHPushFrame(bool Code);
677 virtual void EmitWin64EHEndProlog();
679 /// EmitInstruction - Emit the given @p Instruction into the current
681 virtual void EmitInstruction(const MCInst &Inst) = 0;
683 /// \brief Set the bundle alignment mode from now on in the section.
684 /// The argument is the power of 2 to which the alignment is set. The
685 /// value 0 means turn the bundle alignment off.
686 virtual void EmitBundleAlignMode(unsigned AlignPow2) = 0;
688 /// \brief The following instructions are a bundle-locked group.
690 /// \param AlignToEnd - If true, the bundle-locked group will be aligned to
691 /// the end of a bundle.
692 virtual void EmitBundleLock(bool AlignToEnd) = 0;
694 /// \brief Ends a bundle-locked group.
695 virtual void EmitBundleUnlock() = 0;
697 /// EmitRawText - If this file is backed by a assembly streamer, this dumps
698 /// the specified string in the output .s file. This capability is
699 /// indicated by the hasRawTextSupport() predicate. By default this aborts.
700 void EmitRawText(const Twine &String);
702 /// EmitInlineAsmEnd - Used to perform any cleanup needed after emitting
703 /// inline assembly. Provides the start and end subtarget info values.
704 /// The end subtarget info may be NULL if it is not know, for example, when
705 /// emitting the inline assembly as raw text.
706 virtual void EmitInlineAsmEnd(const MCSubtargetInfo &StartInfo,
707 MCSubtargetInfo *EndInfo) {
709 TargetStreamer->emitInlineAsmEnd(StartInfo, EndInfo);
712 /// Flush - Causes any cached state to be written out.
713 virtual void Flush() {}
715 /// FinishImpl - Streamer specific finalization.
716 virtual void FinishImpl() = 0;
717 /// Finish - Finish emission of machine code.
721 /// createNullStreamer - Create a dummy machine code streamer, which does
722 /// nothing. This is useful for timing the assembler front end.
723 MCStreamer *createNullStreamer(MCContext &Ctx);
725 /// createAsmStreamer - Create a machine code streamer which will print out
726 /// assembly for the native target, suitable for compiling with a native
729 /// \param InstPrint - If given, the instruction printer to use. If not given
730 /// the MCInst representation will be printed. This method takes ownership of
733 /// \param CE - If given, a code emitter to use to show the instruction
734 /// encoding inline with the assembly. This method takes ownership of \p CE.
736 /// \param TAB - If given, a target asm backend to use to show the fixup
737 /// information in conjunction with encoding information. This method takes
738 /// ownership of \p TAB.
740 /// \param ShowInst - Whether to show the MCInst representation inline with
742 MCStreamer *createAsmStreamer(MCContext &Ctx, MCTargetStreamer *TargetStreamer,
743 formatted_raw_ostream &OS, bool isVerboseAsm,
744 bool useLoc, bool useCFI, bool useDwarfDirectory,
745 MCInstPrinter *InstPrint = 0,
746 MCCodeEmitter *CE = 0, MCAsmBackend *TAB = 0,
747 bool ShowInst = false);
749 /// createMachOStreamer - Create a machine code streamer which will generate
750 /// Mach-O format object files.
752 /// Takes ownership of \p TAB and \p CE.
753 MCStreamer *createMachOStreamer(MCContext &Ctx, MCAsmBackend &TAB,
754 raw_ostream &OS, MCCodeEmitter *CE,
755 bool RelaxAll = false);
757 /// createWinCOFFStreamer - Create a machine code streamer which will
758 /// generate Microsoft COFF format object files.
760 /// Takes ownership of \p TAB and \p CE.
761 MCStreamer *createWinCOFFStreamer(MCContext &Ctx, MCAsmBackend &TAB,
762 MCCodeEmitter &CE, raw_ostream &OS,
763 bool RelaxAll = false);
765 /// createELFStreamer - Create a machine code streamer which will generate
766 /// ELF format object files.
767 MCStreamer *createELFStreamer(MCContext &Ctx, MCTargetStreamer *TargetStreamer,
768 MCAsmBackend &TAB, raw_ostream &OS,
769 MCCodeEmitter *CE, bool RelaxAll,
772 /// createPureStreamer - Create a machine code streamer which will generate
773 /// "pure" MC object files, for use with MC-JIT and testing tools.
775 /// Takes ownership of \p TAB and \p CE.
776 MCStreamer *createPureStreamer(MCContext &Ctx, MCAsmBackend &TAB,
777 raw_ostream &OS, MCCodeEmitter *CE);
779 } // end namespace llvm