MCStreamer.h 44 KB

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