Daniel Dunbar | a11af53 | 2009-06-24 01:03:06 +0000 | [diff] [blame] | 1 | //===- lib/MC/MCAsmStreamer.cpp - Text Assembly Output --------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #include "llvm/MC/MCStreamer.h" |
Daniel Dunbar | 8c2eebe | 2009-08-31 08:08:38 +0000 | [diff] [blame] | 11 | #include "llvm/MC/MCAsmInfo.h" |
Daniel Dunbar | 4a0abd8 | 2009-08-27 00:51:57 +0000 | [diff] [blame] | 12 | #include "llvm/MC/MCCodeEmitter.h" |
Daniel Dunbar | a11af53 | 2009-06-24 01:03:06 +0000 | [diff] [blame] | 13 | #include "llvm/MC/MCContext.h" |
Daniel Dunbar | 8c2eebe | 2009-08-31 08:08:38 +0000 | [diff] [blame] | 14 | #include "llvm/MC/MCExpr.h" |
Daniel Dunbar | 2761fc4 | 2010-12-16 03:20:06 +0000 | [diff] [blame] | 15 | #include "llvm/MC/MCFixupKindInfo.h" |
Daniel Dunbar | abde298 | 2009-07-01 06:35:03 +0000 | [diff] [blame] | 16 | #include "llvm/MC/MCInst.h" |
Chris Lattner | 90edac0 | 2009-09-14 03:02:37 +0000 | [diff] [blame] | 17 | #include "llvm/MC/MCInstPrinter.h" |
Evan Cheng | 0e6a052 | 2011-07-18 20:57:22 +0000 | [diff] [blame^] | 18 | #include "llvm/MC/MCRegisterInfo.h" |
Chris Lattner | f9bdedd | 2009-08-10 18:15:01 +0000 | [diff] [blame] | 19 | #include "llvm/MC/MCSectionMachO.h" |
Daniel Dunbar | a11af53 | 2009-06-24 01:03:06 +0000 | [diff] [blame] | 20 | #include "llvm/MC/MCSymbol.h" |
Chris Lattner | 4c42a6d | 2010-03-19 05:48:53 +0000 | [diff] [blame] | 21 | #include "llvm/ADT/OwningPtr.h" |
Chris Lattner | 86e2211 | 2010-01-22 07:29:22 +0000 | [diff] [blame] | 22 | #include "llvm/ADT/SmallString.h" |
Bill Wendling | 916a94b | 2011-06-17 20:35:21 +0000 | [diff] [blame] | 23 | #include "llvm/ADT/StringExtras.h" |
Chris Lattner | 86e2211 | 2010-01-22 07:29:22 +0000 | [diff] [blame] | 24 | #include "llvm/ADT/Twine.h" |
Torok Edwin | c25e758 | 2009-07-11 20:10:48 +0000 | [diff] [blame] | 25 | #include "llvm/Support/ErrorHandling.h" |
Chris Lattner | 663c2d2 | 2009-08-19 06:12:02 +0000 | [diff] [blame] | 26 | #include "llvm/Support/MathExtras.h" |
Daniel Dunbar | 4a0abd8 | 2009-08-27 00:51:57 +0000 | [diff] [blame] | 27 | #include "llvm/Support/Format.h" |
Chris Lattner | 86e2211 | 2010-01-22 07:29:22 +0000 | [diff] [blame] | 28 | #include "llvm/Support/FormattedStream.h" |
Daniel Dunbar | 745dacc | 2010-12-16 03:05:59 +0000 | [diff] [blame] | 29 | #include "llvm/Target/TargetAsmBackend.h" |
Rafael Espindola | 89b9372 | 2010-12-10 07:39:47 +0000 | [diff] [blame] | 30 | #include "llvm/Target/TargetAsmInfo.h" |
Daniel Dunbar | 745dacc | 2010-12-16 03:05:59 +0000 | [diff] [blame] | 31 | #include "llvm/Target/TargetLoweringObjectFile.h" |
Nick Lewycky | 476b242 | 2010-12-19 20:43:38 +0000 | [diff] [blame] | 32 | #include <cctype> |
Daniel Dunbar | a11af53 | 2009-06-24 01:03:06 +0000 | [diff] [blame] | 33 | using namespace llvm; |
| 34 | |
| 35 | namespace { |
| 36 | |
Chris Lattner | 46a947d | 2009-08-17 04:17:34 +0000 | [diff] [blame] | 37 | class MCAsmStreamer : public MCStreamer { |
Bill Wendling | 916a94b | 2011-06-17 20:35:21 +0000 | [diff] [blame] | 38 | protected: |
Chris Lattner | 86e2211 | 2010-01-22 07:29:22 +0000 | [diff] [blame] | 39 | formatted_raw_ostream &OS; |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 40 | const MCAsmInfo &MAI; |
Bill Wendling | 916a94b | 2011-06-17 20:35:21 +0000 | [diff] [blame] | 41 | private: |
Chris Lattner | 4c42a6d | 2010-03-19 05:48:53 +0000 | [diff] [blame] | 42 | OwningPtr<MCInstPrinter> InstPrinter; |
Benjamin Kramer | 1abcd06 | 2010-07-29 17:48:06 +0000 | [diff] [blame] | 43 | OwningPtr<MCCodeEmitter> Emitter; |
Daniel Dunbar | 745dacc | 2010-12-16 03:05:59 +0000 | [diff] [blame] | 44 | OwningPtr<TargetAsmBackend> AsmBackend; |
Jim Grosbach | 00545e1 | 2010-09-22 18:16:55 +0000 | [diff] [blame] | 45 | |
Chris Lattner | 86e2211 | 2010-01-22 07:29:22 +0000 | [diff] [blame] | 46 | SmallString<128> CommentToEmit; |
Chris Lattner | d79d9dc | 2010-01-22 19:17:48 +0000 | [diff] [blame] | 47 | raw_svector_ostream CommentStream; |
Daniel Dunbar | 9dee8e3 | 2010-02-03 18:18:30 +0000 | [diff] [blame] | 48 | |
Daniel Dunbar | 9dee8e3 | 2010-02-03 18:18:30 +0000 | [diff] [blame] | 49 | unsigned IsVerboseAsm : 1; |
| 50 | unsigned ShowInst : 1; |
Rafael Espindola | 89b9372 | 2010-12-10 07:39:47 +0000 | [diff] [blame] | 51 | unsigned UseLoc : 1; |
Rafael Espindola | f1a5c7e | 2011-04-30 03:44:37 +0000 | [diff] [blame] | 52 | unsigned UseCFI : 1; |
Daniel Dunbar | 9dee8e3 | 2010-02-03 18:18:30 +0000 | [diff] [blame] | 53 | |
Rafael Espindola | 277abc8 | 2011-04-30 16:34:57 +0000 | [diff] [blame] | 54 | enum EHSymbolFlags { EHGlobal = 1, |
| 55 | EHWeakDefinition = 1 << 1, |
| 56 | EHPrivateExtern = 1 << 2 }; |
| 57 | DenseMap<const MCSymbol*, unsigned> FlagMap; |
| 58 | |
Rafael Espindola | 5d4918d | 2010-12-04 03:21:47 +0000 | [diff] [blame] | 59 | bool needsSet(const MCExpr *Value); |
| 60 | |
Rafael Espindola | 6e03294 | 2011-05-30 20:20:15 +0000 | [diff] [blame] | 61 | void EmitRegisterName(int64_t Register); |
| 62 | |
Chris Lattner | 46a947d | 2009-08-17 04:17:34 +0000 | [diff] [blame] | 63 | public: |
Chris Lattner | 86e2211 | 2010-01-22 07:29:22 +0000 | [diff] [blame] | 64 | MCAsmStreamer(MCContext &Context, formatted_raw_ostream &os, |
Rafael Espindola | f1a5c7e | 2011-04-30 03:44:37 +0000 | [diff] [blame] | 65 | bool isVerboseAsm, bool useLoc, bool useCFI, |
Daniel Dunbar | 745dacc | 2010-12-16 03:05:59 +0000 | [diff] [blame] | 66 | MCInstPrinter *printer, MCCodeEmitter *emitter, |
| 67 | TargetAsmBackend *asmbackend, |
| 68 | bool showInst) |
Chris Lattner | fdab14b | 2010-03-12 18:28:53 +0000 | [diff] [blame] | 69 | : MCStreamer(Context), OS(os), MAI(Context.getAsmInfo()), |
Daniel Dunbar | 745dacc | 2010-12-16 03:05:59 +0000 | [diff] [blame] | 70 | InstPrinter(printer), Emitter(emitter), AsmBackend(asmbackend), |
| 71 | CommentStream(CommentToEmit), IsVerboseAsm(isVerboseAsm), |
Rafael Espindola | f1a5c7e | 2011-04-30 03:44:37 +0000 | [diff] [blame] | 72 | ShowInst(showInst), UseLoc(useLoc), UseCFI(useCFI) { |
Chris Lattner | 5d672cf | 2010-02-10 00:10:18 +0000 | [diff] [blame] | 73 | if (InstPrinter && IsVerboseAsm) |
| 74 | InstPrinter->setCommentStream(CommentStream); |
| 75 | } |
Chris Lattner | 46a947d | 2009-08-17 04:17:34 +0000 | [diff] [blame] | 76 | ~MCAsmStreamer() {} |
Daniel Dunbar | a11af53 | 2009-06-24 01:03:06 +0000 | [diff] [blame] | 77 | |
Chris Lattner | 86e2211 | 2010-01-22 07:29:22 +0000 | [diff] [blame] | 78 | inline void EmitEOL() { |
Chris Lattner | d79d9dc | 2010-01-22 19:17:48 +0000 | [diff] [blame] | 79 | // If we don't have any comments, just emit a \n. |
| 80 | if (!IsVerboseAsm) { |
Chris Lattner | 86e2211 | 2010-01-22 07:29:22 +0000 | [diff] [blame] | 81 | OS << '\n'; |
| 82 | return; |
| 83 | } |
| 84 | EmitCommentsAndEOL(); |
| 85 | } |
| 86 | void EmitCommentsAndEOL(); |
Chris Lattner | 56591ab | 2010-02-02 23:37:42 +0000 | [diff] [blame] | 87 | |
| 88 | /// isVerboseAsm - Return true if this streamer supports verbose assembly at |
| 89 | /// all. |
| 90 | virtual bool isVerboseAsm() const { return IsVerboseAsm; } |
Jim Grosbach | 00545e1 | 2010-09-22 18:16:55 +0000 | [diff] [blame] | 91 | |
Chris Lattner | 91bead7 | 2010-04-03 21:35:55 +0000 | [diff] [blame] | 92 | /// hasRawTextSupport - We support EmitRawText. |
| 93 | virtual bool hasRawTextSupport() const { return true; } |
Daniel Dunbar | 6b71653 | 2010-02-09 23:00:14 +0000 | [diff] [blame] | 94 | |
Chris Lattner | d32c7cf | 2010-01-22 18:21:35 +0000 | [diff] [blame] | 95 | /// AddComment - Add a comment that can be emitted to the generated .s |
Chris Lattner | 86e2211 | 2010-01-22 07:29:22 +0000 | [diff] [blame] | 96 | /// file if applicable as a QoI issue to make the output of the compiler |
| 97 | /// more readable. This only affects the MCAsmStreamer, and only when |
| 98 | /// verbose assembly output is enabled. |
Chris Lattner | d32c7cf | 2010-01-22 18:21:35 +0000 | [diff] [blame] | 99 | virtual void AddComment(const Twine &T); |
Daniel Dunbar | 6b71653 | 2010-02-09 23:00:14 +0000 | [diff] [blame] | 100 | |
| 101 | /// AddEncodingComment - Add a comment showing the encoding of an instruction. |
| 102 | virtual void AddEncodingComment(const MCInst &Inst); |
| 103 | |
Chris Lattner | d79d9dc | 2010-01-22 19:17:48 +0000 | [diff] [blame] | 104 | /// GetCommentOS - Return a raw_ostream that comments can be written to. |
| 105 | /// Unlike AddComment, you are required to terminate comments with \n if you |
| 106 | /// use this method. |
| 107 | virtual raw_ostream &GetCommentOS() { |
| 108 | if (!IsVerboseAsm) |
| 109 | return nulls(); // Discard comments unless in verbose asm mode. |
| 110 | return CommentStream; |
| 111 | } |
Daniel Dunbar | 6b71653 | 2010-02-09 23:00:14 +0000 | [diff] [blame] | 112 | |
Chris Lattner | 0fd90fd | 2010-01-22 19:52:01 +0000 | [diff] [blame] | 113 | /// AddBlankLine - Emit a blank line to a .s file to pretty it up. |
| 114 | virtual void AddBlankLine() { |
| 115 | EmitEOL(); |
| 116 | } |
Daniel Dunbar | 6b71653 | 2010-02-09 23:00:14 +0000 | [diff] [blame] | 117 | |
Chris Lattner | 46a947d | 2009-08-17 04:17:34 +0000 | [diff] [blame] | 118 | /// @name MCStreamer Interface |
| 119 | /// @{ |
Daniel Dunbar | a11af53 | 2009-06-24 01:03:06 +0000 | [diff] [blame] | 120 | |
Rafael Espindola | 7768a9d | 2011-02-16 01:08:29 +0000 | [diff] [blame] | 121 | virtual void ChangeSection(const MCSection *Section); |
Daniel Dunbar | a11af53 | 2009-06-24 01:03:06 +0000 | [diff] [blame] | 122 | |
Rafael Espindola | d80781b | 2010-09-15 21:48:40 +0000 | [diff] [blame] | 123 | virtual void InitSections() { |
| 124 | // FIXME, this is MachO specific, but the testsuite |
| 125 | // expects this. |
| 126 | SwitchSection(getContext().getMachOSection("__TEXT", "__text", |
| 127 | MCSectionMachO::S_ATTR_PURE_INSTRUCTIONS, |
| 128 | 0, SectionKind::getText())); |
| 129 | } |
| 130 | |
Chris Lattner | 46a947d | 2009-08-17 04:17:34 +0000 | [diff] [blame] | 131 | virtual void EmitLabel(MCSymbol *Symbol); |
Rafael Espindola | 277abc8 | 2011-04-30 16:34:57 +0000 | [diff] [blame] | 132 | virtual void EmitEHSymAttributes(const MCSymbol *Symbol, |
| 133 | MCSymbol *EHSymbol); |
Chris Lattner | a5ad93a | 2010-01-23 06:39:22 +0000 | [diff] [blame] | 134 | virtual void EmitAssemblerFlag(MCAssemblerFlag Flag); |
Jim Grosbach | ce79299 | 2010-11-05 22:08:08 +0000 | [diff] [blame] | 135 | virtual void EmitThumbFunc(MCSymbol *Func); |
Daniel Dunbar | a11af53 | 2009-06-24 01:03:06 +0000 | [diff] [blame] | 136 | |
Daniel Dunbar | 821e333 | 2009-08-31 08:09:28 +0000 | [diff] [blame] | 137 | virtual void EmitAssignment(MCSymbol *Symbol, const MCExpr *Value); |
Rafael Espindola | 484291c | 2010-11-01 14:28:48 +0000 | [diff] [blame] | 138 | virtual void EmitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol); |
Rafael Espindola | 32a006e | 2010-12-03 00:55:40 +0000 | [diff] [blame] | 139 | virtual void EmitDwarfAdvanceLineAddr(int64_t LineDelta, |
| 140 | const MCSymbol *LastLabel, |
Evan Cheng | 672b93a | 2011-07-14 05:43:07 +0000 | [diff] [blame] | 141 | const MCSymbol *Label, |
| 142 | unsigned PointerSize); |
Rafael Espindola | a37bd1d | 2011-04-30 03:21:04 +0000 | [diff] [blame] | 143 | virtual void EmitDwarfAdvanceFrameAddr(const MCSymbol *LastLabel, |
| 144 | const MCSymbol *Label); |
Daniel Dunbar | a11af53 | 2009-06-24 01:03:06 +0000 | [diff] [blame] | 145 | |
Chris Lattner | a5ad93a | 2010-01-23 06:39:22 +0000 | [diff] [blame] | 146 | virtual void EmitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute); |
Kevin Enderby | a5c7832 | 2009-07-13 21:03:15 +0000 | [diff] [blame] | 147 | |
Chris Lattner | 46a947d | 2009-08-17 04:17:34 +0000 | [diff] [blame] | 148 | virtual void EmitSymbolDesc(MCSymbol *Symbol, unsigned DescValue); |
Chris Lattner | b54b9dd | 2010-05-08 19:54:22 +0000 | [diff] [blame] | 149 | virtual void BeginCOFFSymbolDef(const MCSymbol *Symbol); |
| 150 | virtual void EmitCOFFSymbolStorageClass(int StorageClass); |
| 151 | virtual void EmitCOFFSymbolType(int Type); |
| 152 | virtual void EndCOFFSymbolDef(); |
Chris Lattner | 99328ad | 2010-01-25 07:52:13 +0000 | [diff] [blame] | 153 | virtual void EmitELFSize(MCSymbol *Symbol, const MCExpr *Value); |
Chris Lattner | 9eb158d | 2010-01-23 07:47:02 +0000 | [diff] [blame] | 154 | virtual void EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size, |
Daniel Dunbar | 7092c7e | 2009-08-30 06:17:16 +0000 | [diff] [blame] | 155 | unsigned ByteAlignment); |
Kevin Enderby | 95cf30c | 2009-07-14 18:17:10 +0000 | [diff] [blame] | 156 | |
Chris Lattner | 9eb158d | 2010-01-23 07:47:02 +0000 | [diff] [blame] | 157 | /// EmitLocalCommonSymbol - Emit a local common (.lcomm) symbol. |
| 158 | /// |
| 159 | /// @param Symbol - The common symbol to emit. |
| 160 | /// @param Size - The size of the common symbol. |
| 161 | virtual void EmitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size); |
Jim Grosbach | 00545e1 | 2010-09-22 18:16:55 +0000 | [diff] [blame] | 162 | |
Daniel Dunbar | 8751b94 | 2009-08-28 05:48:22 +0000 | [diff] [blame] | 163 | virtual void EmitZerofill(const MCSection *Section, MCSymbol *Symbol = 0, |
Daniel Dunbar | 7092c7e | 2009-08-30 06:17:16 +0000 | [diff] [blame] | 164 | unsigned Size = 0, unsigned ByteAlignment = 0); |
Kevin Enderby | 7114824 | 2009-07-14 21:35:03 +0000 | [diff] [blame] | 165 | |
Eric Christopher | 4d01cbe | 2010-05-18 21:16:04 +0000 | [diff] [blame] | 166 | virtual void EmitTBSSSymbol (const MCSection *Section, MCSymbol *Symbol, |
| 167 | uint64_t Size, unsigned ByteAlignment = 0); |
Jim Grosbach | 00545e1 | 2010-09-22 18:16:55 +0000 | [diff] [blame] | 168 | |
Chris Lattner | aaec205 | 2010-01-19 19:46:13 +0000 | [diff] [blame] | 169 | virtual void EmitBytes(StringRef Data, unsigned AddrSpace); |
Chris Lattner | 4e4db7a | 2009-07-07 20:30:46 +0000 | [diff] [blame] | 170 | |
Rafael Espindola | 89b9372 | 2010-12-10 07:39:47 +0000 | [diff] [blame] | 171 | virtual void EmitValueImpl(const MCExpr *Value, unsigned Size, |
Rafael Espindola | debd7e4 | 2011-05-01 03:50:49 +0000 | [diff] [blame] | 172 | unsigned AddrSpace); |
Rafael Espindola | 2df042c | 2010-12-03 02:54:21 +0000 | [diff] [blame] | 173 | virtual void EmitIntValue(uint64_t Value, unsigned Size, |
| 174 | unsigned AddrSpace = 0); |
Rafael Espindola | 3ff5709 | 2010-11-02 17:22:24 +0000 | [diff] [blame] | 175 | |
Rafael Espindola | e8cfbd8 | 2011-04-21 23:39:26 +0000 | [diff] [blame] | 176 | virtual void EmitULEB128Value(const MCExpr *Value); |
Rafael Espindola | 3ff5709 | 2010-11-02 17:22:24 +0000 | [diff] [blame] | 177 | |
Rafael Espindola | e8cfbd8 | 2011-04-21 23:39:26 +0000 | [diff] [blame] | 178 | virtual void EmitSLEB128Value(const MCExpr *Value); |
Rafael Espindola | 3ff5709 | 2010-11-02 17:22:24 +0000 | [diff] [blame] | 179 | |
Chris Lattner | 718fb59 | 2010-01-25 21:28:50 +0000 | [diff] [blame] | 180 | virtual void EmitGPRel32Value(const MCExpr *Value); |
Jim Grosbach | 00545e1 | 2010-09-22 18:16:55 +0000 | [diff] [blame] | 181 | |
Chris Lattner | 32ae3fe | 2010-01-19 22:03:38 +0000 | [diff] [blame] | 182 | |
Chris Lattner | aaec205 | 2010-01-19 19:46:13 +0000 | [diff] [blame] | 183 | virtual void EmitFill(uint64_t NumBytes, uint8_t FillValue, |
| 184 | unsigned AddrSpace); |
Chris Lattner | 9be3fee | 2009-07-10 22:20:30 +0000 | [diff] [blame] | 185 | |
Chris Lattner | 46a947d | 2009-08-17 04:17:34 +0000 | [diff] [blame] | 186 | virtual void EmitValueToAlignment(unsigned ByteAlignment, int64_t Value = 0, |
| 187 | unsigned ValueSize = 1, |
| 188 | unsigned MaxBytesToEmit = 0); |
Daniel Dunbar | a11af53 | 2009-06-24 01:03:06 +0000 | [diff] [blame] | 189 | |
Kevin Enderby | 6e72048 | 2010-02-23 18:26:34 +0000 | [diff] [blame] | 190 | virtual void EmitCodeAlignment(unsigned ByteAlignment, |
| 191 | unsigned MaxBytesToEmit = 0); |
| 192 | |
Daniel Dunbar | 821e333 | 2009-08-31 08:09:28 +0000 | [diff] [blame] | 193 | virtual void EmitValueToOffset(const MCExpr *Offset, |
Chris Lattner | 46a947d | 2009-08-17 04:17:34 +0000 | [diff] [blame] | 194 | unsigned char Value = 0); |
Daniel Dunbar | a11af53 | 2009-06-24 01:03:06 +0000 | [diff] [blame] | 195 | |
Chris Lattner | a6594fc | 2010-01-25 18:58:59 +0000 | [diff] [blame] | 196 | virtual void EmitFileDirective(StringRef Filename); |
Rafael Espindola | af6b5808 | 2010-11-16 21:20:32 +0000 | [diff] [blame] | 197 | virtual bool EmitDwarfFileDirective(unsigned FileNo, StringRef Filename); |
| 198 | virtual void EmitDwarfLocDirective(unsigned FileNo, unsigned Line, |
| 199 | unsigned Column, unsigned Flags, |
Devang Patel | 3f3bf93 | 2011-04-18 20:26:49 +0000 | [diff] [blame] | 200 | unsigned Isa, unsigned Discriminator, |
| 201 | StringRef FileName); |
Chris Lattner | a6594fc | 2010-01-25 18:58:59 +0000 | [diff] [blame] | 202 | |
Rafael Espindola | 713c4bf | 2011-05-10 13:39:48 +0000 | [diff] [blame] | 203 | virtual void EmitCFISections(bool EH, bool Debug); |
Rafael Espindola | 066c2f4 | 2011-04-12 23:59:07 +0000 | [diff] [blame] | 204 | virtual void EmitCFIStartProc(); |
| 205 | virtual void EmitCFIEndProc(); |
| 206 | virtual void EmitCFIDefCfa(int64_t Register, int64_t Offset); |
| 207 | virtual void EmitCFIDefCfaOffset(int64_t Offset); |
| 208 | virtual void EmitCFIDefCfaRegister(int64_t Register); |
| 209 | virtual void EmitCFIOffset(int64_t Register, int64_t Offset); |
| 210 | virtual void EmitCFIPersonality(const MCSymbol *Sym, unsigned Encoding); |
| 211 | virtual void EmitCFILsda(const MCSymbol *Sym, unsigned Encoding); |
| 212 | virtual void EmitCFIRememberState(); |
| 213 | virtual void EmitCFIRestoreState(); |
| 214 | virtual void EmitCFISameValue(int64_t Register); |
| 215 | virtual void EmitCFIRelOffset(int64_t Register, int64_t Offset); |
| 216 | virtual void EmitCFIAdjustCfaOffset(int64_t Adjustment); |
Rafael Espindola | cdfecc8 | 2010-11-22 14:27:24 +0000 | [diff] [blame] | 217 | |
Charles Davis | fbc539f | 2011-05-22 21:12:15 +0000 | [diff] [blame] | 218 | virtual void EmitWin64EHStartProc(const MCSymbol *Symbol); |
Charles Davis | 0e30f02 | 2011-05-18 04:58:05 +0000 | [diff] [blame] | 219 | virtual void EmitWin64EHEndProc(); |
Charles Davis | f070901 | 2011-05-18 20:54:10 +0000 | [diff] [blame] | 220 | virtual void EmitWin64EHStartChained(); |
| 221 | virtual void EmitWin64EHEndChained(); |
Charles Davis | 440596f | 2011-05-19 17:46:39 +0000 | [diff] [blame] | 222 | virtual void EmitWin64EHHandler(const MCSymbol *Sym, bool Unwind, |
| 223 | bool Except); |
| 224 | virtual void EmitWin64EHHandlerData(); |
Charles Davis | c3b1628 | 2011-05-19 19:35:55 +0000 | [diff] [blame] | 225 | virtual void EmitWin64EHPushReg(unsigned Register); |
| 226 | virtual void EmitWin64EHSetFrame(unsigned Register, unsigned Offset); |
| 227 | virtual void EmitWin64EHAllocStack(unsigned Size); |
| 228 | virtual void EmitWin64EHSaveReg(unsigned Register, unsigned Offset); |
| 229 | virtual void EmitWin64EHSaveXMM(unsigned Register, unsigned Offset); |
Charles Davis | 0e30f02 | 2011-05-18 04:58:05 +0000 | [diff] [blame] | 230 | virtual void EmitWin64EHPushFrame(bool Code); |
| 231 | virtual void EmitWin64EHEndProlog(); |
| 232 | |
Anton Korobeynikov | b5e16af | 2011-03-05 18:43:15 +0000 | [diff] [blame] | 233 | virtual void EmitFnStart(); |
| 234 | virtual void EmitFnEnd(); |
| 235 | virtual void EmitCantUnwind(); |
| 236 | virtual void EmitPersonality(const MCSymbol *Personality); |
| 237 | virtual void EmitHandlerData(); |
Anton Korobeynikov | 57caad7 | 2011-03-05 18:43:32 +0000 | [diff] [blame] | 238 | virtual void EmitSetFP(unsigned FpReg, unsigned SpReg, int64_t Offset = 0); |
| 239 | virtual void EmitPad(int64_t Offset); |
| 240 | virtual void EmitRegSave(const SmallVectorImpl<unsigned> &RegList, bool); |
| 241 | |
Anton Korobeynikov | b5e16af | 2011-03-05 18:43:15 +0000 | [diff] [blame] | 242 | |
Chris Lattner | a6594fc | 2010-01-25 18:58:59 +0000 | [diff] [blame] | 243 | virtual void EmitInstruction(const MCInst &Inst); |
Jim Grosbach | 00545e1 | 2010-09-22 18:16:55 +0000 | [diff] [blame] | 244 | |
Jim Grosbach | bd4ec84 | 2010-09-22 18:18:30 +0000 | [diff] [blame] | 245 | /// EmitRawText - If this file is backed by an assembly streamer, this dumps |
Chris Lattner | 91bead7 | 2010-04-03 21:35:55 +0000 | [diff] [blame] | 246 | /// the specified string in the output .s file. This capability is |
| 247 | /// indicated by the hasRawTextSupport() predicate. |
| 248 | virtual void EmitRawText(StringRef String); |
Jim Grosbach | 00545e1 | 2010-09-22 18:16:55 +0000 | [diff] [blame] | 249 | |
Chris Lattner | 46a947d | 2009-08-17 04:17:34 +0000 | [diff] [blame] | 250 | virtual void Finish(); |
Jim Grosbach | 00545e1 | 2010-09-22 18:16:55 +0000 | [diff] [blame] | 251 | |
Chris Lattner | 46a947d | 2009-08-17 04:17:34 +0000 | [diff] [blame] | 252 | /// @} |
| 253 | }; |
Daniel Dunbar | 84a2926 | 2009-06-24 19:25:34 +0000 | [diff] [blame] | 254 | |
Chris Lattner | 46a947d | 2009-08-17 04:17:34 +0000 | [diff] [blame] | 255 | } // end anonymous namespace. |
Daniel Dunbar | a11af53 | 2009-06-24 01:03:06 +0000 | [diff] [blame] | 256 | |
Chris Lattner | d32c7cf | 2010-01-22 18:21:35 +0000 | [diff] [blame] | 257 | /// AddComment - Add a comment that can be emitted to the generated .s |
Chris Lattner | 86e2211 | 2010-01-22 07:29:22 +0000 | [diff] [blame] | 258 | /// file if applicable as a QoI issue to make the output of the compiler |
| 259 | /// more readable. This only affects the MCAsmStreamer, and only when |
| 260 | /// verbose assembly output is enabled. |
Chris Lattner | d32c7cf | 2010-01-22 18:21:35 +0000 | [diff] [blame] | 261 | void MCAsmStreamer::AddComment(const Twine &T) { |
Chris Lattner | 86e2211 | 2010-01-22 07:29:22 +0000 | [diff] [blame] | 262 | if (!IsVerboseAsm) return; |
Jim Grosbach | 00545e1 | 2010-09-22 18:16:55 +0000 | [diff] [blame] | 263 | |
Chris Lattner | d79d9dc | 2010-01-22 19:17:48 +0000 | [diff] [blame] | 264 | // Make sure that CommentStream is flushed. |
| 265 | CommentStream.flush(); |
Jim Grosbach | 00545e1 | 2010-09-22 18:16:55 +0000 | [diff] [blame] | 266 | |
Chris Lattner | 86e2211 | 2010-01-22 07:29:22 +0000 | [diff] [blame] | 267 | T.toVector(CommentToEmit); |
Chris Lattner | d79d9dc | 2010-01-22 19:17:48 +0000 | [diff] [blame] | 268 | // Each comment goes on its own line. |
| 269 | CommentToEmit.push_back('\n'); |
Jim Grosbach | 00545e1 | 2010-09-22 18:16:55 +0000 | [diff] [blame] | 270 | |
Chris Lattner | 14ca177 | 2010-01-22 21:16:10 +0000 | [diff] [blame] | 271 | // Tell the comment stream that the vector changed underneath it. |
| 272 | CommentStream.resync(); |
Chris Lattner | 86e2211 | 2010-01-22 07:29:22 +0000 | [diff] [blame] | 273 | } |
| 274 | |
| 275 | void MCAsmStreamer::EmitCommentsAndEOL() { |
Chris Lattner | d79d9dc | 2010-01-22 19:17:48 +0000 | [diff] [blame] | 276 | if (CommentToEmit.empty() && CommentStream.GetNumBytesInBuffer() == 0) { |
| 277 | OS << '\n'; |
| 278 | return; |
| 279 | } |
Jim Grosbach | 00545e1 | 2010-09-22 18:16:55 +0000 | [diff] [blame] | 280 | |
Chris Lattner | d79d9dc | 2010-01-22 19:17:48 +0000 | [diff] [blame] | 281 | CommentStream.flush(); |
Chris Lattner | 86e2211 | 2010-01-22 07:29:22 +0000 | [diff] [blame] | 282 | StringRef Comments = CommentToEmit.str(); |
Jim Grosbach | 00545e1 | 2010-09-22 18:16:55 +0000 | [diff] [blame] | 283 | |
Chris Lattner | d79d9dc | 2010-01-22 19:17:48 +0000 | [diff] [blame] | 284 | assert(Comments.back() == '\n' && |
| 285 | "Comment array not newline terminated"); |
| 286 | do { |
Chris Lattner | 86e2211 | 2010-01-22 07:29:22 +0000 | [diff] [blame] | 287 | // Emit a line of comments. |
| 288 | OS.PadToColumn(MAI.getCommentColumn()); |
| 289 | size_t Position = Comments.find('\n'); |
| 290 | OS << MAI.getCommentString() << ' ' << Comments.substr(0, Position) << '\n'; |
Jim Grosbach | 00545e1 | 2010-09-22 18:16:55 +0000 | [diff] [blame] | 291 | |
Chris Lattner | 86e2211 | 2010-01-22 07:29:22 +0000 | [diff] [blame] | 292 | Comments = Comments.substr(Position+1); |
Chris Lattner | d79d9dc | 2010-01-22 19:17:48 +0000 | [diff] [blame] | 293 | } while (!Comments.empty()); |
Jim Grosbach | 00545e1 | 2010-09-22 18:16:55 +0000 | [diff] [blame] | 294 | |
Chris Lattner | 14ca177 | 2010-01-22 21:16:10 +0000 | [diff] [blame] | 295 | CommentToEmit.clear(); |
| 296 | // Tell the comment stream that the vector changed underneath it. |
| 297 | CommentStream.resync(); |
Chris Lattner | 86e2211 | 2010-01-22 07:29:22 +0000 | [diff] [blame] | 298 | } |
| 299 | |
Daniel Dunbar | 304f6a4 | 2009-06-25 21:03:18 +0000 | [diff] [blame] | 300 | static inline int64_t truncateToSize(int64_t Value, unsigned Bytes) { |
| 301 | assert(Bytes && "Invalid size!"); |
| 302 | return Value & ((uint64_t) (int64_t) -1 >> (64 - Bytes * 8)); |
| 303 | } |
| 304 | |
Rafael Espindola | 7768a9d | 2011-02-16 01:08:29 +0000 | [diff] [blame] | 305 | void MCAsmStreamer::ChangeSection(const MCSection *Section) { |
Chris Lattner | 6c2f9e1 | 2009-08-19 05:49:37 +0000 | [diff] [blame] | 306 | assert(Section && "Cannot switch to a null section!"); |
Rafael Espindola | 7768a9d | 2011-02-16 01:08:29 +0000 | [diff] [blame] | 307 | Section->PrintSwitchToSection(MAI, OS); |
Daniel Dunbar | a11af53 | 2009-06-24 01:03:06 +0000 | [diff] [blame] | 308 | } |
| 309 | |
Rafael Espindola | 277abc8 | 2011-04-30 16:34:57 +0000 | [diff] [blame] | 310 | void MCAsmStreamer::EmitEHSymAttributes(const MCSymbol *Symbol, |
| 311 | MCSymbol *EHSymbol) { |
| 312 | if (UseCFI) |
| 313 | return; |
| 314 | |
| 315 | unsigned Flags = FlagMap.lookup(Symbol); |
| 316 | |
| 317 | if (Flags & EHGlobal) |
| 318 | EmitSymbolAttribute(EHSymbol, MCSA_Global); |
| 319 | if (Flags & EHWeakDefinition) |
| 320 | EmitSymbolAttribute(EHSymbol, MCSA_WeakDefinition); |
| 321 | if (Flags & EHPrivateExtern) |
| 322 | EmitSymbolAttribute(EHSymbol, MCSA_PrivateExtern); |
| 323 | } |
| 324 | |
Daniel Dunbar | a11af53 | 2009-06-24 01:03:06 +0000 | [diff] [blame] | 325 | void MCAsmStreamer::EmitLabel(MCSymbol *Symbol) { |
Daniel Dunbar | 8906ff1 | 2009-08-22 07:22:36 +0000 | [diff] [blame] | 326 | assert(Symbol->isUndefined() && "Cannot define a symbol twice!"); |
Rafael Espindola | ed708f9 | 2011-04-27 15:21:19 +0000 | [diff] [blame] | 327 | MCStreamer::EmitLabel(Symbol); |
Daniel Dunbar | 71d259b | 2009-06-24 17:00:42 +0000 | [diff] [blame] | 328 | |
Chris Lattner | e07b75e | 2010-09-22 22:19:53 +0000 | [diff] [blame] | 329 | OS << *Symbol << MAI.getLabelSuffix(); |
Chris Lattner | 7d1e49c | 2010-01-22 07:36:39 +0000 | [diff] [blame] | 330 | EmitEOL(); |
Daniel Dunbar | a11af53 | 2009-06-24 01:03:06 +0000 | [diff] [blame] | 331 | } |
| 332 | |
Chris Lattner | a5ad93a | 2010-01-23 06:39:22 +0000 | [diff] [blame] | 333 | void MCAsmStreamer::EmitAssemblerFlag(MCAssemblerFlag Flag) { |
Kevin Enderby | f96db46 | 2009-07-16 17:56:39 +0000 | [diff] [blame] | 334 | switch (Flag) { |
Daniel Dunbar | 011e4db | 2009-08-13 23:36:34 +0000 | [diff] [blame] | 335 | default: assert(0 && "Invalid flag!"); |
Jason W Kim | afd1cc2 | 2010-09-30 02:45:56 +0000 | [diff] [blame] | 336 | case MCAF_SyntaxUnified: OS << "\t.syntax unified"; break; |
Chris Lattner | a5ad93a | 2010-01-23 06:39:22 +0000 | [diff] [blame] | 337 | case MCAF_SubsectionsViaSymbols: OS << ".subsections_via_symbols"; break; |
Jim Grosbach | ce79299 | 2010-11-05 22:08:08 +0000 | [diff] [blame] | 338 | case MCAF_Code16: OS << "\t.code\t16"; break; |
Jim Grosbach | ba21957 | 2010-11-05 22:40:09 +0000 | [diff] [blame] | 339 | case MCAF_Code32: OS << "\t.code\t32"; break; |
Kevin Enderby | f96db46 | 2009-07-16 17:56:39 +0000 | [diff] [blame] | 340 | } |
Chris Lattner | 7d1e49c | 2010-01-22 07:36:39 +0000 | [diff] [blame] | 341 | EmitEOL(); |
Kevin Enderby | a5c7832 | 2009-07-13 21:03:15 +0000 | [diff] [blame] | 342 | } |
| 343 | |
Jim Grosbach | ce79299 | 2010-11-05 22:08:08 +0000 | [diff] [blame] | 344 | void MCAsmStreamer::EmitThumbFunc(MCSymbol *Func) { |
| 345 | // This needs to emit to a temporary string to get properly quoted |
| 346 | // MCSymbols when they have spaces in them. |
| 347 | OS << "\t.thumb_func"; |
Rafael Espindola | 6469540 | 2011-05-16 16:17:21 +0000 | [diff] [blame] | 348 | // Only Mach-O hasSubsectionsViaSymbols() |
| 349 | if (MAI.hasSubsectionsViaSymbols()) |
Jim Grosbach | ce79299 | 2010-11-05 22:08:08 +0000 | [diff] [blame] | 350 | OS << '\t' << *Func; |
| 351 | EmitEOL(); |
| 352 | } |
| 353 | |
Daniel Dunbar | 821e333 | 2009-08-31 08:09:28 +0000 | [diff] [blame] | 354 | void MCAsmStreamer::EmitAssignment(MCSymbol *Symbol, const MCExpr *Value) { |
Chris Lattner | 7d1e49c | 2010-01-22 07:36:39 +0000 | [diff] [blame] | 355 | OS << *Symbol << " = " << *Value; |
| 356 | EmitEOL(); |
Daniel Dunbar | fffff91 | 2009-10-16 01:34:54 +0000 | [diff] [blame] | 357 | |
| 358 | // FIXME: Lift context changes into super class. |
Daniel Dunbar | 08a408a | 2010-05-05 17:41:00 +0000 | [diff] [blame] | 359 | Symbol->setVariableValue(Value); |
Daniel Dunbar | a11af53 | 2009-06-24 01:03:06 +0000 | [diff] [blame] | 360 | } |
| 361 | |
Rafael Espindola | 484291c | 2010-11-01 14:28:48 +0000 | [diff] [blame] | 362 | void MCAsmStreamer::EmitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol) { |
| 363 | OS << ".weakref " << *Alias << ", " << *Symbol; |
| 364 | EmitEOL(); |
| 365 | } |
| 366 | |
Rafael Espindola | 32a006e | 2010-12-03 00:55:40 +0000 | [diff] [blame] | 367 | void MCAsmStreamer::EmitDwarfAdvanceLineAddr(int64_t LineDelta, |
| 368 | const MCSymbol *LastLabel, |
Evan Cheng | 672b93a | 2011-07-14 05:43:07 +0000 | [diff] [blame] | 369 | const MCSymbol *Label, |
| 370 | unsigned PointerSize) { |
| 371 | EmitDwarfSetLineAddr(LineDelta, Label, PointerSize); |
Rafael Espindola | 32a006e | 2010-12-03 00:55:40 +0000 | [diff] [blame] | 372 | } |
| 373 | |
Rafael Espindola | a37bd1d | 2011-04-30 03:21:04 +0000 | [diff] [blame] | 374 | void MCAsmStreamer::EmitDwarfAdvanceFrameAddr(const MCSymbol *LastLabel, |
| 375 | const MCSymbol *Label) { |
| 376 | EmitIntValue(dwarf::DW_CFA_advance_loc4, 1); |
| 377 | const MCExpr *AddrDelta = BuildSymbolDiff(getContext(), Label, LastLabel); |
Rafael Espindola | a6f2678 | 2011-05-19 21:40:34 +0000 | [diff] [blame] | 378 | AddrDelta = ForceExpAbs(AddrDelta); |
Rafael Espindola | a37bd1d | 2011-04-30 03:21:04 +0000 | [diff] [blame] | 379 | EmitValue(AddrDelta, 4); |
| 380 | } |
| 381 | |
| 382 | |
Daniel Dunbar | fffff91 | 2009-10-16 01:34:54 +0000 | [diff] [blame] | 383 | void MCAsmStreamer::EmitSymbolAttribute(MCSymbol *Symbol, |
Chris Lattner | a5ad93a | 2010-01-23 06:39:22 +0000 | [diff] [blame] | 384 | MCSymbolAttr Attribute) { |
Daniel Dunbar | a11af53 | 2009-06-24 01:03:06 +0000 | [diff] [blame] | 385 | switch (Attribute) { |
Chris Lattner | a5ad93a | 2010-01-23 06:39:22 +0000 | [diff] [blame] | 386 | case MCSA_Invalid: assert(0 && "Invalid symbol attribute"); |
Chris Lattner | ed0ab15 | 2010-01-25 18:30:45 +0000 | [diff] [blame] | 387 | case MCSA_ELF_TypeFunction: /// .type _foo, STT_FUNC # aka @function |
| 388 | case MCSA_ELF_TypeIndFunction: /// .type _foo, STT_GNU_IFUNC |
| 389 | case MCSA_ELF_TypeObject: /// .type _foo, STT_OBJECT # aka @object |
| 390 | case MCSA_ELF_TypeTLS: /// .type _foo, STT_TLS # aka @tls_object |
| 391 | case MCSA_ELF_TypeCommon: /// .type _foo, STT_COMMON # aka @common |
| 392 | case MCSA_ELF_TypeNoType: /// .type _foo, STT_NOTYPE # aka @notype |
Rafael Espindola | e9c0ff2 | 2010-11-13 04:55:06 +0000 | [diff] [blame] | 393 | case MCSA_ELF_TypeGnuUniqueObject: /// .type _foo, @gnu_unique_object |
Chris Lattner | ed0ab15 | 2010-01-25 18:30:45 +0000 | [diff] [blame] | 394 | assert(MAI.hasDotTypeDotSizeDirective() && "Symbol Attr not supported"); |
Dan Gohman | 523d70e | 2010-02-04 01:42:13 +0000 | [diff] [blame] | 395 | OS << "\t.type\t" << *Symbol << ',' |
Chris Lattner | ed0ab15 | 2010-01-25 18:30:45 +0000 | [diff] [blame] | 396 | << ((MAI.getCommentString()[0] != '@') ? '@' : '%'); |
| 397 | switch (Attribute) { |
| 398 | default: assert(0 && "Unknown ELF .type"); |
| 399 | case MCSA_ELF_TypeFunction: OS << "function"; break; |
| 400 | case MCSA_ELF_TypeIndFunction: OS << "gnu_indirect_function"; break; |
| 401 | case MCSA_ELF_TypeObject: OS << "object"; break; |
| 402 | case MCSA_ELF_TypeTLS: OS << "tls_object"; break; |
| 403 | case MCSA_ELF_TypeCommon: OS << "common"; break; |
| 404 | case MCSA_ELF_TypeNoType: OS << "no_type"; break; |
Rafael Espindola | e9c0ff2 | 2010-11-13 04:55:06 +0000 | [diff] [blame] | 405 | case MCSA_ELF_TypeGnuUniqueObject: OS << "gnu_unique_object"; break; |
Chris Lattner | ed0ab15 | 2010-01-25 18:30:45 +0000 | [diff] [blame] | 406 | } |
| 407 | EmitEOL(); |
| 408 | return; |
| 409 | case MCSA_Global: // .globl/.global |
| 410 | OS << MAI.getGlobalDirective(); |
Rafael Espindola | 277abc8 | 2011-04-30 16:34:57 +0000 | [diff] [blame] | 411 | FlagMap[Symbol] |= EHGlobal; |
Chris Lattner | ed0ab15 | 2010-01-25 18:30:45 +0000 | [diff] [blame] | 412 | break; |
Chris Lattner | 61abd7b | 2010-06-21 20:35:01 +0000 | [diff] [blame] | 413 | case MCSA_Hidden: OS << "\t.hidden\t"; break; |
| 414 | case MCSA_IndirectSymbol: OS << "\t.indirect_symbol\t"; break; |
| 415 | case MCSA_Internal: OS << "\t.internal\t"; break; |
| 416 | case MCSA_LazyReference: OS << "\t.lazy_reference\t"; break; |
| 417 | case MCSA_Local: OS << "\t.local\t"; break; |
| 418 | case MCSA_NoDeadStrip: OS << "\t.no_dead_strip\t"; break; |
Kevin Enderby | e8e98d7 | 2010-11-19 18:39:33 +0000 | [diff] [blame] | 419 | case MCSA_SymbolResolver: OS << "\t.symbol_resolver\t"; break; |
Rafael Espindola | 277abc8 | 2011-04-30 16:34:57 +0000 | [diff] [blame] | 420 | case MCSA_PrivateExtern: |
| 421 | OS << "\t.private_extern\t"; |
| 422 | FlagMap[Symbol] |= EHPrivateExtern; |
| 423 | break; |
Chris Lattner | 61abd7b | 2010-06-21 20:35:01 +0000 | [diff] [blame] | 424 | case MCSA_Protected: OS << "\t.protected\t"; break; |
| 425 | case MCSA_Reference: OS << "\t.reference\t"; break; |
| 426 | case MCSA_Weak: OS << "\t.weak\t"; break; |
Rafael Espindola | 277abc8 | 2011-04-30 16:34:57 +0000 | [diff] [blame] | 427 | case MCSA_WeakDefinition: |
| 428 | OS << "\t.weak_definition\t"; |
| 429 | FlagMap[Symbol] |= EHWeakDefinition; |
| 430 | break; |
Chris Lattner | a5ad93a | 2010-01-23 06:39:22 +0000 | [diff] [blame] | 431 | // .weak_reference |
| 432 | case MCSA_WeakReference: OS << MAI.getWeakRefDirective(); break; |
Kevin Enderby | f59cac5 | 2010-07-08 17:22:42 +0000 | [diff] [blame] | 433 | case MCSA_WeakDefAutoPrivate: OS << "\t.weak_def_can_be_hidden\t"; break; |
Daniel Dunbar | a11af53 | 2009-06-24 01:03:06 +0000 | [diff] [blame] | 434 | } |
| 435 | |
Chris Lattner | 7d1e49c | 2010-01-22 07:36:39 +0000 | [diff] [blame] | 436 | OS << *Symbol; |
| 437 | EmitEOL(); |
Daniel Dunbar | a11af53 | 2009-06-24 01:03:06 +0000 | [diff] [blame] | 438 | } |
| 439 | |
Kevin Enderby | 95cf30c | 2009-07-14 18:17:10 +0000 | [diff] [blame] | 440 | void MCAsmStreamer::EmitSymbolDesc(MCSymbol *Symbol, unsigned DescValue) { |
Chris Lattner | 7d1e49c | 2010-01-22 07:36:39 +0000 | [diff] [blame] | 441 | OS << ".desc" << ' ' << *Symbol << ',' << DescValue; |
| 442 | EmitEOL(); |
Kevin Enderby | 95cf30c | 2009-07-14 18:17:10 +0000 | [diff] [blame] | 443 | } |
| 444 | |
Chris Lattner | b54b9dd | 2010-05-08 19:54:22 +0000 | [diff] [blame] | 445 | void MCAsmStreamer::BeginCOFFSymbolDef(const MCSymbol *Symbol) { |
| 446 | OS << "\t.def\t " << *Symbol << ';'; |
| 447 | EmitEOL(); |
| 448 | } |
| 449 | |
| 450 | void MCAsmStreamer::EmitCOFFSymbolStorageClass (int StorageClass) { |
| 451 | OS << "\t.scl\t" << StorageClass << ';'; |
| 452 | EmitEOL(); |
| 453 | } |
| 454 | |
| 455 | void MCAsmStreamer::EmitCOFFSymbolType (int Type) { |
| 456 | OS << "\t.type\t" << Type << ';'; |
| 457 | EmitEOL(); |
| 458 | } |
| 459 | |
| 460 | void MCAsmStreamer::EndCOFFSymbolDef() { |
| 461 | OS << "\t.endef"; |
| 462 | EmitEOL(); |
| 463 | } |
| 464 | |
Chris Lattner | 99328ad | 2010-01-25 07:52:13 +0000 | [diff] [blame] | 465 | void MCAsmStreamer::EmitELFSize(MCSymbol *Symbol, const MCExpr *Value) { |
| 466 | assert(MAI.hasDotTypeDotSizeDirective()); |
| 467 | OS << "\t.size\t" << *Symbol << ", " << *Value << '\n'; |
| 468 | } |
| 469 | |
Chris Lattner | 9eb158d | 2010-01-23 07:47:02 +0000 | [diff] [blame] | 470 | void MCAsmStreamer::EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size, |
Daniel Dunbar | 7092c7e | 2009-08-30 06:17:16 +0000 | [diff] [blame] | 471 | unsigned ByteAlignment) { |
Chris Lattner | 9eb158d | 2010-01-23 07:47:02 +0000 | [diff] [blame] | 472 | OS << "\t.comm\t" << *Symbol << ',' << Size; |
Chris Lattner | 6559d76 | 2010-01-25 07:29:13 +0000 | [diff] [blame] | 473 | if (ByteAlignment != 0) { |
Rafael Espindola | 2e2563b | 2010-01-26 20:21:43 +0000 | [diff] [blame] | 474 | if (MAI.getCOMMDirectiveAlignmentIsInBytes()) |
Chris Lattner | 4ed5438 | 2010-01-19 06:01:04 +0000 | [diff] [blame] | 475 | OS << ',' << ByteAlignment; |
| 476 | else |
| 477 | OS << ',' << Log2_32(ByteAlignment); |
| 478 | } |
Chris Lattner | 7d1e49c | 2010-01-22 07:36:39 +0000 | [diff] [blame] | 479 | EmitEOL(); |
Chris Lattner | 4e4db7a | 2009-07-07 20:30:46 +0000 | [diff] [blame] | 480 | } |
| 481 | |
Chris Lattner | 9eb158d | 2010-01-23 07:47:02 +0000 | [diff] [blame] | 482 | /// EmitLocalCommonSymbol - Emit a local common (.lcomm) symbol. |
| 483 | /// |
| 484 | /// @param Symbol - The common symbol to emit. |
| 485 | /// @param Size - The size of the common symbol. |
| 486 | void MCAsmStreamer::EmitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size) { |
| 487 | assert(MAI.hasLCOMMDirective() && "Doesn't have .lcomm, can't emit it!"); |
| 488 | OS << "\t.lcomm\t" << *Symbol << ',' << Size; |
| 489 | EmitEOL(); |
| 490 | } |
| 491 | |
Daniel Dunbar | 8751b94 | 2009-08-28 05:48:22 +0000 | [diff] [blame] | 492 | void MCAsmStreamer::EmitZerofill(const MCSection *Section, MCSymbol *Symbol, |
Daniel Dunbar | 7092c7e | 2009-08-30 06:17:16 +0000 | [diff] [blame] | 493 | unsigned Size, unsigned ByteAlignment) { |
Daniel Dunbar | 011e4db | 2009-08-13 23:36:34 +0000 | [diff] [blame] | 494 | // Note: a .zerofill directive does not switch sections. |
Chris Lattner | 93b6db3 | 2009-08-08 23:39:42 +0000 | [diff] [blame] | 495 | OS << ".zerofill "; |
Jim Grosbach | 00545e1 | 2010-09-22 18:16:55 +0000 | [diff] [blame] | 496 | |
Chris Lattner | 93b6db3 | 2009-08-08 23:39:42 +0000 | [diff] [blame] | 497 | // This is a mach-o specific directive. |
Chris Lattner | ff4bc46 | 2009-08-10 01:39:42 +0000 | [diff] [blame] | 498 | const MCSectionMachO *MOSection = ((const MCSectionMachO*)Section); |
Daniel Dunbar | 12de0df | 2009-08-14 18:51:45 +0000 | [diff] [blame] | 499 | OS << MOSection->getSegmentName() << "," << MOSection->getSectionName(); |
Jim Grosbach | 00545e1 | 2010-09-22 18:16:55 +0000 | [diff] [blame] | 500 | |
Chris Lattner | 9be3fee | 2009-07-10 22:20:30 +0000 | [diff] [blame] | 501 | if (Symbol != NULL) { |
Chris Lattner | 10b318b | 2010-01-17 21:43:43 +0000 | [diff] [blame] | 502 | OS << ',' << *Symbol << ',' << Size; |
Daniel Dunbar | 7092c7e | 2009-08-30 06:17:16 +0000 | [diff] [blame] | 503 | if (ByteAlignment != 0) |
| 504 | OS << ',' << Log2_32(ByteAlignment); |
Chris Lattner | 9be3fee | 2009-07-10 22:20:30 +0000 | [diff] [blame] | 505 | } |
Chris Lattner | 7d1e49c | 2010-01-22 07:36:39 +0000 | [diff] [blame] | 506 | EmitEOL(); |
Chris Lattner | 9be3fee | 2009-07-10 22:20:30 +0000 | [diff] [blame] | 507 | } |
| 508 | |
Eric Christopher | d04d98d | 2010-05-17 02:13:02 +0000 | [diff] [blame] | 509 | // .tbss sym, size, align |
| 510 | // This depends that the symbol has already been mangled from the original, |
| 511 | // e.g. _a. |
Eric Christopher | 4d01cbe | 2010-05-18 21:16:04 +0000 | [diff] [blame] | 512 | void MCAsmStreamer::EmitTBSSSymbol(const MCSection *Section, MCSymbol *Symbol, |
| 513 | uint64_t Size, unsigned ByteAlignment) { |
Eric Christopher | 482eba0 | 2010-05-14 01:50:28 +0000 | [diff] [blame] | 514 | assert(Symbol != NULL && "Symbol shouldn't be NULL!"); |
Eric Christopher | 4d01cbe | 2010-05-18 21:16:04 +0000 | [diff] [blame] | 515 | // Instead of using the Section we'll just use the shortcut. |
| 516 | // This is a mach-o specific directive and section. |
Eric Christopher | d04d98d | 2010-05-17 02:13:02 +0000 | [diff] [blame] | 517 | OS << ".tbss " << *Symbol << ", " << Size; |
Jim Grosbach | 00545e1 | 2010-09-22 18:16:55 +0000 | [diff] [blame] | 518 | |
Eric Christopher | 4d01cbe | 2010-05-18 21:16:04 +0000 | [diff] [blame] | 519 | // Output align if we have it. We default to 1 so don't bother printing |
| 520 | // that. |
| 521 | if (ByteAlignment > 1) OS << ", " << Log2_32(ByteAlignment); |
Jim Grosbach | 00545e1 | 2010-09-22 18:16:55 +0000 | [diff] [blame] | 522 | |
Eric Christopher | 482eba0 | 2010-05-14 01:50:28 +0000 | [diff] [blame] | 523 | EmitEOL(); |
| 524 | } |
| 525 | |
Chris Lattner | 12e555c | 2010-01-23 00:15:00 +0000 | [diff] [blame] | 526 | static inline char toOctal(int X) { return (X&7)+'0'; } |
| 527 | |
Chris Lattner | a6594fc | 2010-01-25 18:58:59 +0000 | [diff] [blame] | 528 | static void PrintQuotedString(StringRef Data, raw_ostream &OS) { |
| 529 | OS << '"'; |
Jim Grosbach | 00545e1 | 2010-09-22 18:16:55 +0000 | [diff] [blame] | 530 | |
Chris Lattner | a6594fc | 2010-01-25 18:58:59 +0000 | [diff] [blame] | 531 | for (unsigned i = 0, e = Data.size(); i != e; ++i) { |
| 532 | unsigned char C = Data[i]; |
| 533 | if (C == '"' || C == '\\') { |
| 534 | OS << '\\' << (char)C; |
| 535 | continue; |
| 536 | } |
Jim Grosbach | 00545e1 | 2010-09-22 18:16:55 +0000 | [diff] [blame] | 537 | |
Chris Lattner | a6594fc | 2010-01-25 18:58:59 +0000 | [diff] [blame] | 538 | if (isprint((unsigned char)C)) { |
| 539 | OS << (char)C; |
| 540 | continue; |
| 541 | } |
Jim Grosbach | 00545e1 | 2010-09-22 18:16:55 +0000 | [diff] [blame] | 542 | |
Chris Lattner | a6594fc | 2010-01-25 18:58:59 +0000 | [diff] [blame] | 543 | switch (C) { |
| 544 | case '\b': OS << "\\b"; break; |
| 545 | case '\f': OS << "\\f"; break; |
| 546 | case '\n': OS << "\\n"; break; |
| 547 | case '\r': OS << "\\r"; break; |
| 548 | case '\t': OS << "\\t"; break; |
| 549 | default: |
| 550 | OS << '\\'; |
| 551 | OS << toOctal(C >> 6); |
| 552 | OS << toOctal(C >> 3); |
| 553 | OS << toOctal(C >> 0); |
| 554 | break; |
| 555 | } |
| 556 | } |
Jim Grosbach | 00545e1 | 2010-09-22 18:16:55 +0000 | [diff] [blame] | 557 | |
Chris Lattner | a6594fc | 2010-01-25 18:58:59 +0000 | [diff] [blame] | 558 | OS << '"'; |
| 559 | } |
| 560 | |
| 561 | |
Chris Lattner | aaec205 | 2010-01-19 19:46:13 +0000 | [diff] [blame] | 562 | void MCAsmStreamer::EmitBytes(StringRef Data, unsigned AddrSpace) { |
Rafael Espindola | 7768a9d | 2011-02-16 01:08:29 +0000 | [diff] [blame] | 563 | assert(getCurrentSection() && "Cannot emit contents before setting section!"); |
Chris Lattner | 12e555c | 2010-01-23 00:15:00 +0000 | [diff] [blame] | 564 | if (Data.empty()) return; |
Jim Grosbach | 00545e1 | 2010-09-22 18:16:55 +0000 | [diff] [blame] | 565 | |
Chris Lattner | 12e555c | 2010-01-23 00:15:00 +0000 | [diff] [blame] | 566 | if (Data.size() == 1) { |
| 567 | OS << MAI.getData8bitsDirective(AddrSpace); |
| 568 | OS << (unsigned)(unsigned char)Data[0]; |
Chris Lattner | 7d1e49c | 2010-01-22 07:36:39 +0000 | [diff] [blame] | 569 | EmitEOL(); |
Chris Lattner | 12e555c | 2010-01-23 00:15:00 +0000 | [diff] [blame] | 570 | return; |
Chris Lattner | 7d1e49c | 2010-01-22 07:36:39 +0000 | [diff] [blame] | 571 | } |
Chris Lattner | 12e555c | 2010-01-23 00:15:00 +0000 | [diff] [blame] | 572 | |
| 573 | // If the data ends with 0 and the target supports .asciz, use it, otherwise |
| 574 | // use .ascii |
| 575 | if (MAI.getAscizDirective() && Data.back() == 0) { |
| 576 | OS << MAI.getAscizDirective(); |
| 577 | Data = Data.substr(0, Data.size()-1); |
| 578 | } else { |
| 579 | OS << MAI.getAsciiDirective(); |
| 580 | } |
| 581 | |
Chris Lattner | a6594fc | 2010-01-25 18:58:59 +0000 | [diff] [blame] | 582 | OS << ' '; |
| 583 | PrintQuotedString(Data, OS); |
Chris Lattner | 12e555c | 2010-01-23 00:15:00 +0000 | [diff] [blame] | 584 | EmitEOL(); |
Daniel Dunbar | a11af53 | 2009-06-24 01:03:06 +0000 | [diff] [blame] | 585 | } |
| 586 | |
Rafael Espindola | 2df042c | 2010-12-03 02:54:21 +0000 | [diff] [blame] | 587 | void MCAsmStreamer::EmitIntValue(uint64_t Value, unsigned Size, |
| 588 | unsigned AddrSpace) { |
| 589 | EmitValue(MCConstantExpr::Create(Value, getContext()), Size, AddrSpace); |
| 590 | } |
| 591 | |
Rafael Espindola | 89b9372 | 2010-12-10 07:39:47 +0000 | [diff] [blame] | 592 | void MCAsmStreamer::EmitValueImpl(const MCExpr *Value, unsigned Size, |
Rafael Espindola | debd7e4 | 2011-05-01 03:50:49 +0000 | [diff] [blame] | 593 | unsigned AddrSpace) { |
Rafael Espindola | 7768a9d | 2011-02-16 01:08:29 +0000 | [diff] [blame] | 594 | assert(getCurrentSection() && "Cannot emit contents before setting section!"); |
Chris Lattner | 32ae3fe | 2010-01-19 22:03:38 +0000 | [diff] [blame] | 595 | const char *Directive = 0; |
| 596 | switch (Size) { |
| 597 | default: break; |
| 598 | case 1: Directive = MAI.getData8bitsDirective(AddrSpace); break; |
| 599 | case 2: Directive = MAI.getData16bitsDirective(AddrSpace); break; |
| 600 | case 4: Directive = MAI.getData32bitsDirective(AddrSpace); break; |
Chris Lattner | 5eaa54e | 2010-01-20 06:45:39 +0000 | [diff] [blame] | 601 | case 8: |
| 602 | Directive = MAI.getData64bitsDirective(AddrSpace); |
| 603 | // If the target doesn't support 64-bit data, emit as two 32-bit halves. |
| 604 | if (Directive) break; |
Rafael Espindola | ec0b428 | 2010-11-28 23:22:44 +0000 | [diff] [blame] | 605 | int64_t IntValue; |
| 606 | if (!Value->EvaluateAsAbsolute(IntValue)) |
| 607 | report_fatal_error("Don't know how to emit this value."); |
Evan Cheng | 1be0e27 | 2011-07-15 02:09:41 +0000 | [diff] [blame] | 608 | if (getContext().getAsmInfo().isLittleEndian()) { |
Rafael Espindola | ec0b428 | 2010-11-28 23:22:44 +0000 | [diff] [blame] | 609 | EmitIntValue((uint32_t)(IntValue >> 0 ), 4, AddrSpace); |
| 610 | EmitIntValue((uint32_t)(IntValue >> 32), 4, AddrSpace); |
Chris Lattner | 5eaa54e | 2010-01-20 06:45:39 +0000 | [diff] [blame] | 611 | } else { |
Rafael Espindola | ec0b428 | 2010-11-28 23:22:44 +0000 | [diff] [blame] | 612 | EmitIntValue((uint32_t)(IntValue >> 32), 4, AddrSpace); |
| 613 | EmitIntValue((uint32_t)(IntValue >> 0 ), 4, AddrSpace); |
Chris Lattner | 5eaa54e | 2010-01-20 06:45:39 +0000 | [diff] [blame] | 614 | } |
| 615 | return; |
Chris Lattner | 32ae3fe | 2010-01-19 22:03:38 +0000 | [diff] [blame] | 616 | } |
Jim Grosbach | 00545e1 | 2010-09-22 18:16:55 +0000 | [diff] [blame] | 617 | |
Chris Lattner | 32ae3fe | 2010-01-19 22:03:38 +0000 | [diff] [blame] | 618 | assert(Directive && "Invalid size for machine code value!"); |
Chris Lattner | 718fb59 | 2010-01-25 21:28:50 +0000 | [diff] [blame] | 619 | OS << Directive << *Value; |
Chris Lattner | 86e2211 | 2010-01-22 07:29:22 +0000 | [diff] [blame] | 620 | EmitEOL(); |
Daniel Dunbar | a11af53 | 2009-06-24 01:03:06 +0000 | [diff] [blame] | 621 | } |
| 622 | |
Rafael Espindola | e8cfbd8 | 2011-04-21 23:39:26 +0000 | [diff] [blame] | 623 | void MCAsmStreamer::EmitULEB128Value(const MCExpr *Value) { |
Rafael Espindola | a4b23ff | 2010-11-19 04:10:13 +0000 | [diff] [blame] | 624 | int64_t IntValue; |
| 625 | if (Value->EvaluateAsAbsolute(IntValue)) { |
Rafael Espindola | e8cfbd8 | 2011-04-21 23:39:26 +0000 | [diff] [blame] | 626 | EmitULEB128IntValue(IntValue); |
Rafael Espindola | a4b23ff | 2010-11-19 04:10:13 +0000 | [diff] [blame] | 627 | return; |
| 628 | } |
Rafael Espindola | 7387345 | 2010-11-04 18:17:08 +0000 | [diff] [blame] | 629 | assert(MAI.hasLEB128() && "Cannot print a .uleb"); |
| 630 | OS << ".uleb128 " << *Value; |
Rafael Espindola | 3ff5709 | 2010-11-02 17:22:24 +0000 | [diff] [blame] | 631 | EmitEOL(); |
| 632 | } |
| 633 | |
Rafael Espindola | e8cfbd8 | 2011-04-21 23:39:26 +0000 | [diff] [blame] | 634 | void MCAsmStreamer::EmitSLEB128Value(const MCExpr *Value) { |
Rafael Espindola | a4b23ff | 2010-11-19 04:10:13 +0000 | [diff] [blame] | 635 | int64_t IntValue; |
| 636 | if (Value->EvaluateAsAbsolute(IntValue)) { |
Rafael Espindola | e8cfbd8 | 2011-04-21 23:39:26 +0000 | [diff] [blame] | 637 | EmitSLEB128IntValue(IntValue); |
Rafael Espindola | a4b23ff | 2010-11-19 04:10:13 +0000 | [diff] [blame] | 638 | return; |
| 639 | } |
Rafael Espindola | 7387345 | 2010-11-04 18:17:08 +0000 | [diff] [blame] | 640 | assert(MAI.hasLEB128() && "Cannot print a .sleb"); |
| 641 | OS << ".sleb128 " << *Value; |
Rafael Espindola | 3ff5709 | 2010-11-02 17:22:24 +0000 | [diff] [blame] | 642 | EmitEOL(); |
| 643 | } |
| 644 | |
Chris Lattner | 718fb59 | 2010-01-25 21:28:50 +0000 | [diff] [blame] | 645 | void MCAsmStreamer::EmitGPRel32Value(const MCExpr *Value) { |
| 646 | assert(MAI.getGPRel32Directive() != 0); |
| 647 | OS << MAI.getGPRel32Directive() << *Value; |
| 648 | EmitEOL(); |
| 649 | } |
| 650 | |
| 651 | |
Chris Lattner | 6113b3d | 2010-01-19 18:52:28 +0000 | [diff] [blame] | 652 | /// EmitFill - Emit NumBytes bytes worth of the value specified by |
| 653 | /// FillValue. This implements directives such as '.space'. |
Chris Lattner | aaec205 | 2010-01-19 19:46:13 +0000 | [diff] [blame] | 654 | void MCAsmStreamer::EmitFill(uint64_t NumBytes, uint8_t FillValue, |
| 655 | unsigned AddrSpace) { |
Chris Lattner | 8a6d7ac | 2010-01-19 18:58:52 +0000 | [diff] [blame] | 656 | if (NumBytes == 0) return; |
Jim Grosbach | 00545e1 | 2010-09-22 18:16:55 +0000 | [diff] [blame] | 657 | |
Chris Lattner | aaec205 | 2010-01-19 19:46:13 +0000 | [diff] [blame] | 658 | if (AddrSpace == 0) |
| 659 | if (const char *ZeroDirective = MAI.getZeroDirective()) { |
| 660 | OS << ZeroDirective << NumBytes; |
| 661 | if (FillValue != 0) |
| 662 | OS << ',' << (int)FillValue; |
Chris Lattner | 86e2211 | 2010-01-22 07:29:22 +0000 | [diff] [blame] | 663 | EmitEOL(); |
Chris Lattner | aaec205 | 2010-01-19 19:46:13 +0000 | [diff] [blame] | 664 | return; |
| 665 | } |
| 666 | |
| 667 | // Emit a byte at a time. |
| 668 | MCStreamer::EmitFill(NumBytes, FillValue, AddrSpace); |
Chris Lattner | 6113b3d | 2010-01-19 18:52:28 +0000 | [diff] [blame] | 669 | } |
| 670 | |
Daniel Dunbar | 84a2926 | 2009-06-24 19:25:34 +0000 | [diff] [blame] | 671 | void MCAsmStreamer::EmitValueToAlignment(unsigned ByteAlignment, int64_t Value, |
| 672 | unsigned ValueSize, |
| 673 | unsigned MaxBytesToEmit) { |
Chris Lattner | 663c2d2 | 2009-08-19 06:12:02 +0000 | [diff] [blame] | 674 | // Some assemblers don't support non-power of two alignments, so we always |
| 675 | // emit alignments as a power of two if possible. |
| 676 | if (isPowerOf2_32(ByteAlignment)) { |
Chris Lattner | 6e579c6 | 2009-08-19 06:35:36 +0000 | [diff] [blame] | 677 | switch (ValueSize) { |
| 678 | default: llvm_unreachable("Invalid size for machine code value!"); |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 679 | case 1: OS << MAI.getAlignDirective(); break; |
| 680 | // FIXME: use MAI for this! |
Chris Lattner | 6e579c6 | 2009-08-19 06:35:36 +0000 | [diff] [blame] | 681 | case 2: OS << ".p2alignw "; break; |
| 682 | case 4: OS << ".p2alignl "; break; |
| 683 | case 8: llvm_unreachable("Unsupported alignment size!"); |
| 684 | } |
Jim Grosbach | 00545e1 | 2010-09-22 18:16:55 +0000 | [diff] [blame] | 685 | |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 686 | if (MAI.getAlignmentIsInBytes()) |
Chris Lattner | 663c2d2 | 2009-08-19 06:12:02 +0000 | [diff] [blame] | 687 | OS << ByteAlignment; |
| 688 | else |
| 689 | OS << Log2_32(ByteAlignment); |
Daniel Dunbar | 84a2926 | 2009-06-24 19:25:34 +0000 | [diff] [blame] | 690 | |
Chris Lattner | 663c2d2 | 2009-08-19 06:12:02 +0000 | [diff] [blame] | 691 | if (Value || MaxBytesToEmit) { |
Chris Lattner | 579531c | 2009-09-03 04:01:10 +0000 | [diff] [blame] | 692 | OS << ", 0x"; |
| 693 | OS.write_hex(truncateToSize(Value, ValueSize)); |
Chris Lattner | 663c2d2 | 2009-08-19 06:12:02 +0000 | [diff] [blame] | 694 | |
Jim Grosbach | 00545e1 | 2010-09-22 18:16:55 +0000 | [diff] [blame] | 695 | if (MaxBytesToEmit) |
Chris Lattner | 663c2d2 | 2009-08-19 06:12:02 +0000 | [diff] [blame] | 696 | OS << ", " << MaxBytesToEmit; |
| 697 | } |
Chris Lattner | 7d1e49c | 2010-01-22 07:36:39 +0000 | [diff] [blame] | 698 | EmitEOL(); |
Chris Lattner | 663c2d2 | 2009-08-19 06:12:02 +0000 | [diff] [blame] | 699 | return; |
| 700 | } |
Jim Grosbach | 00545e1 | 2010-09-22 18:16:55 +0000 | [diff] [blame] | 701 | |
Chris Lattner | 663c2d2 | 2009-08-19 06:12:02 +0000 | [diff] [blame] | 702 | // Non-power of two alignment. This is not widely supported by assemblers. |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 703 | // FIXME: Parameterize this based on MAI. |
Daniel Dunbar | 84a2926 | 2009-06-24 19:25:34 +0000 | [diff] [blame] | 704 | switch (ValueSize) { |
Chris Lattner | 663c2d2 | 2009-08-19 06:12:02 +0000 | [diff] [blame] | 705 | default: llvm_unreachable("Invalid size for machine code value!"); |
| 706 | case 1: OS << ".balign"; break; |
| 707 | case 2: OS << ".balignw"; break; |
| 708 | case 4: OS << ".balignl"; break; |
| 709 | case 8: llvm_unreachable("Unsupported alignment size!"); |
Daniel Dunbar | 84a2926 | 2009-06-24 19:25:34 +0000 | [diff] [blame] | 710 | } |
| 711 | |
Chris Lattner | 663c2d2 | 2009-08-19 06:12:02 +0000 | [diff] [blame] | 712 | OS << ' ' << ByteAlignment; |
Daniel Dunbar | 304f6a4 | 2009-06-25 21:03:18 +0000 | [diff] [blame] | 713 | OS << ", " << truncateToSize(Value, ValueSize); |
Jim Grosbach | 00545e1 | 2010-09-22 18:16:55 +0000 | [diff] [blame] | 714 | if (MaxBytesToEmit) |
Daniel Dunbar | 84a2926 | 2009-06-24 19:25:34 +0000 | [diff] [blame] | 715 | OS << ", " << MaxBytesToEmit; |
Chris Lattner | 7d1e49c | 2010-01-22 07:36:39 +0000 | [diff] [blame] | 716 | EmitEOL(); |
Daniel Dunbar | 84a2926 | 2009-06-24 19:25:34 +0000 | [diff] [blame] | 717 | } |
| 718 | |
Kevin Enderby | 6e72048 | 2010-02-23 18:26:34 +0000 | [diff] [blame] | 719 | void MCAsmStreamer::EmitCodeAlignment(unsigned ByteAlignment, |
| 720 | unsigned MaxBytesToEmit) { |
Chris Lattner | ec167fd | 2010-02-23 18:44:31 +0000 | [diff] [blame] | 721 | // Emit with a text fill value. |
| 722 | EmitValueToAlignment(ByteAlignment, MAI.getTextAlignFillValue(), |
| 723 | 1, MaxBytesToEmit); |
Kevin Enderby | 6e72048 | 2010-02-23 18:26:34 +0000 | [diff] [blame] | 724 | } |
| 725 | |
Daniel Dunbar | 821e333 | 2009-08-31 08:09:28 +0000 | [diff] [blame] | 726 | void MCAsmStreamer::EmitValueToOffset(const MCExpr *Offset, |
Daniel Dunbar | 84a2926 | 2009-06-24 19:25:34 +0000 | [diff] [blame] | 727 | unsigned char Value) { |
| 728 | // FIXME: Verify that Offset is associated with the current section. |
Chris Lattner | 7d1e49c | 2010-01-22 07:36:39 +0000 | [diff] [blame] | 729 | OS << ".org " << *Offset << ", " << (unsigned) Value; |
| 730 | EmitEOL(); |
Daniel Dunbar | 84a2926 | 2009-06-24 19:25:34 +0000 | [diff] [blame] | 731 | } |
| 732 | |
Chris Lattner | a6594fc | 2010-01-25 18:58:59 +0000 | [diff] [blame] | 733 | |
| 734 | void MCAsmStreamer::EmitFileDirective(StringRef Filename) { |
| 735 | assert(MAI.hasSingleParameterDotFile()); |
| 736 | OS << "\t.file\t"; |
| 737 | PrintQuotedString(Filename, OS); |
| 738 | EmitEOL(); |
| 739 | } |
| 740 | |
Rafael Espindola | af6b5808 | 2010-11-16 21:20:32 +0000 | [diff] [blame] | 741 | bool MCAsmStreamer::EmitDwarfFileDirective(unsigned FileNo, StringRef Filename){ |
Rafael Espindola | 89b9372 | 2010-12-10 07:39:47 +0000 | [diff] [blame] | 742 | if (UseLoc) { |
Rafael Espindola | 195a0ce | 2010-11-19 02:26:16 +0000 | [diff] [blame] | 743 | OS << "\t.file\t" << FileNo << ' '; |
| 744 | PrintQuotedString(Filename, OS); |
| 745 | EmitEOL(); |
| 746 | } |
Rafael Espindola | af6b5808 | 2010-11-16 21:20:32 +0000 | [diff] [blame] | 747 | return this->MCStreamer::EmitDwarfFileDirective(FileNo, Filename); |
| 748 | } |
| 749 | |
| 750 | void MCAsmStreamer::EmitDwarfLocDirective(unsigned FileNo, unsigned Line, |
| 751 | unsigned Column, unsigned Flags, |
| 752 | unsigned Isa, |
Devang Patel | 3f3bf93 | 2011-04-18 20:26:49 +0000 | [diff] [blame] | 753 | unsigned Discriminator, |
| 754 | StringRef FileName) { |
Rafael Espindola | 195a0ce | 2010-11-19 02:26:16 +0000 | [diff] [blame] | 755 | this->MCStreamer::EmitDwarfLocDirective(FileNo, Line, Column, Flags, |
Devang Patel | 3f3bf93 | 2011-04-18 20:26:49 +0000 | [diff] [blame] | 756 | Isa, Discriminator, FileName); |
Rafael Espindola | 89b9372 | 2010-12-10 07:39:47 +0000 | [diff] [blame] | 757 | if (!UseLoc) |
Rafael Espindola | 195a0ce | 2010-11-19 02:26:16 +0000 | [diff] [blame] | 758 | return; |
| 759 | |
Rafael Espindola | af6b5808 | 2010-11-16 21:20:32 +0000 | [diff] [blame] | 760 | OS << "\t.loc\t" << FileNo << " " << Line << " " << Column; |
| 761 | if (Flags & DWARF2_FLAG_BASIC_BLOCK) |
| 762 | OS << " basic_block"; |
| 763 | if (Flags & DWARF2_FLAG_PROLOGUE_END) |
| 764 | OS << " prologue_end"; |
| 765 | if (Flags & DWARF2_FLAG_EPILOGUE_BEGIN) |
| 766 | OS << " epilogue_begin"; |
| 767 | |
| 768 | unsigned OldFlags = getContext().getCurrentDwarfLoc().getFlags(); |
| 769 | if ((Flags & DWARF2_FLAG_IS_STMT) != (OldFlags & DWARF2_FLAG_IS_STMT)) { |
| 770 | OS << " is_stmt "; |
| 771 | |
| 772 | if (Flags & DWARF2_FLAG_IS_STMT) |
| 773 | OS << "1"; |
| 774 | else |
| 775 | OS << "0"; |
| 776 | } |
| 777 | |
| 778 | if (Isa) |
| 779 | OS << "isa " << Isa; |
| 780 | if (Discriminator) |
| 781 | OS << "discriminator " << Discriminator; |
Devang Patel | 3f3bf93 | 2011-04-18 20:26:49 +0000 | [diff] [blame] | 782 | |
| 783 | if (IsVerboseAsm) { |
| 784 | OS.PadToColumn(MAI.getCommentColumn()); |
| 785 | OS << MAI.getCommentString() << ' ' << FileName << ':' |
| 786 | << Line << ':' << Column; |
| 787 | } |
Rafael Espindola | af6b5808 | 2010-11-16 21:20:32 +0000 | [diff] [blame] | 788 | EmitEOL(); |
Chris Lattner | a6594fc | 2010-01-25 18:58:59 +0000 | [diff] [blame] | 789 | } |
| 790 | |
Rafael Espindola | 713c4bf | 2011-05-10 13:39:48 +0000 | [diff] [blame] | 791 | void MCAsmStreamer::EmitCFISections(bool EH, bool Debug) { |
| 792 | MCStreamer::EmitCFISections(EH, Debug); |
| 793 | |
| 794 | if (!UseCFI) |
| 795 | return; |
| 796 | |
| 797 | OS << "\t.cfi_sections "; |
| 798 | if (EH) { |
| 799 | OS << ".eh_frame"; |
| 800 | if (Debug) |
| 801 | OS << ", .debug_frame"; |
| 802 | } else if (Debug) { |
| 803 | OS << ".debug_frame"; |
| 804 | } |
| 805 | |
| 806 | EmitEOL(); |
| 807 | } |
| 808 | |
Rafael Espindola | 066c2f4 | 2011-04-12 23:59:07 +0000 | [diff] [blame] | 809 | void MCAsmStreamer::EmitCFIStartProc() { |
| 810 | MCStreamer::EmitCFIStartProc(); |
Rafael Espindola | cdfecc8 | 2010-11-22 14:27:24 +0000 | [diff] [blame] | 811 | |
Rafael Espindola | f1a5c7e | 2011-04-30 03:44:37 +0000 | [diff] [blame] | 812 | if (!UseCFI) |
| 813 | return; |
| 814 | |
Anton Korobeynikov | c658520 | 2011-01-14 21:57:39 +0000 | [diff] [blame] | 815 | OS << "\t.cfi_startproc"; |
Rafael Espindola | cdfecc8 | 2010-11-22 14:27:24 +0000 | [diff] [blame] | 816 | EmitEOL(); |
Rafael Espindola | cdfecc8 | 2010-11-22 14:27:24 +0000 | [diff] [blame] | 817 | } |
| 818 | |
Rafael Espindola | 066c2f4 | 2011-04-12 23:59:07 +0000 | [diff] [blame] | 819 | void MCAsmStreamer::EmitCFIEndProc() { |
| 820 | MCStreamer::EmitCFIEndProc(); |
Rafael Espindola | cdfecc8 | 2010-11-22 14:27:24 +0000 | [diff] [blame] | 821 | |
Rafael Espindola | f1a5c7e | 2011-04-30 03:44:37 +0000 | [diff] [blame] | 822 | if (!UseCFI) |
| 823 | return; |
| 824 | |
Anton Korobeynikov | c658520 | 2011-01-14 21:57:39 +0000 | [diff] [blame] | 825 | OS << "\t.cfi_endproc"; |
Rafael Espindola | cdfecc8 | 2010-11-22 14:27:24 +0000 | [diff] [blame] | 826 | EmitEOL(); |
Rafael Espindola | cdfecc8 | 2010-11-22 14:27:24 +0000 | [diff] [blame] | 827 | } |
| 828 | |
Rafael Espindola | 6e03294 | 2011-05-30 20:20:15 +0000 | [diff] [blame] | 829 | void MCAsmStreamer::EmitRegisterName(int64_t Register) { |
Akira Hatanaka | 3014b2f | 2011-07-07 20:30:33 +0000 | [diff] [blame] | 830 | if (InstPrinter && !MAI.useDwarfRegNumForCFI()) { |
Evan Cheng | 0e6a052 | 2011-07-18 20:57:22 +0000 | [diff] [blame^] | 831 | const MCRegisterInfo &MRI = getContext().getRegisterInfo(); |
| 832 | unsigned LLVMRegister = MRI.getLLVMRegNum(Register, true); |
Rafael Espindola | cde4ce4 | 2011-06-02 02:34:55 +0000 | [diff] [blame] | 833 | InstPrinter->printRegName(OS, LLVMRegister); |
Rafael Espindola | 6e03294 | 2011-05-30 20:20:15 +0000 | [diff] [blame] | 834 | } else { |
| 835 | OS << Register; |
| 836 | } |
| 837 | } |
| 838 | |
Rafael Espindola | 066c2f4 | 2011-04-12 23:59:07 +0000 | [diff] [blame] | 839 | void MCAsmStreamer::EmitCFIDefCfa(int64_t Register, int64_t Offset) { |
Rafael Espindola | 7f46b08 | 2011-04-29 21:41:06 +0000 | [diff] [blame] | 840 | MCStreamer::EmitCFIDefCfa(Register, Offset); |
| 841 | |
Rafael Espindola | f1a5c7e | 2011-04-30 03:44:37 +0000 | [diff] [blame] | 842 | if (!UseCFI) |
| 843 | return; |
| 844 | |
Rafael Espindola | 6e03294 | 2011-05-30 20:20:15 +0000 | [diff] [blame] | 845 | OS << "\t.cfi_def_cfa "; |
| 846 | EmitRegisterName(Register); |
| 847 | OS << ", " << Offset; |
Rafael Espindola | 7f46b08 | 2011-04-29 21:41:06 +0000 | [diff] [blame] | 848 | EmitEOL(); |
Rafael Espindola | 066c2f4 | 2011-04-12 23:59:07 +0000 | [diff] [blame] | 849 | } |
| 850 | |
| 851 | void MCAsmStreamer::EmitCFIDefCfaOffset(int64_t Offset) { |
| 852 | MCStreamer::EmitCFIDefCfaOffset(Offset); |
Rafael Espindola | cdfecc8 | 2010-11-22 14:27:24 +0000 | [diff] [blame] | 853 | |
Rafael Espindola | f1a5c7e | 2011-04-30 03:44:37 +0000 | [diff] [blame] | 854 | if (!UseCFI) |
| 855 | return; |
| 856 | |
Anton Korobeynikov | c658520 | 2011-01-14 21:57:39 +0000 | [diff] [blame] | 857 | OS << "\t.cfi_def_cfa_offset " << Offset; |
Rafael Espindola | cdfecc8 | 2010-11-22 14:27:24 +0000 | [diff] [blame] | 858 | EmitEOL(); |
Rafael Espindola | cdfecc8 | 2010-11-22 14:27:24 +0000 | [diff] [blame] | 859 | } |
| 860 | |
Rafael Espindola | 066c2f4 | 2011-04-12 23:59:07 +0000 | [diff] [blame] | 861 | void MCAsmStreamer::EmitCFIDefCfaRegister(int64_t Register) { |
| 862 | MCStreamer::EmitCFIDefCfaRegister(Register); |
Rafael Espindola | cdfecc8 | 2010-11-22 14:27:24 +0000 | [diff] [blame] | 863 | |
Rafael Espindola | f1a5c7e | 2011-04-30 03:44:37 +0000 | [diff] [blame] | 864 | if (!UseCFI) |
| 865 | return; |
| 866 | |
Rafael Espindola | 6e03294 | 2011-05-30 20:20:15 +0000 | [diff] [blame] | 867 | OS << "\t.cfi_def_cfa_register "; |
| 868 | EmitRegisterName(Register); |
Rafael Espindola | cdfecc8 | 2010-11-22 14:27:24 +0000 | [diff] [blame] | 869 | EmitEOL(); |
Rafael Espindola | cdfecc8 | 2010-11-22 14:27:24 +0000 | [diff] [blame] | 870 | } |
| 871 | |
Rafael Espindola | 066c2f4 | 2011-04-12 23:59:07 +0000 | [diff] [blame] | 872 | void MCAsmStreamer::EmitCFIOffset(int64_t Register, int64_t Offset) { |
| 873 | this->MCStreamer::EmitCFIOffset(Register, Offset); |
Rafael Espindola | cdfecc8 | 2010-11-22 14:27:24 +0000 | [diff] [blame] | 874 | |
Rafael Espindola | f1a5c7e | 2011-04-30 03:44:37 +0000 | [diff] [blame] | 875 | if (!UseCFI) |
| 876 | return; |
| 877 | |
Rafael Espindola | 6e03294 | 2011-05-30 20:20:15 +0000 | [diff] [blame] | 878 | OS << "\t.cfi_offset "; |
| 879 | EmitRegisterName(Register); |
| 880 | OS << ", " << Offset; |
Rafael Espindola | cdfecc8 | 2010-11-22 14:27:24 +0000 | [diff] [blame] | 881 | EmitEOL(); |
Rafael Espindola | cdfecc8 | 2010-11-22 14:27:24 +0000 | [diff] [blame] | 882 | } |
| 883 | |
Rafael Espindola | 066c2f4 | 2011-04-12 23:59:07 +0000 | [diff] [blame] | 884 | void MCAsmStreamer::EmitCFIPersonality(const MCSymbol *Sym, |
Rafael Espindola | 3a83c40 | 2010-12-27 00:36:05 +0000 | [diff] [blame] | 885 | unsigned Encoding) { |
Rafael Espindola | 066c2f4 | 2011-04-12 23:59:07 +0000 | [diff] [blame] | 886 | MCStreamer::EmitCFIPersonality(Sym, Encoding); |
Rafael Espindola | cdfecc8 | 2010-11-22 14:27:24 +0000 | [diff] [blame] | 887 | |
Rafael Espindola | f1a5c7e | 2011-04-30 03:44:37 +0000 | [diff] [blame] | 888 | if (!UseCFI) |
| 889 | return; |
| 890 | |
Anton Korobeynikov | c658520 | 2011-01-14 21:57:39 +0000 | [diff] [blame] | 891 | OS << "\t.cfi_personality " << Encoding << ", " << *Sym; |
Rafael Espindola | cdfecc8 | 2010-11-22 14:27:24 +0000 | [diff] [blame] | 892 | EmitEOL(); |
Rafael Espindola | cdfecc8 | 2010-11-22 14:27:24 +0000 | [diff] [blame] | 893 | } |
| 894 | |
Rafael Espindola | 066c2f4 | 2011-04-12 23:59:07 +0000 | [diff] [blame] | 895 | void MCAsmStreamer::EmitCFILsda(const MCSymbol *Sym, unsigned Encoding) { |
| 896 | MCStreamer::EmitCFILsda(Sym, Encoding); |
Rafael Espindola | cdfecc8 | 2010-11-22 14:27:24 +0000 | [diff] [blame] | 897 | |
Rafael Espindola | f1a5c7e | 2011-04-30 03:44:37 +0000 | [diff] [blame] | 898 | if (!UseCFI) |
| 899 | return; |
| 900 | |
Anton Korobeynikov | c658520 | 2011-01-14 21:57:39 +0000 | [diff] [blame] | 901 | OS << "\t.cfi_lsda " << Encoding << ", " << *Sym; |
Rafael Espindola | cdfecc8 | 2010-11-22 14:27:24 +0000 | [diff] [blame] | 902 | EmitEOL(); |
Rafael Espindola | 066c2f4 | 2011-04-12 23:59:07 +0000 | [diff] [blame] | 903 | } |
Rafael Espindola | cdfecc8 | 2010-11-22 14:27:24 +0000 | [diff] [blame] | 904 | |
Rafael Espindola | 066c2f4 | 2011-04-12 23:59:07 +0000 | [diff] [blame] | 905 | void MCAsmStreamer::EmitCFIRememberState() { |
| 906 | MCStreamer::EmitCFIRememberState(); |
| 907 | |
Rafael Espindola | f1a5c7e | 2011-04-30 03:44:37 +0000 | [diff] [blame] | 908 | if (!UseCFI) |
| 909 | return; |
| 910 | |
Rafael Espindola | 066c2f4 | 2011-04-12 23:59:07 +0000 | [diff] [blame] | 911 | OS << "\t.cfi_remember_state"; |
| 912 | EmitEOL(); |
| 913 | } |
| 914 | |
| 915 | void MCAsmStreamer::EmitCFIRestoreState() { |
| 916 | MCStreamer::EmitCFIRestoreState(); |
| 917 | |
Rafael Espindola | f1a5c7e | 2011-04-30 03:44:37 +0000 | [diff] [blame] | 918 | if (!UseCFI) |
| 919 | return; |
| 920 | |
Rafael Espindola | 066c2f4 | 2011-04-12 23:59:07 +0000 | [diff] [blame] | 921 | OS << "\t.cfi_restore_state"; |
| 922 | EmitEOL(); |
| 923 | } |
| 924 | |
| 925 | void MCAsmStreamer::EmitCFISameValue(int64_t Register) { |
| 926 | MCStreamer::EmitCFISameValue(Register); |
| 927 | |
Rafael Espindola | f1a5c7e | 2011-04-30 03:44:37 +0000 | [diff] [blame] | 928 | if (!UseCFI) |
| 929 | return; |
| 930 | |
Rafael Espindola | 6e03294 | 2011-05-30 20:20:15 +0000 | [diff] [blame] | 931 | OS << "\t.cfi_same_value "; |
| 932 | EmitRegisterName(Register); |
Rafael Espindola | 066c2f4 | 2011-04-12 23:59:07 +0000 | [diff] [blame] | 933 | EmitEOL(); |
| 934 | } |
| 935 | |
| 936 | void MCAsmStreamer::EmitCFIRelOffset(int64_t Register, int64_t Offset) { |
| 937 | MCStreamer::EmitCFIRelOffset(Register, Offset); |
| 938 | |
Rafael Espindola | f1a5c7e | 2011-04-30 03:44:37 +0000 | [diff] [blame] | 939 | if (!UseCFI) |
| 940 | return; |
| 941 | |
Rafael Espindola | 6e03294 | 2011-05-30 20:20:15 +0000 | [diff] [blame] | 942 | OS << "\t.cfi_rel_offset "; |
| 943 | EmitRegisterName(Register); |
| 944 | OS << ", " << Offset; |
Rafael Espindola | 066c2f4 | 2011-04-12 23:59:07 +0000 | [diff] [blame] | 945 | EmitEOL(); |
| 946 | } |
| 947 | |
| 948 | void MCAsmStreamer::EmitCFIAdjustCfaOffset(int64_t Adjustment) { |
| 949 | MCStreamer::EmitCFIAdjustCfaOffset(Adjustment); |
| 950 | |
Rafael Espindola | f1a5c7e | 2011-04-30 03:44:37 +0000 | [diff] [blame] | 951 | if (!UseCFI) |
| 952 | return; |
| 953 | |
Rafael Espindola | 066c2f4 | 2011-04-12 23:59:07 +0000 | [diff] [blame] | 954 | OS << "\t.cfi_adjust_cfa_offset " << Adjustment; |
| 955 | EmitEOL(); |
Rafael Espindola | cdfecc8 | 2010-11-22 14:27:24 +0000 | [diff] [blame] | 956 | } |
| 957 | |
Charles Davis | fbc539f | 2011-05-22 21:12:15 +0000 | [diff] [blame] | 958 | void MCAsmStreamer::EmitWin64EHStartProc(const MCSymbol *Symbol) { |
Charles Davis | cde87e2 | 2011-05-20 18:19:22 +0000 | [diff] [blame] | 959 | MCStreamer::EmitWin64EHStartProc(Symbol); |
| 960 | |
Charles Davis | 440596f | 2011-05-19 17:46:39 +0000 | [diff] [blame] | 961 | OS << ".seh_proc " << *Symbol; |
Charles Davis | 0e30f02 | 2011-05-18 04:58:05 +0000 | [diff] [blame] | 962 | EmitEOL(); |
| 963 | } |
| 964 | |
Charles Davis | 8b3e5e5 | 2011-05-18 22:13:51 +0000 | [diff] [blame] | 965 | void MCAsmStreamer::EmitWin64EHEndProc() { |
Charles Davis | cde87e2 | 2011-05-20 18:19:22 +0000 | [diff] [blame] | 966 | MCStreamer::EmitWin64EHEndProc(); |
| 967 | |
Charles Davis | 440596f | 2011-05-19 17:46:39 +0000 | [diff] [blame] | 968 | OS << "\t.seh_endproc"; |
Charles Davis | 0e30f02 | 2011-05-18 04:58:05 +0000 | [diff] [blame] | 969 | EmitEOL(); |
| 970 | } |
| 971 | |
Charles Davis | 8b3e5e5 | 2011-05-18 22:13:51 +0000 | [diff] [blame] | 972 | void MCAsmStreamer::EmitWin64EHStartChained() { |
Charles Davis | cde87e2 | 2011-05-20 18:19:22 +0000 | [diff] [blame] | 973 | MCStreamer::EmitWin64EHStartChained(); |
| 974 | |
Charles Davis | 440596f | 2011-05-19 17:46:39 +0000 | [diff] [blame] | 975 | OS << "\t.seh_startchained"; |
Charles Davis | f070901 | 2011-05-18 20:54:10 +0000 | [diff] [blame] | 976 | EmitEOL(); |
| 977 | } |
| 978 | |
Charles Davis | 8b3e5e5 | 2011-05-18 22:13:51 +0000 | [diff] [blame] | 979 | void MCAsmStreamer::EmitWin64EHEndChained() { |
Charles Davis | cde87e2 | 2011-05-20 18:19:22 +0000 | [diff] [blame] | 980 | MCStreamer::EmitWin64EHEndChained(); |
| 981 | |
Charles Davis | 440596f | 2011-05-19 17:46:39 +0000 | [diff] [blame] | 982 | OS << "\t.seh_endchained"; |
Charles Davis | f070901 | 2011-05-18 20:54:10 +0000 | [diff] [blame] | 983 | EmitEOL(); |
| 984 | } |
| 985 | |
Charles Davis | 440596f | 2011-05-19 17:46:39 +0000 | [diff] [blame] | 986 | void MCAsmStreamer::EmitWin64EHHandler(const MCSymbol *Sym, bool Unwind, |
| 987 | bool Except) { |
Charles Davis | cde87e2 | 2011-05-20 18:19:22 +0000 | [diff] [blame] | 988 | MCStreamer::EmitWin64EHHandler(Sym, Unwind, Except); |
| 989 | |
Charles Davis | 440596f | 2011-05-19 17:46:39 +0000 | [diff] [blame] | 990 | OS << "\t.seh_handler " << *Sym; |
| 991 | if (Unwind) |
| 992 | OS << ", @unwind"; |
| 993 | if (Except) |
| 994 | OS << ", @except"; |
Charles Davis | f070901 | 2011-05-18 20:54:10 +0000 | [diff] [blame] | 995 | EmitEOL(); |
| 996 | } |
| 997 | |
Charles Davis | 440596f | 2011-05-19 17:46:39 +0000 | [diff] [blame] | 998 | void MCAsmStreamer::EmitWin64EHHandlerData() { |
Charles Davis | cde87e2 | 2011-05-20 18:19:22 +0000 | [diff] [blame] | 999 | MCStreamer::EmitWin64EHHandlerData(); |
| 1000 | |
Charles Davis | 410ef2b | 2011-05-25 21:43:45 +0000 | [diff] [blame] | 1001 | // Switch sections. Don't call SwitchSection directly, because that will |
| 1002 | // cause the section switch to be visible in the emitted assembly. |
| 1003 | // We only do this so the section switch that terminates the handler |
| 1004 | // data block is visible. |
Charles Davis | 7b06b73 | 2011-05-27 19:09:24 +0000 | [diff] [blame] | 1005 | MCWin64EHUnwindInfo *CurFrame = getCurrentW64UnwindInfo(); |
| 1006 | StringRef suffix=MCWin64EHUnwindEmitter::GetSectionSuffix(CurFrame->Function); |
Charles Davis | 410ef2b | 2011-05-25 21:43:45 +0000 | [diff] [blame] | 1007 | const MCSection *xdataSect = |
Charles Davis | 7b06b73 | 2011-05-27 19:09:24 +0000 | [diff] [blame] | 1008 | getContext().getTargetAsmInfo().getWin64EHTableSection(suffix); |
Charles Davis | 410ef2b | 2011-05-25 21:43:45 +0000 | [diff] [blame] | 1009 | if (xdataSect) |
| 1010 | SwitchSectionNoChange(xdataSect); |
| 1011 | |
Charles Davis | 440596f | 2011-05-19 17:46:39 +0000 | [diff] [blame] | 1012 | OS << "\t.seh_handlerdata"; |
Charles Davis | f070901 | 2011-05-18 20:54:10 +0000 | [diff] [blame] | 1013 | EmitEOL(); |
| 1014 | } |
| 1015 | |
Charles Davis | c3b1628 | 2011-05-19 19:35:55 +0000 | [diff] [blame] | 1016 | void MCAsmStreamer::EmitWin64EHPushReg(unsigned Register) { |
Charles Davis | cde87e2 | 2011-05-20 18:19:22 +0000 | [diff] [blame] | 1017 | MCStreamer::EmitWin64EHPushReg(Register); |
| 1018 | |
Charles Davis | 440596f | 2011-05-19 17:46:39 +0000 | [diff] [blame] | 1019 | OS << "\t.seh_pushreg " << Register; |
Charles Davis | 0e30f02 | 2011-05-18 04:58:05 +0000 | [diff] [blame] | 1020 | EmitEOL(); |
| 1021 | } |
| 1022 | |
Charles Davis | c3b1628 | 2011-05-19 19:35:55 +0000 | [diff] [blame] | 1023 | void MCAsmStreamer::EmitWin64EHSetFrame(unsigned Register, unsigned Offset) { |
Charles Davis | cde87e2 | 2011-05-20 18:19:22 +0000 | [diff] [blame] | 1024 | MCStreamer::EmitWin64EHSetFrame(Register, Offset); |
| 1025 | |
Charles Davis | 440596f | 2011-05-19 17:46:39 +0000 | [diff] [blame] | 1026 | OS << "\t.seh_setframe " << Register << ", " << Offset; |
Charles Davis | 0e30f02 | 2011-05-18 04:58:05 +0000 | [diff] [blame] | 1027 | EmitEOL(); |
| 1028 | } |
| 1029 | |
Charles Davis | c3b1628 | 2011-05-19 19:35:55 +0000 | [diff] [blame] | 1030 | void MCAsmStreamer::EmitWin64EHAllocStack(unsigned Size) { |
Charles Davis | cde87e2 | 2011-05-20 18:19:22 +0000 | [diff] [blame] | 1031 | MCStreamer::EmitWin64EHAllocStack(Size); |
| 1032 | |
Charles Davis | 440596f | 2011-05-19 17:46:39 +0000 | [diff] [blame] | 1033 | OS << "\t.seh_stackalloc " << Size; |
Charles Davis | 0e30f02 | 2011-05-18 04:58:05 +0000 | [diff] [blame] | 1034 | EmitEOL(); |
| 1035 | } |
| 1036 | |
Charles Davis | c3b1628 | 2011-05-19 19:35:55 +0000 | [diff] [blame] | 1037 | void MCAsmStreamer::EmitWin64EHSaveReg(unsigned Register, unsigned Offset) { |
Charles Davis | cde87e2 | 2011-05-20 18:19:22 +0000 | [diff] [blame] | 1038 | MCStreamer::EmitWin64EHSaveReg(Register, Offset); |
| 1039 | |
Charles Davis | 440596f | 2011-05-19 17:46:39 +0000 | [diff] [blame] | 1040 | OS << "\t.seh_savereg " << Register << ", " << Offset; |
| 1041 | EmitEOL(); |
| 1042 | } |
| 1043 | |
Charles Davis | c3b1628 | 2011-05-19 19:35:55 +0000 | [diff] [blame] | 1044 | void MCAsmStreamer::EmitWin64EHSaveXMM(unsigned Register, unsigned Offset) { |
Charles Davis | cde87e2 | 2011-05-20 18:19:22 +0000 | [diff] [blame] | 1045 | MCStreamer::EmitWin64EHSaveXMM(Register, Offset); |
| 1046 | |
Charles Davis | 440596f | 2011-05-19 17:46:39 +0000 | [diff] [blame] | 1047 | OS << "\t.seh_savexmm " << Register << ", " << Offset; |
Charles Davis | 0e30f02 | 2011-05-18 04:58:05 +0000 | [diff] [blame] | 1048 | EmitEOL(); |
| 1049 | } |
| 1050 | |
Charles Davis | 8b3e5e5 | 2011-05-18 22:13:51 +0000 | [diff] [blame] | 1051 | void MCAsmStreamer::EmitWin64EHPushFrame(bool Code) { |
Charles Davis | cde87e2 | 2011-05-20 18:19:22 +0000 | [diff] [blame] | 1052 | MCStreamer::EmitWin64EHPushFrame(Code); |
| 1053 | |
Charles Davis | 440596f | 2011-05-19 17:46:39 +0000 | [diff] [blame] | 1054 | OS << "\t.seh_pushframe"; |
Charles Davis | 0e30f02 | 2011-05-18 04:58:05 +0000 | [diff] [blame] | 1055 | if (Code) |
Charles Davis | 440596f | 2011-05-19 17:46:39 +0000 | [diff] [blame] | 1056 | OS << " @code"; |
Charles Davis | 0e30f02 | 2011-05-18 04:58:05 +0000 | [diff] [blame] | 1057 | EmitEOL(); |
| 1058 | } |
| 1059 | |
Charles Davis | 8b3e5e5 | 2011-05-18 22:13:51 +0000 | [diff] [blame] | 1060 | void MCAsmStreamer::EmitWin64EHEndProlog(void) { |
Charles Davis | cde87e2 | 2011-05-20 18:19:22 +0000 | [diff] [blame] | 1061 | MCStreamer::EmitWin64EHEndProlog(); |
| 1062 | |
Charles Davis | 440596f | 2011-05-19 17:46:39 +0000 | [diff] [blame] | 1063 | OS << "\t.seh_endprologue"; |
Charles Davis | 0e30f02 | 2011-05-18 04:58:05 +0000 | [diff] [blame] | 1064 | EmitEOL(); |
| 1065 | } |
| 1066 | |
Daniel Dunbar | 6b71653 | 2010-02-09 23:00:14 +0000 | [diff] [blame] | 1067 | void MCAsmStreamer::AddEncodingComment(const MCInst &Inst) { |
| 1068 | raw_ostream &OS = GetCommentOS(); |
| 1069 | SmallString<256> Code; |
| 1070 | SmallVector<MCFixup, 4> Fixups; |
| 1071 | raw_svector_ostream VecOS(Code); |
| 1072 | Emitter->EncodeInstruction(Inst, VecOS, Fixups); |
| 1073 | VecOS.flush(); |
Chris Lattner | a6594fc | 2010-01-25 18:58:59 +0000 | [diff] [blame] | 1074 | |
Daniel Dunbar | 6b71653 | 2010-02-09 23:00:14 +0000 | [diff] [blame] | 1075 | // If we are showing fixups, create symbolic markers in the encoded |
| 1076 | // representation. We do this by making a per-bit map to the fixup item index, |
| 1077 | // then trying to display it as nicely as possible. |
Daniel Dunbar | 5532cf4 | 2010-02-10 01:41:14 +0000 | [diff] [blame] | 1078 | SmallVector<uint8_t, 64> FixupMap; |
| 1079 | FixupMap.resize(Code.size() * 8); |
Daniel Dunbar | 6b71653 | 2010-02-09 23:00:14 +0000 | [diff] [blame] | 1080 | for (unsigned i = 0, e = Code.size() * 8; i != e; ++i) |
| 1081 | FixupMap[i] = 0; |
| 1082 | |
| 1083 | for (unsigned i = 0, e = Fixups.size(); i != e; ++i) { |
| 1084 | MCFixup &F = Fixups[i]; |
Daniel Dunbar | 2761fc4 | 2010-12-16 03:20:06 +0000 | [diff] [blame] | 1085 | const MCFixupKindInfo &Info = AsmBackend->getFixupKindInfo(F.getKind()); |
Daniel Dunbar | 6b71653 | 2010-02-09 23:00:14 +0000 | [diff] [blame] | 1086 | for (unsigned j = 0; j != Info.TargetSize; ++j) { |
| 1087 | unsigned Index = F.getOffset() * 8 + Info.TargetOffset + j; |
| 1088 | assert(Index < Code.size() * 8 && "Invalid offset in fixup!"); |
| 1089 | FixupMap[Index] = 1 + i; |
| 1090 | } |
| 1091 | } |
| 1092 | |
Evan Cheng | 5c2eef6 | 2011-07-08 22:49:42 +0000 | [diff] [blame] | 1093 | // FIXME: Note the fixup comments for Thumb2 are completely bogus since the |
Evan Cheng | 8fbbd1c | 2011-01-13 23:27:39 +0000 | [diff] [blame] | 1094 | // high order halfword of a 32-bit Thumb2 instruction is emitted first. |
Daniel Dunbar | 6b71653 | 2010-02-09 23:00:14 +0000 | [diff] [blame] | 1095 | OS << "encoding: ["; |
| 1096 | for (unsigned i = 0, e = Code.size(); i != e; ++i) { |
| 1097 | if (i) |
| 1098 | OS << ','; |
| 1099 | |
| 1100 | // See if all bits are the same map entry. |
| 1101 | uint8_t MapEntry = FixupMap[i * 8 + 0]; |
| 1102 | for (unsigned j = 1; j != 8; ++j) { |
| 1103 | if (FixupMap[i * 8 + j] == MapEntry) |
| 1104 | continue; |
| 1105 | |
| 1106 | MapEntry = uint8_t(~0U); |
| 1107 | break; |
| 1108 | } |
| 1109 | |
| 1110 | if (MapEntry != uint8_t(~0U)) { |
| 1111 | if (MapEntry == 0) { |
| 1112 | OS << format("0x%02x", uint8_t(Code[i])); |
| 1113 | } else { |
Evan Cheng | 82caf1a | 2011-01-13 21:45:26 +0000 | [diff] [blame] | 1114 | if (Code[i]) { |
Evan Cheng | 8fbbd1c | 2011-01-13 23:27:39 +0000 | [diff] [blame] | 1115 | // FIXME: Some of the 8 bits require fix up. |
Evan Cheng | 82caf1a | 2011-01-13 21:45:26 +0000 | [diff] [blame] | 1116 | OS << format("0x%02x", uint8_t(Code[i])) << '\'' |
| 1117 | << char('A' + MapEntry - 1) << '\''; |
| 1118 | } else |
| 1119 | OS << char('A' + MapEntry - 1); |
Daniel Dunbar | 6b71653 | 2010-02-09 23:00:14 +0000 | [diff] [blame] | 1120 | } |
| 1121 | } else { |
| 1122 | // Otherwise, write out in binary. |
| 1123 | OS << "0b"; |
Jay Foad | 95c3e48 | 2011-06-23 09:09:15 +0000 | [diff] [blame] | 1124 | for (unsigned j = 8; j--;) { |
Daniel Dunbar | 6b71653 | 2010-02-09 23:00:14 +0000 | [diff] [blame] | 1125 | unsigned Bit = (Code[i] >> j) & 1; |
NAKAMURA Takumi | d645151 | 2011-03-27 01:44:40 +0000 | [diff] [blame] | 1126 | |
Chris Lattner | 3170a3b | 2010-11-15 05:56:19 +0000 | [diff] [blame] | 1127 | unsigned FixupBit; |
Evan Cheng | 1be0e27 | 2011-07-15 02:09:41 +0000 | [diff] [blame] | 1128 | if (getContext().getAsmInfo().isLittleEndian()) |
Chris Lattner | 3170a3b | 2010-11-15 05:56:19 +0000 | [diff] [blame] | 1129 | FixupBit = i * 8 + j; |
| 1130 | else |
| 1131 | FixupBit = i * 8 + (7-j); |
NAKAMURA Takumi | d645151 | 2011-03-27 01:44:40 +0000 | [diff] [blame] | 1132 | |
Jay Foad | 95c3e48 | 2011-06-23 09:09:15 +0000 | [diff] [blame] | 1133 | if (uint8_t MapEntry = FixupMap[FixupBit]) { |
| 1134 | assert(Bit == 0 && "Encoder wrote into fixed up bit!"); |
| 1135 | OS << char('A' + MapEntry - 1); |
Daniel Dunbar | 6b71653 | 2010-02-09 23:00:14 +0000 | [diff] [blame] | 1136 | } else |
| 1137 | OS << Bit; |
| 1138 | } |
| 1139 | } |
| 1140 | } |
| 1141 | OS << "]\n"; |
| 1142 | |
| 1143 | for (unsigned i = 0, e = Fixups.size(); i != e; ++i) { |
| 1144 | MCFixup &F = Fixups[i]; |
Daniel Dunbar | 2761fc4 | 2010-12-16 03:20:06 +0000 | [diff] [blame] | 1145 | const MCFixupKindInfo &Info = AsmBackend->getFixupKindInfo(F.getKind()); |
Daniel Dunbar | 6b71653 | 2010-02-09 23:00:14 +0000 | [diff] [blame] | 1146 | OS << " fixup " << char('A' + i) << " - " << "offset: " << F.getOffset() |
Daniel Dunbar | 5d5a1e1 | 2010-02-10 04:47:08 +0000 | [diff] [blame] | 1147 | << ", value: " << *F.getValue() << ", kind: " << Info.Name << "\n"; |
Daniel Dunbar | 6b71653 | 2010-02-09 23:00:14 +0000 | [diff] [blame] | 1148 | } |
| 1149 | } |
| 1150 | |
Anton Korobeynikov | b5e16af | 2011-03-05 18:43:15 +0000 | [diff] [blame] | 1151 | void MCAsmStreamer::EmitFnStart() { |
| 1152 | OS << "\t.fnstart"; |
| 1153 | EmitEOL(); |
| 1154 | } |
| 1155 | |
| 1156 | void MCAsmStreamer::EmitFnEnd() { |
| 1157 | OS << "\t.fnend"; |
| 1158 | EmitEOL(); |
| 1159 | } |
| 1160 | |
| 1161 | void MCAsmStreamer::EmitCantUnwind() { |
| 1162 | OS << "\t.cantunwind"; |
| 1163 | EmitEOL(); |
| 1164 | } |
| 1165 | |
| 1166 | void MCAsmStreamer::EmitHandlerData() { |
| 1167 | OS << "\t.handlerdata"; |
| 1168 | EmitEOL(); |
| 1169 | } |
| 1170 | |
| 1171 | void MCAsmStreamer::EmitPersonality(const MCSymbol *Personality) { |
| 1172 | OS << "\t.personality " << Personality->getName(); |
| 1173 | EmitEOL(); |
| 1174 | } |
| 1175 | |
Anton Korobeynikov | 57caad7 | 2011-03-05 18:43:32 +0000 | [diff] [blame] | 1176 | void MCAsmStreamer::EmitSetFP(unsigned FpReg, unsigned SpReg, int64_t Offset) { |
Rafael Espindola | cde4ce4 | 2011-06-02 02:34:55 +0000 | [diff] [blame] | 1177 | OS << "\t.setfp\t"; |
| 1178 | InstPrinter->printRegName(OS, FpReg); |
| 1179 | OS << ", "; |
| 1180 | InstPrinter->printRegName(OS, SpReg); |
Anton Korobeynikov | 57caad7 | 2011-03-05 18:43:32 +0000 | [diff] [blame] | 1181 | if (Offset) |
| 1182 | OS << ", #" << Offset; |
| 1183 | EmitEOL(); |
| 1184 | } |
| 1185 | |
| 1186 | void MCAsmStreamer::EmitPad(int64_t Offset) { |
| 1187 | OS << "\t.pad\t#" << Offset; |
| 1188 | EmitEOL(); |
| 1189 | } |
| 1190 | |
| 1191 | void MCAsmStreamer::EmitRegSave(const SmallVectorImpl<unsigned> &RegList, |
| 1192 | bool isVector) { |
| 1193 | assert(RegList.size() && "RegList should not be empty"); |
| 1194 | if (isVector) |
| 1195 | OS << "\t.vsave\t{"; |
| 1196 | else |
| 1197 | OS << "\t.save\t{"; |
| 1198 | |
Rafael Espindola | cde4ce4 | 2011-06-02 02:34:55 +0000 | [diff] [blame] | 1199 | InstPrinter->printRegName(OS, RegList[0]); |
Anton Korobeynikov | 57caad7 | 2011-03-05 18:43:32 +0000 | [diff] [blame] | 1200 | |
Rafael Espindola | cde4ce4 | 2011-06-02 02:34:55 +0000 | [diff] [blame] | 1201 | for (unsigned i = 1, e = RegList.size(); i != e; ++i) { |
| 1202 | OS << ", "; |
| 1203 | InstPrinter->printRegName(OS, RegList[i]); |
| 1204 | } |
Anton Korobeynikov | 57caad7 | 2011-03-05 18:43:32 +0000 | [diff] [blame] | 1205 | |
| 1206 | OS << "}"; |
| 1207 | EmitEOL(); |
| 1208 | } |
| 1209 | |
Daniel Dunbar | 6b71653 | 2010-02-09 23:00:14 +0000 | [diff] [blame] | 1210 | void MCAsmStreamer::EmitInstruction(const MCInst &Inst) { |
Rafael Espindola | 7768a9d | 2011-02-16 01:08:29 +0000 | [diff] [blame] | 1211 | assert(getCurrentSection() && "Cannot emit contents before setting section!"); |
Daniel Dunbar | 6b71653 | 2010-02-09 23:00:14 +0000 | [diff] [blame] | 1212 | |
| 1213 | // Show the encoding in a comment if we have a code emitter. |
| 1214 | if (Emitter) |
| 1215 | AddEncodingComment(Inst); |
| 1216 | |
Chris Lattner | 30d9a64 | 2010-02-09 00:54:51 +0000 | [diff] [blame] | 1217 | // Show the MCInst if enabled. |
Daniel Dunbar | c9adb8c | 2010-05-26 15:18:13 +0000 | [diff] [blame] | 1218 | if (ShowInst) { |
Daniel Dunbar | 67c076c | 2010-03-22 21:49:34 +0000 | [diff] [blame] | 1219 | Inst.dump_pretty(GetCommentOS(), &MAI, InstPrinter.get(), "\n "); |
Daniel Dunbar | c9adb8c | 2010-05-26 15:18:13 +0000 | [diff] [blame] | 1220 | GetCommentOS() << "\n"; |
| 1221 | } |
| 1222 | |
Daniel Dunbar | 67c076c | 2010-03-22 21:49:34 +0000 | [diff] [blame] | 1223 | // If we have an AsmPrinter, use that to print, otherwise print the MCInst. |
Daniel Dunbar | 9dee8e3 | 2010-02-03 18:18:30 +0000 | [diff] [blame] | 1224 | if (InstPrinter) |
Chris Lattner | d374087 | 2010-04-04 05:04:31 +0000 | [diff] [blame] | 1225 | InstPrinter->printInst(&Inst, OS); |
Daniel Dunbar | 9dee8e3 | 2010-02-03 18:18:30 +0000 | [diff] [blame] | 1226 | else |
| 1227 | Inst.print(OS, &MAI); |
Chris Lattner | 7d1e49c | 2010-01-22 07:36:39 +0000 | [diff] [blame] | 1228 | EmitEOL(); |
Daniel Dunbar | a11af53 | 2009-06-24 01:03:06 +0000 | [diff] [blame] | 1229 | } |
| 1230 | |
Jim Grosbach | bd4ec84 | 2010-09-22 18:18:30 +0000 | [diff] [blame] | 1231 | /// EmitRawText - If this file is backed by an assembly streamer, this dumps |
Chris Lattner | 91bead7 | 2010-04-03 21:35:55 +0000 | [diff] [blame] | 1232 | /// the specified string in the output .s file. This capability is |
| 1233 | /// indicated by the hasRawTextSupport() predicate. |
| 1234 | void MCAsmStreamer::EmitRawText(StringRef String) { |
Chris Lattner | d5928dc | 2010-04-03 22:06:56 +0000 | [diff] [blame] | 1235 | if (!String.empty() && String.back() == '\n') |
| 1236 | String = String.substr(0, String.size()-1); |
Chris Lattner | 91bead7 | 2010-04-03 21:35:55 +0000 | [diff] [blame] | 1237 | OS << String; |
Chris Lattner | d5928dc | 2010-04-03 22:06:56 +0000 | [diff] [blame] | 1238 | EmitEOL(); |
Chris Lattner | 91bead7 | 2010-04-03 21:35:55 +0000 | [diff] [blame] | 1239 | } |
| 1240 | |
Daniel Dunbar | a11af53 | 2009-06-24 01:03:06 +0000 | [diff] [blame] | 1241 | void MCAsmStreamer::Finish() { |
Rafael Espindola | 195a0ce | 2010-11-19 02:26:16 +0000 | [diff] [blame] | 1242 | // Dump out the dwarf file & directory tables and line tables. |
Rafael Espindola | 89b9372 | 2010-12-10 07:39:47 +0000 | [diff] [blame] | 1243 | if (getContext().hasDwarfFiles() && !UseLoc) |
| 1244 | MCDwarfFileTable::Emit(this); |
Rafael Espindola | 5426a9e | 2011-05-01 04:49:54 +0000 | [diff] [blame] | 1245 | |
Rafael Espindola | c25dad8 | 2011-05-10 03:14:15 +0000 | [diff] [blame] | 1246 | if (!UseCFI) |
| 1247 | EmitFrames(false); |
Daniel Dunbar | a11af53 | 2009-06-24 01:03:06 +0000 | [diff] [blame] | 1248 | } |
Chris Lattner | 86e2211 | 2010-01-22 07:29:22 +0000 | [diff] [blame] | 1249 | MCStreamer *llvm::createAsmStreamer(MCContext &Context, |
| 1250 | formatted_raw_ostream &OS, |
Rafael Espindola | 89b9372 | 2010-12-10 07:39:47 +0000 | [diff] [blame] | 1251 | bool isVerboseAsm, bool useLoc, |
Bill Wendling | 916a94b | 2011-06-17 20:35:21 +0000 | [diff] [blame] | 1252 | bool useCFI, MCInstPrinter *IP, |
| 1253 | MCCodeEmitter *CE, TargetAsmBackend *TAB, |
Bill Wendling | e266ce6 | 2011-06-17 20:55:01 +0000 | [diff] [blame] | 1254 | bool ShowInst) { |
Rafael Espindola | f1a5c7e | 2011-04-30 03:44:37 +0000 | [diff] [blame] | 1255 | return new MCAsmStreamer(Context, OS, isVerboseAsm, useLoc, useCFI, |
Daniel Dunbar | 745dacc | 2010-12-16 03:05:59 +0000 | [diff] [blame] | 1256 | IP, CE, TAB, ShowInst); |
Daniel Dunbar | a11af53 | 2009-06-24 01:03:06 +0000 | [diff] [blame] | 1257 | } |