Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

707 lines
28 KiB

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