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 MCTargetStreamer(MCStreamer &S);
74 virtual ~MCTargetStreamer();
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 ARMTargetStreamer(MCStreamer &S);
87 virtual void emitFnStart() = 0;
88 virtual void emitFnEnd() = 0;
89 virtual void emitCantUnwind() = 0;
90 virtual void emitPersonality(const MCSymbol *Personality) = 0;
91 virtual void emitPersonalityIndex(unsigned Index) = 0;
92 virtual void emitHandlerData() = 0;
93 virtual void emitSetFP(unsigned FpReg, unsigned SpReg,
94 int64_t Offset = 0) = 0;
95 virtual void emitPad(int64_t Offset) = 0;
96 virtual void emitRegSave(const SmallVectorImpl<unsigned> &RegList,
98 virtual void emitUnwindRaw(int64_t StackOffset,
99 const SmallVectorImpl<uint8_t> &Opcodes) = 0;
101 virtual void switchVendor(StringRef Vendor) = 0;
102 virtual void emitAttribute(unsigned Attribute, unsigned Value) = 0;
103 virtual void emitTextAttribute(unsigned Attribute, StringRef String) = 0;
104 virtual void emitIntTextAttribute(unsigned Attribute, unsigned IntValue,
105 StringRef StringValue = "") = 0;
106 virtual void emitFPU(unsigned FPU) = 0;
107 virtual void emitArch(unsigned Arch) = 0;
108 virtual void finishAttributeSection() = 0;
109 virtual void emitInst(uint32_t Inst, char Suffix = '\0') = 0;
112 /// MCStreamer - Streaming machine code generation interface. This interface
113 /// is intended to provide a programatic interface that is very similar to the
114 /// level that an assembler .s file provides. It has callbacks to emit bytes,
115 /// handle directives, etc. The implementation of this interface retains
116 /// state to know what the current section is etc.
118 /// There are multiple implementations of this interface: one for writing out
119 /// a .s file, and implementations that write out .o files of various formats.
123 OwningPtr<MCTargetStreamer> TargetStreamer;
125 MCStreamer(const MCStreamer &) LLVM_DELETED_FUNCTION;
126 MCStreamer &operator=(const MCStreamer &) LLVM_DELETED_FUNCTION;
131 std::vector<MCDwarfFrameInfo> FrameInfos;
132 MCDwarfFrameInfo *getCurrentFrameInfo();
133 MCSymbol *EmitCFICommon();
134 void EnsureValidFrame();
136 std::vector<MCWin64EHUnwindInfo *> W64UnwindInfos;
137 MCWin64EHUnwindInfo *CurrentW64UnwindInfo;
138 void setCurrentW64UnwindInfo(MCWin64EHUnwindInfo *Frame);
139 void EnsureValidW64UnwindInfo();
141 MCSymbol *LastSymbol;
143 // SymbolOrdering - Tracks an index to represent the order
144 // a symbol was emitted in. Zero means we did not emit that symbol.
145 DenseMap<const MCSymbol *, unsigned> SymbolOrdering;
147 /// SectionStack - This is stack of current and previous section
148 /// values saved by PushSection.
149 SmallVector<std::pair<MCSectionSubPair, MCSectionSubPair>, 4> SectionStack;
152 MCStreamer(MCContext &Ctx);
154 const MCExpr *BuildSymbolDiff(MCContext &Context, const MCSymbol *A,
157 const MCExpr *ForceExpAbs(const MCExpr *Expr);
159 void RecordProcStart(MCDwarfFrameInfo &Frame);
160 virtual void EmitCFIStartProcImpl(MCDwarfFrameInfo &Frame);
161 void RecordProcEnd(MCDwarfFrameInfo &Frame);
162 virtual void EmitCFIEndProcImpl(MCDwarfFrameInfo &CurFrame);
163 void EmitFrames(MCAsmBackend *MAB, bool usingCFI);
165 MCWin64EHUnwindInfo *getCurrentW64UnwindInfo() {
166 return CurrentW64UnwindInfo;
168 void EmitW64Tables();
170 virtual void EmitRawTextImpl(StringRef String);
173 virtual ~MCStreamer();
175 void setTargetStreamer(MCTargetStreamer *TS) {
176 TargetStreamer.reset(TS);
181 virtual void reset();
183 MCContext &getContext() const { return Context; }
185 MCTargetStreamer *getTargetStreamer() {
186 return TargetStreamer.get();
189 unsigned getNumFrameInfos() { return FrameInfos.size(); }
191 const MCDwarfFrameInfo &getFrameInfo(unsigned i) { return FrameInfos[i]; }
193 ArrayRef<MCDwarfFrameInfo> getFrameInfos() const { return FrameInfos; }
195 unsigned getNumW64UnwindInfos() { return W64UnwindInfos.size(); }
197 MCWin64EHUnwindInfo &getW64UnwindInfo(unsigned i) {
198 return *W64UnwindInfos[i];
201 void generateCompactUnwindEncodings(MCAsmBackend *MAB);
203 /// @name Assembly File Formatting.
206 /// isVerboseAsm - Return true if this streamer supports verbose assembly
207 /// and if it is enabled.
208 virtual bool isVerboseAsm() const { return false; }
210 /// hasRawTextSupport - Return true if this asm streamer supports emitting
211 /// unformatted text to the .s file with EmitRawText.
212 virtual bool hasRawTextSupport() const { return false; }
214 /// AddComment - Add a comment that can be emitted to the generated .s
215 /// file if applicable as a QoI issue to make the output of the compiler
216 /// more readable. This only affects the MCAsmStreamer, and only when
217 /// verbose assembly output is enabled.
219 /// If the comment includes embedded \n's, they will each get the comment
220 /// prefix as appropriate. The added comment should not end with a \n.
221 virtual void AddComment(const Twine &T) {}
223 /// GetCommentOS - Return a raw_ostream that comments can be written to.
224 /// Unlike AddComment, you are required to terminate comments with \n if you
226 virtual raw_ostream &GetCommentOS();
228 /// Print T and prefix it with the comment string (normally #) and optionally
229 /// a tab. This prints the comment immediately, not at the end of the
230 /// current line. It is basically a safe version of EmitRawText: since it
231 /// only prints comments, the object streamer ignores it instead of asserting.
232 virtual void emitRawComment(const Twine &T, bool TabPrefix = true);
234 /// AddBlankLine - Emit a blank line to a .s file to pretty it up.
235 virtual void AddBlankLine() {}
239 /// @name Symbol & Section Management
242 /// getCurrentSection - Return the current section that the streamer is
243 /// emitting code to.
244 MCSectionSubPair getCurrentSection() const {
245 if (!SectionStack.empty())
246 return SectionStack.back().first;
247 return MCSectionSubPair();
250 /// getPreviousSection - Return the previous section that the streamer is
251 /// emitting code to.
252 MCSectionSubPair getPreviousSection() const {
253 if (!SectionStack.empty())
254 return SectionStack.back().second;
255 return MCSectionSubPair();
258 /// GetSymbolOrder - Returns an index to represent the order
259 /// a symbol was emitted in. (zero if we did not emit that symbol)
260 unsigned GetSymbolOrder(const MCSymbol *Sym) const {
261 return SymbolOrdering.lookup(Sym);
264 /// ChangeSection - Update streamer for a new active section.
266 /// This is called by PopSection and SwitchSection, if the current
268 virtual void ChangeSection(const MCSection *, const MCExpr *) = 0;
270 /// pushSection - Save the current and previous section on the
273 SectionStack.push_back(
274 std::make_pair(getCurrentSection(), getPreviousSection()));
277 /// popSection - Restore the current and previous section from
278 /// the section stack. Calls ChangeSection as needed.
280 /// Returns false if the stack was empty.
282 if (SectionStack.size() <= 1)
284 MCSectionSubPair oldSection = SectionStack.pop_back_val().first;
285 MCSectionSubPair curSection = SectionStack.back().first;
287 if (oldSection != curSection)
288 ChangeSection(curSection.first, curSection.second);
292 bool SubSection(const MCExpr *Subsection) {
293 if (SectionStack.empty())
296 SwitchSection(SectionStack.back().first.first, Subsection);
300 /// SwitchSection - Set the current section where code is being emitted to
301 /// @p Section. This is required to update CurSection.
303 /// This corresponds to assembler directives like .section, .text, etc.
304 void SwitchSection(const MCSection *Section, const MCExpr *Subsection = 0) {
305 assert(Section && "Cannot switch to a null section!");
306 MCSectionSubPair curSection = SectionStack.back().first;
307 SectionStack.back().second = curSection;
308 if (MCSectionSubPair(Section, Subsection) != curSection) {
309 SectionStack.back().first = MCSectionSubPair(Section, Subsection);
310 ChangeSection(Section, Subsection);
314 /// SwitchSectionNoChange - Set the current section where code is being
315 /// emitted to @p Section. This is required to update CurSection. This
316 /// version does not call ChangeSection.
317 void SwitchSectionNoChange(const MCSection *Section,
318 const MCExpr *Subsection = 0) {
319 assert(Section && "Cannot switch to a null section!");
320 MCSectionSubPair curSection = SectionStack.back().first;
321 SectionStack.back().second = curSection;
322 if (MCSectionSubPair(Section, Subsection) != curSection)
323 SectionStack.back().first = MCSectionSubPair(Section, Subsection);
326 /// Create the default sections and set the initial one.
328 /// @param Force - If false, a text streamer implementation can be a nop.
329 /// Used by CodeGen to avoid starting every file with '.text'.
330 virtual void InitSections(bool Force = true);
332 /// AssignSection - Sets the symbol's section.
334 /// Each emitted symbol will be tracked in the ordering table,
335 /// so we can sort on them later.
336 void AssignSection(MCSymbol *Symbol, const MCSection *Section);
338 /// EmitLabel - Emit a label for @p Symbol into the current section.
340 /// This corresponds to an assembler statement such as:
343 /// @param Symbol - The symbol to emit. A given symbol should only be
344 /// emitted as a label once, and symbols emitted as a label should never be
345 /// used in an assignment.
346 // FIXME: These emission are non-const because we mutate the symbol to
347 // add the section we're emitting it to later.
348 virtual void EmitLabel(MCSymbol *Symbol);
350 virtual void EmitDebugLabel(MCSymbol *Symbol);
352 virtual void EmitEHSymAttributes(const MCSymbol *Symbol, MCSymbol *EHSymbol);
354 /// EmitAssemblerFlag - Note in the output the specified @p Flag.
355 virtual void EmitAssemblerFlag(MCAssemblerFlag Flag) = 0;
357 /// EmitLinkerOptions - Emit the given list @p Options of strings as linker
358 /// options into the output.
359 virtual void EmitLinkerOptions(ArrayRef<std::string> Kind) {}
361 /// EmitDataRegion - Note in the output the specified region @p Kind.
362 virtual void EmitDataRegion(MCDataRegionType Kind) {}
364 /// EmitThumbFunc - Note in the output that the specified @p Func is
365 /// a Thumb mode function (ARM target only).
366 virtual void EmitThumbFunc(MCSymbol *Func) = 0;
368 /// getOrCreateSymbolData - Get symbol data for given symbol.
369 virtual MCSymbolData &getOrCreateSymbolData(MCSymbol *Symbol);
371 /// EmitAssignment - Emit an assignment of @p Value to @p Symbol.
373 /// This corresponds to an assembler statement such as:
376 /// The assignment generates no code, but has the side effect of binding the
377 /// value in the current context. For the assembly streamer, this prints the
378 /// binding into the .s file.
380 /// @param Symbol - The symbol being assigned to.
381 /// @param Value - The value for the symbol.
382 virtual void EmitAssignment(MCSymbol *Symbol, const MCExpr *Value) = 0;
384 /// EmitWeakReference - Emit an weak reference from @p Alias to @p Symbol.
386 /// This corresponds to an assembler statement such as:
387 /// .weakref alias, symbol
389 /// @param Alias - The alias that is being created.
390 /// @param Symbol - The symbol being aliased.
391 virtual void EmitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol) = 0;
393 /// EmitSymbolAttribute - Add the given @p Attribute to @p Symbol.
394 virtual bool EmitSymbolAttribute(MCSymbol *Symbol,
395 MCSymbolAttr Attribute) = 0;
397 /// EmitSymbolDesc - Set the @p DescValue for the @p Symbol.
399 /// @param Symbol - The symbol to have its n_desc field set.
400 /// @param DescValue - The value to set into the n_desc field.
401 virtual void EmitSymbolDesc(MCSymbol *Symbol, unsigned DescValue) = 0;
403 /// BeginCOFFSymbolDef - Start emitting COFF symbol definition
405 /// @param Symbol - The symbol to have its External & Type fields set.
406 virtual void BeginCOFFSymbolDef(const MCSymbol *Symbol) = 0;
408 /// EmitCOFFSymbolStorageClass - Emit the storage class of the symbol.
410 /// @param StorageClass - The storage class the symbol should have.
411 virtual void EmitCOFFSymbolStorageClass(int StorageClass) = 0;
413 /// EmitCOFFSymbolType - Emit the type of the symbol.
415 /// @param Type - A COFF type identifier (see COFF::SymbolType in X86COFF.h)
416 virtual void EmitCOFFSymbolType(int Type) = 0;
418 /// EndCOFFSymbolDef - Marks the end of the symbol definition.
419 virtual void EndCOFFSymbolDef() = 0;
421 /// EmitCOFFSectionIndex - Emits a COFF section index.
423 /// @param Symbol - Symbol the section number relocation should point to.
424 virtual void EmitCOFFSectionIndex(MCSymbol const *Symbol);
426 /// EmitCOFFSecRel32 - Emits a COFF section relative relocation.
428 /// @param Symbol - Symbol the section relative relocation should point to.
429 virtual void EmitCOFFSecRel32(MCSymbol const *Symbol);
431 /// EmitELFSize - Emit an ELF .size directive.
433 /// This corresponds to an assembler statement such as:
434 /// .size symbol, expression
436 virtual void EmitELFSize(MCSymbol *Symbol, const MCExpr *Value) = 0;
438 /// EmitCommonSymbol - Emit a common symbol.
440 /// @param Symbol - The common symbol to emit.
441 /// @param Size - The size of the common symbol.
442 /// @param ByteAlignment - The alignment of the symbol if
443 /// non-zero. This must be a power of 2.
444 virtual void EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
445 unsigned ByteAlignment) = 0;
447 /// EmitLocalCommonSymbol - Emit a local common (.lcomm) symbol.
449 /// @param Symbol - The common symbol to emit.
450 /// @param Size - The size of the common symbol.
451 /// @param ByteAlignment - The alignment of the common symbol in bytes.
452 virtual void EmitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size,
453 unsigned ByteAlignment) = 0;
455 /// EmitZerofill - Emit the zerofill section and an optional symbol.
457 /// @param Section - The zerofill section to create and or to put the symbol
458 /// @param Symbol - The zerofill symbol to emit, if non-NULL.
459 /// @param Size - The size of the zerofill symbol.
460 /// @param ByteAlignment - The alignment of the zerofill symbol if
461 /// non-zero. This must be a power of 2 on some targets.
462 virtual void EmitZerofill(const MCSection *Section, MCSymbol *Symbol = 0,
463 uint64_t Size = 0, unsigned ByteAlignment = 0) = 0;
465 /// EmitTBSSSymbol - Emit a thread local bss (.tbss) symbol.
467 /// @param Section - The thread local common section.
468 /// @param Symbol - The thread local common symbol to emit.
469 /// @param Size - The size of the symbol.
470 /// @param ByteAlignment - The alignment of the thread local common symbol
471 /// if non-zero. This must be a power of 2 on some targets.
472 virtual void EmitTBSSSymbol(const MCSection *Section, MCSymbol *Symbol,
473 uint64_t Size, unsigned ByteAlignment = 0) = 0;
476 /// @name Generating Data
479 /// EmitBytes - Emit the bytes in \p Data into the output.
481 /// This is used to implement assembler directives such as .byte, .ascii,
483 virtual void EmitBytes(StringRef Data) = 0;
485 /// EmitValue - Emit the expression @p Value into the output as a native
486 /// integer of the given @p Size bytes.
488 /// This is used to implement assembler directives such as .word, .quad,
491 /// @param Value - The value to emit.
492 /// @param Size - The size of the integer (in bytes) to emit. This must
493 /// match a native machine width.
494 virtual void EmitValueImpl(const MCExpr *Value, unsigned Size) = 0;
496 void EmitValue(const MCExpr *Value, unsigned Size);
498 /// EmitIntValue - Special case of EmitValue that avoids the client having
499 /// to pass in a MCExpr for constant integers.
500 virtual void EmitIntValue(uint64_t Value, unsigned Size);
502 /// EmitAbsValue - Emit the Value, but try to avoid relocations. On MachO
503 /// this is done by producing
506 void EmitAbsValue(const MCExpr *Value, unsigned Size);
508 virtual void EmitULEB128Value(const MCExpr *Value) = 0;
510 virtual void EmitSLEB128Value(const MCExpr *Value) = 0;
512 /// EmitULEB128Value - Special case of EmitULEB128Value that avoids the
513 /// client having to pass in a MCExpr for constant integers.
514 void EmitULEB128IntValue(uint64_t Value, unsigned Padding = 0);
516 /// EmitSLEB128Value - Special case of EmitSLEB128Value that avoids the
517 /// client having to pass in a MCExpr for constant integers.
518 void EmitSLEB128IntValue(int64_t Value);
520 /// EmitSymbolValue - Special case of EmitValue that avoids the client
521 /// having to pass in a MCExpr for MCSymbols.
522 void EmitSymbolValue(const MCSymbol *Sym, unsigned Size);
524 /// EmitGPRel64Value - Emit the expression @p Value into the output as a
525 /// gprel64 (64-bit GP relative) value.
527 /// This is used to implement assembler directives such as .gpdword on
528 /// targets that support them.
529 virtual void EmitGPRel64Value(const MCExpr *Value);
531 /// EmitGPRel32Value - Emit the expression @p Value into the output as a
532 /// gprel32 (32-bit GP relative) value.
534 /// This is used to implement assembler directives such as .gprel32 on
535 /// targets that support them.
536 virtual void EmitGPRel32Value(const MCExpr *Value);
538 /// EmitFill - Emit NumBytes bytes worth of the value specified by
539 /// FillValue. This implements directives such as '.space'.
540 virtual void EmitFill(uint64_t NumBytes, uint8_t FillValue);
542 /// \brief Emit NumBytes worth of zeros.
543 /// This function properly handles data in virtual sections.
544 virtual void EmitZeros(uint64_t NumBytes);
546 /// EmitValueToAlignment - Emit some number of copies of @p Value until
547 /// the byte alignment @p ByteAlignment is reached.
549 /// If the number of bytes need to emit for the alignment is not a multiple
550 /// of @p ValueSize, then the contents of the emitted fill bytes is
553 /// This used to implement the .align assembler directive.
555 /// @param ByteAlignment - The alignment to reach. This must be a power of
556 /// two on some targets.
557 /// @param Value - The value to use when filling bytes.
558 /// @param ValueSize - The size of the integer (in bytes) to emit for
559 /// @p Value. This must match a native machine width.
560 /// @param MaxBytesToEmit - The maximum numbers of bytes to emit, or 0. If
561 /// the alignment cannot be reached in this many bytes, no bytes are
563 virtual void EmitValueToAlignment(unsigned ByteAlignment, int64_t Value = 0,
564 unsigned ValueSize = 1,
565 unsigned MaxBytesToEmit = 0) = 0;
567 /// EmitCodeAlignment - Emit nops until the byte alignment @p ByteAlignment
570 /// This used to align code where the alignment bytes may be executed. This
571 /// can emit different bytes for different sizes to optimize execution.
573 /// @param ByteAlignment - The alignment to reach. This must be a power of
574 /// two on some targets.
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 EmitCodeAlignment(unsigned ByteAlignment,
579 unsigned MaxBytesToEmit = 0) = 0;
581 /// EmitValueToOffset - Emit some number of copies of @p Value until the
582 /// byte offset @p Offset is reached.
584 /// This is used to implement assembler directives such as .org.
586 /// @param Offset - The offset to reach. This may be an expression, but the
587 /// expression must be associated with the current section.
588 /// @param Value - The value to use when filling bytes.
589 /// @return false on success, true if the offset was invalid.
590 virtual bool EmitValueToOffset(const MCExpr *Offset,
591 unsigned char Value = 0) = 0;
595 /// EmitFileDirective - Switch to a new logical file. This is used to
596 /// implement the '.file "foo.c"' assembler directive.
597 virtual void EmitFileDirective(StringRef Filename) = 0;
599 /// Emit the "identifiers" directive. This implements the
600 /// '.ident "version foo"' assembler directive.
601 virtual void EmitIdent(StringRef IdentString) {}
603 /// EmitDwarfFileDirective - Associate a filename with a specified logical
604 /// file number. This implements the DWARF2 '.file 4 "foo.c"' assembler
606 virtual bool EmitDwarfFileDirective(unsigned FileNo, StringRef Directory,
607 StringRef Filename, unsigned CUID = 0);
609 /// EmitDwarfLocDirective - This implements the DWARF2
610 // '.loc fileno lineno ...' assembler directive.
611 virtual void EmitDwarfLocDirective(unsigned FileNo, unsigned Line,
612 unsigned Column, unsigned Flags,
613 unsigned Isa, unsigned Discriminator,
616 virtual void EmitDwarfAdvanceLineAddr(int64_t LineDelta,
617 const MCSymbol *LastLabel,
618 const MCSymbol *Label,
619 unsigned PointerSize) = 0;
621 virtual void EmitDwarfAdvanceFrameAddr(const MCSymbol *LastLabel,
622 const MCSymbol *Label) {}
624 void EmitDwarfSetLineAddr(int64_t LineDelta, const MCSymbol *Label,
627 virtual void EmitCompactUnwindEncoding(uint32_t CompactUnwindEncoding);
628 virtual void EmitCFISections(bool EH, bool Debug);
629 void EmitCFIStartProc(bool IsSimple);
630 void EmitCFIEndProc();
631 virtual void EmitCFIDefCfa(int64_t Register, int64_t Offset);
632 virtual void EmitCFIDefCfaOffset(int64_t Offset);
633 virtual void EmitCFIDefCfaRegister(int64_t Register);
634 virtual void EmitCFIOffset(int64_t Register, int64_t Offset);
635 virtual void EmitCFIPersonality(const MCSymbol *Sym, unsigned Encoding);
636 virtual void EmitCFILsda(const MCSymbol *Sym, unsigned Encoding);
637 virtual void EmitCFIRememberState();
638 virtual void EmitCFIRestoreState();
639 virtual void EmitCFISameValue(int64_t Register);
640 virtual void EmitCFIRestore(int64_t Register);
641 virtual void EmitCFIRelOffset(int64_t Register, int64_t Offset);
642 virtual void EmitCFIAdjustCfaOffset(int64_t Adjustment);
643 virtual void EmitCFIEscape(StringRef Values);
644 virtual void EmitCFISignalFrame();
645 virtual void EmitCFIUndefined(int64_t Register);
646 virtual void EmitCFIRegister(int64_t Register1, int64_t Register2);
647 virtual void EmitCFIWindowSave();
649 virtual void EmitWin64EHStartProc(const MCSymbol *Symbol);
650 virtual void EmitWin64EHEndProc();
651 virtual void EmitWin64EHStartChained();
652 virtual void EmitWin64EHEndChained();
653 virtual void EmitWin64EHHandler(const MCSymbol *Sym, bool Unwind,
655 virtual void EmitWin64EHHandlerData();
656 virtual void EmitWin64EHPushReg(unsigned Register);
657 virtual void EmitWin64EHSetFrame(unsigned Register, unsigned Offset);
658 virtual void EmitWin64EHAllocStack(unsigned Size);
659 virtual void EmitWin64EHSaveReg(unsigned Register, unsigned Offset);
660 virtual void EmitWin64EHSaveXMM(unsigned Register, unsigned Offset);
661 virtual void EmitWin64EHPushFrame(bool Code);
662 virtual void EmitWin64EHEndProlog();
664 /// EmitInstruction - Emit the given @p Instruction into the current
666 virtual void EmitInstruction(const MCInst &Inst) = 0;
668 /// \brief Set the bundle alignment mode from now on in the section.
669 /// The argument is the power of 2 to which the alignment is set. The
670 /// value 0 means turn the bundle alignment off.
671 virtual void EmitBundleAlignMode(unsigned AlignPow2) = 0;
673 /// \brief The following instructions are a bundle-locked group.
675 /// \param AlignToEnd - If true, the bundle-locked group will be aligned to
676 /// the end of a bundle.
677 virtual void EmitBundleLock(bool AlignToEnd) = 0;
679 /// \brief Ends a bundle-locked group.
680 virtual void EmitBundleUnlock() = 0;
682 /// EmitRawText - If this file is backed by a assembly streamer, this dumps
683 /// the specified string in the output .s file. This capability is
684 /// indicated by the hasRawTextSupport() predicate. By default this aborts.
685 void EmitRawText(const Twine &String);
687 /// Flush - Causes any cached state to be written out.
688 virtual void Flush() {}
690 /// FinishImpl - Streamer specific finalization.
691 virtual void FinishImpl() = 0;
692 /// Finish - Finish emission of machine code.
696 /// createNullStreamer - Create a dummy machine code streamer, which does
697 /// nothing. This is useful for timing the assembler front end.
698 MCStreamer *createNullStreamer(MCContext &Ctx);
700 /// createAsmStreamer - Create a machine code streamer which will print out
701 /// assembly for the native target, suitable for compiling with a native
704 /// \param InstPrint - If given, the instruction printer to use. If not given
705 /// the MCInst representation will be printed. This method takes ownership of
708 /// \param CE - If given, a code emitter to use to show the instruction
709 /// encoding inline with the assembly. This method takes ownership of \p CE.
711 /// \param TAB - If given, a target asm backend to use to show the fixup
712 /// information in conjunction with encoding information. This method takes
713 /// ownership of \p TAB.
715 /// \param ShowInst - Whether to show the MCInst representation inline with
717 MCStreamer *createAsmStreamer(MCContext &Ctx, formatted_raw_ostream &OS,
718 bool isVerboseAsm, bool useLoc, bool useCFI,
719 bool useDwarfDirectory,
720 MCInstPrinter *InstPrint = 0,
721 MCCodeEmitter *CE = 0, MCAsmBackend *TAB = 0,
722 bool ShowInst = false);
724 /// createMachOStreamer - Create a machine code streamer which will generate
725 /// Mach-O format object files.
727 /// Takes ownership of \p TAB and \p CE.
728 MCStreamer *createMachOStreamer(MCContext &Ctx, MCAsmBackend &TAB,
729 raw_ostream &OS, MCCodeEmitter *CE,
730 bool RelaxAll = false);
732 /// createWinCOFFStreamer - Create a machine code streamer which will
733 /// generate Microsoft COFF format object files.
735 /// Takes ownership of \p TAB and \p CE.
736 MCStreamer *createWinCOFFStreamer(MCContext &Ctx, MCAsmBackend &TAB,
737 MCCodeEmitter &CE, raw_ostream &OS,
738 bool RelaxAll = false);
740 /// createELFStreamer - Create a machine code streamer which will generate
741 /// ELF format object files.
742 MCStreamer *createELFStreamer(MCContext &Ctx, MCAsmBackend &TAB,
743 raw_ostream &OS, MCCodeEmitter *CE, bool RelaxAll,
746 /// createPureStreamer - Create a machine code streamer which will generate
747 /// "pure" MC object files, for use with MC-JIT and testing tools.
749 /// Takes ownership of \p TAB and \p CE.
750 MCStreamer *createPureStreamer(MCContext &Ctx, MCAsmBackend &TAB,
751 raw_ostream &OS, MCCodeEmitter *CE);
753 } // end namespace llvm