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