1//===- MCStreamer.h - High-level Streaming Machine Code Output --*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file declares the MCStreamer class.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_MC_MCSTREAMER_H
14#define LLVM_MC_MCSTREAMER_H
15
16#include "llvm/ADT/ArrayRef.h"
17#include "llvm/ADT/DenseMap.h"
18#include "llvm/ADT/SmallVector.h"
19#include "llvm/ADT/StringRef.h"
20#include "llvm/MC/MCDirectives.h"
21#include "llvm/MC/MCDwarf.h"
22#include "llvm/MC/MCFragment.h"
23#include "llvm/MC/MCLinkerOptimizationHint.h"
24#include "llvm/MC/MCPseudoProbe.h"
25#include "llvm/MC/MCWinEH.h"
26#include "llvm/Support/Compiler.h"
27#include "llvm/Support/Error.h"
28#include "llvm/Support/MD5.h"
29#include "llvm/Support/SMLoc.h"
30#include "llvm/Support/VersionTuple.h"
31#include "llvm/TargetParser/ARMTargetParser.h"
32#include <cassert>
33#include <cstdint>
34#include <memory>
35#include <optional>
36#include <string>
37#include <utility>
38#include <vector>
39
40namespace llvm {
41
42class APInt;
43class AssemblerConstantPools;
44class MCAsmBackend;
45class MCAssembler;
46class MCContext;
47class MCExpr;
48class MCFragment;
49class MCInst;
50class MCInstPrinter;
51class MCRegister;
52class MCSection;
53class MCStreamer;
54class MCSubtargetInfo;
55class MCSymbol;
56class MCSymbolRefExpr;
57class Triple;
58class Twine;
59class raw_ostream;
60
61namespace codeview {
62struct DefRangeRegisterRelHeader;
63struct DefRangeSubfieldRegisterHeader;
64struct DefRangeRegisterHeader;
65struct DefRangeFramePointerRelHeader;
66}
67
68using MCSectionSubPair = std::pair<MCSection *, uint32_t>;
69
70/// Target specific streamer interface. This is used so that targets can
71/// implement support for target specific assembly directives.
72///
73/// If target foo wants to use this, it should implement 3 classes:
74/// * FooTargetStreamer : public MCTargetStreamer
75/// * FooTargetAsmStreamer : public FooTargetStreamer
76/// * FooTargetELFStreamer : public FooTargetStreamer
77///
78/// FooTargetStreamer should have a pure virtual method for each directive. For
79/// example, for a ".bar symbol_name" directive, it should have
80/// virtual emitBar(const MCSymbol &Symbol) = 0;
81///
82/// The FooTargetAsmStreamer and FooTargetELFStreamer classes implement the
83/// method. The assembly streamer just prints ".bar symbol_name". The object
84/// streamer does whatever is needed to implement .bar in the object file.
85///
86/// In the assembly printer and parser the target streamer can be used by
87/// calling getTargetStreamer and casting it to FooTargetStreamer:
88///
89/// MCTargetStreamer &TS = OutStreamer.getTargetStreamer();
90/// FooTargetStreamer &ATS = static_cast<FooTargetStreamer &>(TS);
91///
92/// The base classes FooTargetAsmStreamer and FooTargetELFStreamer should
93/// *never* be treated differently. Callers should always talk to a
94/// FooTargetStreamer.
95class LLVM_ABI MCTargetStreamer {
96protected:
97 MCStreamer &Streamer;
98
99public:
100 MCTargetStreamer(MCStreamer &S);
101 virtual ~MCTargetStreamer();
102
103 MCStreamer &getStreamer() { return Streamer; }
104 MCContext &getContext();
105
106 // Allow a target to add behavior to the EmitLabel of MCStreamer.
107 virtual void emitLabel(MCSymbol *Symbol);
108 // Allow a target to add behavior to the emitAssignment of MCStreamer.
109 virtual void emitAssignment(MCSymbol *Symbol, const MCExpr *Value);
110
111 virtual void prettyPrintAsm(MCInstPrinter &InstPrinter, uint64_t Address,
112 const MCInst &Inst, const MCSubtargetInfo &STI,
113 raw_ostream &OS);
114
115 virtual void emitDwarfFileDirective(StringRef Directive);
116
117 /// Update streamer for a new active section.
118 ///
119 /// This is called by popSection and switchSection, if the current
120 /// section changes.
121 virtual void changeSection(const MCSection *CurSection, MCSection *Section,
122 uint32_t SubSection, raw_ostream &OS);
123
124 virtual void emitValue(const MCExpr *Value);
125
126 /// Emit the bytes in \p Data into the output.
127 ///
128 /// This is used to emit bytes in \p Data as sequence of .byte directives.
129 virtual void emitRawBytes(StringRef Data);
130
131 virtual void emitConstantPools();
132
133 virtual void finish();
134};
135
136// FIXME: declared here because it is used from
137// lib/CodeGen/AsmPrinter/ARMException.cpp.
138class LLVM_ABI ARMTargetStreamer : public MCTargetStreamer {
139public:
140 ARMTargetStreamer(MCStreamer &S);
141 ~ARMTargetStreamer() override;
142
143 virtual void emitFnStart();
144 virtual void emitFnEnd();
145 virtual void emitCantUnwind();
146 virtual void emitPersonality(const MCSymbol *Personality);
147 virtual void emitPersonalityIndex(unsigned Index);
148 virtual void emitHandlerData();
149 virtual void emitSetFP(MCRegister FpReg, MCRegister SpReg,
150 int64_t Offset = 0);
151 virtual void emitMovSP(MCRegister Reg, int64_t Offset = 0);
152 virtual void emitPad(int64_t Offset);
153 virtual void emitRegSave(const SmallVectorImpl<MCRegister> &RegList,
154 bool isVector);
155 virtual void emitUnwindRaw(int64_t StackOffset,
156 const SmallVectorImpl<uint8_t> &Opcodes);
157
158 virtual void switchVendor(StringRef Vendor);
159 virtual void emitAttribute(unsigned Attribute, unsigned Value);
160 virtual void emitTextAttribute(unsigned Attribute, StringRef String);
161 virtual void emitIntTextAttribute(unsigned Attribute, unsigned IntValue,
162 StringRef StringValue = "");
163 virtual void emitFPU(ARM::FPUKind FPU);
164 virtual void emitArch(ARM::ArchKind Arch);
165 virtual void emitArchExtension(uint64_t ArchExt);
166 virtual void emitObjectArch(ARM::ArchKind Arch);
167 void emitTargetAttributes(const MCSubtargetInfo &STI);
168 virtual void finishAttributeSection();
169 virtual void emitInst(uint32_t Inst, char Suffix = '\0');
170
171 virtual void annotateTLSDescriptorSequence(const MCSymbolRefExpr *SRE);
172
173 virtual void emitSyntaxUnified();
174
175 virtual void emitCode16();
176 virtual void emitCode32();
177
178 // Note in the output that the specified \p Symbol is a Thumb mode function.
179 virtual void emitThumbFunc(MCSymbol *Symbol);
180 virtual void emitThumbSet(MCSymbol *Symbol, const MCExpr *Value);
181
182 void emitConstantPools() override;
183
184 virtual void emitARMWinCFIAllocStack(unsigned Size, bool Wide);
185 virtual void emitARMWinCFISaveRegMask(unsigned Mask, bool Wide);
186 virtual void emitARMWinCFISaveSP(unsigned Reg);
187 virtual void emitARMWinCFISaveFRegs(unsigned First, unsigned Last);
188 virtual void emitARMWinCFISaveLR(unsigned Offset);
189 virtual void emitARMWinCFIPrologEnd(bool Fragment);
190 virtual void emitARMWinCFINop(bool Wide);
191 virtual void emitARMWinCFIEpilogStart(unsigned Condition);
192 virtual void emitARMWinCFIEpilogEnd();
193 virtual void emitARMWinCFICustom(unsigned Opcode);
194
195 /// Reset any state between object emissions, i.e. the equivalent of
196 /// MCStreamer's reset method.
197 virtual void reset();
198
199 /// Callback used to implement the ldr= pseudo.
200 /// Add a new entry to the constant pool for the current section and return an
201 /// MCExpr that can be used to refer to the constant pool location.
202 const MCExpr *addConstantPoolEntry(const MCExpr *, SMLoc Loc);
203
204 /// Callback used to implement the .ltorg directive.
205 /// Emit contents of constant pool for the current section.
206 void emitCurrentConstantPool();
207
208private:
209 std::unique_ptr<AssemblerConstantPools> ConstantPools;
210};
211
212/// Streaming machine code generation interface.
213///
214/// This interface is intended to provide a programmatic interface that is very
215/// similar to the level that an assembler .s file provides. It has callbacks
216/// to emit bytes, handle directives, etc. The implementation of this interface
217/// retains state to know what the current section is etc.
218///
219/// There are multiple implementations of this interface: one for writing out
220/// a .s file, and implementations that write out .o files of various formats.
221///
222class LLVM_ABI MCStreamer {
223 MCContext &Context;
224 std::unique_ptr<MCTargetStreamer> TargetStreamer;
225
226 std::vector<MCDwarfFrameInfo> DwarfFrameInfos;
227 // This is a pair of index into DwarfFrameInfos and the MCSection associated
228 // with the frame. Note, we use an index instead of an iterator because they
229 // can be invalidated in std::vector.
230 SmallVector<std::pair<size_t, MCSection *>, 1> FrameInfoStack;
231 MCDwarfFrameInfo *getCurrentDwarfFrameInfo();
232
233 /// Similar to DwarfFrameInfos, but for SEH unwind info. Chained frames may
234 /// refer to each other, so use std::unique_ptr to provide pointer stability.
235 std::vector<std::unique_ptr<WinEH::FrameInfo>> WinFrameInfos;
236
237 WinEH::FrameInfo *CurrentWinFrameInfo;
238 size_t CurrentProcWinFrameInfoStartIndex;
239
240 /// This is stack of current and previous section values saved by
241 /// pushSection.
242 SmallVector<std::pair<MCSectionSubPair, MCSectionSubPair>, 4> SectionStack;
243
244 /// Pointer to the parser's SMLoc if available. This is used to provide
245 /// locations for diagnostics.
246 const SMLoc *StartTokLocPtr = nullptr;
247
248 /// The next unique ID to use when creating a WinCFI-related section (.pdata
249 /// or .xdata). This ID ensures that we have a one-to-one mapping from
250 /// code section to unwind info section, which MSVC's incremental linker
251 /// requires.
252 unsigned NextWinCFIID = 0;
253
254 bool UseAssemblerInfoForParsing = true;
255
256 /// Is the assembler allowed to insert padding automatically? For
257 /// correctness reasons, we sometimes need to ensure instructions aren't
258 /// separated in unexpected ways. At the moment, this feature is only
259 /// useable from an integrated assembler, but assembly syntax is under
260 /// discussion for future inclusion.
261 bool AllowAutoPadding = false;
262
263protected:
264 // Symbol of the current epilog for which we are processing SEH directives.
265 WinEH::FrameInfo::Epilog *CurrentWinEpilog = nullptr;
266
267 MCFragment *CurFrag = nullptr;
268
269 MCStreamer(MCContext &Ctx);
270
271 /// This is called by popSection and switchSection, if the current
272 /// section changes.
273 virtual void changeSection(MCSection *, uint32_t);
274
275 virtual void emitCFIStartProcImpl(MCDwarfFrameInfo &Frame);
276 virtual void emitCFIEndProcImpl(MCDwarfFrameInfo &CurFrame);
277
278 WinEH::FrameInfo *getCurrentWinFrameInfo() {
279 return CurrentWinFrameInfo;
280 }
281
282 virtual void emitWindowsUnwindTables(WinEH::FrameInfo *Frame);
283
284 virtual void emitWindowsUnwindTables();
285
286 virtual void emitRawTextImpl(StringRef String);
287
288 /// Returns true if the .cv_loc directive is in the right section.
289 bool checkCVLocSection(unsigned FuncId, unsigned FileNo, SMLoc Loc);
290
291public:
292 MCStreamer(const MCStreamer &) = delete;
293 MCStreamer &operator=(const MCStreamer &) = delete;
294 virtual ~MCStreamer();
295
296 void visitUsedExpr(const MCExpr &Expr);
297 virtual void visitUsedSymbol(const MCSymbol &Sym);
298
299 void setTargetStreamer(MCTargetStreamer *TS) {
300 TargetStreamer.reset(p: TS);
301 }
302
303 void setStartTokLocPtr(const SMLoc *Loc) { StartTokLocPtr = Loc; }
304 SMLoc getStartTokLoc() const {
305 return StartTokLocPtr ? *StartTokLocPtr : SMLoc();
306 }
307
308 /// State management
309 ///
310 virtual void reset();
311
312 MCContext &getContext() const { return Context; }
313
314 // MCObjectStreamer has an MCAssembler and allows more expression folding at
315 // parse time.
316 virtual MCAssembler *getAssemblerPtr() { return nullptr; }
317
318 void setUseAssemblerInfoForParsing(bool v) { UseAssemblerInfoForParsing = v; }
319 bool getUseAssemblerInfoForParsing() { return UseAssemblerInfoForParsing; }
320
321 MCTargetStreamer *getTargetStreamer() {
322 return TargetStreamer.get();
323 }
324
325 void setAllowAutoPadding(bool v) { AllowAutoPadding = v; }
326 bool getAllowAutoPadding() const { return AllowAutoPadding; }
327
328 MCSymbol *emitLineTableLabel();
329
330 /// When emitting an object file, create and emit a real label. When emitting
331 /// textual assembly, this should do nothing to avoid polluting our output.
332 virtual MCSymbol *emitCFILabel();
333
334 /// Retrieve the current frame info if one is available and it is not yet
335 /// closed. Otherwise, issue an error and return null.
336 WinEH::FrameInfo *EnsureValidWinFrameInfo(SMLoc Loc);
337
338 unsigned getNumFrameInfos();
339 ArrayRef<MCDwarfFrameInfo> getDwarfFrameInfos() const;
340
341 bool hasUnfinishedDwarfFrameInfo();
342
343 unsigned getNumWinFrameInfos() { return WinFrameInfos.size(); }
344 ArrayRef<std::unique_ptr<WinEH::FrameInfo>> getWinFrameInfos() const {
345 return WinFrameInfos;
346 }
347
348 WinEH::FrameInfo::Epilog *getCurrentWinEpilog() const {
349 return CurrentWinEpilog;
350 }
351
352 bool isInEpilogCFI() const { return CurrentWinEpilog; }
353
354 void generateCompactUnwindEncodings(MCAsmBackend *MAB);
355
356 /// \name Assembly File Formatting.
357 /// @{
358
359 /// Return true if this streamer supports verbose assembly and if it is
360 /// enabled.
361 virtual bool isVerboseAsm() const { return false; }
362
363 /// Return true if this asm streamer supports emitting unformatted text
364 /// to the .s file with EmitRawText.
365 virtual bool hasRawTextSupport() const { return false; }
366
367 /// Is the integrated assembler required for this streamer to function
368 /// correctly?
369 virtual bool isIntegratedAssemblerRequired() const { return false; }
370
371 /// Add a textual comment.
372 ///
373 /// Typically for comments that can be emitted to the generated .s
374 /// file if applicable as a QoI issue to make the output of the compiler
375 /// more readable. This only affects the MCAsmStreamer, and only when
376 /// verbose assembly output is enabled.
377 ///
378 /// If the comment includes embedded \n's, they will each get the comment
379 /// prefix as appropriate. The added comment should not end with a \n.
380 /// By default, each comment is terminated with an end of line, i.e. the
381 /// EOL param is set to true by default. If one prefers not to end the
382 /// comment with a new line then the EOL param should be passed
383 /// with a false value.
384 virtual void AddComment(const Twine &T, bool EOL = true) {}
385
386 /// Return a raw_ostream that comments can be written to. Unlike
387 /// AddComment, you are required to terminate comments with \n if you use this
388 /// method.
389 virtual raw_ostream &getCommentOS();
390
391 /// Print T and prefix it with the comment string (normally #) and
392 /// optionally a tab. This prints the comment immediately, not at the end of
393 /// the current line. It is basically a safe version of EmitRawText: since it
394 /// only prints comments, the object streamer ignores it instead of asserting.
395 virtual void emitRawComment(const Twine &T, bool TabPrefix = true);
396
397 /// Add explicit comment T. T is required to be a valid
398 /// comment in the output and does not need to be escaped.
399 virtual void addExplicitComment(const Twine &T);
400
401 /// Emit added explicit comments.
402 virtual void emitExplicitComments();
403
404 /// Emit a blank line to a .s file to pretty it up.
405 virtual void addBlankLine() {}
406
407 /// @}
408
409 /// \name Symbol & Section Management
410 /// @{
411
412 /// Return the current section that the streamer is emitting code to.
413 MCSectionSubPair getCurrentSection() const {
414 if (!SectionStack.empty())
415 return SectionStack.back().first;
416 return MCSectionSubPair();
417 }
418 MCSection *getCurrentSectionOnly() const {
419 return CurFrag->getParent();
420 }
421
422 /// Return the previous section that the streamer is emitting code to.
423 MCSectionSubPair getPreviousSection() const {
424 if (!SectionStack.empty())
425 return SectionStack.back().second;
426 return MCSectionSubPair();
427 }
428
429 MCFragment *getCurrentFragment() const {
430 assert(!getCurrentSection().first ||
431 CurFrag->getParent() == getCurrentSection().first);
432 return CurFrag;
433 }
434
435 /// Save the current and previous section on the section stack.
436 void pushSection() {
437 SectionStack.push_back(
438 Elt: std::make_pair(x: getCurrentSection(), y: getPreviousSection()));
439 }
440
441 /// Restore the current and previous section from the section stack.
442 /// Calls changeSection as needed.
443 ///
444 /// Returns false if the stack was empty.
445 virtual bool popSection();
446
447 /// Set the current section where code is being emitted to \p Section. This
448 /// is required to update CurSection.
449 ///
450 /// This corresponds to assembler directives like .section, .text, etc.
451 virtual void switchSection(MCSection *Section, uint32_t Subsec = 0);
452 bool switchSection(MCSection *Section, const MCExpr *);
453
454 /// Similar to switchSection, but does not print the section directive.
455 virtual void switchSectionNoPrint(MCSection *Section);
456
457 /// Create the default sections and set the initial one.
458 virtual void initSections(bool NoExecStack, const MCSubtargetInfo &STI);
459
460 MCSymbol *endSection(MCSection *Section);
461
462 /// Returns the mnemonic for \p MI, if the streamer has access to a
463 /// instruction printer and returns an empty string otherwise.
464 virtual StringRef getMnemonic(const MCInst &MI) const { return ""; }
465
466 /// Emit a label for \p Symbol into the current section.
467 ///
468 /// This corresponds to an assembler statement such as:
469 /// foo:
470 ///
471 /// \param Symbol - The symbol to emit. A given symbol should only be
472 /// emitted as a label once, and symbols emitted as a label should never be
473 /// used in an assignment.
474 // FIXME: These emission are non-const because we mutate the symbol to
475 // add the section we're emitting it to later.
476 virtual void emitLabel(MCSymbol *Symbol, SMLoc Loc = SMLoc());
477
478 virtual void emitEHSymAttributes(const MCSymbol *Symbol, MCSymbol *EHSymbol);
479
480 /// Emit a .subsection_via_symbols directive.
481 virtual void emitSubsectionsViaSymbols();
482
483 /// Emit the given list \p Options of strings as linker
484 /// options into the output.
485 virtual void emitLinkerOptions(ArrayRef<std::string> Kind) {}
486
487 /// Note in the output the specified region \p Kind.
488 virtual void emitDataRegion(MCDataRegionType Kind) {}
489
490 /// Specify the Mach-O minimum deployment target version.
491 virtual void emitVersionMin(MCVersionMinType Type, unsigned Major,
492 unsigned Minor, unsigned Update,
493 VersionTuple SDKVersion) {}
494
495 /// Emit/Specify Mach-O build version command.
496 /// \p Platform should be one of MachO::PlatformType.
497 virtual void emitBuildVersion(unsigned Platform, unsigned Major,
498 unsigned Minor, unsigned Update,
499 VersionTuple SDKVersion) {}
500
501 virtual void emitDarwinTargetVariantBuildVersion(unsigned Platform,
502 unsigned Major,
503 unsigned Minor,
504 unsigned Update,
505 VersionTuple SDKVersion) {}
506
507 void emitVersionForTarget(const Triple &Target,
508 const VersionTuple &SDKVersion,
509 const Triple *DarwinTargetVariantTriple,
510 const VersionTuple &DarwinTargetVariantSDKVersion);
511
512 /// Emit an assignment of \p Value to \p Symbol.
513 ///
514 /// This corresponds to an assembler statement such as:
515 /// symbol = value
516 ///
517 /// The assignment generates no code, but has the side effect of binding the
518 /// value in the current context. For the assembly streamer, this prints the
519 /// binding into the .s file.
520 ///
521 /// \param Symbol - The symbol being assigned to.
522 /// \param Value - The value for the symbol.
523 virtual void emitAssignment(MCSymbol *Symbol, const MCExpr *Value);
524
525 /// Emit an assignment of \p Value to \p Symbol, but only if \p Value is also
526 /// emitted.
527 virtual void emitConditionalAssignment(MCSymbol *Symbol, const MCExpr *Value);
528
529 /// Emit an weak reference from \p Alias to \p Symbol.
530 ///
531 /// This corresponds to an assembler statement such as:
532 /// .weakref alias, symbol
533 ///
534 /// \param Alias - The alias that is being created.
535 /// \param Symbol - The symbol being aliased.
536 virtual void emitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol);
537
538 /// Add the given \p Attribute to \p Symbol.
539 virtual bool emitSymbolAttribute(MCSymbol *Symbol,
540 MCSymbolAttr Attribute) = 0;
541
542 /// Set the \p DescValue for the \p Symbol.
543 ///
544 /// \param Symbol - The symbol to have its n_desc field set.
545 /// \param DescValue - The value to set into the n_desc field.
546 virtual void emitSymbolDesc(MCSymbol *Symbol, unsigned DescValue);
547
548 /// Start emitting COFF symbol definition
549 ///
550 /// \param Symbol - The symbol to have its External & Type fields set.
551 virtual void beginCOFFSymbolDef(const MCSymbol *Symbol);
552
553 /// Emit the storage class of the symbol.
554 ///
555 /// \param StorageClass - The storage class the symbol should have.
556 virtual void emitCOFFSymbolStorageClass(int StorageClass);
557
558 /// Emit the type of the symbol.
559 ///
560 /// \param Type - A COFF type identifier (see COFF::SymbolType in X86COFF.h)
561 virtual void emitCOFFSymbolType(int Type);
562
563 /// Marks the end of the symbol definition.
564 virtual void endCOFFSymbolDef();
565
566 virtual void emitCOFFSafeSEH(MCSymbol const *Symbol);
567
568 /// Emits the symbol table index of a Symbol into the current section.
569 virtual void emitCOFFSymbolIndex(MCSymbol const *Symbol);
570
571 /// Emits a COFF section index.
572 ///
573 /// \param Symbol - Symbol the section number relocation should point to.
574 virtual void emitCOFFSectionIndex(MCSymbol const *Symbol);
575
576 /// Emits a COFF section relative relocation.
577 ///
578 /// \param Symbol - Symbol the section relative relocation should point to.
579 virtual void emitCOFFSecRel32(MCSymbol const *Symbol, uint64_t Offset);
580
581 /// Emits a COFF image relative relocation.
582 ///
583 /// \param Symbol - Symbol the image relative relocation should point to.
584 virtual void emitCOFFImgRel32(MCSymbol const *Symbol, int64_t Offset);
585
586 /// Emits the physical number of the section containing the given symbol as
587 /// assigned during object writing (i.e., this is not a runtime relocation).
588 virtual void emitCOFFSecNumber(MCSymbol const *Symbol);
589
590 /// Emits the offset of the symbol from the beginning of the section during
591 /// object writing (i.e., this is not a runtime relocation).
592 virtual void emitCOFFSecOffset(MCSymbol const *Symbol);
593
594 /// Emits an lcomm directive with XCOFF csect information.
595 ///
596 /// \param LabelSym - Label on the block of storage.
597 /// \param Size - The size of the block of storage.
598 /// \param CsectSym - Csect name for the block of storage.
599 /// \param Alignment - The alignment of the symbol in bytes.
600 virtual void emitXCOFFLocalCommonSymbol(MCSymbol *LabelSym, uint64_t Size,
601 MCSymbol *CsectSym, Align Alignment);
602
603 /// Emit a symbol's linkage and visibility with a linkage directive for XCOFF.
604 ///
605 /// \param Symbol - The symbol to emit.
606 /// \param Linkage - The linkage of the symbol to emit.
607 /// \param Visibility - The visibility of the symbol to emit or MCSA_Invalid
608 /// if the symbol does not have an explicit visibility.
609 virtual void emitXCOFFSymbolLinkageWithVisibility(MCSymbol *Symbol,
610 MCSymbolAttr Linkage,
611 MCSymbolAttr Visibility);
612
613 /// Emit a XCOFF .rename directive which creates a synonym for an illegal or
614 /// undesirable name.
615 ///
616 /// \param Name - The name used internally in the assembly for references to
617 /// the symbol.
618 /// \param Rename - The value to which the Name parameter is
619 /// changed at the end of assembly.
620 virtual void emitXCOFFRenameDirective(const MCSymbol *Name, StringRef Rename);
621
622 /// Emit an XCOFF .except directive which adds information about
623 /// a trap instruction to the object file exception section
624 ///
625 /// \param Symbol - The function containing the trap.
626 /// \param Lang - The language code for the exception entry.
627 /// \param Reason - The reason code for the exception entry.
628 virtual void emitXCOFFExceptDirective(const MCSymbol *Symbol,
629 const MCSymbol *Trap,
630 unsigned Lang, unsigned Reason,
631 unsigned FunctionSize, bool hasDebug);
632
633 /// Emit a XCOFF .ref directive which creates R_REF type entry in the
634 /// relocation table for one or more symbols.
635 ///
636 /// \param Sym - The symbol on the .ref directive.
637 virtual void emitXCOFFRefDirective(const MCSymbol *Symbol);
638
639 /// Emit a C_INFO symbol with XCOFF embedded metadata to the .info section.
640 ///
641 /// \param Name - The embedded metadata name
642 /// \param Metadata - The embedded metadata
643 virtual void emitXCOFFCInfoSym(StringRef Name, StringRef Metadata);
644
645 /// Emit an ELF .size directive.
646 ///
647 /// This corresponds to an assembler statement such as:
648 /// .size symbol, expression
649 virtual void emitELFSize(MCSymbol *Symbol, const MCExpr *Value);
650
651 /// Emit an ELF .symver directive.
652 ///
653 /// This corresponds to an assembler statement such as:
654 /// .symver _start, foo@@SOME_VERSION
655 virtual void emitELFSymverDirective(const MCSymbol *OriginalSym,
656 StringRef Name, bool KeepOriginalSym);
657
658 /// Emit a Linker Optimization Hint (LOH) directive.
659 /// \param Args - Arguments of the LOH.
660 virtual void emitLOHDirective(MCLOHType Kind, const MCLOHArgs &Args) {}
661
662 /// Emit a .gnu_attribute directive.
663 virtual void emitGNUAttribute(unsigned Tag, unsigned Value) {}
664
665 /// Emit a common symbol.
666 ///
667 /// \param Symbol - The common symbol to emit.
668 /// \param Size - The size of the common symbol.
669 /// \param ByteAlignment - The alignment of the symbol.
670 virtual void emitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
671 Align ByteAlignment) = 0;
672
673 /// Emit a local common (.lcomm) symbol.
674 ///
675 /// \param Symbol - The common symbol to emit.
676 /// \param Size - The size of the common symbol.
677 /// \param ByteAlignment - The alignment of the common symbol in bytes.
678 virtual void emitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size,
679 Align ByteAlignment);
680
681 /// Emit the zerofill section and an optional symbol.
682 ///
683 /// \param Section - The zerofill section to create and or to put the symbol
684 /// \param Symbol - The zerofill symbol to emit, if non-NULL.
685 /// \param Size - The size of the zerofill symbol.
686 /// \param ByteAlignment - The alignment of the zerofill symbol.
687 virtual void emitZerofill(MCSection *Section, MCSymbol *Symbol = nullptr,
688 uint64_t Size = 0, Align ByteAlignment = Align(1),
689 SMLoc Loc = SMLoc());
690
691 /// Emit a thread local bss (.tbss) symbol.
692 ///
693 /// \param Section - The thread local common section.
694 /// \param Symbol - The thread local common symbol to emit.
695 /// \param Size - The size of the symbol.
696 /// \param ByteAlignment - The alignment of the thread local common symbol.
697 virtual void emitTBSSSymbol(MCSection *Section, MCSymbol *Symbol,
698 uint64_t Size, Align ByteAlignment = Align(1));
699
700 /// @}
701 /// \name Generating Data
702 /// @{
703
704 /// Emit the bytes in \p Data into the output.
705 ///
706 /// This is used to implement assembler directives such as .byte, .ascii,
707 /// etc.
708 virtual void emitBytes(StringRef Data);
709
710 /// Functionally identical to EmitBytes. When emitting textual assembly, this
711 /// method uses .byte directives instead of .ascii or .asciz for readability.
712 virtual void emitBinaryData(StringRef Data);
713
714 /// Emit the expression \p Value into the output as a native
715 /// integer of the given \p Size bytes.
716 ///
717 /// This is used to implement assembler directives such as .word, .quad,
718 /// etc.
719 ///
720 /// \param Value - The value to emit.
721 /// \param Size - The size of the integer (in bytes) to emit. This must
722 /// match a native machine width.
723 /// \param Loc - The location of the expression for error reporting.
724 virtual void emitValueImpl(const MCExpr *Value, unsigned Size,
725 SMLoc Loc = SMLoc());
726
727 void emitValue(const MCExpr *Value, unsigned Size, SMLoc Loc = SMLoc());
728
729 /// Special case of EmitValue that avoids the client having
730 /// to pass in a MCExpr for constant integers.
731 virtual void emitIntValue(uint64_t Value, unsigned Size);
732 virtual void emitIntValue(const APInt &Value);
733
734 /// Special case of EmitValue that avoids the client having to pass
735 /// in a MCExpr for constant integers & prints in Hex format for certain
736 /// modes.
737 virtual void emitIntValueInHex(uint64_t Value, unsigned Size) {
738 emitIntValue(Value, Size);
739 }
740
741 void emitInt8(uint64_t Value) { emitIntValue(Value, Size: 1); }
742 void emitInt16(uint64_t Value) { emitIntValue(Value, Size: 2); }
743 void emitInt32(uint64_t Value) { emitIntValue(Value, Size: 4); }
744 void emitInt64(uint64_t Value) { emitIntValue(Value, Size: 8); }
745
746 /// Special case of EmitValue that avoids the client having to pass
747 /// in a MCExpr for constant integers & prints in Hex format for certain
748 /// modes, pads the field with leading zeros to Size width
749 virtual void emitIntValueInHexWithPadding(uint64_t Value, unsigned Size) {
750 emitIntValue(Value, Size);
751 }
752
753 virtual void emitULEB128Value(const MCExpr *Value);
754
755 virtual void emitSLEB128Value(const MCExpr *Value);
756
757 /// Special case of EmitULEB128Value that avoids the client having to
758 /// pass in a MCExpr for constant integers.
759 unsigned emitULEB128IntValue(uint64_t Value, unsigned PadTo = 0);
760
761 /// Special case of EmitSLEB128Value that avoids the client having to
762 /// pass in a MCExpr for constant integers.
763 unsigned emitSLEB128IntValue(int64_t Value);
764
765 /// Special case of EmitValue that avoids the client having to pass in
766 /// a MCExpr for MCSymbols.
767 void emitSymbolValue(const MCSymbol *Sym, unsigned Size,
768 bool IsSectionRelative = false);
769
770 /// Emit NumBytes bytes worth of the value specified by FillValue.
771 /// This implements directives such as '.space'.
772 void emitFill(uint64_t NumBytes, uint8_t FillValue);
773
774 /// Emit \p Size bytes worth of the value specified by \p FillValue.
775 ///
776 /// This is used to implement assembler directives such as .space or .skip.
777 ///
778 /// \param NumBytes - The number of bytes to emit.
779 /// \param FillValue - The value to use when filling bytes.
780 /// \param Loc - The location of the expression for error reporting.
781 virtual void emitFill(const MCExpr &NumBytes, uint64_t FillValue,
782 SMLoc Loc = SMLoc());
783
784 /// Emit \p NumValues copies of \p Size bytes. Each \p Size bytes is
785 /// taken from the lowest order 4 bytes of \p Expr expression.
786 ///
787 /// This is used to implement assembler directives such as .fill.
788 ///
789 /// \param NumValues - The number of copies of \p Size bytes to emit.
790 /// \param Size - The size (in bytes) of each repeated value.
791 /// \param Expr - The expression from which \p Size bytes are used.
792 virtual void emitFill(const MCExpr &NumValues, int64_t Size, int64_t Expr,
793 SMLoc Loc = SMLoc());
794
795 virtual void emitNops(int64_t NumBytes, int64_t ControlledNopLength,
796 SMLoc Loc, const MCSubtargetInfo& STI);
797
798 /// Emit NumBytes worth of zeros.
799 /// This function properly handles data in virtual sections.
800 void emitZeros(uint64_t NumBytes);
801
802 /// Emit some number of copies of \p Value until the byte alignment \p
803 /// ByteAlignment is reached.
804 ///
805 /// If the number of bytes need to emit for the alignment is not a multiple
806 /// of \p ValueSize, then the contents of the emitted fill bytes is
807 /// undefined.
808 ///
809 /// This used to implement the .align assembler directive.
810 ///
811 /// \param Alignment - The alignment to reach.
812 /// \param Value - The value to use when filling bytes.
813 /// \param ValueSize - The size of the integer (in bytes) to emit for
814 /// \p Value. This must match a native machine width.
815 /// \param MaxBytesToEmit - The maximum numbers of bytes to emit, or 0. If
816 /// the alignment cannot be reached in this many bytes, no bytes are
817 /// emitted.
818 virtual void emitValueToAlignment(Align Alignment, int64_t Value = 0,
819 unsigned ValueSize = 1,
820 unsigned MaxBytesToEmit = 0);
821
822 /// Emit nops until the byte alignment \p ByteAlignment is reached.
823 ///
824 /// This used to align code where the alignment bytes may be executed. This
825 /// can emit different bytes for different sizes to optimize execution.
826 ///
827 /// \param Alignment - The alignment to reach.
828 /// \param STI - The MCSubtargetInfo in operation when padding is emitted.
829 /// \param MaxBytesToEmit - The maximum numbers of bytes to emit, or 0. If
830 /// the alignment cannot be reached in this many bytes, no bytes are
831 /// emitted.
832 virtual void emitCodeAlignment(Align Alignment, const MCSubtargetInfo *STI,
833 unsigned MaxBytesToEmit = 0);
834
835 /// Emit some number of copies of \p Value until the byte offset \p
836 /// Offset is reached.
837 ///
838 /// This is used to implement assembler directives such as .org.
839 ///
840 /// \param Offset - The offset to reach. This may be an expression, but the
841 /// expression must be associated with the current section.
842 /// \param Value - The value to use when filling bytes.
843 virtual void emitValueToOffset(const MCExpr *Offset, unsigned char Value,
844 SMLoc Loc);
845
846 /// @}
847
848 /// Switch to a new logical file. This is used to implement the '.file
849 /// "foo.c"' assembler directive.
850 virtual void emitFileDirective(StringRef Filename);
851
852 /// Emit ".file assembler diretive with additioal info.
853 virtual void emitFileDirective(StringRef Filename, StringRef CompilerVersion,
854 StringRef TimeStamp, StringRef Description);
855
856 /// Emit the "identifiers" directive. This implements the
857 /// '.ident "version foo"' assembler directive.
858 virtual void emitIdent(StringRef IdentString) {}
859
860 /// Associate a filename with a specified logical file number. This
861 /// implements the DWARF2 '.file 4 "foo.c"' assembler directive.
862 unsigned emitDwarfFileDirective(
863 unsigned FileNo, StringRef Directory, StringRef Filename,
864 std::optional<MD5::MD5Result> Checksum = std::nullopt,
865 std::optional<StringRef> Source = std::nullopt, unsigned CUID = 0) {
866 return cantFail(
867 ValOrErr: tryEmitDwarfFileDirective(FileNo, Directory, Filename, Checksum,
868 Source, CUID));
869 }
870
871 /// Associate a filename with a specified logical file number.
872 /// Also associate a directory, optional checksum, and optional source
873 /// text with the logical file. This implements the DWARF2
874 /// '.file 4 "dir/foo.c"' assembler directive, and the DWARF5
875 /// '.file 4 "dir/foo.c" md5 "..." source "..."' assembler directive.
876 virtual Expected<unsigned> tryEmitDwarfFileDirective(
877 unsigned FileNo, StringRef Directory, StringRef Filename,
878 std::optional<MD5::MD5Result> Checksum = std::nullopt,
879 std::optional<StringRef> Source = std::nullopt, unsigned CUID = 0);
880
881 /// Specify the "root" file of the compilation, using the ".file 0" extension.
882 virtual void emitDwarfFile0Directive(StringRef Directory, StringRef Filename,
883 std::optional<MD5::MD5Result> Checksum,
884 std::optional<StringRef> Source,
885 unsigned CUID = 0);
886
887 virtual void emitCFIBKeyFrame();
888 virtual void emitCFIMTETaggedFrame();
889
890 /// This implements the DWARF2 '.loc fileno lineno ...' assembler
891 /// directive.
892 virtual void emitDwarfLocDirective(unsigned FileNo, unsigned Line,
893 unsigned Column, unsigned Flags,
894 unsigned Isa, unsigned Discriminator,
895 StringRef FileName,
896 StringRef Comment = {});
897
898 /// This implements the '.loc_label Name' directive.
899 virtual void emitDwarfLocLabelDirective(SMLoc Loc, StringRef Name);
900
901 /// Associate a filename with a specified logical file number, and also
902 /// specify that file's checksum information. This implements the '.cv_file 4
903 /// "foo.c"' assembler directive. Returns true on success.
904 virtual bool emitCVFileDirective(unsigned FileNo, StringRef Filename,
905 ArrayRef<uint8_t> Checksum,
906 unsigned ChecksumKind);
907
908 /// Introduces a function id for use with .cv_loc.
909 virtual bool emitCVFuncIdDirective(unsigned FunctionId);
910
911 /// Introduces an inline call site id for use with .cv_loc. Includes
912 /// extra information for inline line table generation.
913 virtual bool emitCVInlineSiteIdDirective(unsigned FunctionId, unsigned IAFunc,
914 unsigned IAFile, unsigned IALine,
915 unsigned IACol, SMLoc Loc);
916
917 /// This implements the CodeView '.cv_loc' assembler directive.
918 virtual void emitCVLocDirective(unsigned FunctionId, unsigned FileNo,
919 unsigned Line, unsigned Column,
920 bool PrologueEnd, bool IsStmt,
921 StringRef FileName, SMLoc Loc);
922
923 /// This implements the CodeView '.cv_linetable' assembler directive.
924 virtual void emitCVLinetableDirective(unsigned FunctionId,
925 const MCSymbol *FnStart,
926 const MCSymbol *FnEnd);
927
928 /// This implements the CodeView '.cv_inline_linetable' assembler
929 /// directive.
930 virtual void emitCVInlineLinetableDirective(unsigned PrimaryFunctionId,
931 unsigned SourceFileId,
932 unsigned SourceLineNum,
933 const MCSymbol *FnStartSym,
934 const MCSymbol *FnEndSym);
935
936 /// This implements the CodeView '.cv_def_range' assembler
937 /// directive.
938 virtual void emitCVDefRangeDirective(
939 ArrayRef<std::pair<const MCSymbol *, const MCSymbol *>> Ranges,
940 StringRef FixedSizePortion);
941
942 virtual void emitCVDefRangeDirective(
943 ArrayRef<std::pair<const MCSymbol *, const MCSymbol *>> Ranges,
944 codeview::DefRangeRegisterRelHeader DRHdr);
945
946 virtual void emitCVDefRangeDirective(
947 ArrayRef<std::pair<const MCSymbol *, const MCSymbol *>> Ranges,
948 codeview::DefRangeSubfieldRegisterHeader DRHdr);
949
950 virtual void emitCVDefRangeDirective(
951 ArrayRef<std::pair<const MCSymbol *, const MCSymbol *>> Ranges,
952 codeview::DefRangeRegisterHeader DRHdr);
953
954 virtual void emitCVDefRangeDirective(
955 ArrayRef<std::pair<const MCSymbol *, const MCSymbol *>> Ranges,
956 codeview::DefRangeFramePointerRelHeader DRHdr);
957
958 /// This implements the CodeView '.cv_stringtable' assembler directive.
959 virtual void emitCVStringTableDirective() {}
960
961 /// This implements the CodeView '.cv_filechecksums' assembler directive.
962 virtual void emitCVFileChecksumsDirective() {}
963
964 /// This implements the CodeView '.cv_filechecksumoffset' assembler
965 /// directive.
966 virtual void emitCVFileChecksumOffsetDirective(unsigned FileNo) {}
967
968 /// This implements the CodeView '.cv_fpo_data' assembler directive.
969 virtual void emitCVFPOData(const MCSymbol *ProcSym, SMLoc Loc = {}) {}
970
971 /// Emit the absolute difference between two symbols.
972 ///
973 /// \pre Offset of \c Hi is greater than the offset \c Lo.
974 virtual void emitAbsoluteSymbolDiff(const MCSymbol *Hi, const MCSymbol *Lo,
975 unsigned Size);
976
977 /// Emit the absolute difference between two symbols encoded with ULEB128.
978 virtual void emitAbsoluteSymbolDiffAsULEB128(const MCSymbol *Hi,
979 const MCSymbol *Lo);
980
981 virtual MCSymbol *getDwarfLineTableSymbol(unsigned CUID);
982 virtual void emitCFISections(bool EH, bool Debug);
983 void emitCFIStartProc(bool IsSimple, SMLoc Loc = SMLoc());
984 void emitCFIEndProc();
985 virtual void emitCFIDefCfa(int64_t Register, int64_t Offset, SMLoc Loc = {});
986 virtual void emitCFIDefCfaOffset(int64_t Offset, SMLoc Loc = {});
987 virtual void emitCFIDefCfaRegister(int64_t Register, SMLoc Loc = {});
988 virtual void emitCFILLVMDefAspaceCfa(int64_t Register, int64_t Offset,
989 int64_t AddressSpace, SMLoc Loc = {});
990 virtual void emitCFIOffset(int64_t Register, int64_t Offset, SMLoc Loc = {});
991 virtual void emitCFIPersonality(const MCSymbol *Sym, unsigned Encoding);
992 virtual void emitCFILsda(const MCSymbol *Sym, unsigned Encoding);
993 virtual void emitCFIRememberState(SMLoc Loc);
994 virtual void emitCFIRestoreState(SMLoc Loc);
995 virtual void emitCFISameValue(int64_t Register, SMLoc Loc = {});
996 virtual void emitCFIRestore(int64_t Register, SMLoc Loc = {});
997 virtual void emitCFIRelOffset(int64_t Register, int64_t Offset, SMLoc Loc);
998 virtual void emitCFIAdjustCfaOffset(int64_t Adjustment, SMLoc Loc = {});
999 virtual void emitCFIEscape(StringRef Values, SMLoc Loc = {});
1000 virtual void emitCFIReturnColumn(int64_t Register);
1001 virtual void emitCFIGnuArgsSize(int64_t Size, SMLoc Loc = {});
1002 virtual void emitCFISignalFrame();
1003 virtual void emitCFIUndefined(int64_t Register, SMLoc Loc = {});
1004 virtual void emitCFIRegister(int64_t Register1, int64_t Register2,
1005 SMLoc Loc = {});
1006 virtual void emitCFIWindowSave(SMLoc Loc = {});
1007 virtual void emitCFINegateRAState(SMLoc Loc = {});
1008 virtual void emitCFINegateRAStateWithPC(SMLoc Loc = {});
1009 virtual void emitCFILabelDirective(SMLoc Loc, StringRef Name);
1010 virtual void emitCFIValOffset(int64_t Register, int64_t Offset,
1011 SMLoc Loc = {});
1012
1013 virtual void emitWinCFIStartProc(const MCSymbol *Symbol, SMLoc Loc = SMLoc());
1014 virtual void emitWinCFIEndProc(SMLoc Loc = SMLoc());
1015 /// This is used on platforms, such as Windows on ARM64, that require function
1016 /// or funclet sizes to be emitted in .xdata before the End marker is emitted
1017 /// for the frame. We cannot use the End marker, as it is not set at the
1018 /// point of emitting .xdata, in order to indicate that the frame is active.
1019 virtual void emitWinCFIFuncletOrFuncEnd(SMLoc Loc = SMLoc());
1020 virtual void emitWinCFIStartChained(SMLoc Loc = SMLoc());
1021 virtual void emitWinCFIEndChained(SMLoc Loc = SMLoc());
1022 virtual void emitWinCFIPushReg(MCRegister Register, SMLoc Loc = SMLoc());
1023 virtual void emitWinCFISetFrame(MCRegister Register, unsigned Offset,
1024 SMLoc Loc = SMLoc());
1025 virtual void emitWinCFIAllocStack(unsigned Size, SMLoc Loc = SMLoc());
1026 virtual void emitWinCFISaveReg(MCRegister Register, unsigned Offset,
1027 SMLoc Loc = SMLoc());
1028 virtual void emitWinCFISaveXMM(MCRegister Register, unsigned Offset,
1029 SMLoc Loc = SMLoc());
1030 virtual void emitWinCFIPushFrame(bool Code, SMLoc Loc = SMLoc());
1031 virtual void emitWinCFIEndProlog(SMLoc Loc = SMLoc());
1032 virtual void emitWinCFIBeginEpilogue(SMLoc Loc = SMLoc());
1033 virtual void emitWinCFIEndEpilogue(SMLoc Loc = SMLoc());
1034 virtual void emitWinCFIUnwindV2Start(SMLoc Loc = SMLoc());
1035 virtual void emitWinCFIUnwindVersion(uint8_t Version, SMLoc Loc = SMLoc());
1036 virtual void emitWinEHHandler(const MCSymbol *Sym, bool Unwind, bool Except,
1037 SMLoc Loc = SMLoc());
1038 virtual void emitWinEHHandlerData(SMLoc Loc = SMLoc());
1039
1040 virtual void emitCGProfileEntry(const MCSymbolRefExpr *From,
1041 const MCSymbolRefExpr *To, uint64_t Count);
1042
1043 /// Get the .pdata section used for the given section. Typically the given
1044 /// section is either the main .text section or some other COMDAT .text
1045 /// section, but it may be any section containing code.
1046 MCSection *getAssociatedPDataSection(const MCSection *TextSec);
1047
1048 /// Get the .xdata section used for the given section.
1049 MCSection *getAssociatedXDataSection(const MCSection *TextSec);
1050
1051 virtual void emitSyntaxDirective();
1052
1053 /// Record a relocation described by the .reloc directive. Return std::nullopt
1054 /// if succeeded. Otherwise, return a pair (Name is invalid, error message).
1055 virtual std::optional<std::pair<bool, std::string>>
1056 emitRelocDirective(const MCExpr &Offset, StringRef Name, const MCExpr *Expr,
1057 SMLoc Loc, const MCSubtargetInfo &STI) {
1058 return std::nullopt;
1059 }
1060
1061 virtual void emitAddrsig() {}
1062 virtual void emitAddrsigSym(const MCSymbol *Sym) {}
1063
1064 /// Emit the given \p Instruction into the current section.
1065 virtual void emitInstruction(const MCInst &Inst, const MCSubtargetInfo &STI);
1066
1067 /// Emit the a pseudo probe into the current section.
1068 virtual void emitPseudoProbe(uint64_t Guid, uint64_t Index, uint64_t Type,
1069 uint64_t Attr, uint64_t Discriminator,
1070 const MCPseudoProbeInlineStack &InlineStack,
1071 MCSymbol *FnSym);
1072
1073 /// Set the bundle alignment mode from now on in the section.
1074 /// The value 1 means turn the bundle alignment off.
1075 virtual void emitBundleAlignMode(Align Alignment);
1076
1077 /// The following instructions are a bundle-locked group.
1078 ///
1079 /// \param AlignToEnd - If true, the bundle-locked group will be aligned to
1080 /// the end of a bundle.
1081 virtual void emitBundleLock(bool AlignToEnd);
1082
1083 /// Ends a bundle-locked group.
1084 virtual void emitBundleUnlock();
1085
1086 /// If this file is backed by a assembly streamer, this dumps the
1087 /// specified string in the output .s file. This capability is indicated by
1088 /// the hasRawTextSupport() predicate. By default this aborts.
1089 void emitRawText(const Twine &String);
1090
1091 /// Streamer specific finalization.
1092 virtual void finishImpl();
1093 /// Finish emission of machine code.
1094 void finish(SMLoc EndLoc = SMLoc());
1095
1096 virtual bool mayHaveInstructions(MCSection &Sec) const { return true; }
1097
1098 /// Emit a special value of 0xffffffff if producing 64-bit debugging info.
1099 void maybeEmitDwarf64Mark();
1100
1101 /// Emit a unit length field. The actual format, DWARF32 or DWARF64, is chosen
1102 /// according to the settings.
1103 virtual void emitDwarfUnitLength(uint64_t Length, const Twine &Comment);
1104
1105 /// Emit a unit length field. The actual format, DWARF32 or DWARF64, is chosen
1106 /// according to the settings.
1107 /// Return the end symbol generated inside, the caller needs to emit it.
1108 virtual MCSymbol *emitDwarfUnitLength(const Twine &Prefix,
1109 const Twine &Comment);
1110
1111 /// Emit the debug line start label.
1112 virtual void emitDwarfLineStartLabel(MCSymbol *StartSym);
1113
1114 /// Emit the debug line end entry.
1115 virtual void emitDwarfLineEndEntry(MCSection *Section, MCSymbol *LastLabel,
1116 MCSymbol *EndLabel = nullptr) {}
1117
1118 /// If targets does not support representing debug line section by .loc/.file
1119 /// directives in assembly output, we need to populate debug line section with
1120 /// raw debug line contents.
1121 virtual void emitDwarfAdvanceLineAddr(int64_t LineDelta,
1122 const MCSymbol *LastLabel,
1123 const MCSymbol *Label,
1124 unsigned PointerSize) {}
1125};
1126
1127inline MCContext &MCTargetStreamer::getContext() {
1128 return Streamer.getContext();
1129}
1130
1131/// Create a dummy machine code streamer, which does nothing. This is useful for
1132/// timing the assembler front end.
1133LLVM_ABI MCStreamer *createNullStreamer(MCContext &Ctx);
1134
1135} // end namespace llvm
1136
1137#endif // LLVM_MC_MCSTREAMER_H
1138

Provided by KDAB

Privacy Policy
Update your C++ knowledge – Modern C++11/14/17 Training
Find out more

source code of llvm/include/llvm/MC/MCStreamer.h