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 {
79 virtual void anchor();
81 virtual void emitFnStart() = 0;
82 virtual void emitFnEnd() = 0;
83 virtual void emitCantUnwind() = 0;
84 virtual void emitPersonality(const MCSymbol *Personality) = 0;
85 virtual void emitHandlerData() = 0;
86 virtual void emitSetFP(unsigned FpReg, unsigned SpReg,
87 int64_t Offset = 0) = 0;
88 virtual void emitPad(int64_t Offset) = 0;
89 virtual void emitRegSave(const SmallVectorImpl<unsigned> &RegList,
92 virtual void switchVendor(StringRef Vendor) = 0;
93 virtual void emitAttribute(unsigned Attribute, unsigned Value) = 0;
94 virtual void emitTextAttribute(unsigned Attribute, StringRef String) = 0;
95 virtual void emitFPU(unsigned FPU) = 0;
96 virtual void finishAttributeSection() = 0;
99 /// MCStreamer - Streaming machine code generation interface. This interface
100 /// is intended to provide a programatic interface that is very similar to the
101 /// level that an assembler .s file provides. It has callbacks to emit bytes,
102 /// handle directives, etc. The implementation of this interface retains
103 /// state to know what the current section is etc.
105 /// There are multiple implementations of this interface: one for writing out
106 /// a .s file, and implementations that write out .o files of various formats.
110 OwningPtr<MCTargetStreamer> TargetStreamer;
112 MCStreamer(const MCStreamer &) LLVM_DELETED_FUNCTION;
113 MCStreamer &operator=(const MCStreamer &) LLVM_DELETED_FUNCTION;
118 std::vector<MCDwarfFrameInfo> FrameInfos;
119 MCDwarfFrameInfo *getCurrentFrameInfo();
120 MCSymbol *EmitCFICommon();
121 void EnsureValidFrame();
123 std::vector<MCWin64EHUnwindInfo *> W64UnwindInfos;
124 MCWin64EHUnwindInfo *CurrentW64UnwindInfo;
125 void setCurrentW64UnwindInfo(MCWin64EHUnwindInfo *Frame);
126 void EnsureValidW64UnwindInfo();
128 MCSymbol *LastSymbol;
130 // SymbolOrdering - Tracks an index to represent the order
131 // a symbol was emitted in. Zero means we did not emit that symbol.
132 DenseMap<const MCSymbol *, unsigned> SymbolOrdering;
134 /// SectionStack - This is stack of current and previous section
135 /// values saved by PushSection.
136 SmallVector<std::pair<MCSectionSubPair, MCSectionSubPair>, 4> SectionStack;
138 bool AutoInitSections;
141 MCStreamer(MCContext &Ctx, MCTargetStreamer *TargetStreamer);
143 const MCExpr *BuildSymbolDiff(MCContext &Context, const MCSymbol *A,
146 const MCExpr *ForceExpAbs(const MCExpr *Expr);
148 void RecordProcStart(MCDwarfFrameInfo &Frame);
149 virtual void EmitCFIStartProcImpl(MCDwarfFrameInfo &Frame);
150 void RecordProcEnd(MCDwarfFrameInfo &Frame);
151 virtual void EmitCFIEndProcImpl(MCDwarfFrameInfo &CurFrame);
152 void EmitFrames(MCAsmBackend *MAB, bool usingCFI);
154 MCWin64EHUnwindInfo *getCurrentW64UnwindInfo() {
155 return CurrentW64UnwindInfo;
157 void EmitW64Tables();
159 virtual void EmitRawTextImpl(StringRef String);
162 virtual ~MCStreamer();
166 virtual void reset();
168 MCContext &getContext() const { return Context; }
170 MCTargetStreamer &getTargetStreamer() {
171 assert(TargetStreamer);
172 return *TargetStreamer;
175 unsigned getNumFrameInfos() { return FrameInfos.size(); }
177 const MCDwarfFrameInfo &getFrameInfo(unsigned i) { return FrameInfos[i]; }
179 ArrayRef<MCDwarfFrameInfo> getFrameInfos() const { return FrameInfos; }
181 unsigned getNumW64UnwindInfos() { return W64UnwindInfos.size(); }
183 MCWin64EHUnwindInfo &getW64UnwindInfo(unsigned i) {
184 return *W64UnwindInfos[i];
187 void generateCompactUnwindEncodings(MCAsmBackend *MAB);
189 /// @name Assembly File Formatting.
192 /// isVerboseAsm - Return true if this streamer supports verbose assembly
193 /// and if it is enabled.
194 virtual bool isVerboseAsm() const { return false; }
196 /// hasRawTextSupport - Return true if this asm streamer supports emitting
197 /// unformatted text to the .s file with EmitRawText.
198 virtual bool hasRawTextSupport() const { return false; }
200 /// AddComment - Add a comment that can be emitted to the generated .s
201 /// file if applicable as a QoI issue to make the output of the compiler
202 /// more readable. This only affects the MCAsmStreamer, and only when
203 /// verbose assembly output is enabled.
205 /// If the comment includes embedded \n's, they will each get the comment
206 /// prefix as appropriate. The added comment should not end with a \n.
207 virtual void AddComment(const Twine &T) {}
209 /// GetCommentOS - Return a raw_ostream that comments can be written to.
210 /// Unlike AddComment, you are required to terminate comments with \n if you
212 virtual raw_ostream &GetCommentOS();
214 /// AddBlankLine - Emit a blank line to a .s file to pretty it up.
215 virtual void AddBlankLine() {}
219 /// @name Symbol & Section Management
222 /// getCurrentSection - Return the current section that the streamer is
223 /// emitting code to.
224 MCSectionSubPair getCurrentSection() const {
225 if (!SectionStack.empty())
226 return SectionStack.back().first;
227 return MCSectionSubPair();
230 /// getPreviousSection - Return the previous section that the streamer is
231 /// emitting code to.
232 MCSectionSubPair getPreviousSection() const {
233 if (!SectionStack.empty())
234 return SectionStack.back().second;
235 return MCSectionSubPair();
238 /// GetSymbolOrder - Returns an index to represent the order
239 /// a symbol was emitted in. (zero if we did not emit that symbol)
240 unsigned GetSymbolOrder(const MCSymbol *Sym) const {
241 return SymbolOrdering.lookup(Sym);
244 /// ChangeSection - Update streamer for a new active section.
246 /// This is called by PopSection and SwitchSection, if the current
248 virtual void ChangeSection(const MCSection *, const MCExpr *) = 0;
250 /// pushSection - Save the current and previous section on the
253 SectionStack.push_back(
254 std::make_pair(getCurrentSection(), getPreviousSection()));
257 /// popSection - Restore the current and previous section from
258 /// the section stack. Calls ChangeSection as needed.
260 /// Returns false if the stack was empty.
262 if (SectionStack.size() <= 1)
264 MCSectionSubPair oldSection = SectionStack.pop_back_val().first;
265 MCSectionSubPair curSection = SectionStack.back().first;
267 if (oldSection != curSection)
268 ChangeSection(curSection.first, curSection.second);
272 bool SubSection(const MCExpr *Subsection) {
273 if (SectionStack.empty())
276 SwitchSection(SectionStack.back().first.first, Subsection);
280 /// SwitchSection - Set the current section where code is being emitted to
281 /// @p Section. This is required to update CurSection.
283 /// This corresponds to assembler directives like .section, .text, etc.
284 void SwitchSection(const MCSection *Section, const MCExpr *Subsection = 0) {
285 assert(Section && "Cannot switch to a null section!");
286 MCSectionSubPair curSection = SectionStack.back().first;
287 SectionStack.back().second = curSection;
288 if (MCSectionSubPair(Section, Subsection) != curSection) {
289 SectionStack.back().first = MCSectionSubPair(Section, Subsection);
290 ChangeSection(Section, Subsection);
294 /// SwitchSectionNoChange - Set the current section where code is being
295 /// emitted to @p Section. This is required to update CurSection. This
296 /// version does not call ChangeSection.
297 void SwitchSectionNoChange(const MCSection *Section,
298 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);
306 /// Initialize the streamer.
307 void InitStreamer() {
308 if (AutoInitSections)
312 /// Tell this MCStreamer to call InitSections upon initialization.
313 void setAutoInitSections(bool AutoInitSections) {
314 this->AutoInitSections = AutoInitSections;
317 /// InitSections - Create the default sections and set the initial one.
318 virtual void InitSections() = 0;
320 /// InitToTextSection - Create a text section and switch the streamer to it.
321 virtual void InitToTextSection() = 0;
323 /// AssignSection - Sets the symbol's section.
325 /// Each emitted symbol will be tracked in the ordering table,
326 /// so we can sort on them later.
327 void AssignSection(MCSymbol *Symbol, const MCSection *Section);
329 /// EmitLabel - Emit a label for @p Symbol into the current section.
331 /// This corresponds to an assembler statement such as:
334 /// @param Symbol - The symbol to emit. A given symbol should only be
335 /// emitted as a label once, and symbols emitted as a label should never be
336 /// used in an assignment.
337 virtual void EmitLabel(MCSymbol *Symbol);
339 virtual void EmitDebugLabel(MCSymbol *Symbol);
341 virtual void EmitEHSymAttributes(const MCSymbol *Symbol, MCSymbol *EHSymbol);
343 /// EmitAssemblerFlag - Note in the output the specified @p Flag.
344 virtual void EmitAssemblerFlag(MCAssemblerFlag Flag) = 0;
346 /// EmitLinkerOptions - Emit the given list @p Options of strings as linker
347 /// options into the output.
348 virtual void EmitLinkerOptions(ArrayRef<std::string> Kind) {}
350 /// EmitDataRegion - Note in the output the specified region @p Kind.
351 virtual void EmitDataRegion(MCDataRegionType Kind) {}
353 /// EmitThumbFunc - Note in the output that the specified @p Func is
354 /// a Thumb mode function (ARM target only).
355 virtual void EmitThumbFunc(MCSymbol *Func) = 0;
357 /// getOrCreateSymbolData - Get symbol data for given symbol.
358 virtual MCSymbolData &getOrCreateSymbolData(MCSymbol *Symbol);
360 /// EmitAssignment - Emit an assignment of @p Value to @p Symbol.
362 /// This corresponds to an assembler statement such as:
365 /// The assignment generates no code, but has the side effect of binding the
366 /// value in the current context. For the assembly streamer, this prints the
367 /// binding into the .s file.
369 /// @param Symbol - The symbol being assigned to.
370 /// @param Value - The value for the symbol.
371 virtual void EmitAssignment(MCSymbol *Symbol, const MCExpr *Value) = 0;
373 /// EmitWeakReference - Emit an weak reference from @p Alias to @p Symbol.
375 /// This corresponds to an assembler statement such as:
376 /// .weakref alias, symbol
378 /// @param Alias - The alias that is being created.
379 /// @param Symbol - The symbol being aliased.
380 virtual void EmitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol) = 0;
382 /// EmitSymbolAttribute - Add the given @p Attribute to @p Symbol.
383 virtual bool EmitSymbolAttribute(MCSymbol *Symbol,
384 MCSymbolAttr Attribute) = 0;
386 /// EmitSymbolDesc - Set the @p DescValue for the @p Symbol.
388 /// @param Symbol - The symbol to have its n_desc field set.
389 /// @param DescValue - The value to set into the n_desc field.
390 virtual void EmitSymbolDesc(MCSymbol *Symbol, unsigned DescValue) = 0;
392 /// BeginCOFFSymbolDef - Start emitting COFF symbol definition
394 /// @param Symbol - The symbol to have its External & Type fields set.
395 virtual void BeginCOFFSymbolDef(const MCSymbol *Symbol) = 0;
397 /// EmitCOFFSymbolStorageClass - Emit the storage class of the symbol.
399 /// @param StorageClass - The storage class the symbol should have.
400 virtual void EmitCOFFSymbolStorageClass(int StorageClass) = 0;
402 /// EmitCOFFSymbolType - Emit the type of the symbol.
404 /// @param Type - A COFF type identifier (see COFF::SymbolType in X86COFF.h)
405 virtual void EmitCOFFSymbolType(int Type) = 0;
407 /// EndCOFFSymbolDef - Marks the end of the symbol definition.
408 virtual void EndCOFFSymbolDef() = 0;
410 /// EmitCOFFSecRel32 - Emits a COFF section relative relocation.
412 /// @param Symbol - Symbol the section relative realocation should point to.
413 virtual void EmitCOFFSecRel32(MCSymbol const *Symbol);
415 /// EmitELFSize - Emit an ELF .size directive.
417 /// This corresponds to an assembler statement such as:
418 /// .size symbol, expression
420 virtual void EmitELFSize(MCSymbol *Symbol, const MCExpr *Value) = 0;
422 /// EmitCommonSymbol - Emit a common symbol.
424 /// @param Symbol - The common symbol to emit.
425 /// @param Size - The size of the common symbol.
426 /// @param ByteAlignment - The alignment of the symbol if
427 /// non-zero. This must be a power of 2.
428 virtual void EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
429 unsigned ByteAlignment) = 0;
431 /// EmitLocalCommonSymbol - Emit a local common (.lcomm) symbol.
433 /// @param Symbol - The common symbol to emit.
434 /// @param Size - The size of the common symbol.
435 /// @param ByteAlignment - The alignment of the common symbol in bytes.
436 virtual void EmitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size,
437 unsigned ByteAlignment) = 0;
439 /// EmitZerofill - Emit the zerofill section and an optional symbol.
441 /// @param Section - The zerofill section to create and or to put the symbol
442 /// @param Symbol - The zerofill symbol to emit, if non-NULL.
443 /// @param Size - The size of the zerofill symbol.
444 /// @param ByteAlignment - The alignment of the zerofill symbol if
445 /// non-zero. This must be a power of 2 on some targets.
446 virtual void EmitZerofill(const MCSection *Section, MCSymbol *Symbol = 0,
447 uint64_t Size = 0, unsigned ByteAlignment = 0) = 0;
449 /// EmitTBSSSymbol - Emit a thread local bss (.tbss) symbol.
451 /// @param Section - The thread local common section.
452 /// @param Symbol - The thread local common symbol to emit.
453 /// @param Size - The size of the symbol.
454 /// @param ByteAlignment - The alignment of the thread local common symbol
455 /// if non-zero. This must be a power of 2 on some targets.
456 virtual void EmitTBSSSymbol(const MCSection *Section, MCSymbol *Symbol,
457 uint64_t Size, unsigned ByteAlignment = 0) = 0;
460 /// @name Generating Data
463 /// EmitBytes - Emit the bytes in \p Data into the output.
465 /// This is used to implement assembler directives such as .byte, .ascii,
467 virtual void EmitBytes(StringRef Data) = 0;
469 /// EmitValue - Emit the expression @p Value into the output as a native
470 /// integer of the given @p Size bytes.
472 /// This is used to implement assembler directives such as .word, .quad,
475 /// @param Value - The value to emit.
476 /// @param Size - The size of the integer (in bytes) to emit. This must
477 /// match a native machine width.
478 virtual void EmitValueImpl(const MCExpr *Value, unsigned Size) = 0;
480 void EmitValue(const MCExpr *Value, unsigned Size);
482 /// EmitIntValue - Special case of EmitValue that avoids the client having
483 /// to pass in a MCExpr for constant integers.
484 virtual void EmitIntValue(uint64_t Value, unsigned Size);
486 /// EmitAbsValue - Emit the Value, but try to avoid relocations. On MachO
487 /// this is done by producing
490 void EmitAbsValue(const MCExpr *Value, unsigned Size);
492 virtual void EmitULEB128Value(const MCExpr *Value) = 0;
494 virtual void EmitSLEB128Value(const MCExpr *Value) = 0;
496 /// EmitULEB128Value - Special case of EmitULEB128Value that avoids the
497 /// client having to pass in a MCExpr for constant integers.
498 void EmitULEB128IntValue(uint64_t Value, unsigned Padding = 0);
500 /// EmitSLEB128Value - Special case of EmitSLEB128Value that avoids the
501 /// client having to pass in a MCExpr for constant integers.
502 void EmitSLEB128IntValue(int64_t Value);
504 /// EmitSymbolValue - Special case of EmitValue that avoids the client
505 /// having to pass in a MCExpr for MCSymbols.
506 void EmitSymbolValue(const MCSymbol *Sym, unsigned Size);
508 /// EmitGPRel64Value - Emit the expression @p Value into the output as a
509 /// gprel64 (64-bit GP relative) value.
511 /// This is used to implement assembler directives such as .gpdword on
512 /// targets that support them.
513 virtual void EmitGPRel64Value(const MCExpr *Value);
515 /// EmitGPRel32Value - Emit the expression @p Value into the output as a
516 /// gprel32 (32-bit GP relative) value.
518 /// This is used to implement assembler directives such as .gprel32 on
519 /// targets that support them.
520 virtual void EmitGPRel32Value(const MCExpr *Value);
522 /// EmitFill - Emit NumBytes bytes worth of the value specified by
523 /// FillValue. This implements directives such as '.space'.
524 virtual void EmitFill(uint64_t NumBytes, uint8_t FillValue);
526 /// \brief Emit NumBytes worth of zeros.
527 /// This function properly handles data in virtual sections.
528 virtual void EmitZeros(uint64_t NumBytes);
530 /// EmitValueToAlignment - Emit some number of copies of @p Value until
531 /// the byte alignment @p ByteAlignment is reached.
533 /// If the number of bytes need to emit for the alignment is not a multiple
534 /// of @p ValueSize, then the contents of the emitted fill bytes is
537 /// This used to implement the .align assembler directive.
539 /// @param ByteAlignment - The alignment to reach. This must be a power of
540 /// two on some targets.
541 /// @param Value - The value to use when filling bytes.
542 /// @param ValueSize - The size of the integer (in bytes) to emit for
543 /// @p Value. This must match a native machine width.
544 /// @param MaxBytesToEmit - The maximum numbers of bytes to emit, or 0. If
545 /// the alignment cannot be reached in this many bytes, no bytes are
547 virtual void EmitValueToAlignment(unsigned ByteAlignment, int64_t Value = 0,
548 unsigned ValueSize = 1,
549 unsigned MaxBytesToEmit = 0) = 0;
551 /// EmitCodeAlignment - Emit nops until the byte alignment @p ByteAlignment
554 /// This used to align code where the alignment bytes may be executed. This
555 /// can emit different bytes for different sizes to optimize execution.
557 /// @param ByteAlignment - The alignment to reach. This must be a power of
558 /// two on some targets.
559 /// @param MaxBytesToEmit - The maximum numbers of bytes to emit, or 0. If
560 /// the alignment cannot be reached in this many bytes, no bytes are
562 virtual void EmitCodeAlignment(unsigned ByteAlignment,
563 unsigned MaxBytesToEmit = 0) = 0;
565 /// EmitValueToOffset - Emit some number of copies of @p Value until the
566 /// byte offset @p Offset is reached.
568 /// This is used to implement assembler directives such as .org.
570 /// @param Offset - The offset to reach. This may be an expression, but the
571 /// expression must be associated with the current section.
572 /// @param Value - The value to use when filling bytes.
573 /// @return false on success, true if the offset was invalid.
574 virtual bool EmitValueToOffset(const MCExpr *Offset,
575 unsigned char Value = 0) = 0;
579 /// EmitFileDirective - Switch to a new logical file. This is used to
580 /// implement the '.file "foo.c"' assembler directive.
581 virtual void EmitFileDirective(StringRef Filename) = 0;
583 /// Emit the "identifiers" directive. This implements the
584 /// '.ident "version foo"' assembler directive.
585 virtual void EmitIdent(StringRef IdentString) {}
587 /// EmitDwarfFileDirective - Associate a filename with a specified logical
588 /// file number. This implements the DWARF2 '.file 4 "foo.c"' assembler
590 virtual bool EmitDwarfFileDirective(unsigned FileNo, StringRef Directory,
591 StringRef Filename, unsigned CUID = 0);
593 /// EmitDwarfLocDirective - This implements the DWARF2
594 // '.loc fileno lineno ...' assembler directive.
595 virtual void EmitDwarfLocDirective(unsigned FileNo, unsigned Line,
596 unsigned Column, unsigned Flags,
597 unsigned Isa, unsigned Discriminator,
600 virtual void EmitDwarfAdvanceLineAddr(int64_t LineDelta,
601 const MCSymbol *LastLabel,
602 const MCSymbol *Label,
603 unsigned PointerSize) = 0;
605 virtual void EmitDwarfAdvanceFrameAddr(const MCSymbol *LastLabel,
606 const MCSymbol *Label) {}
608 void EmitDwarfSetLineAddr(int64_t LineDelta, const MCSymbol *Label,
611 virtual void EmitCompactUnwindEncoding(uint32_t CompactUnwindEncoding);
612 virtual void EmitCFISections(bool EH, bool Debug);
613 void EmitCFIStartProc();
614 void EmitCFIEndProc();
615 virtual void EmitCFIDefCfa(int64_t Register, int64_t Offset);
616 virtual void EmitCFIDefCfaOffset(int64_t Offset);
617 virtual void EmitCFIDefCfaRegister(int64_t Register);
618 virtual void EmitCFIOffset(int64_t Register, int64_t Offset);
619 virtual void EmitCFIPersonality(const MCSymbol *Sym, unsigned Encoding);
620 virtual void EmitCFILsda(const MCSymbol *Sym, unsigned Encoding);
621 virtual void EmitCFIRememberState();
622 virtual void EmitCFIRestoreState();
623 virtual void EmitCFISameValue(int64_t Register);
624 virtual void EmitCFIRestore(int64_t Register);
625 virtual void EmitCFIRelOffset(int64_t Register, int64_t Offset);
626 virtual void EmitCFIAdjustCfaOffset(int64_t Adjustment);
627 virtual void EmitCFIEscape(StringRef Values);
628 virtual void EmitCFISignalFrame();
629 virtual void EmitCFIUndefined(int64_t Register);
630 virtual void EmitCFIRegister(int64_t Register1, int64_t Register2);
631 virtual void EmitCFIWindowSave();
633 virtual void EmitWin64EHStartProc(const MCSymbol *Symbol);
634 virtual void EmitWin64EHEndProc();
635 virtual void EmitWin64EHStartChained();
636 virtual void EmitWin64EHEndChained();
637 virtual void EmitWin64EHHandler(const MCSymbol *Sym, bool Unwind,
639 virtual void EmitWin64EHHandlerData();
640 virtual void EmitWin64EHPushReg(unsigned Register);
641 virtual void EmitWin64EHSetFrame(unsigned Register, unsigned Offset);
642 virtual void EmitWin64EHAllocStack(unsigned Size);
643 virtual void EmitWin64EHSaveReg(unsigned Register, unsigned Offset);
644 virtual void EmitWin64EHSaveXMM(unsigned Register, unsigned Offset);
645 virtual void EmitWin64EHPushFrame(bool Code);
646 virtual void EmitWin64EHEndProlog();
648 /// EmitInstruction - Emit the given @p Instruction into the current
650 virtual void EmitInstruction(const MCInst &Inst) = 0;
652 /// \brief Set the bundle alignment mode from now on in the section.
653 /// The argument is the power of 2 to which the alignment is set. The
654 /// value 0 means turn the bundle alignment off.
655 virtual void EmitBundleAlignMode(unsigned AlignPow2) = 0;
657 /// \brief The following instructions are a bundle-locked group.
659 /// \param AlignToEnd - If true, the bundle-locked group will be aligned to
660 /// the end of a bundle.
661 virtual void EmitBundleLock(bool AlignToEnd) = 0;
663 /// \brief Ends a bundle-locked group.
664 virtual void EmitBundleUnlock() = 0;
666 /// EmitRawText - If this file is backed by a assembly streamer, this dumps
667 /// the specified string in the output .s file. This capability is
668 /// indicated by the hasRawTextSupport() predicate. By default this aborts.
669 void EmitRawText(const Twine &String);
671 /// Flush - Causes any cached state to be written out.
672 virtual void Flush() {}
674 /// FinishImpl - Streamer specific finalization.
675 virtual void FinishImpl() = 0;
676 /// Finish - Finish emission of machine code.
680 /// createNullStreamer - Create a dummy machine code streamer, which does
681 /// nothing. This is useful for timing the assembler front end.
682 MCStreamer *createNullStreamer(MCContext &Ctx);
684 /// createAsmStreamer - Create a machine code streamer which will print out
685 /// assembly for the native target, suitable for compiling with a native
688 /// \param InstPrint - If given, the instruction printer to use. If not given
689 /// the MCInst representation will be printed. This method takes ownership of
692 /// \param CE - If given, a code emitter to use to show the instruction
693 /// encoding inline with the assembly. This method takes ownership of \p CE.
695 /// \param TAB - If given, a target asm backend to use to show the fixup
696 /// information in conjunction with encoding information. This method takes
697 /// ownership of \p TAB.
699 /// \param ShowInst - Whether to show the MCInst representation inline with
701 MCStreamer *createAsmStreamer(MCContext &Ctx, MCTargetStreamer *TargetStreamer,
702 formatted_raw_ostream &OS, bool isVerboseAsm,
703 bool useLoc, bool useCFI, bool useDwarfDirectory,
704 MCInstPrinter *InstPrint = 0,
705 MCCodeEmitter *CE = 0, MCAsmBackend *TAB = 0,
706 bool ShowInst = false);
708 /// createMachOStreamer - Create a machine code streamer which will generate
709 /// Mach-O format object files.
711 /// Takes ownership of \p TAB and \p CE.
712 MCStreamer *createMachOStreamer(MCContext &Ctx, MCAsmBackend &TAB,
713 raw_ostream &OS, MCCodeEmitter *CE,
714 bool RelaxAll = false);
716 /// createWinCOFFStreamer - Create a machine code streamer which will
717 /// generate Microsoft COFF format object files.
719 /// Takes ownership of \p TAB and \p CE.
720 MCStreamer *createWinCOFFStreamer(MCContext &Ctx, MCAsmBackend &TAB,
721 MCCodeEmitter &CE, raw_ostream &OS,
722 bool RelaxAll = false);
724 /// createELFStreamer - Create a machine code streamer which will generate
725 /// ELF format object files.
726 MCStreamer *createELFStreamer(MCContext &Ctx, MCTargetStreamer *TargetStreamer,
727 MCAsmBackend &TAB, raw_ostream &OS,
728 MCCodeEmitter *CE, bool RelaxAll,
731 /// createPureStreamer - Create a machine code streamer which will generate
732 /// "pure" MC object files, for use with MC-JIT and testing tools.
734 /// Takes ownership of \p TAB and \p CE.
735 MCStreamer *createPureStreamer(MCContext &Ctx, MCAsmBackend &TAB,
736 raw_ostream &OS, MCCodeEmitter *CE);
738 } // end namespace llvm