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