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"
39 class formatted_raw_ostream;
41 typedef std::pair<const MCSection *, const MCExpr *> MCSectionSubPair;
43 /// Target specific streamer interface. This is used so that targets can
44 /// implement support for target specific assembly directives.
46 /// If target foo wants to use this, it should implement 3 classes:
47 /// * FooTargetStreamer : public MCTargetStreamer
48 /// * FooTargetAsmSreamer : public FooTargetStreamer
49 /// * FooTargetELFStreamer : public FooTargetStreamer
51 /// FooTargetStreamer should have a pure virtual method for each directive. For
52 /// example, for a ".bar symbol_name" directive, it should have
53 /// virtual emitBar(const MCSymbol &Symbol) = 0;
55 /// The FooTargetAsmSreamer and FooTargetELFStreamer classes implement the
56 /// method. The assembly streamer just prints ".bar symbol_name". The object
57 /// streamer does whatever is needed to implement .bar in the object file.
59 /// In the assembly printer and parser the target streamer can be used by
60 /// calling getTargetStreamer and casting it to FooTargetStreamer:
62 /// MCTargetStreamer &TS = OutStreamer.getTargetStreamer();
63 /// FooTargetStreamer &ATS = static_cast<FooTargetStreamer &>(TS);
65 /// The base classes FooTargetAsmSreamer and FooTargetELFStreamer should *never*
66 /// be treated differently. Callers should always talk to a FooTargetStreamer.
67 class MCTargetStreamer {
72 virtual ~MCTargetStreamer();
73 void setStreamer(MCStreamer *S) { Streamer = S; }
76 // FIXME: declared here because it is used from
77 // lib/CodeGen/AsmPrinter/ARMException.cpp.
78 class ARMTargetStreamer : public MCTargetStreamer {
80 virtual void emitFnStart() = 0;
81 virtual void emitFnEnd() = 0;
82 virtual void emitCantUnwind() = 0;
83 virtual void emitPersonality(const MCSymbol *Personality) = 0;
84 virtual void emitHandlerData() = 0;
85 virtual void emitSetFP(unsigned FpReg, unsigned SpReg,
86 int64_t Offset = 0) = 0;
87 virtual void emitPad(int64_t Offset) = 0;
88 virtual void emitRegSave(const SmallVectorImpl<unsigned> &RegList,
91 virtual void switchVendor(StringRef Vendor) = 0;
92 virtual void emitAttribute(unsigned Attribute, unsigned Value) = 0;
93 virtual void emitTextAttribute(unsigned Attribute, StringRef String) = 0;
94 virtual void emitFPU(unsigned FPU) = 0;
95 virtual void finishAttributeSection() = 0;
98 /// MCStreamer - Streaming machine code generation interface. This interface
99 /// is intended to provide a programatic interface that is very similar to the
100 /// level that an assembler .s file provides. It has callbacks to emit bytes,
101 /// handle directives, etc. The implementation of this interface retains
102 /// state to know what the current section is etc.
104 /// There are multiple implementations of this interface: one for writing out
105 /// a .s file, and implementations that write out .o files of various formats.
109 OwningPtr<MCTargetStreamer> TargetStreamer;
111 MCStreamer(const MCStreamer &) LLVM_DELETED_FUNCTION;
112 MCStreamer &operator=(const MCStreamer &) LLVM_DELETED_FUNCTION;
117 std::vector<MCDwarfFrameInfo> FrameInfos;
118 MCDwarfFrameInfo *getCurrentFrameInfo();
119 MCSymbol *EmitCFICommon();
120 void EnsureValidFrame();
122 std::vector<MCWin64EHUnwindInfo *> W64UnwindInfos;
123 MCWin64EHUnwindInfo *CurrentW64UnwindInfo;
124 void setCurrentW64UnwindInfo(MCWin64EHUnwindInfo *Frame);
125 void EnsureValidW64UnwindInfo();
127 MCSymbol *LastSymbol;
129 // SymbolOrdering - Tracks an index to represent the order
130 // a symbol was emitted in. Zero means we did not emit that symbol.
131 DenseMap<const MCSymbol *, unsigned> SymbolOrdering;
133 /// SectionStack - This is stack of current and previous section
134 /// values saved by PushSection.
135 SmallVector<std::pair<MCSectionSubPair, MCSectionSubPair>, 4> SectionStack;
137 bool AutoInitSections;
140 MCStreamer(MCContext &Ctx, MCTargetStreamer *TargetStreamer);
142 const MCExpr *BuildSymbolDiff(MCContext &Context, const MCSymbol *A,
145 const MCExpr *ForceExpAbs(const MCExpr *Expr);
147 void RecordProcStart(MCDwarfFrameInfo &Frame);
148 virtual void EmitCFIStartProcImpl(MCDwarfFrameInfo &Frame);
149 void RecordProcEnd(MCDwarfFrameInfo &Frame);
150 virtual void EmitCFIEndProcImpl(MCDwarfFrameInfo &CurFrame);
151 void EmitFrames(MCAsmBackend *MAB, bool usingCFI);
153 MCWin64EHUnwindInfo *getCurrentW64UnwindInfo() {
154 return CurrentW64UnwindInfo;
156 void EmitW64Tables();
158 virtual void EmitRawTextImpl(StringRef String);
161 virtual ~MCStreamer();
165 virtual void reset();
167 MCContext &getContext() const { return Context; }
169 MCTargetStreamer &getTargetStreamer() {
170 assert(TargetStreamer);
171 return *TargetStreamer;
174 unsigned getNumFrameInfos() { return FrameInfos.size(); }
176 const MCDwarfFrameInfo &getFrameInfo(unsigned i) { return FrameInfos[i]; }
178 ArrayRef<MCDwarfFrameInfo> getFrameInfos() const { return FrameInfos; }
180 unsigned getNumW64UnwindInfos() { return W64UnwindInfos.size(); }
182 MCWin64EHUnwindInfo &getW64UnwindInfo(unsigned i) {
183 return *W64UnwindInfos[i];
186 void generateCompactUnwindEncodings(MCAsmBackend *MAB);
188 /// @name Assembly File Formatting.
191 /// isVerboseAsm - Return true if this streamer supports verbose assembly
192 /// and if it is enabled.
193 virtual bool isVerboseAsm() const { return false; }
195 /// hasRawTextSupport - Return true if this asm streamer supports emitting
196 /// unformatted text to the .s file with EmitRawText.
197 virtual bool hasRawTextSupport() const { return false; }
199 /// AddComment - Add a comment that can be emitted to the generated .s
200 /// file if applicable as a QoI issue to make the output of the compiler
201 /// more readable. This only affects the MCAsmStreamer, and only when
202 /// verbose assembly output is enabled.
204 /// If the comment includes embedded \n's, they will each get the comment
205 /// prefix as appropriate. The added comment should not end with a \n.
206 virtual void AddComment(const Twine &T) {}
208 /// GetCommentOS - Return a raw_ostream that comments can be written to.
209 /// Unlike AddComment, you are required to terminate comments with \n if you
211 virtual raw_ostream &GetCommentOS();
213 /// AddBlankLine - Emit a blank line to a .s file to pretty it up.
214 virtual void AddBlankLine() {}
218 /// @name Symbol & Section Management
221 /// getCurrentSection - Return the current section that the streamer is
222 /// emitting code to.
223 MCSectionSubPair getCurrentSection() const {
224 if (!SectionStack.empty())
225 return SectionStack.back().first;
226 return MCSectionSubPair();
229 /// getPreviousSection - Return the previous section that the streamer is
230 /// emitting code to.
231 MCSectionSubPair getPreviousSection() const {
232 if (!SectionStack.empty())
233 return SectionStack.back().second;
234 return MCSectionSubPair();
237 /// GetSymbolOrder - Returns an index to represent the order
238 /// a symbol was emitted in. (zero if we did not emit that symbol)
239 unsigned GetSymbolOrder(const MCSymbol *Sym) const {
240 return SymbolOrdering.lookup(Sym);
243 /// ChangeSection - Update streamer for a new active section.
245 /// This is called by PopSection and SwitchSection, if the current
247 virtual void ChangeSection(const MCSection *, const MCExpr *) = 0;
249 /// pushSection - Save the current and previous section on the
252 SectionStack.push_back(
253 std::make_pair(getCurrentSection(), getPreviousSection()));
256 /// popSection - Restore the current and previous section from
257 /// the section stack. Calls ChangeSection as needed.
259 /// Returns false if the stack was empty.
261 if (SectionStack.size() <= 1)
263 MCSectionSubPair oldSection = SectionStack.pop_back_val().first;
264 MCSectionSubPair curSection = SectionStack.back().first;
266 if (oldSection != curSection)
267 ChangeSection(curSection.first, curSection.second);
271 bool SubSection(const MCExpr *Subsection) {
272 if (SectionStack.empty())
275 SwitchSection(SectionStack.back().first.first, Subsection);
279 /// SwitchSection - Set the current section where code is being emitted to
280 /// @p Section. This is required to update CurSection.
282 /// This corresponds to assembler directives like .section, .text, etc.
283 void SwitchSection(const MCSection *Section, const MCExpr *Subsection = 0) {
284 assert(Section && "Cannot switch to a null section!");
285 MCSectionSubPair curSection = SectionStack.back().first;
286 SectionStack.back().second = curSection;
287 if (MCSectionSubPair(Section, Subsection) != curSection) {
288 SectionStack.back().first = MCSectionSubPair(Section, Subsection);
289 ChangeSection(Section, Subsection);
293 /// SwitchSectionNoChange - Set the current section where code is being
294 /// emitted to @p Section. This is required to update CurSection. This
295 /// version does not call ChangeSection.
296 void SwitchSectionNoChange(const MCSection *Section,
297 const MCExpr *Subsection = 0) {
298 assert(Section && "Cannot switch to a null section!");
299 MCSectionSubPair curSection = SectionStack.back().first;
300 SectionStack.back().second = curSection;
301 if (MCSectionSubPair(Section, Subsection) != curSection)
302 SectionStack.back().first = MCSectionSubPair(Section, Subsection);
305 /// Initialize the streamer.
306 void InitStreamer() {
307 if (AutoInitSections)
311 /// Tell this MCStreamer to call InitSections upon initialization.
312 void setAutoInitSections(bool AutoInitSections) {
313 this->AutoInitSections = AutoInitSections;
316 /// InitSections - Create the default sections and set the initial one.
317 virtual void InitSections() = 0;
319 /// InitToTextSection - Create a text section and switch the streamer to it.
320 virtual void InitToTextSection() = 0;
322 /// AssignSection - Sets the symbol's section.
324 /// Each emitted symbol will be tracked in the ordering table,
325 /// so we can sort on them later.
326 void AssignSection(MCSymbol *Symbol, const MCSection *Section);
328 /// EmitLabel - Emit a label for @p Symbol into the current section.
330 /// This corresponds to an assembler statement such as:
333 /// @param Symbol - The symbol to emit. A given symbol should only be
334 /// emitted as a label once, and symbols emitted as a label should never be
335 /// used in an assignment.
336 virtual void EmitLabel(MCSymbol *Symbol);
338 virtual void EmitDebugLabel(MCSymbol *Symbol);
340 virtual void EmitEHSymAttributes(const MCSymbol *Symbol, MCSymbol *EHSymbol);
342 /// EmitAssemblerFlag - Note in the output the specified @p Flag.
343 virtual void EmitAssemblerFlag(MCAssemblerFlag Flag) = 0;
345 /// EmitLinkerOptions - Emit the given list @p Options of strings as linker
346 /// options into the output.
347 virtual void EmitLinkerOptions(ArrayRef<std::string> Kind) {}
349 /// EmitDataRegion - Note in the output the specified region @p Kind.
350 virtual void EmitDataRegion(MCDataRegionType Kind) {}
352 /// EmitThumbFunc - Note in the output that the specified @p Func is
353 /// a Thumb mode function (ARM target only).
354 virtual void EmitThumbFunc(MCSymbol *Func) = 0;
356 /// getOrCreateSymbolData - Get symbol data for given symbol.
357 virtual MCSymbolData &getOrCreateSymbolData(MCSymbol *Symbol);
359 /// EmitAssignment - Emit an assignment of @p Value to @p Symbol.
361 /// This corresponds to an assembler statement such as:
364 /// The assignment generates no code, but has the side effect of binding the
365 /// value in the current context. For the assembly streamer, this prints the
366 /// binding into the .s file.
368 /// @param Symbol - The symbol being assigned to.
369 /// @param Value - The value for the symbol.
370 virtual void EmitAssignment(MCSymbol *Symbol, const MCExpr *Value) = 0;
372 /// EmitWeakReference - Emit an weak reference from @p Alias to @p Symbol.
374 /// This corresponds to an assembler statement such as:
375 /// .weakref alias, symbol
377 /// @param Alias - The alias that is being created.
378 /// @param Symbol - The symbol being aliased.
379 virtual void EmitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol) = 0;
381 /// EmitSymbolAttribute - Add the given @p Attribute to @p Symbol.
382 virtual bool EmitSymbolAttribute(MCSymbol *Symbol,
383 MCSymbolAttr Attribute) = 0;
385 /// EmitSymbolDesc - Set the @p DescValue for the @p Symbol.
387 /// @param Symbol - The symbol to have its n_desc field set.
388 /// @param DescValue - The value to set into the n_desc field.
389 virtual void EmitSymbolDesc(MCSymbol *Symbol, unsigned DescValue) = 0;
391 /// BeginCOFFSymbolDef - Start emitting COFF symbol definition
393 /// @param Symbol - The symbol to have its External & Type fields set.
394 virtual void BeginCOFFSymbolDef(const MCSymbol *Symbol) = 0;
396 /// EmitCOFFSymbolStorageClass - Emit the storage class of the symbol.
398 /// @param StorageClass - The storage class the symbol should have.
399 virtual void EmitCOFFSymbolStorageClass(int StorageClass) = 0;
401 /// EmitCOFFSymbolType - Emit the type of the symbol.
403 /// @param Type - A COFF type identifier (see COFF::SymbolType in X86COFF.h)
404 virtual void EmitCOFFSymbolType(int Type) = 0;
406 /// EndCOFFSymbolDef - Marks the end of the symbol definition.
407 virtual void EndCOFFSymbolDef() = 0;
409 /// EmitCOFFSecRel32 - Emits a COFF section relative relocation.
411 /// @param Symbol - Symbol the section relative realocation should point to.
412 virtual void EmitCOFFSecRel32(MCSymbol const *Symbol);
414 /// EmitELFSize - Emit an ELF .size directive.
416 /// This corresponds to an assembler statement such as:
417 /// .size symbol, expression
419 virtual void EmitELFSize(MCSymbol *Symbol, const MCExpr *Value) = 0;
421 /// EmitCommonSymbol - Emit a common symbol.
423 /// @param Symbol - The common symbol to emit.
424 /// @param Size - The size of the common symbol.
425 /// @param ByteAlignment - The alignment of the symbol if
426 /// non-zero. This must be a power of 2.
427 virtual void EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
428 unsigned ByteAlignment) = 0;
430 /// EmitLocalCommonSymbol - Emit a local common (.lcomm) symbol.
432 /// @param Symbol - The common symbol to emit.
433 /// @param Size - The size of the common symbol.
434 /// @param ByteAlignment - The alignment of the common symbol in bytes.
435 virtual void EmitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size,
436 unsigned ByteAlignment) = 0;
438 /// EmitZerofill - Emit the zerofill section and an optional symbol.
440 /// @param Section - The zerofill section to create and or to put the symbol
441 /// @param Symbol - The zerofill symbol to emit, if non-NULL.
442 /// @param Size - The size of the zerofill symbol.
443 /// @param ByteAlignment - The alignment of the zerofill symbol if
444 /// non-zero. This must be a power of 2 on some targets.
445 virtual void EmitZerofill(const MCSection *Section, MCSymbol *Symbol = 0,
446 uint64_t Size = 0, unsigned ByteAlignment = 0) = 0;
448 /// EmitTBSSSymbol - Emit a thread local bss (.tbss) symbol.
450 /// @param Section - The thread local common section.
451 /// @param Symbol - The thread local common symbol to emit.
452 /// @param Size - The size of the symbol.
453 /// @param ByteAlignment - The alignment of the thread local common symbol
454 /// if non-zero. This must be a power of 2 on some targets.
455 virtual void EmitTBSSSymbol(const MCSection *Section, MCSymbol *Symbol,
456 uint64_t Size, unsigned ByteAlignment = 0) = 0;
459 /// @name Generating Data
462 /// EmitBytes - Emit the bytes in \p Data into the output.
464 /// This is used to implement assembler directives such as .byte, .ascii,
466 virtual void EmitBytes(StringRef Data) = 0;
468 /// EmitValue - Emit the expression @p Value into the output as a native
469 /// integer of the given @p Size bytes.
471 /// This is used to implement assembler directives such as .word, .quad,
474 /// @param Value - The value to emit.
475 /// @param Size - The size of the integer (in bytes) to emit. This must
476 /// match a native machine width.
477 virtual void EmitValueImpl(const MCExpr *Value, unsigned Size) = 0;
479 void EmitValue(const MCExpr *Value, unsigned Size);
481 /// EmitIntValue - Special case of EmitValue that avoids the client having
482 /// to pass in a MCExpr for constant integers.
483 virtual void EmitIntValue(uint64_t Value, unsigned Size);
485 /// EmitAbsValue - Emit the Value, but try to avoid relocations. On MachO
486 /// this is done by producing
489 void EmitAbsValue(const MCExpr *Value, unsigned Size);
491 virtual void EmitULEB128Value(const MCExpr *Value) = 0;
493 virtual void EmitSLEB128Value(const MCExpr *Value) = 0;
495 /// EmitULEB128Value - Special case of EmitULEB128Value that avoids the
496 /// client having to pass in a MCExpr for constant integers.
497 void EmitULEB128IntValue(uint64_t Value, unsigned Padding = 0);
499 /// EmitSLEB128Value - Special case of EmitSLEB128Value that avoids the
500 /// client having to pass in a MCExpr for constant integers.
501 void EmitSLEB128IntValue(int64_t Value);
503 /// EmitSymbolValue - Special case of EmitValue that avoids the client
504 /// having to pass in a MCExpr for MCSymbols.
505 void EmitSymbolValue(const MCSymbol *Sym, unsigned Size);
507 /// EmitGPRel64Value - Emit the expression @p Value into the output as a
508 /// gprel64 (64-bit GP relative) value.
510 /// This is used to implement assembler directives such as .gpdword on
511 /// targets that support them.
512 virtual void EmitGPRel64Value(const MCExpr *Value);
514 /// EmitGPRel32Value - Emit the expression @p Value into the output as a
515 /// gprel32 (32-bit GP relative) value.
517 /// This is used to implement assembler directives such as .gprel32 on
518 /// targets that support them.
519 virtual void EmitGPRel32Value(const MCExpr *Value);
521 /// EmitFill - Emit NumBytes bytes worth of the value specified by
522 /// FillValue. This implements directives such as '.space'.
523 virtual void EmitFill(uint64_t NumBytes, uint8_t FillValue);
525 /// \brief Emit NumBytes worth of zeros.
526 /// This function properly handles data in virtual sections.
527 virtual void EmitZeros(uint64_t NumBytes);
529 /// EmitValueToAlignment - Emit some number of copies of @p Value until
530 /// the byte alignment @p ByteAlignment is reached.
532 /// If the number of bytes need to emit for the alignment is not a multiple
533 /// of @p ValueSize, then the contents of the emitted fill bytes is
536 /// This used to implement the .align assembler directive.
538 /// @param ByteAlignment - The alignment to reach. This must be a power of
539 /// two on some targets.
540 /// @param Value - The value to use when filling bytes.
541 /// @param ValueSize - The size of the integer (in bytes) to emit for
542 /// @p Value. This must match a native machine width.
543 /// @param MaxBytesToEmit - The maximum numbers of bytes to emit, or 0. If
544 /// the alignment cannot be reached in this many bytes, no bytes are
546 virtual void EmitValueToAlignment(unsigned ByteAlignment, int64_t Value = 0,
547 unsigned ValueSize = 1,
548 unsigned MaxBytesToEmit = 0) = 0;
550 /// EmitCodeAlignment - Emit nops until the byte alignment @p ByteAlignment
553 /// This used to align code where the alignment bytes may be executed. This
554 /// can emit different bytes for different sizes to optimize execution.
556 /// @param ByteAlignment - The alignment to reach. This must be a power of
557 /// two on some targets.
558 /// @param MaxBytesToEmit - The maximum numbers of bytes to emit, or 0. If
559 /// the alignment cannot be reached in this many bytes, no bytes are
561 virtual void EmitCodeAlignment(unsigned ByteAlignment,
562 unsigned MaxBytesToEmit = 0) = 0;
564 /// EmitValueToOffset - Emit some number of copies of @p Value until the
565 /// byte offset @p Offset is reached.
567 /// This is used to implement assembler directives such as .org.
569 /// @param Offset - The offset to reach. This may be an expression, but the
570 /// expression must be associated with the current section.
571 /// @param Value - The value to use when filling bytes.
572 /// @return false on success, true if the offset was invalid.
573 virtual bool EmitValueToOffset(const MCExpr *Offset,
574 unsigned char Value = 0) = 0;
578 /// EmitFileDirective - Switch to a new logical file. This is used to
579 /// implement the '.file "foo.c"' assembler directive.
580 virtual void EmitFileDirective(StringRef Filename) = 0;
582 /// Emit the "identifiers" directive. This implements the
583 /// '.ident "version foo"' assembler directive.
584 virtual void EmitIdent(StringRef IdentString) {}
586 /// EmitDwarfFileDirective - Associate a filename with a specified logical
587 /// file number. This implements the DWARF2 '.file 4 "foo.c"' assembler
589 virtual bool EmitDwarfFileDirective(unsigned FileNo, StringRef Directory,
590 StringRef Filename, unsigned CUID = 0);
592 /// EmitDwarfLocDirective - This implements the DWARF2
593 // '.loc fileno lineno ...' assembler directive.
594 virtual void EmitDwarfLocDirective(unsigned FileNo, unsigned Line,
595 unsigned Column, unsigned Flags,
596 unsigned Isa, unsigned Discriminator,
599 virtual void EmitDwarfAdvanceLineAddr(int64_t LineDelta,
600 const MCSymbol *LastLabel,
601 const MCSymbol *Label,
602 unsigned PointerSize) = 0;
604 virtual void EmitDwarfAdvanceFrameAddr(const MCSymbol *LastLabel,
605 const MCSymbol *Label) {}
607 void EmitDwarfSetLineAddr(int64_t LineDelta, const MCSymbol *Label,
610 virtual void EmitCompactUnwindEncoding(uint32_t CompactUnwindEncoding);
611 virtual void EmitCFISections(bool EH, bool Debug);
612 void EmitCFIStartProc();
613 void EmitCFIEndProc();
614 virtual void EmitCFIDefCfa(int64_t Register, int64_t Offset);
615 virtual void EmitCFIDefCfaOffset(int64_t Offset);
616 virtual void EmitCFIDefCfaRegister(int64_t Register);
617 virtual void EmitCFIOffset(int64_t Register, int64_t Offset);
618 virtual void EmitCFIPersonality(const MCSymbol *Sym, unsigned Encoding);
619 virtual void EmitCFILsda(const MCSymbol *Sym, unsigned Encoding);
620 virtual void EmitCFIRememberState();
621 virtual void EmitCFIRestoreState();
622 virtual void EmitCFISameValue(int64_t Register);
623 virtual void EmitCFIRestore(int64_t Register);
624 virtual void EmitCFIRelOffset(int64_t Register, int64_t Offset);
625 virtual void EmitCFIAdjustCfaOffset(int64_t Adjustment);
626 virtual void EmitCFIEscape(StringRef Values);
627 virtual void EmitCFISignalFrame();
628 virtual void EmitCFIUndefined(int64_t Register);
629 virtual void EmitCFIRegister(int64_t Register1, int64_t Register2);
630 virtual void EmitCFIWindowSave();
632 virtual void EmitWin64EHStartProc(const MCSymbol *Symbol);
633 virtual void EmitWin64EHEndProc();
634 virtual void EmitWin64EHStartChained();
635 virtual void EmitWin64EHEndChained();
636 virtual void EmitWin64EHHandler(const MCSymbol *Sym, bool Unwind,
638 virtual void EmitWin64EHHandlerData();
639 virtual void EmitWin64EHPushReg(unsigned Register);
640 virtual void EmitWin64EHSetFrame(unsigned Register, unsigned Offset);
641 virtual void EmitWin64EHAllocStack(unsigned Size);
642 virtual void EmitWin64EHSaveReg(unsigned Register, unsigned Offset);
643 virtual void EmitWin64EHSaveXMM(unsigned Register, unsigned Offset);
644 virtual void EmitWin64EHPushFrame(bool Code);
645 virtual void EmitWin64EHEndProlog();
647 /// EmitInstruction - Emit the given @p Instruction into the current
649 virtual void EmitInstruction(const MCInst &Inst) = 0;
651 /// \brief Set the bundle alignment mode from now on in the section.
652 /// The argument is the power of 2 to which the alignment is set. The
653 /// value 0 means turn the bundle alignment off.
654 virtual void EmitBundleAlignMode(unsigned AlignPow2) = 0;
656 /// \brief The following instructions are a bundle-locked group.
658 /// \param AlignToEnd - If true, the bundle-locked group will be aligned to
659 /// the end of a bundle.
660 virtual void EmitBundleLock(bool AlignToEnd) = 0;
662 /// \brief Ends a bundle-locked group.
663 virtual void EmitBundleUnlock() = 0;
665 /// EmitRawText - If this file is backed by a assembly streamer, this dumps
666 /// the specified string in the output .s file. This capability is
667 /// indicated by the hasRawTextSupport() predicate. By default this aborts.
668 void EmitRawText(const Twine &String);
670 /// Flush - Causes any cached state to be written out.
671 virtual void Flush() {}
673 /// FinishImpl - Streamer specific finalization.
674 virtual void FinishImpl() = 0;
675 /// Finish - Finish emission of machine code.
679 /// createNullStreamer - Create a dummy machine code streamer, which does
680 /// nothing. This is useful for timing the assembler front end.
681 MCStreamer *createNullStreamer(MCContext &Ctx);
683 /// createAsmStreamer - Create a machine code streamer which will print out
684 /// assembly for the native target, suitable for compiling with a native
687 /// \param InstPrint - If given, the instruction printer to use. If not given
688 /// the MCInst representation will be printed. This method takes ownership of
691 /// \param CE - If given, a code emitter to use to show the instruction
692 /// encoding inline with the assembly. This method takes ownership of \p CE.
694 /// \param TAB - If given, a target asm backend to use to show the fixup
695 /// information in conjunction with encoding information. This method takes
696 /// ownership of \p TAB.
698 /// \param ShowInst - Whether to show the MCInst representation inline with
700 MCStreamer *createAsmStreamer(MCContext &Ctx, MCTargetStreamer *TargetStreamer,
701 formatted_raw_ostream &OS, bool isVerboseAsm,
702 bool useLoc, bool useCFI, bool useDwarfDirectory,
703 MCInstPrinter *InstPrint = 0,
704 MCCodeEmitter *CE = 0, MCAsmBackend *TAB = 0,
705 bool ShowInst = false);
707 /// createMachOStreamer - Create a machine code streamer which will generate
708 /// Mach-O format object files.
710 /// Takes ownership of \p TAB and \p CE.
711 MCStreamer *createMachOStreamer(MCContext &Ctx, MCAsmBackend &TAB,
712 raw_ostream &OS, MCCodeEmitter *CE,
713 bool RelaxAll = false);
715 /// createWinCOFFStreamer - Create a machine code streamer which will
716 /// generate Microsoft COFF format object files.
718 /// Takes ownership of \p TAB and \p CE.
719 MCStreamer *createWinCOFFStreamer(MCContext &Ctx, MCAsmBackend &TAB,
720 MCCodeEmitter &CE, raw_ostream &OS,
721 bool RelaxAll = false);
723 /// createELFStreamer - Create a machine code streamer which will generate
724 /// ELF format object files.
725 MCStreamer *createELFStreamer(MCContext &Ctx, MCTargetStreamer *TargetStreamer,
726 MCAsmBackend &TAB, raw_ostream &OS,
727 MCCodeEmitter *CE, bool RelaxAll,
730 /// createPureStreamer - Create a machine code streamer which will generate
731 /// "pure" MC object files, for use with MC-JIT and testing tools.
733 /// Takes ownership of \p TAB and \p CE.
734 MCStreamer *createPureStreamer(MCContext &Ctx, MCAsmBackend &TAB,
735 raw_ostream &OS, MCCodeEmitter *CE);
737 } // end namespace llvm