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 class AArch64TargetStreamer : public MCTargetStreamer {
91 AArch64TargetStreamer(MCStreamer &S);
92 ~AArch64TargetStreamer();
95 void finish() override;
97 /// Callback used to implement the ldr= pseudo.
98 /// Add a new entry to the constant pool for the current section and return an
99 /// MCExpr that can be used to refer to the constant pool location.
100 const MCExpr *addConstantPoolEntry(const MCExpr *);
102 /// Callback used to implemnt the .ltorg directive.
103 /// Emit contents of constant pool for the current section.
104 void emitCurrentConstantPool();
107 std::unique_ptr<AssemblerConstantPools> ConstantPools;
110 // FIXME: declared here because it is used from
111 // lib/CodeGen/AsmPrinter/ARMException.cpp.
112 class ARMTargetStreamer : public MCTargetStreamer {
114 ARMTargetStreamer(MCStreamer &S);
115 ~ARMTargetStreamer();
117 virtual void emitFnStart();
118 virtual void emitFnEnd();
119 virtual void emitCantUnwind();
120 virtual void emitPersonality(const MCSymbol *Personality);
121 virtual void emitPersonalityIndex(unsigned Index);
122 virtual void emitHandlerData();
123 virtual void emitSetFP(unsigned FpReg, unsigned SpReg,
125 virtual void emitMovSP(unsigned Reg, int64_t Offset = 0);
126 virtual void emitPad(int64_t Offset);
127 virtual void emitRegSave(const SmallVectorImpl<unsigned> &RegList,
129 virtual void emitUnwindRaw(int64_t StackOffset,
130 const SmallVectorImpl<uint8_t> &Opcodes);
132 virtual void switchVendor(StringRef Vendor);
133 virtual void emitAttribute(unsigned Attribute, unsigned Value);
134 virtual void emitTextAttribute(unsigned Attribute, StringRef String);
135 virtual void emitIntTextAttribute(unsigned Attribute, unsigned IntValue,
136 StringRef StringValue = "");
137 virtual void emitFPU(unsigned FPU);
138 virtual void emitArch(unsigned Arch);
139 virtual void emitObjectArch(unsigned Arch);
140 virtual void finishAttributeSection();
141 virtual void emitInst(uint32_t Inst, char Suffix = '\0');
143 virtual void AnnotateTLSDescriptorSequence(const MCSymbolRefExpr *SRE);
145 virtual void emitThumbSet(MCSymbol *Symbol, const MCExpr *Value);
147 void finish() override;
149 /// Callback used to implement the ldr= pseudo.
150 /// Add a new entry to the constant pool for the current section and return an
151 /// MCExpr that can be used to refer to the constant pool location.
152 const MCExpr *addConstantPoolEntry(const MCExpr *);
154 /// Callback used to implemnt the .ltorg directive.
155 /// Emit contents of constant pool for the current section.
156 void emitCurrentConstantPool();
159 std::unique_ptr<AssemblerConstantPools> ConstantPools;
162 /// MCStreamer - Streaming machine code generation interface. This interface
163 /// is intended to provide a programatic interface that is very similar to the
164 /// level that an assembler .s file provides. It has callbacks to emit bytes,
165 /// handle directives, etc. The implementation of this interface retains
166 /// state to know what the current section is etc.
168 /// There are multiple implementations of this interface: one for writing out
169 /// a .s file, and implementations that write out .o files of various formats.
173 std::unique_ptr<MCTargetStreamer> TargetStreamer;
175 MCStreamer(const MCStreamer &) LLVM_DELETED_FUNCTION;
176 MCStreamer &operator=(const MCStreamer &) LLVM_DELETED_FUNCTION;
178 std::vector<MCDwarfFrameInfo> FrameInfos;
179 MCDwarfFrameInfo *getCurrentFrameInfo();
180 MCSymbol *EmitCFICommon();
181 void EnsureValidFrame();
183 std::vector<MCWin64EHUnwindInfo *> W64UnwindInfos;
184 MCWin64EHUnwindInfo *CurrentW64UnwindInfo;
185 void setCurrentW64UnwindInfo(MCWin64EHUnwindInfo *Frame);
186 void EnsureValidW64UnwindInfo();
188 // SymbolOrdering - Tracks an index to represent the order
189 // a symbol was emitted in. Zero means we did not emit that symbol.
190 DenseMap<const MCSymbol *, unsigned> SymbolOrdering;
192 /// SectionStack - This is stack of current and previous section
193 /// values saved by PushSection.
194 SmallVector<std::pair<MCSectionSubPair, MCSectionSubPair>, 4> SectionStack;
197 MCStreamer(MCContext &Ctx);
199 const MCExpr *BuildSymbolDiff(MCContext &Context, const MCSymbol *A,
202 const MCExpr *ForceExpAbs(const MCExpr *Expr);
204 virtual void EmitCFIStartProcImpl(MCDwarfFrameInfo &Frame);
205 virtual void EmitCFIEndProcImpl(MCDwarfFrameInfo &CurFrame);
207 MCWin64EHUnwindInfo *getCurrentW64UnwindInfo() {
208 return CurrentW64UnwindInfo;
210 void EmitW64Tables();
212 virtual void EmitRawTextImpl(StringRef String);
215 virtual ~MCStreamer();
217 void visitUsedExpr(const MCExpr &Expr);
218 virtual void visitUsedSymbol(const MCSymbol &Sym);
220 void setTargetStreamer(MCTargetStreamer *TS) {
221 TargetStreamer.reset(TS);
226 virtual void reset();
228 MCContext &getContext() const { return Context; }
230 MCTargetStreamer *getTargetStreamer() {
231 return TargetStreamer.get();
234 unsigned getNumFrameInfos() { return FrameInfos.size(); }
236 const MCDwarfFrameInfo &getFrameInfo(unsigned i) { return FrameInfos[i]; }
238 ArrayRef<MCDwarfFrameInfo> getFrameInfos() const { return FrameInfos; }
240 unsigned getNumW64UnwindInfos() { return W64UnwindInfos.size(); }
242 MCWin64EHUnwindInfo &getW64UnwindInfo(unsigned i) {
243 return *W64UnwindInfos[i];
246 ArrayRef<MCWin64EHUnwindInfo *> getW64UnwindInfos() const {
247 return W64UnwindInfos;
250 void generateCompactUnwindEncodings(MCAsmBackend *MAB);
252 /// @name Assembly File Formatting.
255 /// isVerboseAsm - Return true if this streamer supports verbose assembly
256 /// and if it is enabled.
257 virtual bool isVerboseAsm() const { return false; }
259 /// hasRawTextSupport - Return true if this asm streamer supports emitting
260 /// unformatted text to the .s file with EmitRawText.
261 virtual bool hasRawTextSupport() const { return false; }
263 /// Is the integrated assembler required for this streamer to function
265 virtual bool isIntegratedAssemblerRequired() const { return false; }
267 /// AddComment - Add a comment that can be emitted to the generated .s
268 /// file if applicable as a QoI issue to make the output of the compiler
269 /// more readable. This only affects the MCAsmStreamer, and only when
270 /// verbose assembly output is enabled.
272 /// If the comment includes embedded \n's, they will each get the comment
273 /// prefix as appropriate. The added comment should not end with a \n.
274 virtual void AddComment(const Twine &T) {}
276 /// GetCommentOS - Return a raw_ostream that comments can be written to.
277 /// Unlike AddComment, you are required to terminate comments with \n if you
279 virtual raw_ostream &GetCommentOS();
281 /// Print T and prefix it with the comment string (normally #) and optionally
282 /// a tab. This prints the comment immediately, not at the end of the
283 /// current line. It is basically a safe version of EmitRawText: since it
284 /// only prints comments, the object streamer ignores it instead of asserting.
285 virtual void emitRawComment(const Twine &T, bool TabPrefix = true);
287 /// AddBlankLine - Emit a blank line to a .s file to pretty it up.
288 virtual void AddBlankLine() {}
292 /// @name Symbol & Section Management
295 /// getCurrentSection - Return the current section that the streamer is
296 /// emitting code to.
297 MCSectionSubPair getCurrentSection() const {
298 if (!SectionStack.empty())
299 return SectionStack.back().first;
300 return MCSectionSubPair();
303 /// getPreviousSection - Return the previous section that the streamer is
304 /// emitting code to.
305 MCSectionSubPair getPreviousSection() const {
306 if (!SectionStack.empty())
307 return SectionStack.back().second;
308 return MCSectionSubPair();
311 /// GetSymbolOrder - Returns an index to represent the order
312 /// a symbol was emitted in. (zero if we did not emit that symbol)
313 unsigned GetSymbolOrder(const MCSymbol *Sym) const {
314 return SymbolOrdering.lookup(Sym);
317 /// ChangeSection - Update streamer for a new active section.
319 /// This is called by PopSection and SwitchSection, if the current
321 virtual void ChangeSection(const MCSection *, const MCExpr *);
323 /// pushSection - Save the current and previous section on the
326 SectionStack.push_back(
327 std::make_pair(getCurrentSection(), getPreviousSection()));
330 /// popSection - Restore the current and previous section from
331 /// the section stack. Calls ChangeSection as needed.
333 /// Returns false if the stack was empty.
335 if (SectionStack.size() <= 1)
337 MCSectionSubPair oldSection = SectionStack.pop_back_val().first;
338 MCSectionSubPair curSection = SectionStack.back().first;
340 if (oldSection != curSection)
341 ChangeSection(curSection.first, curSection.second);
345 bool SubSection(const MCExpr *Subsection) {
346 if (SectionStack.empty())
349 SwitchSection(SectionStack.back().first.first, Subsection);
353 /// SwitchSection - Set the current section where code is being emitted to
354 /// @p Section. This is required to update CurSection.
356 /// This corresponds to assembler directives like .section, .text, etc.
357 void SwitchSection(const MCSection *Section,
358 const MCExpr *Subsection = nullptr) {
359 assert(Section && "Cannot switch to a null section!");
360 MCSectionSubPair curSection = SectionStack.back().first;
361 SectionStack.back().second = curSection;
362 if (MCSectionSubPair(Section, Subsection) != curSection) {
363 SectionStack.back().first = MCSectionSubPair(Section, Subsection);
364 ChangeSection(Section, Subsection);
368 /// SwitchSectionNoChange - Set the current section where code is being
369 /// emitted to @p Section. This is required to update CurSection. This
370 /// version does not call ChangeSection.
371 void SwitchSectionNoChange(const MCSection *Section,
372 const MCExpr *Subsection = nullptr) {
373 assert(Section && "Cannot switch to a null section!");
374 MCSectionSubPair curSection = SectionStack.back().first;
375 SectionStack.back().second = curSection;
376 if (MCSectionSubPair(Section, Subsection) != curSection)
377 SectionStack.back().first = MCSectionSubPair(Section, Subsection);
380 /// Create the default sections and set the initial one.
381 virtual void InitSections();
383 /// AssignSection - Sets the symbol's section.
385 /// Each emitted symbol will be tracked in the ordering table,
386 /// so we can sort on them later.
387 void AssignSection(MCSymbol *Symbol, const MCSection *Section);
389 /// EmitLabel - Emit a label for @p Symbol into the current section.
391 /// This corresponds to an assembler statement such as:
394 /// @param Symbol - The symbol to emit. A given symbol should only be
395 /// emitted as a label once, and symbols emitted as a label should never be
396 /// used in an assignment.
397 // FIXME: These emission are non-const because we mutate the symbol to
398 // add the section we're emitting it to later.
399 virtual void EmitLabel(MCSymbol *Symbol);
401 virtual void EmitEHSymAttributes(const MCSymbol *Symbol, MCSymbol *EHSymbol);
403 /// EmitAssemblerFlag - Note in the output the specified @p Flag.
404 virtual void EmitAssemblerFlag(MCAssemblerFlag Flag);
406 /// EmitLinkerOptions - Emit the given list @p Options of strings as linker
407 /// options into the output.
408 virtual void EmitLinkerOptions(ArrayRef<std::string> Kind) {}
410 /// EmitDataRegion - Note in the output the specified region @p Kind.
411 virtual void EmitDataRegion(MCDataRegionType Kind) {}
413 /// EmitVersionMin - Specify the MachO minimum deployment target version.
414 virtual void EmitVersionMin(MCVersionMinType, unsigned Major, unsigned Minor,
417 /// EmitThumbFunc - Note in the output that the specified @p Func is
418 /// a Thumb mode function (ARM target only).
419 virtual void EmitThumbFunc(MCSymbol *Func);
421 /// EmitAssignment - Emit an assignment of @p Value to @p Symbol.
423 /// This corresponds to an assembler statement such as:
426 /// The assignment generates no code, but has the side effect of binding the
427 /// value in the current context. For the assembly streamer, this prints the
428 /// binding into the .s file.
430 /// @param Symbol - The symbol being assigned to.
431 /// @param Value - The value for the symbol.
432 virtual void EmitAssignment(MCSymbol *Symbol, const MCExpr *Value);
434 /// EmitWeakReference - Emit an weak reference from @p Alias to @p Symbol.
436 /// This corresponds to an assembler statement such as:
437 /// .weakref alias, symbol
439 /// @param Alias - The alias that is being created.
440 /// @param Symbol - The symbol being aliased.
441 virtual void EmitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol);
443 /// EmitSymbolAttribute - Add the given @p Attribute to @p Symbol.
444 virtual bool EmitSymbolAttribute(MCSymbol *Symbol,
445 MCSymbolAttr Attribute) = 0;
447 /// EmitSymbolDesc - Set the @p DescValue for the @p Symbol.
449 /// @param Symbol - The symbol to have its n_desc field set.
450 /// @param DescValue - The value to set into the n_desc field.
451 virtual void EmitSymbolDesc(MCSymbol *Symbol, unsigned DescValue);
453 /// BeginCOFFSymbolDef - Start emitting COFF symbol definition
455 /// @param Symbol - The symbol to have its External & Type fields set.
456 virtual void BeginCOFFSymbolDef(const MCSymbol *Symbol);
458 /// EmitCOFFSymbolStorageClass - Emit the storage class of the symbol.
460 /// @param StorageClass - The storage class the symbol should have.
461 virtual void EmitCOFFSymbolStorageClass(int StorageClass);
463 /// EmitCOFFSymbolType - Emit the type of the symbol.
465 /// @param Type - A COFF type identifier (see COFF::SymbolType in X86COFF.h)
466 virtual void EmitCOFFSymbolType(int Type);
468 /// EndCOFFSymbolDef - Marks the end of the symbol definition.
469 virtual void EndCOFFSymbolDef();
471 /// EmitCOFFSectionIndex - Emits a COFF section index.
473 /// @param Symbol - Symbol the section number relocation should point to.
474 virtual void EmitCOFFSectionIndex(MCSymbol const *Symbol);
476 /// EmitCOFFSecRel32 - Emits a COFF section relative relocation.
478 /// @param Symbol - Symbol the section relative relocation should point to.
479 virtual void EmitCOFFSecRel32(MCSymbol const *Symbol);
481 /// EmitELFSize - Emit an ELF .size directive.
483 /// This corresponds to an assembler statement such as:
484 /// .size symbol, expression
486 virtual void EmitELFSize(MCSymbol *Symbol, const MCExpr *Value);
488 /// \brief Emit a Linker Optimization Hint (LOH) directive.
489 /// \param Args - Arguments of the LOH.
490 virtual void EmitLOHDirective(MCLOHType Kind, const MCLOHArgs &Args) {}
492 /// EmitCommonSymbol - Emit a common symbol.
494 /// @param Symbol - The common symbol to emit.
495 /// @param Size - The size of the common symbol.
496 /// @param ByteAlignment - The alignment of the symbol if
497 /// non-zero. This must be a power of 2.
498 virtual void EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
499 unsigned ByteAlignment) = 0;
501 /// EmitLocalCommonSymbol - Emit a local common (.lcomm) symbol.
503 /// @param Symbol - The common symbol to emit.
504 /// @param Size - The size of the common symbol.
505 /// @param ByteAlignment - The alignment of the common symbol in bytes.
506 virtual void EmitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size,
507 unsigned ByteAlignment);
509 /// EmitZerofill - Emit the zerofill section and an optional symbol.
511 /// @param Section - The zerofill section to create and or to put the symbol
512 /// @param Symbol - The zerofill symbol to emit, if non-NULL.
513 /// @param Size - The size of the zerofill symbol.
514 /// @param ByteAlignment - The alignment of the zerofill symbol if
515 /// non-zero. This must be a power of 2 on some targets.
516 virtual void EmitZerofill(const MCSection *Section,
517 MCSymbol *Symbol = nullptr, uint64_t Size = 0,
518 unsigned ByteAlignment = 0) = 0;
520 /// EmitTBSSSymbol - Emit a thread local bss (.tbss) symbol.
522 /// @param Section - The thread local common section.
523 /// @param Symbol - The thread local common symbol to emit.
524 /// @param Size - The size of the symbol.
525 /// @param ByteAlignment - The alignment of the thread local common symbol
526 /// if non-zero. This must be a power of 2 on some targets.
527 virtual void EmitTBSSSymbol(const MCSection *Section, MCSymbol *Symbol,
528 uint64_t Size, unsigned ByteAlignment = 0);
531 /// @name Generating Data
534 /// EmitBytes - Emit the bytes in \p Data into the output.
536 /// This is used to implement assembler directives such as .byte, .ascii,
538 virtual void EmitBytes(StringRef Data);
540 /// EmitValue - Emit the expression @p Value into the output as a native
541 /// integer of the given @p Size bytes.
543 /// This is used to implement assembler directives such as .word, .quad,
546 /// @param Value - The value to emit.
547 /// @param Size - The size of the integer (in bytes) to emit. This must
548 /// match a native machine width.
549 /// @param Loc - The location of the expression for error reporting.
550 virtual void EmitValueImpl(const MCExpr *Value, unsigned Size,
551 const SMLoc &Loc = SMLoc());
553 void EmitValue(const MCExpr *Value, unsigned Size,
554 const SMLoc &Loc = SMLoc());
556 /// EmitIntValue - Special case of EmitValue that avoids the client having
557 /// to pass in a MCExpr for constant integers.
558 virtual void EmitIntValue(uint64_t Value, unsigned Size);
560 /// EmitAbsValue - Emit the Value, but try to avoid relocations. On MachO
561 /// this is done by producing
564 void EmitAbsValue(const MCExpr *Value, unsigned Size);
566 virtual void EmitULEB128Value(const MCExpr *Value);
568 virtual void EmitSLEB128Value(const MCExpr *Value);
570 /// EmitULEB128Value - Special case of EmitULEB128Value that avoids the
571 /// client having to pass in a MCExpr for constant integers.
572 void EmitULEB128IntValue(uint64_t Value, unsigned Padding = 0);
574 /// EmitSLEB128Value - Special case of EmitSLEB128Value that avoids the
575 /// client having to pass in a MCExpr for constant integers.
576 void EmitSLEB128IntValue(int64_t Value);
578 /// EmitSymbolValue - Special case of EmitValue that avoids the client
579 /// having to pass in a MCExpr for MCSymbols.
580 void EmitSymbolValue(const MCSymbol *Sym, unsigned Size);
582 /// EmitGPRel64Value - Emit the expression @p Value into the output as a
583 /// gprel64 (64-bit GP relative) value.
585 /// This is used to implement assembler directives such as .gpdword on
586 /// targets that support them.
587 virtual void EmitGPRel64Value(const MCExpr *Value);
589 /// EmitGPRel32Value - Emit the expression @p Value into the output as a
590 /// gprel32 (32-bit GP relative) value.
592 /// This is used to implement assembler directives such as .gprel32 on
593 /// targets that support them.
594 virtual void EmitGPRel32Value(const MCExpr *Value);
596 /// EmitFill - Emit NumBytes bytes worth of the value specified by
597 /// FillValue. This implements directives such as '.space'.
598 virtual void EmitFill(uint64_t NumBytes, uint8_t FillValue);
600 /// \brief Emit NumBytes worth of zeros.
601 /// This function properly handles data in virtual sections.
602 virtual void EmitZeros(uint64_t NumBytes);
604 /// EmitValueToAlignment - Emit some number of copies of @p Value until
605 /// the byte alignment @p ByteAlignment is reached.
607 /// If the number of bytes need to emit for the alignment is not a multiple
608 /// of @p ValueSize, then the contents of the emitted fill bytes is
611 /// This used to implement the .align assembler directive.
613 /// @param ByteAlignment - The alignment to reach. This must be a power of
614 /// two on some targets.
615 /// @param Value - The value to use when filling bytes.
616 /// @param ValueSize - The size of the integer (in bytes) to emit for
617 /// @p Value. This must match a native machine width.
618 /// @param MaxBytesToEmit - The maximum numbers of bytes to emit, or 0. If
619 /// the alignment cannot be reached in this many bytes, no bytes are
621 virtual void EmitValueToAlignment(unsigned ByteAlignment, int64_t Value = 0,
622 unsigned ValueSize = 1,
623 unsigned MaxBytesToEmit = 0);
625 /// EmitCodeAlignment - Emit nops until the byte alignment @p ByteAlignment
628 /// This used to align code where the alignment bytes may be executed. This
629 /// can emit different bytes for different sizes to optimize execution.
631 /// @param ByteAlignment - The alignment to reach. This must be a power of
632 /// two on some targets.
633 /// @param MaxBytesToEmit - The maximum numbers of bytes to emit, or 0. If
634 /// the alignment cannot be reached in this many bytes, no bytes are
636 virtual void EmitCodeAlignment(unsigned ByteAlignment,
637 unsigned MaxBytesToEmit = 0);
639 /// EmitValueToOffset - Emit some number of copies of @p Value until the
640 /// byte offset @p Offset is reached.
642 /// This is used to implement assembler directives such as .org.
644 /// @param Offset - The offset to reach. This may be an expression, but the
645 /// expression must be associated with the current section.
646 /// @param Value - The value to use when filling bytes.
647 /// @return false on success, true if the offset was invalid.
648 virtual bool EmitValueToOffset(const MCExpr *Offset,
649 unsigned char Value = 0);
653 /// EmitFileDirective - Switch to a new logical file. This is used to
654 /// implement the '.file "foo.c"' assembler directive.
655 virtual void EmitFileDirective(StringRef Filename);
657 /// Emit the "identifiers" directive. This implements the
658 /// '.ident "version foo"' assembler directive.
659 virtual void EmitIdent(StringRef IdentString) {}
661 /// EmitDwarfFileDirective - Associate a filename with a specified logical
662 /// file number. This implements the DWARF2 '.file 4 "foo.c"' assembler
664 virtual unsigned EmitDwarfFileDirective(unsigned FileNo, StringRef Directory,
668 /// EmitDwarfLocDirective - This implements the DWARF2
669 // '.loc fileno lineno ...' assembler directive.
670 virtual void EmitDwarfLocDirective(unsigned FileNo, unsigned Line,
671 unsigned Column, unsigned Flags,
672 unsigned Isa, unsigned Discriminator,
675 virtual MCSymbol *getDwarfLineTableSymbol(unsigned CUID);
677 void EmitDwarfSetLineAddr(int64_t LineDelta, const MCSymbol *Label,
680 virtual void EmitCompactUnwindEncoding(uint32_t CompactUnwindEncoding);
681 virtual void EmitCFISections(bool EH, bool Debug);
682 void EmitCFIStartProc(bool IsSimple);
683 void EmitCFIEndProc();
684 virtual void EmitCFIDefCfa(int64_t Register, int64_t Offset);
685 virtual void EmitCFIDefCfaOffset(int64_t Offset);
686 virtual void EmitCFIDefCfaRegister(int64_t Register);
687 virtual void EmitCFIOffset(int64_t Register, int64_t Offset);
688 virtual void EmitCFIPersonality(const MCSymbol *Sym, unsigned Encoding);
689 virtual void EmitCFILsda(const MCSymbol *Sym, unsigned Encoding);
690 virtual void EmitCFIRememberState();
691 virtual void EmitCFIRestoreState();
692 virtual void EmitCFISameValue(int64_t Register);
693 virtual void EmitCFIRestore(int64_t Register);
694 virtual void EmitCFIRelOffset(int64_t Register, int64_t Offset);
695 virtual void EmitCFIAdjustCfaOffset(int64_t Adjustment);
696 virtual void EmitCFIEscape(StringRef Values);
697 virtual void EmitCFISignalFrame();
698 virtual void EmitCFIUndefined(int64_t Register);
699 virtual void EmitCFIRegister(int64_t Register1, int64_t Register2);
700 virtual void EmitCFIWindowSave();
702 virtual void EmitWinCFIStartProc(const MCSymbol *Symbol);
703 virtual void EmitWinCFIEndProc();
704 virtual void EmitWinCFIStartChained();
705 virtual void EmitWinCFIEndChained();
706 virtual void EmitWinCFIPushReg(unsigned Register);
707 virtual void EmitWinCFISetFrame(unsigned Register, unsigned Offset);
708 virtual void EmitWinCFIAllocStack(unsigned Size);
709 virtual void EmitWinCFISaveReg(unsigned Register, unsigned Offset);
710 virtual void EmitWinCFISaveXMM(unsigned Register, unsigned Offset);
711 virtual void EmitWinCFIPushFrame(bool Code);
712 virtual void EmitWinCFIEndProlog();
714 virtual void EmitWinEHHandler(const MCSymbol *Sym, bool Unwind, bool Except);
715 virtual void EmitWinEHHandlerData();
717 /// EmitInstruction - Emit the given @p Instruction into the current
719 virtual void EmitInstruction(const MCInst &Inst, const MCSubtargetInfo &STI);
721 /// \brief Set the bundle alignment mode from now on in the section.
722 /// The argument is the power of 2 to which the alignment is set. The
723 /// value 0 means turn the bundle alignment off.
724 virtual void EmitBundleAlignMode(unsigned AlignPow2);
726 /// \brief The following instructions are a bundle-locked group.
728 /// \param AlignToEnd - If true, the bundle-locked group will be aligned to
729 /// the end of a bundle.
730 virtual void EmitBundleLock(bool AlignToEnd);
732 /// \brief Ends a bundle-locked group.
733 virtual void EmitBundleUnlock();
735 /// EmitRawText - If this file is backed by a assembly streamer, this dumps
736 /// the specified string in the output .s file. This capability is
737 /// indicated by the hasRawTextSupport() predicate. By default this aborts.
738 void EmitRawText(const Twine &String);
740 /// Flush - Causes any cached state to be written out.
741 virtual void Flush() {}
743 /// FinishImpl - Streamer specific finalization.
744 virtual void FinishImpl();
745 /// Finish - Finish emission of machine code.
748 virtual bool mayHaveInstructions() const { return true; }
751 /// createNullStreamer - Create a dummy machine code streamer, which does
752 /// nothing. This is useful for timing the assembler front end.
753 MCStreamer *createNullStreamer(MCContext &Ctx);
755 /// createAsmStreamer - Create a machine code streamer which will print out
756 /// assembly for the native target, suitable for compiling with a native
759 /// \param InstPrint - If given, the instruction printer to use. If not given
760 /// the MCInst representation will be printed. This method takes ownership of
763 /// \param CE - If given, a code emitter to use to show the instruction
764 /// encoding inline with the assembly. This method takes ownership of \p CE.
766 /// \param TAB - If given, a target asm backend to use to show the fixup
767 /// information in conjunction with encoding information. This method takes
768 /// ownership of \p TAB.
770 /// \param ShowInst - Whether to show the MCInst representation inline with
772 MCStreamer *createAsmStreamer(MCContext &Ctx, formatted_raw_ostream &OS,
773 bool isVerboseAsm, bool useDwarfDirectory,
774 MCInstPrinter *InstPrint, MCCodeEmitter *CE,
775 MCAsmBackend *TAB, bool ShowInst);
777 /// createMachOStreamer - Create a machine code streamer which will generate
778 /// Mach-O format object files.
780 /// Takes ownership of \p TAB and \p CE.
781 MCStreamer *createMachOStreamer(MCContext &Ctx, MCAsmBackend &TAB,
782 raw_ostream &OS, MCCodeEmitter *CE,
783 bool RelaxAll = false,
784 bool LabelSections = false);
786 /// createELFStreamer - Create a machine code streamer which will generate
787 /// ELF format object files.
788 MCStreamer *createELFStreamer(MCContext &Ctx, MCAsmBackend &TAB,
789 raw_ostream &OS, MCCodeEmitter *CE, bool RelaxAll,
792 } // end namespace llvm