Home | History | Annotate | Download | only in MC
      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 
     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 
     34 MCStreamer::~MCStreamer() {
     35   for (unsigned i = 0; i < getNumW64UnwindInfos(); ++i)
     36     delete W64UnwindInfos[i];
     37 }
     38 
     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 
     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 
     62 raw_ostream &MCStreamer::GetCommentOS() {
     63   // By default, discard comments.
     64   return nulls();
     65 }
     66 
     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.
     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.
     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.
    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 
    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 
    120 void MCStreamer::EmitValue(const MCExpr *Value, unsigned Size,
    121                            unsigned AddrSpace) {
    122   EmitValueImpl(Value, Size, AddrSpace);
    123 }
    124 
    125 void MCStreamer::EmitSymbolValue(const MCSymbol *Sym, unsigned Size,
    126                                   unsigned AddrSpace) {
    127   EmitValueImpl(MCSymbolRefExpr::Create(Sym, getContext()), Size,
    128                 AddrSpace);
    129 }
    130 
    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'.
    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 
    144 bool MCStreamer::EmitDwarfFileDirective(unsigned FileNo,
    145                                         StringRef Directory,
    146                                         StringRef Filename) {
    147   return getContext().GetDwarfFile(Directory, Filename, FileNo) == 0;
    148 }
    149 
    150 void 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 
    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 
    171 void MCStreamer::EmitEHSymAttributes(const MCSymbol *Symbol,
    172                                      MCSymbol *EHSymbol) {
    173 }
    174 
    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());
    179   LastSymbol = Symbol;
    180 }
    181 
    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 
    263 void MCStreamer::EmitCompactUnwindEncoding(uint32_t CompactUnwindEncoding) {
    264   EnsureValidFrame();
    265   MCDwarfFrameInfo *CurFrame = getCurrentFrameInfo();
    266   CurFrame->CompactUnwindEncoding = CompactUnwindEncoding;
    267 }
    268 
    269 void MCStreamer::EmitCFISections(bool EH, bool Debug) {
    270   assert(EH || Debug);
    271   EmitEHFrame = EH;
    272   EmitDebugFrame = Debug;
    273 }
    274 
    275 void MCStreamer::EmitCFIStartProc() {
    276   MCDwarfFrameInfo *CurFrame = getCurrentFrameInfo();
    277   if (CurFrame && !CurFrame->End)
    278     report_fatal_error("Starting a frame before finishing the previous one!");
    279 
    280   MCDwarfFrameInfo Frame;
    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();
    286   if (LastSymbol && LastSymbol->getName().startswith(Prefix)) {
    287     Frame.Begin = LastSymbol;
    288   } else {
    289     Frame.Begin = getContext().CreateTempSymbol();
    290     EmitLabel(Frame.Begin);
    291   }
    292 
    293   FrameInfos.push_back(Frame);
    294   RegionIndicator = Code;
    295 }
    296 
    297 void MCStreamer::EmitCFIEndProc() {
    298   EnsureValidFrame();
    299   MCDwarfFrameInfo *CurFrame = getCurrentFrameInfo();
    300   CurFrame->End = getContext().CreateTempSymbol();
    301   EmitLabel(CurFrame->End);
    302 }
    303 
    304 void MCStreamer::EmitCFIDefCfa(int64_t Register, int64_t Offset) {
    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);
    313 }
    314 
    315 void MCStreamer::EmitCFIDefCfaOffset(int64_t Offset) {
    316   EnsureValidFrame();
    317   MCDwarfFrameInfo *CurFrame = getCurrentFrameInfo();
    318   MCSymbol *Label = getContext().CreateTempSymbol();
    319   EmitLabel(Label);
    320   MachineLocation Dest(MachineLocation::VirtualFP);
    321   MachineLocation Source(MachineLocation::VirtualFP, -Offset);
    322   MCCFIInstruction Instruction(Label, Dest, Source);
    323   CurFrame->Instructions.push_back(Instruction);
    324 }
    325 
    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 
    337 void MCStreamer::EmitCFIDefCfaRegister(int64_t Register) {
    338   EnsureValidFrame();
    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);
    346 }
    347 
    348 void MCStreamer::EmitCFIOffset(int64_t Register, int64_t Offset) {
    349   EnsureValidFrame();
    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);
    357 }
    358 
    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 
    370 void MCStreamer::EmitCFIPersonality(const MCSymbol *Sym,
    371                                     unsigned Encoding) {
    372   EnsureValidFrame();
    373   MCDwarfFrameInfo *CurFrame = getCurrentFrameInfo();
    374   CurFrame->Personality = Sym;
    375   CurFrame->PersonalityEncoding = Encoding;
    376 }
    377 
    378 void MCStreamer::EmitCFILsda(const MCSymbol *Sym, unsigned Encoding) {
    379   EnsureValidFrame();
    380   MCDwarfFrameInfo *CurFrame = getCurrentFrameInfo();
    381   CurFrame->Lsda = Sym;
    382   CurFrame->LsdaEncoding = Encoding;
    383 }
    384 
    385 void MCStreamer::EmitCFIRememberState() {
    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);
    392 }
    393 
    394 void MCStreamer::EmitCFIRestoreState() {
    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);
    402 }
    403 
    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 
    413 void MCStreamer::setCurrentW64UnwindInfo(MCWin64EHUnwindInfo *Frame) {
    414   W64UnwindInfos.push_back(Frame);
    415   CurrentW64UnwindInfo = W64UnwindInfos.back();
    416 }
    417 
    418 void MCStreamer::EnsureValidW64UnwindInfo() {
    419   MCWin64EHUnwindInfo *CurFrame = CurrentW64UnwindInfo;
    420   if (!CurFrame || CurFrame->End)
    421     report_fatal_error("No open Win64 EH frame function!");
    422 }
    423 
    424 void MCStreamer::EmitWin64EHStartProc(const MCSymbol *Symbol) {
    425   MCWin64EHUnwindInfo *CurFrame = CurrentW64UnwindInfo;
    426   if (CurFrame && !CurFrame->End)
    427     report_fatal_error("Starting a function before ending the previous one!");
    428   MCWin64EHUnwindInfo *Frame = new MCWin64EHUnwindInfo;
    429   Frame->Begin = getContext().CreateTempSymbol();
    430   Frame->Function = Symbol;
    431   EmitLabel(Frame->Begin);
    432   setCurrentW64UnwindInfo(Frame);
    433 }
    434 
    435 void MCStreamer::EmitWin64EHEndProc() {
    436   EnsureValidW64UnwindInfo();
    437   MCWin64EHUnwindInfo *CurFrame = CurrentW64UnwindInfo;
    438   if (CurFrame->ChainedParent)
    439     report_fatal_error("Not all chained regions terminated!");
    440   CurFrame->End = getContext().CreateTempSymbol();
    441   EmitLabel(CurFrame->End);
    442 }
    443 
    444 void MCStreamer::EmitWin64EHStartChained() {
    445   EnsureValidW64UnwindInfo();
    446   MCWin64EHUnwindInfo *Frame = new MCWin64EHUnwindInfo;
    447   MCWin64EHUnwindInfo *CurFrame = CurrentW64UnwindInfo;
    448   Frame->Begin = getContext().CreateTempSymbol();
    449   Frame->Function = CurFrame->Function;
    450   Frame->ChainedParent = CurFrame;
    451   EmitLabel(Frame->Begin);
    452   setCurrentW64UnwindInfo(Frame);
    453 }
    454 
    455 void MCStreamer::EmitWin64EHEndChained() {
    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;
    463 }
    464 
    465 void MCStreamer::EmitWin64EHHandler(const MCSymbol *Sym, bool Unwind,
    466                                     bool Except) {
    467   EnsureValidW64UnwindInfo();
    468   MCWin64EHUnwindInfo *CurFrame = CurrentW64UnwindInfo;
    469   if (CurFrame->ChainedParent)
    470     report_fatal_error("Chained unwind areas can't have handlers!");
    471   CurFrame->ExceptionHandler = Sym;
    472   if (!Except && !Unwind)
    473     report_fatal_error("Don't know what kind of handler this is!");
    474   if (Unwind)
    475     CurFrame->HandlesUnwind = true;
    476   if (Except)
    477     CurFrame->HandlesExceptions = true;
    478 }
    479 
    480 void MCStreamer::EmitWin64EHHandlerData() {
    481   EnsureValidW64UnwindInfo();
    482   MCWin64EHUnwindInfo *CurFrame = CurrentW64UnwindInfo;
    483   if (CurFrame->ChainedParent)
    484     report_fatal_error("Chained unwind areas can't have handlers!");
    485 }
    486 
    487 void MCStreamer::EmitWin64EHPushReg(unsigned Register) {
    488   EnsureValidW64UnwindInfo();
    489   MCWin64EHUnwindInfo *CurFrame = CurrentW64UnwindInfo;
    490   MCSymbol *Label = getContext().CreateTempSymbol();
    491   MCWin64EHInstruction Inst(Win64EH::UOP_PushNonVol, Label, Register);
    492   EmitLabel(Label);
    493   CurFrame->Instructions.push_back(Inst);
    494 }
    495 
    496 void MCStreamer::EmitWin64EHSetFrame(unsigned Register, unsigned Offset) {
    497   EnsureValidW64UnwindInfo();
    498   MCWin64EHUnwindInfo *CurFrame = CurrentW64UnwindInfo;
    499   if (CurFrame->LastFrameInst >= 0)
    500     report_fatal_error("Frame register and offset already specified!");
    501   if (Offset & 0x0F)
    502     report_fatal_error("Misaligned frame pointer offset!");
    503   MCWin64EHInstruction Inst(Win64EH::UOP_SetFPReg, NULL, Register, Offset);
    504   CurFrame->LastFrameInst = CurFrame->Instructions.size();
    505   CurFrame->Instructions.push_back(Inst);
    506 }
    507 
    508 void MCStreamer::EmitWin64EHAllocStack(unsigned Size) {
    509   EnsureValidW64UnwindInfo();
    510   if (Size & 7)
    511     report_fatal_error("Misaligned stack allocation!");
    512   MCWin64EHUnwindInfo *CurFrame = CurrentW64UnwindInfo;
    513   MCSymbol *Label = getContext().CreateTempSymbol();
    514   MCWin64EHInstruction Inst(Label, Size);
    515   EmitLabel(Label);
    516   CurFrame->Instructions.push_back(Inst);
    517 }
    518 
    519 void MCStreamer::EmitWin64EHSaveReg(unsigned Register, unsigned Offset) {
    520   EnsureValidW64UnwindInfo();
    521   if (Offset & 7)
    522     report_fatal_error("Misaligned saved register offset!");
    523   MCWin64EHUnwindInfo *CurFrame = CurrentW64UnwindInfo;
    524   MCSymbol *Label = getContext().CreateTempSymbol();
    525   MCWin64EHInstruction Inst(
    526      Offset > 512*1024-8 ? Win64EH::UOP_SaveNonVolBig : Win64EH::UOP_SaveNonVol,
    527                             Label, Register, Offset);
    528   EmitLabel(Label);
    529   CurFrame->Instructions.push_back(Inst);
    530 }
    531 
    532 void MCStreamer::EmitWin64EHSaveXMM(unsigned Register, unsigned Offset) {
    533   EnsureValidW64UnwindInfo();
    534   if (Offset & 0x0F)
    535     report_fatal_error("Misaligned saved vector register offset!");
    536   MCWin64EHUnwindInfo *CurFrame = CurrentW64UnwindInfo;
    537   MCSymbol *Label = getContext().CreateTempSymbol();
    538   MCWin64EHInstruction Inst(
    539     Offset > 512*1024-16 ? Win64EH::UOP_SaveXMM128Big : Win64EH::UOP_SaveXMM128,
    540                             Label, Register, Offset);
    541   EmitLabel(Label);
    542   CurFrame->Instructions.push_back(Inst);
    543 }
    544 
    545 void MCStreamer::EmitWin64EHPushFrame(bool Code) {
    546   EnsureValidW64UnwindInfo();
    547   MCWin64EHUnwindInfo *CurFrame = CurrentW64UnwindInfo;
    548   if (CurFrame->Instructions.size() > 0)
    549     report_fatal_error("If present, PushMachFrame must be the first UOP");
    550   MCSymbol *Label = getContext().CreateTempSymbol();
    551   MCWin64EHInstruction Inst(Win64EH::UOP_PushMachFrame, Label, Code);
    552   EmitLabel(Label);
    553   CurFrame->Instructions.push_back(Inst);
    554 }
    555 
    556 void MCStreamer::EmitWin64EHEndProlog() {
    557   EnsureValidW64UnwindInfo();
    558   MCWin64EHUnwindInfo *CurFrame = CurrentW64UnwindInfo;
    559   CurFrame->PrologEnd = getContext().CreateTempSymbol();
    560   EmitLabel(CurFrame->PrologEnd);
    561 }
    562 
    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 
    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 
    603 /// EmitRawText - If this file is backed by an assembly streamer, this dumps
    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 }
    611 
    612 void MCStreamer::EmitRawText(const Twine &T) {
    613   SmallString<128> Str;
    614   T.toVector(Str);
    615   EmitRawText(Str.str());
    616 }
    617 
    618 void MCStreamer::EmitFrames(bool usingCFI) {
    619   if (!getNumFrameInfos())
    620     return;
    621 
    622   if (EmitEHFrame)
    623     MCDwarfFrameEmitter::Emit(*this, usingCFI, true);
    624 
    625   if (EmitDebugFrame)
    626     MCDwarfFrameEmitter::Emit(*this, usingCFI, false);
    627 }
    628 
    629 void MCStreamer::EmitW64Tables() {
    630   if (!getNumW64UnwindInfos())
    631     return;
    632 
    633   MCWin64EHUnwindEmitter::Emit(*this);
    634 }
    635