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