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