/Users/buildslave/jenkins/sharedspace/clang-stage2-coverage-R@2/llvm/include/llvm/MC/MCStreamer.h
Line | Count | Source (jump to first uncovered line) |
1 | | //===- 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/SmallVector.h" |
20 | | #include "llvm/ADT/StringRef.h" |
21 | | #include "llvm/MC/MCDirectives.h" |
22 | | #include "llvm/MC/MCDwarf.h" |
23 | | #include "llvm/MC/MCLinkerOptimizationHint.h" |
24 | | #include "llvm/MC/MCSymbol.h" |
25 | | #include "llvm/MC/MCWinEH.h" |
26 | | #include "llvm/Support/SMLoc.h" |
27 | | #include "llvm/Support/TargetParser.h" |
28 | | #include <cassert> |
29 | | #include <cstdint> |
30 | | #include <memory> |
31 | | #include <string> |
32 | | #include <utility> |
33 | | #include <vector> |
34 | | |
35 | | namespace llvm { |
36 | | |
37 | | class AssemblerConstantPools; |
38 | | class formatted_raw_ostream; |
39 | | class MCAsmBackend; |
40 | | class MCCodeEmitter; |
41 | | class MCContext; |
42 | | class MCExpr; |
43 | | class MCInst; |
44 | | class MCInstPrinter; |
45 | | class MCSection; |
46 | | class MCStreamer; |
47 | | class MCSymbolRefExpr; |
48 | | class MCSubtargetInfo; |
49 | | class raw_ostream; |
50 | | class Twine; |
51 | | |
52 | | using MCSectionSubPair = std::pair<MCSection *, const MCExpr *>; |
53 | | |
54 | | /// Target specific streamer interface. This is used so that targets can |
55 | | /// implement support for target specific assembly directives. |
56 | | /// |
57 | | /// If target foo wants to use this, it should implement 3 classes: |
58 | | /// * FooTargetStreamer : public MCTargetStreamer |
59 | | /// * FooTargetAsmStreamer : public FooTargetStreamer |
60 | | /// * FooTargetELFStreamer : public FooTargetStreamer |
61 | | /// |
62 | | /// FooTargetStreamer should have a pure virtual method for each directive. For |
63 | | /// example, for a ".bar symbol_name" directive, it should have |
64 | | /// virtual emitBar(const MCSymbol &Symbol) = 0; |
65 | | /// |
66 | | /// The FooTargetAsmStreamer and FooTargetELFStreamer classes implement the |
67 | | /// method. The assembly streamer just prints ".bar symbol_name". The object |
68 | | /// streamer does whatever is needed to implement .bar in the object file. |
69 | | /// |
70 | | /// In the assembly printer and parser the target streamer can be used by |
71 | | /// calling getTargetStreamer and casting it to FooTargetStreamer: |
72 | | /// |
73 | | /// MCTargetStreamer &TS = OutStreamer.getTargetStreamer(); |
74 | | /// FooTargetStreamer &ATS = static_cast<FooTargetStreamer &>(TS); |
75 | | /// |
76 | | /// The base classes FooTargetAsmStreamer and FooTargetELFStreamer should |
77 | | /// *never* be treated differently. Callers should always talk to a |
78 | | /// FooTargetStreamer. |
79 | | class MCTargetStreamer { |
80 | | protected: |
81 | | MCStreamer &Streamer; |
82 | | |
83 | | public: |
84 | | MCTargetStreamer(MCStreamer &S); |
85 | | virtual ~MCTargetStreamer(); |
86 | | |
87 | 10.4k | MCStreamer &getStreamer() { return Streamer; } |
88 | | |
89 | | // Allow a target to add behavior to the EmitLabel of MCStreamer. |
90 | | virtual void emitLabel(MCSymbol *Symbol); |
91 | | // Allow a target to add behavior to the emitAssignment of MCStreamer. |
92 | | virtual void emitAssignment(MCSymbol *Symbol, const MCExpr *Value); |
93 | | |
94 | | virtual void prettyPrintAsm(MCInstPrinter &InstPrinter, raw_ostream &OS, |
95 | | const MCInst &Inst, const MCSubtargetInfo &STI); |
96 | | |
97 | | virtual void finish(); |
98 | | }; |
99 | | |
100 | | // FIXME: declared here because it is used from |
101 | | // lib/CodeGen/AsmPrinter/ARMException.cpp. |
102 | | class ARMTargetStreamer : public MCTargetStreamer { |
103 | | public: |
104 | | ARMTargetStreamer(MCStreamer &S); |
105 | | ~ARMTargetStreamer() override; |
106 | | |
107 | | virtual void emitFnStart(); |
108 | | virtual void emitFnEnd(); |
109 | | virtual void emitCantUnwind(); |
110 | | virtual void emitPersonality(const MCSymbol *Personality); |
111 | | virtual void emitPersonalityIndex(unsigned Index); |
112 | | virtual void emitHandlerData(); |
113 | | virtual void emitSetFP(unsigned FpReg, unsigned SpReg, |
114 | | int64_t Offset = 0); |
115 | | virtual void emitMovSP(unsigned Reg, int64_t Offset = 0); |
116 | | virtual void emitPad(int64_t Offset); |
117 | | virtual void emitRegSave(const SmallVectorImpl<unsigned> &RegList, |
118 | | bool isVector); |
119 | | virtual void emitUnwindRaw(int64_t StackOffset, |
120 | | const SmallVectorImpl<uint8_t> &Opcodes); |
121 | | |
122 | | virtual void switchVendor(StringRef Vendor); |
123 | | virtual void emitAttribute(unsigned Attribute, unsigned Value); |
124 | | virtual void emitTextAttribute(unsigned Attribute, StringRef String); |
125 | | virtual void emitIntTextAttribute(unsigned Attribute, unsigned IntValue, |
126 | | StringRef StringValue = ""); |
127 | | virtual void emitFPU(unsigned FPU); |
128 | | virtual void emitArch(ARM::ArchKind Arch); |
129 | | virtual void emitArchExtension(unsigned ArchExt); |
130 | | virtual void emitObjectArch(ARM::ArchKind Arch); |
131 | | void emitTargetAttributes(const MCSubtargetInfo &STI); |
132 | | virtual void finishAttributeSection(); |
133 | | virtual void emitInst(uint32_t Inst, char Suffix = '\0'); |
134 | | |
135 | | virtual void AnnotateTLSDescriptorSequence(const MCSymbolRefExpr *SRE); |
136 | | |
137 | | virtual void emitThumbSet(MCSymbol *Symbol, const MCExpr *Value); |
138 | | |
139 | | void finish() override; |
140 | | |
141 | | /// Reset any state between object emissions, i.e. the equivalent of |
142 | | /// MCStreamer's reset method. |
143 | | virtual void reset(); |
144 | | |
145 | | /// Callback used to implement the ldr= pseudo. |
146 | | /// Add a new entry to the constant pool for the current section and return an |
147 | | /// MCExpr that can be used to refer to the constant pool location. |
148 | | const MCExpr *addConstantPoolEntry(const MCExpr *, SMLoc Loc); |
149 | | |
150 | | /// Callback used to implemnt the .ltorg directive. |
151 | | /// Emit contents of constant pool for the current section. |
152 | | void emitCurrentConstantPool(); |
153 | | |
154 | | private: |
155 | | std::unique_ptr<AssemblerConstantPools> ConstantPools; |
156 | | }; |
157 | | |
158 | | /// \brief Streaming machine code generation interface. |
159 | | /// |
160 | | /// This interface is intended to provide a programatic interface that is very |
161 | | /// similar to the level that an assembler .s file provides. It has callbacks |
162 | | /// to emit bytes, handle directives, etc. The implementation of this interface |
163 | | /// retains state to know what the current section is etc. |
164 | | /// |
165 | | /// There are multiple implementations of this interface: one for writing out |
166 | | /// a .s file, and implementations that write out .o files of various formats. |
167 | | /// |
168 | | class MCStreamer { |
169 | | MCContext &Context; |
170 | | std::unique_ptr<MCTargetStreamer> TargetStreamer; |
171 | | |
172 | | std::vector<MCDwarfFrameInfo> DwarfFrameInfos; |
173 | | MCDwarfFrameInfo *getCurrentDwarfFrameInfo(); |
174 | | void EnsureValidDwarfFrame(); |
175 | | |
176 | | MCSymbol *EmitCFILabel(); |
177 | | MCSymbol *EmitCFICommon(); |
178 | | |
179 | | std::vector<WinEH::FrameInfo *> WinFrameInfos; |
180 | | WinEH::FrameInfo *CurrentWinFrameInfo; |
181 | | void EnsureValidWinFrameInfo(); |
182 | | |
183 | | /// \brief Tracks an index to represent the order a symbol was emitted in. |
184 | | /// Zero means we did not emit that symbol. |
185 | | DenseMap<const MCSymbol *, unsigned> SymbolOrdering; |
186 | | |
187 | | /// \brief This is stack of current and previous section values saved by |
188 | | /// PushSection. |
189 | | SmallVector<std::pair<MCSectionSubPair, MCSectionSubPair>, 4> SectionStack; |
190 | | |
191 | | /// The next unique ID to use when creating a WinCFI-related section (.pdata |
192 | | /// or .xdata). This ID ensures that we have a one-to-one mapping from |
193 | | /// code section to unwind info section, which MSVC's incremental linker |
194 | | /// requires. |
195 | | unsigned NextWinCFIID = 0; |
196 | | |
197 | | protected: |
198 | | MCStreamer(MCContext &Ctx); |
199 | | |
200 | | virtual void EmitCFIStartProcImpl(MCDwarfFrameInfo &Frame); |
201 | | virtual void EmitCFIEndProcImpl(MCDwarfFrameInfo &CurFrame); |
202 | | |
203 | 392 | WinEH::FrameInfo *getCurrentWinFrameInfo() { |
204 | 392 | return CurrentWinFrameInfo; |
205 | 392 | } |
206 | | |
207 | | virtual void EmitWindowsUnwindTables(); |
208 | | |
209 | | virtual void EmitRawTextImpl(StringRef String); |
210 | | |
211 | | public: |
212 | | MCStreamer(const MCStreamer &) = delete; |
213 | | MCStreamer &operator=(const MCStreamer &) = delete; |
214 | | virtual ~MCStreamer(); |
215 | | |
216 | | void visitUsedExpr(const MCExpr &Expr); |
217 | | virtual void visitUsedSymbol(const MCSymbol &Sym); |
218 | | |
219 | 14.3k | void setTargetStreamer(MCTargetStreamer *TS) { |
220 | 14.3k | TargetStreamer.reset(TS); |
221 | 14.3k | } |
222 | | |
223 | | /// State management |
224 | | /// |
225 | | virtual void reset(); |
226 | | |
227 | 64.1M | MCContext &getContext() const { return Context; } |
228 | | |
229 | 10.2M | MCTargetStreamer *getTargetStreamer() { |
230 | 10.2M | return TargetStreamer.get(); |
231 | 10.2M | } |
232 | | |
233 | 23.0k | unsigned getNumFrameInfos() { return DwarfFrameInfos.size(); } |
234 | 7.81k | ArrayRef<MCDwarfFrameInfo> getDwarfFrameInfos() const { |
235 | 7.81k | return DwarfFrameInfos; |
236 | 7.81k | } |
237 | | |
238 | | bool hasUnfinishedDwarfFrameInfo(); |
239 | | |
240 | 73.2k | unsigned getNumWinFrameInfos() { return WinFrameInfos.size(); } |
241 | 82 | ArrayRef<WinEH::FrameInfo *> getWinFrameInfos() const { |
242 | 82 | return WinFrameInfos; |
243 | 82 | } |
244 | | |
245 | | void generateCompactUnwindEncodings(MCAsmBackend *MAB); |
246 | | |
247 | | /// \name Assembly File Formatting. |
248 | | /// @{ |
249 | | |
250 | | /// \brief Return true if this streamer supports verbose assembly and if it is |
251 | | /// enabled. |
252 | 45.0k | virtual bool isVerboseAsm() const { return false; } |
253 | | |
254 | | /// \brief Return true if this asm streamer supports emitting unformatted text |
255 | | /// to the .s file with EmitRawText. |
256 | 216k | virtual bool hasRawTextSupport() const { return false; } |
257 | | |
258 | | /// \brief Is the integrated assembler required for this streamer to function |
259 | | /// correctly? |
260 | 1.70k | virtual bool isIntegratedAssemblerRequired() const { return false; } |
261 | | |
262 | | /// \brief Add a textual comment. |
263 | | /// |
264 | | /// Typically for comments that can be emitted to the generated .s |
265 | | /// file if applicable as a QoI issue to make the output of the compiler |
266 | | /// more readable. This only affects the MCAsmStreamer, and only when |
267 | | /// verbose assembly output is enabled. |
268 | | /// |
269 | | /// If the comment includes embedded \n's, they will each get the comment |
270 | | /// prefix as appropriate. The added comment should not end with a \n. |
271 | | /// By default, each comment is terminated with an end of line, i.e. the |
272 | | /// EOL param is set to true by default. If one prefers not to end the |
273 | | /// comment with a new line then the EOL param should be passed |
274 | | /// with a false value. |
275 | 181k | virtual void AddComment(const Twine &T, bool EOL = true) {} |
276 | | |
277 | | /// \brief Return a raw_ostream that comments can be written to. Unlike |
278 | | /// AddComment, you are required to terminate comments with \n if you use this |
279 | | /// method. |
280 | | virtual raw_ostream &GetCommentOS(); |
281 | | |
282 | | /// \brief Print T and prefix it with the comment string (normally #) and |
283 | | /// optionally a tab. This prints the comment immediately, not at the end of |
284 | | /// the current line. It is basically a safe version of EmitRawText: since it |
285 | | /// only prints comments, the object streamer ignores it instead of asserting. |
286 | | virtual void emitRawComment(const Twine &T, bool TabPrefix = true); |
287 | | |
288 | | /// \brief Add explicit comment T. T is required to be a valid |
289 | | /// comment in the output and does not need to be escaped. |
290 | | virtual void addExplicitComment(const Twine &T); |
291 | | |
292 | | /// \brief Emit added explicit comments. |
293 | | virtual void emitExplicitComments(); |
294 | | |
295 | | /// AddBlankLine - Emit a blank line to a .s file to pretty it up. |
296 | 1.36M | virtual void AddBlankLine() {} |
297 | | |
298 | | /// @} |
299 | | |
300 | | /// \name Symbol & Section Management |
301 | | /// @{ |
302 | | |
303 | | /// \brief Return the current section that the streamer is emitting code to. |
304 | 103M | MCSectionSubPair getCurrentSection() const { |
305 | 103M | if (!SectionStack.empty()) |
306 | 103M | return SectionStack.back().first; |
307 | 18.4E | return MCSectionSubPair(); |
308 | 103M | } |
309 | 103M | MCSection *getCurrentSectionOnly() const { return getCurrentSection().first; } |
310 | | |
311 | | /// \brief Return the previous section that the streamer is emitting code to. |
312 | 13.0k | MCSectionSubPair getPreviousSection() const { |
313 | 13.0k | if (!SectionStack.empty()) |
314 | 13.0k | return SectionStack.back().second; |
315 | 0 | return MCSectionSubPair(); |
316 | 13.0k | } |
317 | | |
318 | | /// \brief Returns an index to represent the order a symbol was emitted in. |
319 | | /// (zero if we did not emit that symbol) |
320 | 14 | unsigned GetSymbolOrder(const MCSymbol *Sym) const { |
321 | 14 | return SymbolOrdering.lookup(Sym); |
322 | 14 | } |
323 | | |
324 | | /// \brief Update streamer for a new active section. |
325 | | /// |
326 | | /// This is called by PopSection and SwitchSection, if the current |
327 | | /// section changes. |
328 | | virtual void ChangeSection(MCSection *, const MCExpr *); |
329 | | |
330 | | /// \brief Save the current and previous section on the section stack. |
331 | 1.29k | void PushSection() { |
332 | 1.29k | SectionStack.push_back( |
333 | 1.29k | std::make_pair(getCurrentSection(), getPreviousSection())); |
334 | 1.29k | } |
335 | | |
336 | | /// \brief Restore the current and previous section from the section stack. |
337 | | /// Calls ChangeSection as needed. |
338 | | /// |
339 | | /// Returns false if the stack was empty. |
340 | 1.29k | bool PopSection() { |
341 | 1.29k | if (SectionStack.size() <= 1) |
342 | 0 | return false; |
343 | 1.29k | auto I = SectionStack.end(); |
344 | 1.29k | --I; |
345 | 1.29k | MCSectionSubPair OldSection = I->first; |
346 | 1.29k | --I; |
347 | 1.29k | MCSectionSubPair NewSection = I->first; |
348 | 1.29k | |
349 | 1.29k | if (OldSection != NewSection) |
350 | 1.07k | ChangeSection(NewSection.first, NewSection.second); |
351 | 1.29k | SectionStack.pop_back(); |
352 | 1.29k | return true; |
353 | 1.29k | } |
354 | | |
355 | 4 | bool SubSection(const MCExpr *Subsection) { |
356 | 4 | if (SectionStack.empty()) |
357 | 0 | return false; |
358 | 4 | |
359 | 4 | SwitchSection(SectionStack.back().first.first, Subsection); |
360 | 4 | return true; |
361 | 4 | } |
362 | | |
363 | | /// Set the current section where code is being emitted to \p Section. This |
364 | | /// is required to update CurSection. |
365 | | /// |
366 | | /// This corresponds to assembler directives like .section, .text, etc. |
367 | | virtual void SwitchSection(MCSection *Section, |
368 | | const MCExpr *Subsection = nullptr); |
369 | | |
370 | | /// \brief Set the current section where code is being emitted to \p Section. |
371 | | /// This is required to update CurSection. This version does not call |
372 | | /// ChangeSection. |
373 | | void SwitchSectionNoChange(MCSection *Section, |
374 | 328 | const MCExpr *Subsection = nullptr) { |
375 | 328 | assert(Section && "Cannot switch to a null section!"); |
376 | 328 | MCSectionSubPair curSection = SectionStack.back().first; |
377 | 328 | SectionStack.back().second = curSection; |
378 | 328 | if (MCSectionSubPair(Section, Subsection) != curSection) |
379 | 328 | SectionStack.back().first = MCSectionSubPair(Section, Subsection); |
380 | 328 | } |
381 | | |
382 | | /// \brief Create the default sections and set the initial one. |
383 | | virtual void InitSections(bool NoExecStack); |
384 | | |
385 | | MCSymbol *endSection(MCSection *Section); |
386 | | |
387 | | /// \brief Sets the symbol's section. |
388 | | /// |
389 | | /// Each emitted symbol will be tracked in the ordering table, |
390 | | /// so we can sort on them later. |
391 | | void AssignFragment(MCSymbol *Symbol, MCFragment *Fragment); |
392 | | |
393 | | /// \brief Emit a label for \p Symbol into the current section. |
394 | | /// |
395 | | /// This corresponds to an assembler statement such as: |
396 | | /// foo: |
397 | | /// |
398 | | /// \param Symbol - The symbol to emit. A given symbol should only be |
399 | | /// emitted as a label once, and symbols emitted as a label should never be |
400 | | /// used in an assignment. |
401 | | // FIXME: These emission are non-const because we mutate the symbol to |
402 | | // add the section we're emitting it to later. |
403 | | virtual void EmitLabel(MCSymbol *Symbol, SMLoc Loc = SMLoc()); |
404 | | |
405 | | virtual void EmitEHSymAttributes(const MCSymbol *Symbol, MCSymbol *EHSymbol); |
406 | | |
407 | | /// \brief Note in the output the specified \p Flag. |
408 | | virtual void EmitAssemblerFlag(MCAssemblerFlag Flag); |
409 | | |
410 | | /// \brief Emit the given list \p Options of strings as linker |
411 | | /// options into the output. |
412 | 0 | virtual void EmitLinkerOptions(ArrayRef<std::string> Kind) {} |
413 | | |
414 | | /// \brief Note in the output the specified region \p Kind. |
415 | 132 | virtual void EmitDataRegion(MCDataRegionType Kind) {} |
416 | | |
417 | | /// \brief Specify the MachO minimum deployment target version. |
418 | | virtual void EmitVersionMin(MCVersionMinType, unsigned Major, unsigned Minor, |
419 | 67 | unsigned Update) {} |
420 | | |
421 | | /// \brief Note in the output that the specified \p Func is a Thumb mode |
422 | | /// function (ARM target only). |
423 | | virtual void EmitThumbFunc(MCSymbol *Func); |
424 | | |
425 | | /// \brief Emit an assignment of \p Value to \p Symbol. |
426 | | /// |
427 | | /// This corresponds to an assembler statement such as: |
428 | | /// symbol = value |
429 | | /// |
430 | | /// The assignment generates no code, but has the side effect of binding the |
431 | | /// value in the current context. For the assembly streamer, this prints the |
432 | | /// binding into the .s file. |
433 | | /// |
434 | | /// \param Symbol - The symbol being assigned to. |
435 | | /// \param Value - The value for the symbol. |
436 | | virtual void EmitAssignment(MCSymbol *Symbol, const MCExpr *Value); |
437 | | |
438 | | /// \brief Emit an weak reference from \p Alias to \p Symbol. |
439 | | /// |
440 | | /// This corresponds to an assembler statement such as: |
441 | | /// .weakref alias, symbol |
442 | | /// |
443 | | /// \param Alias - The alias that is being created. |
444 | | /// \param Symbol - The symbol being aliased. |
445 | | virtual void EmitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol); |
446 | | |
447 | | /// \brief Add the given \p Attribute to \p Symbol. |
448 | | virtual bool EmitSymbolAttribute(MCSymbol *Symbol, |
449 | | MCSymbolAttr Attribute) = 0; |
450 | | |
451 | | /// \brief Set the \p DescValue for the \p Symbol. |
452 | | /// |
453 | | /// \param Symbol - The symbol to have its n_desc field set. |
454 | | /// \param DescValue - The value to set into the n_desc field. |
455 | | virtual void EmitSymbolDesc(MCSymbol *Symbol, unsigned DescValue); |
456 | | |
457 | | /// \brief Start emitting COFF symbol definition |
458 | | /// |
459 | | /// \param Symbol - The symbol to have its External & Type fields set. |
460 | | virtual void BeginCOFFSymbolDef(const MCSymbol *Symbol); |
461 | | |
462 | | /// \brief Emit the storage class of the symbol. |
463 | | /// |
464 | | /// \param StorageClass - The storage class the symbol should have. |
465 | | virtual void EmitCOFFSymbolStorageClass(int StorageClass); |
466 | | |
467 | | /// \brief Emit the type of the symbol. |
468 | | /// |
469 | | /// \param Type - A COFF type identifier (see COFF::SymbolType in X86COFF.h) |
470 | | virtual void EmitCOFFSymbolType(int Type); |
471 | | |
472 | | /// \brief Marks the end of the symbol definition. |
473 | | virtual void EndCOFFSymbolDef(); |
474 | | |
475 | | virtual void EmitCOFFSafeSEH(MCSymbol const *Symbol); |
476 | | |
477 | | /// \brief Emits a COFF section index. |
478 | | /// |
479 | | /// \param Symbol - Symbol the section number relocation should point to. |
480 | | virtual void EmitCOFFSectionIndex(MCSymbol const *Symbol); |
481 | | |
482 | | /// \brief Emits a COFF section relative relocation. |
483 | | /// |
484 | | /// \param Symbol - Symbol the section relative relocation should point to. |
485 | | virtual void EmitCOFFSecRel32(MCSymbol const *Symbol, uint64_t Offset); |
486 | | |
487 | | /// \brief Emit an ELF .size directive. |
488 | | /// |
489 | | /// This corresponds to an assembler statement such as: |
490 | | /// .size symbol, expression |
491 | | virtual void emitELFSize(MCSymbol *Symbol, const MCExpr *Value); |
492 | | |
493 | | /// \brief Emit an ELF .symver directive. |
494 | | /// |
495 | | /// This corresponds to an assembler statement such as: |
496 | | /// .symver _start, foo@@SOME_VERSION |
497 | | /// \param Alias - The versioned alias (i.e. "foo@@SOME_VERSION") |
498 | | /// \param Aliasee - The aliased symbol (i.e. "_start") |
499 | | virtual void emitELFSymverDirective(MCSymbol *Alias, const MCSymbol *Aliasee); |
500 | | |
501 | | /// \brief Emit a Linker Optimization Hint (LOH) directive. |
502 | | /// \param Args - Arguments of the LOH. |
503 | 0 | virtual void EmitLOHDirective(MCLOHType Kind, const MCLOHArgs &Args) {} |
504 | | |
505 | | /// \brief Emit a common symbol. |
506 | | /// |
507 | | /// \param Symbol - The common symbol to emit. |
508 | | /// \param Size - The size of the common symbol. |
509 | | /// \param ByteAlignment - The alignment of the symbol if |
510 | | /// non-zero. This must be a power of 2. |
511 | | virtual void EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size, |
512 | | unsigned ByteAlignment) = 0; |
513 | | |
514 | | /// \brief Emit a local common (.lcomm) symbol. |
515 | | /// |
516 | | /// \param Symbol - The common symbol to emit. |
517 | | /// \param Size - The size of the common symbol. |
518 | | /// \param ByteAlignment - The alignment of the common symbol in bytes. |
519 | | virtual void EmitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size, |
520 | | unsigned ByteAlignment); |
521 | | |
522 | | /// \brief Emit the zerofill section and an optional symbol. |
523 | | /// |
524 | | /// \param Section - The zerofill section to create and or to put the symbol |
525 | | /// \param Symbol - The zerofill symbol to emit, if non-NULL. |
526 | | /// \param Size - The size of the zerofill symbol. |
527 | | /// \param ByteAlignment - The alignment of the zerofill symbol if |
528 | | /// non-zero. This must be a power of 2 on some targets. |
529 | | virtual void EmitZerofill(MCSection *Section, MCSymbol *Symbol = nullptr, |
530 | | uint64_t Size = 0, unsigned ByteAlignment = 0) = 0; |
531 | | |
532 | | /// \brief Emit a thread local bss (.tbss) symbol. |
533 | | /// |
534 | | /// \param Section - The thread local common section. |
535 | | /// \param Symbol - The thread local common symbol to emit. |
536 | | /// \param Size - The size of the symbol. |
537 | | /// \param ByteAlignment - The alignment of the thread local common symbol |
538 | | /// if non-zero. This must be a power of 2 on some targets. |
539 | | virtual void EmitTBSSSymbol(MCSection *Section, MCSymbol *Symbol, |
540 | | uint64_t Size, unsigned ByteAlignment = 0); |
541 | | |
542 | | /// @} |
543 | | /// \name Generating Data |
544 | | /// @{ |
545 | | |
546 | | /// \brief Emit the bytes in \p Data into the output. |
547 | | /// |
548 | | /// This is used to implement assembler directives such as .byte, .ascii, |
549 | | /// etc. |
550 | | virtual void EmitBytes(StringRef Data); |
551 | | |
552 | | /// Functionally identical to EmitBytes. When emitting textual assembly, this |
553 | | /// method uses .byte directives instead of .ascii or .asciz for readability. |
554 | | virtual void EmitBinaryData(StringRef Data); |
555 | | |
556 | | /// \brief Emit the expression \p Value into the output as a native |
557 | | /// integer of the given \p Size bytes. |
558 | | /// |
559 | | /// This is used to implement assembler directives such as .word, .quad, |
560 | | /// etc. |
561 | | /// |
562 | | /// \param Value - The value to emit. |
563 | | /// \param Size - The size of the integer (in bytes) to emit. This must |
564 | | /// match a native machine width. |
565 | | /// \param Loc - The location of the expression for error reporting. |
566 | | virtual void EmitValueImpl(const MCExpr *Value, unsigned Size, |
567 | | SMLoc Loc = SMLoc()); |
568 | | |
569 | | void EmitValue(const MCExpr *Value, unsigned Size, SMLoc Loc = SMLoc()); |
570 | | |
571 | | /// \brief Special case of EmitValue that avoids the client having |
572 | | /// to pass in a MCExpr for constant integers. |
573 | | virtual void EmitIntValue(uint64_t Value, unsigned Size); |
574 | | |
575 | | virtual void EmitULEB128Value(const MCExpr *Value); |
576 | | |
577 | | virtual void EmitSLEB128Value(const MCExpr *Value); |
578 | | |
579 | | /// \brief Special case of EmitULEB128Value that avoids the client having to |
580 | | /// pass in a MCExpr for constant integers. |
581 | | void EmitULEB128IntValue(uint64_t Value); |
582 | | |
583 | | /// \brief Like EmitULEB128Value but pads the output to specific number of |
584 | | /// bytes. |
585 | | void EmitPaddedULEB128IntValue(uint64_t Value, unsigned PadTo); |
586 | | |
587 | | /// \brief Special case of EmitSLEB128Value that avoids the client having to |
588 | | /// pass in a MCExpr for constant integers. |
589 | | void EmitSLEB128IntValue(int64_t Value); |
590 | | |
591 | | /// \brief Special case of EmitValue that avoids the client having to pass in |
592 | | /// a MCExpr for MCSymbols. |
593 | | void EmitSymbolValue(const MCSymbol *Sym, unsigned Size, |
594 | | bool IsSectionRelative = false); |
595 | | |
596 | | /// \brief Emit the expression \p Value into the output as a dtprel |
597 | | /// (64-bit DTP relative) value. |
598 | | /// |
599 | | /// This is used to implement assembler directives such as .dtpreldword on |
600 | | /// targets that support them. |
601 | | virtual void EmitDTPRel64Value(const MCExpr *Value); |
602 | | |
603 | | /// \brief Emit the expression \p Value into the output as a dtprel |
604 | | /// (32-bit DTP relative) value. |
605 | | /// |
606 | | /// This is used to implement assembler directives such as .dtprelword on |
607 | | /// targets that support them. |
608 | | virtual void EmitDTPRel32Value(const MCExpr *Value); |
609 | | |
610 | | /// \brief Emit the expression \p Value into the output as a tprel |
611 | | /// (64-bit TP relative) value. |
612 | | /// |
613 | | /// This is used to implement assembler directives such as .tpreldword on |
614 | | /// targets that support them. |
615 | | virtual void EmitTPRel64Value(const MCExpr *Value); |
616 | | |
617 | | /// \brief Emit the expression \p Value into the output as a tprel |
618 | | /// (32-bit TP relative) value. |
619 | | /// |
620 | | /// This is used to implement assembler directives such as .tprelword on |
621 | | /// targets that support them. |
622 | | virtual void EmitTPRel32Value(const MCExpr *Value); |
623 | | |
624 | | /// \brief Emit the expression \p Value into the output as a gprel64 (64-bit |
625 | | /// GP relative) value. |
626 | | /// |
627 | | /// This is used to implement assembler directives such as .gpdword on |
628 | | /// targets that support them. |
629 | | virtual void EmitGPRel64Value(const MCExpr *Value); |
630 | | |
631 | | /// \brief Emit the expression \p Value into the output as a gprel32 (32-bit |
632 | | /// GP relative) value. |
633 | | /// |
634 | | /// This is used to implement assembler directives such as .gprel32 on |
635 | | /// targets that support them. |
636 | | virtual void EmitGPRel32Value(const MCExpr *Value); |
637 | | |
638 | | /// \brief Emit NumBytes bytes worth of the value specified by FillValue. |
639 | | /// This implements directives such as '.space'. |
640 | | virtual void emitFill(uint64_t NumBytes, uint8_t FillValue); |
641 | | |
642 | | /// \brief Emit \p Size bytes worth of the value specified by \p FillValue. |
643 | | /// |
644 | | /// This is used to implement assembler directives such as .space or .skip. |
645 | | /// |
646 | | /// \param NumBytes - The number of bytes to emit. |
647 | | /// \param FillValue - The value to use when filling bytes. |
648 | | /// \param Loc - The location of the expression for error reporting. |
649 | | virtual void emitFill(const MCExpr &NumBytes, uint64_t FillValue, |
650 | | SMLoc Loc = SMLoc()); |
651 | | |
652 | | /// \brief Emit \p NumValues copies of \p Size bytes. Each \p Size bytes is |
653 | | /// taken from the lowest order 4 bytes of \p Expr expression. |
654 | | /// |
655 | | /// This is used to implement assembler directives such as .fill. |
656 | | /// |
657 | | /// \param NumValues - The number of copies of \p Size bytes to emit. |
658 | | /// \param Size - The size (in bytes) of each repeated value. |
659 | | /// \param Expr - The expression from which \p Size bytes are used. |
660 | | virtual void emitFill(uint64_t NumValues, int64_t Size, int64_t Expr); |
661 | | virtual void emitFill(const MCExpr &NumValues, int64_t Size, int64_t Expr, |
662 | | SMLoc Loc = SMLoc()); |
663 | | |
664 | | /// \brief Emit NumBytes worth of zeros. |
665 | | /// This function properly handles data in virtual sections. |
666 | | void EmitZeros(uint64_t NumBytes); |
667 | | |
668 | | /// \brief Emit some number of copies of \p Value until the byte alignment \p |
669 | | /// ByteAlignment is reached. |
670 | | /// |
671 | | /// If the number of bytes need to emit for the alignment is not a multiple |
672 | | /// of \p ValueSize, then the contents of the emitted fill bytes is |
673 | | /// undefined. |
674 | | /// |
675 | | /// This used to implement the .align assembler directive. |
676 | | /// |
677 | | /// \param ByteAlignment - The alignment to reach. This must be a power of |
678 | | /// two on some targets. |
679 | | /// \param Value - The value to use when filling bytes. |
680 | | /// \param ValueSize - The size of the integer (in bytes) to emit for |
681 | | /// \p Value. This must match a native machine width. |
682 | | /// \param MaxBytesToEmit - The maximum numbers of bytes to emit, or 0. If |
683 | | /// the alignment cannot be reached in this many bytes, no bytes are |
684 | | /// emitted. |
685 | | virtual void EmitValueToAlignment(unsigned ByteAlignment, int64_t Value = 0, |
686 | | unsigned ValueSize = 1, |
687 | | unsigned MaxBytesToEmit = 0); |
688 | | |
689 | | /// \brief Emit nops until the byte alignment \p ByteAlignment is reached. |
690 | | /// |
691 | | /// This used to align code where the alignment bytes may be executed. This |
692 | | /// can emit different bytes for different sizes to optimize execution. |
693 | | /// |
694 | | /// \param ByteAlignment - The alignment to reach. This must be a power of |
695 | | /// two on some targets. |
696 | | /// \param MaxBytesToEmit - The maximum numbers of bytes to emit, or 0. If |
697 | | /// the alignment cannot be reached in this many bytes, no bytes are |
698 | | /// emitted. |
699 | | virtual void EmitCodeAlignment(unsigned ByteAlignment, |
700 | | unsigned MaxBytesToEmit = 0); |
701 | | |
702 | | /// \brief Emit some number of copies of \p Value until the byte offset \p |
703 | | /// Offset is reached. |
704 | | /// |
705 | | /// This is used to implement assembler directives such as .org. |
706 | | /// |
707 | | /// \param Offset - The offset to reach. This may be an expression, but the |
708 | | /// expression must be associated with the current section. |
709 | | /// \param Value - The value to use when filling bytes. |
710 | | virtual void emitValueToOffset(const MCExpr *Offset, unsigned char Value, |
711 | | SMLoc Loc); |
712 | | |
713 | | /// @} |
714 | | |
715 | | /// \brief Switch to a new logical file. This is used to implement the '.file |
716 | | /// "foo.c"' assembler directive. |
717 | | virtual void EmitFileDirective(StringRef Filename); |
718 | | |
719 | | /// \brief Emit the "identifiers" directive. This implements the |
720 | | /// '.ident "version foo"' assembler directive. |
721 | 3 | virtual void EmitIdent(StringRef IdentString) {} |
722 | | |
723 | | /// \brief Associate a filename with a specified logical file number. This |
724 | | /// implements the DWARF2 '.file 4 "foo.c"' assembler directive. |
725 | | virtual unsigned EmitDwarfFileDirective(unsigned FileNo, StringRef Directory, |
726 | | StringRef Filename, |
727 | | unsigned CUID = 0); |
728 | | |
729 | | /// \brief This implements the DWARF2 '.loc fileno lineno ...' assembler |
730 | | /// directive. |
731 | | virtual void EmitDwarfLocDirective(unsigned FileNo, unsigned Line, |
732 | | unsigned Column, unsigned Flags, |
733 | | unsigned Isa, unsigned Discriminator, |
734 | | StringRef FileName); |
735 | | |
736 | | /// Associate a filename with a specified logical file number, and also |
737 | | /// specify that file's checksum information. This implements the '.cv_file 4 |
738 | | /// "foo.c"' assembler directive. Returns true on success. |
739 | | virtual bool EmitCVFileDirective(unsigned FileNo, StringRef Filename, |
740 | | ArrayRef<uint8_t> Checksum, |
741 | | unsigned ChecksumKind); |
742 | | |
743 | | /// \brief Introduces a function id for use with .cv_loc. |
744 | | virtual bool EmitCVFuncIdDirective(unsigned FunctionId); |
745 | | |
746 | | /// \brief Introduces an inline call site id for use with .cv_loc. Includes |
747 | | /// extra information for inline line table generation. |
748 | | virtual bool EmitCVInlineSiteIdDirective(unsigned FunctionId, unsigned IAFunc, |
749 | | unsigned IAFile, unsigned IALine, |
750 | | unsigned IACol, SMLoc Loc); |
751 | | |
752 | | /// \brief This implements the CodeView '.cv_loc' assembler directive. |
753 | | virtual void EmitCVLocDirective(unsigned FunctionId, unsigned FileNo, |
754 | | unsigned Line, unsigned Column, |
755 | | bool PrologueEnd, bool IsStmt, |
756 | | StringRef FileName, SMLoc Loc); |
757 | | |
758 | | /// \brief This implements the CodeView '.cv_linetable' assembler directive. |
759 | | virtual void EmitCVLinetableDirective(unsigned FunctionId, |
760 | | const MCSymbol *FnStart, |
761 | | const MCSymbol *FnEnd); |
762 | | |
763 | | /// \brief This implements the CodeView '.cv_inline_linetable' assembler |
764 | | /// directive. |
765 | | virtual void EmitCVInlineLinetableDirective(unsigned PrimaryFunctionId, |
766 | | unsigned SourceFileId, |
767 | | unsigned SourceLineNum, |
768 | | const MCSymbol *FnStartSym, |
769 | | const MCSymbol *FnEndSym); |
770 | | |
771 | | /// \brief This implements the CodeView '.cv_def_range' assembler |
772 | | /// directive. |
773 | | virtual void EmitCVDefRangeDirective( |
774 | | ArrayRef<std::pair<const MCSymbol *, const MCSymbol *>> Ranges, |
775 | | StringRef FixedSizePortion); |
776 | | |
777 | | /// \brief This implements the CodeView '.cv_stringtable' assembler directive. |
778 | 0 | virtual void EmitCVStringTableDirective() {} |
779 | | |
780 | | /// \brief This implements the CodeView '.cv_filechecksums' assembler directive. |
781 | 0 | virtual void EmitCVFileChecksumsDirective() {} |
782 | | |
783 | | /// This implements the CodeView '.cv_filechecksumoffset' assembler |
784 | | /// directive. |
785 | 0 | virtual void EmitCVFileChecksumOffsetDirective(unsigned FileNo) {} |
786 | | |
787 | | /// Emit the absolute difference between two symbols. |
788 | | /// |
789 | | /// \pre Offset of \c Hi is greater than the offset \c Lo. |
790 | | virtual void emitAbsoluteSymbolDiff(const MCSymbol *Hi, const MCSymbol *Lo, |
791 | | unsigned Size); |
792 | | |
793 | | virtual MCSymbol *getDwarfLineTableSymbol(unsigned CUID); |
794 | | virtual void EmitCFISections(bool EH, bool Debug); |
795 | | void EmitCFIStartProc(bool IsSimple); |
796 | | void EmitCFIEndProc(); |
797 | | virtual void EmitCFIDefCfa(int64_t Register, int64_t Offset); |
798 | | virtual void EmitCFIDefCfaOffset(int64_t Offset); |
799 | | virtual void EmitCFIDefCfaRegister(int64_t Register); |
800 | | virtual void EmitCFIOffset(int64_t Register, int64_t Offset); |
801 | | virtual void EmitCFIPersonality(const MCSymbol *Sym, unsigned Encoding); |
802 | | virtual void EmitCFILsda(const MCSymbol *Sym, unsigned Encoding); |
803 | | virtual void EmitCFIRememberState(); |
804 | | virtual void EmitCFIRestoreState(); |
805 | | virtual void EmitCFISameValue(int64_t Register); |
806 | | virtual void EmitCFIRestore(int64_t Register); |
807 | | virtual void EmitCFIRelOffset(int64_t Register, int64_t Offset); |
808 | | virtual void EmitCFIAdjustCfaOffset(int64_t Adjustment); |
809 | | virtual void EmitCFIEscape(StringRef Values); |
810 | | virtual void EmitCFIReturnColumn(int64_t Register); |
811 | | virtual void EmitCFIGnuArgsSize(int64_t Size); |
812 | | virtual void EmitCFISignalFrame(); |
813 | | virtual void EmitCFIUndefined(int64_t Register); |
814 | | virtual void EmitCFIRegister(int64_t Register1, int64_t Register2); |
815 | | virtual void EmitCFIWindowSave(); |
816 | | |
817 | | virtual void EmitWinCFIStartProc(const MCSymbol *Symbol); |
818 | | virtual void EmitWinCFIEndProc(); |
819 | | virtual void EmitWinCFIStartChained(); |
820 | | virtual void EmitWinCFIEndChained(); |
821 | | virtual void EmitWinCFIPushReg(unsigned Register); |
822 | | virtual void EmitWinCFISetFrame(unsigned Register, unsigned Offset); |
823 | | virtual void EmitWinCFIAllocStack(unsigned Size); |
824 | | virtual void EmitWinCFISaveReg(unsigned Register, unsigned Offset); |
825 | | virtual void EmitWinCFISaveXMM(unsigned Register, unsigned Offset); |
826 | | virtual void EmitWinCFIPushFrame(bool Code); |
827 | | virtual void EmitWinCFIEndProlog(); |
828 | | |
829 | | virtual void EmitWinEHHandler(const MCSymbol *Sym, bool Unwind, bool Except); |
830 | | virtual void EmitWinEHHandlerData(); |
831 | | |
832 | | /// Get the .pdata section used for the given section. Typically the given |
833 | | /// section is either the main .text section or some other COMDAT .text |
834 | | /// section, but it may be any section containing code. |
835 | | MCSection *getAssociatedPDataSection(const MCSection *TextSec); |
836 | | |
837 | | /// Get the .xdata section used for the given section. |
838 | | MCSection *getAssociatedXDataSection(const MCSection *TextSec); |
839 | | |
840 | | virtual void EmitSyntaxDirective(); |
841 | | |
842 | | /// \brief Emit a .reloc directive. |
843 | | /// Returns true if the relocation could not be emitted because Name is not |
844 | | /// known. |
845 | | virtual bool EmitRelocDirective(const MCExpr &Offset, StringRef Name, |
846 | 0 | const MCExpr *Expr, SMLoc Loc) { |
847 | 0 | return true; |
848 | 0 | } |
849 | | |
850 | | /// \brief Emit the given \p Instruction into the current section. |
851 | | /// PrintSchedInfo == true then schedul comment should be added to output |
852 | | virtual void EmitInstruction(const MCInst &Inst, const MCSubtargetInfo &STI, |
853 | | bool PrintSchedInfo = false); |
854 | | |
855 | | /// \brief Set the bundle alignment mode from now on in the section. |
856 | | /// The argument is the power of 2 to which the alignment is set. The |
857 | | /// value 0 means turn the bundle alignment off. |
858 | | virtual void EmitBundleAlignMode(unsigned AlignPow2); |
859 | | |
860 | | /// \brief The following instructions are a bundle-locked group. |
861 | | /// |
862 | | /// \param AlignToEnd - If true, the bundle-locked group will be aligned to |
863 | | /// the end of a bundle. |
864 | | virtual void EmitBundleLock(bool AlignToEnd); |
865 | | |
866 | | /// \brief Ends a bundle-locked group. |
867 | | virtual void EmitBundleUnlock(); |
868 | | |
869 | | /// \brief If this file is backed by a assembly streamer, this dumps the |
870 | | /// specified string in the output .s file. This capability is indicated by |
871 | | /// the hasRawTextSupport() predicate. By default this aborts. |
872 | | void EmitRawText(const Twine &String); |
873 | | |
874 | | /// \brief Streamer specific finalization. |
875 | | virtual void FinishImpl(); |
876 | | /// \brief Finish emission of machine code. |
877 | | void Finish(); |
878 | | |
879 | 5 | virtual bool mayHaveInstructions(MCSection &Sec) const { return true; } |
880 | | }; |
881 | | |
882 | | /// Create a dummy machine code streamer, which does nothing. This is useful for |
883 | | /// timing the assembler front end. |
884 | | MCStreamer *createNullStreamer(MCContext &Ctx); |
885 | | |
886 | | /// Create a machine code streamer which will print out assembly for the native |
887 | | /// target, suitable for compiling with a native assembler. |
888 | | /// |
889 | | /// \param InstPrint - If given, the instruction printer to use. If not given |
890 | | /// the MCInst representation will be printed. This method takes ownership of |
891 | | /// InstPrint. |
892 | | /// |
893 | | /// \param CE - If given, a code emitter to use to show the instruction |
894 | | /// encoding inline with the assembly. This method takes ownership of \p CE. |
895 | | /// |
896 | | /// \param TAB - If given, a target asm backend to use to show the fixup |
897 | | /// information in conjunction with encoding information. This method takes |
898 | | /// ownership of \p TAB. |
899 | | /// |
900 | | /// \param ShowInst - Whether to show the MCInst representation inline with |
901 | | /// the assembly. |
902 | | MCStreamer *createAsmStreamer(MCContext &Ctx, |
903 | | std::unique_ptr<formatted_raw_ostream> OS, |
904 | | bool isVerboseAsm, bool useDwarfDirectory, |
905 | | MCInstPrinter *InstPrint, MCCodeEmitter *CE, |
906 | | MCAsmBackend *TAB, bool ShowInst); |
907 | | |
908 | | } // end namespace llvm |
909 | | |
910 | | #endif // LLVM_MC_MCSTREAMER_H |