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/MCLinkerOptimizationHint.h"
23 #include "llvm/MC/MCWin64EH.h"
24 #include "llvm/Support/DataTypes.h"
37 class MCSymbolRefExpr;
38 class MCSubtargetInfo;
42 class formatted_raw_ostream;
43 class AssemblerConstantPools;
45 typedef std::pair<const MCSection *, const MCExpr *> MCSectionSubPair;
47 /// Target specific streamer interface. This is used so that targets can
48 /// implement support for target specific assembly directives.
50 /// If target foo wants to use this, it should implement 3 classes:
51 /// * FooTargetStreamer : public MCTargetStreamer
52 /// * FooTargetAsmSreamer : public FooTargetStreamer
53 /// * FooTargetELFStreamer : public FooTargetStreamer
55 /// FooTargetStreamer should have a pure virtual method for each directive. For
56 /// example, for a ".bar symbol_name" directive, it should have
57 /// virtual emitBar(const MCSymbol &Symbol) = 0;
59 /// The FooTargetAsmSreamer and FooTargetELFStreamer classes implement the
60 /// method. The assembly streamer just prints ".bar symbol_name". The object
61 /// streamer does whatever is needed to implement .bar in the object file.
63 /// In the assembly printer and parser the target streamer can be used by
64 /// calling getTargetStreamer and casting it to FooTargetStreamer:
66 /// MCTargetStreamer &TS = OutStreamer.getTargetStreamer();
67 /// FooTargetStreamer &ATS = static_cast<FooTargetStreamer &>(TS);
69 /// The base classes FooTargetAsmSreamer and FooTargetELFStreamer should *never*
70 /// be treated differently. Callers should always talk to a FooTargetStreamer.
71 class MCTargetStreamer {
76 MCTargetStreamer(MCStreamer &S);
77 virtual ~MCTargetStreamer();
79 const MCStreamer &getStreamer() { return Streamer; }
81 // Allow a target to add behavior to the EmitLabel of MCStreamer.
82 virtual void emitLabel(MCSymbol *Symbol);
83 // Allow a target to add behavior to the emitAssignment of MCStreamer.
84 virtual void emitAssignment(MCSymbol *Symbol, const MCExpr *Value);
86 virtual void finish();
89 // FIXME: declared here because it is used from
90 // lib/CodeGen/AsmPrinter/ARMException.cpp.
91 class ARMTargetStreamer : public MCTargetStreamer {
93 ARMTargetStreamer(MCStreamer &S);
96 virtual void emitFnStart();
97 virtual void emitFnEnd();
98 virtual void emitCantUnwind();
99 virtual void emitPersonality(const MCSymbol *Personality);
100 virtual void emitPersonalityIndex(unsigned Index);
101 virtual void emitHandlerData();
102 virtual void emitSetFP(unsigned FpReg, unsigned SpReg,
104 virtual void emitMovSP(unsigned Reg, int64_t Offset = 0);
105 virtual void emitPad(int64_t Offset);
106 virtual void emitRegSave(const SmallVectorImpl<unsigned> &RegList,
108 virtual void emitUnwindRaw(int64_t StackOffset,
109 const SmallVectorImpl<uint8_t> &Opcodes);
111 virtual void switchVendor(StringRef Vendor);
112 virtual void emitAttribute(unsigned Attribute, unsigned Value);
113 virtual void emitTextAttribute(unsigned Attribute, StringRef String);
114 virtual void emitIntTextAttribute(unsigned Attribute, unsigned IntValue,
115 StringRef StringValue = "");
116 virtual void emitFPU(unsigned FPU);
117 virtual void emitArch(unsigned Arch);
118 virtual void emitObjectArch(unsigned Arch);
119 virtual void finishAttributeSection();
120 virtual void emitInst(uint32_t Inst, char Suffix = '\0');
122 virtual void AnnotateTLSDescriptorSequence(const MCSymbolRefExpr *SRE);
124 virtual void emitThumbSet(MCSymbol *Symbol, const MCExpr *Value);
126 void finish() override;
128 /// Callback used to implement the ldr= pseudo.
129 /// Add a new entry to the constant pool for the current section and return an
130 /// MCExpr that can be used to refer to the constant pool location.
131 const MCExpr *addConstantPoolEntry(const MCExpr *);
133 /// Callback used to implemnt the .ltorg directive.
134 /// Emit contents of constant pool for the current section.
135 void emitCurrentConstantPool();
138 std::unique_ptr<AssemblerConstantPools> ConstantPools;
141 /// MCStreamer - Streaming machine code generation interface. This interface
142 /// is intended to provide a programatic interface that is very similar to the
143 /// level that an assembler .s file provides. It has callbacks to emit bytes,
144 /// handle directives, etc. The implementation of this interface retains
145 /// state to know what the current section is etc.
147 /// There are multiple implementations of this interface: one for writing out
148 /// a .s file, and implementations that write out .o files of various formats.
152 std::unique_ptr<MCTargetStreamer> TargetStreamer;
154 MCStreamer(const MCStreamer &) LLVM_DELETED_FUNCTION;
155 MCStreamer &operator=(const MCStreamer &) LLVM_DELETED_FUNCTION;
157 std::vector<MCDwarfFrameInfo> FrameInfos;
158 MCDwarfFrameInfo *getCurrentFrameInfo();
159 MCSymbol *EmitCFICommon();
160 void EnsureValidFrame();
162 std::vector<MCWin64EHUnwindInfo *> W64UnwindInfos;
163 MCWin64EHUnwindInfo *CurrentW64UnwindInfo;
164 void setCurrentW64UnwindInfo(MCWin64EHUnwindInfo *Frame);
165 void EnsureValidW64UnwindInfo();
167 MCSymbol *LastSymbol;
169 // SymbolOrdering - Tracks an index to represent the order
170 // a symbol was emitted in. Zero means we did not emit that symbol.
171 DenseMap<const MCSymbol *, unsigned> SymbolOrdering;
173 /// SectionStack - This is stack of current and previous section
174 /// values saved by PushSection.
175 SmallVector<std::pair<MCSectionSubPair, MCSectionSubPair>, 4> SectionStack;
178 MCStreamer(MCContext &Ctx);
180 const MCExpr *BuildSymbolDiff(MCContext &Context, const MCSymbol *A,
183 const MCExpr *ForceExpAbs(const MCExpr *Expr);
185 void RecordProcStart(MCDwarfFrameInfo &Frame);
186 virtual void EmitCFIStartProcImpl(MCDwarfFrameInfo &Frame);
187 void RecordProcEnd(MCDwarfFrameInfo &Frame);
188 virtual void EmitCFIEndProcImpl(MCDwarfFrameInfo &CurFrame);
190 MCWin64EHUnwindInfo *getCurrentW64UnwindInfo() {
191 return CurrentW64UnwindInfo;
193 void EmitW64Tables();
195 virtual void EmitRawTextImpl(StringRef String);
198 virtual ~MCStreamer();
200 void setTargetStreamer(MCTargetStreamer *TS) {
201 TargetStreamer.reset(TS);
206 virtual void reset();
208 MCContext &getContext() const { return Context; }
210 MCTargetStreamer *getTargetStreamer() {
211 return TargetStreamer.get();
214 unsigned getNumFrameInfos() { return FrameInfos.size(); }
216 const MCDwarfFrameInfo &getFrameInfo(unsigned i) { return FrameInfos[i]; }
218 ArrayRef<MCDwarfFrameInfo> getFrameInfos() const { return FrameInfos; }
220 unsigned getNumW64UnwindInfos() { return W64UnwindInfos.size(); }
222 MCWin64EHUnwindInfo &getW64UnwindInfo(unsigned i) {
223 return *W64UnwindInfos[i];
226 void generateCompactUnwindEncodings(MCAsmBackend *MAB);
228 /// @name Assembly File Formatting.
231 /// isVerboseAsm - Return true if this streamer supports verbose assembly
232 /// and if it is enabled.
233 virtual bool isVerboseAsm() const { return false; }
235 /// hasRawTextSupport - Return true if this asm streamer supports emitting
236 /// unformatted text to the .s file with EmitRawText.
237 virtual bool hasRawTextSupport() const { return false; }
239 /// Is the integrated assembler required for this streamer to function
241 virtual bool isIntegratedAssemblerRequired() const { return false; }
243 /// AddComment - Add a comment that can be emitted to the generated .s
244 /// file if applicable as a QoI issue to make the output of the compiler
245 /// more readable. This only affects the MCAsmStreamer, and only when
246 /// verbose assembly output is enabled.
248 /// If the comment includes embedded \n's, they will each get the comment
249 /// prefix as appropriate. The added comment should not end with a \n.
250 virtual void AddComment(const Twine &T) {}
252 /// GetCommentOS - Return a raw_ostream that comments can be written to.
253 /// Unlike AddComment, you are required to terminate comments with \n if you
255 virtual raw_ostream &GetCommentOS();
257 /// Print T and prefix it with the comment string (normally #) and optionally
258 /// a tab. This prints the comment immediately, not at the end of the
259 /// current line. It is basically a safe version of EmitRawText: since it
260 /// only prints comments, the object streamer ignores it instead of asserting.
261 virtual void emitRawComment(const Twine &T, bool TabPrefix = true);
263 /// AddBlankLine - Emit a blank line to a .s file to pretty it up.
264 virtual void AddBlankLine() {}
268 /// @name Symbol & Section Management
271 /// getCurrentSection - Return the current section that the streamer is
272 /// emitting code to.
273 MCSectionSubPair getCurrentSection() const {
274 if (!SectionStack.empty())
275 return SectionStack.back().first;
276 return MCSectionSubPair();
279 /// getPreviousSection - Return the previous section that the streamer is
280 /// emitting code to.
281 MCSectionSubPair getPreviousSection() const {
282 if (!SectionStack.empty())
283 return SectionStack.back().second;
284 return MCSectionSubPair();
287 /// GetSymbolOrder - Returns an index to represent the order
288 /// a symbol was emitted in. (zero if we did not emit that symbol)
289 unsigned GetSymbolOrder(const MCSymbol *Sym) const {
290 return SymbolOrdering.lookup(Sym);
293 /// ChangeSection - Update streamer for a new active section.
295 /// This is called by PopSection and SwitchSection, if the current
297 virtual void ChangeSection(const MCSection *, const MCExpr *) = 0;
299 /// pushSection - Save the current and previous section on the
302 SectionStack.push_back(
303 std::make_pair(getCurrentSection(), getPreviousSection()));
306 /// popSection - Restore the current and previous section from
307 /// the section stack. Calls ChangeSection as needed.
309 /// Returns false if the stack was empty.
311 if (SectionStack.size() <= 1)
313 MCSectionSubPair oldSection = SectionStack.pop_back_val().first;
314 MCSectionSubPair curSection = SectionStack.back().first;
316 if (oldSection != curSection)
317 ChangeSection(curSection.first, curSection.second);
321 bool SubSection(const MCExpr *Subsection) {
322 if (SectionStack.empty())
325 SwitchSection(SectionStack.back().first.first, Subsection);
329 /// SwitchSection - Set the current section where code is being emitted to
330 /// @p Section. This is required to update CurSection.
332 /// This corresponds to assembler directives like .section, .text, etc.
333 void SwitchSection(const MCSection *Section,
334 const MCExpr *Subsection = nullptr) {
335 assert(Section && "Cannot switch to a null section!");
336 MCSectionSubPair curSection = SectionStack.back().first;
337 SectionStack.back().second = curSection;
338 if (MCSectionSubPair(Section, Subsection) != curSection) {
339 SectionStack.back().first = MCSectionSubPair(Section, Subsection);
340 ChangeSection(Section, Subsection);
344 /// SwitchSectionNoChange - Set the current section where code is being
345 /// emitted to @p Section. This is required to update CurSection. This
346 /// version does not call ChangeSection.
347 void SwitchSectionNoChange(const MCSection *Section,
348 const MCExpr *Subsection = nullptr) {
349 assert(Section && "Cannot switch to a null section!");
350 MCSectionSubPair curSection = SectionStack.back().first;
351 SectionStack.back().second = curSection;
352 if (MCSectionSubPair(Section, Subsection) != curSection)
353 SectionStack.back().first = MCSectionSubPair(Section, Subsection);
356 /// Create the default sections and set the initial one.
357 virtual void InitSections();
359 /// AssignSection - Sets the symbol's section.
361 /// Each emitted symbol will be tracked in the ordering table,
362 /// so we can sort on them later.
363 void AssignSection(MCSymbol *Symbol, const MCSection *Section);
365 /// EmitLabel - Emit a label for @p Symbol into the current section.
367 /// This corresponds to an assembler statement such as:
370 /// @param Symbol - The symbol to emit. A given symbol should only be
371 /// emitted as a label once, and symbols emitted as a label should never be
372 /// used in an assignment.
373 // FIXME: These emission are non-const because we mutate the symbol to
374 // add the section we're emitting it to later.
375 virtual void EmitLabel(MCSymbol *Symbol);
377 virtual void EmitDebugLabel(MCSymbol *Symbol);
379 virtual void EmitEHSymAttributes(const MCSymbol *Symbol, MCSymbol *EHSymbol);
381 /// EmitAssemblerFlag - Note in the output the specified @p Flag.
382 virtual void EmitAssemblerFlag(MCAssemblerFlag Flag) = 0;
384 /// EmitLinkerOptions - Emit the given list @p Options of strings as linker
385 /// options into the output.
386 virtual void EmitLinkerOptions(ArrayRef<std::string> Kind) {}
388 /// EmitDataRegion - Note in the output the specified region @p Kind.
389 virtual void EmitDataRegion(MCDataRegionType Kind) {}
391 /// EmitVersionMin - Specify the MachO minimum deployment target version.
392 virtual void EmitVersionMin(MCVersionMinType, unsigned Major, unsigned Minor,
395 /// EmitThumbFunc - Note in the output that the specified @p Func is
396 /// a Thumb mode function (ARM target only).
397 virtual void EmitThumbFunc(MCSymbol *Func) = 0;
399 /// EmitAssignment - Emit an assignment of @p Value to @p Symbol.
401 /// This corresponds to an assembler statement such as:
404 /// The assignment generates no code, but has the side effect of binding the
405 /// value in the current context. For the assembly streamer, this prints the
406 /// binding into the .s file.
408 /// @param Symbol - The symbol being assigned to.
409 /// @param Value - The value for the symbol.
410 virtual void EmitAssignment(MCSymbol *Symbol, const MCExpr *Value);
412 /// EmitWeakReference - Emit an weak reference from @p Alias to @p Symbol.
414 /// This corresponds to an assembler statement such as:
415 /// .weakref alias, symbol
417 /// @param Alias - The alias that is being created.
418 /// @param Symbol - The symbol being aliased.
419 virtual void EmitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol) = 0;
421 /// EmitSymbolAttribute - Add the given @p Attribute to @p Symbol.
422 virtual bool EmitSymbolAttribute(MCSymbol *Symbol,
423 MCSymbolAttr Attribute) = 0;
425 /// EmitSymbolDesc - Set the @p DescValue for the @p Symbol.
427 /// @param Symbol - The symbol to have its n_desc field set.
428 /// @param DescValue - The value to set into the n_desc field.
429 virtual void EmitSymbolDesc(MCSymbol *Symbol, unsigned DescValue) = 0;
431 /// BeginCOFFSymbolDef - Start emitting COFF symbol definition
433 /// @param Symbol - The symbol to have its External & Type fields set.
434 virtual void BeginCOFFSymbolDef(const MCSymbol *Symbol) = 0;
436 /// EmitCOFFSymbolStorageClass - Emit the storage class of the symbol.
438 /// @param StorageClass - The storage class the symbol should have.
439 virtual void EmitCOFFSymbolStorageClass(int StorageClass) = 0;
441 /// EmitCOFFSymbolType - Emit the type of the symbol.
443 /// @param Type - A COFF type identifier (see COFF::SymbolType in X86COFF.h)
444 virtual void EmitCOFFSymbolType(int Type) = 0;
446 /// EndCOFFSymbolDef - Marks the end of the symbol definition.
447 virtual void EndCOFFSymbolDef() = 0;
449 /// EmitCOFFSectionIndex - Emits a COFF section index.
451 /// @param Symbol - Symbol the section number relocation should point to.
452 virtual void EmitCOFFSectionIndex(MCSymbol const *Symbol);
454 /// EmitCOFFSecRel32 - Emits a COFF section relative relocation.
456 /// @param Symbol - Symbol the section relative relocation should point to.
457 virtual void EmitCOFFSecRel32(MCSymbol const *Symbol);
459 /// EmitELFSize - Emit an ELF .size directive.
461 /// This corresponds to an assembler statement such as:
462 /// .size symbol, expression
464 virtual void EmitELFSize(MCSymbol *Symbol, const MCExpr *Value) = 0;
466 /// \brief Emit a Linker Optimization Hint (LOH) directive.
467 /// \param Args - Arguments of the LOH.
468 virtual void EmitLOHDirective(MCLOHType Kind, const MCLOHArgs &Args) {}
470 /// EmitCommonSymbol - Emit a common symbol.
472 /// @param Symbol - The common symbol to emit.
473 /// @param Size - The size of the common symbol.
474 /// @param ByteAlignment - The alignment of the symbol if
475 /// non-zero. This must be a power of 2.
476 virtual void EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
477 unsigned ByteAlignment) = 0;
479 /// EmitLocalCommonSymbol - Emit a local common (.lcomm) symbol.
481 /// @param Symbol - The common symbol to emit.
482 /// @param Size - The size of the common symbol.
483 /// @param ByteAlignment - The alignment of the common symbol in bytes.
484 virtual void EmitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size,
485 unsigned ByteAlignment) = 0;
487 /// EmitZerofill - Emit the zerofill section and an optional symbol.
489 /// @param Section - The zerofill section to create and or to put the symbol
490 /// @param Symbol - The zerofill symbol to emit, if non-NULL.
491 /// @param Size - The size of the zerofill symbol.
492 /// @param ByteAlignment - The alignment of the zerofill symbol if
493 /// non-zero. This must be a power of 2 on some targets.
494 virtual void EmitZerofill(const MCSection *Section,
495 MCSymbol *Symbol = nullptr, uint64_t Size = 0,
496 unsigned ByteAlignment = 0) = 0;
498 /// EmitTBSSSymbol - Emit a thread local bss (.tbss) symbol.
500 /// @param Section - The thread local common section.
501 /// @param Symbol - The thread local common symbol to emit.
502 /// @param Size - The size of the symbol.
503 /// @param ByteAlignment - The alignment of the thread local common symbol
504 /// if non-zero. This must be a power of 2 on some targets.
505 virtual void EmitTBSSSymbol(const MCSection *Section, MCSymbol *Symbol,
506 uint64_t Size, unsigned ByteAlignment = 0) = 0;
509 /// @name Generating Data
512 /// EmitBytes - Emit the bytes in \p Data into the output.
514 /// This is used to implement assembler directives such as .byte, .ascii,
516 virtual void EmitBytes(StringRef Data) = 0;
518 /// EmitValue - Emit the expression @p Value into the output as a native
519 /// integer of the given @p Size bytes.
521 /// This is used to implement assembler directives such as .word, .quad,
524 /// @param Value - The value to emit.
525 /// @param Size - The size of the integer (in bytes) to emit. This must
526 /// match a native machine width.
527 /// @param Loc - The location of the expression for error reporting.
528 virtual void EmitValueImpl(const MCExpr *Value, unsigned Size,
529 const SMLoc &Loc = SMLoc()) = 0;
531 void EmitValue(const MCExpr *Value, unsigned Size,
532 const SMLoc &Loc = SMLoc());
534 /// EmitIntValue - Special case of EmitValue that avoids the client having
535 /// to pass in a MCExpr for constant integers.
536 virtual void EmitIntValue(uint64_t Value, unsigned Size);
538 /// EmitAbsValue - Emit the Value, but try to avoid relocations. On MachO
539 /// this is done by producing
542 void EmitAbsValue(const MCExpr *Value, unsigned Size);
544 virtual void EmitULEB128Value(const MCExpr *Value) = 0;
546 virtual void EmitSLEB128Value(const MCExpr *Value) = 0;
548 /// EmitULEB128Value - Special case of EmitULEB128Value that avoids the
549 /// client having to pass in a MCExpr for constant integers.
550 void EmitULEB128IntValue(uint64_t Value, unsigned Padding = 0);
552 /// EmitSLEB128Value - Special case of EmitSLEB128Value that avoids the
553 /// client having to pass in a MCExpr for constant integers.
554 void EmitSLEB128IntValue(int64_t Value);
556 /// EmitSymbolValue - Special case of EmitValue that avoids the client
557 /// having to pass in a MCExpr for MCSymbols.
558 void EmitSymbolValue(const MCSymbol *Sym, unsigned Size);
560 /// EmitGPRel64Value - Emit the expression @p Value into the output as a
561 /// gprel64 (64-bit GP relative) value.
563 /// This is used to implement assembler directives such as .gpdword on
564 /// targets that support them.
565 virtual void EmitGPRel64Value(const MCExpr *Value);
567 /// EmitGPRel32Value - Emit the expression @p Value into the output as a
568 /// gprel32 (32-bit GP relative) value.
570 /// This is used to implement assembler directives such as .gprel32 on
571 /// targets that support them.
572 virtual void EmitGPRel32Value(const MCExpr *Value);
574 /// EmitFill - Emit NumBytes bytes worth of the value specified by
575 /// FillValue. This implements directives such as '.space'.
576 virtual void EmitFill(uint64_t NumBytes, uint8_t FillValue);
578 /// \brief Emit NumBytes worth of zeros.
579 /// This function properly handles data in virtual sections.
580 virtual void EmitZeros(uint64_t NumBytes);
582 /// EmitValueToAlignment - Emit some number of copies of @p Value until
583 /// the byte alignment @p ByteAlignment is reached.
585 /// If the number of bytes need to emit for the alignment is not a multiple
586 /// of @p ValueSize, then the contents of the emitted fill bytes is
589 /// This used to implement the .align assembler directive.
591 /// @param ByteAlignment - The alignment to reach. This must be a power of
592 /// two on some targets.
593 /// @param Value - The value to use when filling bytes.
594 /// @param ValueSize - The size of the integer (in bytes) to emit for
595 /// @p Value. This must match a native machine width.
596 /// @param MaxBytesToEmit - The maximum numbers of bytes to emit, or 0. If
597 /// the alignment cannot be reached in this many bytes, no bytes are
599 virtual void EmitValueToAlignment(unsigned ByteAlignment, int64_t Value = 0,
600 unsigned ValueSize = 1,
601 unsigned MaxBytesToEmit = 0) = 0;
603 /// EmitCodeAlignment - Emit nops until the byte alignment @p ByteAlignment
606 /// This used to align code where the alignment bytes may be executed. This
607 /// can emit different bytes for different sizes to optimize execution.
609 /// @param ByteAlignment - The alignment to reach. This must be a power of
610 /// two on some targets.
611 /// @param MaxBytesToEmit - The maximum numbers of bytes to emit, or 0. If
612 /// the alignment cannot be reached in this many bytes, no bytes are
614 virtual void EmitCodeAlignment(unsigned ByteAlignment,
615 unsigned MaxBytesToEmit = 0) = 0;
617 /// EmitValueToOffset - Emit some number of copies of @p Value until the
618 /// byte offset @p Offset is reached.
620 /// This is used to implement assembler directives such as .org.
622 /// @param Offset - The offset to reach. This may be an expression, but the
623 /// expression must be associated with the current section.
624 /// @param Value - The value to use when filling bytes.
625 /// @return false on success, true if the offset was invalid.
626 virtual bool EmitValueToOffset(const MCExpr *Offset,
627 unsigned char Value = 0) = 0;
631 /// EmitFileDirective - Switch to a new logical file. This is used to
632 /// implement the '.file "foo.c"' assembler directive.
633 virtual void EmitFileDirective(StringRef Filename) = 0;
635 /// Emit the "identifiers" directive. This implements the
636 /// '.ident "version foo"' assembler directive.
637 virtual void EmitIdent(StringRef IdentString) {}
639 /// EmitDwarfFileDirective - Associate a filename with a specified logical
640 /// file number. This implements the DWARF2 '.file 4 "foo.c"' assembler
642 virtual unsigned EmitDwarfFileDirective(unsigned FileNo, StringRef Directory,
646 /// EmitDwarfLocDirective - This implements the DWARF2
647 // '.loc fileno lineno ...' assembler directive.
648 virtual void EmitDwarfLocDirective(unsigned FileNo, unsigned Line,
649 unsigned Column, unsigned Flags,
650 unsigned Isa, unsigned Discriminator,
653 virtual MCSymbol *getDwarfLineTableSymbol(unsigned CUID);
655 void EmitDwarfSetLineAddr(int64_t LineDelta, const MCSymbol *Label,
658 virtual void EmitCompactUnwindEncoding(uint32_t CompactUnwindEncoding);
659 virtual void EmitCFISections(bool EH, bool Debug);
660 void EmitCFIStartProc(bool IsSimple);
661 void EmitCFIEndProc();
662 virtual void EmitCFIDefCfa(int64_t Register, int64_t Offset);
663 virtual void EmitCFIDefCfaOffset(int64_t Offset);
664 virtual void EmitCFIDefCfaRegister(int64_t Register);
665 virtual void EmitCFIOffset(int64_t Register, int64_t Offset);
666 virtual void EmitCFIPersonality(const MCSymbol *Sym, unsigned Encoding);
667 virtual void EmitCFILsda(const MCSymbol *Sym, unsigned Encoding);
668 virtual void EmitCFIRememberState();
669 virtual void EmitCFIRestoreState();
670 virtual void EmitCFISameValue(int64_t Register);
671 virtual void EmitCFIRestore(int64_t Register);
672 virtual void EmitCFIRelOffset(int64_t Register, int64_t Offset);
673 virtual void EmitCFIAdjustCfaOffset(int64_t Adjustment);
674 virtual void EmitCFIEscape(StringRef Values);
675 virtual void EmitCFISignalFrame();
676 virtual void EmitCFIUndefined(int64_t Register);
677 virtual void EmitCFIRegister(int64_t Register1, int64_t Register2);
678 virtual void EmitCFIWindowSave();
680 virtual void EmitWin64EHStartProc(const MCSymbol *Symbol);
681 virtual void EmitWin64EHEndProc();
682 virtual void EmitWin64EHStartChained();
683 virtual void EmitWin64EHEndChained();
684 virtual void EmitWin64EHHandler(const MCSymbol *Sym, bool Unwind,
686 virtual void EmitWin64EHHandlerData();
687 virtual void EmitWin64EHPushReg(unsigned Register);
688 virtual void EmitWin64EHSetFrame(unsigned Register, unsigned Offset);
689 virtual void EmitWin64EHAllocStack(unsigned Size);
690 virtual void EmitWin64EHSaveReg(unsigned Register, unsigned Offset);
691 virtual void EmitWin64EHSaveXMM(unsigned Register, unsigned Offset);
692 virtual void EmitWin64EHPushFrame(bool Code);
693 virtual void EmitWin64EHEndProlog();
695 /// EmitInstruction - Emit the given @p Instruction into the current
697 virtual void EmitInstruction(const MCInst &Inst, const MCSubtargetInfo &STI) = 0;
699 /// \brief Set the bundle alignment mode from now on in the section.
700 /// The argument is the power of 2 to which the alignment is set. The
701 /// value 0 means turn the bundle alignment off.
702 virtual void EmitBundleAlignMode(unsigned AlignPow2) = 0;
704 /// \brief The following instructions are a bundle-locked group.
706 /// \param AlignToEnd - If true, the bundle-locked group will be aligned to
707 /// the end of a bundle.
708 virtual void EmitBundleLock(bool AlignToEnd) = 0;
710 /// \brief Ends a bundle-locked group.
711 virtual void EmitBundleUnlock() = 0;
713 /// EmitRawText - If this file is backed by a assembly streamer, this dumps
714 /// the specified string in the output .s file. This capability is
715 /// indicated by the hasRawTextSupport() predicate. By default this aborts.
716 void EmitRawText(const Twine &String);
718 /// Flush - Causes any cached state to be written out.
719 virtual void Flush() {}
721 /// FinishImpl - Streamer specific finalization.
722 virtual void FinishImpl() = 0;
723 /// Finish - Finish emission of machine code.
726 virtual bool mayHaveInstructions() const { return true; }
729 /// createNullStreamer - Create a dummy machine code streamer, which does
730 /// nothing. This is useful for timing the assembler front end.
731 MCStreamer *createNullStreamer(MCContext &Ctx);
733 /// createAsmStreamer - Create a machine code streamer which will print out
734 /// assembly for the native target, suitable for compiling with a native
737 /// \param InstPrint - If given, the instruction printer to use. If not given
738 /// the MCInst representation will be printed. This method takes ownership of
741 /// \param CE - If given, a code emitter to use to show the instruction
742 /// encoding inline with the assembly. This method takes ownership of \p CE.
744 /// \param TAB - If given, a target asm backend to use to show the fixup
745 /// information in conjunction with encoding information. This method takes
746 /// ownership of \p TAB.
748 /// \param ShowInst - Whether to show the MCInst representation inline with
750 MCStreamer *createAsmStreamer(MCContext &Ctx, formatted_raw_ostream &OS,
751 bool isVerboseAsm, bool useDwarfDirectory,
752 MCInstPrinter *InstPrint, MCCodeEmitter *CE,
753 MCAsmBackend *TAB, bool ShowInst);
755 /// createMachOStreamer - Create a machine code streamer which will generate
756 /// Mach-O format object files.
758 /// Takes ownership of \p TAB and \p CE.
759 MCStreamer *createMachOStreamer(MCContext &Ctx, MCAsmBackend &TAB,
760 raw_ostream &OS, MCCodeEmitter *CE,
761 bool RelaxAll = false,
762 bool LabelSections = false);
764 /// createELFStreamer - Create a machine code streamer which will generate
765 /// ELF format object files.
766 MCStreamer *createELFStreamer(MCContext &Ctx, MCAsmBackend &TAB,
767 raw_ostream &OS, MCCodeEmitter *CE, bool RelaxAll,
770 } // end namespace llvm