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