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/SmallVector.h" 19 #include "llvm/MC/MCAssembler.h" 20 #include "llvm/MC/MCDirectives.h" 21 #include "llvm/MC/MCDwarf.h" 22 #include "llvm/MC/MCWin64EH.h" 23 #include "llvm/Support/DataTypes.h" 24 #include <string> 25 26 namespace llvm { 27 class MCAsmBackend; 28 class MCCodeEmitter; 29 class MCContext; 30 class MCExpr; 31 class MCInst; 32 class MCInstPrinter; 33 class MCSection; 34 class MCSymbol; 35 class StringRef; 36 class Twine; 37 class raw_ostream; 38 class formatted_raw_ostream; 39 40 /// MCStreamer - Streaming machine code generation interface. This interface 41 /// is intended to provide a programatic interface that is very similar to the 42 /// level that an assembler .s file provides. It has callbacks to emit bytes, 43 /// handle directives, etc. The implementation of this interface retains 44 /// state to know what the current section is etc. 45 /// 46 /// There are multiple implementations of this interface: one for writing out 47 /// a .s file, and implementations that write out .o files of various formats. 48 /// 49 class MCStreamer { 50 public: 51 enum StreamerKind { 52 SK_AsmStreamer, 53 SK_NullStreamer, 54 SK_RecordStreamer, 55 56 // MCObjectStreamer subclasses. 57 SK_ELFStreamer, 58 SK_ARMELFStreamer, 59 SK_MachOStreamer, 60 SK_PureStreamer, 61 SK_MipsELFStreamer, 62 SK_WinCOFFStreamer 63 }; 64 65 private: 66 const StreamerKind Kind; 67 MCContext &Context; 68 69 MCStreamer(const MCStreamer&) LLVM_DELETED_FUNCTION; 70 MCStreamer &operator=(const MCStreamer&) LLVM_DELETED_FUNCTION; 71 72 bool EmitEHFrame; 73 bool EmitDebugFrame; 74 75 std::vector<MCDwarfFrameInfo> FrameInfos; 76 MCDwarfFrameInfo *getCurrentFrameInfo(); 77 MCSymbol *EmitCFICommon(); 78 void EnsureValidFrame(); 79 80 std::vector<MCWin64EHUnwindInfo *> W64UnwindInfos; 81 MCWin64EHUnwindInfo *CurrentW64UnwindInfo; 82 void setCurrentW64UnwindInfo(MCWin64EHUnwindInfo *Frame); 83 void EnsureValidW64UnwindInfo(); 84 85 MCSymbol* LastSymbol; 86 87 /// SectionStack - This is stack of current and previous section 88 /// values saved by PushSection. 89 SmallVector<std::pair<const MCSection *, 90 const MCSection *>, 4> SectionStack; 91 92 bool AutoInitSections; 93 94 protected: 95 MCStreamer(StreamerKind Kind, MCContext &Ctx); 96 97 const MCExpr *BuildSymbolDiff(MCContext &Context, const MCSymbol *A, 98 const MCSymbol *B); 99 100 const MCExpr *ForceExpAbs(const MCExpr* Expr); 101 102 void RecordProcStart(MCDwarfFrameInfo &Frame); 103 virtual void EmitCFIStartProcImpl(MCDwarfFrameInfo &Frame); 104 void RecordProcEnd(MCDwarfFrameInfo &Frame); 105 virtual void EmitCFIEndProcImpl(MCDwarfFrameInfo &CurFrame); 106 void EmitFrames(bool usingCFI); 107 getCurrentW64UnwindInfo()108 MCWin64EHUnwindInfo *getCurrentW64UnwindInfo(){return CurrentW64UnwindInfo;} 109 void EmitW64Tables(); 110 111 public: 112 virtual ~MCStreamer(); 113 getKind()114 StreamerKind getKind() const { return Kind; } 115 116 /// State management 117 /// 118 virtual void reset(); 119 getContext()120 MCContext &getContext() const { return Context; } 121 getNumFrameInfos()122 unsigned getNumFrameInfos() { 123 return FrameInfos.size(); 124 } 125 getFrameInfo(unsigned i)126 const MCDwarfFrameInfo &getFrameInfo(unsigned i) { 127 return FrameInfos[i]; 128 } 129 getFrameInfos()130 ArrayRef<MCDwarfFrameInfo> getFrameInfos() { 131 return FrameInfos; 132 } 133 getNumW64UnwindInfos()134 unsigned getNumW64UnwindInfos() { 135 return W64UnwindInfos.size(); 136 } 137 getW64UnwindInfo(unsigned i)138 MCWin64EHUnwindInfo &getW64UnwindInfo(unsigned i) { 139 return *W64UnwindInfos[i]; 140 } 141 142 /// @name Assembly File Formatting. 143 /// @{ 144 145 /// isVerboseAsm - Return true if this streamer supports verbose assembly 146 /// and if it is enabled. isVerboseAsm()147 virtual bool isVerboseAsm() const { return false; } 148 149 /// hasRawTextSupport - Return true if this asm streamer supports emitting 150 /// unformatted text to the .s file with EmitRawText. hasRawTextSupport()151 virtual bool hasRawTextSupport() const { return false; } 152 153 /// AddComment - Add a comment that can be emitted to the generated .s 154 /// file if applicable as a QoI issue to make the output of the compiler 155 /// more readable. This only affects the MCAsmStreamer, and only when 156 /// verbose assembly output is enabled. 157 /// 158 /// If the comment includes embedded \n's, they will each get the comment 159 /// prefix as appropriate. The added comment should not end with a \n. AddComment(const Twine & T)160 virtual void AddComment(const Twine &T) {} 161 162 /// GetCommentOS - Return a raw_ostream that comments can be written to. 163 /// Unlike AddComment, you are required to terminate comments with \n if you 164 /// use this method. 165 virtual raw_ostream &GetCommentOS(); 166 167 /// AddBlankLine - Emit a blank line to a .s file to pretty it up. AddBlankLine()168 virtual void AddBlankLine() {} 169 170 /// @} 171 172 /// @name Symbol & Section Management 173 /// @{ 174 175 /// getCurrentSection - Return the current section that the streamer is 176 /// emitting code to. getCurrentSection()177 const MCSection *getCurrentSection() const { 178 if (!SectionStack.empty()) 179 return SectionStack.back().first; 180 return NULL; 181 } 182 183 /// getPreviousSection - Return the previous section that the streamer is 184 /// emitting code to. getPreviousSection()185 const MCSection *getPreviousSection() const { 186 if (!SectionStack.empty()) 187 return SectionStack.back().second; 188 return NULL; 189 } 190 191 /// ChangeSection - Update streamer for a new active section. 192 /// 193 /// This is called by PopSection and SwitchSection, if the current 194 /// section changes. 195 virtual void ChangeSection(const MCSection *) = 0; 196 197 /// pushSection - Save the current and previous section on the 198 /// section stack. PushSection()199 void PushSection() { 200 SectionStack.push_back(std::make_pair(getCurrentSection(), 201 getPreviousSection())); 202 } 203 204 /// popSection - Restore the current and previous section from 205 /// the section stack. Calls ChangeSection as needed. 206 /// 207 /// Returns false if the stack was empty. PopSection()208 bool PopSection() { 209 if (SectionStack.size() <= 1) 210 return false; 211 const MCSection *oldSection = SectionStack.pop_back_val().first; 212 const MCSection *curSection = SectionStack.back().first; 213 214 if (oldSection != curSection) 215 ChangeSection(curSection); 216 return true; 217 } 218 219 /// SwitchSection - Set the current section where code is being emitted to 220 /// @p Section. This is required to update CurSection. 221 /// 222 /// This corresponds to assembler directives like .section, .text, etc. SwitchSection(const MCSection * Section)223 void SwitchSection(const MCSection *Section) { 224 assert(Section && "Cannot switch to a null section!"); 225 const MCSection *curSection = SectionStack.back().first; 226 SectionStack.back().second = curSection; 227 if (Section != curSection) { 228 SectionStack.back().first = Section; 229 ChangeSection(Section); 230 } 231 } 232 233 /// SwitchSectionNoChange - Set the current section where code is being 234 /// emitted to @p Section. This is required to update CurSection. This 235 /// version does not call ChangeSection. SwitchSectionNoChange(const MCSection * Section)236 void SwitchSectionNoChange(const MCSection *Section) { 237 assert(Section && "Cannot switch to a null section!"); 238 const MCSection *curSection = SectionStack.back().first; 239 SectionStack.back().second = curSection; 240 if (Section != curSection) 241 SectionStack.back().first = Section; 242 } 243 244 /// Initialize the streamer. InitStreamer()245 void InitStreamer() { 246 if (AutoInitSections) 247 InitSections(); 248 } 249 250 /// Tell this MCStreamer to call InitSections upon initialization. setAutoInitSections(bool AutoInitSections)251 void setAutoInitSections(bool AutoInitSections) { 252 this->AutoInitSections = AutoInitSections; 253 } 254 255 /// InitSections - Create the default sections and set the initial one. 256 virtual void InitSections() = 0; 257 258 /// InitToTextSection - Create a text section and switch the streamer to it. 259 virtual void InitToTextSection() = 0; 260 261 /// EmitLabel - Emit a label for @p Symbol into the current section. 262 /// 263 /// This corresponds to an assembler statement such as: 264 /// foo: 265 /// 266 /// @param Symbol - The symbol to emit. A given symbol should only be 267 /// emitted as a label once, and symbols emitted as a label should never be 268 /// used in an assignment. 269 virtual void EmitLabel(MCSymbol *Symbol); 270 271 virtual void EmitDebugLabel(MCSymbol *Symbol); 272 273 virtual void EmitEHSymAttributes(const MCSymbol *Symbol, 274 MCSymbol *EHSymbol); 275 276 /// EmitAssemblerFlag - Note in the output the specified @p Flag. 277 virtual void EmitAssemblerFlag(MCAssemblerFlag Flag) = 0; 278 279 /// EmitLinkerOptions - Emit the given list @p Options of strings as linker 280 /// options into the output. EmitLinkerOptions(ArrayRef<std::string> Kind)281 virtual void EmitLinkerOptions(ArrayRef<std::string> Kind) {} 282 283 /// EmitDataRegion - Note in the output the specified region @p Kind. EmitDataRegion(MCDataRegionType Kind)284 virtual void EmitDataRegion(MCDataRegionType Kind) {} 285 286 /// EmitThumbFunc - Note in the output that the specified @p Func is 287 /// a Thumb mode function (ARM target only). 288 virtual void EmitThumbFunc(MCSymbol *Func) = 0; 289 290 /// getOrCreateSymbolData - Get symbol data for given symbol. 291 virtual MCSymbolData &getOrCreateSymbolData(MCSymbol *Symbol); 292 293 /// EmitAssignment - Emit an assignment of @p Value to @p Symbol. 294 /// 295 /// This corresponds to an assembler statement such as: 296 /// symbol = value 297 /// 298 /// The assignment generates no code, but has the side effect of binding the 299 /// value in the current context. For the assembly streamer, this prints the 300 /// binding into the .s file. 301 /// 302 /// @param Symbol - The symbol being assigned to. 303 /// @param Value - The value for the symbol. 304 virtual void EmitAssignment(MCSymbol *Symbol, const MCExpr *Value) = 0; 305 306 /// EmitWeakReference - Emit an weak reference from @p Alias to @p Symbol. 307 /// 308 /// This corresponds to an assembler statement such as: 309 /// .weakref alias, symbol 310 /// 311 /// @param Alias - The alias that is being created. 312 /// @param Symbol - The symbol being aliased. 313 virtual void EmitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol) = 0; 314 315 /// EmitSymbolAttribute - Add the given @p Attribute to @p Symbol. 316 virtual void EmitSymbolAttribute(MCSymbol *Symbol, 317 MCSymbolAttr Attribute) = 0; 318 319 /// EmitSymbolDesc - Set the @p DescValue for the @p Symbol. 320 /// 321 /// @param Symbol - The symbol to have its n_desc field set. 322 /// @param DescValue - The value to set into the n_desc field. 323 virtual void EmitSymbolDesc(MCSymbol *Symbol, unsigned DescValue) = 0; 324 325 /// BeginCOFFSymbolDef - Start emitting COFF symbol definition 326 /// 327 /// @param Symbol - The symbol to have its External & Type fields set. 328 virtual void BeginCOFFSymbolDef(const MCSymbol *Symbol) = 0; 329 330 /// EmitCOFFSymbolStorageClass - Emit the storage class of the symbol. 331 /// 332 /// @param StorageClass - The storage class the symbol should have. 333 virtual void EmitCOFFSymbolStorageClass(int StorageClass) = 0; 334 335 /// EmitCOFFSymbolType - Emit the type of the symbol. 336 /// 337 /// @param Type - A COFF type identifier (see COFF::SymbolType in X86COFF.h) 338 virtual void EmitCOFFSymbolType(int Type) = 0; 339 340 /// EndCOFFSymbolDef - Marks the end of the symbol definition. 341 virtual void EndCOFFSymbolDef() = 0; 342 343 /// EmitCOFFSecRel32 - Emits a COFF section relative relocation. 344 /// 345 /// @param Symbol - Symbol the section relative realocation should point to. 346 virtual void EmitCOFFSecRel32(MCSymbol const *Symbol); 347 348 /// EmitELFSize - Emit an ELF .size directive. 349 /// 350 /// This corresponds to an assembler statement such as: 351 /// .size symbol, expression 352 /// 353 virtual void EmitELFSize(MCSymbol *Symbol, const MCExpr *Value) = 0; 354 355 /// EmitCommonSymbol - Emit a common symbol. 356 /// 357 /// @param Symbol - The common symbol to emit. 358 /// @param Size - The size of the common symbol. 359 /// @param ByteAlignment - The alignment of the symbol if 360 /// non-zero. This must be a power of 2. 361 virtual void EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size, 362 unsigned ByteAlignment) = 0; 363 364 /// EmitLocalCommonSymbol - Emit a local common (.lcomm) symbol. 365 /// 366 /// @param Symbol - The common symbol to emit. 367 /// @param Size - The size of the common symbol. 368 /// @param ByteAlignment - The alignment of the common symbol in bytes. 369 virtual void EmitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size, 370 unsigned ByteAlignment) = 0; 371 372 /// EmitZerofill - Emit the zerofill section and an optional symbol. 373 /// 374 /// @param Section - The zerofill section to create and or to put the symbol 375 /// @param Symbol - The zerofill symbol to emit, if non-NULL. 376 /// @param Size - The size of the zerofill symbol. 377 /// @param ByteAlignment - The alignment of the zerofill symbol if 378 /// non-zero. This must be a power of 2 on some targets. 379 virtual void EmitZerofill(const MCSection *Section, MCSymbol *Symbol = 0, 380 uint64_t Size = 0,unsigned ByteAlignment = 0) = 0; 381 382 /// EmitTBSSSymbol - Emit a thread local bss (.tbss) symbol. 383 /// 384 /// @param Section - The thread local common section. 385 /// @param Symbol - The thread local common symbol to emit. 386 /// @param Size - The size of the symbol. 387 /// @param ByteAlignment - The alignment of the thread local common symbol 388 /// if non-zero. This must be a power of 2 on some targets. 389 virtual void EmitTBSSSymbol(const MCSection *Section, MCSymbol *Symbol, 390 uint64_t Size, unsigned ByteAlignment = 0) = 0; 391 392 /// @} 393 /// @name Generating Data 394 /// @{ 395 396 /// EmitBytes - Emit the bytes in \p Data into the output. 397 /// 398 /// This is used to implement assembler directives such as .byte, .ascii, 399 /// etc. 400 virtual void EmitBytes(StringRef Data, unsigned AddrSpace = 0) = 0; 401 402 /// EmitValue - Emit the expression @p Value into the output as a native 403 /// integer of the given @p Size bytes. 404 /// 405 /// This is used to implement assembler directives such as .word, .quad, 406 /// etc. 407 /// 408 /// @param Value - The value to emit. 409 /// @param Size - The size of the integer (in bytes) to emit. This must 410 /// match a native machine width. 411 virtual void EmitValueImpl(const MCExpr *Value, unsigned Size, 412 unsigned AddrSpace) = 0; 413 414 void EmitValue(const MCExpr *Value, unsigned Size, unsigned AddrSpace = 0); 415 416 /// EmitIntValue - Special case of EmitValue that avoids the client having 417 /// to pass in a MCExpr for constant integers. 418 virtual void EmitIntValue(uint64_t Value, unsigned Size, 419 unsigned AddrSpace = 0); 420 421 /// EmitAbsValue - Emit the Value, but try to avoid relocations. On MachO 422 /// this is done by producing 423 /// foo = value 424 /// .long foo 425 void EmitAbsValue(const MCExpr *Value, unsigned Size, 426 unsigned AddrSpace = 0); 427 428 virtual void EmitULEB128Value(const MCExpr *Value) = 0; 429 430 virtual void EmitSLEB128Value(const MCExpr *Value) = 0; 431 432 /// EmitULEB128Value - Special case of EmitULEB128Value that avoids the 433 /// client having to pass in a MCExpr for constant integers. 434 void EmitULEB128IntValue(uint64_t Value, unsigned Padding = 0, 435 unsigned AddrSpace = 0); 436 437 /// EmitSLEB128Value - Special case of EmitSLEB128Value that avoids the 438 /// client having to pass in a MCExpr for constant integers. 439 void EmitSLEB128IntValue(int64_t Value, unsigned AddrSpace = 0); 440 441 /// EmitSymbolValue - Special case of EmitValue that avoids the client 442 /// having to pass in a MCExpr for MCSymbols. 443 void EmitSymbolValue(const MCSymbol *Sym, unsigned Size, 444 unsigned AddrSpace = 0); 445 446 /// EmitGPRel64Value - Emit the expression @p Value into the output as a 447 /// gprel64 (64-bit GP relative) value. 448 /// 449 /// This is used to implement assembler directives such as .gpdword on 450 /// targets that support them. 451 virtual void EmitGPRel64Value(const MCExpr *Value); 452 453 /// EmitGPRel32Value - Emit the expression @p Value into the output as a 454 /// gprel32 (32-bit GP relative) value. 455 /// 456 /// This is used to implement assembler directives such as .gprel32 on 457 /// targets that support them. 458 virtual void EmitGPRel32Value(const MCExpr *Value); 459 460 /// EmitFill - Emit NumBytes bytes worth of the value specified by 461 /// FillValue. This implements directives such as '.space'. 462 virtual void EmitFill(uint64_t NumBytes, uint8_t FillValue, 463 unsigned AddrSpace = 0); 464 465 /// EmitZeros - Emit NumBytes worth of zeros. This is a convenience 466 /// function that just wraps EmitFill. 467 void EmitZeros(uint64_t NumBytes, unsigned AddrSpace = 0) { 468 EmitFill(NumBytes, 0, AddrSpace); 469 } 470 471 /// EmitValueToAlignment - Emit some number of copies of @p Value until 472 /// the byte alignment @p ByteAlignment is reached. 473 /// 474 /// If the number of bytes need to emit for the alignment is not a multiple 475 /// of @p ValueSize, then the contents of the emitted fill bytes is 476 /// undefined. 477 /// 478 /// This used to implement the .align assembler directive. 479 /// 480 /// @param ByteAlignment - The alignment to reach. This must be a power of 481 /// two on some targets. 482 /// @param Value - The value to use when filling bytes. 483 /// @param ValueSize - The size of the integer (in bytes) to emit for 484 /// @p Value. This must match a native machine width. 485 /// @param MaxBytesToEmit - The maximum numbers of bytes to emit, or 0. If 486 /// the alignment cannot be reached in this many bytes, no bytes are 487 /// emitted. 488 virtual void EmitValueToAlignment(unsigned ByteAlignment, int64_t Value = 0, 489 unsigned ValueSize = 1, 490 unsigned MaxBytesToEmit = 0) = 0; 491 492 /// EmitCodeAlignment - Emit nops until the byte alignment @p ByteAlignment 493 /// is reached. 494 /// 495 /// This used to align code where the alignment bytes may be executed. This 496 /// can emit different bytes for different sizes to optimize execution. 497 /// 498 /// @param ByteAlignment - The alignment to reach. This must be a power of 499 /// two on some targets. 500 /// @param MaxBytesToEmit - The maximum numbers of bytes to emit, or 0. If 501 /// the alignment cannot be reached in this many bytes, no bytes are 502 /// emitted. 503 virtual void EmitCodeAlignment(unsigned ByteAlignment, 504 unsigned MaxBytesToEmit = 0) = 0; 505 506 /// EmitValueToOffset - Emit some number of copies of @p Value until the 507 /// byte offset @p Offset is reached. 508 /// 509 /// This is used to implement assembler directives such as .org. 510 /// 511 /// @param Offset - The offset to reach. This may be an expression, but the 512 /// expression must be associated with the current section. 513 /// @param Value - The value to use when filling bytes. 514 /// @return false on success, true if the offset was invalid. 515 virtual bool EmitValueToOffset(const MCExpr *Offset, 516 unsigned char Value = 0) = 0; 517 518 /// @} 519 520 /// EmitFileDirective - Switch to a new logical file. This is used to 521 /// implement the '.file "foo.c"' assembler directive. 522 virtual void EmitFileDirective(StringRef Filename) = 0; 523 524 /// EmitDwarfFileDirective - Associate a filename with a specified logical 525 /// file number. This implements the DWARF2 '.file 4 "foo.c"' assembler 526 /// directive. 527 virtual bool EmitDwarfFileDirective(unsigned FileNo, StringRef Directory, 528 StringRef Filename, unsigned CUID = 0); 529 530 /// EmitDwarfLocDirective - This implements the DWARF2 531 // '.loc fileno lineno ...' assembler directive. 532 virtual void EmitDwarfLocDirective(unsigned FileNo, unsigned Line, 533 unsigned Column, unsigned Flags, 534 unsigned Isa, 535 unsigned Discriminator, 536 StringRef FileName); 537 538 virtual void EmitDwarfAdvanceLineAddr(int64_t LineDelta, 539 const MCSymbol *LastLabel, 540 const MCSymbol *Label, 541 unsigned PointerSize) = 0; 542 EmitDwarfAdvanceFrameAddr(const MCSymbol * LastLabel,const MCSymbol * Label)543 virtual void EmitDwarfAdvanceFrameAddr(const MCSymbol *LastLabel, 544 const MCSymbol *Label) { 545 } 546 547 void EmitDwarfSetLineAddr(int64_t LineDelta, const MCSymbol *Label, 548 int PointerSize); 549 550 virtual void EmitCompactUnwindEncoding(uint32_t CompactUnwindEncoding); 551 virtual void EmitCFISections(bool EH, bool Debug); 552 void EmitCFIStartProc(); 553 void EmitCFIEndProc(); 554 virtual void EmitCFIDefCfa(int64_t Register, int64_t Offset); 555 virtual void EmitCFIDefCfaOffset(int64_t Offset); 556 virtual void EmitCFIDefCfaRegister(int64_t Register); 557 virtual void EmitCFIOffset(int64_t Register, int64_t Offset); 558 virtual void EmitCFIPersonality(const MCSymbol *Sym, unsigned Encoding); 559 virtual void EmitCFILsda(const MCSymbol *Sym, unsigned Encoding); 560 virtual void EmitCFIRememberState(); 561 virtual void EmitCFIRestoreState(); 562 virtual void EmitCFISameValue(int64_t Register); 563 virtual void EmitCFIRestore(int64_t Register); 564 virtual void EmitCFIRelOffset(int64_t Register, int64_t Offset); 565 virtual void EmitCFIAdjustCfaOffset(int64_t Adjustment); 566 virtual void EmitCFIEscape(StringRef Values); 567 virtual void EmitCFISignalFrame(); 568 virtual void EmitCFIUndefined(int64_t Register); 569 virtual void EmitCFIRegister(int64_t Register1, int64_t Register2); 570 571 virtual void EmitWin64EHStartProc(const MCSymbol *Symbol); 572 virtual void EmitWin64EHEndProc(); 573 virtual void EmitWin64EHStartChained(); 574 virtual void EmitWin64EHEndChained(); 575 virtual void EmitWin64EHHandler(const MCSymbol *Sym, bool Unwind, 576 bool Except); 577 virtual void EmitWin64EHHandlerData(); 578 virtual void EmitWin64EHPushReg(unsigned Register); 579 virtual void EmitWin64EHSetFrame(unsigned Register, unsigned Offset); 580 virtual void EmitWin64EHAllocStack(unsigned Size); 581 virtual void EmitWin64EHSaveReg(unsigned Register, unsigned Offset); 582 virtual void EmitWin64EHSaveXMM(unsigned Register, unsigned Offset); 583 virtual void EmitWin64EHPushFrame(bool Code); 584 virtual void EmitWin64EHEndProlog(); 585 586 /// EmitInstruction - Emit the given @p Instruction into the current 587 /// section. 588 virtual void EmitInstruction(const MCInst &Inst) = 0; 589 590 /// \brief Set the bundle alignment mode from now on in the section. 591 /// The argument is the power of 2 to which the alignment is set. The 592 /// value 0 means turn the bundle alignment off. 593 virtual void EmitBundleAlignMode(unsigned AlignPow2) = 0; 594 595 /// \brief The following instructions are a bundle-locked group. 596 /// 597 /// \param AlignToEnd - If true, the bundle-locked group will be aligned to 598 /// the end of a bundle. 599 virtual void EmitBundleLock(bool AlignToEnd) = 0; 600 601 /// \brief Ends a bundle-locked group. 602 virtual void EmitBundleUnlock() = 0; 603 604 /// EmitRawText - If this file is backed by a assembly streamer, this dumps 605 /// the specified string in the output .s file. This capability is 606 /// indicated by the hasRawTextSupport() predicate. By default this aborts. 607 virtual void EmitRawText(StringRef String); 608 void EmitRawText(const Twine &String); 609 610 /// ARM-related methods. 611 /// FIXME: Eventually we should have some "target MC streamer" and move 612 /// these methods there. 613 virtual void EmitFnStart(); 614 virtual void EmitFnEnd(); 615 virtual void EmitCantUnwind(); 616 virtual void EmitPersonality(const MCSymbol *Personality); 617 virtual void EmitHandlerData(); 618 virtual void EmitSetFP(unsigned FpReg, unsigned SpReg, int64_t Offset = 0); 619 virtual void EmitPad(int64_t Offset); 620 virtual void EmitRegSave(const SmallVectorImpl<unsigned> &RegList, 621 bool isVector); 622 623 /// PPC-related methods. 624 /// FIXME: Eventually replace it with some "target MC streamer" and move 625 /// these methods there. 626 virtual void EmitTCEntry(const MCSymbol &S); 627 628 /// FinishImpl - Streamer specific finalization. 629 virtual void FinishImpl() = 0; 630 /// Finish - Finish emission of machine code. 631 void Finish(); 632 }; 633 634 /// createNullStreamer - Create a dummy machine code streamer, which does 635 /// nothing. This is useful for timing the assembler front end. 636 MCStreamer *createNullStreamer(MCContext &Ctx); 637 638 /// createAsmStreamer - Create a machine code streamer which will print out 639 /// assembly for the native target, suitable for compiling with a native 640 /// assembler. 641 /// 642 /// \param InstPrint - If given, the instruction printer to use. If not given 643 /// the MCInst representation will be printed. This method takes ownership of 644 /// InstPrint. 645 /// 646 /// \param CE - If given, a code emitter to use to show the instruction 647 /// encoding inline with the assembly. This method takes ownership of \p CE. 648 /// 649 /// \param TAB - If given, a target asm backend to use to show the fixup 650 /// information in conjunction with encoding information. This method takes 651 /// ownership of \p TAB. 652 /// 653 /// \param ShowInst - Whether to show the MCInst representation inline with 654 /// the assembly. 655 MCStreamer *createAsmStreamer(MCContext &Ctx, formatted_raw_ostream &OS, 656 bool isVerboseAsm, 657 bool useLoc, 658 bool useCFI, 659 bool useDwarfDirectory, 660 MCInstPrinter *InstPrint = 0, 661 MCCodeEmitter *CE = 0, 662 MCAsmBackend *TAB = 0, 663 bool ShowInst = false); 664 665 /// createMachOStreamer - Create a machine code streamer which will generate 666 /// Mach-O format object files. 667 /// 668 /// Takes ownership of \p TAB and \p CE. 669 MCStreamer *createMachOStreamer(MCContext &Ctx, MCAsmBackend &TAB, 670 raw_ostream &OS, MCCodeEmitter *CE, 671 bool RelaxAll = false); 672 673 /// createWinCOFFStreamer - Create a machine code streamer which will 674 /// generate Microsoft COFF format object files. 675 /// 676 /// Takes ownership of \p TAB and \p CE. 677 MCStreamer *createWinCOFFStreamer(MCContext &Ctx, 678 MCAsmBackend &TAB, 679 MCCodeEmitter &CE, raw_ostream &OS, 680 bool RelaxAll = false); 681 682 /// createELFStreamer - Create a machine code streamer which will generate 683 /// ELF format object files. 684 MCStreamer *createELFStreamer(MCContext &Ctx, MCAsmBackend &TAB, 685 raw_ostream &OS, MCCodeEmitter *CE, 686 bool RelaxAll, bool NoExecStack); 687 688 /// createPureStreamer - Create a machine code streamer which will generate 689 /// "pure" MC object files, for use with MC-JIT and testing tools. 690 /// 691 /// Takes ownership of \p TAB and \p CE. 692 MCStreamer *createPureStreamer(MCContext &Ctx, MCAsmBackend &TAB, 693 raw_ostream &OS, MCCodeEmitter *CE); 694 695 } // end namespace llvm 696 697 #endif 698