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 setTargetStreamer(MCTargetStreamer *TS) {
218 TargetStreamer.reset(TS);
223 virtual void reset();
225 MCContext &getContext() const { return Context; }
227 MCTargetStreamer *getTargetStreamer() {
228 return TargetStreamer.get();
231 unsigned getNumFrameInfos() { return FrameInfos.size(); }
233 const MCDwarfFrameInfo &getFrameInfo(unsigned i) { return FrameInfos[i]; }
235 ArrayRef<MCDwarfFrameInfo> getFrameInfos() const { return FrameInfos; }
237 unsigned getNumW64UnwindInfos() { return W64UnwindInfos.size(); }
239 MCWin64EHUnwindInfo &getW64UnwindInfo(unsigned i) {
240 return *W64UnwindInfos[i];
243 void generateCompactUnwindEncodings(MCAsmBackend *MAB);
245 /// @name Assembly File Formatting.
248 /// isVerboseAsm - Return true if this streamer supports verbose assembly
249 /// and if it is enabled.
250 virtual bool isVerboseAsm() const { return false; }
252 /// hasRawTextSupport - Return true if this asm streamer supports emitting
253 /// unformatted text to the .s file with EmitRawText.
254 virtual bool hasRawTextSupport() const { return false; }
256 /// Is the integrated assembler required for this streamer to function
258 virtual bool isIntegratedAssemblerRequired() const { return false; }
260 /// AddComment - Add a comment that can be emitted to the generated .s
261 /// file if applicable as a QoI issue to make the output of the compiler
262 /// more readable. This only affects the MCAsmStreamer, and only when
263 /// verbose assembly output is enabled.
265 /// If the comment includes embedded \n's, they will each get the comment
266 /// prefix as appropriate. The added comment should not end with a \n.
267 virtual void AddComment(const Twine &T) {}
269 /// GetCommentOS - Return a raw_ostream that comments can be written to.
270 /// Unlike AddComment, you are required to terminate comments with \n if you
272 virtual raw_ostream &GetCommentOS();
274 /// Print T and prefix it with the comment string (normally #) and optionally
275 /// a tab. This prints the comment immediately, not at the end of the
276 /// current line. It is basically a safe version of EmitRawText: since it
277 /// only prints comments, the object streamer ignores it instead of asserting.
278 virtual void emitRawComment(const Twine &T, bool TabPrefix = true);
280 /// AddBlankLine - Emit a blank line to a .s file to pretty it up.
281 virtual void AddBlankLine() {}
285 /// @name Symbol & Section Management
288 /// getCurrentSection - Return the current section that the streamer is
289 /// emitting code to.
290 MCSectionSubPair getCurrentSection() const {
291 if (!SectionStack.empty())
292 return SectionStack.back().first;
293 return MCSectionSubPair();
296 /// getPreviousSection - Return the previous section that the streamer is
297 /// emitting code to.
298 MCSectionSubPair getPreviousSection() const {
299 if (!SectionStack.empty())
300 return SectionStack.back().second;
301 return MCSectionSubPair();
304 /// GetSymbolOrder - Returns an index to represent the order
305 /// a symbol was emitted in. (zero if we did not emit that symbol)
306 unsigned GetSymbolOrder(const MCSymbol *Sym) const {
307 return SymbolOrdering.lookup(Sym);
310 /// ChangeSection - Update streamer for a new active section.
312 /// This is called by PopSection and SwitchSection, if the current
314 virtual void ChangeSection(const MCSection *, const MCExpr *) = 0;
316 /// pushSection - Save the current and previous section on the
319 SectionStack.push_back(
320 std::make_pair(getCurrentSection(), getPreviousSection()));
323 /// popSection - Restore the current and previous section from
324 /// the section stack. Calls ChangeSection as needed.
326 /// Returns false if the stack was empty.
328 if (SectionStack.size() <= 1)
330 MCSectionSubPair oldSection = SectionStack.pop_back_val().first;
331 MCSectionSubPair curSection = SectionStack.back().first;
333 if (oldSection != curSection)
334 ChangeSection(curSection.first, curSection.second);
338 bool SubSection(const MCExpr *Subsection) {
339 if (SectionStack.empty())
342 SwitchSection(SectionStack.back().first.first, Subsection);
346 /// SwitchSection - Set the current section where code is being emitted to
347 /// @p Section. This is required to update CurSection.
349 /// This corresponds to assembler directives like .section, .text, etc.
350 void SwitchSection(const MCSection *Section,
351 const MCExpr *Subsection = nullptr) {
352 assert(Section && "Cannot switch to a null section!");
353 MCSectionSubPair curSection = SectionStack.back().first;
354 SectionStack.back().second = curSection;
355 if (MCSectionSubPair(Section, Subsection) != curSection) {
356 SectionStack.back().first = MCSectionSubPair(Section, Subsection);
357 ChangeSection(Section, Subsection);
361 /// SwitchSectionNoChange - Set the current section where code is being
362 /// emitted to @p Section. This is required to update CurSection. This
363 /// version does not call ChangeSection.
364 void SwitchSectionNoChange(const MCSection *Section,
365 const MCExpr *Subsection = nullptr) {
366 assert(Section && "Cannot switch to a null section!");
367 MCSectionSubPair curSection = SectionStack.back().first;
368 SectionStack.back().second = curSection;
369 if (MCSectionSubPair(Section, Subsection) != curSection)
370 SectionStack.back().first = MCSectionSubPair(Section, Subsection);
373 /// Create the default sections and set the initial one.
374 virtual void InitSections();
376 /// AssignSection - Sets the symbol's section.
378 /// Each emitted symbol will be tracked in the ordering table,
379 /// so we can sort on them later.
380 void AssignSection(MCSymbol *Symbol, const MCSection *Section);
382 /// EmitLabel - Emit a label for @p Symbol into the current section.
384 /// This corresponds to an assembler statement such as:
387 /// @param Symbol - The symbol to emit. A given symbol should only be
388 /// emitted as a label once, and symbols emitted as a label should never be
389 /// used in an assignment.
390 // FIXME: These emission are non-const because we mutate the symbol to
391 // add the section we're emitting it to later.
392 virtual void EmitLabel(MCSymbol *Symbol);
394 virtual void EmitEHSymAttributes(const MCSymbol *Symbol, MCSymbol *EHSymbol);
396 /// EmitAssemblerFlag - Note in the output the specified @p Flag.
397 virtual void EmitAssemblerFlag(MCAssemblerFlag Flag) = 0;
399 /// EmitLinkerOptions - Emit the given list @p Options of strings as linker
400 /// options into the output.
401 virtual void EmitLinkerOptions(ArrayRef<std::string> Kind) {}
403 /// EmitDataRegion - Note in the output the specified region @p Kind.
404 virtual void EmitDataRegion(MCDataRegionType Kind) {}
406 /// EmitVersionMin - Specify the MachO minimum deployment target version.
407 virtual void EmitVersionMin(MCVersionMinType, unsigned Major, unsigned Minor,
410 /// EmitThumbFunc - Note in the output that the specified @p Func is
411 /// a Thumb mode function (ARM target only).
412 virtual void EmitThumbFunc(MCSymbol *Func) = 0;
414 /// EmitAssignment - Emit an assignment of @p Value to @p Symbol.
416 /// This corresponds to an assembler statement such as:
419 /// The assignment generates no code, but has the side effect of binding the
420 /// value in the current context. For the assembly streamer, this prints the
421 /// binding into the .s file.
423 /// @param Symbol - The symbol being assigned to.
424 /// @param Value - The value for the symbol.
425 virtual void EmitAssignment(MCSymbol *Symbol, const MCExpr *Value);
427 /// EmitWeakReference - Emit an weak reference from @p Alias to @p Symbol.
429 /// This corresponds to an assembler statement such as:
430 /// .weakref alias, symbol
432 /// @param Alias - The alias that is being created.
433 /// @param Symbol - The symbol being aliased.
434 virtual void EmitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol) = 0;
436 /// EmitSymbolAttribute - Add the given @p Attribute to @p Symbol.
437 virtual bool EmitSymbolAttribute(MCSymbol *Symbol,
438 MCSymbolAttr Attribute) = 0;
440 /// EmitSymbolDesc - Set the @p DescValue for the @p Symbol.
442 /// @param Symbol - The symbol to have its n_desc field set.
443 /// @param DescValue - The value to set into the n_desc field.
444 virtual void EmitSymbolDesc(MCSymbol *Symbol, unsigned DescValue) = 0;
446 /// BeginCOFFSymbolDef - Start emitting COFF symbol definition
448 /// @param Symbol - The symbol to have its External & Type fields set.
449 virtual void BeginCOFFSymbolDef(const MCSymbol *Symbol) = 0;
451 /// EmitCOFFSymbolStorageClass - Emit the storage class of the symbol.
453 /// @param StorageClass - The storage class the symbol should have.
454 virtual void EmitCOFFSymbolStorageClass(int StorageClass) = 0;
456 /// EmitCOFFSymbolType - Emit the type of the symbol.
458 /// @param Type - A COFF type identifier (see COFF::SymbolType in X86COFF.h)
459 virtual void EmitCOFFSymbolType(int Type) = 0;
461 /// EndCOFFSymbolDef - Marks the end of the symbol definition.
462 virtual void EndCOFFSymbolDef() = 0;
464 /// EmitCOFFSectionIndex - Emits a COFF section index.
466 /// @param Symbol - Symbol the section number relocation should point to.
467 virtual void EmitCOFFSectionIndex(MCSymbol const *Symbol);
469 /// EmitCOFFSecRel32 - Emits a COFF section relative relocation.
471 /// @param Symbol - Symbol the section relative relocation should point to.
472 virtual void EmitCOFFSecRel32(MCSymbol const *Symbol);
474 /// EmitELFSize - Emit an ELF .size directive.
476 /// This corresponds to an assembler statement such as:
477 /// .size symbol, expression
479 virtual void EmitELFSize(MCSymbol *Symbol, const MCExpr *Value) = 0;
481 /// \brief Emit a Linker Optimization Hint (LOH) directive.
482 /// \param Args - Arguments of the LOH.
483 virtual void EmitLOHDirective(MCLOHType Kind, const MCLOHArgs &Args) {}
485 /// EmitCommonSymbol - Emit a common symbol.
487 /// @param Symbol - The common symbol to emit.
488 /// @param Size - The size of the common symbol.
489 /// @param ByteAlignment - The alignment of the symbol if
490 /// non-zero. This must be a power of 2.
491 virtual void EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
492 unsigned ByteAlignment) = 0;
494 /// EmitLocalCommonSymbol - Emit a local common (.lcomm) symbol.
496 /// @param Symbol - The common symbol to emit.
497 /// @param Size - The size of the common symbol.
498 /// @param ByteAlignment - The alignment of the common symbol in bytes.
499 virtual void EmitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size,
500 unsigned ByteAlignment) = 0;
502 /// EmitZerofill - Emit the zerofill section and an optional symbol.
504 /// @param Section - The zerofill section to create and or to put the symbol
505 /// @param Symbol - The zerofill symbol to emit, if non-NULL.
506 /// @param Size - The size of the zerofill symbol.
507 /// @param ByteAlignment - The alignment of the zerofill symbol if
508 /// non-zero. This must be a power of 2 on some targets.
509 virtual void EmitZerofill(const MCSection *Section,
510 MCSymbol *Symbol = nullptr, uint64_t Size = 0,
511 unsigned ByteAlignment = 0) = 0;
513 /// EmitTBSSSymbol - Emit a thread local bss (.tbss) symbol.
515 /// @param Section - The thread local common section.
516 /// @param Symbol - The thread local common symbol to emit.
517 /// @param Size - The size of the symbol.
518 /// @param ByteAlignment - The alignment of the thread local common symbol
519 /// if non-zero. This must be a power of 2 on some targets.
520 virtual void EmitTBSSSymbol(const MCSection *Section, MCSymbol *Symbol,
521 uint64_t Size, unsigned ByteAlignment = 0) = 0;
524 /// @name Generating Data
527 /// EmitBytes - Emit the bytes in \p Data into the output.
529 /// This is used to implement assembler directives such as .byte, .ascii,
531 virtual void EmitBytes(StringRef Data) = 0;
533 /// EmitValue - Emit the expression @p Value into the output as a native
534 /// integer of the given @p Size bytes.
536 /// This is used to implement assembler directives such as .word, .quad,
539 /// @param Value - The value to emit.
540 /// @param Size - The size of the integer (in bytes) to emit. This must
541 /// match a native machine width.
542 /// @param Loc - The location of the expression for error reporting.
543 virtual void EmitValueImpl(const MCExpr *Value, unsigned Size,
544 const SMLoc &Loc = SMLoc()) = 0;
546 void EmitValue(const MCExpr *Value, unsigned Size,
547 const SMLoc &Loc = SMLoc());
549 /// EmitIntValue - Special case of EmitValue that avoids the client having
550 /// to pass in a MCExpr for constant integers.
551 virtual void EmitIntValue(uint64_t Value, unsigned Size);
553 /// EmitAbsValue - Emit the Value, but try to avoid relocations. On MachO
554 /// this is done by producing
557 void EmitAbsValue(const MCExpr *Value, unsigned Size);
559 virtual void EmitULEB128Value(const MCExpr *Value) = 0;
561 virtual void EmitSLEB128Value(const MCExpr *Value) = 0;
563 /// EmitULEB128Value - Special case of EmitULEB128Value that avoids the
564 /// client having to pass in a MCExpr for constant integers.
565 void EmitULEB128IntValue(uint64_t Value, unsigned Padding = 0);
567 /// EmitSLEB128Value - Special case of EmitSLEB128Value that avoids the
568 /// client having to pass in a MCExpr for constant integers.
569 void EmitSLEB128IntValue(int64_t Value);
571 /// EmitSymbolValue - Special case of EmitValue that avoids the client
572 /// having to pass in a MCExpr for MCSymbols.
573 void EmitSymbolValue(const MCSymbol *Sym, unsigned Size);
575 /// EmitGPRel64Value - Emit the expression @p Value into the output as a
576 /// gprel64 (64-bit GP relative) value.
578 /// This is used to implement assembler directives such as .gpdword on
579 /// targets that support them.
580 virtual void EmitGPRel64Value(const MCExpr *Value);
582 /// EmitGPRel32Value - Emit the expression @p Value into the output as a
583 /// gprel32 (32-bit GP relative) value.
585 /// This is used to implement assembler directives such as .gprel32 on
586 /// targets that support them.
587 virtual void EmitGPRel32Value(const MCExpr *Value);
589 /// EmitFill - Emit NumBytes bytes worth of the value specified by
590 /// FillValue. This implements directives such as '.space'.
591 virtual void EmitFill(uint64_t NumBytes, uint8_t FillValue);
593 /// \brief Emit NumBytes worth of zeros.
594 /// This function properly handles data in virtual sections.
595 virtual void EmitZeros(uint64_t NumBytes);
597 /// EmitValueToAlignment - Emit some number of copies of @p Value until
598 /// the byte alignment @p ByteAlignment is reached.
600 /// If the number of bytes need to emit for the alignment is not a multiple
601 /// of @p ValueSize, then the contents of the emitted fill bytes is
604 /// This used to implement the .align assembler directive.
606 /// @param ByteAlignment - The alignment to reach. This must be a power of
607 /// two on some targets.
608 /// @param Value - The value to use when filling bytes.
609 /// @param ValueSize - The size of the integer (in bytes) to emit for
610 /// @p Value. This must match a native machine width.
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 EmitValueToAlignment(unsigned ByteAlignment, int64_t Value = 0,
615 unsigned ValueSize = 1,
616 unsigned MaxBytesToEmit = 0) = 0;
618 /// EmitCodeAlignment - Emit nops until the byte alignment @p ByteAlignment
621 /// This used to align code where the alignment bytes may be executed. This
622 /// can emit different bytes for different sizes to optimize execution.
624 /// @param ByteAlignment - The alignment to reach. This must be a power of
625 /// two on some targets.
626 /// @param MaxBytesToEmit - The maximum numbers of bytes to emit, or 0. If
627 /// the alignment cannot be reached in this many bytes, no bytes are
629 virtual void EmitCodeAlignment(unsigned ByteAlignment,
630 unsigned MaxBytesToEmit = 0) = 0;
632 /// EmitValueToOffset - Emit some number of copies of @p Value until the
633 /// byte offset @p Offset is reached.
635 /// This is used to implement assembler directives such as .org.
637 /// @param Offset - The offset to reach. This may be an expression, but the
638 /// expression must be associated with the current section.
639 /// @param Value - The value to use when filling bytes.
640 /// @return false on success, true if the offset was invalid.
641 virtual bool EmitValueToOffset(const MCExpr *Offset,
642 unsigned char Value = 0) = 0;
646 /// EmitFileDirective - Switch to a new logical file. This is used to
647 /// implement the '.file "foo.c"' assembler directive.
648 virtual void EmitFileDirective(StringRef Filename) = 0;
650 /// Emit the "identifiers" directive. This implements the
651 /// '.ident "version foo"' assembler directive.
652 virtual void EmitIdent(StringRef IdentString) {}
654 /// EmitDwarfFileDirective - Associate a filename with a specified logical
655 /// file number. This implements the DWARF2 '.file 4 "foo.c"' assembler
657 virtual unsigned EmitDwarfFileDirective(unsigned FileNo, StringRef Directory,
661 /// EmitDwarfLocDirective - This implements the DWARF2
662 // '.loc fileno lineno ...' assembler directive.
663 virtual void EmitDwarfLocDirective(unsigned FileNo, unsigned Line,
664 unsigned Column, unsigned Flags,
665 unsigned Isa, unsigned Discriminator,
668 virtual MCSymbol *getDwarfLineTableSymbol(unsigned CUID);
670 void EmitDwarfSetLineAddr(int64_t LineDelta, const MCSymbol *Label,
673 virtual void EmitCompactUnwindEncoding(uint32_t CompactUnwindEncoding);
674 virtual void EmitCFISections(bool EH, bool Debug);
675 void EmitCFIStartProc(bool IsSimple);
676 void EmitCFIEndProc();
677 virtual void EmitCFIDefCfa(int64_t Register, int64_t Offset);
678 virtual void EmitCFIDefCfaOffset(int64_t Offset);
679 virtual void EmitCFIDefCfaRegister(int64_t Register);
680 virtual void EmitCFIOffset(int64_t Register, int64_t Offset);
681 virtual void EmitCFIPersonality(const MCSymbol *Sym, unsigned Encoding);
682 virtual void EmitCFILsda(const MCSymbol *Sym, unsigned Encoding);
683 virtual void EmitCFIRememberState();
684 virtual void EmitCFIRestoreState();
685 virtual void EmitCFISameValue(int64_t Register);
686 virtual void EmitCFIRestore(int64_t Register);
687 virtual void EmitCFIRelOffset(int64_t Register, int64_t Offset);
688 virtual void EmitCFIAdjustCfaOffset(int64_t Adjustment);
689 virtual void EmitCFIEscape(StringRef Values);
690 virtual void EmitCFISignalFrame();
691 virtual void EmitCFIUndefined(int64_t Register);
692 virtual void EmitCFIRegister(int64_t Register1, int64_t Register2);
693 virtual void EmitCFIWindowSave();
695 virtual void EmitWin64EHStartProc(const MCSymbol *Symbol);
696 virtual void EmitWin64EHEndProc();
697 virtual void EmitWin64EHStartChained();
698 virtual void EmitWin64EHEndChained();
699 virtual void EmitWin64EHHandler(const MCSymbol *Sym, bool Unwind,
701 virtual void EmitWin64EHHandlerData();
702 virtual void EmitWin64EHPushReg(unsigned Register);
703 virtual void EmitWin64EHSetFrame(unsigned Register, unsigned Offset);
704 virtual void EmitWin64EHAllocStack(unsigned Size);
705 virtual void EmitWin64EHSaveReg(unsigned Register, unsigned Offset);
706 virtual void EmitWin64EHSaveXMM(unsigned Register, unsigned Offset);
707 virtual void EmitWin64EHPushFrame(bool Code);
708 virtual void EmitWin64EHEndProlog();
710 /// EmitInstruction - Emit the given @p Instruction into the current
712 virtual void EmitInstruction(const MCInst &Inst, const MCSubtargetInfo &STI) = 0;
714 /// \brief Set the bundle alignment mode from now on in the section.
715 /// The argument is the power of 2 to which the alignment is set. The
716 /// value 0 means turn the bundle alignment off.
717 virtual void EmitBundleAlignMode(unsigned AlignPow2) = 0;
719 /// \brief The following instructions are a bundle-locked group.
721 /// \param AlignToEnd - If true, the bundle-locked group will be aligned to
722 /// the end of a bundle.
723 virtual void EmitBundleLock(bool AlignToEnd) = 0;
725 /// \brief Ends a bundle-locked group.
726 virtual void EmitBundleUnlock() = 0;
728 /// EmitRawText - If this file is backed by a assembly streamer, this dumps
729 /// the specified string in the output .s file. This capability is
730 /// indicated by the hasRawTextSupport() predicate. By default this aborts.
731 void EmitRawText(const Twine &String);
733 /// Flush - Causes any cached state to be written out.
734 virtual void Flush() {}
736 /// FinishImpl - Streamer specific finalization.
737 virtual void FinishImpl() = 0;
738 /// Finish - Finish emission of machine code.
741 virtual bool mayHaveInstructions() const { return true; }
744 /// createNullStreamer - Create a dummy machine code streamer, which does
745 /// nothing. This is useful for timing the assembler front end.
746 MCStreamer *createNullStreamer(MCContext &Ctx);
748 /// createAsmStreamer - Create a machine code streamer which will print out
749 /// assembly for the native target, suitable for compiling with a native
752 /// \param InstPrint - If given, the instruction printer to use. If not given
753 /// the MCInst representation will be printed. This method takes ownership of
756 /// \param CE - If given, a code emitter to use to show the instruction
757 /// encoding inline with the assembly. This method takes ownership of \p CE.
759 /// \param TAB - If given, a target asm backend to use to show the fixup
760 /// information in conjunction with encoding information. This method takes
761 /// ownership of \p TAB.
763 /// \param ShowInst - Whether to show the MCInst representation inline with
765 MCStreamer *createAsmStreamer(MCContext &Ctx, formatted_raw_ostream &OS,
766 bool isVerboseAsm, bool useDwarfDirectory,
767 MCInstPrinter *InstPrint, MCCodeEmitter *CE,
768 MCAsmBackend *TAB, bool ShowInst);
770 /// createMachOStreamer - Create a machine code streamer which will generate
771 /// Mach-O format object files.
773 /// Takes ownership of \p TAB and \p CE.
774 MCStreamer *createMachOStreamer(MCContext &Ctx, MCAsmBackend &TAB,
775 raw_ostream &OS, MCCodeEmitter *CE,
776 bool RelaxAll = false,
777 bool LabelSections = false);
779 /// createELFStreamer - Create a machine code streamer which will generate
780 /// ELF format object files.
781 MCStreamer *createELFStreamer(MCContext &Ctx, MCAsmBackend &TAB,
782 raw_ostream &OS, MCCodeEmitter *CE, bool RelaxAll,
785 } // end namespace llvm