Daniel Dunbar | a11af53 | 2009-06-24 01:03:06 +0000 | [diff] [blame] | 1 | //===- lib/MC/MCStreamer.cpp - Streaming Machine Code 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 | |
Rafael Espindola | 0bbe0b4 | 2010-12-06 17:27:56 +0000 | [diff] [blame] | 10 | #include "llvm/MC/MCAsmInfo.h" |
Rafael Espindola | af6b5808 | 2010-11-16 21:20:32 +0000 | [diff] [blame] | 11 | #include "llvm/MC/MCContext.h" |
Daniel Dunbar | a11af53 | 2009-06-24 01:03:06 +0000 | [diff] [blame] | 12 | #include "llvm/MC/MCStreamer.h" |
Chris Lattner | ddf6bdd | 2010-01-19 18:45:47 +0000 | [diff] [blame] | 13 | #include "llvm/MC/MCExpr.h" |
Kevin Enderby | c095793 | 2010-09-30 16:52:03 +0000 | [diff] [blame] | 14 | #include "llvm/MC/MCObjectWriter.h" |
Rafael Espindola | ed708f9 | 2011-04-27 15:21:19 +0000 | [diff] [blame] | 15 | #include "llvm/MC/MCSymbol.h" |
Rafael Espindola | 484291c | 2010-11-01 14:28:48 +0000 | [diff] [blame] | 16 | #include "llvm/Support/ErrorHandling.h" |
Chris Lattner | d79d9dc | 2010-01-22 19:17:48 +0000 | [diff] [blame] | 17 | #include "llvm/Support/raw_ostream.h" |
Chris Lattner | 58bc4dd | 2010-04-03 22:12:35 +0000 | [diff] [blame] | 18 | #include "llvm/ADT/SmallString.h" |
Owen Anderson | 2fec6c5 | 2011-10-04 23:26:17 +0000 | [diff] [blame] | 19 | #include "llvm/ADT/StringExtras.h" |
Chris Lattner | 58bc4dd | 2010-04-03 22:12:35 +0000 | [diff] [blame] | 20 | #include "llvm/ADT/Twine.h" |
Chris Lattner | 3580dea | 2010-04-03 21:48:59 +0000 | [diff] [blame] | 21 | #include <cstdlib> |
Daniel Dunbar | a11af53 | 2009-06-24 01:03:06 +0000 | [diff] [blame] | 22 | using namespace llvm; |
| 23 | |
Rafael Espindola | f9efd83 | 2011-05-10 01:10:18 +0000 | [diff] [blame] | 24 | MCStreamer::MCStreamer(MCContext &Ctx) : Context(Ctx), EmitEHFrame(true), |
Charles Davis | 40de0e0 | 2011-05-24 21:22:53 +0000 | [diff] [blame] | 25 | EmitDebugFrame(false), |
Benjamin Kramer | 2df9f8d | 2011-08-25 04:04:18 +0000 | [diff] [blame] | 26 | CurrentW64UnwindInfo(0), |
Owen Anderson | 2fec6c5 | 2011-10-04 23:26:17 +0000 | [diff] [blame] | 27 | LastSymbol(0), |
| 28 | UniqueCodeBeginSuffix(0), |
| 29 | UniqueDataBeginSuffix(0) { |
Joerg Sonnenberger | 7d0805d | 2011-02-21 01:07:42 +0000 | [diff] [blame] | 30 | const MCSection *section = NULL; |
| 31 | SectionStack.push_back(std::make_pair(section, section)); |
Daniel Dunbar | a11af53 | 2009-06-24 01:03:06 +0000 | [diff] [blame] | 32 | } |
| 33 | |
| 34 | MCStreamer::~MCStreamer() { |
Charles Davis | 4eeb7b6 | 2011-05-27 02:01:08 +0000 | [diff] [blame] | 35 | for (unsigned i = 0; i < getNumW64UnwindInfos(); ++i) |
| 36 | delete W64UnwindInfos[i]; |
Daniel Dunbar | a11af53 | 2009-06-24 01:03:06 +0000 | [diff] [blame] | 37 | } |
Chris Lattner | ddf6bdd | 2010-01-19 18:45:47 +0000 | [diff] [blame] | 38 | |
Rafael Espindola | a37bd1d | 2011-04-30 03:21:04 +0000 | [diff] [blame] | 39 | const MCExpr *MCStreamer::BuildSymbolDiff(MCContext &Context, |
| 40 | const MCSymbol *A, |
| 41 | const MCSymbol *B) { |
| 42 | MCSymbolRefExpr::VariantKind Variant = MCSymbolRefExpr::VK_None; |
| 43 | const MCExpr *ARef = |
| 44 | MCSymbolRefExpr::Create(A, Variant, Context); |
| 45 | const MCExpr *BRef = |
| 46 | MCSymbolRefExpr::Create(B, Variant, Context); |
| 47 | const MCExpr *AddrDelta = |
| 48 | MCBinaryExpr::Create(MCBinaryExpr::Sub, ARef, BRef, Context); |
| 49 | return AddrDelta; |
| 50 | } |
| 51 | |
Rafael Espindola | a6f2678 | 2011-05-19 21:40:34 +0000 | [diff] [blame] | 52 | const MCExpr *MCStreamer::ForceExpAbs(const MCExpr* Expr) { |
Rafael Espindola | 78ff647 | 2011-05-19 22:05:56 +0000 | [diff] [blame] | 53 | if (Context.getAsmInfo().hasAggressiveSymbolFolding() || |
| 54 | isa<MCSymbolRefExpr>(Expr)) |
Rafael Espindola | a6f2678 | 2011-05-19 21:40:34 +0000 | [diff] [blame] | 55 | return Expr; |
Rafael Espindola | a37bd1d | 2011-04-30 03:21:04 +0000 | [diff] [blame] | 56 | |
Rafael Espindola | a6f2678 | 2011-05-19 21:40:34 +0000 | [diff] [blame] | 57 | MCSymbol *ABS = Context.CreateTempSymbol(); |
| 58 | EmitAssignment(ABS, Expr); |
| 59 | return MCSymbolRefExpr::Create(ABS, Context); |
Rafael Espindola | a37bd1d | 2011-04-30 03:21:04 +0000 | [diff] [blame] | 60 | } |
| 61 | |
Chris Lattner | d79d9dc | 2010-01-22 19:17:48 +0000 | [diff] [blame] | 62 | raw_ostream &MCStreamer::GetCommentOS() { |
| 63 | // By default, discard comments. |
| 64 | return nulls(); |
| 65 | } |
| 66 | |
Rafael Espindola | 32a006e | 2010-12-03 00:55:40 +0000 | [diff] [blame] | 67 | void MCStreamer::EmitDwarfSetLineAddr(int64_t LineDelta, |
| 68 | const MCSymbol *Label, int PointerSize) { |
| 69 | // emit the sequence to set the address |
| 70 | EmitIntValue(dwarf::DW_LNS_extended_op, 1); |
| 71 | EmitULEB128IntValue(PointerSize + 1); |
| 72 | EmitIntValue(dwarf::DW_LNE_set_address, 1); |
| 73 | EmitSymbolValue(Label, PointerSize); |
| 74 | |
| 75 | // emit the sequence for the LineDelta (from 1) and a zero address delta. |
| 76 | MCDwarfLineAddr::Emit(this, LineDelta, 0); |
| 77 | } |
Chris Lattner | d79d9dc | 2010-01-22 19:17:48 +0000 | [diff] [blame] | 78 | |
Chris Lattner | 32ae3fe | 2010-01-19 22:03:38 +0000 | [diff] [blame] | 79 | /// EmitIntValue - Special case of EmitValue that avoids the client having to |
| 80 | /// pass in a MCExpr for constant integers. |
| 81 | void MCStreamer::EmitIntValue(uint64_t Value, unsigned Size, |
| 82 | unsigned AddrSpace) { |
Devang Patel | dea914b | 2010-12-09 19:26:21 +0000 | [diff] [blame] | 83 | assert(Size <= 8 && "Invalid size"); |
Matt Beaumont-Gay | 818b5f5 | 2010-12-15 23:14:45 +0000 | [diff] [blame] | 84 | assert((isUIntN(8 * Size, Value) || isIntN(8 * Size, Value)) && |
| 85 | "Invalid size"); |
Rafael Espindola | 2df042c | 2010-12-03 02:54:21 +0000 | [diff] [blame] | 86 | char buf[8]; |
Evan Cheng | 1be0e27 | 2011-07-15 02:09:41 +0000 | [diff] [blame] | 87 | const bool isLittleEndian = Context.getAsmInfo().isLittleEndian(); |
Roman Divacky | 6589153 | 2011-06-07 17:31:02 +0000 | [diff] [blame] | 88 | for (unsigned i = 0; i != Size; ++i) { |
| 89 | unsigned index = isLittleEndian ? i : (Size - i - 1); |
| 90 | buf[i] = uint8_t(Value >> (index * 8)); |
| 91 | } |
Rafael Espindola | 2df042c | 2010-12-03 02:54:21 +0000 | [diff] [blame] | 92 | EmitBytes(StringRef(buf, Size), AddrSpace); |
Chris Lattner | 32ae3fe | 2010-01-19 22:03:38 +0000 | [diff] [blame] | 93 | } |
| 94 | |
Rafael Espindola | 3ff5709 | 2010-11-02 17:22:24 +0000 | [diff] [blame] | 95 | /// EmitULEB128Value - Special case of EmitULEB128Value that avoids the |
| 96 | /// client having to pass in a MCExpr for constant integers. |
| 97 | void MCStreamer::EmitULEB128IntValue(uint64_t Value, unsigned AddrSpace) { |
Rafael Espindola | 660b5fc | 2010-12-03 01:19:49 +0000 | [diff] [blame] | 98 | SmallString<32> Tmp; |
| 99 | raw_svector_ostream OSE(Tmp); |
| 100 | MCObjectWriter::EncodeULEB128(Value, OSE); |
| 101 | EmitBytes(OSE.str(), AddrSpace); |
Kevin Enderby | c095793 | 2010-09-30 16:52:03 +0000 | [diff] [blame] | 102 | } |
| 103 | |
Rafael Espindola | 3ff5709 | 2010-11-02 17:22:24 +0000 | [diff] [blame] | 104 | /// EmitSLEB128Value - Special case of EmitSLEB128Value that avoids the |
| 105 | /// client having to pass in a MCExpr for constant integers. |
| 106 | void MCStreamer::EmitSLEB128IntValue(int64_t Value, unsigned AddrSpace) { |
Rafael Espindola | 660b5fc | 2010-12-03 01:19:49 +0000 | [diff] [blame] | 107 | SmallString<32> Tmp; |
| 108 | raw_svector_ostream OSE(Tmp); |
| 109 | MCObjectWriter::EncodeSLEB128(Value, OSE); |
| 110 | EmitBytes(OSE.str(), AddrSpace); |
Kevin Enderby | c095793 | 2010-09-30 16:52:03 +0000 | [diff] [blame] | 111 | } |
| 112 | |
Rafael Espindola | 0bbe0b4 | 2010-12-06 17:27:56 +0000 | [diff] [blame] | 113 | void MCStreamer::EmitAbsValue(const MCExpr *Value, unsigned Size, |
| 114 | unsigned AddrSpace) { |
Rafael Espindola | a6f2678 | 2011-05-19 21:40:34 +0000 | [diff] [blame] | 115 | const MCExpr *ABS = ForceExpAbs(Value); |
| 116 | EmitValue(ABS, Size, AddrSpace); |
Rafael Espindola | 0bbe0b4 | 2010-12-06 17:27:56 +0000 | [diff] [blame] | 117 | } |
| 118 | |
Rafael Espindola | 89b9372 | 2010-12-10 07:39:47 +0000 | [diff] [blame] | 119 | |
| 120 | void MCStreamer::EmitValue(const MCExpr *Value, unsigned Size, |
| 121 | unsigned AddrSpace) { |
Rafael Espindola | debd7e4 | 2011-05-01 03:50:49 +0000 | [diff] [blame] | 122 | EmitValueImpl(Value, Size, AddrSpace); |
Rafael Espindola | 89b9372 | 2010-12-10 07:39:47 +0000 | [diff] [blame] | 123 | } |
| 124 | |
| 125 | void MCStreamer::EmitSymbolValue(const MCSymbol *Sym, unsigned Size, |
Rafael Espindola | debd7e4 | 2011-05-01 03:50:49 +0000 | [diff] [blame] | 126 | unsigned AddrSpace) { |
| 127 | EmitValueImpl(MCSymbolRefExpr::Create(Sym, getContext()), Size, |
Rafael Espindola | 89b9372 | 2010-12-10 07:39:47 +0000 | [diff] [blame] | 128 | AddrSpace); |
| 129 | } |
| 130 | |
Rafael Espindola | 3e03211 | 2010-11-28 15:09:24 +0000 | [diff] [blame] | 131 | void MCStreamer::EmitGPRel32Value(const MCExpr *Value) { |
| 132 | report_fatal_error("unsupported directive in streamer"); |
| 133 | } |
| 134 | |
Chris Lattner | ddf6bdd | 2010-01-19 18:45:47 +0000 | [diff] [blame] | 135 | /// EmitFill - Emit NumBytes bytes worth of the value specified by |
| 136 | /// FillValue. This implements directives such as '.space'. |
Chris Lattner | aaec205 | 2010-01-19 19:46:13 +0000 | [diff] [blame] | 137 | void MCStreamer::EmitFill(uint64_t NumBytes, uint8_t FillValue, |
| 138 | unsigned AddrSpace) { |
Chris Lattner | ddf6bdd | 2010-01-19 18:45:47 +0000 | [diff] [blame] | 139 | const MCExpr *E = MCConstantExpr::Create(FillValue, getContext()); |
| 140 | for (uint64_t i = 0, e = NumBytes; i != e; ++i) |
Chris Lattner | aaec205 | 2010-01-19 19:46:13 +0000 | [diff] [blame] | 141 | EmitValue(E, 1, AddrSpace); |
Chris Lattner | ddf6bdd | 2010-01-19 18:45:47 +0000 | [diff] [blame] | 142 | } |
Chris Lattner | 91bead7 | 2010-04-03 21:35:55 +0000 | [diff] [blame] | 143 | |
Rafael Espindola | af6b5808 | 2010-11-16 21:20:32 +0000 | [diff] [blame] | 144 | bool MCStreamer::EmitDwarfFileDirective(unsigned FileNo, |
Nick Lewycky | 44d798d | 2011-10-17 23:05:28 +0000 | [diff] [blame] | 145 | StringRef Directory, |
Rafael Espindola | af6b5808 | 2010-11-16 21:20:32 +0000 | [diff] [blame] | 146 | StringRef Filename) { |
Nick Lewycky | 44d798d | 2011-10-17 23:05:28 +0000 | [diff] [blame] | 147 | return getContext().GetDwarfFile(Directory, Filename, FileNo) == 0; |
Rafael Espindola | af6b5808 | 2010-11-16 21:20:32 +0000 | [diff] [blame] | 148 | } |
| 149 | |
| 150 | void MCStreamer::EmitDwarfLocDirective(unsigned FileNo, unsigned Line, |
| 151 | unsigned Column, unsigned Flags, |
| 152 | unsigned Isa, |
Devang Patel | 3f3bf93 | 2011-04-18 20:26:49 +0000 | [diff] [blame] | 153 | unsigned Discriminator, |
| 154 | StringRef FileName) { |
Rafael Espindola | af6b5808 | 2010-11-16 21:20:32 +0000 | [diff] [blame] | 155 | getContext().setCurrentDwarfLoc(FileNo, Line, Column, Flags, Isa, |
| 156 | Discriminator); |
| 157 | } |
| 158 | |
Rafael Espindola | 89b9372 | 2010-12-10 07:39:47 +0000 | [diff] [blame] | 159 | MCDwarfFrameInfo *MCStreamer::getCurrentFrameInfo() { |
| 160 | if (FrameInfos.empty()) |
| 161 | return NULL; |
| 162 | return &FrameInfos.back(); |
| 163 | } |
| 164 | |
| 165 | void MCStreamer::EnsureValidFrame() { |
| 166 | MCDwarfFrameInfo *CurFrame = getCurrentFrameInfo(); |
| 167 | if (!CurFrame || CurFrame->End) |
| 168 | report_fatal_error("No open frame"); |
| 169 | } |
| 170 | |
Rafael Espindola | 8bca410 | 2011-04-28 12:50:37 +0000 | [diff] [blame] | 171 | void MCStreamer::EmitEHSymAttributes(const MCSymbol *Symbol, |
| 172 | MCSymbol *EHSymbol) { |
| 173 | } |
| 174 | |
Rafael Espindola | ed708f9 | 2011-04-27 15:21:19 +0000 | [diff] [blame] | 175 | void MCStreamer::EmitLabel(MCSymbol *Symbol) { |
| 176 | assert(!Symbol->isVariable() && "Cannot emit a variable symbol!"); |
| 177 | assert(getCurrentSection() && "Cannot emit before setting section!"); |
| 178 | Symbol->setSection(*getCurrentSection()); |
Rafael Espindola | 49cb9b8 | 2011-08-02 20:24:22 +0000 | [diff] [blame] | 179 | LastSymbol = Symbol; |
Rafael Espindola | ed708f9 | 2011-04-27 15:21:19 +0000 | [diff] [blame] | 180 | } |
| 181 | |
Owen Anderson | 2fec6c5 | 2011-10-04 23:26:17 +0000 | [diff] [blame] | 182 | void MCStreamer::EmitDataRegion() { |
| 183 | if (RegionIndicator == Data) return; |
| 184 | |
| 185 | MCContext &Context = getContext(); |
| 186 | const MCAsmInfo &MAI = Context.getAsmInfo(); |
| 187 | if (!MAI.getSupportsDataRegions()) return; |
| 188 | |
| 189 | // Generate a unique symbol name. |
| 190 | MCSymbol *NewSym = Context.GetOrCreateSymbol( |
| 191 | Twine(MAI.getDataBeginLabelName()) + |
| 192 | utostr(UniqueDataBeginSuffix++)); |
| 193 | EmitLabel(NewSym); |
| 194 | |
| 195 | RegionIndicator = Data; |
| 196 | } |
| 197 | |
| 198 | void MCStreamer::EmitCodeRegion() { |
| 199 | if (RegionIndicator == Code) return; |
| 200 | |
| 201 | MCContext &Context = getContext(); |
| 202 | const MCAsmInfo &MAI = Context.getAsmInfo(); |
| 203 | if (!MAI.getSupportsDataRegions()) return; |
| 204 | |
| 205 | // Generate a unique symbol name. |
| 206 | MCSymbol *NewSym = Context.GetOrCreateSymbol( |
| 207 | Twine(MAI.getCodeBeginLabelName()) + |
| 208 | utostr(UniqueCodeBeginSuffix++)); |
| 209 | EmitLabel(NewSym); |
| 210 | |
| 211 | RegionIndicator = Code; |
| 212 | } |
| 213 | |
| 214 | void MCStreamer::EmitJumpTable8Region() { |
| 215 | if (RegionIndicator == JumpTable8) return; |
| 216 | |
| 217 | MCContext &Context = getContext(); |
| 218 | const MCAsmInfo &MAI = Context.getAsmInfo(); |
| 219 | if (!MAI.getSupportsDataRegions()) return; |
| 220 | |
| 221 | // Generate a unique symbol name. |
| 222 | MCSymbol *NewSym = Context.GetOrCreateSymbol( |
| 223 | Twine(MAI.getJumpTable8BeginLabelName()) + |
| 224 | utostr(UniqueDataBeginSuffix++)); |
| 225 | EmitLabel(NewSym); |
| 226 | |
| 227 | RegionIndicator = JumpTable8; |
| 228 | } |
| 229 | |
| 230 | void MCStreamer::EmitJumpTable16Region() { |
| 231 | if (RegionIndicator == JumpTable16) return; |
| 232 | |
| 233 | MCContext &Context = getContext(); |
| 234 | const MCAsmInfo &MAI = Context.getAsmInfo(); |
| 235 | if (!MAI.getSupportsDataRegions()) return; |
| 236 | |
| 237 | // Generate a unique symbol name. |
| 238 | MCSymbol *NewSym = Context.GetOrCreateSymbol( |
| 239 | Twine(MAI.getJumpTable16BeginLabelName()) + |
| 240 | utostr(UniqueDataBeginSuffix++)); |
| 241 | EmitLabel(NewSym); |
| 242 | |
| 243 | RegionIndicator = JumpTable16; |
| 244 | } |
| 245 | |
| 246 | |
| 247 | void MCStreamer::EmitJumpTable32Region() { |
| 248 | if (RegionIndicator == JumpTable32) return; |
| 249 | |
| 250 | MCContext &Context = getContext(); |
| 251 | const MCAsmInfo &MAI = Context.getAsmInfo(); |
| 252 | if (!MAI.getSupportsDataRegions()) return; |
| 253 | |
| 254 | // Generate a unique symbol name. |
| 255 | MCSymbol *NewSym = Context.GetOrCreateSymbol( |
| 256 | Twine(MAI.getJumpTable32BeginLabelName()) + |
| 257 | utostr(UniqueDataBeginSuffix++)); |
| 258 | EmitLabel(NewSym); |
| 259 | |
| 260 | RegionIndicator = JumpTable32; |
| 261 | } |
| 262 | |
Bill Wendling | d967578 | 2011-07-19 00:01:42 +0000 | [diff] [blame] | 263 | void MCStreamer::EmitCompactUnwindEncoding(uint32_t CompactUnwindEncoding) { |
| 264 | EnsureValidFrame(); |
| 265 | MCDwarfFrameInfo *CurFrame = getCurrentFrameInfo(); |
| 266 | CurFrame->CompactUnwindEncoding = CompactUnwindEncoding; |
| 267 | } |
| 268 | |
Rafael Espindola | f9efd83 | 2011-05-10 01:10:18 +0000 | [diff] [blame] | 269 | void MCStreamer::EmitCFISections(bool EH, bool Debug) { |
Rafael Espindola | 713c4bf | 2011-05-10 13:39:48 +0000 | [diff] [blame] | 270 | assert(EH || Debug); |
Rafael Espindola | f9efd83 | 2011-05-10 01:10:18 +0000 | [diff] [blame] | 271 | EmitEHFrame = EH; |
| 272 | EmitDebugFrame = Debug; |
| 273 | } |
| 274 | |
Rafael Espindola | 066c2f4 | 2011-04-12 23:59:07 +0000 | [diff] [blame] | 275 | void MCStreamer::EmitCFIStartProc() { |
Rafael Espindola | 89b9372 | 2010-12-10 07:39:47 +0000 | [diff] [blame] | 276 | MCDwarfFrameInfo *CurFrame = getCurrentFrameInfo(); |
Rafael Espindola | 066c2f4 | 2011-04-12 23:59:07 +0000 | [diff] [blame] | 277 | if (CurFrame && !CurFrame->End) |
Rafael Espindola | 89b9372 | 2010-12-10 07:39:47 +0000 | [diff] [blame] | 278 | report_fatal_error("Starting a frame before finishing the previous one!"); |
Rafael Espindola | 49cb9b8 | 2011-08-02 20:24:22 +0000 | [diff] [blame] | 279 | |
Evan Cheng | 5fbe5e7 | 2011-08-24 22:31:37 +0000 | [diff] [blame] | 280 | MCDwarfFrameInfo Frame; |
Rafael Espindola | 49cb9b8 | 2011-08-02 20:24:22 +0000 | [diff] [blame] | 281 | Frame.Function = LastSymbol; |
| 282 | |
| 283 | // If the function is externally visible, we need to create a local |
| 284 | // symbol to avoid relocations. |
| 285 | StringRef Prefix = getContext().getAsmInfo().getPrivateGlobalPrefix(); |
Evan Cheng | 5fbe5e7 | 2011-08-24 22:31:37 +0000 | [diff] [blame] | 286 | if (LastSymbol && LastSymbol->getName().startswith(Prefix)) { |
Rafael Espindola | 49cb9b8 | 2011-08-02 20:24:22 +0000 | [diff] [blame] | 287 | Frame.Begin = LastSymbol; |
| 288 | } else { |
| 289 | Frame.Begin = getContext().CreateTempSymbol(); |
| 290 | EmitLabel(Frame.Begin); |
| 291 | } |
| 292 | |
Rafael Espindola | 89b9372 | 2010-12-10 07:39:47 +0000 | [diff] [blame] | 293 | FrameInfos.push_back(Frame); |
Owen Anderson | 2fec6c5 | 2011-10-04 23:26:17 +0000 | [diff] [blame] | 294 | RegionIndicator = Code; |
Rafael Espindola | cdfecc8 | 2010-11-22 14:27:24 +0000 | [diff] [blame] | 295 | } |
| 296 | |
Rafael Espindola | 066c2f4 | 2011-04-12 23:59:07 +0000 | [diff] [blame] | 297 | void MCStreamer::EmitCFIEndProc() { |
Rafael Espindola | 89b9372 | 2010-12-10 07:39:47 +0000 | [diff] [blame] | 298 | EnsureValidFrame(); |
| 299 | MCDwarfFrameInfo *CurFrame = getCurrentFrameInfo(); |
| 300 | CurFrame->End = getContext().CreateTempSymbol(); |
| 301 | EmitLabel(CurFrame->End); |
Rafael Espindola | cdfecc8 | 2010-11-22 14:27:24 +0000 | [diff] [blame] | 302 | } |
| 303 | |
Rafael Espindola | 066c2f4 | 2011-04-12 23:59:07 +0000 | [diff] [blame] | 304 | void MCStreamer::EmitCFIDefCfa(int64_t Register, int64_t Offset) { |
Rafael Espindola | b40a71f | 2010-12-29 01:42:56 +0000 | [diff] [blame] | 305 | EnsureValidFrame(); |
| 306 | MCDwarfFrameInfo *CurFrame = getCurrentFrameInfo(); |
| 307 | MCSymbol *Label = getContext().CreateTempSymbol(); |
| 308 | EmitLabel(Label); |
| 309 | MachineLocation Dest(MachineLocation::VirtualFP); |
| 310 | MachineLocation Source(Register, -Offset); |
| 311 | MCCFIInstruction Instruction(Label, Dest, Source); |
| 312 | CurFrame->Instructions.push_back(Instruction); |
Rafael Espindola | b40a71f | 2010-12-29 01:42:56 +0000 | [diff] [blame] | 313 | } |
| 314 | |
Rafael Espindola | 066c2f4 | 2011-04-12 23:59:07 +0000 | [diff] [blame] | 315 | void MCStreamer::EmitCFIDefCfaOffset(int64_t Offset) { |
Rafael Espindola | 89b9372 | 2010-12-10 07:39:47 +0000 | [diff] [blame] | 316 | EnsureValidFrame(); |
Rafael Espindola | 5bba084 | 2010-12-28 04:15:37 +0000 | [diff] [blame] | 317 | MCDwarfFrameInfo *CurFrame = getCurrentFrameInfo(); |
| 318 | MCSymbol *Label = getContext().CreateTempSymbol(); |
| 319 | EmitLabel(Label); |
| 320 | MachineLocation Dest(MachineLocation::VirtualFP); |
| 321 | MachineLocation Source(MachineLocation::VirtualFP, -Offset); |
Rafael Espindola | fe024d0 | 2010-12-28 18:36:23 +0000 | [diff] [blame] | 322 | MCCFIInstruction Instruction(Label, Dest, Source); |
| 323 | CurFrame->Instructions.push_back(Instruction); |
Rafael Espindola | cdfecc8 | 2010-11-22 14:27:24 +0000 | [diff] [blame] | 324 | } |
| 325 | |
Rafael Espindola | 5d7dcd3 | 2011-04-12 18:53:30 +0000 | [diff] [blame] | 326 | void MCStreamer::EmitCFIAdjustCfaOffset(int64_t Adjustment) { |
| 327 | EnsureValidFrame(); |
| 328 | MCDwarfFrameInfo *CurFrame = getCurrentFrameInfo(); |
| 329 | MCSymbol *Label = getContext().CreateTempSymbol(); |
| 330 | EmitLabel(Label); |
| 331 | MachineLocation Dest(MachineLocation::VirtualFP); |
| 332 | MachineLocation Source(MachineLocation::VirtualFP, Adjustment); |
| 333 | MCCFIInstruction Instruction(MCCFIInstruction::RelMove, Label, Dest, Source); |
| 334 | CurFrame->Instructions.push_back(Instruction); |
| 335 | } |
| 336 | |
Rafael Espindola | 066c2f4 | 2011-04-12 23:59:07 +0000 | [diff] [blame] | 337 | void MCStreamer::EmitCFIDefCfaRegister(int64_t Register) { |
Rafael Espindola | 89b9372 | 2010-12-10 07:39:47 +0000 | [diff] [blame] | 338 | EnsureValidFrame(); |
Rafael Espindola | b4601bd | 2010-12-29 00:26:06 +0000 | [diff] [blame] | 339 | MCDwarfFrameInfo *CurFrame = getCurrentFrameInfo(); |
| 340 | MCSymbol *Label = getContext().CreateTempSymbol(); |
| 341 | EmitLabel(Label); |
| 342 | MachineLocation Dest(Register); |
| 343 | MachineLocation Source(MachineLocation::VirtualFP); |
| 344 | MCCFIInstruction Instruction(Label, Dest, Source); |
| 345 | CurFrame->Instructions.push_back(Instruction); |
Rafael Espindola | cdfecc8 | 2010-11-22 14:27:24 +0000 | [diff] [blame] | 346 | } |
| 347 | |
Rafael Espindola | 066c2f4 | 2011-04-12 23:59:07 +0000 | [diff] [blame] | 348 | void MCStreamer::EmitCFIOffset(int64_t Register, int64_t Offset) { |
Rafael Espindola | 89b9372 | 2010-12-10 07:39:47 +0000 | [diff] [blame] | 349 | EnsureValidFrame(); |
Rafael Espindola | b790a17 | 2010-12-29 00:09:59 +0000 | [diff] [blame] | 350 | MCDwarfFrameInfo *CurFrame = getCurrentFrameInfo(); |
| 351 | MCSymbol *Label = getContext().CreateTempSymbol(); |
| 352 | EmitLabel(Label); |
| 353 | MachineLocation Dest(Register, Offset); |
| 354 | MachineLocation Source(Register, Offset); |
| 355 | MCCFIInstruction Instruction(Label, Dest, Source); |
| 356 | CurFrame->Instructions.push_back(Instruction); |
Rafael Espindola | cdfecc8 | 2010-11-22 14:27:24 +0000 | [diff] [blame] | 357 | } |
| 358 | |
Rafael Espindola | 25f492e | 2011-04-12 16:12:03 +0000 | [diff] [blame] | 359 | void MCStreamer::EmitCFIRelOffset(int64_t Register, int64_t Offset) { |
| 360 | EnsureValidFrame(); |
| 361 | MCDwarfFrameInfo *CurFrame = getCurrentFrameInfo(); |
| 362 | MCSymbol *Label = getContext().CreateTempSymbol(); |
| 363 | EmitLabel(Label); |
| 364 | MachineLocation Dest(Register, Offset); |
| 365 | MachineLocation Source(Register, Offset); |
| 366 | MCCFIInstruction Instruction(MCCFIInstruction::RelMove, Label, Dest, Source); |
| 367 | CurFrame->Instructions.push_back(Instruction); |
| 368 | } |
| 369 | |
Rafael Espindola | 066c2f4 | 2011-04-12 23:59:07 +0000 | [diff] [blame] | 370 | void MCStreamer::EmitCFIPersonality(const MCSymbol *Sym, |
Rafael Espindola | 3a83c40 | 2010-12-27 00:36:05 +0000 | [diff] [blame] | 371 | unsigned Encoding) { |
Rafael Espindola | 89b9372 | 2010-12-10 07:39:47 +0000 | [diff] [blame] | 372 | EnsureValidFrame(); |
| 373 | MCDwarfFrameInfo *CurFrame = getCurrentFrameInfo(); |
| 374 | CurFrame->Personality = Sym; |
Rafael Espindola | 3a83c40 | 2010-12-27 00:36:05 +0000 | [diff] [blame] | 375 | CurFrame->PersonalityEncoding = Encoding; |
Rafael Espindola | cdfecc8 | 2010-11-22 14:27:24 +0000 | [diff] [blame] | 376 | } |
| 377 | |
Rafael Espindola | 066c2f4 | 2011-04-12 23:59:07 +0000 | [diff] [blame] | 378 | void MCStreamer::EmitCFILsda(const MCSymbol *Sym, unsigned Encoding) { |
Rafael Espindola | 89b9372 | 2010-12-10 07:39:47 +0000 | [diff] [blame] | 379 | EnsureValidFrame(); |
| 380 | MCDwarfFrameInfo *CurFrame = getCurrentFrameInfo(); |
| 381 | CurFrame->Lsda = Sym; |
Rafael Espindola | bdc3167 | 2010-12-27 15:56:22 +0000 | [diff] [blame] | 382 | CurFrame->LsdaEncoding = Encoding; |
Rafael Espindola | cdfecc8 | 2010-11-22 14:27:24 +0000 | [diff] [blame] | 383 | } |
| 384 | |
Rafael Espindola | 066c2f4 | 2011-04-12 23:59:07 +0000 | [diff] [blame] | 385 | void MCStreamer::EmitCFIRememberState() { |
Rafael Espindola | fe024d0 | 2010-12-28 18:36:23 +0000 | [diff] [blame] | 386 | EnsureValidFrame(); |
| 387 | MCDwarfFrameInfo *CurFrame = getCurrentFrameInfo(); |
| 388 | MCSymbol *Label = getContext().CreateTempSymbol(); |
| 389 | EmitLabel(Label); |
| 390 | MCCFIInstruction Instruction(MCCFIInstruction::Remember, Label); |
| 391 | CurFrame->Instructions.push_back(Instruction); |
Rafael Espindola | fe024d0 | 2010-12-28 18:36:23 +0000 | [diff] [blame] | 392 | } |
| 393 | |
Rafael Espindola | 066c2f4 | 2011-04-12 23:59:07 +0000 | [diff] [blame] | 394 | void MCStreamer::EmitCFIRestoreState() { |
Rafael Espindola | fe024d0 | 2010-12-28 18:36:23 +0000 | [diff] [blame] | 395 | // FIXME: Error if there is no matching cfi_remember_state. |
| 396 | EnsureValidFrame(); |
| 397 | MCDwarfFrameInfo *CurFrame = getCurrentFrameInfo(); |
| 398 | MCSymbol *Label = getContext().CreateTempSymbol(); |
| 399 | EmitLabel(Label); |
| 400 | MCCFIInstruction Instruction(MCCFIInstruction::Restore, Label); |
| 401 | CurFrame->Instructions.push_back(Instruction); |
Rafael Espindola | fe024d0 | 2010-12-28 18:36:23 +0000 | [diff] [blame] | 402 | } |
| 403 | |
Rafael Espindola | c575439 | 2011-04-12 15:31:05 +0000 | [diff] [blame] | 404 | void MCStreamer::EmitCFISameValue(int64_t Register) { |
| 405 | EnsureValidFrame(); |
| 406 | MCDwarfFrameInfo *CurFrame = getCurrentFrameInfo(); |
| 407 | MCSymbol *Label = getContext().CreateTempSymbol(); |
| 408 | EmitLabel(Label); |
| 409 | MCCFIInstruction Instruction(MCCFIInstruction::SameValue, Label, Register); |
| 410 | CurFrame->Instructions.push_back(Instruction); |
| 411 | } |
| 412 | |
Charles Davis | 91d9a1c | 2011-05-19 04:04:13 +0000 | [diff] [blame] | 413 | void MCStreamer::setCurrentW64UnwindInfo(MCWin64EHUnwindInfo *Frame) { |
Charles Davis | ca93138 | 2011-05-26 02:45:47 +0000 | [diff] [blame] | 414 | W64UnwindInfos.push_back(Frame); |
| 415 | CurrentW64UnwindInfo = W64UnwindInfos.back(); |
Charles Davis | 9c77398 | 2011-05-18 04:47:22 +0000 | [diff] [blame] | 416 | } |
| 417 | |
Charles Davis | 0855bc5 | 2011-05-19 02:49:00 +0000 | [diff] [blame] | 418 | void MCStreamer::EnsureValidW64UnwindInfo() { |
Charles Davis | 91d9a1c | 2011-05-19 04:04:13 +0000 | [diff] [blame] | 419 | MCWin64EHUnwindInfo *CurFrame = CurrentW64UnwindInfo; |
Charles Davis | 0855bc5 | 2011-05-19 02:49:00 +0000 | [diff] [blame] | 420 | if (!CurFrame || CurFrame->End) |
| 421 | report_fatal_error("No open Win64 EH frame function!"); |
| 422 | } |
| 423 | |
Charles Davis | fbc539f | 2011-05-22 21:12:15 +0000 | [diff] [blame] | 424 | void MCStreamer::EmitWin64EHStartProc(const MCSymbol *Symbol) { |
Charles Davis | 91d9a1c | 2011-05-19 04:04:13 +0000 | [diff] [blame] | 425 | MCWin64EHUnwindInfo *CurFrame = CurrentW64UnwindInfo; |
Charles Davis | 0855bc5 | 2011-05-19 02:49:00 +0000 | [diff] [blame] | 426 | if (CurFrame && !CurFrame->End) |
| 427 | report_fatal_error("Starting a function before ending the previous one!"); |
Charles Davis | 4eeb7b6 | 2011-05-27 02:01:08 +0000 | [diff] [blame] | 428 | MCWin64EHUnwindInfo *Frame = new MCWin64EHUnwindInfo; |
Charles Davis | ca93138 | 2011-05-26 02:45:47 +0000 | [diff] [blame] | 429 | Frame->Begin = getContext().CreateTempSymbol(); |
| 430 | Frame->Function = Symbol; |
| 431 | EmitLabel(Frame->Begin); |
| 432 | setCurrentW64UnwindInfo(Frame); |
Charles Davis | 0855bc5 | 2011-05-19 02:49:00 +0000 | [diff] [blame] | 433 | } |
| 434 | |
| 435 | void MCStreamer::EmitWin64EHEndProc() { |
| 436 | EnsureValidW64UnwindInfo(); |
Charles Davis | 91d9a1c | 2011-05-19 04:04:13 +0000 | [diff] [blame] | 437 | MCWin64EHUnwindInfo *CurFrame = CurrentW64UnwindInfo; |
| 438 | if (CurFrame->ChainedParent) |
Charles Davis | 0855bc5 | 2011-05-19 02:49:00 +0000 | [diff] [blame] | 439 | report_fatal_error("Not all chained regions terminated!"); |
| 440 | CurFrame->End = getContext().CreateTempSymbol(); |
| 441 | EmitLabel(CurFrame->End); |
Charles Davis | ff96a12 | 2011-05-15 17:20:01 +0000 | [diff] [blame] | 442 | } |
| 443 | |
Charles Davis | 440596f | 2011-05-19 17:46:39 +0000 | [diff] [blame] | 444 | void MCStreamer::EmitWin64EHStartChained() { |
Charles Davis | 91d9a1c | 2011-05-19 04:04:13 +0000 | [diff] [blame] | 445 | EnsureValidW64UnwindInfo(); |
Charles Davis | 4eeb7b6 | 2011-05-27 02:01:08 +0000 | [diff] [blame] | 446 | MCWin64EHUnwindInfo *Frame = new MCWin64EHUnwindInfo; |
Charles Davis | 91d9a1c | 2011-05-19 04:04:13 +0000 | [diff] [blame] | 447 | MCWin64EHUnwindInfo *CurFrame = CurrentW64UnwindInfo; |
Charles Davis | ca93138 | 2011-05-26 02:45:47 +0000 | [diff] [blame] | 448 | Frame->Begin = getContext().CreateTempSymbol(); |
| 449 | Frame->Function = CurFrame->Function; |
| 450 | Frame->ChainedParent = CurFrame; |
| 451 | EmitLabel(Frame->Begin); |
| 452 | setCurrentW64UnwindInfo(Frame); |
Charles Davis | f070901 | 2011-05-18 20:54:10 +0000 | [diff] [blame] | 453 | } |
| 454 | |
Charles Davis | 440596f | 2011-05-19 17:46:39 +0000 | [diff] [blame] | 455 | void MCStreamer::EmitWin64EHEndChained() { |
Charles Davis | 91d9a1c | 2011-05-19 04:04:13 +0000 | [diff] [blame] | 456 | EnsureValidW64UnwindInfo(); |
| 457 | MCWin64EHUnwindInfo *CurFrame = CurrentW64UnwindInfo; |
| 458 | if (!CurFrame->ChainedParent) |
| 459 | report_fatal_error("End of a chained region outside a chained region!"); |
| 460 | CurFrame->End = getContext().CreateTempSymbol(); |
| 461 | EmitLabel(CurFrame->End); |
| 462 | CurrentW64UnwindInfo = CurFrame->ChainedParent; |
Charles Davis | f070901 | 2011-05-18 20:54:10 +0000 | [diff] [blame] | 463 | } |
| 464 | |
Charles Davis | 440596f | 2011-05-19 17:46:39 +0000 | [diff] [blame] | 465 | void MCStreamer::EmitWin64EHHandler(const MCSymbol *Sym, bool Unwind, |
| 466 | bool Except) { |
| 467 | EnsureValidW64UnwindInfo(); |
| 468 | MCWin64EHUnwindInfo *CurFrame = CurrentW64UnwindInfo; |
Charles Davis | 81f3830 | 2011-05-21 17:36:25 +0000 | [diff] [blame] | 469 | if (CurFrame->ChainedParent) |
| 470 | report_fatal_error("Chained unwind areas can't have handlers!"); |
Charles Davis | 440596f | 2011-05-19 17:46:39 +0000 | [diff] [blame] | 471 | CurFrame->ExceptionHandler = Sym; |
Charles Davis | 321fe74 | 2011-05-21 15:57:49 +0000 | [diff] [blame] | 472 | if (!Except && !Unwind) |
Charles Davis | 440596f | 2011-05-19 17:46:39 +0000 | [diff] [blame] | 473 | report_fatal_error("Don't know what kind of handler this is!"); |
Charles Davis | 321fe74 | 2011-05-21 15:57:49 +0000 | [diff] [blame] | 474 | if (Unwind) |
| 475 | CurFrame->HandlesUnwind = true; |
| 476 | if (Except) |
| 477 | CurFrame->HandlesExceptions = true; |
Charles Davis | 440596f | 2011-05-19 17:46:39 +0000 | [diff] [blame] | 478 | } |
| 479 | |
| 480 | void MCStreamer::EmitWin64EHHandlerData() { |
Charles Davis | d0b76d0 | 2011-05-20 16:06:22 +0000 | [diff] [blame] | 481 | EnsureValidW64UnwindInfo(); |
Charles Davis | 81f3830 | 2011-05-21 17:36:25 +0000 | [diff] [blame] | 482 | MCWin64EHUnwindInfo *CurFrame = CurrentW64UnwindInfo; |
| 483 | if (CurFrame->ChainedParent) |
| 484 | report_fatal_error("Chained unwind areas can't have handlers!"); |
Charles Davis | f070901 | 2011-05-18 20:54:10 +0000 | [diff] [blame] | 485 | } |
| 486 | |
Charles Davis | c3b1628 | 2011-05-19 19:35:55 +0000 | [diff] [blame] | 487 | void MCStreamer::EmitWin64EHPushReg(unsigned Register) { |
| 488 | EnsureValidW64UnwindInfo(); |
| 489 | MCWin64EHUnwindInfo *CurFrame = CurrentW64UnwindInfo; |
Charles Davis | c4cbf9b | 2011-05-27 03:25:01 +0000 | [diff] [blame] | 490 | MCSymbol *Label = getContext().CreateTempSymbol(); |
| 491 | MCWin64EHInstruction Inst(Win64EH::UOP_PushNonVol, Label, Register); |
| 492 | EmitLabel(Label); |
Charles Davis | c3b1628 | 2011-05-19 19:35:55 +0000 | [diff] [blame] | 493 | CurFrame->Instructions.push_back(Inst); |
Charles Davis | f070901 | 2011-05-18 20:54:10 +0000 | [diff] [blame] | 494 | } |
| 495 | |
Charles Davis | c3b1628 | 2011-05-19 19:35:55 +0000 | [diff] [blame] | 496 | void MCStreamer::EmitWin64EHSetFrame(unsigned Register, unsigned Offset) { |
| 497 | EnsureValidW64UnwindInfo(); |
Charles Davis | c2d3022 | 2011-05-27 01:42:17 +0000 | [diff] [blame] | 498 | MCWin64EHUnwindInfo *CurFrame = CurrentW64UnwindInfo; |
| 499 | if (CurFrame->LastFrameInst >= 0) |
| 500 | report_fatal_error("Frame register and offset already specified!"); |
Charles Davis | edeecbf | 2011-05-22 00:56:20 +0000 | [diff] [blame] | 501 | if (Offset & 0x0F) |
| 502 | report_fatal_error("Misaligned frame pointer offset!"); |
Charles Davis | c4cbf9b | 2011-05-27 03:25:01 +0000 | [diff] [blame] | 503 | MCWin64EHInstruction Inst(Win64EH::UOP_SetFPReg, NULL, Register, Offset); |
Charles Davis | 5c2256a | 2011-05-21 00:09:04 +0000 | [diff] [blame] | 504 | CurFrame->LastFrameInst = CurFrame->Instructions.size(); |
Charles Davis | c3b1628 | 2011-05-19 19:35:55 +0000 | [diff] [blame] | 505 | CurFrame->Instructions.push_back(Inst); |
Charles Davis | ff96a12 | 2011-05-15 17:20:01 +0000 | [diff] [blame] | 506 | } |
| 507 | |
Charles Davis | c3b1628 | 2011-05-19 19:35:55 +0000 | [diff] [blame] | 508 | void MCStreamer::EmitWin64EHAllocStack(unsigned Size) { |
| 509 | EnsureValidW64UnwindInfo(); |
Charles Davis | edeecbf | 2011-05-22 00:56:20 +0000 | [diff] [blame] | 510 | if (Size & 7) |
| 511 | report_fatal_error("Misaligned stack allocation!"); |
Charles Davis | c3b1628 | 2011-05-19 19:35:55 +0000 | [diff] [blame] | 512 | MCWin64EHUnwindInfo *CurFrame = CurrentW64UnwindInfo; |
Charles Davis | c4cbf9b | 2011-05-27 03:25:01 +0000 | [diff] [blame] | 513 | MCSymbol *Label = getContext().CreateTempSymbol(); |
| 514 | MCWin64EHInstruction Inst(Label, Size); |
| 515 | EmitLabel(Label); |
Charles Davis | c3b1628 | 2011-05-19 19:35:55 +0000 | [diff] [blame] | 516 | CurFrame->Instructions.push_back(Inst); |
Charles Davis | ff96a12 | 2011-05-15 17:20:01 +0000 | [diff] [blame] | 517 | } |
| 518 | |
Charles Davis | c3b1628 | 2011-05-19 19:35:55 +0000 | [diff] [blame] | 519 | void MCStreamer::EmitWin64EHSaveReg(unsigned Register, unsigned Offset) { |
| 520 | EnsureValidW64UnwindInfo(); |
Charles Davis | edeecbf | 2011-05-22 00:56:20 +0000 | [diff] [blame] | 521 | if (Offset & 7) |
| 522 | report_fatal_error("Misaligned saved register offset!"); |
Charles Davis | c3b1628 | 2011-05-19 19:35:55 +0000 | [diff] [blame] | 523 | MCWin64EHUnwindInfo *CurFrame = CurrentW64UnwindInfo; |
Charles Davis | c4cbf9b | 2011-05-27 03:25:01 +0000 | [diff] [blame] | 524 | MCSymbol *Label = getContext().CreateTempSymbol(); |
Charles Davis | c3b1628 | 2011-05-19 19:35:55 +0000 | [diff] [blame] | 525 | MCWin64EHInstruction Inst( |
Charles Davis | c2d3022 | 2011-05-27 01:42:17 +0000 | [diff] [blame] | 526 | Offset > 512*1024-8 ? Win64EH::UOP_SaveNonVolBig : Win64EH::UOP_SaveNonVol, |
Charles Davis | c4cbf9b | 2011-05-27 03:25:01 +0000 | [diff] [blame] | 527 | Label, Register, Offset); |
| 528 | EmitLabel(Label); |
Charles Davis | c3b1628 | 2011-05-19 19:35:55 +0000 | [diff] [blame] | 529 | CurFrame->Instructions.push_back(Inst); |
Charles Davis | ff96a12 | 2011-05-15 17:20:01 +0000 | [diff] [blame] | 530 | } |
| 531 | |
Charles Davis | c3b1628 | 2011-05-19 19:35:55 +0000 | [diff] [blame] | 532 | void MCStreamer::EmitWin64EHSaveXMM(unsigned Register, unsigned Offset) { |
| 533 | EnsureValidW64UnwindInfo(); |
Charles Davis | edeecbf | 2011-05-22 00:56:20 +0000 | [diff] [blame] | 534 | if (Offset & 0x0F) |
| 535 | report_fatal_error("Misaligned saved vector register offset!"); |
Charles Davis | c3b1628 | 2011-05-19 19:35:55 +0000 | [diff] [blame] | 536 | MCWin64EHUnwindInfo *CurFrame = CurrentW64UnwindInfo; |
Charles Davis | c4cbf9b | 2011-05-27 03:25:01 +0000 | [diff] [blame] | 537 | MCSymbol *Label = getContext().CreateTempSymbol(); |
Charles Davis | c3b1628 | 2011-05-19 19:35:55 +0000 | [diff] [blame] | 538 | MCWin64EHInstruction Inst( |
Charles Davis | c2d3022 | 2011-05-27 01:42:17 +0000 | [diff] [blame] | 539 | Offset > 512*1024-16 ? Win64EH::UOP_SaveXMM128Big : Win64EH::UOP_SaveXMM128, |
Charles Davis | c4cbf9b | 2011-05-27 03:25:01 +0000 | [diff] [blame] | 540 | Label, Register, Offset); |
| 541 | EmitLabel(Label); |
Charles Davis | c3b1628 | 2011-05-19 19:35:55 +0000 | [diff] [blame] | 542 | CurFrame->Instructions.push_back(Inst); |
Charles Davis | ff96a12 | 2011-05-15 17:20:01 +0000 | [diff] [blame] | 543 | } |
| 544 | |
Charles Davis | 440596f | 2011-05-19 17:46:39 +0000 | [diff] [blame] | 545 | void MCStreamer::EmitWin64EHPushFrame(bool Code) { |
Charles Davis | c3b1628 | 2011-05-19 19:35:55 +0000 | [diff] [blame] | 546 | EnsureValidW64UnwindInfo(); |
| 547 | MCWin64EHUnwindInfo *CurFrame = CurrentW64UnwindInfo; |
Charles Davis | c2d3022 | 2011-05-27 01:42:17 +0000 | [diff] [blame] | 548 | if (CurFrame->Instructions.size() > 0) |
| 549 | report_fatal_error("If present, PushMachFrame must be the first UOP"); |
Charles Davis | c4cbf9b | 2011-05-27 03:25:01 +0000 | [diff] [blame] | 550 | MCSymbol *Label = getContext().CreateTempSymbol(); |
| 551 | MCWin64EHInstruction Inst(Win64EH::UOP_PushMachFrame, Label, Code); |
| 552 | EmitLabel(Label); |
Charles Davis | c3b1628 | 2011-05-19 19:35:55 +0000 | [diff] [blame] | 553 | CurFrame->Instructions.push_back(Inst); |
Charles Davis | ff96a12 | 2011-05-15 17:20:01 +0000 | [diff] [blame] | 554 | } |
| 555 | |
Charles Davis | 440596f | 2011-05-19 17:46:39 +0000 | [diff] [blame] | 556 | void MCStreamer::EmitWin64EHEndProlog() { |
Charles Davis | 61558aa | 2011-05-19 21:24:54 +0000 | [diff] [blame] | 557 | EnsureValidW64UnwindInfo(); |
| 558 | MCWin64EHUnwindInfo *CurFrame = CurrentW64UnwindInfo; |
| 559 | CurFrame->PrologEnd = getContext().CreateTempSymbol(); |
| 560 | EmitLabel(CurFrame->PrologEnd); |
Charles Davis | cacdc4f | 2011-05-16 21:13:58 +0000 | [diff] [blame] | 561 | } |
| 562 | |
Anton Korobeynikov | b5e16af | 2011-03-05 18:43:15 +0000 | [diff] [blame] | 563 | void MCStreamer::EmitFnStart() { |
| 564 | errs() << "Not implemented yet\n"; |
| 565 | abort(); |
| 566 | } |
| 567 | |
| 568 | void MCStreamer::EmitFnEnd() { |
| 569 | errs() << "Not implemented yet\n"; |
| 570 | abort(); |
| 571 | } |
| 572 | |
| 573 | void MCStreamer::EmitCantUnwind() { |
| 574 | errs() << "Not implemented yet\n"; |
| 575 | abort(); |
| 576 | } |
| 577 | |
| 578 | void MCStreamer::EmitHandlerData() { |
| 579 | errs() << "Not implemented yet\n"; |
| 580 | abort(); |
| 581 | } |
| 582 | |
| 583 | void MCStreamer::EmitPersonality(const MCSymbol *Personality) { |
| 584 | errs() << "Not implemented yet\n"; |
| 585 | abort(); |
| 586 | } |
| 587 | |
Anton Korobeynikov | 57caad7 | 2011-03-05 18:43:32 +0000 | [diff] [blame] | 588 | void MCStreamer::EmitSetFP(unsigned FpReg, unsigned SpReg, int64_t Offset) { |
| 589 | errs() << "Not implemented yet\n"; |
| 590 | abort(); |
| 591 | } |
| 592 | |
| 593 | void MCStreamer::EmitPad(int64_t Offset) { |
| 594 | errs() << "Not implemented yet\n"; |
| 595 | abort(); |
| 596 | } |
| 597 | |
| 598 | void MCStreamer::EmitRegSave(const SmallVectorImpl<unsigned> &RegList, bool) { |
| 599 | errs() << "Not implemented yet\n"; |
| 600 | abort(); |
| 601 | } |
| 602 | |
Matt Fleming | ab3b365 | 2010-05-20 19:45:09 +0000 | [diff] [blame] | 603 | /// EmitRawText - If this file is backed by an assembly streamer, this dumps |
Chris Lattner | 91bead7 | 2010-04-03 21:35:55 +0000 | [diff] [blame] | 604 | /// the specified string in the output .s file. This capability is |
| 605 | /// indicated by the hasRawTextSupport() predicate. |
| 606 | void MCStreamer::EmitRawText(StringRef String) { |
| 607 | errs() << "EmitRawText called on an MCStreamer that doesn't support it, " |
| 608 | " something must not be fully mc'ized\n"; |
| 609 | abort(); |
| 610 | } |
Chris Lattner | 58bc4dd | 2010-04-03 22:12:35 +0000 | [diff] [blame] | 611 | |
| 612 | void MCStreamer::EmitRawText(const Twine &T) { |
| 613 | SmallString<128> Str; |
| 614 | T.toVector(Str); |
| 615 | EmitRawText(Str.str()); |
| 616 | } |
Rafael Espindola | c25dad8 | 2011-05-10 03:14:15 +0000 | [diff] [blame] | 617 | |
| 618 | void MCStreamer::EmitFrames(bool usingCFI) { |
| 619 | if (!getNumFrameInfos()) |
| 620 | return; |
| 621 | |
| 622 | if (EmitEHFrame) |
Rafael Espindola | 40a7dbb | 2011-05-10 03:54:12 +0000 | [diff] [blame] | 623 | MCDwarfFrameEmitter::Emit(*this, usingCFI, true); |
| 624 | |
| 625 | if (EmitDebugFrame) |
| 626 | MCDwarfFrameEmitter::Emit(*this, usingCFI, false); |
Rafael Espindola | c25dad8 | 2011-05-10 03:14:15 +0000 | [diff] [blame] | 627 | } |
Charles Davis | 38ea9ee | 2011-05-22 04:15:07 +0000 | [diff] [blame] | 628 | |
| 629 | void MCStreamer::EmitW64Tables() { |
| 630 | if (!getNumW64UnwindInfos()) |
| 631 | return; |
| 632 | |
| 633 | MCWin64EHUnwindEmitter::Emit(*this); |
| 634 | } |