MCStreamer.h 46 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154
  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/ARMTargetParser.h"
  34. #include "llvm/Support/TargetParser.h"
  35. #include "llvm/Support/VersionTuple.h"
  36. #include <cassert>
  37. #include <cstdint>
  38. #include <memory>
  39. #include <string>
  40. #include <utility>
  41. #include <vector>
  42. namespace llvm {
  43. class AssemblerConstantPools;
  44. class MCAsmBackend;
  45. class MCContext;
  46. struct MCDwarfFrameInfo;
  47. class MCExpr;
  48. class MCInst;
  49. class MCInstPrinter;
  50. class MCRegister;
  51. class MCSection;
  52. class MCStreamer;
  53. class MCSymbolRefExpr;
  54. class MCSubtargetInfo;
  55. class raw_ostream;
  56. class Twine;
  57. namespace codeview {
  58. struct DefRangeRegisterRelHeader;
  59. struct DefRangeSubfieldRegisterHeader;
  60. struct DefRangeRegisterHeader;
  61. struct DefRangeFramePointerRelHeader;
  62. }
  63. using MCSectionSubPair = std::pair<MCSection *, const MCExpr *>;
  64. /// Target specific streamer interface. This is used so that targets can
  65. /// implement support for target specific assembly directives.
  66. ///
  67. /// If target foo wants to use this, it should implement 3 classes:
  68. /// * FooTargetStreamer : public MCTargetStreamer
  69. /// * FooTargetAsmStreamer : public FooTargetStreamer
  70. /// * FooTargetELFStreamer : public FooTargetStreamer
  71. ///
  72. /// FooTargetStreamer should have a pure virtual method for each directive. For
  73. /// example, for a ".bar symbol_name" directive, it should have
  74. /// virtual emitBar(const MCSymbol &Symbol) = 0;
  75. ///
  76. /// The FooTargetAsmStreamer and FooTargetELFStreamer classes implement the
  77. /// method. The assembly streamer just prints ".bar symbol_name". The object
  78. /// streamer does whatever is needed to implement .bar in the object file.
  79. ///
  80. /// In the assembly printer and parser the target streamer can be used by
  81. /// calling getTargetStreamer and casting it to FooTargetStreamer:
  82. ///
  83. /// MCTargetStreamer &TS = OutStreamer.getTargetStreamer();
  84. /// FooTargetStreamer &ATS = static_cast<FooTargetStreamer &>(TS);
  85. ///
  86. /// The base classes FooTargetAsmStreamer and FooTargetELFStreamer should
  87. /// *never* be treated differently. Callers should always talk to a
  88. /// FooTargetStreamer.
  89. class MCTargetStreamer {
  90. protected:
  91. MCStreamer &Streamer;
  92. public:
  93. MCTargetStreamer(MCStreamer &S);
  94. virtual ~MCTargetStreamer();
  95. MCStreamer &getStreamer() { return Streamer; }
  96. // Allow a target to add behavior to the EmitLabel of MCStreamer.
  97. virtual void emitLabel(MCSymbol *Symbol);
  98. // Allow a target to add behavior to the emitAssignment of MCStreamer.
  99. virtual void emitAssignment(MCSymbol *Symbol, const MCExpr *Value);
  100. virtual void prettyPrintAsm(MCInstPrinter &InstPrinter, uint64_t Address,
  101. const MCInst &Inst, const MCSubtargetInfo &STI,
  102. raw_ostream &OS);
  103. virtual void emitDwarfFileDirective(StringRef Directive);
  104. /// Update streamer for a new active section.
  105. ///
  106. /// This is called by PopSection and SwitchSection, if the current
  107. /// section changes.
  108. virtual void changeSection(const MCSection *CurSection, MCSection *Section,
  109. const MCExpr *SubSection, raw_ostream &OS);
  110. virtual void emitValue(const MCExpr *Value);
  111. /// Emit the bytes in \p Data into the output.
  112. ///
  113. /// This is used to emit bytes in \p Data as sequence of .byte directives.
  114. virtual void emitRawBytes(StringRef Data);
  115. virtual void emitConstantPools();
  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 emitConstantPools() 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 implement 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 programmatic 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. /// separated 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. /// Retrieve 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, const MCSubtargetInfo &STI);
  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. virtual void emitDarwinTargetVariantBuildVersion(unsigned Platform,
  410. unsigned Major,
  411. unsigned Minor,
  412. unsigned Update,
  413. VersionTuple SDKVersion) {}
  414. void emitVersionForTarget(const Triple &Target,
  415. const VersionTuple &SDKVersion,
  416. const Triple *DarwinTargetVariantTriple,
  417. const VersionTuple &DarwinTargetVariantSDKVersion);
  418. /// Note in the output that the specified \p Func is a Thumb mode
  419. /// function (ARM target only).
  420. virtual void emitThumbFunc(MCSymbol *Func);
  421. /// Emit an assignment of \p Value to \p Symbol.
  422. ///
  423. /// This corresponds to an assembler statement such as:
  424. /// symbol = value
  425. ///
  426. /// The assignment generates no code, but has the side effect of binding the
  427. /// value in the current context. For the assembly streamer, this prints the
  428. /// binding into the .s file.
  429. ///
  430. /// \param Symbol - The symbol being assigned to.
  431. /// \param Value - The value for the symbol.
  432. virtual void emitAssignment(MCSymbol *Symbol, const MCExpr *Value);
  433. /// Emit an assignment of \p Value to \p Symbol, but only if \p Value is also
  434. /// emitted.
  435. virtual void emitConditionalAssignment(MCSymbol *Symbol, const MCExpr *Value);
  436. /// Emit an weak reference from \p Alias to \p Symbol.
  437. ///
  438. /// This corresponds to an assembler statement such as:
  439. /// .weakref alias, symbol
  440. ///
  441. /// \param Alias - The alias that is being created.
  442. /// \param Symbol - The symbol being aliased.
  443. virtual void emitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol);
  444. /// Add the given \p Attribute to \p Symbol.
  445. virtual bool emitSymbolAttribute(MCSymbol *Symbol,
  446. MCSymbolAttr Attribute) = 0;
  447. /// Set the \p DescValue for the \p Symbol.
  448. ///
  449. /// \param Symbol - The symbol to have its n_desc field set.
  450. /// \param DescValue - The value to set into the n_desc field.
  451. virtual void emitSymbolDesc(MCSymbol *Symbol, unsigned DescValue);
  452. /// Start emitting COFF symbol definition
  453. ///
  454. /// \param Symbol - The symbol to have its External & Type fields set.
  455. virtual void BeginCOFFSymbolDef(const MCSymbol *Symbol);
  456. /// Emit the storage class of the symbol.
  457. ///
  458. /// \param StorageClass - The storage class the symbol should have.
  459. virtual void EmitCOFFSymbolStorageClass(int StorageClass);
  460. /// Emit the type of the symbol.
  461. ///
  462. /// \param Type - A COFF type identifier (see COFF::SymbolType in X86COFF.h)
  463. virtual void EmitCOFFSymbolType(int Type);
  464. /// Marks the end of the symbol definition.
  465. virtual void EndCOFFSymbolDef();
  466. virtual void EmitCOFFSafeSEH(MCSymbol const *Symbol);
  467. /// Emits the symbol table index of a Symbol into the current section.
  468. virtual void EmitCOFFSymbolIndex(MCSymbol const *Symbol);
  469. /// Emits a COFF section index.
  470. ///
  471. /// \param Symbol - Symbol the section number relocation should point to.
  472. virtual void EmitCOFFSectionIndex(MCSymbol const *Symbol);
  473. /// Emits a COFF section relative relocation.
  474. ///
  475. /// \param Symbol - Symbol the section relative relocation should point to.
  476. virtual void EmitCOFFSecRel32(MCSymbol const *Symbol, uint64_t Offset);
  477. /// Emits a COFF image relative relocation.
  478. ///
  479. /// \param Symbol - Symbol the image relative relocation should point to.
  480. virtual void EmitCOFFImgRel32(MCSymbol const *Symbol, int64_t Offset);
  481. /// Emits an lcomm directive with XCOFF csect information.
  482. ///
  483. /// \param LabelSym - Label on the block of storage.
  484. /// \param Size - The size of the block of storage.
  485. /// \param CsectSym - Csect name for the block of storage.
  486. /// \param ByteAlignment - The alignment of the symbol in bytes. Must be a
  487. /// power of 2.
  488. virtual void emitXCOFFLocalCommonSymbol(MCSymbol *LabelSym, uint64_t Size,
  489. MCSymbol *CsectSym,
  490. unsigned ByteAlignment);
  491. /// Emit a symbol's linkage and visibility with a linkage directive for XCOFF.
  492. ///
  493. /// \param Symbol - The symbol to emit.
  494. /// \param Linkage - The linkage of the symbol to emit.
  495. /// \param Visibility - The visibility of the symbol to emit or MCSA_Invalid
  496. /// if the symbol does not have an explicit visibility.
  497. virtual void emitXCOFFSymbolLinkageWithVisibility(MCSymbol *Symbol,
  498. MCSymbolAttr Linkage,
  499. MCSymbolAttr Visibility);
  500. /// Emit a XCOFF .rename directive which creates a synonym for an illegal or
  501. /// undesirable name.
  502. ///
  503. /// \param Name - The name used internally in the assembly for references to
  504. /// the symbol.
  505. /// \param Rename - The value to which the Name parameter is
  506. /// changed at the end of assembly.
  507. virtual void emitXCOFFRenameDirective(const MCSymbol *Name, StringRef Rename);
  508. /// Emit an ELF .size directive.
  509. ///
  510. /// This corresponds to an assembler statement such as:
  511. /// .size symbol, expression
  512. virtual void emitELFSize(MCSymbol *Symbol, const MCExpr *Value);
  513. /// Emit an ELF .symver directive.
  514. ///
  515. /// This corresponds to an assembler statement such as:
  516. /// .symver _start, foo@@SOME_VERSION
  517. virtual void emitELFSymverDirective(const MCSymbol *OriginalSym,
  518. StringRef Name, bool KeepOriginalSym);
  519. /// Emit a Linker Optimization Hint (LOH) directive.
  520. /// \param Args - Arguments of the LOH.
  521. virtual void emitLOHDirective(MCLOHType Kind, const MCLOHArgs &Args) {}
  522. /// Emit a .gnu_attribute directive.
  523. virtual void emitGNUAttribute(unsigned Tag, unsigned Value) {}
  524. /// Emit a common symbol.
  525. ///
  526. /// \param Symbol - The common symbol to emit.
  527. /// \param Size - The size of the common symbol.
  528. /// \param ByteAlignment - The alignment of the symbol if
  529. /// non-zero. This must be a power of 2.
  530. virtual void emitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
  531. unsigned ByteAlignment) = 0;
  532. /// Emit a local common (.lcomm) symbol.
  533. ///
  534. /// \param Symbol - The common symbol to emit.
  535. /// \param Size - The size of the common symbol.
  536. /// \param ByteAlignment - The alignment of the common symbol in bytes.
  537. virtual void emitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size,
  538. unsigned ByteAlignment);
  539. /// Emit the zerofill section and an optional symbol.
  540. ///
  541. /// \param Section - The zerofill section to create and or to put the symbol
  542. /// \param Symbol - The zerofill symbol to emit, if non-NULL.
  543. /// \param Size - The size of the zerofill symbol.
  544. /// \param ByteAlignment - The alignment of the zerofill symbol if
  545. /// non-zero. This must be a power of 2 on some targets.
  546. virtual void emitZerofill(MCSection *Section, MCSymbol *Symbol = nullptr,
  547. uint64_t Size = 0, unsigned ByteAlignment = 0,
  548. SMLoc Loc = SMLoc()) = 0;
  549. /// Emit a thread local bss (.tbss) symbol.
  550. ///
  551. /// \param Section - The thread local common section.
  552. /// \param Symbol - The thread local common symbol to emit.
  553. /// \param Size - The size of the symbol.
  554. /// \param ByteAlignment - The alignment of the thread local common symbol
  555. /// if non-zero. This must be a power of 2 on some targets.
  556. virtual void emitTBSSSymbol(MCSection *Section, MCSymbol *Symbol,
  557. uint64_t Size, unsigned ByteAlignment = 0);
  558. /// @}
  559. /// \name Generating Data
  560. /// @{
  561. /// Emit the bytes in \p Data into the output.
  562. ///
  563. /// This is used to implement assembler directives such as .byte, .ascii,
  564. /// etc.
  565. virtual void emitBytes(StringRef Data);
  566. /// Functionally identical to EmitBytes. When emitting textual assembly, this
  567. /// method uses .byte directives instead of .ascii or .asciz for readability.
  568. virtual void emitBinaryData(StringRef Data);
  569. /// Emit the expression \p Value into the output as a native
  570. /// integer of the given \p Size bytes.
  571. ///
  572. /// This is used to implement assembler directives such as .word, .quad,
  573. /// etc.
  574. ///
  575. /// \param Value - The value to emit.
  576. /// \param Size - The size of the integer (in bytes) to emit. This must
  577. /// match a native machine width.
  578. /// \param Loc - The location of the expression for error reporting.
  579. virtual void emitValueImpl(const MCExpr *Value, unsigned Size,
  580. SMLoc Loc = SMLoc());
  581. void emitValue(const MCExpr *Value, unsigned Size, SMLoc Loc = SMLoc());
  582. /// Special case of EmitValue that avoids the client having
  583. /// to pass in a MCExpr for constant integers.
  584. virtual void emitIntValue(uint64_t Value, unsigned Size);
  585. virtual void emitIntValue(APInt Value);
  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.
  589. virtual void emitIntValueInHex(uint64_t Value, unsigned Size) {
  590. emitIntValue(Value, Size);
  591. }
  592. void emitInt8(uint64_t Value) { emitIntValue(Value, 1); }
  593. void emitInt16(uint64_t Value) { emitIntValue(Value, 2); }
  594. void emitInt32(uint64_t Value) { emitIntValue(Value, 4); }
  595. void emitInt64(uint64_t Value) { emitIntValue(Value, 8); }
  596. /// Special case of EmitValue that avoids the client having to pass
  597. /// in a MCExpr for constant integers & prints in Hex format for certain
  598. /// modes, pads the field with leading zeros to Size width
  599. virtual void emitIntValueInHexWithPadding(uint64_t Value, unsigned Size) {
  600. emitIntValue(Value, Size);
  601. }
  602. virtual void emitULEB128Value(const MCExpr *Value);
  603. virtual void emitSLEB128Value(const MCExpr *Value);
  604. /// Special case of EmitULEB128Value that avoids the client having to
  605. /// pass in a MCExpr for constant integers.
  606. void emitULEB128IntValue(uint64_t Value, unsigned PadTo = 0);
  607. /// Special case of EmitSLEB128Value that avoids the client having to
  608. /// pass in a MCExpr for constant integers.
  609. void emitSLEB128IntValue(int64_t Value);
  610. /// Special case of EmitValue that avoids the client having to pass in
  611. /// a MCExpr for MCSymbols.
  612. void emitSymbolValue(const MCSymbol *Sym, unsigned Size,
  613. bool IsSectionRelative = false);
  614. /// Emit the expression \p Value into the output as a dtprel
  615. /// (64-bit DTP relative) value.
  616. ///
  617. /// This is used to implement assembler directives such as .dtpreldword on
  618. /// targets that support them.
  619. virtual void emitDTPRel64Value(const MCExpr *Value);
  620. /// Emit the expression \p Value into the output as a dtprel
  621. /// (32-bit DTP relative) value.
  622. ///
  623. /// This is used to implement assembler directives such as .dtprelword on
  624. /// targets that support them.
  625. virtual void emitDTPRel32Value(const MCExpr *Value);
  626. /// Emit the expression \p Value into the output as a tprel
  627. /// (64-bit TP relative) value.
  628. ///
  629. /// This is used to implement assembler directives such as .tpreldword on
  630. /// targets that support them.
  631. virtual void emitTPRel64Value(const MCExpr *Value);
  632. /// Emit the expression \p Value into the output as a tprel
  633. /// (32-bit TP relative) value.
  634. ///
  635. /// This is used to implement assembler directives such as .tprelword on
  636. /// targets that support them.
  637. virtual void emitTPRel32Value(const MCExpr *Value);
  638. /// Emit the expression \p Value into the output as a gprel64 (64-bit
  639. /// GP relative) value.
  640. ///
  641. /// This is used to implement assembler directives such as .gpdword on
  642. /// targets that support them.
  643. virtual void emitGPRel64Value(const MCExpr *Value);
  644. /// Emit the expression \p Value into the output as a gprel32 (32-bit
  645. /// GP relative) value.
  646. ///
  647. /// This is used to implement assembler directives such as .gprel32 on
  648. /// targets that support them.
  649. virtual void emitGPRel32Value(const MCExpr *Value);
  650. /// Emit NumBytes bytes worth of the value specified by FillValue.
  651. /// This implements directives such as '.space'.
  652. void emitFill(uint64_t NumBytes, uint8_t FillValue);
  653. /// Emit \p Size bytes worth of the value specified by \p FillValue.
  654. ///
  655. /// This is used to implement assembler directives such as .space or .skip.
  656. ///
  657. /// \param NumBytes - The number of bytes to emit.
  658. /// \param FillValue - The value to use when filling bytes.
  659. /// \param Loc - The location of the expression for error reporting.
  660. virtual void emitFill(const MCExpr &NumBytes, uint64_t FillValue,
  661. SMLoc Loc = SMLoc());
  662. /// Emit \p NumValues copies of \p Size bytes. Each \p Size bytes is
  663. /// taken from the lowest order 4 bytes of \p Expr expression.
  664. ///
  665. /// This is used to implement assembler directives such as .fill.
  666. ///
  667. /// \param NumValues - The number of copies of \p Size bytes to emit.
  668. /// \param Size - The size (in bytes) of each repeated value.
  669. /// \param Expr - The expression from which \p Size bytes are used.
  670. virtual void emitFill(const MCExpr &NumValues, int64_t Size, int64_t Expr,
  671. SMLoc Loc = SMLoc());
  672. virtual void emitNops(int64_t NumBytes, int64_t ControlledNopLength,
  673. SMLoc Loc, const MCSubtargetInfo& STI);
  674. /// Emit NumBytes worth of zeros.
  675. /// This function properly handles data in virtual sections.
  676. void emitZeros(uint64_t NumBytes);
  677. /// Emit some number of copies of \p Value until the byte alignment \p
  678. /// ByteAlignment is reached.
  679. ///
  680. /// If the number of bytes need to emit for the alignment is not a multiple
  681. /// of \p ValueSize, then the contents of the emitted fill bytes is
  682. /// undefined.
  683. ///
  684. /// This used to implement the .align assembler directive.
  685. ///
  686. /// \param ByteAlignment - The alignment to reach. This must be a power of
  687. /// two on some targets.
  688. /// \param Value - The value to use when filling bytes.
  689. /// \param ValueSize - The size of the integer (in bytes) to emit for
  690. /// \p Value. This must match a native machine width.
  691. /// \param MaxBytesToEmit - The maximum numbers of bytes to emit, or 0. If
  692. /// the alignment cannot be reached in this many bytes, no bytes are
  693. /// emitted.
  694. virtual void emitValueToAlignment(unsigned ByteAlignment, int64_t Value = 0,
  695. unsigned ValueSize = 1,
  696. unsigned MaxBytesToEmit = 0);
  697. /// Emit nops until the byte alignment \p ByteAlignment is reached.
  698. ///
  699. /// This used to align code where the alignment bytes may be executed. This
  700. /// can emit different bytes for different sizes to optimize execution.
  701. ///
  702. /// \param ByteAlignment - The alignment to reach. This must be a power of
  703. /// two on some targets.
  704. /// \param STI - The MCSubtargetInfo in operation when padding is emitted.
  705. /// \param MaxBytesToEmit - The maximum numbers of bytes to emit, or 0. If
  706. /// the alignment cannot be reached in this many bytes, no bytes are
  707. /// emitted.
  708. virtual void emitCodeAlignment(unsigned ByteAlignment,
  709. const MCSubtargetInfo *STI,
  710. unsigned MaxBytesToEmit = 0);
  711. /// Emit some number of copies of \p Value until the byte offset \p
  712. /// Offset is reached.
  713. ///
  714. /// This is used to implement assembler directives such as .org.
  715. ///
  716. /// \param Offset - The offset to reach. This may be an expression, but the
  717. /// expression must be associated with the current section.
  718. /// \param Value - The value to use when filling bytes.
  719. virtual void emitValueToOffset(const MCExpr *Offset, unsigned char Value,
  720. SMLoc Loc);
  721. /// @}
  722. /// Switch to a new logical file. This is used to implement the '.file
  723. /// "foo.c"' assembler directive.
  724. virtual void emitFileDirective(StringRef Filename);
  725. /// Emit ".file assembler diretive with additioal info.
  726. virtual void emitFileDirective(StringRef Filename, StringRef CompilerVerion,
  727. StringRef TimeStamp, StringRef Description);
  728. /// Emit the "identifiers" directive. This implements the
  729. /// '.ident "version foo"' assembler directive.
  730. virtual void emitIdent(StringRef IdentString) {}
  731. /// Associate a filename with a specified logical file number. This
  732. /// implements the DWARF2 '.file 4 "foo.c"' assembler directive.
  733. unsigned emitDwarfFileDirective(unsigned FileNo, StringRef Directory,
  734. StringRef Filename,
  735. Optional<MD5::MD5Result> Checksum = None,
  736. Optional<StringRef> Source = None,
  737. unsigned CUID = 0) {
  738. return cantFail(
  739. tryEmitDwarfFileDirective(FileNo, Directory, Filename, Checksum,
  740. Source, CUID));
  741. }
  742. /// Associate a filename with a specified logical file number.
  743. /// Also associate a directory, optional checksum, and optional source
  744. /// text with the logical file. This implements the DWARF2
  745. /// '.file 4 "dir/foo.c"' assembler directive, and the DWARF5
  746. /// '.file 4 "dir/foo.c" md5 "..." source "..."' assembler directive.
  747. virtual Expected<unsigned> tryEmitDwarfFileDirective(
  748. unsigned FileNo, StringRef Directory, StringRef Filename,
  749. Optional<MD5::MD5Result> Checksum = None, Optional<StringRef> Source = None,
  750. unsigned CUID = 0);
  751. /// Specify the "root" file of the compilation, using the ".file 0" extension.
  752. virtual void emitDwarfFile0Directive(StringRef Directory, StringRef Filename,
  753. Optional<MD5::MD5Result> Checksum,
  754. Optional<StringRef> Source,
  755. unsigned CUID = 0);
  756. virtual void emitCFIBKeyFrame();
  757. /// This implements the DWARF2 '.loc fileno lineno ...' assembler
  758. /// directive.
  759. virtual void emitDwarfLocDirective(unsigned FileNo, unsigned Line,
  760. unsigned Column, unsigned Flags,
  761. unsigned Isa, unsigned Discriminator,
  762. StringRef FileName);
  763. /// Associate a filename with a specified logical file number, and also
  764. /// specify that file's checksum information. This implements the '.cv_file 4
  765. /// "foo.c"' assembler directive. Returns true on success.
  766. virtual bool EmitCVFileDirective(unsigned FileNo, StringRef Filename,
  767. ArrayRef<uint8_t> Checksum,
  768. unsigned ChecksumKind);
  769. /// Introduces a function id for use with .cv_loc.
  770. virtual bool EmitCVFuncIdDirective(unsigned FunctionId);
  771. /// Introduces an inline call site id for use with .cv_loc. Includes
  772. /// extra information for inline line table generation.
  773. virtual bool EmitCVInlineSiteIdDirective(unsigned FunctionId, unsigned IAFunc,
  774. unsigned IAFile, unsigned IALine,
  775. unsigned IACol, SMLoc Loc);
  776. /// This implements the CodeView '.cv_loc' assembler directive.
  777. virtual void emitCVLocDirective(unsigned FunctionId, unsigned FileNo,
  778. unsigned Line, unsigned Column,
  779. bool PrologueEnd, bool IsStmt,
  780. StringRef FileName, SMLoc Loc);
  781. /// This implements the CodeView '.cv_linetable' assembler directive.
  782. virtual void emitCVLinetableDirective(unsigned FunctionId,
  783. const MCSymbol *FnStart,
  784. const MCSymbol *FnEnd);
  785. /// This implements the CodeView '.cv_inline_linetable' assembler
  786. /// directive.
  787. virtual void emitCVInlineLinetableDirective(unsigned PrimaryFunctionId,
  788. unsigned SourceFileId,
  789. unsigned SourceLineNum,
  790. const MCSymbol *FnStartSym,
  791. const MCSymbol *FnEndSym);
  792. /// This implements the CodeView '.cv_def_range' assembler
  793. /// directive.
  794. virtual void emitCVDefRangeDirective(
  795. ArrayRef<std::pair<const MCSymbol *, const MCSymbol *>> Ranges,
  796. StringRef FixedSizePortion);
  797. virtual void emitCVDefRangeDirective(
  798. ArrayRef<std::pair<const MCSymbol *, const MCSymbol *>> Ranges,
  799. codeview::DefRangeRegisterRelHeader DRHdr);
  800. virtual void emitCVDefRangeDirective(
  801. ArrayRef<std::pair<const MCSymbol *, const MCSymbol *>> Ranges,
  802. codeview::DefRangeSubfieldRegisterHeader DRHdr);
  803. virtual void emitCVDefRangeDirective(
  804. ArrayRef<std::pair<const MCSymbol *, const MCSymbol *>> Ranges,
  805. codeview::DefRangeRegisterHeader DRHdr);
  806. virtual void emitCVDefRangeDirective(
  807. ArrayRef<std::pair<const MCSymbol *, const MCSymbol *>> Ranges,
  808. codeview::DefRangeFramePointerRelHeader DRHdr);
  809. /// This implements the CodeView '.cv_stringtable' assembler directive.
  810. virtual void emitCVStringTableDirective() {}
  811. /// This implements the CodeView '.cv_filechecksums' assembler directive.
  812. virtual void emitCVFileChecksumsDirective() {}
  813. /// This implements the CodeView '.cv_filechecksumoffset' assembler
  814. /// directive.
  815. virtual void emitCVFileChecksumOffsetDirective(unsigned FileNo) {}
  816. /// This implements the CodeView '.cv_fpo_data' assembler directive.
  817. virtual void EmitCVFPOData(const MCSymbol *ProcSym, SMLoc Loc = {}) {}
  818. /// Emit the absolute difference between two symbols.
  819. ///
  820. /// \pre Offset of \c Hi is greater than the offset \c Lo.
  821. virtual void emitAbsoluteSymbolDiff(const MCSymbol *Hi, const MCSymbol *Lo,
  822. unsigned Size);
  823. /// Emit the absolute difference between two symbols encoded with ULEB128.
  824. virtual void emitAbsoluteSymbolDiffAsULEB128(const MCSymbol *Hi,
  825. const MCSymbol *Lo);
  826. virtual MCSymbol *getDwarfLineTableSymbol(unsigned CUID);
  827. virtual void emitCFISections(bool EH, bool Debug);
  828. void emitCFIStartProc(bool IsSimple, SMLoc Loc = SMLoc());
  829. void emitCFIEndProc();
  830. virtual void emitCFIDefCfa(int64_t Register, int64_t Offset);
  831. virtual void emitCFIDefCfaOffset(int64_t Offset);
  832. virtual void emitCFIDefCfaRegister(int64_t Register);
  833. virtual void emitCFILLVMDefAspaceCfa(int64_t Register, int64_t Offset,
  834. int64_t AddressSpace);
  835. virtual void emitCFIOffset(int64_t Register, int64_t Offset);
  836. virtual void emitCFIPersonality(const MCSymbol *Sym, unsigned Encoding);
  837. virtual void emitCFILsda(const MCSymbol *Sym, unsigned Encoding);
  838. virtual void emitCFIRememberState();
  839. virtual void emitCFIRestoreState();
  840. virtual void emitCFISameValue(int64_t Register);
  841. virtual void emitCFIRestore(int64_t Register);
  842. virtual void emitCFIRelOffset(int64_t Register, int64_t Offset);
  843. virtual void emitCFIAdjustCfaOffset(int64_t Adjustment);
  844. virtual void emitCFIEscape(StringRef Values);
  845. virtual void emitCFIReturnColumn(int64_t Register);
  846. virtual void emitCFIGnuArgsSize(int64_t Size);
  847. virtual void emitCFISignalFrame();
  848. virtual void emitCFIUndefined(int64_t Register);
  849. virtual void emitCFIRegister(int64_t Register1, int64_t Register2);
  850. virtual void emitCFIWindowSave();
  851. virtual void emitCFINegateRAState();
  852. virtual void EmitWinCFIStartProc(const MCSymbol *Symbol, SMLoc Loc = SMLoc());
  853. virtual void EmitWinCFIEndProc(SMLoc Loc = SMLoc());
  854. /// This is used on platforms, such as Windows on ARM64, that require function
  855. /// or funclet sizes to be emitted in .xdata before the End marker is emitted
  856. /// for the frame. We cannot use the End marker, as it is not set at the
  857. /// point of emitting .xdata, in order to indicate that the frame is active.
  858. virtual void EmitWinCFIFuncletOrFuncEnd(SMLoc Loc = SMLoc());
  859. virtual void EmitWinCFIStartChained(SMLoc Loc = SMLoc());
  860. virtual void EmitWinCFIEndChained(SMLoc Loc = SMLoc());
  861. virtual void EmitWinCFIPushReg(MCRegister Register, SMLoc Loc = SMLoc());
  862. virtual void EmitWinCFISetFrame(MCRegister Register, unsigned Offset,
  863. SMLoc Loc = SMLoc());
  864. virtual void EmitWinCFIAllocStack(unsigned Size, SMLoc Loc = SMLoc());
  865. virtual void EmitWinCFISaveReg(MCRegister Register, unsigned Offset,
  866. SMLoc Loc = SMLoc());
  867. virtual void EmitWinCFISaveXMM(MCRegister Register, unsigned Offset,
  868. SMLoc Loc = SMLoc());
  869. virtual void EmitWinCFIPushFrame(bool Code, SMLoc Loc = SMLoc());
  870. virtual void EmitWinCFIEndProlog(SMLoc Loc = SMLoc());
  871. virtual void EmitWinEHHandler(const MCSymbol *Sym, bool Unwind, bool Except,
  872. SMLoc Loc = SMLoc());
  873. virtual void EmitWinEHHandlerData(SMLoc Loc = SMLoc());
  874. virtual void emitCGProfileEntry(const MCSymbolRefExpr *From,
  875. const MCSymbolRefExpr *To, uint64_t Count);
  876. /// Get the .pdata section used for the given section. Typically the given
  877. /// section is either the main .text section or some other COMDAT .text
  878. /// section, but it may be any section containing code.
  879. MCSection *getAssociatedPDataSection(const MCSection *TextSec);
  880. /// Get the .xdata section used for the given section.
  881. MCSection *getAssociatedXDataSection(const MCSection *TextSec);
  882. virtual void emitSyntaxDirective();
  883. /// Record a relocation described by the .reloc directive. Return None if
  884. /// succeeded. Otherwise, return a pair (Name is invalid, error message).
  885. virtual Optional<std::pair<bool, std::string>>
  886. emitRelocDirective(const MCExpr &Offset, StringRef Name, const MCExpr *Expr,
  887. SMLoc Loc, const MCSubtargetInfo &STI) {
  888. return None;
  889. }
  890. virtual void emitAddrsig() {}
  891. virtual void emitAddrsigSym(const MCSymbol *Sym) {}
  892. /// Emit the given \p Instruction into the current section.
  893. virtual void emitInstruction(const MCInst &Inst, const MCSubtargetInfo &STI);
  894. /// Emit the a pseudo probe into the current section.
  895. virtual void emitPseudoProbe(uint64_t Guid, uint64_t Index, uint64_t Type,
  896. uint64_t Attr,
  897. const MCPseudoProbeInlineStack &InlineStack);
  898. /// Set the bundle alignment mode from now on in the section.
  899. /// The argument is the power of 2 to which the alignment is set. The
  900. /// value 0 means turn the bundle alignment off.
  901. virtual void emitBundleAlignMode(unsigned AlignPow2);
  902. /// The following instructions are a bundle-locked group.
  903. ///
  904. /// \param AlignToEnd - If true, the bundle-locked group will be aligned to
  905. /// the end of a bundle.
  906. virtual void emitBundleLock(bool AlignToEnd);
  907. /// Ends a bundle-locked group.
  908. virtual void emitBundleUnlock();
  909. /// If this file is backed by a assembly streamer, this dumps the
  910. /// specified string in the output .s file. This capability is indicated by
  911. /// the hasRawTextSupport() predicate. By default this aborts.
  912. void emitRawText(const Twine &String);
  913. /// Streamer specific finalization.
  914. virtual void finishImpl();
  915. /// Finish emission of machine code.
  916. void Finish(SMLoc EndLoc = SMLoc());
  917. virtual bool mayHaveInstructions(MCSection &Sec) const { return true; }
  918. /// Emit a special value of 0xffffffff if producing 64-bit debugging info.
  919. void maybeEmitDwarf64Mark();
  920. /// Emit a unit length field. The actual format, DWARF32 or DWARF64, is chosen
  921. /// according to the settings.
  922. virtual void emitDwarfUnitLength(uint64_t Length, const Twine &Comment);
  923. /// Emit a unit length field. The actual format, DWARF32 or DWARF64, is chosen
  924. /// according to the settings.
  925. /// Return the end symbol generated inside, the caller needs to emit it.
  926. virtual MCSymbol *emitDwarfUnitLength(const Twine &Prefix,
  927. const Twine &Comment);
  928. /// Emit the debug line start label.
  929. virtual void emitDwarfLineStartLabel(MCSymbol *StartSym);
  930. /// Emit the debug line end entry.
  931. virtual void emitDwarfLineEndEntry(MCSection *Section, MCSymbol *LastLabel) {}
  932. /// If targets does not support representing debug line section by .loc/.file
  933. /// directives in assembly output, we need to populate debug line section with
  934. /// raw debug line contents.
  935. virtual void emitDwarfAdvanceLineAddr(int64_t LineDelta,
  936. const MCSymbol *LastLabel,
  937. const MCSymbol *Label,
  938. unsigned PointerSize) {}
  939. /// Do finalization for the streamer at the end of a section.
  940. virtual void doFinalizationAtSectionEnd(MCSection *Section) {}
  941. };
  942. /// Create a dummy machine code streamer, which does nothing. This is useful for
  943. /// timing the assembler front end.
  944. MCStreamer *createNullStreamer(MCContext &Ctx);
  945. } // end namespace llvm
  946. #endif // LLVM_MC_MCSTREAMER_H
  947. #ifdef __GNUC__
  948. #pragma GCC diagnostic pop
  949. #endif