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);
80 // FIXME: declared here because it is used from
81 // lib/CodeGen/AsmPrinter/ARMException.cpp.
82 class ARMTargetStreamer : public MCTargetStreamer {
83 virtual void anchor();
85 virtual void emitFnStart() = 0;
86 virtual void emitFnEnd() = 0;
87 virtual void emitCantUnwind() = 0;
88 virtual void emitPersonality(const MCSymbol *Personality) = 0;
89 virtual void emitPersonalityIndex(unsigned Index) = 0;
90 virtual void emitHandlerData() = 0;
91 virtual void emitSetFP(unsigned FpReg, unsigned SpReg,
92 int64_t Offset = 0) = 0;
93 virtual void emitPad(int64_t Offset) = 0;
94 virtual void emitRegSave(const SmallVectorImpl<unsigned> &RegList,
96 virtual void emitUnwindRaw(int64_t StackOffset,
97 const SmallVectorImpl<uint8_t> &Opcodes) = 0;
99 virtual void switchVendor(StringRef Vendor) = 0;
100 virtual void emitAttribute(unsigned Attribute, unsigned Value) = 0;
101 virtual void emitTextAttribute(unsigned Attribute, StringRef String) = 0;
102 virtual void emitIntTextAttribute(unsigned Attribute, unsigned IntValue,
103 StringRef StringValue = "") = 0;
104 virtual void emitFPU(unsigned FPU) = 0;
105 virtual void emitArch(unsigned Arch) = 0;
106 virtual void finishAttributeSection() = 0;
107 virtual void emitInst(uint32_t Inst, char Suffix = '\0') = 0;
110 /// MCStreamer - Streaming machine code generation interface. This interface
111 /// is intended to provide a programatic interface that is very similar to the
112 /// level that an assembler .s file provides. It has callbacks to emit bytes,
113 /// handle directives, etc. The implementation of this interface retains
114 /// state to know what the current section is etc.
116 /// There are multiple implementations of this interface: one for writing out
117 /// a .s file, and implementations that write out .o files of various formats.
121 OwningPtr<MCTargetStreamer> TargetStreamer;
123 MCStreamer(const MCStreamer &) LLVM_DELETED_FUNCTION;
124 MCStreamer &operator=(const MCStreamer &) LLVM_DELETED_FUNCTION;
129 std::vector<MCDwarfFrameInfo> FrameInfos;
130 MCDwarfFrameInfo *getCurrentFrameInfo();
131 MCSymbol *EmitCFICommon();
132 void EnsureValidFrame();
134 std::vector<MCWin64EHUnwindInfo *> W64UnwindInfos;
135 MCWin64EHUnwindInfo *CurrentW64UnwindInfo;
136 void setCurrentW64UnwindInfo(MCWin64EHUnwindInfo *Frame);
137 void EnsureValidW64UnwindInfo();
139 MCSymbol *LastSymbol;
141 // SymbolOrdering - Tracks an index to represent the order
142 // a symbol was emitted in. Zero means we did not emit that symbol.
143 DenseMap<const MCSymbol *, unsigned> SymbolOrdering;
145 /// SectionStack - This is stack of current and previous section
146 /// values saved by PushSection.
147 SmallVector<std::pair<MCSectionSubPair, MCSectionSubPair>, 4> SectionStack;
150 MCStreamer(MCContext &Ctx, MCTargetStreamer *TargetStreamer);
152 const MCExpr *BuildSymbolDiff(MCContext &Context, const MCSymbol *A,
155 const MCExpr *ForceExpAbs(const MCExpr *Expr);
157 void RecordProcStart(MCDwarfFrameInfo &Frame);
158 virtual void EmitCFIStartProcImpl(MCDwarfFrameInfo &Frame);
159 void RecordProcEnd(MCDwarfFrameInfo &Frame);
160 virtual void EmitCFIEndProcImpl(MCDwarfFrameInfo &CurFrame);
161 void EmitFrames(MCAsmBackend *MAB, bool usingCFI);
163 MCWin64EHUnwindInfo *getCurrentW64UnwindInfo() {
164 return CurrentW64UnwindInfo;
166 void EmitW64Tables();
168 virtual void EmitRawTextImpl(StringRef String);
171 virtual ~MCStreamer();
175 virtual void reset();
177 MCContext &getContext() const { return Context; }
179 MCTargetStreamer *getTargetStreamer() {
180 return TargetStreamer.get();
183 unsigned getNumFrameInfos() { return FrameInfos.size(); }
185 const MCDwarfFrameInfo &getFrameInfo(unsigned i) { return FrameInfos[i]; }
187 ArrayRef<MCDwarfFrameInfo> getFrameInfos() const { return FrameInfos; }
189 unsigned getNumW64UnwindInfos() { return W64UnwindInfos.size(); }
191 MCWin64EHUnwindInfo &getW64UnwindInfo(unsigned i) {
192 return *W64UnwindInfos[i];
195 void generateCompactUnwindEncodings(MCAsmBackend *MAB);
197 /// @name Assembly File Formatting.
200 /// isVerboseAsm - Return true if this streamer supports verbose assembly
201 /// and if it is enabled.
202 virtual bool isVerboseAsm() const { return false; }
204 /// hasRawTextSupport - Return true if this asm streamer supports emitting
205 /// unformatted text to the .s file with EmitRawText.
206 virtual bool hasRawTextSupport() const { return false; }
208 /// AddComment - Add a comment that can be emitted to the generated .s
209 /// file if applicable as a QoI issue to make the output of the compiler
210 /// more readable. This only affects the MCAsmStreamer, and only when
211 /// verbose assembly output is enabled.
213 /// If the comment includes embedded \n's, they will each get the comment
214 /// prefix as appropriate. The added comment should not end with a \n.
215 virtual void AddComment(const Twine &T) {}
217 /// GetCommentOS - Return a raw_ostream that comments can be written to.
218 /// Unlike AddComment, you are required to terminate comments with \n if you
220 virtual raw_ostream &GetCommentOS();
222 /// Print T and prefix it with the comment string (normally #) and optionally
223 /// a tab. This prints the comment immediately, not at the end of the
224 /// current line. It is basically a safe version of EmitRawText: since it
225 /// only prints comments, the object streamer ignores it instead of asserting.
226 virtual void emitRawComment(const Twine &T, bool TabPrefix = true);
228 /// AddBlankLine - Emit a blank line to a .s file to pretty it up.
229 virtual void AddBlankLine() {}
233 /// @name Symbol & Section Management
236 /// getCurrentSection - Return the current section that the streamer is
237 /// emitting code to.
238 MCSectionSubPair getCurrentSection() const {
239 if (!SectionStack.empty())
240 return SectionStack.back().first;
241 return MCSectionSubPair();
244 /// getPreviousSection - Return the previous section that the streamer is
245 /// emitting code to.
246 MCSectionSubPair getPreviousSection() const {
247 if (!SectionStack.empty())
248 return SectionStack.back().second;
249 return MCSectionSubPair();
252 /// GetSymbolOrder - Returns an index to represent the order
253 /// a symbol was emitted in. (zero if we did not emit that symbol)
254 unsigned GetSymbolOrder(const MCSymbol *Sym) const {
255 return SymbolOrdering.lookup(Sym);
258 /// ChangeSection - Update streamer for a new active section.
260 /// This is called by PopSection and SwitchSection, if the current
262 virtual void ChangeSection(const MCSection *, const MCExpr *) = 0;
264 /// pushSection - Save the current and previous section on the
267 SectionStack.push_back(
268 std::make_pair(getCurrentSection(), getPreviousSection()));
271 /// popSection - Restore the current and previous section from
272 /// the section stack. Calls ChangeSection as needed.
274 /// Returns false if the stack was empty.
276 if (SectionStack.size() <= 1)
278 MCSectionSubPair oldSection = SectionStack.pop_back_val().first;
279 MCSectionSubPair curSection = SectionStack.back().first;
281 if (oldSection != curSection)
282 ChangeSection(curSection.first, curSection.second);
286 bool SubSection(const MCExpr *Subsection) {
287 if (SectionStack.empty())
290 SwitchSection(SectionStack.back().first.first, Subsection);
294 /// SwitchSection - Set the current section where code is being emitted to
295 /// @p Section. This is required to update CurSection.
297 /// This corresponds to assembler directives like .section, .text, etc.
298 void SwitchSection(const MCSection *Section, const MCExpr *Subsection = 0) {
299 assert(Section && "Cannot switch to a null section!");
300 MCSectionSubPair curSection = SectionStack.back().first;
301 SectionStack.back().second = curSection;
302 if (MCSectionSubPair(Section, Subsection) != curSection) {
303 SectionStack.back().first = MCSectionSubPair(Section, Subsection);
304 ChangeSection(Section, Subsection);
308 /// SwitchSectionNoChange - Set the current section where code is being
309 /// emitted to @p Section. This is required to update CurSection. This
310 /// version does not call ChangeSection.
311 void SwitchSectionNoChange(const MCSection *Section,
312 const MCExpr *Subsection = 0) {
313 assert(Section && "Cannot switch to a null section!");
314 MCSectionSubPair curSection = SectionStack.back().first;
315 SectionStack.back().second = curSection;
316 if (MCSectionSubPair(Section, Subsection) != curSection)
317 SectionStack.back().first = MCSectionSubPair(Section, Subsection);
320 /// Create the default sections and set the initial one.
322 /// @param Force - If false, a text streamer implementation can be a nop.
323 /// Used by CodeGen to avoid starting every file with '.text'.
324 virtual void InitSections(bool Force = true);
326 /// AssignSection - Sets the symbol's section.
328 /// Each emitted symbol will be tracked in the ordering table,
329 /// so we can sort on them later.
330 void AssignSection(MCSymbol *Symbol, const MCSection *Section);
332 /// EmitLabel - Emit a label for @p Symbol into the current section.
334 /// This corresponds to an assembler statement such as:
337 /// @param Symbol - The symbol to emit. A given symbol should only be
338 /// emitted as a label once, and symbols emitted as a label should never be
339 /// used in an assignment.
340 // FIXME: These emission are non-const because we mutate the symbol to
341 // add the section we're emitting it to later.
342 virtual void EmitLabel(MCSymbol *Symbol);
344 virtual void EmitDebugLabel(MCSymbol *Symbol);
346 virtual void EmitEHSymAttributes(const MCSymbol *Symbol, MCSymbol *EHSymbol);
348 /// EmitAssemblerFlag - Note in the output the specified @p Flag.
349 virtual void EmitAssemblerFlag(MCAssemblerFlag Flag) = 0;
351 /// EmitLinkerOptions - Emit the given list @p Options of strings as linker
352 /// options into the output.
353 virtual void EmitLinkerOptions(ArrayRef<std::string> Kind) {}
355 /// EmitDataRegion - Note in the output the specified region @p Kind.
356 virtual void EmitDataRegion(MCDataRegionType Kind) {}
358 /// EmitThumbFunc - Note in the output that the specified @p Func is
359 /// a Thumb mode function (ARM target only).
360 virtual void EmitThumbFunc(MCSymbol *Func) = 0;
362 /// getOrCreateSymbolData - Get symbol data for given symbol.
363 virtual MCSymbolData &getOrCreateSymbolData(MCSymbol *Symbol);
365 /// EmitAssignment - Emit an assignment of @p Value to @p Symbol.
367 /// This corresponds to an assembler statement such as:
370 /// The assignment generates no code, but has the side effect of binding the
371 /// value in the current context. For the assembly streamer, this prints the
372 /// binding into the .s file.
374 /// @param Symbol - The symbol being assigned to.
375 /// @param Value - The value for the symbol.
376 virtual void EmitAssignment(MCSymbol *Symbol, const MCExpr *Value) = 0;
378 /// EmitWeakReference - Emit an weak reference from @p Alias to @p Symbol.
380 /// This corresponds to an assembler statement such as:
381 /// .weakref alias, symbol
383 /// @param Alias - The alias that is being created.
384 /// @param Symbol - The symbol being aliased.
385 virtual void EmitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol) = 0;
387 /// EmitSymbolAttribute - Add the given @p Attribute to @p Symbol.
388 virtual bool EmitSymbolAttribute(MCSymbol *Symbol,
389 MCSymbolAttr Attribute) = 0;
391 /// EmitSymbolDesc - Set the @p DescValue for the @p Symbol.
393 /// @param Symbol - The symbol to have its n_desc field set.
394 /// @param DescValue - The value to set into the n_desc field.
395 virtual void EmitSymbolDesc(MCSymbol *Symbol, unsigned DescValue) = 0;
397 /// BeginCOFFSymbolDef - Start emitting COFF symbol definition
399 /// @param Symbol - The symbol to have its External & Type fields set.
400 virtual void BeginCOFFSymbolDef(const MCSymbol *Symbol) = 0;
402 /// EmitCOFFSymbolStorageClass - Emit the storage class of the symbol.
404 /// @param StorageClass - The storage class the symbol should have.
405 virtual void EmitCOFFSymbolStorageClass(int StorageClass) = 0;
407 /// EmitCOFFSymbolType - Emit the type of the symbol.
409 /// @param Type - A COFF type identifier (see COFF::SymbolType in X86COFF.h)
410 virtual void EmitCOFFSymbolType(int Type) = 0;
412 /// EndCOFFSymbolDef - Marks the end of the symbol definition.
413 virtual void EndCOFFSymbolDef() = 0;
415 /// EmitCOFFSectionIndex - Emits a COFF section index.
417 /// @param Symbol - Symbol the section number relocation should point to.
418 virtual void EmitCOFFSectionIndex(MCSymbol const *Symbol);
420 /// EmitCOFFSecRel32 - Emits a COFF section relative relocation.
422 /// @param Symbol - Symbol the section relative relocation should point to.
423 virtual void EmitCOFFSecRel32(MCSymbol const *Symbol);
425 /// EmitELFSize - Emit an ELF .size directive.
427 /// This corresponds to an assembler statement such as:
428 /// .size symbol, expression
430 virtual void EmitELFSize(MCSymbol *Symbol, const MCExpr *Value) = 0;
432 /// EmitCommonSymbol - Emit a common symbol.
434 /// @param Symbol - The common symbol to emit.
435 /// @param Size - The size of the common symbol.
436 /// @param ByteAlignment - The alignment of the symbol if
437 /// non-zero. This must be a power of 2.
438 virtual void EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
439 unsigned ByteAlignment) = 0;
441 /// EmitLocalCommonSymbol - Emit a local common (.lcomm) symbol.
443 /// @param Symbol - The common symbol to emit.
444 /// @param Size - The size of the common symbol.
445 /// @param ByteAlignment - The alignment of the common symbol in bytes.
446 virtual void EmitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size,
447 unsigned ByteAlignment) = 0;
449 /// EmitZerofill - Emit the zerofill section and an optional symbol.
451 /// @param Section - The zerofill section to create and or to put the symbol
452 /// @param Symbol - The zerofill symbol to emit, if non-NULL.
453 /// @param Size - The size of the zerofill symbol.
454 /// @param ByteAlignment - The alignment of the zerofill symbol if
455 /// non-zero. This must be a power of 2 on some targets.
456 virtual void EmitZerofill(const MCSection *Section, MCSymbol *Symbol = 0,
457 uint64_t Size = 0, unsigned ByteAlignment = 0) = 0;
459 /// EmitTBSSSymbol - Emit a thread local bss (.tbss) symbol.
461 /// @param Section - The thread local common section.
462 /// @param Symbol - The thread local common symbol to emit.
463 /// @param Size - The size of the symbol.
464 /// @param ByteAlignment - The alignment of the thread local common symbol
465 /// if non-zero. This must be a power of 2 on some targets.
466 virtual void EmitTBSSSymbol(const MCSection *Section, MCSymbol *Symbol,
467 uint64_t Size, unsigned ByteAlignment = 0) = 0;
470 /// @name Generating Data
473 /// EmitBytes - Emit the bytes in \p Data into the output.
475 /// This is used to implement assembler directives such as .byte, .ascii,
477 virtual void EmitBytes(StringRef Data) = 0;
479 /// EmitValue - Emit the expression @p Value into the output as a native
480 /// integer of the given @p Size bytes.
482 /// This is used to implement assembler directives such as .word, .quad,
485 /// @param Value - The value to emit.
486 /// @param Size - The size of the integer (in bytes) to emit. This must
487 /// match a native machine width.
488 virtual void EmitValueImpl(const MCExpr *Value, unsigned Size) = 0;
490 void EmitValue(const MCExpr *Value, unsigned Size);
492 /// EmitIntValue - Special case of EmitValue that avoids the client having
493 /// to pass in a MCExpr for constant integers.
494 virtual void EmitIntValue(uint64_t Value, unsigned Size);
496 /// EmitAbsValue - Emit the Value, but try to avoid relocations. On MachO
497 /// this is done by producing
500 void EmitAbsValue(const MCExpr *Value, unsigned Size);
502 virtual void EmitULEB128Value(const MCExpr *Value) = 0;
504 virtual void EmitSLEB128Value(const MCExpr *Value) = 0;
506 /// EmitULEB128Value - Special case of EmitULEB128Value that avoids the
507 /// client having to pass in a MCExpr for constant integers.
508 void EmitULEB128IntValue(uint64_t Value, unsigned Padding = 0);
510 /// EmitSLEB128Value - Special case of EmitSLEB128Value that avoids the
511 /// client having to pass in a MCExpr for constant integers.
512 void EmitSLEB128IntValue(int64_t Value);
514 /// EmitSymbolValue - Special case of EmitValue that avoids the client
515 /// having to pass in a MCExpr for MCSymbols.
516 void EmitSymbolValue(const MCSymbol *Sym, unsigned Size);
518 /// EmitGPRel64Value - Emit the expression @p Value into the output as a
519 /// gprel64 (64-bit GP relative) value.
521 /// This is used to implement assembler directives such as .gpdword on
522 /// targets that support them.
523 virtual void EmitGPRel64Value(const MCExpr *Value);
525 /// EmitGPRel32Value - Emit the expression @p Value into the output as a
526 /// gprel32 (32-bit GP relative) value.
528 /// This is used to implement assembler directives such as .gprel32 on
529 /// targets that support them.
530 virtual void EmitGPRel32Value(const MCExpr *Value);
532 /// EmitFill - Emit NumBytes bytes worth of the value specified by
533 /// FillValue. This implements directives such as '.space'.
534 virtual void EmitFill(uint64_t NumBytes, uint8_t FillValue);
536 /// \brief Emit NumBytes worth of zeros.
537 /// This function properly handles data in virtual sections.
538 virtual void EmitZeros(uint64_t NumBytes);
540 /// EmitValueToAlignment - Emit some number of copies of @p Value until
541 /// the byte alignment @p ByteAlignment is reached.
543 /// If the number of bytes need to emit for the alignment is not a multiple
544 /// of @p ValueSize, then the contents of the emitted fill bytes is
547 /// This used to implement the .align assembler directive.
549 /// @param ByteAlignment - The alignment to reach. This must be a power of
550 /// two on some targets.
551 /// @param Value - The value to use when filling bytes.
552 /// @param ValueSize - The size of the integer (in bytes) to emit for
553 /// @p Value. This must match a native machine width.
554 /// @param MaxBytesToEmit - The maximum numbers of bytes to emit, or 0. If
555 /// the alignment cannot be reached in this many bytes, no bytes are
557 virtual void EmitValueToAlignment(unsigned ByteAlignment, int64_t Value = 0,
558 unsigned ValueSize = 1,
559 unsigned MaxBytesToEmit = 0) = 0;
561 /// EmitCodeAlignment - Emit nops until the byte alignment @p ByteAlignment
564 /// This used to align code where the alignment bytes may be executed. This
565 /// can emit different bytes for different sizes to optimize execution.
567 /// @param ByteAlignment - The alignment to reach. This must be a power of
568 /// two on some targets.
569 /// @param MaxBytesToEmit - The maximum numbers of bytes to emit, or 0. If
570 /// the alignment cannot be reached in this many bytes, no bytes are
572 virtual void EmitCodeAlignment(unsigned ByteAlignment,
573 unsigned MaxBytesToEmit = 0) = 0;
575 /// EmitValueToOffset - Emit some number of copies of @p Value until the
576 /// byte offset @p Offset is reached.
578 /// This is used to implement assembler directives such as .org.
580 /// @param Offset - The offset to reach. This may be an expression, but the
581 /// expression must be associated with the current section.
582 /// @param Value - The value to use when filling bytes.
583 /// @return false on success, true if the offset was invalid.
584 virtual bool EmitValueToOffset(const MCExpr *Offset,
585 unsigned char Value = 0) = 0;
589 /// EmitFileDirective - Switch to a new logical file. This is used to
590 /// implement the '.file "foo.c"' assembler directive.
591 virtual void EmitFileDirective(StringRef Filename) = 0;
593 /// Emit the "identifiers" directive. This implements the
594 /// '.ident "version foo"' assembler directive.
595 virtual void EmitIdent(StringRef IdentString) {}
597 /// EmitDwarfFileDirective - Associate a filename with a specified logical
598 /// file number. This implements the DWARF2 '.file 4 "foo.c"' assembler
600 virtual bool EmitDwarfFileDirective(unsigned FileNo, StringRef Directory,
601 StringRef Filename, unsigned CUID = 0);
603 /// EmitDwarfLocDirective - This implements the DWARF2
604 // '.loc fileno lineno ...' assembler directive.
605 virtual void EmitDwarfLocDirective(unsigned FileNo, unsigned Line,
606 unsigned Column, unsigned Flags,
607 unsigned Isa, unsigned Discriminator,
610 virtual void EmitDwarfAdvanceLineAddr(int64_t LineDelta,
611 const MCSymbol *LastLabel,
612 const MCSymbol *Label,
613 unsigned PointerSize) = 0;
615 virtual void EmitDwarfAdvanceFrameAddr(const MCSymbol *LastLabel,
616 const MCSymbol *Label) {}
618 void EmitDwarfSetLineAddr(int64_t LineDelta, const MCSymbol *Label,
621 virtual void EmitCompactUnwindEncoding(uint32_t CompactUnwindEncoding);
622 virtual void EmitCFISections(bool EH, bool Debug);
623 void EmitCFIStartProc();
624 void EmitCFIEndProc();
625 virtual void EmitCFIDefCfa(int64_t Register, int64_t Offset);
626 virtual void EmitCFIDefCfaOffset(int64_t Offset);
627 virtual void EmitCFIDefCfaRegister(int64_t Register);
628 virtual void EmitCFIOffset(int64_t Register, int64_t Offset);
629 virtual void EmitCFIPersonality(const MCSymbol *Sym, unsigned Encoding);
630 virtual void EmitCFILsda(const MCSymbol *Sym, unsigned Encoding);
631 virtual void EmitCFIRememberState();
632 virtual void EmitCFIRestoreState();
633 virtual void EmitCFISameValue(int64_t Register);
634 virtual void EmitCFIRestore(int64_t Register);
635 virtual void EmitCFIRelOffset(int64_t Register, int64_t Offset);
636 virtual void EmitCFIAdjustCfaOffset(int64_t Adjustment);
637 virtual void EmitCFIEscape(StringRef Values);
638 virtual void EmitCFISignalFrame();
639 virtual void EmitCFIUndefined(int64_t Register);
640 virtual void EmitCFIRegister(int64_t Register1, int64_t Register2);
641 virtual void EmitCFIWindowSave();
643 virtual void EmitWin64EHStartProc(const MCSymbol *Symbol);
644 virtual void EmitWin64EHEndProc();
645 virtual void EmitWin64EHStartChained();
646 virtual void EmitWin64EHEndChained();
647 virtual void EmitWin64EHHandler(const MCSymbol *Sym, bool Unwind,
649 virtual void EmitWin64EHHandlerData();
650 virtual void EmitWin64EHPushReg(unsigned Register);
651 virtual void EmitWin64EHSetFrame(unsigned Register, unsigned Offset);
652 virtual void EmitWin64EHAllocStack(unsigned Size);
653 virtual void EmitWin64EHSaveReg(unsigned Register, unsigned Offset);
654 virtual void EmitWin64EHSaveXMM(unsigned Register, unsigned Offset);
655 virtual void EmitWin64EHPushFrame(bool Code);
656 virtual void EmitWin64EHEndProlog();
658 /// EmitInstruction - Emit the given @p Instruction into the current
660 virtual void EmitInstruction(const MCInst &Inst) = 0;
662 /// \brief Set the bundle alignment mode from now on in the section.
663 /// The argument is the power of 2 to which the alignment is set. The
664 /// value 0 means turn the bundle alignment off.
665 virtual void EmitBundleAlignMode(unsigned AlignPow2) = 0;
667 /// \brief The following instructions are a bundle-locked group.
669 /// \param AlignToEnd - If true, the bundle-locked group will be aligned to
670 /// the end of a bundle.
671 virtual void EmitBundleLock(bool AlignToEnd) = 0;
673 /// \brief Ends a bundle-locked group.
674 virtual void EmitBundleUnlock() = 0;
676 /// EmitRawText - If this file is backed by a assembly streamer, this dumps
677 /// the specified string in the output .s file. This capability is
678 /// indicated by the hasRawTextSupport() predicate. By default this aborts.
679 void EmitRawText(const Twine &String);
681 /// Flush - Causes any cached state to be written out.
682 virtual void Flush() {}
684 /// FinishImpl - Streamer specific finalization.
685 virtual void FinishImpl() = 0;
686 /// Finish - Finish emission of machine code.
690 /// createNullStreamer - Create a dummy machine code streamer, which does
691 /// nothing. This is useful for timing the assembler front end.
692 MCStreamer *createNullStreamer(MCContext &Ctx);
694 /// createAsmStreamer - Create a machine code streamer which will print out
695 /// assembly for the native target, suitable for compiling with a native
698 /// \param InstPrint - If given, the instruction printer to use. If not given
699 /// the MCInst representation will be printed. This method takes ownership of
702 /// \param CE - If given, a code emitter to use to show the instruction
703 /// encoding inline with the assembly. This method takes ownership of \p CE.
705 /// \param TAB - If given, a target asm backend to use to show the fixup
706 /// information in conjunction with encoding information. This method takes
707 /// ownership of \p TAB.
709 /// \param ShowInst - Whether to show the MCInst representation inline with
711 MCStreamer *createAsmStreamer(MCContext &Ctx, MCTargetStreamer *TargetStreamer,
712 formatted_raw_ostream &OS, bool isVerboseAsm,
713 bool useLoc, bool useCFI, bool useDwarfDirectory,
714 MCInstPrinter *InstPrint = 0,
715 MCCodeEmitter *CE = 0, MCAsmBackend *TAB = 0,
716 bool ShowInst = false);
718 /// createMachOStreamer - Create a machine code streamer which will generate
719 /// Mach-O format object files.
721 /// Takes ownership of \p TAB and \p CE.
722 MCStreamer *createMachOStreamer(MCContext &Ctx, MCAsmBackend &TAB,
723 raw_ostream &OS, MCCodeEmitter *CE,
724 bool RelaxAll = false);
726 /// createWinCOFFStreamer - Create a machine code streamer which will
727 /// generate Microsoft COFF format object files.
729 /// Takes ownership of \p TAB and \p CE.
730 MCStreamer *createWinCOFFStreamer(MCContext &Ctx, MCAsmBackend &TAB,
731 MCCodeEmitter &CE, raw_ostream &OS,
732 bool RelaxAll = false);
734 /// createELFStreamer - Create a machine code streamer which will generate
735 /// ELF format object files.
736 MCStreamer *createELFStreamer(MCContext &Ctx, MCTargetStreamer *TargetStreamer,
737 MCAsmBackend &TAB, raw_ostream &OS,
738 MCCodeEmitter *CE, bool RelaxAll,
741 /// createPureStreamer - Create a machine code streamer which will generate
742 /// "pure" MC object files, for use with MC-JIT and testing tools.
744 /// Takes ownership of \p TAB and \p CE.
745 MCStreamer *createPureStreamer(MCContext &Ctx, MCAsmBackend &TAB,
746 raw_ostream &OS, MCCodeEmitter *CE);
748 } // end namespace llvm