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