blob: 67284fb379f388ea849441369d61da314ef0ef04 [file] [log] [blame]
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01001//===- MCStreamer.h - High-level Streaming Machine Code Output --*- C++ -*-===//
2//
Andrew Walbran16937d02019-10-22 13:54:20 +01003// 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
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01006//
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/Optional.h"
19#include "llvm/ADT/SmallVector.h"
20#include "llvm/ADT/StringRef.h"
21#include "llvm/MC/MCDirectives.h"
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010022#include "llvm/MC/MCLinkerOptimizationHint.h"
23#include "llvm/MC/MCSymbol.h"
24#include "llvm/MC/MCWinEH.h"
25#include "llvm/Support/Error.h"
26#include "llvm/Support/MD5.h"
27#include "llvm/Support/SMLoc.h"
28#include "llvm/Support/TargetParser.h"
Andrew Walbran16937d02019-10-22 13:54:20 +010029#include "llvm/Support/VersionTuple.h"
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010030#include <cassert>
31#include <cstdint>
32#include <memory>
33#include <string>
34#include <utility>
35#include <vector>
36
37namespace llvm {
38
39class AssemblerConstantPools;
40class formatted_raw_ostream;
41class MCAsmBackend;
42class MCCodeEmitter;
43struct MCCodePaddingContext;
44class MCContext;
Andrew Walbran3d2c1972020-04-07 12:24:26 +010045struct MCDwarfFrameInfo;
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010046class MCExpr;
47class MCInst;
48class MCInstPrinter;
49class MCSection;
50class MCStreamer;
51class MCSymbolRefExpr;
52class MCSubtargetInfo;
53class raw_ostream;
54class Twine;
55
56using MCSectionSubPair = std::pair<MCSection *, const MCExpr *>;
57
58/// Target specific streamer interface. This is used so that targets can
59/// implement support for target specific assembly directives.
60///
61/// If target foo wants to use this, it should implement 3 classes:
62/// * FooTargetStreamer : public MCTargetStreamer
63/// * FooTargetAsmStreamer : public FooTargetStreamer
64/// * FooTargetELFStreamer : public FooTargetStreamer
65///
66/// FooTargetStreamer should have a pure virtual method for each directive. For
67/// example, for a ".bar symbol_name" directive, it should have
68/// virtual emitBar(const MCSymbol &Symbol) = 0;
69///
70/// The FooTargetAsmStreamer and FooTargetELFStreamer classes implement the
71/// method. The assembly streamer just prints ".bar symbol_name". The object
72/// streamer does whatever is needed to implement .bar in the object file.
73///
74/// In the assembly printer and parser the target streamer can be used by
75/// calling getTargetStreamer and casting it to FooTargetStreamer:
76///
77/// MCTargetStreamer &TS = OutStreamer.getTargetStreamer();
78/// FooTargetStreamer &ATS = static_cast<FooTargetStreamer &>(TS);
79///
80/// The base classes FooTargetAsmStreamer and FooTargetELFStreamer should
81/// *never* be treated differently. Callers should always talk to a
82/// FooTargetStreamer.
83class MCTargetStreamer {
84protected:
85 MCStreamer &Streamer;
86
87public:
88 MCTargetStreamer(MCStreamer &S);
89 virtual ~MCTargetStreamer();
90
91 MCStreamer &getStreamer() { return Streamer; }
92
93 // Allow a target to add behavior to the EmitLabel of MCStreamer.
94 virtual void emitLabel(MCSymbol *Symbol);
95 // Allow a target to add behavior to the emitAssignment of MCStreamer.
96 virtual void emitAssignment(MCSymbol *Symbol, const MCExpr *Value);
97
98 virtual void prettyPrintAsm(MCInstPrinter &InstPrinter, raw_ostream &OS,
99 const MCInst &Inst, const MCSubtargetInfo &STI);
100
101 virtual void emitDwarfFileDirective(StringRef Directive);
102
103 /// Update streamer for a new active section.
104 ///
105 /// This is called by PopSection and SwitchSection, if the current
106 /// section changes.
107 virtual void changeSection(const MCSection *CurSection, MCSection *Section,
108 const MCExpr *SubSection, raw_ostream &OS);
109
110 virtual void emitValue(const MCExpr *Value);
111
Andrew Walbran16937d02019-10-22 13:54:20 +0100112 /// Emit the bytes in \p Data into the output.
113 ///
114 /// This is used to emit bytes in \p Data as sequence of .byte directives.
115 virtual void emitRawBytes(StringRef Data);
116
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100117 virtual void finish();
118};
119
120// FIXME: declared here because it is used from
121// lib/CodeGen/AsmPrinter/ARMException.cpp.
122class ARMTargetStreamer : public MCTargetStreamer {
123public:
124 ARMTargetStreamer(MCStreamer &S);
125 ~ARMTargetStreamer() override;
126
127 virtual void emitFnStart();
128 virtual void emitFnEnd();
129 virtual void emitCantUnwind();
130 virtual void emitPersonality(const MCSymbol *Personality);
131 virtual void emitPersonalityIndex(unsigned Index);
132 virtual void emitHandlerData();
133 virtual void emitSetFP(unsigned FpReg, unsigned SpReg,
134 int64_t Offset = 0);
135 virtual void emitMovSP(unsigned Reg, int64_t Offset = 0);
136 virtual void emitPad(int64_t Offset);
137 virtual void emitRegSave(const SmallVectorImpl<unsigned> &RegList,
138 bool isVector);
139 virtual void emitUnwindRaw(int64_t StackOffset,
140 const SmallVectorImpl<uint8_t> &Opcodes);
141
142 virtual void switchVendor(StringRef Vendor);
143 virtual void emitAttribute(unsigned Attribute, unsigned Value);
144 virtual void emitTextAttribute(unsigned Attribute, StringRef String);
145 virtual void emitIntTextAttribute(unsigned Attribute, unsigned IntValue,
146 StringRef StringValue = "");
147 virtual void emitFPU(unsigned FPU);
148 virtual void emitArch(ARM::ArchKind Arch);
149 virtual void emitArchExtension(unsigned ArchExt);
150 virtual void emitObjectArch(ARM::ArchKind Arch);
151 void emitTargetAttributes(const MCSubtargetInfo &STI);
152 virtual void finishAttributeSection();
153 virtual void emitInst(uint32_t Inst, char Suffix = '\0');
154
155 virtual void AnnotateTLSDescriptorSequence(const MCSymbolRefExpr *SRE);
156
157 virtual void emitThumbSet(MCSymbol *Symbol, const MCExpr *Value);
158
159 void finish() override;
160
161 /// Reset any state between object emissions, i.e. the equivalent of
162 /// MCStreamer's reset method.
163 virtual void reset();
164
165 /// Callback used to implement the ldr= pseudo.
166 /// Add a new entry to the constant pool for the current section and return an
167 /// MCExpr that can be used to refer to the constant pool location.
168 const MCExpr *addConstantPoolEntry(const MCExpr *, SMLoc Loc);
169
170 /// Callback used to implemnt the .ltorg directive.
171 /// Emit contents of constant pool for the current section.
172 void emitCurrentConstantPool();
173
174private:
175 std::unique_ptr<AssemblerConstantPools> ConstantPools;
176};
177
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100178/// Streaming machine code generation interface.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100179///
180/// This interface is intended to provide a programatic interface that is very
181/// similar to the level that an assembler .s file provides. It has callbacks
182/// to emit bytes, handle directives, etc. The implementation of this interface
183/// retains state to know what the current section is etc.
184///
185/// There are multiple implementations of this interface: one for writing out
186/// a .s file, and implementations that write out .o files of various formats.
187///
188class MCStreamer {
189 MCContext &Context;
190 std::unique_ptr<MCTargetStreamer> TargetStreamer;
191
192 std::vector<MCDwarfFrameInfo> DwarfFrameInfos;
193 MCDwarfFrameInfo *getCurrentDwarfFrameInfo();
194
195 /// Similar to DwarfFrameInfos, but for SEH unwind info. Chained frames may
196 /// refer to each other, so use std::unique_ptr to provide pointer stability.
197 std::vector<std::unique_ptr<WinEH::FrameInfo>> WinFrameInfos;
198
199 WinEH::FrameInfo *CurrentWinFrameInfo;
200
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100201 /// Tracks an index to represent the order a symbol was emitted in.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100202 /// Zero means we did not emit that symbol.
203 DenseMap<const MCSymbol *, unsigned> SymbolOrdering;
204
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100205 /// This is stack of current and previous section values saved by
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100206 /// PushSection.
207 SmallVector<std::pair<MCSectionSubPair, MCSectionSubPair>, 4> SectionStack;
208
209 /// The next unique ID to use when creating a WinCFI-related section (.pdata
210 /// or .xdata). This ID ensures that we have a one-to-one mapping from
211 /// code section to unwind info section, which MSVC's incremental linker
212 /// requires.
213 unsigned NextWinCFIID = 0;
214
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100215 bool UseAssemblerInfoForParsing;
216
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100217protected:
218 MCStreamer(MCContext &Ctx);
219
220 virtual void EmitCFIStartProcImpl(MCDwarfFrameInfo &Frame);
221 virtual void EmitCFIEndProcImpl(MCDwarfFrameInfo &CurFrame);
222
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100223 WinEH::FrameInfo *getCurrentWinFrameInfo() {
224 return CurrentWinFrameInfo;
225 }
226
227 virtual void EmitWindowsUnwindTables();
228
229 virtual void EmitRawTextImpl(StringRef String);
230
Andrew Scull0372a572018-11-16 15:47:06 +0000231 /// Returns true if the the .cv_loc directive is in the right section.
232 bool checkCVLocSection(unsigned FuncId, unsigned FileNo, SMLoc Loc);
233
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100234public:
235 MCStreamer(const MCStreamer &) = delete;
236 MCStreamer &operator=(const MCStreamer &) = delete;
237 virtual ~MCStreamer();
238
239 void visitUsedExpr(const MCExpr &Expr);
240 virtual void visitUsedSymbol(const MCSymbol &Sym);
241
242 void setTargetStreamer(MCTargetStreamer *TS) {
243 TargetStreamer.reset(TS);
244 }
245
246 /// State management
247 ///
248 virtual void reset();
249
250 MCContext &getContext() const { return Context; }
251
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100252 virtual MCAssembler *getAssemblerPtr() { return nullptr; }
253
254 void setUseAssemblerInfoForParsing(bool v) { UseAssemblerInfoForParsing = v; }
255 bool getUseAssemblerInfoForParsing() { return UseAssemblerInfoForParsing; }
256
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100257 MCTargetStreamer *getTargetStreamer() {
258 return TargetStreamer.get();
259 }
260
Andrew Walbran16937d02019-10-22 13:54:20 +0100261 /// When emitting an object file, create and emit a real label. When emitting
262 /// textual assembly, this should do nothing to avoid polluting our output.
263 virtual MCSymbol *EmitCFILabel();
264
265 /// Retreive the current frame info if one is available and it is not yet
266 /// closed. Otherwise, issue an error and return null.
267 WinEH::FrameInfo *EnsureValidWinFrameInfo(SMLoc Loc);
268
Andrew Walbran3d2c1972020-04-07 12:24:26 +0100269 unsigned getNumFrameInfos();
270 ArrayRef<MCDwarfFrameInfo> getDwarfFrameInfos() const;
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100271
272 bool hasUnfinishedDwarfFrameInfo();
273
274 unsigned getNumWinFrameInfos() { return WinFrameInfos.size(); }
275 ArrayRef<std::unique_ptr<WinEH::FrameInfo>> getWinFrameInfos() const {
276 return WinFrameInfos;
277 }
278
279 void generateCompactUnwindEncodings(MCAsmBackend *MAB);
280
281 /// \name Assembly File Formatting.
282 /// @{
283
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100284 /// Return true if this streamer supports verbose assembly and if it is
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100285 /// enabled.
286 virtual bool isVerboseAsm() const { return false; }
287
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100288 /// Return true if this asm streamer supports emitting unformatted text
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100289 /// to the .s file with EmitRawText.
290 virtual bool hasRawTextSupport() const { return false; }
291
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100292 /// Is the integrated assembler required for this streamer to function
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100293 /// correctly?
294 virtual bool isIntegratedAssemblerRequired() const { return false; }
295
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100296 /// Add a textual comment.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100297 ///
298 /// Typically for comments that can be emitted to the generated .s
299 /// file if applicable as a QoI issue to make the output of the compiler
300 /// more readable. This only affects the MCAsmStreamer, and only when
301 /// verbose assembly output is enabled.
302 ///
303 /// If the comment includes embedded \n's, they will each get the comment
304 /// prefix as appropriate. The added comment should not end with a \n.
305 /// By default, each comment is terminated with an end of line, i.e. the
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100306 /// EOL param is set to true by default. If one prefers not to end the
307 /// comment with a new line then the EOL param should be passed
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100308 /// with a false value.
309 virtual void AddComment(const Twine &T, bool EOL = true) {}
310
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100311 /// Return a raw_ostream that comments can be written to. Unlike
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100312 /// AddComment, you are required to terminate comments with \n if you use this
313 /// method.
314 virtual raw_ostream &GetCommentOS();
315
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100316 /// Print T and prefix it with the comment string (normally #) and
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100317 /// optionally a tab. This prints the comment immediately, not at the end of
318 /// the current line. It is basically a safe version of EmitRawText: since it
319 /// only prints comments, the object streamer ignores it instead of asserting.
320 virtual void emitRawComment(const Twine &T, bool TabPrefix = true);
321
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100322 /// Add explicit comment T. T is required to be a valid
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100323 /// comment in the output and does not need to be escaped.
324 virtual void addExplicitComment(const Twine &T);
325
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100326 /// Emit added explicit comments.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100327 virtual void emitExplicitComments();
328
329 /// AddBlankLine - Emit a blank line to a .s file to pretty it up.
330 virtual void AddBlankLine() {}
331
332 /// @}
333
334 /// \name Symbol & Section Management
335 /// @{
336
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100337 /// Return the current section that the streamer is emitting code to.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100338 MCSectionSubPair getCurrentSection() const {
339 if (!SectionStack.empty())
340 return SectionStack.back().first;
341 return MCSectionSubPair();
342 }
343 MCSection *getCurrentSectionOnly() const { return getCurrentSection().first; }
344
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100345 /// Return the previous section that the streamer is emitting code to.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100346 MCSectionSubPair getPreviousSection() const {
347 if (!SectionStack.empty())
348 return SectionStack.back().second;
349 return MCSectionSubPair();
350 }
351
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100352 /// Returns an index to represent the order a symbol was emitted in.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100353 /// (zero if we did not emit that symbol)
354 unsigned GetSymbolOrder(const MCSymbol *Sym) const {
355 return SymbolOrdering.lookup(Sym);
356 }
357
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100358 /// Update streamer for a new active section.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100359 ///
360 /// This is called by PopSection and SwitchSection, if the current
361 /// section changes.
362 virtual void ChangeSection(MCSection *, const MCExpr *);
363
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100364 /// Save the current and previous section on the section stack.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100365 void PushSection() {
366 SectionStack.push_back(
367 std::make_pair(getCurrentSection(), getPreviousSection()));
368 }
369
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100370 /// Restore the current and previous section from the section stack.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100371 /// Calls ChangeSection as needed.
372 ///
373 /// Returns false if the stack was empty.
374 bool PopSection() {
375 if (SectionStack.size() <= 1)
376 return false;
377 auto I = SectionStack.end();
378 --I;
379 MCSectionSubPair OldSection = I->first;
380 --I;
381 MCSectionSubPair NewSection = I->first;
382
383 if (OldSection != NewSection)
384 ChangeSection(NewSection.first, NewSection.second);
385 SectionStack.pop_back();
386 return true;
387 }
388
389 bool SubSection(const MCExpr *Subsection) {
390 if (SectionStack.empty())
391 return false;
392
393 SwitchSection(SectionStack.back().first.first, Subsection);
394 return true;
395 }
396
397 /// Set the current section where code is being emitted to \p Section. This
398 /// is required to update CurSection.
399 ///
400 /// This corresponds to assembler directives like .section, .text, etc.
401 virtual void SwitchSection(MCSection *Section,
402 const MCExpr *Subsection = nullptr);
403
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100404 /// Set the current section where code is being emitted to \p Section.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100405 /// This is required to update CurSection. This version does not call
406 /// ChangeSection.
407 void SwitchSectionNoChange(MCSection *Section,
408 const MCExpr *Subsection = nullptr) {
409 assert(Section && "Cannot switch to a null section!");
410 MCSectionSubPair curSection = SectionStack.back().first;
411 SectionStack.back().second = curSection;
412 if (MCSectionSubPair(Section, Subsection) != curSection)
413 SectionStack.back().first = MCSectionSubPair(Section, Subsection);
414 }
415
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100416 /// Create the default sections and set the initial one.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100417 virtual void InitSections(bool NoExecStack);
418
419 MCSymbol *endSection(MCSection *Section);
420
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100421 /// Sets the symbol's section.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100422 ///
423 /// Each emitted symbol will be tracked in the ordering table,
424 /// so we can sort on them later.
425 void AssignFragment(MCSymbol *Symbol, MCFragment *Fragment);
426
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100427 /// Emit a label for \p Symbol into the current section.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100428 ///
429 /// This corresponds to an assembler statement such as:
430 /// foo:
431 ///
432 /// \param Symbol - The symbol to emit. A given symbol should only be
433 /// emitted as a label once, and symbols emitted as a label should never be
434 /// used in an assignment.
435 // FIXME: These emission are non-const because we mutate the symbol to
436 // add the section we're emitting it to later.
437 virtual void EmitLabel(MCSymbol *Symbol, SMLoc Loc = SMLoc());
438
439 virtual void EmitEHSymAttributes(const MCSymbol *Symbol, MCSymbol *EHSymbol);
440
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100441 /// Note in the output the specified \p Flag.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100442 virtual void EmitAssemblerFlag(MCAssemblerFlag Flag);
443
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100444 /// Emit the given list \p Options of strings as linker
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100445 /// options into the output.
446 virtual void EmitLinkerOptions(ArrayRef<std::string> Kind) {}
447
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100448 /// Note in the output the specified region \p Kind.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100449 virtual void EmitDataRegion(MCDataRegionType Kind) {}
450
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100451 /// Specify the Mach-O minimum deployment target version.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100452 virtual void EmitVersionMin(MCVersionMinType Type, unsigned Major,
Andrew Walbran16937d02019-10-22 13:54:20 +0100453 unsigned Minor, unsigned Update,
454 VersionTuple SDKVersion) {}
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100455
456 /// Emit/Specify Mach-O build version command.
457 /// \p Platform should be one of MachO::PlatformType.
458 virtual void EmitBuildVersion(unsigned Platform, unsigned Major,
Andrew Walbran16937d02019-10-22 13:54:20 +0100459 unsigned Minor, unsigned Update,
460 VersionTuple SDKVersion) {}
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100461
Andrew Walbran16937d02019-10-22 13:54:20 +0100462 void EmitVersionForTarget(const Triple &Target,
463 const VersionTuple &SDKVersion);
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100464
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100465 /// Note in the output that the specified \p Func is a Thumb mode
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100466 /// function (ARM target only).
467 virtual void EmitThumbFunc(MCSymbol *Func);
468
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100469 /// Emit an assignment of \p Value to \p Symbol.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100470 ///
471 /// This corresponds to an assembler statement such as:
472 /// symbol = value
473 ///
474 /// The assignment generates no code, but has the side effect of binding the
475 /// value in the current context. For the assembly streamer, this prints the
476 /// binding into the .s file.
477 ///
478 /// \param Symbol - The symbol being assigned to.
479 /// \param Value - The value for the symbol.
480 virtual void EmitAssignment(MCSymbol *Symbol, const MCExpr *Value);
481
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100482 /// Emit an weak reference from \p Alias to \p Symbol.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100483 ///
484 /// This corresponds to an assembler statement such as:
485 /// .weakref alias, symbol
486 ///
487 /// \param Alias - The alias that is being created.
488 /// \param Symbol - The symbol being aliased.
489 virtual void EmitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol);
490
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100491 /// Add the given \p Attribute to \p Symbol.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100492 virtual bool EmitSymbolAttribute(MCSymbol *Symbol,
493 MCSymbolAttr Attribute) = 0;
494
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100495 /// Set the \p DescValue for the \p Symbol.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100496 ///
497 /// \param Symbol - The symbol to have its n_desc field set.
498 /// \param DescValue - The value to set into the n_desc field.
499 virtual void EmitSymbolDesc(MCSymbol *Symbol, unsigned DescValue);
500
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100501 /// Start emitting COFF symbol definition
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100502 ///
503 /// \param Symbol - The symbol to have its External & Type fields set.
504 virtual void BeginCOFFSymbolDef(const MCSymbol *Symbol);
505
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100506 /// Emit the storage class of the symbol.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100507 ///
508 /// \param StorageClass - The storage class the symbol should have.
509 virtual void EmitCOFFSymbolStorageClass(int StorageClass);
510
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100511 /// Emit the type of the symbol.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100512 ///
513 /// \param Type - A COFF type identifier (see COFF::SymbolType in X86COFF.h)
514 virtual void EmitCOFFSymbolType(int Type);
515
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100516 /// Marks the end of the symbol definition.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100517 virtual void EndCOFFSymbolDef();
518
519 virtual void EmitCOFFSafeSEH(MCSymbol const *Symbol);
520
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100521 /// Emits the symbol table index of a Symbol into the current section.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100522 virtual void EmitCOFFSymbolIndex(MCSymbol const *Symbol);
523
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100524 /// Emits a COFF section index.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100525 ///
526 /// \param Symbol - Symbol the section number relocation should point to.
527 virtual void EmitCOFFSectionIndex(MCSymbol const *Symbol);
528
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100529 /// Emits a COFF section relative relocation.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100530 ///
531 /// \param Symbol - Symbol the section relative relocation should point to.
532 virtual void EmitCOFFSecRel32(MCSymbol const *Symbol, uint64_t Offset);
533
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100534 /// Emits a COFF image relative relocation.
535 ///
536 /// \param Symbol - Symbol the image relative relocation should point to.
537 virtual void EmitCOFFImgRel32(MCSymbol const *Symbol, int64_t Offset);
538
539 /// Emit an ELF .size directive.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100540 ///
541 /// This corresponds to an assembler statement such as:
542 /// .size symbol, expression
543 virtual void emitELFSize(MCSymbol *Symbol, const MCExpr *Value);
544
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100545 /// Emit an ELF .symver directive.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100546 ///
547 /// This corresponds to an assembler statement such as:
548 /// .symver _start, foo@@SOME_VERSION
549 /// \param AliasName - The versioned alias (i.e. "foo@@SOME_VERSION")
550 /// \param Aliasee - The aliased symbol (i.e. "_start")
551 virtual void emitELFSymverDirective(StringRef AliasName,
552 const MCSymbol *Aliasee);
553
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100554 /// Emit a Linker Optimization Hint (LOH) directive.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100555 /// \param Args - Arguments of the LOH.
556 virtual void EmitLOHDirective(MCLOHType Kind, const MCLOHArgs &Args) {}
557
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100558 /// Emit a common symbol.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100559 ///
560 /// \param Symbol - The common symbol to emit.
561 /// \param Size - The size of the common symbol.
562 /// \param ByteAlignment - The alignment of the symbol if
563 /// non-zero. This must be a power of 2.
564 virtual void EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
565 unsigned ByteAlignment) = 0;
566
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100567 /// Emit a local common (.lcomm) symbol.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100568 ///
569 /// \param Symbol - The common symbol to emit.
570 /// \param Size - The size of the common symbol.
571 /// \param ByteAlignment - The alignment of the common symbol in bytes.
572 virtual void EmitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size,
573 unsigned ByteAlignment);
574
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100575 /// Emit the zerofill section and an optional symbol.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100576 ///
577 /// \param Section - The zerofill section to create and or to put the symbol
578 /// \param Symbol - The zerofill symbol to emit, if non-NULL.
579 /// \param Size - The size of the zerofill symbol.
580 /// \param ByteAlignment - The alignment of the zerofill symbol if
581 /// non-zero. This must be a power of 2 on some targets.
582 virtual void EmitZerofill(MCSection *Section, MCSymbol *Symbol = nullptr,
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100583 uint64_t Size = 0, unsigned ByteAlignment = 0,
584 SMLoc Loc = SMLoc()) = 0;
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100585
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100586 /// Emit a thread local bss (.tbss) symbol.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100587 ///
588 /// \param Section - The thread local common section.
589 /// \param Symbol - The thread local common symbol to emit.
590 /// \param Size - The size of the symbol.
591 /// \param ByteAlignment - The alignment of the thread local common symbol
592 /// if non-zero. This must be a power of 2 on some targets.
593 virtual void EmitTBSSSymbol(MCSection *Section, MCSymbol *Symbol,
594 uint64_t Size, unsigned ByteAlignment = 0);
595
596 /// @}
597 /// \name Generating Data
598 /// @{
599
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100600 /// Emit the bytes in \p Data into the output.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100601 ///
602 /// This is used to implement assembler directives such as .byte, .ascii,
603 /// etc.
604 virtual void EmitBytes(StringRef Data);
605
606 /// Functionally identical to EmitBytes. When emitting textual assembly, this
607 /// method uses .byte directives instead of .ascii or .asciz for readability.
608 virtual void EmitBinaryData(StringRef Data);
609
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100610 /// Emit the expression \p Value into the output as a native
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100611 /// integer of the given \p Size bytes.
612 ///
613 /// This is used to implement assembler directives such as .word, .quad,
614 /// etc.
615 ///
616 /// \param Value - The value to emit.
617 /// \param Size - The size of the integer (in bytes) to emit. This must
618 /// match a native machine width.
619 /// \param Loc - The location of the expression for error reporting.
620 virtual void EmitValueImpl(const MCExpr *Value, unsigned Size,
621 SMLoc Loc = SMLoc());
622
623 void EmitValue(const MCExpr *Value, unsigned Size, SMLoc Loc = SMLoc());
624
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100625 /// Special case of EmitValue that avoids the client having
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100626 /// to pass in a MCExpr for constant integers.
627 virtual void EmitIntValue(uint64_t Value, unsigned Size);
628
629 virtual void EmitULEB128Value(const MCExpr *Value);
630
631 virtual void EmitSLEB128Value(const MCExpr *Value);
632
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100633 /// Special case of EmitULEB128Value that avoids the client having to
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100634 /// pass in a MCExpr for constant integers.
Andrew Walbran3d2c1972020-04-07 12:24:26 +0100635 void EmitULEB128IntValue(uint64_t Value, unsigned PadTo = 0);
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100636
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100637 /// Special case of EmitSLEB128Value that avoids the client having to
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100638 /// pass in a MCExpr for constant integers.
639 void EmitSLEB128IntValue(int64_t Value);
640
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100641 /// Special case of EmitValue that avoids the client having to pass in
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100642 /// a MCExpr for MCSymbols.
643 void EmitSymbolValue(const MCSymbol *Sym, unsigned Size,
644 bool IsSectionRelative = false);
645
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100646 /// Emit the expression \p Value into the output as a dtprel
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100647 /// (64-bit DTP relative) value.
648 ///
649 /// This is used to implement assembler directives such as .dtpreldword on
650 /// targets that support them.
651 virtual void EmitDTPRel64Value(const MCExpr *Value);
652
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100653 /// Emit the expression \p Value into the output as a dtprel
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100654 /// (32-bit DTP relative) value.
655 ///
656 /// This is used to implement assembler directives such as .dtprelword on
657 /// targets that support them.
658 virtual void EmitDTPRel32Value(const MCExpr *Value);
659
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100660 /// Emit the expression \p Value into the output as a tprel
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100661 /// (64-bit TP relative) value.
662 ///
663 /// This is used to implement assembler directives such as .tpreldword on
664 /// targets that support them.
665 virtual void EmitTPRel64Value(const MCExpr *Value);
666
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100667 /// Emit the expression \p Value into the output as a tprel
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100668 /// (32-bit TP relative) value.
669 ///
670 /// This is used to implement assembler directives such as .tprelword on
671 /// targets that support them.
672 virtual void EmitTPRel32Value(const MCExpr *Value);
673
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100674 /// Emit the expression \p Value into the output as a gprel64 (64-bit
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100675 /// GP relative) value.
676 ///
677 /// This is used to implement assembler directives such as .gpdword on
678 /// targets that support them.
679 virtual void EmitGPRel64Value(const MCExpr *Value);
680
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100681 /// Emit the expression \p Value into the output as a gprel32 (32-bit
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100682 /// GP relative) value.
683 ///
684 /// This is used to implement assembler directives such as .gprel32 on
685 /// targets that support them.
686 virtual void EmitGPRel32Value(const MCExpr *Value);
687
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100688 /// Emit NumBytes bytes worth of the value specified by FillValue.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100689 /// This implements directives such as '.space'.
690 void emitFill(uint64_t NumBytes, uint8_t FillValue);
691
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100692 /// Emit \p Size bytes worth of the value specified by \p FillValue.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100693 ///
694 /// This is used to implement assembler directives such as .space or .skip.
695 ///
696 /// \param NumBytes - The number of bytes to emit.
697 /// \param FillValue - The value to use when filling bytes.
698 /// \param Loc - The location of the expression for error reporting.
699 virtual void emitFill(const MCExpr &NumBytes, uint64_t FillValue,
700 SMLoc Loc = SMLoc());
701
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100702 /// Emit \p NumValues copies of \p Size bytes. Each \p Size bytes is
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100703 /// taken from the lowest order 4 bytes of \p Expr expression.
704 ///
705 /// This is used to implement assembler directives such as .fill.
706 ///
707 /// \param NumValues - The number of copies of \p Size bytes to emit.
708 /// \param Size - The size (in bytes) of each repeated value.
709 /// \param Expr - The expression from which \p Size bytes are used.
710 virtual void emitFill(const MCExpr &NumValues, int64_t Size, int64_t Expr,
711 SMLoc Loc = SMLoc());
712
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100713 /// Emit NumBytes worth of zeros.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100714 /// This function properly handles data in virtual sections.
715 void EmitZeros(uint64_t NumBytes);
716
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100717 /// Emit some number of copies of \p Value until the byte alignment \p
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100718 /// ByteAlignment is reached.
719 ///
720 /// If the number of bytes need to emit for the alignment is not a multiple
721 /// of \p ValueSize, then the contents of the emitted fill bytes is
722 /// undefined.
723 ///
724 /// This used to implement the .align assembler directive.
725 ///
726 /// \param ByteAlignment - The alignment to reach. This must be a power of
727 /// two on some targets.
728 /// \param Value - The value to use when filling bytes.
729 /// \param ValueSize - The size of the integer (in bytes) to emit for
730 /// \p Value. This must match a native machine width.
731 /// \param MaxBytesToEmit - The maximum numbers of bytes to emit, or 0. If
732 /// the alignment cannot be reached in this many bytes, no bytes are
733 /// emitted.
734 virtual void EmitValueToAlignment(unsigned ByteAlignment, int64_t Value = 0,
735 unsigned ValueSize = 1,
736 unsigned MaxBytesToEmit = 0);
737
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100738 /// Emit nops until the byte alignment \p ByteAlignment is reached.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100739 ///
740 /// This used to align code where the alignment bytes may be executed. This
741 /// can emit different bytes for different sizes to optimize execution.
742 ///
743 /// \param ByteAlignment - The alignment to reach. This must be a power of
744 /// two on some targets.
745 /// \param MaxBytesToEmit - The maximum numbers of bytes to emit, or 0. If
746 /// the alignment cannot be reached in this many bytes, no bytes are
747 /// emitted.
748 virtual void EmitCodeAlignment(unsigned ByteAlignment,
749 unsigned MaxBytesToEmit = 0);
750
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100751 /// Emit some number of copies of \p Value until the byte offset \p
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100752 /// Offset is reached.
753 ///
754 /// This is used to implement assembler directives such as .org.
755 ///
756 /// \param Offset - The offset to reach. This may be an expression, but the
757 /// expression must be associated with the current section.
758 /// \param Value - The value to use when filling bytes.
759 virtual void emitValueToOffset(const MCExpr *Offset, unsigned char Value,
760 SMLoc Loc);
761
762 virtual void
763 EmitCodePaddingBasicBlockStart(const MCCodePaddingContext &Context) {}
764
765 virtual void
766 EmitCodePaddingBasicBlockEnd(const MCCodePaddingContext &Context) {}
767
768 /// @}
769
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100770 /// Switch to a new logical file. This is used to implement the '.file
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100771 /// "foo.c"' assembler directive.
772 virtual void EmitFileDirective(StringRef Filename);
773
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100774 /// Emit the "identifiers" directive. This implements the
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100775 /// '.ident "version foo"' assembler directive.
776 virtual void EmitIdent(StringRef IdentString) {}
777
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100778 /// Associate a filename with a specified logical file number. This
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100779 /// implements the DWARF2 '.file 4 "foo.c"' assembler directive.
780 unsigned EmitDwarfFileDirective(unsigned FileNo, StringRef Directory,
781 StringRef Filename,
Andrew Walbran3d2c1972020-04-07 12:24:26 +0100782 Optional<MD5::MD5Result> Checksum = None,
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100783 Optional<StringRef> Source = None,
784 unsigned CUID = 0) {
785 return cantFail(
786 tryEmitDwarfFileDirective(FileNo, Directory, Filename, Checksum,
787 Source, CUID));
788 }
789
790 /// Associate a filename with a specified logical file number.
791 /// Also associate a directory, optional checksum, and optional source
792 /// text with the logical file. This implements the DWARF2
793 /// '.file 4 "dir/foo.c"' assembler directive, and the DWARF5
794 /// '.file 4 "dir/foo.c" md5 "..." source "..."' assembler directive.
795 virtual Expected<unsigned> tryEmitDwarfFileDirective(
796 unsigned FileNo, StringRef Directory, StringRef Filename,
Andrew Walbran3d2c1972020-04-07 12:24:26 +0100797 Optional<MD5::MD5Result> Checksum = None, Optional<StringRef> Source = None,
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100798 unsigned CUID = 0);
799
800 /// Specify the "root" file of the compilation, using the ".file 0" extension.
801 virtual void emitDwarfFile0Directive(StringRef Directory, StringRef Filename,
Andrew Walbran3d2c1972020-04-07 12:24:26 +0100802 Optional<MD5::MD5Result> Checksum,
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100803 Optional<StringRef> Source,
804 unsigned CUID = 0);
805
Andrew Walbran16937d02019-10-22 13:54:20 +0100806 virtual void EmitCFIBKeyFrame();
807
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100808 /// This implements the DWARF2 '.loc fileno lineno ...' assembler
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100809 /// directive.
810 virtual void EmitDwarfLocDirective(unsigned FileNo, unsigned Line,
811 unsigned Column, unsigned Flags,
812 unsigned Isa, unsigned Discriminator,
813 StringRef FileName);
814
815 /// Associate a filename with a specified logical file number, and also
816 /// specify that file's checksum information. This implements the '.cv_file 4
817 /// "foo.c"' assembler directive. Returns true on success.
818 virtual bool EmitCVFileDirective(unsigned FileNo, StringRef Filename,
819 ArrayRef<uint8_t> Checksum,
820 unsigned ChecksumKind);
821
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100822 /// Introduces a function id for use with .cv_loc.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100823 virtual bool EmitCVFuncIdDirective(unsigned FunctionId);
824
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100825 /// Introduces an inline call site id for use with .cv_loc. Includes
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100826 /// extra information for inline line table generation.
827 virtual bool EmitCVInlineSiteIdDirective(unsigned FunctionId, unsigned IAFunc,
828 unsigned IAFile, unsigned IALine,
829 unsigned IACol, SMLoc Loc);
830
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100831 /// This implements the CodeView '.cv_loc' assembler directive.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100832 virtual void EmitCVLocDirective(unsigned FunctionId, unsigned FileNo,
833 unsigned Line, unsigned Column,
834 bool PrologueEnd, bool IsStmt,
835 StringRef FileName, SMLoc Loc);
836
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100837 /// This implements the CodeView '.cv_linetable' assembler directive.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100838 virtual void EmitCVLinetableDirective(unsigned FunctionId,
839 const MCSymbol *FnStart,
840 const MCSymbol *FnEnd);
841
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100842 /// This implements the CodeView '.cv_inline_linetable' assembler
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100843 /// directive.
844 virtual void EmitCVInlineLinetableDirective(unsigned PrimaryFunctionId,
845 unsigned SourceFileId,
846 unsigned SourceLineNum,
847 const MCSymbol *FnStartSym,
848 const MCSymbol *FnEndSym);
849
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100850 /// This implements the CodeView '.cv_def_range' assembler
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100851 /// directive.
852 virtual void EmitCVDefRangeDirective(
853 ArrayRef<std::pair<const MCSymbol *, const MCSymbol *>> Ranges,
854 StringRef FixedSizePortion);
855
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100856 /// This implements the CodeView '.cv_stringtable' assembler directive.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100857 virtual void EmitCVStringTableDirective() {}
858
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100859 /// This implements the CodeView '.cv_filechecksums' assembler directive.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100860 virtual void EmitCVFileChecksumsDirective() {}
861
862 /// This implements the CodeView '.cv_filechecksumoffset' assembler
863 /// directive.
864 virtual void EmitCVFileChecksumOffsetDirective(unsigned FileNo) {}
865
866 /// This implements the CodeView '.cv_fpo_data' assembler directive.
867 virtual void EmitCVFPOData(const MCSymbol *ProcSym, SMLoc Loc = {}) {}
868
869 /// Emit the absolute difference between two symbols.
870 ///
871 /// \pre Offset of \c Hi is greater than the offset \c Lo.
872 virtual void emitAbsoluteSymbolDiff(const MCSymbol *Hi, const MCSymbol *Lo,
873 unsigned Size);
874
875 /// Emit the absolute difference between two symbols encoded with ULEB128.
876 virtual void emitAbsoluteSymbolDiffAsULEB128(const MCSymbol *Hi,
877 const MCSymbol *Lo);
878
879 virtual MCSymbol *getDwarfLineTableSymbol(unsigned CUID);
880 virtual void EmitCFISections(bool EH, bool Debug);
Andrew Walbran16937d02019-10-22 13:54:20 +0100881 void EmitCFIStartProc(bool IsSimple, SMLoc Loc = SMLoc());
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100882 void EmitCFIEndProc();
883 virtual void EmitCFIDefCfa(int64_t Register, int64_t Offset);
884 virtual void EmitCFIDefCfaOffset(int64_t Offset);
885 virtual void EmitCFIDefCfaRegister(int64_t Register);
886 virtual void EmitCFIOffset(int64_t Register, int64_t Offset);
887 virtual void EmitCFIPersonality(const MCSymbol *Sym, unsigned Encoding);
888 virtual void EmitCFILsda(const MCSymbol *Sym, unsigned Encoding);
889 virtual void EmitCFIRememberState();
890 virtual void EmitCFIRestoreState();
891 virtual void EmitCFISameValue(int64_t Register);
892 virtual void EmitCFIRestore(int64_t Register);
893 virtual void EmitCFIRelOffset(int64_t Register, int64_t Offset);
894 virtual void EmitCFIAdjustCfaOffset(int64_t Adjustment);
895 virtual void EmitCFIEscape(StringRef Values);
896 virtual void EmitCFIReturnColumn(int64_t Register);
897 virtual void EmitCFIGnuArgsSize(int64_t Size);
898 virtual void EmitCFISignalFrame();
899 virtual void EmitCFIUndefined(int64_t Register);
900 virtual void EmitCFIRegister(int64_t Register1, int64_t Register2);
901 virtual void EmitCFIWindowSave();
Andrew Walbran16937d02019-10-22 13:54:20 +0100902 virtual void EmitCFINegateRAState();
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100903
904 virtual void EmitWinCFIStartProc(const MCSymbol *Symbol, SMLoc Loc = SMLoc());
905 virtual void EmitWinCFIEndProc(SMLoc Loc = SMLoc());
Andrew Walbran16937d02019-10-22 13:54:20 +0100906 /// This is used on platforms, such as Windows on ARM64, that require function
907 /// or funclet sizes to be emitted in .xdata before the End marker is emitted
908 /// for the frame. We cannot use the End marker, as it is not set at the
909 /// point of emitting .xdata, in order to indicate that the frame is active.
910 virtual void EmitWinCFIFuncletOrFuncEnd(SMLoc Loc = SMLoc());
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100911 virtual void EmitWinCFIStartChained(SMLoc Loc = SMLoc());
912 virtual void EmitWinCFIEndChained(SMLoc Loc = SMLoc());
913 virtual void EmitWinCFIPushReg(unsigned Register, SMLoc Loc = SMLoc());
914 virtual void EmitWinCFISetFrame(unsigned Register, unsigned Offset,
915 SMLoc Loc = SMLoc());
916 virtual void EmitWinCFIAllocStack(unsigned Size, SMLoc Loc = SMLoc());
917 virtual void EmitWinCFISaveReg(unsigned Register, unsigned Offset,
918 SMLoc Loc = SMLoc());
919 virtual void EmitWinCFISaveXMM(unsigned Register, unsigned Offset,
920 SMLoc Loc = SMLoc());
921 virtual void EmitWinCFIPushFrame(bool Code, SMLoc Loc = SMLoc());
922 virtual void EmitWinCFIEndProlog(SMLoc Loc = SMLoc());
923 virtual void EmitWinEHHandler(const MCSymbol *Sym, bool Unwind, bool Except,
924 SMLoc Loc = SMLoc());
925 virtual void EmitWinEHHandlerData(SMLoc Loc = SMLoc());
926
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100927 virtual void emitCGProfileEntry(const MCSymbolRefExpr *From,
928 const MCSymbolRefExpr *To, uint64_t Count);
929
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100930 /// Get the .pdata section used for the given section. Typically the given
931 /// section is either the main .text section or some other COMDAT .text
932 /// section, but it may be any section containing code.
933 MCSection *getAssociatedPDataSection(const MCSection *TextSec);
934
935 /// Get the .xdata section used for the given section.
936 MCSection *getAssociatedXDataSection(const MCSection *TextSec);
937
938 virtual void EmitSyntaxDirective();
939
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100940 /// Emit a .reloc directive.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100941 /// Returns true if the relocation could not be emitted because Name is not
942 /// known.
943 virtual bool EmitRelocDirective(const MCExpr &Offset, StringRef Name,
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100944 const MCExpr *Expr, SMLoc Loc,
945 const MCSubtargetInfo &STI) {
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100946 return true;
947 }
948
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100949 virtual void EmitAddrsig() {}
950 virtual void EmitAddrsigSym(const MCSymbol *Sym) {}
951
952 /// Emit the given \p Instruction into the current section.
Andrew Walbran16937d02019-10-22 13:54:20 +0100953 virtual void EmitInstruction(const MCInst &Inst, const MCSubtargetInfo &STI);
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100954
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100955 /// Set the bundle alignment mode from now on in the section.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100956 /// The argument is the power of 2 to which the alignment is set. The
957 /// value 0 means turn the bundle alignment off.
958 virtual void EmitBundleAlignMode(unsigned AlignPow2);
959
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100960 /// The following instructions are a bundle-locked group.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100961 ///
962 /// \param AlignToEnd - If true, the bundle-locked group will be aligned to
963 /// the end of a bundle.
964 virtual void EmitBundleLock(bool AlignToEnd);
965
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100966 /// Ends a bundle-locked group.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100967 virtual void EmitBundleUnlock();
968
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100969 /// If this file is backed by a assembly streamer, this dumps the
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100970 /// specified string in the output .s file. This capability is indicated by
971 /// the hasRawTextSupport() predicate. By default this aborts.
972 void EmitRawText(const Twine &String);
973
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100974 /// Streamer specific finalization.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100975 virtual void FinishImpl();
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100976 /// Finish emission of machine code.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100977 void Finish();
978
979 virtual bool mayHaveInstructions(MCSection &Sec) const { return true; }
980};
981
982/// Create a dummy machine code streamer, which does nothing. This is useful for
983/// timing the assembler front end.
984MCStreamer *createNullStreamer(MCContext &Ctx);
985
986/// Create a machine code streamer which will print out assembly for the native
987/// target, suitable for compiling with a native assembler.
988///
989/// \param InstPrint - If given, the instruction printer to use. If not given
990/// the MCInst representation will be printed. This method takes ownership of
991/// InstPrint.
992///
993/// \param CE - If given, a code emitter to use to show the instruction
994/// encoding inline with the assembly. This method takes ownership of \p CE.
995///
996/// \param TAB - If given, a target asm backend to use to show the fixup
997/// information in conjunction with encoding information. This method takes
998/// ownership of \p TAB.
999///
1000/// \param ShowInst - Whether to show the MCInst representation inline with
1001/// the assembly.
1002MCStreamer *createAsmStreamer(MCContext &Ctx,
1003 std::unique_ptr<formatted_raw_ostream> OS,
1004 bool isVerboseAsm, bool useDwarfDirectory,
1005 MCInstPrinter *InstPrint, MCCodeEmitter *CE,
1006 MCAsmBackend *TAB, bool ShowInst);
1007
1008} // end namespace llvm
1009
1010#endif // LLVM_MC_MCSTREAMER_H