MCStreamer.h 45 KB

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