blob: 91fb4e537b4c8eae882176d4ddcc2b5fa490a445 [file] [log] [blame]
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01001//===- MCStreamer.h - High-level Streaming Machine Code Output --*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file declares the MCStreamer class.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_MC_MCSTREAMER_H
15#define LLVM_MC_MCSTREAMER_H
16
17#include "llvm/ADT/ArrayRef.h"
18#include "llvm/ADT/DenseMap.h"
19#include "llvm/ADT/Optional.h"
20#include "llvm/ADT/SmallVector.h"
21#include "llvm/ADT/StringRef.h"
22#include "llvm/MC/MCDirectives.h"
23#include "llvm/MC/MCDwarf.h"
24#include "llvm/MC/MCLinkerOptimizationHint.h"
25#include "llvm/MC/MCSymbol.h"
26#include "llvm/MC/MCWinEH.h"
27#include "llvm/Support/Error.h"
28#include "llvm/Support/MD5.h"
29#include "llvm/Support/SMLoc.h"
30#include "llvm/Support/TargetParser.h"
31#include <cassert>
32#include <cstdint>
33#include <memory>
34#include <string>
35#include <utility>
36#include <vector>
37
38namespace llvm {
39
40class AssemblerConstantPools;
41class formatted_raw_ostream;
42class MCAsmBackend;
43class MCCodeEmitter;
44struct MCCodePaddingContext;
45class MCContext;
46class 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
112 virtual void finish();
113};
114
115// FIXME: declared here because it is used from
116// lib/CodeGen/AsmPrinter/ARMException.cpp.
117class ARMTargetStreamer : public MCTargetStreamer {
118public:
119 ARMTargetStreamer(MCStreamer &S);
120 ~ARMTargetStreamer() override;
121
122 virtual void emitFnStart();
123 virtual void emitFnEnd();
124 virtual void emitCantUnwind();
125 virtual void emitPersonality(const MCSymbol *Personality);
126 virtual void emitPersonalityIndex(unsigned Index);
127 virtual void emitHandlerData();
128 virtual void emitSetFP(unsigned FpReg, unsigned SpReg,
129 int64_t Offset = 0);
130 virtual void emitMovSP(unsigned Reg, int64_t Offset = 0);
131 virtual void emitPad(int64_t Offset);
132 virtual void emitRegSave(const SmallVectorImpl<unsigned> &RegList,
133 bool isVector);
134 virtual void emitUnwindRaw(int64_t StackOffset,
135 const SmallVectorImpl<uint8_t> &Opcodes);
136
137 virtual void switchVendor(StringRef Vendor);
138 virtual void emitAttribute(unsigned Attribute, unsigned Value);
139 virtual void emitTextAttribute(unsigned Attribute, StringRef String);
140 virtual void emitIntTextAttribute(unsigned Attribute, unsigned IntValue,
141 StringRef StringValue = "");
142 virtual void emitFPU(unsigned FPU);
143 virtual void emitArch(ARM::ArchKind Arch);
144 virtual void emitArchExtension(unsigned ArchExt);
145 virtual void emitObjectArch(ARM::ArchKind Arch);
146 void emitTargetAttributes(const MCSubtargetInfo &STI);
147 virtual void finishAttributeSection();
148 virtual void emitInst(uint32_t Inst, char Suffix = '\0');
149
150 virtual void AnnotateTLSDescriptorSequence(const MCSymbolRefExpr *SRE);
151
152 virtual void emitThumbSet(MCSymbol *Symbol, const MCExpr *Value);
153
154 void finish() override;
155
156 /// Reset any state between object emissions, i.e. the equivalent of
157 /// MCStreamer's reset method.
158 virtual void reset();
159
160 /// Callback used to implement the ldr= pseudo.
161 /// Add a new entry to the constant pool for the current section and return an
162 /// MCExpr that can be used to refer to the constant pool location.
163 const MCExpr *addConstantPoolEntry(const MCExpr *, SMLoc Loc);
164
165 /// Callback used to implemnt the .ltorg directive.
166 /// Emit contents of constant pool for the current section.
167 void emitCurrentConstantPool();
168
169private:
170 std::unique_ptr<AssemblerConstantPools> ConstantPools;
171};
172
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100173/// Streaming machine code generation interface.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100174///
175/// This interface is intended to provide a programatic interface that is very
176/// similar to the level that an assembler .s file provides. It has callbacks
177/// to emit bytes, handle directives, etc. The implementation of this interface
178/// retains state to know what the current section is etc.
179///
180/// There are multiple implementations of this interface: one for writing out
181/// a .s file, and implementations that write out .o files of various formats.
182///
183class MCStreamer {
184 MCContext &Context;
185 std::unique_ptr<MCTargetStreamer> TargetStreamer;
186
187 std::vector<MCDwarfFrameInfo> DwarfFrameInfos;
188 MCDwarfFrameInfo *getCurrentDwarfFrameInfo();
189
190 /// Similar to DwarfFrameInfos, but for SEH unwind info. Chained frames may
191 /// refer to each other, so use std::unique_ptr to provide pointer stability.
192 std::vector<std::unique_ptr<WinEH::FrameInfo>> WinFrameInfos;
193
194 WinEH::FrameInfo *CurrentWinFrameInfo;
195
196 /// Retreive the current frame info if one is available and it is not yet
197 /// closed. Otherwise, issue an error and return null.
198 WinEH::FrameInfo *EnsureValidWinFrameInfo(SMLoc Loc);
199
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100200 /// Tracks an index to represent the order a symbol was emitted in.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100201 /// Zero means we did not emit that symbol.
202 DenseMap<const MCSymbol *, unsigned> SymbolOrdering;
203
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100204 /// This is stack of current and previous section values saved by
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100205 /// PushSection.
206 SmallVector<std::pair<MCSectionSubPair, MCSectionSubPair>, 4> SectionStack;
207
208 /// The next unique ID to use when creating a WinCFI-related section (.pdata
209 /// or .xdata). This ID ensures that we have a one-to-one mapping from
210 /// code section to unwind info section, which MSVC's incremental linker
211 /// requires.
212 unsigned NextWinCFIID = 0;
213
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100214 bool UseAssemblerInfoForParsing;
215
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100216protected:
217 MCStreamer(MCContext &Ctx);
218
219 virtual void EmitCFIStartProcImpl(MCDwarfFrameInfo &Frame);
220 virtual void EmitCFIEndProcImpl(MCDwarfFrameInfo &CurFrame);
221
222 /// When emitting an object file, create and emit a real label. When emitting
223 /// textual assembly, this should do nothing to avoid polluting our output.
224 virtual MCSymbol *EmitCFILabel();
225
226 WinEH::FrameInfo *getCurrentWinFrameInfo() {
227 return CurrentWinFrameInfo;
228 }
229
230 virtual void EmitWindowsUnwindTables();
231
232 virtual void EmitRawTextImpl(StringRef String);
233
Andrew Scull0372a572018-11-16 15:47:06 +0000234 /// Returns true if the the .cv_loc directive is in the right section.
235 bool checkCVLocSection(unsigned FuncId, unsigned FileNo, SMLoc Loc);
236
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100237public:
238 MCStreamer(const MCStreamer &) = delete;
239 MCStreamer &operator=(const MCStreamer &) = delete;
240 virtual ~MCStreamer();
241
242 void visitUsedExpr(const MCExpr &Expr);
243 virtual void visitUsedSymbol(const MCSymbol &Sym);
244
245 void setTargetStreamer(MCTargetStreamer *TS) {
246 TargetStreamer.reset(TS);
247 }
248
249 /// State management
250 ///
251 virtual void reset();
252
253 MCContext &getContext() const { return Context; }
254
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100255 virtual MCAssembler *getAssemblerPtr() { return nullptr; }
256
257 void setUseAssemblerInfoForParsing(bool v) { UseAssemblerInfoForParsing = v; }
258 bool getUseAssemblerInfoForParsing() { return UseAssemblerInfoForParsing; }
259
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100260 MCTargetStreamer *getTargetStreamer() {
261 return TargetStreamer.get();
262 }
263
264 unsigned getNumFrameInfos() { return DwarfFrameInfos.size(); }
265 ArrayRef<MCDwarfFrameInfo> getDwarfFrameInfos() const {
266 return DwarfFrameInfos;
267 }
268
269 bool hasUnfinishedDwarfFrameInfo();
270
271 unsigned getNumWinFrameInfos() { return WinFrameInfos.size(); }
272 ArrayRef<std::unique_ptr<WinEH::FrameInfo>> getWinFrameInfos() const {
273 return WinFrameInfos;
274 }
275
276 void generateCompactUnwindEncodings(MCAsmBackend *MAB);
277
278 /// \name Assembly File Formatting.
279 /// @{
280
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100281 /// Return true if this streamer supports verbose assembly and if it is
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100282 /// enabled.
283 virtual bool isVerboseAsm() const { return false; }
284
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100285 /// Return true if this asm streamer supports emitting unformatted text
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100286 /// to the .s file with EmitRawText.
287 virtual bool hasRawTextSupport() const { return false; }
288
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100289 /// Is the integrated assembler required for this streamer to function
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100290 /// correctly?
291 virtual bool isIntegratedAssemblerRequired() const { return false; }
292
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100293 /// Add a textual comment.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100294 ///
295 /// Typically for comments that can be emitted to the generated .s
296 /// file if applicable as a QoI issue to make the output of the compiler
297 /// more readable. This only affects the MCAsmStreamer, and only when
298 /// verbose assembly output is enabled.
299 ///
300 /// If the comment includes embedded \n's, they will each get the comment
301 /// prefix as appropriate. The added comment should not end with a \n.
302 /// By default, each comment is terminated with an end of line, i.e. the
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100303 /// EOL param is set to true by default. If one prefers not to end the
304 /// comment with a new line then the EOL param should be passed
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100305 /// with a false value.
306 virtual void AddComment(const Twine &T, bool EOL = true) {}
307
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100308 /// Return a raw_ostream that comments can be written to. Unlike
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100309 /// AddComment, you are required to terminate comments with \n if you use this
310 /// method.
311 virtual raw_ostream &GetCommentOS();
312
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100313 /// Print T and prefix it with the comment string (normally #) and
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100314 /// optionally a tab. This prints the comment immediately, not at the end of
315 /// the current line. It is basically a safe version of EmitRawText: since it
316 /// only prints comments, the object streamer ignores it instead of asserting.
317 virtual void emitRawComment(const Twine &T, bool TabPrefix = true);
318
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100319 /// Add explicit comment T. T is required to be a valid
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100320 /// comment in the output and does not need to be escaped.
321 virtual void addExplicitComment(const Twine &T);
322
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100323 /// Emit added explicit comments.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100324 virtual void emitExplicitComments();
325
326 /// AddBlankLine - Emit a blank line to a .s file to pretty it up.
327 virtual void AddBlankLine() {}
328
329 /// @}
330
331 /// \name Symbol & Section Management
332 /// @{
333
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100334 /// Return the current section that the streamer is emitting code to.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100335 MCSectionSubPair getCurrentSection() const {
336 if (!SectionStack.empty())
337 return SectionStack.back().first;
338 return MCSectionSubPair();
339 }
340 MCSection *getCurrentSectionOnly() const { return getCurrentSection().first; }
341
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100342 /// Return the previous section that the streamer is emitting code to.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100343 MCSectionSubPair getPreviousSection() const {
344 if (!SectionStack.empty())
345 return SectionStack.back().second;
346 return MCSectionSubPair();
347 }
348
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100349 /// Returns an index to represent the order a symbol was emitted in.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100350 /// (zero if we did not emit that symbol)
351 unsigned GetSymbolOrder(const MCSymbol *Sym) const {
352 return SymbolOrdering.lookup(Sym);
353 }
354
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100355 /// Update streamer for a new active section.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100356 ///
357 /// This is called by PopSection and SwitchSection, if the current
358 /// section changes.
359 virtual void ChangeSection(MCSection *, const MCExpr *);
360
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100361 /// Save the current and previous section on the section stack.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100362 void PushSection() {
363 SectionStack.push_back(
364 std::make_pair(getCurrentSection(), getPreviousSection()));
365 }
366
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100367 /// Restore the current and previous section from the section stack.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100368 /// Calls ChangeSection as needed.
369 ///
370 /// Returns false if the stack was empty.
371 bool PopSection() {
372 if (SectionStack.size() <= 1)
373 return false;
374 auto I = SectionStack.end();
375 --I;
376 MCSectionSubPair OldSection = I->first;
377 --I;
378 MCSectionSubPair NewSection = I->first;
379
380 if (OldSection != NewSection)
381 ChangeSection(NewSection.first, NewSection.second);
382 SectionStack.pop_back();
383 return true;
384 }
385
386 bool SubSection(const MCExpr *Subsection) {
387 if (SectionStack.empty())
388 return false;
389
390 SwitchSection(SectionStack.back().first.first, Subsection);
391 return true;
392 }
393
394 /// Set the current section where code is being emitted to \p Section. This
395 /// is required to update CurSection.
396 ///
397 /// This corresponds to assembler directives like .section, .text, etc.
398 virtual void SwitchSection(MCSection *Section,
399 const MCExpr *Subsection = nullptr);
400
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100401 /// Set the current section where code is being emitted to \p Section.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100402 /// This is required to update CurSection. This version does not call
403 /// ChangeSection.
404 void SwitchSectionNoChange(MCSection *Section,
405 const MCExpr *Subsection = nullptr) {
406 assert(Section && "Cannot switch to a null section!");
407 MCSectionSubPair curSection = SectionStack.back().first;
408 SectionStack.back().second = curSection;
409 if (MCSectionSubPair(Section, Subsection) != curSection)
410 SectionStack.back().first = MCSectionSubPair(Section, Subsection);
411 }
412
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100413 /// Create the default sections and set the initial one.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100414 virtual void InitSections(bool NoExecStack);
415
416 MCSymbol *endSection(MCSection *Section);
417
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100418 /// Sets the symbol's section.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100419 ///
420 /// Each emitted symbol will be tracked in the ordering table,
421 /// so we can sort on them later.
422 void AssignFragment(MCSymbol *Symbol, MCFragment *Fragment);
423
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100424 /// Emit a label for \p Symbol into the current section.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100425 ///
426 /// This corresponds to an assembler statement such as:
427 /// foo:
428 ///
429 /// \param Symbol - The symbol to emit. A given symbol should only be
430 /// emitted as a label once, and symbols emitted as a label should never be
431 /// used in an assignment.
432 // FIXME: These emission are non-const because we mutate the symbol to
433 // add the section we're emitting it to later.
434 virtual void EmitLabel(MCSymbol *Symbol, SMLoc Loc = SMLoc());
435
436 virtual void EmitEHSymAttributes(const MCSymbol *Symbol, MCSymbol *EHSymbol);
437
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100438 /// Note in the output the specified \p Flag.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100439 virtual void EmitAssemblerFlag(MCAssemblerFlag Flag);
440
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100441 /// Emit the given list \p Options of strings as linker
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100442 /// options into the output.
443 virtual void EmitLinkerOptions(ArrayRef<std::string> Kind) {}
444
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100445 /// Note in the output the specified region \p Kind.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100446 virtual void EmitDataRegion(MCDataRegionType Kind) {}
447
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100448 /// Specify the Mach-O minimum deployment target version.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100449 virtual void EmitVersionMin(MCVersionMinType Type, unsigned Major,
450 unsigned Minor, unsigned Update) {}
451
452 /// Emit/Specify Mach-O build version command.
453 /// \p Platform should be one of MachO::PlatformType.
454 virtual void EmitBuildVersion(unsigned Platform, unsigned Major,
455 unsigned Minor, unsigned Update) {}
456
457 void EmitVersionForTarget(const Triple &Target);
458
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100459 /// Note in the output that the specified \p Func is a Thumb mode
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100460 /// function (ARM target only).
461 virtual void EmitThumbFunc(MCSymbol *Func);
462
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100463 /// Emit an assignment of \p Value to \p Symbol.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100464 ///
465 /// This corresponds to an assembler statement such as:
466 /// symbol = value
467 ///
468 /// The assignment generates no code, but has the side effect of binding the
469 /// value in the current context. For the assembly streamer, this prints the
470 /// binding into the .s file.
471 ///
472 /// \param Symbol - The symbol being assigned to.
473 /// \param Value - The value for the symbol.
474 virtual void EmitAssignment(MCSymbol *Symbol, const MCExpr *Value);
475
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100476 /// Emit an weak reference from \p Alias to \p Symbol.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100477 ///
478 /// This corresponds to an assembler statement such as:
479 /// .weakref alias, symbol
480 ///
481 /// \param Alias - The alias that is being created.
482 /// \param Symbol - The symbol being aliased.
483 virtual void EmitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol);
484
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100485 /// Add the given \p Attribute to \p Symbol.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100486 virtual bool EmitSymbolAttribute(MCSymbol *Symbol,
487 MCSymbolAttr Attribute) = 0;
488
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100489 /// Set the \p DescValue for the \p Symbol.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100490 ///
491 /// \param Symbol - The symbol to have its n_desc field set.
492 /// \param DescValue - The value to set into the n_desc field.
493 virtual void EmitSymbolDesc(MCSymbol *Symbol, unsigned DescValue);
494
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100495 /// Start emitting COFF symbol definition
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100496 ///
497 /// \param Symbol - The symbol to have its External & Type fields set.
498 virtual void BeginCOFFSymbolDef(const MCSymbol *Symbol);
499
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100500 /// Emit the storage class of the symbol.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100501 ///
502 /// \param StorageClass - The storage class the symbol should have.
503 virtual void EmitCOFFSymbolStorageClass(int StorageClass);
504
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100505 /// Emit the type of the symbol.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100506 ///
507 /// \param Type - A COFF type identifier (see COFF::SymbolType in X86COFF.h)
508 virtual void EmitCOFFSymbolType(int Type);
509
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100510 /// Marks the end of the symbol definition.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100511 virtual void EndCOFFSymbolDef();
512
513 virtual void EmitCOFFSafeSEH(MCSymbol const *Symbol);
514
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100515 /// Emits the symbol table index of a Symbol into the current section.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100516 virtual void EmitCOFFSymbolIndex(MCSymbol const *Symbol);
517
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100518 /// Emits a COFF section index.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100519 ///
520 /// \param Symbol - Symbol the section number relocation should point to.
521 virtual void EmitCOFFSectionIndex(MCSymbol const *Symbol);
522
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100523 /// Emits a COFF section relative relocation.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100524 ///
525 /// \param Symbol - Symbol the section relative relocation should point to.
526 virtual void EmitCOFFSecRel32(MCSymbol const *Symbol, uint64_t Offset);
527
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100528 /// Emits a COFF image relative relocation.
529 ///
530 /// \param Symbol - Symbol the image relative relocation should point to.
531 virtual void EmitCOFFImgRel32(MCSymbol const *Symbol, int64_t Offset);
532
533 /// Emit an ELF .size directive.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100534 ///
535 /// This corresponds to an assembler statement such as:
536 /// .size symbol, expression
537 virtual void emitELFSize(MCSymbol *Symbol, const MCExpr *Value);
538
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100539 /// Emit an ELF .symver directive.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100540 ///
541 /// This corresponds to an assembler statement such as:
542 /// .symver _start, foo@@SOME_VERSION
543 /// \param AliasName - The versioned alias (i.e. "foo@@SOME_VERSION")
544 /// \param Aliasee - The aliased symbol (i.e. "_start")
545 virtual void emitELFSymverDirective(StringRef AliasName,
546 const MCSymbol *Aliasee);
547
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100548 /// Emit a Linker Optimization Hint (LOH) directive.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100549 /// \param Args - Arguments of the LOH.
550 virtual void EmitLOHDirective(MCLOHType Kind, const MCLOHArgs &Args) {}
551
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100552 /// Emit a common symbol.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100553 ///
554 /// \param Symbol - The common symbol to emit.
555 /// \param Size - The size of the common symbol.
556 /// \param ByteAlignment - The alignment of the symbol if
557 /// non-zero. This must be a power of 2.
558 virtual void EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
559 unsigned ByteAlignment) = 0;
560
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100561 /// Emit a local common (.lcomm) symbol.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100562 ///
563 /// \param Symbol - The common symbol to emit.
564 /// \param Size - The size of the common symbol.
565 /// \param ByteAlignment - The alignment of the common symbol in bytes.
566 virtual void EmitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size,
567 unsigned ByteAlignment);
568
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100569 /// Emit the zerofill section and an optional symbol.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100570 ///
571 /// \param Section - The zerofill section to create and or to put the symbol
572 /// \param Symbol - The zerofill symbol to emit, if non-NULL.
573 /// \param Size - The size of the zerofill symbol.
574 /// \param ByteAlignment - The alignment of the zerofill symbol if
575 /// non-zero. This must be a power of 2 on some targets.
576 virtual void EmitZerofill(MCSection *Section, MCSymbol *Symbol = nullptr,
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100577 uint64_t Size = 0, unsigned ByteAlignment = 0,
578 SMLoc Loc = SMLoc()) = 0;
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100579
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100580 /// Emit a thread local bss (.tbss) symbol.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100581 ///
582 /// \param Section - The thread local common section.
583 /// \param Symbol - The thread local common symbol to emit.
584 /// \param Size - The size of the symbol.
585 /// \param ByteAlignment - The alignment of the thread local common symbol
586 /// if non-zero. This must be a power of 2 on some targets.
587 virtual void EmitTBSSSymbol(MCSection *Section, MCSymbol *Symbol,
588 uint64_t Size, unsigned ByteAlignment = 0);
589
590 /// @}
591 /// \name Generating Data
592 /// @{
593
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100594 /// Emit the bytes in \p Data into the output.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100595 ///
596 /// This is used to implement assembler directives such as .byte, .ascii,
597 /// etc.
598 virtual void EmitBytes(StringRef Data);
599
600 /// Functionally identical to EmitBytes. When emitting textual assembly, this
601 /// method uses .byte directives instead of .ascii or .asciz for readability.
602 virtual void EmitBinaryData(StringRef Data);
603
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100604 /// Emit the expression \p Value into the output as a native
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100605 /// integer of the given \p Size bytes.
606 ///
607 /// This is used to implement assembler directives such as .word, .quad,
608 /// etc.
609 ///
610 /// \param Value - The value to emit.
611 /// \param Size - The size of the integer (in bytes) to emit. This must
612 /// match a native machine width.
613 /// \param Loc - The location of the expression for error reporting.
614 virtual void EmitValueImpl(const MCExpr *Value, unsigned Size,
615 SMLoc Loc = SMLoc());
616
617 void EmitValue(const MCExpr *Value, unsigned Size, SMLoc Loc = SMLoc());
618
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100619 /// Special case of EmitValue that avoids the client having
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100620 /// to pass in a MCExpr for constant integers.
621 virtual void EmitIntValue(uint64_t Value, unsigned Size);
622
623 virtual void EmitULEB128Value(const MCExpr *Value);
624
625 virtual void EmitSLEB128Value(const MCExpr *Value);
626
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100627 /// Special case of EmitULEB128Value that avoids the client having to
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100628 /// pass in a MCExpr for constant integers.
629 void EmitULEB128IntValue(uint64_t Value);
630
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100631 /// Special case of EmitSLEB128Value that avoids the client having to
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100632 /// pass in a MCExpr for constant integers.
633 void EmitSLEB128IntValue(int64_t Value);
634
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100635 /// Special case of EmitValue that avoids the client having to pass in
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100636 /// a MCExpr for MCSymbols.
637 void EmitSymbolValue(const MCSymbol *Sym, unsigned Size,
638 bool IsSectionRelative = false);
639
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100640 /// Emit the expression \p Value into the output as a dtprel
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100641 /// (64-bit DTP relative) value.
642 ///
643 /// This is used to implement assembler directives such as .dtpreldword on
644 /// targets that support them.
645 virtual void EmitDTPRel64Value(const MCExpr *Value);
646
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100647 /// Emit the expression \p Value into the output as a dtprel
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100648 /// (32-bit DTP relative) value.
649 ///
650 /// This is used to implement assembler directives such as .dtprelword on
651 /// targets that support them.
652 virtual void EmitDTPRel32Value(const MCExpr *Value);
653
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100654 /// Emit the expression \p Value into the output as a tprel
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100655 /// (64-bit TP relative) value.
656 ///
657 /// This is used to implement assembler directives such as .tpreldword on
658 /// targets that support them.
659 virtual void EmitTPRel64Value(const MCExpr *Value);
660
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100661 /// Emit the expression \p Value into the output as a tprel
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100662 /// (32-bit TP relative) value.
663 ///
664 /// This is used to implement assembler directives such as .tprelword on
665 /// targets that support them.
666 virtual void EmitTPRel32Value(const MCExpr *Value);
667
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100668 /// Emit the expression \p Value into the output as a gprel64 (64-bit
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100669 /// GP relative) value.
670 ///
671 /// This is used to implement assembler directives such as .gpdword on
672 /// targets that support them.
673 virtual void EmitGPRel64Value(const MCExpr *Value);
674
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100675 /// Emit the expression \p Value into the output as a gprel32 (32-bit
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100676 /// GP relative) value.
677 ///
678 /// This is used to implement assembler directives such as .gprel32 on
679 /// targets that support them.
680 virtual void EmitGPRel32Value(const MCExpr *Value);
681
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100682 /// Emit NumBytes bytes worth of the value specified by FillValue.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100683 /// This implements directives such as '.space'.
684 void emitFill(uint64_t NumBytes, uint8_t FillValue);
685
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100686 /// Emit \p Size bytes worth of the value specified by \p FillValue.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100687 ///
688 /// This is used to implement assembler directives such as .space or .skip.
689 ///
690 /// \param NumBytes - The number of bytes to emit.
691 /// \param FillValue - The value to use when filling bytes.
692 /// \param Loc - The location of the expression for error reporting.
693 virtual void emitFill(const MCExpr &NumBytes, uint64_t FillValue,
694 SMLoc Loc = SMLoc());
695
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100696 /// Emit \p NumValues copies of \p Size bytes. Each \p Size bytes is
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100697 /// taken from the lowest order 4 bytes of \p Expr expression.
698 ///
699 /// This is used to implement assembler directives such as .fill.
700 ///
701 /// \param NumValues - The number of copies of \p Size bytes to emit.
702 /// \param Size - The size (in bytes) of each repeated value.
703 /// \param Expr - The expression from which \p Size bytes are used.
704 virtual void emitFill(const MCExpr &NumValues, int64_t Size, int64_t Expr,
705 SMLoc Loc = SMLoc());
706
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100707 /// Emit NumBytes worth of zeros.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100708 /// This function properly handles data in virtual sections.
709 void EmitZeros(uint64_t NumBytes);
710
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100711 /// Emit some number of copies of \p Value until the byte alignment \p
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100712 /// ByteAlignment is reached.
713 ///
714 /// If the number of bytes need to emit for the alignment is not a multiple
715 /// of \p ValueSize, then the contents of the emitted fill bytes is
716 /// undefined.
717 ///
718 /// This used to implement the .align assembler directive.
719 ///
720 /// \param ByteAlignment - The alignment to reach. This must be a power of
721 /// two on some targets.
722 /// \param Value - The value to use when filling bytes.
723 /// \param ValueSize - The size of the integer (in bytes) to emit for
724 /// \p Value. This must match a native machine width.
725 /// \param MaxBytesToEmit - The maximum numbers of bytes to emit, or 0. If
726 /// the alignment cannot be reached in this many bytes, no bytes are
727 /// emitted.
728 virtual void EmitValueToAlignment(unsigned ByteAlignment, int64_t Value = 0,
729 unsigned ValueSize = 1,
730 unsigned MaxBytesToEmit = 0);
731
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100732 /// Emit nops until the byte alignment \p ByteAlignment is reached.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100733 ///
734 /// This used to align code where the alignment bytes may be executed. This
735 /// can emit different bytes for different sizes to optimize execution.
736 ///
737 /// \param ByteAlignment - The alignment to reach. This must be a power of
738 /// two on some targets.
739 /// \param MaxBytesToEmit - The maximum numbers of bytes to emit, or 0. If
740 /// the alignment cannot be reached in this many bytes, no bytes are
741 /// emitted.
742 virtual void EmitCodeAlignment(unsigned ByteAlignment,
743 unsigned MaxBytesToEmit = 0);
744
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100745 /// Emit some number of copies of \p Value until the byte offset \p
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100746 /// Offset is reached.
747 ///
748 /// This is used to implement assembler directives such as .org.
749 ///
750 /// \param Offset - The offset to reach. This may be an expression, but the
751 /// expression must be associated with the current section.
752 /// \param Value - The value to use when filling bytes.
753 virtual void emitValueToOffset(const MCExpr *Offset, unsigned char Value,
754 SMLoc Loc);
755
756 virtual void
757 EmitCodePaddingBasicBlockStart(const MCCodePaddingContext &Context) {}
758
759 virtual void
760 EmitCodePaddingBasicBlockEnd(const MCCodePaddingContext &Context) {}
761
762 /// @}
763
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100764 /// Switch to a new logical file. This is used to implement the '.file
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100765 /// "foo.c"' assembler directive.
766 virtual void EmitFileDirective(StringRef Filename);
767
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100768 /// Emit the "identifiers" directive. This implements the
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100769 /// '.ident "version foo"' assembler directive.
770 virtual void EmitIdent(StringRef IdentString) {}
771
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100772 /// Associate a filename with a specified logical file number. This
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100773 /// implements the DWARF2 '.file 4 "foo.c"' assembler directive.
774 unsigned EmitDwarfFileDirective(unsigned FileNo, StringRef Directory,
775 StringRef Filename,
776 MD5::MD5Result *Checksum = nullptr,
777 Optional<StringRef> Source = None,
778 unsigned CUID = 0) {
779 return cantFail(
780 tryEmitDwarfFileDirective(FileNo, Directory, Filename, Checksum,
781 Source, CUID));
782 }
783
784 /// Associate a filename with a specified logical file number.
785 /// Also associate a directory, optional checksum, and optional source
786 /// text with the logical file. This implements the DWARF2
787 /// '.file 4 "dir/foo.c"' assembler directive, and the DWARF5
788 /// '.file 4 "dir/foo.c" md5 "..." source "..."' assembler directive.
789 virtual Expected<unsigned> tryEmitDwarfFileDirective(
790 unsigned FileNo, StringRef Directory, StringRef Filename,
791 MD5::MD5Result *Checksum = nullptr, Optional<StringRef> Source = None,
792 unsigned CUID = 0);
793
794 /// Specify the "root" file of the compilation, using the ".file 0" extension.
795 virtual void emitDwarfFile0Directive(StringRef Directory, StringRef Filename,
796 MD5::MD5Result *Checksum,
797 Optional<StringRef> Source,
798 unsigned CUID = 0);
799
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100800 /// This implements the DWARF2 '.loc fileno lineno ...' assembler
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100801 /// directive.
802 virtual void EmitDwarfLocDirective(unsigned FileNo, unsigned Line,
803 unsigned Column, unsigned Flags,
804 unsigned Isa, unsigned Discriminator,
805 StringRef FileName);
806
807 /// Associate a filename with a specified logical file number, and also
808 /// specify that file's checksum information. This implements the '.cv_file 4
809 /// "foo.c"' assembler directive. Returns true on success.
810 virtual bool EmitCVFileDirective(unsigned FileNo, StringRef Filename,
811 ArrayRef<uint8_t> Checksum,
812 unsigned ChecksumKind);
813
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100814 /// Introduces a function id for use with .cv_loc.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100815 virtual bool EmitCVFuncIdDirective(unsigned FunctionId);
816
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100817 /// Introduces an inline call site id for use with .cv_loc. Includes
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100818 /// extra information for inline line table generation.
819 virtual bool EmitCVInlineSiteIdDirective(unsigned FunctionId, unsigned IAFunc,
820 unsigned IAFile, unsigned IALine,
821 unsigned IACol, SMLoc Loc);
822
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100823 /// This implements the CodeView '.cv_loc' assembler directive.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100824 virtual void EmitCVLocDirective(unsigned FunctionId, unsigned FileNo,
825 unsigned Line, unsigned Column,
826 bool PrologueEnd, bool IsStmt,
827 StringRef FileName, SMLoc Loc);
828
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100829 /// This implements the CodeView '.cv_linetable' assembler directive.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100830 virtual void EmitCVLinetableDirective(unsigned FunctionId,
831 const MCSymbol *FnStart,
832 const MCSymbol *FnEnd);
833
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100834 /// This implements the CodeView '.cv_inline_linetable' assembler
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100835 /// directive.
836 virtual void EmitCVInlineLinetableDirective(unsigned PrimaryFunctionId,
837 unsigned SourceFileId,
838 unsigned SourceLineNum,
839 const MCSymbol *FnStartSym,
840 const MCSymbol *FnEndSym);
841
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100842 /// This implements the CodeView '.cv_def_range' assembler
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100843 /// directive.
844 virtual void EmitCVDefRangeDirective(
845 ArrayRef<std::pair<const MCSymbol *, const MCSymbol *>> Ranges,
846 StringRef FixedSizePortion);
847
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100848 /// This implements the CodeView '.cv_stringtable' assembler directive.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100849 virtual void EmitCVStringTableDirective() {}
850
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100851 /// This implements the CodeView '.cv_filechecksums' assembler directive.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100852 virtual void EmitCVFileChecksumsDirective() {}
853
854 /// This implements the CodeView '.cv_filechecksumoffset' assembler
855 /// directive.
856 virtual void EmitCVFileChecksumOffsetDirective(unsigned FileNo) {}
857
858 /// This implements the CodeView '.cv_fpo_data' assembler directive.
859 virtual void EmitCVFPOData(const MCSymbol *ProcSym, SMLoc Loc = {}) {}
860
861 /// Emit the absolute difference between two symbols.
862 ///
863 /// \pre Offset of \c Hi is greater than the offset \c Lo.
864 virtual void emitAbsoluteSymbolDiff(const MCSymbol *Hi, const MCSymbol *Lo,
865 unsigned Size);
866
867 /// Emit the absolute difference between two symbols encoded with ULEB128.
868 virtual void emitAbsoluteSymbolDiffAsULEB128(const MCSymbol *Hi,
869 const MCSymbol *Lo);
870
871 virtual MCSymbol *getDwarfLineTableSymbol(unsigned CUID);
872 virtual void EmitCFISections(bool EH, bool Debug);
873 void EmitCFIStartProc(bool IsSimple);
874 void EmitCFIEndProc();
875 virtual void EmitCFIDefCfa(int64_t Register, int64_t Offset);
876 virtual void EmitCFIDefCfaOffset(int64_t Offset);
877 virtual void EmitCFIDefCfaRegister(int64_t Register);
878 virtual void EmitCFIOffset(int64_t Register, int64_t Offset);
879 virtual void EmitCFIPersonality(const MCSymbol *Sym, unsigned Encoding);
880 virtual void EmitCFILsda(const MCSymbol *Sym, unsigned Encoding);
881 virtual void EmitCFIRememberState();
882 virtual void EmitCFIRestoreState();
883 virtual void EmitCFISameValue(int64_t Register);
884 virtual void EmitCFIRestore(int64_t Register);
885 virtual void EmitCFIRelOffset(int64_t Register, int64_t Offset);
886 virtual void EmitCFIAdjustCfaOffset(int64_t Adjustment);
887 virtual void EmitCFIEscape(StringRef Values);
888 virtual void EmitCFIReturnColumn(int64_t Register);
889 virtual void EmitCFIGnuArgsSize(int64_t Size);
890 virtual void EmitCFISignalFrame();
891 virtual void EmitCFIUndefined(int64_t Register);
892 virtual void EmitCFIRegister(int64_t Register1, int64_t Register2);
893 virtual void EmitCFIWindowSave();
894
895 virtual void EmitWinCFIStartProc(const MCSymbol *Symbol, SMLoc Loc = SMLoc());
896 virtual void EmitWinCFIEndProc(SMLoc Loc = SMLoc());
897 virtual void EmitWinCFIStartChained(SMLoc Loc = SMLoc());
898 virtual void EmitWinCFIEndChained(SMLoc Loc = SMLoc());
899 virtual void EmitWinCFIPushReg(unsigned Register, SMLoc Loc = SMLoc());
900 virtual void EmitWinCFISetFrame(unsigned Register, unsigned Offset,
901 SMLoc Loc = SMLoc());
902 virtual void EmitWinCFIAllocStack(unsigned Size, SMLoc Loc = SMLoc());
903 virtual void EmitWinCFISaveReg(unsigned Register, unsigned Offset,
904 SMLoc Loc = SMLoc());
905 virtual void EmitWinCFISaveXMM(unsigned Register, unsigned Offset,
906 SMLoc Loc = SMLoc());
907 virtual void EmitWinCFIPushFrame(bool Code, SMLoc Loc = SMLoc());
908 virtual void EmitWinCFIEndProlog(SMLoc Loc = SMLoc());
909 virtual void EmitWinEHHandler(const MCSymbol *Sym, bool Unwind, bool Except,
910 SMLoc Loc = SMLoc());
911 virtual void EmitWinEHHandlerData(SMLoc Loc = SMLoc());
912
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100913 virtual void emitCGProfileEntry(const MCSymbolRefExpr *From,
914 const MCSymbolRefExpr *To, uint64_t Count);
915
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100916 /// Get the .pdata section used for the given section. Typically the given
917 /// section is either the main .text section or some other COMDAT .text
918 /// section, but it may be any section containing code.
919 MCSection *getAssociatedPDataSection(const MCSection *TextSec);
920
921 /// Get the .xdata section used for the given section.
922 MCSection *getAssociatedXDataSection(const MCSection *TextSec);
923
924 virtual void EmitSyntaxDirective();
925
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100926 /// Emit a .reloc directive.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100927 /// Returns true if the relocation could not be emitted because Name is not
928 /// known.
929 virtual bool EmitRelocDirective(const MCExpr &Offset, StringRef Name,
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100930 const MCExpr *Expr, SMLoc Loc,
931 const MCSubtargetInfo &STI) {
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100932 return true;
933 }
934
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100935 virtual void EmitAddrsig() {}
936 virtual void EmitAddrsigSym(const MCSymbol *Sym) {}
937
938 /// Emit the given \p Instruction into the current section.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100939 /// PrintSchedInfo == true then schedul comment should be added to output
940 virtual void EmitInstruction(const MCInst &Inst, const MCSubtargetInfo &STI,
941 bool PrintSchedInfo = false);
942
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100943 /// Set the bundle alignment mode from now on in the section.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100944 /// The argument is the power of 2 to which the alignment is set. The
945 /// value 0 means turn the bundle alignment off.
946 virtual void EmitBundleAlignMode(unsigned AlignPow2);
947
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100948 /// The following instructions are a bundle-locked group.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100949 ///
950 /// \param AlignToEnd - If true, the bundle-locked group will be aligned to
951 /// the end of a bundle.
952 virtual void EmitBundleLock(bool AlignToEnd);
953
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100954 /// Ends a bundle-locked group.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100955 virtual void EmitBundleUnlock();
956
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100957 /// If this file is backed by a assembly streamer, this dumps the
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100958 /// specified string in the output .s file. This capability is indicated by
959 /// the hasRawTextSupport() predicate. By default this aborts.
960 void EmitRawText(const Twine &String);
961
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100962 /// Streamer specific finalization.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100963 virtual void FinishImpl();
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100964 /// Finish emission of machine code.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100965 void Finish();
966
967 virtual bool mayHaveInstructions(MCSection &Sec) const { return true; }
968};
969
970/// Create a dummy machine code streamer, which does nothing. This is useful for
971/// timing the assembler front end.
972MCStreamer *createNullStreamer(MCContext &Ctx);
973
974/// Create a machine code streamer which will print out assembly for the native
975/// target, suitable for compiling with a native assembler.
976///
977/// \param InstPrint - If given, the instruction printer to use. If not given
978/// the MCInst representation will be printed. This method takes ownership of
979/// InstPrint.
980///
981/// \param CE - If given, a code emitter to use to show the instruction
982/// encoding inline with the assembly. This method takes ownership of \p CE.
983///
984/// \param TAB - If given, a target asm backend to use to show the fixup
985/// information in conjunction with encoding information. This method takes
986/// ownership of \p TAB.
987///
988/// \param ShowInst - Whether to show the MCInst representation inline with
989/// the assembly.
990MCStreamer *createAsmStreamer(MCContext &Ctx,
991 std::unique_ptr<formatted_raw_ostream> OS,
992 bool isVerboseAsm, bool useDwarfDirectory,
993 MCInstPrinter *InstPrint, MCCodeEmitter *CE,
994 MCAsmBackend *TAB, bool ShowInst);
995
996} // end namespace llvm
997
998#endif // LLVM_MC_MCSTREAMER_H