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