1a11af531ec48ad84f790b9511f003ac5c934a999Daniel Dunbar//===- lib/MC/MCStreamer.cpp - Streaming Machine Code Output --------------===//
2a11af531ec48ad84f790b9511f003ac5c934a999Daniel Dunbar//
3a11af531ec48ad84f790b9511f003ac5c934a999Daniel Dunbar//                     The LLVM Compiler Infrastructure
4a11af531ec48ad84f790b9511f003ac5c934a999Daniel Dunbar//
5a11af531ec48ad84f790b9511f003ac5c934a999Daniel Dunbar// This file is distributed under the University of Illinois Open Source
6a11af531ec48ad84f790b9511f003ac5c934a999Daniel Dunbar// License. See LICENSE.TXT for details.
7a11af531ec48ad84f790b9511f003ac5c934a999Daniel Dunbar//
8a11af531ec48ad84f790b9511f003ac5c934a999Daniel Dunbar//===----------------------------------------------------------------------===//
9a11af531ec48ad84f790b9511f003ac5c934a999Daniel Dunbar
10d04a8d4b33ff316ca4cf961e06c9e312eff8e64fChandler Carruth#include "llvm/MC/MCStreamer.h"
11d04a8d4b33ff316ca4cf961e06c9e312eff8e64fChandler Carruth#include "llvm/ADT/SmallString.h"
12d04a8d4b33ff316ca4cf961e06c9e312eff8e64fChandler Carruth#include "llvm/ADT/Twine.h"
13c3cee57f7d20f69a84fd88464ed8cf050e63c7adBill Wendling#include "llvm/MC/MCAsmBackend.h"
140bbe0b440ee2cef47dcb7b281825eb70341c16ddRafael Espindola#include "llvm/MC/MCAsmInfo.h"
15af6b5808756d6ce335df9eb158efa33894b401c4Rafael Espindola#include "llvm/MC/MCContext.h"
16ddf6bdde44287b5b559bc403a02ff971e15e8303Chris Lattner#include "llvm/MC/MCExpr.h"
1736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines#include "llvm/MC/MCObjectFileInfo.h"
18c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby#include "llvm/MC/MCObjectWriter.h"
19ed708f9c1facb9928ef2f79503e7030c8f25b00dRafael Espindola#include "llvm/MC/MCSymbol.h"
20484291c27319668ad99cb87def000254357736fbRafael Espindola#include "llvm/Support/ErrorHandling.h"
212d39a0e52df9ce050bd4e2de3a2ecca8fd9a87c3Jim Grosbach#include "llvm/Support/LEB128.h"
22d04a8d4b33ff316ca4cf961e06c9e312eff8e64fChandler Carruth#include "llvm/Support/raw_ostream.h"
233580dea910d622f2a6dbb72e97f5f7d0ef979542Chris Lattner#include <cstdlib>
24a11af531ec48ad84f790b9511f003ac5c934a999Daniel Dunbarusing namespace llvm;
25a11af531ec48ad84f790b9511f003ac5c934a999Daniel Dunbar
26354362524a72b3fa43a6c09380b7ae3b2380cbbaJuergen Ributzka// Pin the vtables to this file.
27320296a4cfe414ce59f406b8a5ce15272f563103Rafael EspindolaMCTargetStreamer::~MCTargetStreamer() {}
28320296a4cfe414ce59f406b8a5ce15272f563103Rafael Espindola
2936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen HinesMCTargetStreamer::MCTargetStreamer(MCStreamer &S) : Streamer(S) {
3036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  S.setTargetStreamer(this);
3136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines}
3236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines
3336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hinesvoid MCTargetStreamer::emitLabel(MCSymbol *Symbol) {}
3436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines
3536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hinesvoid MCTargetStreamer::finish() {}
3636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines
3736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hinesvoid MCTargetStreamer::emitAssignment(MCSymbol *Symbol, const MCExpr *Value) {}
3836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines
3936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen HinesMCStreamer::MCStreamer(MCContext &Ctx)
40cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines    : Context(Ctx), CurrentW64UnwindInfo(nullptr) {
41df39be6cb4eb44011db3d3e86f8fe463f81ce127Peter Collingbourne  SectionStack.push_back(std::pair<MCSectionSubPair, MCSectionSubPair>());
42a11af531ec48ad84f790b9511f003ac5c934a999Daniel Dunbar}
43a11af531ec48ad84f790b9511f003ac5c934a999Daniel Dunbar
44a11af531ec48ad84f790b9511f003ac5c934a999Daniel DunbarMCStreamer::~MCStreamer() {
454eeb7b662b78f5c520fb258b3f9df18b1227cde5Charles Davis  for (unsigned i = 0; i < getNumW64UnwindInfos(); ++i)
464eeb7b662b78f5c520fb258b3f9df18b1227cde5Charles Davis    delete W64UnwindInfos[i];
47a11af531ec48ad84f790b9511f003ac5c934a999Daniel Dunbar}
48ddf6bdde44287b5b559bc403a02ff971e15e8303Chris Lattner
495399d2502acaf96fe8420e61913e77f0b23650ffPedro Artigasvoid MCStreamer::reset() {
505399d2502acaf96fe8420e61913e77f0b23650ffPedro Artigas  for (unsigned i = 0; i < getNumW64UnwindInfos(); ++i)
515399d2502acaf96fe8420e61913e77f0b23650ffPedro Artigas    delete W64UnwindInfos[i];
528cb6b971601d42a27e40f0f1d4828671441989f5Charles Davis  W64UnwindInfos.clear();
53dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines  CurrentW64UnwindInfo = nullptr;
545399d2502acaf96fe8420e61913e77f0b23650ffPedro Artigas  SectionStack.clear();
55df39be6cb4eb44011db3d3e86f8fe463f81ce127Peter Collingbourne  SectionStack.push_back(std::pair<MCSectionSubPair, MCSectionSubPair>());
565399d2502acaf96fe8420e61913e77f0b23650ffPedro Artigas}
575399d2502acaf96fe8420e61913e77f0b23650ffPedro Artigas
58a37bd1d02c0e3d93474fdf30352bf4a425cbe25bRafael Espindolaconst MCExpr *MCStreamer::BuildSymbolDiff(MCContext &Context,
59a37bd1d02c0e3d93474fdf30352bf4a425cbe25bRafael Espindola                                          const MCSymbol *A,
60a37bd1d02c0e3d93474fdf30352bf4a425cbe25bRafael Espindola                                          const MCSymbol *B) {
61a37bd1d02c0e3d93474fdf30352bf4a425cbe25bRafael Espindola  MCSymbolRefExpr::VariantKind Variant = MCSymbolRefExpr::VK_None;
62a37bd1d02c0e3d93474fdf30352bf4a425cbe25bRafael Espindola  const MCExpr *ARef =
63a37bd1d02c0e3d93474fdf30352bf4a425cbe25bRafael Espindola    MCSymbolRefExpr::Create(A, Variant, Context);
64a37bd1d02c0e3d93474fdf30352bf4a425cbe25bRafael Espindola  const MCExpr *BRef =
65a37bd1d02c0e3d93474fdf30352bf4a425cbe25bRafael Espindola    MCSymbolRefExpr::Create(B, Variant, Context);
66a37bd1d02c0e3d93474fdf30352bf4a425cbe25bRafael Espindola  const MCExpr *AddrDelta =
67a37bd1d02c0e3d93474fdf30352bf4a425cbe25bRafael Espindola    MCBinaryExpr::Create(MCBinaryExpr::Sub, ARef, BRef, Context);
68a37bd1d02c0e3d93474fdf30352bf4a425cbe25bRafael Espindola  return AddrDelta;
69a37bd1d02c0e3d93474fdf30352bf4a425cbe25bRafael Espindola}
70a37bd1d02c0e3d93474fdf30352bf4a425cbe25bRafael Espindola
71a6f2678f08299f053feb58337fc4322131d99bf4Rafael Espindolaconst MCExpr *MCStreamer::ForceExpAbs(const MCExpr* Expr) {
7236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  assert(!isa<MCSymbolRefExpr>(Expr));
7336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  if (Context.getAsmInfo()->hasAggressiveSymbolFolding())
74a6f2678f08299f053feb58337fc4322131d99bf4Rafael Espindola    return Expr;
75a6f2678f08299f053feb58337fc4322131d99bf4Rafael Espindola
76a6f2678f08299f053feb58337fc4322131d99bf4Rafael Espindola  MCSymbol *ABS = Context.CreateTempSymbol();
77a6f2678f08299f053feb58337fc4322131d99bf4Rafael Espindola  EmitAssignment(ABS, Expr);
78a6f2678f08299f053feb58337fc4322131d99bf4Rafael Espindola  return MCSymbolRefExpr::Create(ABS, Context);
79a37bd1d02c0e3d93474fdf30352bf4a425cbe25bRafael Espindola}
80a37bd1d02c0e3d93474fdf30352bf4a425cbe25bRafael Espindola
81d79d9dce47d505369662ae5111dba24f9ccdef68Chris Lattnerraw_ostream &MCStreamer::GetCommentOS() {
82d79d9dce47d505369662ae5111dba24f9ccdef68Chris Lattner  // By default, discard comments.
83d79d9dce47d505369662ae5111dba24f9ccdef68Chris Lattner  return nulls();
84c3cee57f7d20f69a84fd88464ed8cf050e63c7adBill Wendling}
85c3cee57f7d20f69a84fd88464ed8cf050e63c7adBill Wendling
8636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hinesvoid MCStreamer::emitRawComment(const Twine &T, bool TabPrefix) {}
8736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines
88da11df0c22f5d0ba2e2be3ae4a7076c806233db8Bill Wendlingvoid MCStreamer::generateCompactUnwindEncodings(MCAsmBackend *MAB) {
89c3cee57f7d20f69a84fd88464ed8cf050e63c7adBill Wendling  for (std::vector<MCDwarfFrameInfo>::iterator I = FrameInfos.begin(),
90c3cee57f7d20f69a84fd88464ed8cf050e63c7adBill Wendling         E = FrameInfos.end(); I != E; ++I)
91da11df0c22f5d0ba2e2be3ae4a7076c806233db8Bill Wendling    I->CompactUnwindEncoding =
921d5ad97531a0213f06cc526a0c8ea7b2150f6accBill Wendling      (MAB ? MAB->generateCompactUnwindEncoding(I->Instructions) : 0);
93d79d9dce47d505369662ae5111dba24f9ccdef68Chris Lattner}
94d79d9dce47d505369662ae5111dba24f9ccdef68Chris Lattner
9532a006e606742b1c5401e49607e33717bb5441f0Rafael Espindolavoid MCStreamer::EmitDwarfSetLineAddr(int64_t LineDelta,
9632a006e606742b1c5401e49607e33717bb5441f0Rafael Espindola                                      const MCSymbol *Label, int PointerSize) {
9732a006e606742b1c5401e49607e33717bb5441f0Rafael Espindola  // emit the sequence to set the address
9832a006e606742b1c5401e49607e33717bb5441f0Rafael Espindola  EmitIntValue(dwarf::DW_LNS_extended_op, 1);
9932a006e606742b1c5401e49607e33717bb5441f0Rafael Espindola  EmitULEB128IntValue(PointerSize + 1);
10032a006e606742b1c5401e49607e33717bb5441f0Rafael Espindola  EmitIntValue(dwarf::DW_LNE_set_address, 1);
10132a006e606742b1c5401e49607e33717bb5441f0Rafael Espindola  EmitSymbolValue(Label, PointerSize);
10232a006e606742b1c5401e49607e33717bb5441f0Rafael Espindola
10332a006e606742b1c5401e49607e33717bb5441f0Rafael Espindola  // emit the sequence for the LineDelta (from 1) and a zero address delta.
10432a006e606742b1c5401e49607e33717bb5441f0Rafael Espindola  MCDwarfLineAddr::Emit(this, LineDelta, 0);
10532a006e606742b1c5401e49607e33717bb5441f0Rafael Espindola}
106d79d9dce47d505369662ae5111dba24f9ccdef68Chris Lattner
10732ae3fe0ba469240753e2342e36485f7c9acfb5cChris Lattner/// EmitIntValue - Special case of EmitValue that avoids the client having to
10832ae3fe0ba469240753e2342e36485f7c9acfb5cChris Lattner/// pass in a MCExpr for constant integers.
109a3863ea2dacafc925a8272ebf9884fc64bef686cRafael Espindolavoid MCStreamer::EmitIntValue(uint64_t Value, unsigned Size) {
110dea914bed9fb1d5c08e944557989ccddb6849000Devang Patel  assert(Size <= 8 && "Invalid size");
111818b5f5dd7979b097564f829896353df286127ffMatt Beaumont-Gay  assert((isUIntN(8 * Size, Value) || isIntN(8 * Size, Value)) &&
112818b5f5dd7979b097564f829896353df286127ffMatt Beaumont-Gay         "Invalid size");
1132df042cb32ecb8d2e1d499dfa27d5074c8b40e13Rafael Espindola  char buf[8];
11499cb622041a0839c7dfcf0263c5102a305a0fdb5Bill Wendling  const bool isLittleEndian = Context.getAsmInfo()->isLittleEndian();
11565891533a3b35d7fc8fa807a96b7ee2f09ff22b5Roman Divacky  for (unsigned i = 0; i != Size; ++i) {
11665891533a3b35d7fc8fa807a96b7ee2f09ff22b5Roman Divacky    unsigned index = isLittleEndian ? i : (Size - i - 1);
11765891533a3b35d7fc8fa807a96b7ee2f09ff22b5Roman Divacky    buf[i] = uint8_t(Value >> (index * 8));
11865891533a3b35d7fc8fa807a96b7ee2f09ff22b5Roman Divacky  }
119a3863ea2dacafc925a8272ebf9884fc64bef686cRafael Espindola  EmitBytes(StringRef(buf, Size));
12032ae3fe0ba469240753e2342e36485f7c9acfb5cChris Lattner}
12132ae3fe0ba469240753e2342e36485f7c9acfb5cChris Lattner
1223ff57094a7d176a759ddb1e1668489d89064f56cRafael Espindola/// EmitULEB128Value - Special case of EmitULEB128Value that avoids the
1233ff57094a7d176a759ddb1e1668489d89064f56cRafael Espindola/// client having to pass in a MCExpr for constant integers.
124a3863ea2dacafc925a8272ebf9884fc64bef686cRafael Espindolavoid MCStreamer::EmitULEB128IntValue(uint64_t Value, unsigned Padding) {
125b601ab5cce6c560dff365cd87f6854ea95f76f54Benjamin Kramer  SmallString<128> Tmp;
126660b5fc4d019bf22fbe14dfb81c5b59444fa3506Rafael Espindola  raw_svector_ostream OSE(Tmp);
1272d39a0e52df9ce050bd4e2de3a2ecca8fd9a87c3Jim Grosbach  encodeULEB128(Value, OSE, Padding);
128a3863ea2dacafc925a8272ebf9884fc64bef686cRafael Espindola  EmitBytes(OSE.str());
129c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby}
130c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby
1313ff57094a7d176a759ddb1e1668489d89064f56cRafael Espindola/// EmitSLEB128Value - Special case of EmitSLEB128Value that avoids the
1323ff57094a7d176a759ddb1e1668489d89064f56cRafael Espindola/// client having to pass in a MCExpr for constant integers.
133a3863ea2dacafc925a8272ebf9884fc64bef686cRafael Espindolavoid MCStreamer::EmitSLEB128IntValue(int64_t Value) {
134b601ab5cce6c560dff365cd87f6854ea95f76f54Benjamin Kramer  SmallString<128> Tmp;
135660b5fc4d019bf22fbe14dfb81c5b59444fa3506Rafael Espindola  raw_svector_ostream OSE(Tmp);
1362d39a0e52df9ce050bd4e2de3a2ecca8fd9a87c3Jim Grosbach  encodeSLEB128(Value, OSE);
137a3863ea2dacafc925a8272ebf9884fc64bef686cRafael Espindola  EmitBytes(OSE.str());
138c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby}
139c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby
140a3863ea2dacafc925a8272ebf9884fc64bef686cRafael Espindolavoid MCStreamer::EmitAbsValue(const MCExpr *Value, unsigned Size) {
141a6f2678f08299f053feb58337fc4322131d99bf4Rafael Espindola  const MCExpr *ABS = ForceExpAbs(Value);
142a3863ea2dacafc925a8272ebf9884fc64bef686cRafael Espindola  EmitValue(ABS, Size);
1430bbe0b440ee2cef47dcb7b281825eb70341c16ddRafael Espindola}
1440bbe0b440ee2cef47dcb7b281825eb70341c16ddRafael Espindola
14589b9372605db2ce3b0085c84089e389f7bc1fbddRafael Espindola
146dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hinesvoid MCStreamer::EmitValue(const MCExpr *Value, unsigned Size,
147dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines                           const SMLoc &Loc) {
148dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines  EmitValueImpl(Value, Size, Loc);
14989b9372605db2ce3b0085c84089e389f7bc1fbddRafael Espindola}
15089b9372605db2ce3b0085c84089e389f7bc1fbddRafael Espindola
151a3863ea2dacafc925a8272ebf9884fc64bef686cRafael Espindolavoid MCStreamer::EmitSymbolValue(const MCSymbol *Sym, unsigned Size) {
152a3863ea2dacafc925a8272ebf9884fc64bef686cRafael Espindola  EmitValueImpl(MCSymbolRefExpr::Create(Sym, getContext()), Size);
15389b9372605db2ce3b0085c84089e389f7bc1fbddRafael Espindola}
15489b9372605db2ce3b0085c84089e389f7bc1fbddRafael Espindola
1556c2cf8b1fbcf70fd9db6fe44032c1ceaa2299760Akira Hatanakavoid MCStreamer::EmitGPRel64Value(const MCExpr *Value) {
1566c2cf8b1fbcf70fd9db6fe44032c1ceaa2299760Akira Hatanaka  report_fatal_error("unsupported directive in streamer");
1576c2cf8b1fbcf70fd9db6fe44032c1ceaa2299760Akira Hatanaka}
1586c2cf8b1fbcf70fd9db6fe44032c1ceaa2299760Akira Hatanaka
1593e03211625bba5bbb70a193c140ebf4dd8388bb7Rafael Espindolavoid MCStreamer::EmitGPRel32Value(const MCExpr *Value) {
1603e03211625bba5bbb70a193c140ebf4dd8388bb7Rafael Espindola  report_fatal_error("unsupported directive in streamer");
1613e03211625bba5bbb70a193c140ebf4dd8388bb7Rafael Espindola}
1623e03211625bba5bbb70a193c140ebf4dd8388bb7Rafael Espindola
163ddf6bdde44287b5b559bc403a02ff971e15e8303Chris Lattner/// EmitFill - Emit NumBytes bytes worth of the value specified by
164ddf6bdde44287b5b559bc403a02ff971e15e8303Chris Lattner/// FillValue.  This implements directives such as '.space'.
165a3863ea2dacafc925a8272ebf9884fc64bef686cRafael Espindolavoid MCStreamer::EmitFill(uint64_t NumBytes, uint8_t FillValue) {
166ddf6bdde44287b5b559bc403a02ff971e15e8303Chris Lattner  const MCExpr *E = MCConstantExpr::Create(FillValue, getContext());
167ddf6bdde44287b5b559bc403a02ff971e15e8303Chris Lattner  for (uint64_t i = 0, e = NumBytes; i != e; ++i)
168a3863ea2dacafc925a8272ebf9884fc64bef686cRafael Espindola    EmitValue(E, 1);
169ddf6bdde44287b5b559bc403a02ff971e15e8303Chris Lattner}
17091bead790518fcf5cb26019fb1ebf2372e8a5b3fChris Lattner
171a3863ea2dacafc925a8272ebf9884fc64bef686cRafael Espindola/// The implementation in this class just redirects to EmitFill.
172a3863ea2dacafc925a8272ebf9884fc64bef686cRafael Espindolavoid MCStreamer::EmitZeros(uint64_t NumBytes) {
173a3863ea2dacafc925a8272ebf9884fc64bef686cRafael Espindola  EmitFill(NumBytes, 0);
174b02f1e9a6bc332ebd77571fdffcdc44d77e76b31Serge Pavlov}
175b02f1e9a6bc332ebd77571fdffcdc44d77e76b31Serge Pavlov
17636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hinesunsigned MCStreamer::EmitDwarfFileDirective(unsigned FileNo,
17736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines                                            StringRef Directory,
17836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines                                            StringRef Filename, unsigned CUID) {
17936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  return getContext().GetDwarfFile(Directory, Filename, FileNo, CUID);
180af6b5808756d6ce335df9eb158efa33894b401c4Rafael Espindola}
181af6b5808756d6ce335df9eb158efa33894b401c4Rafael Espindola
182af6b5808756d6ce335df9eb158efa33894b401c4Rafael Espindolavoid MCStreamer::EmitDwarfLocDirective(unsigned FileNo, unsigned Line,
183af6b5808756d6ce335df9eb158efa33894b401c4Rafael Espindola                                       unsigned Column, unsigned Flags,
184af6b5808756d6ce335df9eb158efa33894b401c4Rafael Espindola                                       unsigned Isa,
1853f3bf9387b75f4c932e4c59bd7af719d26ae4b99Devang Patel                                       unsigned Discriminator,
1863f3bf9387b75f4c932e4c59bd7af719d26ae4b99Devang Patel                                       StringRef FileName) {
187af6b5808756d6ce335df9eb158efa33894b401c4Rafael Espindola  getContext().setCurrentDwarfLoc(FileNo, Line, Column, Flags, Isa,
188af6b5808756d6ce335df9eb158efa33894b401c4Rafael Espindola                                  Discriminator);
189af6b5808756d6ce335df9eb158efa33894b401c4Rafael Espindola}
190af6b5808756d6ce335df9eb158efa33894b401c4Rafael Espindola
19136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen HinesMCSymbol *MCStreamer::getDwarfLineTableSymbol(unsigned CUID) {
19236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  MCDwarfLineTable &Table = getContext().getMCDwarfLineTable(CUID);
19336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  if (!Table.getLabel()) {
19436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines    StringRef Prefix = Context.getAsmInfo()->getPrivateGlobalPrefix();
19536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines    Table.setLabel(
19636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines        Context.GetOrCreateSymbol(Prefix + "line_table_start" + Twine(CUID)));
19736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  }
19836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  return Table.getLabel();
19936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines}
20036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines
20189b9372605db2ce3b0085c84089e389f7bc1fbddRafael EspindolaMCDwarfFrameInfo *MCStreamer::getCurrentFrameInfo() {
20289b9372605db2ce3b0085c84089e389f7bc1fbddRafael Espindola  if (FrameInfos.empty())
203dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines    return nullptr;
20489b9372605db2ce3b0085c84089e389f7bc1fbddRafael Espindola  return &FrameInfos.back();
20589b9372605db2ce3b0085c84089e389f7bc1fbddRafael Espindola}
20689b9372605db2ce3b0085c84089e389f7bc1fbddRafael Espindola
20789b9372605db2ce3b0085c84089e389f7bc1fbddRafael Espindolavoid MCStreamer::EnsureValidFrame() {
20889b9372605db2ce3b0085c84089e389f7bc1fbddRafael Espindola  MCDwarfFrameInfo *CurFrame = getCurrentFrameInfo();
20989b9372605db2ce3b0085c84089e389f7bc1fbddRafael Espindola  if (!CurFrame || CurFrame->End)
21089b9372605db2ce3b0085c84089e389f7bc1fbddRafael Espindola    report_fatal_error("No open frame");
21189b9372605db2ce3b0085c84089e389f7bc1fbddRafael Espindola}
21289b9372605db2ce3b0085c84089e389f7bc1fbddRafael Espindola
2138bca4106dfc2945723251db10e340183f3e372ddRafael Espindolavoid MCStreamer::EmitEHSymAttributes(const MCSymbol *Symbol,
2148bca4106dfc2945723251db10e340183f3e372ddRafael Espindola                                     MCSymbol *EHSymbol) {
2158bca4106dfc2945723251db10e340183f3e372ddRafael Espindola}
2168bca4106dfc2945723251db10e340183f3e372ddRafael Espindola
21736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hinesvoid MCStreamer::InitSections() {
21836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  SwitchSection(getContext().getObjectFileInfo()->getTextSection());
21936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines}
22036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines
2215cc319a42a914b24b164a94d9a563c728a7a4026Richard Mittonvoid MCStreamer::AssignSection(MCSymbol *Symbol, const MCSection *Section) {
2225cc319a42a914b24b164a94d9a563c728a7a4026Richard Mitton  if (Section)
2235cc319a42a914b24b164a94d9a563c728a7a4026Richard Mitton    Symbol->setSection(*Section);
2245cc319a42a914b24b164a94d9a563c728a7a4026Richard Mitton  else
2255cc319a42a914b24b164a94d9a563c728a7a4026Richard Mitton    Symbol->setUndefined();
2265cc319a42a914b24b164a94d9a563c728a7a4026Richard Mitton
2275cc319a42a914b24b164a94d9a563c728a7a4026Richard Mitton  // As we emit symbols into a section, track the order so that they can
2285cc319a42a914b24b164a94d9a563c728a7a4026Richard Mitton  // be sorted upon later. Zero is reserved to mean 'unemitted'.
2295cc319a42a914b24b164a94d9a563c728a7a4026Richard Mitton  SymbolOrdering[Symbol] = 1 + SymbolOrdering.size();
2305cc319a42a914b24b164a94d9a563c728a7a4026Richard Mitton}
2315cc319a42a914b24b164a94d9a563c728a7a4026Richard Mitton
232ed708f9c1facb9928ef2f79503e7030c8f25b00dRafael Espindolavoid MCStreamer::EmitLabel(MCSymbol *Symbol) {
233ed708f9c1facb9928ef2f79503e7030c8f25b00dRafael Espindola  assert(!Symbol->isVariable() && "Cannot emit a variable symbol!");
234df39be6cb4eb44011db3d3e86f8fe463f81ce127Peter Collingbourne  assert(getCurrentSection().first && "Cannot emit before setting section!");
2355cc319a42a914b24b164a94d9a563c728a7a4026Richard Mitton  AssignSection(Symbol, getCurrentSection().first);
23636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines
23736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  MCTargetStreamer *TS = getTargetStreamer();
23836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  if (TS)
23936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines    TS->emitLabel(Symbol);
240ed708f9c1facb9928ef2f79503e7030c8f25b00dRafael Espindola}
241ed708f9c1facb9928ef2f79503e7030c8f25b00dRafael Espindola
242d967578a8c506be341d20a1558eebb31484b8b6dBill Wendlingvoid MCStreamer::EmitCompactUnwindEncoding(uint32_t CompactUnwindEncoding) {
243d967578a8c506be341d20a1558eebb31484b8b6dBill Wendling  EnsureValidFrame();
244d967578a8c506be341d20a1558eebb31484b8b6dBill Wendling  MCDwarfFrameInfo *CurFrame = getCurrentFrameInfo();
245d967578a8c506be341d20a1558eebb31484b8b6dBill Wendling  CurFrame->CompactUnwindEncoding = CompactUnwindEncoding;
246d967578a8c506be341d20a1558eebb31484b8b6dBill Wendling}
247d967578a8c506be341d20a1558eebb31484b8b6dBill Wendling
248f9efd83166401bca542c6702ea329f9901c4e04bRafael Espindolavoid MCStreamer::EmitCFISections(bool EH, bool Debug) {
249713c4bfc36260bfc9273d414b14757bd7819f9b1Rafael Espindola  assert(EH || Debug);
250f9efd83166401bca542c6702ea329f9901c4e04bRafael Espindola}
251f9efd83166401bca542c6702ea329f9901c4e04bRafael Espindola
25236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hinesvoid MCStreamer::EmitCFIStartProc(bool IsSimple) {
25389b9372605db2ce3b0085c84089e389f7bc1fbddRafael Espindola  MCDwarfFrameInfo *CurFrame = getCurrentFrameInfo();
254066c2f495ae396ce5335e374c45b1e4ace4f2470Rafael Espindola  if (CurFrame && !CurFrame->End)
25589b9372605db2ce3b0085c84089e389f7bc1fbddRafael Espindola    report_fatal_error("Starting a frame before finishing the previous one!");
25649cb9b88867426d1a430f248550d3cc785a68fe4Rafael Espindola
2575fbe5e783ee0c5ae27c17490a752d7e603e84ed2Evan Cheng  MCDwarfFrameInfo Frame;
25836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  Frame.IsSimple = IsSimple;
259547be2699c547b79a7735858a64921d8ccf180f7Rafael Espindola  EmitCFIStartProcImpl(Frame);
260547be2699c547b79a7735858a64921d8ccf180f7Rafael Espindola
261547be2699c547b79a7735858a64921d8ccf180f7Rafael Espindola  FrameInfos.push_back(Frame);
262547be2699c547b79a7735858a64921d8ccf180f7Rafael Espindola}
26349cb9b88867426d1a430f248550d3cc785a68fe4Rafael Espindola
264547be2699c547b79a7735858a64921d8ccf180f7Rafael Espindolavoid MCStreamer::EmitCFIStartProcImpl(MCDwarfFrameInfo &Frame) {
265547be2699c547b79a7735858a64921d8ccf180f7Rafael Espindola}
266547be2699c547b79a7735858a64921d8ccf180f7Rafael Espindola
267066c2f495ae396ce5335e374c45b1e4ace4f2470Rafael Espindolavoid MCStreamer::EmitCFIEndProc() {
26889b9372605db2ce3b0085c84089e389f7bc1fbddRafael Espindola  EnsureValidFrame();
26989b9372605db2ce3b0085c84089e389f7bc1fbddRafael Espindola  MCDwarfFrameInfo *CurFrame = getCurrentFrameInfo();
2701fe9737eb49ecb80fbb547f0e16e10a726cd53cfRafael Espindola  EmitCFIEndProcImpl(*CurFrame);
2711fe9737eb49ecb80fbb547f0e16e10a726cd53cfRafael Espindola}
2721fe9737eb49ecb80fbb547f0e16e10a726cd53cfRafael Espindola
2731fe9737eb49ecb80fbb547f0e16e10a726cd53cfRafael Espindolavoid MCStreamer::EmitCFIEndProcImpl(MCDwarfFrameInfo &Frame) {
274cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines  // Put a dummy non-null value in Frame.End to mark that this frame has been
275cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines  // closed.
276cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines  Frame.End = (MCSymbol *) 1;
277cdfecc8759941c2996214070478d30084b79d463Rafael Espindola}
278cdfecc8759941c2996214070478d30084b79d463Rafael Espindola
279529a01df02ad221e8e55097a8ee36b85234eb078Rafael EspindolaMCSymbol *MCStreamer::EmitCFICommon() {
280b40a71fda188f8ca564e606ac2cb051a44ada311Rafael Espindola  EnsureValidFrame();
281b40a71fda188f8ca564e606ac2cb051a44ada311Rafael Espindola  MCSymbol *Label = getContext().CreateTempSymbol();
282b40a71fda188f8ca564e606ac2cb051a44ada311Rafael Espindola  EmitLabel(Label);
283529a01df02ad221e8e55097a8ee36b85234eb078Rafael Espindola  return Label;
284529a01df02ad221e8e55097a8ee36b85234eb078Rafael Espindola}
285529a01df02ad221e8e55097a8ee36b85234eb078Rafael Espindola
286529a01df02ad221e8e55097a8ee36b85234eb078Rafael Espindolavoid MCStreamer::EmitCFIDefCfa(int64_t Register, int64_t Offset) {
287529a01df02ad221e8e55097a8ee36b85234eb078Rafael Espindola  MCSymbol *Label = EmitCFICommon();
28828c9ea3c13dfb8f6bb3226ba511d189135fcb140Rafael Espindola  MCCFIInstruction Instruction =
28928c9ea3c13dfb8f6bb3226ba511d189135fcb140Rafael Espindola    MCCFIInstruction::createDefCfa(Label, Register, Offset);
290529a01df02ad221e8e55097a8ee36b85234eb078Rafael Espindola  MCDwarfFrameInfo *CurFrame = getCurrentFrameInfo();
291b40a71fda188f8ca564e606ac2cb051a44ada311Rafael Espindola  CurFrame->Instructions.push_back(Instruction);
292b40a71fda188f8ca564e606ac2cb051a44ada311Rafael Espindola}
293b40a71fda188f8ca564e606ac2cb051a44ada311Rafael Espindola
294066c2f495ae396ce5335e374c45b1e4ace4f2470Rafael Espindolavoid MCStreamer::EmitCFIDefCfaOffset(int64_t Offset) {
295529a01df02ad221e8e55097a8ee36b85234eb078Rafael Espindola  MCSymbol *Label = EmitCFICommon();
29628c9ea3c13dfb8f6bb3226ba511d189135fcb140Rafael Espindola  MCCFIInstruction Instruction =
29728c9ea3c13dfb8f6bb3226ba511d189135fcb140Rafael Espindola    MCCFIInstruction::createDefCfaOffset(Label, Offset);
298529a01df02ad221e8e55097a8ee36b85234eb078Rafael Espindola  MCDwarfFrameInfo *CurFrame = getCurrentFrameInfo();
299fe024d0a624404ada11fb330e7360abc5f88742eRafael Espindola  CurFrame->Instructions.push_back(Instruction);
300cdfecc8759941c2996214070478d30084b79d463Rafael Espindola}
301cdfecc8759941c2996214070478d30084b79d463Rafael Espindola
3025d7dcd3335234d2a2bc16dc69f86fbb5dcaa8962Rafael Espindolavoid MCStreamer::EmitCFIAdjustCfaOffset(int64_t Adjustment) {
303529a01df02ad221e8e55097a8ee36b85234eb078Rafael Espindola  MCSymbol *Label = EmitCFICommon();
30428c9ea3c13dfb8f6bb3226ba511d189135fcb140Rafael Espindola  MCCFIInstruction Instruction =
30528c9ea3c13dfb8f6bb3226ba511d189135fcb140Rafael Espindola    MCCFIInstruction::createAdjustCfaOffset(Label, Adjustment);
306529a01df02ad221e8e55097a8ee36b85234eb078Rafael Espindola  MCDwarfFrameInfo *CurFrame = getCurrentFrameInfo();
3075d7dcd3335234d2a2bc16dc69f86fbb5dcaa8962Rafael Espindola  CurFrame->Instructions.push_back(Instruction);
3085d7dcd3335234d2a2bc16dc69f86fbb5dcaa8962Rafael Espindola}
3095d7dcd3335234d2a2bc16dc69f86fbb5dcaa8962Rafael Espindola
310066c2f495ae396ce5335e374c45b1e4ace4f2470Rafael Espindolavoid MCStreamer::EmitCFIDefCfaRegister(int64_t Register) {
311529a01df02ad221e8e55097a8ee36b85234eb078Rafael Espindola  MCSymbol *Label = EmitCFICommon();
31228c9ea3c13dfb8f6bb3226ba511d189135fcb140Rafael Espindola  MCCFIInstruction Instruction =
31328c9ea3c13dfb8f6bb3226ba511d189135fcb140Rafael Espindola    MCCFIInstruction::createDefCfaRegister(Label, Register);
314529a01df02ad221e8e55097a8ee36b85234eb078Rafael Espindola  MCDwarfFrameInfo *CurFrame = getCurrentFrameInfo();
315b4601bd2ffdde372f1323f6b6ec98acd433501ceRafael Espindola  CurFrame->Instructions.push_back(Instruction);
316cdfecc8759941c2996214070478d30084b79d463Rafael Espindola}
317cdfecc8759941c2996214070478d30084b79d463Rafael Espindola
318066c2f495ae396ce5335e374c45b1e4ace4f2470Rafael Espindolavoid MCStreamer::EmitCFIOffset(int64_t Register, int64_t Offset) {
319529a01df02ad221e8e55097a8ee36b85234eb078Rafael Espindola  MCSymbol *Label = EmitCFICommon();
32028c9ea3c13dfb8f6bb3226ba511d189135fcb140Rafael Espindola  MCCFIInstruction Instruction =
3217f74d2c2c197eec76ae2b41fed9c227c0dcc04cbRafael Espindola    MCCFIInstruction::createOffset(Label, Register, Offset);
322529a01df02ad221e8e55097a8ee36b85234eb078Rafael Espindola  MCDwarfFrameInfo *CurFrame = getCurrentFrameInfo();
323b790a17efba26f4365b5ffb847dd53fde063c48dRafael Espindola  CurFrame->Instructions.push_back(Instruction);
324cdfecc8759941c2996214070478d30084b79d463Rafael Espindola}
325cdfecc8759941c2996214070478d30084b79d463Rafael Espindola
32625f492e77858dc5a95fcd7180e73aff47925b668Rafael Espindolavoid MCStreamer::EmitCFIRelOffset(int64_t Register, int64_t Offset) {
327529a01df02ad221e8e55097a8ee36b85234eb078Rafael Espindola  MCSymbol *Label = EmitCFICommon();
32828c9ea3c13dfb8f6bb3226ba511d189135fcb140Rafael Espindola  MCCFIInstruction Instruction =
32928c9ea3c13dfb8f6bb3226ba511d189135fcb140Rafael Espindola    MCCFIInstruction::createRelOffset(Label, Register, Offset);
330529a01df02ad221e8e55097a8ee36b85234eb078Rafael Espindola  MCDwarfFrameInfo *CurFrame = getCurrentFrameInfo();
33125f492e77858dc5a95fcd7180e73aff47925b668Rafael Espindola  CurFrame->Instructions.push_back(Instruction);
33225f492e77858dc5a95fcd7180e73aff47925b668Rafael Espindola}
33325f492e77858dc5a95fcd7180e73aff47925b668Rafael Espindola
334066c2f495ae396ce5335e374c45b1e4ace4f2470Rafael Espindolavoid MCStreamer::EmitCFIPersonality(const MCSymbol *Sym,
3353a83c40ab61d5ca624f2bbadd70237c6adbdb304Rafael Espindola                                    unsigned Encoding) {
33689b9372605db2ce3b0085c84089e389f7bc1fbddRafael Espindola  EnsureValidFrame();
33789b9372605db2ce3b0085c84089e389f7bc1fbddRafael Espindola  MCDwarfFrameInfo *CurFrame = getCurrentFrameInfo();
33889b9372605db2ce3b0085c84089e389f7bc1fbddRafael Espindola  CurFrame->Personality = Sym;
3393a83c40ab61d5ca624f2bbadd70237c6adbdb304Rafael Espindola  CurFrame->PersonalityEncoding = Encoding;
340cdfecc8759941c2996214070478d30084b79d463Rafael Espindola}
341cdfecc8759941c2996214070478d30084b79d463Rafael Espindola
342066c2f495ae396ce5335e374c45b1e4ace4f2470Rafael Espindolavoid MCStreamer::EmitCFILsda(const MCSymbol *Sym, unsigned Encoding) {
34389b9372605db2ce3b0085c84089e389f7bc1fbddRafael Espindola  EnsureValidFrame();
34489b9372605db2ce3b0085c84089e389f7bc1fbddRafael Espindola  MCDwarfFrameInfo *CurFrame = getCurrentFrameInfo();
34589b9372605db2ce3b0085c84089e389f7bc1fbddRafael Espindola  CurFrame->Lsda = Sym;
346bdc3167c086dd4358e24692075db5e7784140843Rafael Espindola  CurFrame->LsdaEncoding = Encoding;
347cdfecc8759941c2996214070478d30084b79d463Rafael Espindola}
348cdfecc8759941c2996214070478d30084b79d463Rafael Espindola
349066c2f495ae396ce5335e374c45b1e4ace4f2470Rafael Espindolavoid MCStreamer::EmitCFIRememberState() {
350529a01df02ad221e8e55097a8ee36b85234eb078Rafael Espindola  MCSymbol *Label = EmitCFICommon();
35128c9ea3c13dfb8f6bb3226ba511d189135fcb140Rafael Espindola  MCCFIInstruction Instruction = MCCFIInstruction::createRememberState(Label);
352529a01df02ad221e8e55097a8ee36b85234eb078Rafael Espindola  MCDwarfFrameInfo *CurFrame = getCurrentFrameInfo();
353fe024d0a624404ada11fb330e7360abc5f88742eRafael Espindola  CurFrame->Instructions.push_back(Instruction);
354fe024d0a624404ada11fb330e7360abc5f88742eRafael Espindola}
355fe024d0a624404ada11fb330e7360abc5f88742eRafael Espindola
356066c2f495ae396ce5335e374c45b1e4ace4f2470Rafael Espindolavoid MCStreamer::EmitCFIRestoreState() {
357fe024d0a624404ada11fb330e7360abc5f88742eRafael Espindola  // FIXME: Error if there is no matching cfi_remember_state.
358529a01df02ad221e8e55097a8ee36b85234eb078Rafael Espindola  MCSymbol *Label = EmitCFICommon();
35928c9ea3c13dfb8f6bb3226ba511d189135fcb140Rafael Espindola  MCCFIInstruction Instruction = MCCFIInstruction::createRestoreState(Label);
360529a01df02ad221e8e55097a8ee36b85234eb078Rafael Espindola  MCDwarfFrameInfo *CurFrame = getCurrentFrameInfo();
361fe024d0a624404ada11fb330e7360abc5f88742eRafael Espindola  CurFrame->Instructions.push_back(Instruction);
362fe024d0a624404ada11fb330e7360abc5f88742eRafael Espindola}
363fe024d0a624404ada11fb330e7360abc5f88742eRafael Espindola
364c57543964d1382d3d3a5005f415b6c0f49671b3aRafael Espindolavoid MCStreamer::EmitCFISameValue(int64_t Register) {
365529a01df02ad221e8e55097a8ee36b85234eb078Rafael Espindola  MCSymbol *Label = EmitCFICommon();
36628c9ea3c13dfb8f6bb3226ba511d189135fcb140Rafael Espindola  MCCFIInstruction Instruction =
36728c9ea3c13dfb8f6bb3226ba511d189135fcb140Rafael Espindola    MCCFIInstruction::createSameValue(Label, Register);
368529a01df02ad221e8e55097a8ee36b85234eb078Rafael Espindola  MCDwarfFrameInfo *CurFrame = getCurrentFrameInfo();
369c57543964d1382d3d3a5005f415b6c0f49671b3aRafael Espindola  CurFrame->Instructions.push_back(Instruction);
370c57543964d1382d3d3a5005f415b6c0f49671b3aRafael Espindola}
371c57543964d1382d3d3a5005f415b6c0f49671b3aRafael Espindola
372ed23bdb65fe86cdb7a38c8c1998ec965e6973966Rafael Espindolavoid MCStreamer::EmitCFIRestore(int64_t Register) {
373529a01df02ad221e8e55097a8ee36b85234eb078Rafael Espindola  MCSymbol *Label = EmitCFICommon();
37428c9ea3c13dfb8f6bb3226ba511d189135fcb140Rafael Espindola  MCCFIInstruction Instruction =
37528c9ea3c13dfb8f6bb3226ba511d189135fcb140Rafael Espindola    MCCFIInstruction::createRestore(Label, Register);
376529a01df02ad221e8e55097a8ee36b85234eb078Rafael Espindola  MCDwarfFrameInfo *CurFrame = getCurrentFrameInfo();
377ed23bdb65fe86cdb7a38c8c1998ec965e6973966Rafael Espindola  CurFrame->Instructions.push_back(Instruction);
378ed23bdb65fe86cdb7a38c8c1998ec965e6973966Rafael Espindola}
379ed23bdb65fe86cdb7a38c8c1998ec965e6973966Rafael Espindola
3806f0b181bc70318f8d5d4b9bdead7fc748677fe2aRafael Espindolavoid MCStreamer::EmitCFIEscape(StringRef Values) {
381529a01df02ad221e8e55097a8ee36b85234eb078Rafael Espindola  MCSymbol *Label = EmitCFICommon();
38228c9ea3c13dfb8f6bb3226ba511d189135fcb140Rafael Espindola  MCCFIInstruction Instruction = MCCFIInstruction::createEscape(Label, Values);
383529a01df02ad221e8e55097a8ee36b85234eb078Rafael Espindola  MCDwarfFrameInfo *CurFrame = getCurrentFrameInfo();
3846f0b181bc70318f8d5d4b9bdead7fc748677fe2aRafael Espindola  CurFrame->Instructions.push_back(Instruction);
3856f0b181bc70318f8d5d4b9bdead7fc748677fe2aRafael Espindola}
3866f0b181bc70318f8d5d4b9bdead7fc748677fe2aRafael Espindola
38716d7d437e03ce87fdaef7971919302920d54a966Rafael Espindolavoid MCStreamer::EmitCFISignalFrame() {
38816d7d437e03ce87fdaef7971919302920d54a966Rafael Espindola  EnsureValidFrame();
38916d7d437e03ce87fdaef7971919302920d54a966Rafael Espindola  MCDwarfFrameInfo *CurFrame = getCurrentFrameInfo();
39016d7d437e03ce87fdaef7971919302920d54a966Rafael Espindola  CurFrame->IsSignalFrame = true;
39116d7d437e03ce87fdaef7971919302920d54a966Rafael Espindola}
39216d7d437e03ce87fdaef7971919302920d54a966Rafael Espindola
393c8fec7e21f5c24303eab8a8592f3b8faff347d86Rafael Espindolavoid MCStreamer::EmitCFIUndefined(int64_t Register) {
394529a01df02ad221e8e55097a8ee36b85234eb078Rafael Espindola  MCSymbol *Label = EmitCFICommon();
39528c9ea3c13dfb8f6bb3226ba511d189135fcb140Rafael Espindola  MCCFIInstruction Instruction =
39628c9ea3c13dfb8f6bb3226ba511d189135fcb140Rafael Espindola    MCCFIInstruction::createUndefined(Label, Register);
397529a01df02ad221e8e55097a8ee36b85234eb078Rafael Espindola  MCDwarfFrameInfo *CurFrame = getCurrentFrameInfo();
398c8fec7e21f5c24303eab8a8592f3b8faff347d86Rafael Espindola  CurFrame->Instructions.push_back(Instruction);
399c8fec7e21f5c24303eab8a8592f3b8faff347d86Rafael Espindola}
400c8fec7e21f5c24303eab8a8592f3b8faff347d86Rafael Espindola
401f4f14f68f6078ea6681ee27b5bf42719d7db3441Rafael Espindolavoid MCStreamer::EmitCFIRegister(int64_t Register1, int64_t Register2) {
402f4f14f68f6078ea6681ee27b5bf42719d7db3441Rafael Espindola  MCSymbol *Label = EmitCFICommon();
403f4f14f68f6078ea6681ee27b5bf42719d7db3441Rafael Espindola  MCCFIInstruction Instruction =
404f4f14f68f6078ea6681ee27b5bf42719d7db3441Rafael Espindola    MCCFIInstruction::createRegister(Label, Register1, Register2);
405f4f14f68f6078ea6681ee27b5bf42719d7db3441Rafael Espindola  MCDwarfFrameInfo *CurFrame = getCurrentFrameInfo();
406f4f14f68f6078ea6681ee27b5bf42719d7db3441Rafael Espindola  CurFrame->Instructions.push_back(Instruction);
407f4f14f68f6078ea6681ee27b5bf42719d7db3441Rafael Espindola}
408f4f14f68f6078ea6681ee27b5bf42719d7db3441Rafael Espindola
40983ba58e5f0a5afbb23d7d2092d817accded4455aVenkatraman Govindarajuvoid MCStreamer::EmitCFIWindowSave() {
41083ba58e5f0a5afbb23d7d2092d817accded4455aVenkatraman Govindaraju  MCSymbol *Label = EmitCFICommon();
41183ba58e5f0a5afbb23d7d2092d817accded4455aVenkatraman Govindaraju  MCCFIInstruction Instruction =
41283ba58e5f0a5afbb23d7d2092d817accded4455aVenkatraman Govindaraju    MCCFIInstruction::createWindowSave(Label);
41383ba58e5f0a5afbb23d7d2092d817accded4455aVenkatraman Govindaraju  MCDwarfFrameInfo *CurFrame = getCurrentFrameInfo();
41483ba58e5f0a5afbb23d7d2092d817accded4455aVenkatraman Govindaraju  CurFrame->Instructions.push_back(Instruction);
41583ba58e5f0a5afbb23d7d2092d817accded4455aVenkatraman Govindaraju}
41683ba58e5f0a5afbb23d7d2092d817accded4455aVenkatraman Govindaraju
41791d9a1c0f7c598d51c50f80bc9e8dfc1494f78c1Charles Davisvoid MCStreamer::setCurrentW64UnwindInfo(MCWin64EHUnwindInfo *Frame) {
418ca93138e11f404a19553049a569f1fa6ad491b67Charles Davis  W64UnwindInfos.push_back(Frame);
419ca93138e11f404a19553049a569f1fa6ad491b67Charles Davis  CurrentW64UnwindInfo = W64UnwindInfos.back();
4209c77398d1c89f615735d304cd7eda3c3e9b1504fCharles Davis}
4219c77398d1c89f615735d304cd7eda3c3e9b1504fCharles Davis
4220855bc5b973320052c87bdcc2fa17b9711edc3deCharles Davisvoid MCStreamer::EnsureValidW64UnwindInfo() {
42391d9a1c0f7c598d51c50f80bc9e8dfc1494f78c1Charles Davis  MCWin64EHUnwindInfo *CurFrame = CurrentW64UnwindInfo;
4240855bc5b973320052c87bdcc2fa17b9711edc3deCharles Davis  if (!CurFrame || CurFrame->End)
4250855bc5b973320052c87bdcc2fa17b9711edc3deCharles Davis    report_fatal_error("No open Win64 EH frame function!");
4260855bc5b973320052c87bdcc2fa17b9711edc3deCharles Davis}
4270855bc5b973320052c87bdcc2fa17b9711edc3deCharles Davis
428cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hinesvoid MCStreamer::EmitWinCFIStartProc(const MCSymbol *Symbol) {
42991d9a1c0f7c598d51c50f80bc9e8dfc1494f78c1Charles Davis  MCWin64EHUnwindInfo *CurFrame = CurrentW64UnwindInfo;
4300855bc5b973320052c87bdcc2fa17b9711edc3deCharles Davis  if (CurFrame && !CurFrame->End)
4310855bc5b973320052c87bdcc2fa17b9711edc3deCharles Davis    report_fatal_error("Starting a function before ending the previous one!");
4324eeb7b662b78f5c520fb258b3f9df18b1227cde5Charles Davis  MCWin64EHUnwindInfo *Frame = new MCWin64EHUnwindInfo;
433ca93138e11f404a19553049a569f1fa6ad491b67Charles Davis  Frame->Begin = getContext().CreateTempSymbol();
434ca93138e11f404a19553049a569f1fa6ad491b67Charles Davis  Frame->Function = Symbol;
435ca93138e11f404a19553049a569f1fa6ad491b67Charles Davis  EmitLabel(Frame->Begin);
436ca93138e11f404a19553049a569f1fa6ad491b67Charles Davis  setCurrentW64UnwindInfo(Frame);
4370855bc5b973320052c87bdcc2fa17b9711edc3deCharles Davis}
4380855bc5b973320052c87bdcc2fa17b9711edc3deCharles Davis
439cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hinesvoid MCStreamer::EmitWinCFIEndProc() {
4400855bc5b973320052c87bdcc2fa17b9711edc3deCharles Davis  EnsureValidW64UnwindInfo();
44191d9a1c0f7c598d51c50f80bc9e8dfc1494f78c1Charles Davis  MCWin64EHUnwindInfo *CurFrame = CurrentW64UnwindInfo;
44291d9a1c0f7c598d51c50f80bc9e8dfc1494f78c1Charles Davis  if (CurFrame->ChainedParent)
4430855bc5b973320052c87bdcc2fa17b9711edc3deCharles Davis    report_fatal_error("Not all chained regions terminated!");
4440855bc5b973320052c87bdcc2fa17b9711edc3deCharles Davis  CurFrame->End = getContext().CreateTempSymbol();
4450855bc5b973320052c87bdcc2fa17b9711edc3deCharles Davis  EmitLabel(CurFrame->End);
446ff96a12db635daf4f88cfea899e63a885dfaa9edCharles Davis}
447ff96a12db635daf4f88cfea899e63a885dfaa9edCharles Davis
448cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hinesvoid MCStreamer::EmitWinCFIStartChained() {
44991d9a1c0f7c598d51c50f80bc9e8dfc1494f78c1Charles Davis  EnsureValidW64UnwindInfo();
4504eeb7b662b78f5c520fb258b3f9df18b1227cde5Charles Davis  MCWin64EHUnwindInfo *Frame = new MCWin64EHUnwindInfo;
45191d9a1c0f7c598d51c50f80bc9e8dfc1494f78c1Charles Davis  MCWin64EHUnwindInfo *CurFrame = CurrentW64UnwindInfo;
452ca93138e11f404a19553049a569f1fa6ad491b67Charles Davis  Frame->Begin = getContext().CreateTempSymbol();
453ca93138e11f404a19553049a569f1fa6ad491b67Charles Davis  Frame->Function = CurFrame->Function;
454ca93138e11f404a19553049a569f1fa6ad491b67Charles Davis  Frame->ChainedParent = CurFrame;
455ca93138e11f404a19553049a569f1fa6ad491b67Charles Davis  EmitLabel(Frame->Begin);
456ca93138e11f404a19553049a569f1fa6ad491b67Charles Davis  setCurrentW64UnwindInfo(Frame);
457f07090134d06e0cf3508e8b8e87d775f0a7982c1Charles Davis}
458f07090134d06e0cf3508e8b8e87d775f0a7982c1Charles Davis
459cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hinesvoid MCStreamer::EmitWinCFIEndChained() {
46091d9a1c0f7c598d51c50f80bc9e8dfc1494f78c1Charles Davis  EnsureValidW64UnwindInfo();
46191d9a1c0f7c598d51c50f80bc9e8dfc1494f78c1Charles Davis  MCWin64EHUnwindInfo *CurFrame = CurrentW64UnwindInfo;
46291d9a1c0f7c598d51c50f80bc9e8dfc1494f78c1Charles Davis  if (!CurFrame->ChainedParent)
46391d9a1c0f7c598d51c50f80bc9e8dfc1494f78c1Charles Davis    report_fatal_error("End of a chained region outside a chained region!");
46491d9a1c0f7c598d51c50f80bc9e8dfc1494f78c1Charles Davis  CurFrame->End = getContext().CreateTempSymbol();
46591d9a1c0f7c598d51c50f80bc9e8dfc1494f78c1Charles Davis  EmitLabel(CurFrame->End);
46691d9a1c0f7c598d51c50f80bc9e8dfc1494f78c1Charles Davis  CurrentW64UnwindInfo = CurFrame->ChainedParent;
467f07090134d06e0cf3508e8b8e87d775f0a7982c1Charles Davis}
468f07090134d06e0cf3508e8b8e87d775f0a7982c1Charles Davis
469cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hinesvoid MCStreamer::EmitWinEHHandler(const MCSymbol *Sym, bool Unwind,
470cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines                                  bool Except) {
471440596ffe5bb77a202acb36d5eadd158976ff39aCharles Davis  EnsureValidW64UnwindInfo();
472440596ffe5bb77a202acb36d5eadd158976ff39aCharles Davis  MCWin64EHUnwindInfo *CurFrame = CurrentW64UnwindInfo;
47381f3830f2ed0b26e8bd7ae62e127db427f9f350dCharles Davis  if (CurFrame->ChainedParent)
47481f3830f2ed0b26e8bd7ae62e127db427f9f350dCharles Davis    report_fatal_error("Chained unwind areas can't have handlers!");
475440596ffe5bb77a202acb36d5eadd158976ff39aCharles Davis  CurFrame->ExceptionHandler = Sym;
476321fe74b2d40d7762175fbd3054fda00b5e70833Charles Davis  if (!Except && !Unwind)
477440596ffe5bb77a202acb36d5eadd158976ff39aCharles Davis    report_fatal_error("Don't know what kind of handler this is!");
478321fe74b2d40d7762175fbd3054fda00b5e70833Charles Davis  if (Unwind)
479321fe74b2d40d7762175fbd3054fda00b5e70833Charles Davis    CurFrame->HandlesUnwind = true;
480321fe74b2d40d7762175fbd3054fda00b5e70833Charles Davis  if (Except)
481321fe74b2d40d7762175fbd3054fda00b5e70833Charles Davis    CurFrame->HandlesExceptions = true;
482440596ffe5bb77a202acb36d5eadd158976ff39aCharles Davis}
483440596ffe5bb77a202acb36d5eadd158976ff39aCharles Davis
484cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hinesvoid MCStreamer::EmitWinEHHandlerData() {
485d0b76d00048352affac4fad0ef005e28f5340b76Charles Davis  EnsureValidW64UnwindInfo();
48681f3830f2ed0b26e8bd7ae62e127db427f9f350dCharles Davis  MCWin64EHUnwindInfo *CurFrame = CurrentW64UnwindInfo;
48781f3830f2ed0b26e8bd7ae62e127db427f9f350dCharles Davis  if (CurFrame->ChainedParent)
48881f3830f2ed0b26e8bd7ae62e127db427f9f350dCharles Davis    report_fatal_error("Chained unwind areas can't have handlers!");
489f07090134d06e0cf3508e8b8e87d775f0a7982c1Charles Davis}
490f07090134d06e0cf3508e8b8e87d775f0a7982c1Charles Davis
491cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hinesvoid MCStreamer::EmitWinCFIPushReg(unsigned Register) {
492c3b162857a587c9877e903f038471b882b213232Charles Davis  EnsureValidW64UnwindInfo();
493c3b162857a587c9877e903f038471b882b213232Charles Davis  MCWin64EHUnwindInfo *CurFrame = CurrentW64UnwindInfo;
494c4cbf9b6aa95cf861a5a80bfccf615ff5c53e4efCharles Davis  MCSymbol *Label = getContext().CreateTempSymbol();
495c4cbf9b6aa95cf861a5a80bfccf615ff5c53e4efCharles Davis  MCWin64EHInstruction Inst(Win64EH::UOP_PushNonVol, Label, Register);
496c4cbf9b6aa95cf861a5a80bfccf615ff5c53e4efCharles Davis  EmitLabel(Label);
497c3b162857a587c9877e903f038471b882b213232Charles Davis  CurFrame->Instructions.push_back(Inst);
498f07090134d06e0cf3508e8b8e87d775f0a7982c1Charles Davis}
499f07090134d06e0cf3508e8b8e87d775f0a7982c1Charles Davis
500cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hinesvoid MCStreamer::EmitWinCFISetFrame(unsigned Register, unsigned Offset) {
501c3b162857a587c9877e903f038471b882b213232Charles Davis  EnsureValidW64UnwindInfo();
502c2d3022aa6104a21f4368c522ccbf9a4d282b7c6Charles Davis  MCWin64EHUnwindInfo *CurFrame = CurrentW64UnwindInfo;
503c2d3022aa6104a21f4368c522ccbf9a4d282b7c6Charles Davis  if (CurFrame->LastFrameInst >= 0)
504c2d3022aa6104a21f4368c522ccbf9a4d282b7c6Charles Davis    report_fatal_error("Frame register and offset already specified!");
505edeecbff0e231c04b7222a79a26017a48668f0e2Charles Davis  if (Offset & 0x0F)
506edeecbff0e231c04b7222a79a26017a48668f0e2Charles Davis    report_fatal_error("Misaligned frame pointer offset!");
507cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines  if (Offset > 240)
508cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines    report_fatal_error("Frame offset must be less than or equal to 240!");
509f0a0d578089572be37063bbe37063edb28148159Kai Nacke  MCSymbol *Label = getContext().CreateTempSymbol();
510f0a0d578089572be37063bbe37063edb28148159Kai Nacke  MCWin64EHInstruction Inst(Win64EH::UOP_SetFPReg, Label, Register, Offset);
511f0a0d578089572be37063bbe37063edb28148159Kai Nacke  EmitLabel(Label);
5125c2256a5719172273eaef198f92d8af924ff8623Charles Davis  CurFrame->LastFrameInst = CurFrame->Instructions.size();
513c3b162857a587c9877e903f038471b882b213232Charles Davis  CurFrame->Instructions.push_back(Inst);
514ff96a12db635daf4f88cfea899e63a885dfaa9edCharles Davis}
515ff96a12db635daf4f88cfea899e63a885dfaa9edCharles Davis
516cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hinesvoid MCStreamer::EmitWinCFIAllocStack(unsigned Size) {
517c3b162857a587c9877e903f038471b882b213232Charles Davis  EnsureValidW64UnwindInfo();
518cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines  if (Size == 0)
519cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines    report_fatal_error("Allocation size must be non-zero!");
520edeecbff0e231c04b7222a79a26017a48668f0e2Charles Davis  if (Size & 7)
521edeecbff0e231c04b7222a79a26017a48668f0e2Charles Davis    report_fatal_error("Misaligned stack allocation!");
522c3b162857a587c9877e903f038471b882b213232Charles Davis  MCWin64EHUnwindInfo *CurFrame = CurrentW64UnwindInfo;
523c4cbf9b6aa95cf861a5a80bfccf615ff5c53e4efCharles Davis  MCSymbol *Label = getContext().CreateTempSymbol();
524c4cbf9b6aa95cf861a5a80bfccf615ff5c53e4efCharles Davis  MCWin64EHInstruction Inst(Label, Size);
525c4cbf9b6aa95cf861a5a80bfccf615ff5c53e4efCharles Davis  EmitLabel(Label);
526c3b162857a587c9877e903f038471b882b213232Charles Davis  CurFrame->Instructions.push_back(Inst);
527ff96a12db635daf4f88cfea899e63a885dfaa9edCharles Davis}
528ff96a12db635daf4f88cfea899e63a885dfaa9edCharles Davis
529cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hinesvoid MCStreamer::EmitWinCFISaveReg(unsigned Register, unsigned Offset) {
530c3b162857a587c9877e903f038471b882b213232Charles Davis  EnsureValidW64UnwindInfo();
531edeecbff0e231c04b7222a79a26017a48668f0e2Charles Davis  if (Offset & 7)
532edeecbff0e231c04b7222a79a26017a48668f0e2Charles Davis    report_fatal_error("Misaligned saved register offset!");
533c3b162857a587c9877e903f038471b882b213232Charles Davis  MCWin64EHUnwindInfo *CurFrame = CurrentW64UnwindInfo;
534c4cbf9b6aa95cf861a5a80bfccf615ff5c53e4efCharles Davis  MCSymbol *Label = getContext().CreateTempSymbol();
535c3b162857a587c9877e903f038471b882b213232Charles Davis  MCWin64EHInstruction Inst(
536c2d3022aa6104a21f4368c522ccbf9a4d282b7c6Charles Davis     Offset > 512*1024-8 ? Win64EH::UOP_SaveNonVolBig : Win64EH::UOP_SaveNonVol,
537c4cbf9b6aa95cf861a5a80bfccf615ff5c53e4efCharles Davis                            Label, Register, Offset);
538c4cbf9b6aa95cf861a5a80bfccf615ff5c53e4efCharles Davis  EmitLabel(Label);
539c3b162857a587c9877e903f038471b882b213232Charles Davis  CurFrame->Instructions.push_back(Inst);
540ff96a12db635daf4f88cfea899e63a885dfaa9edCharles Davis}
541ff96a12db635daf4f88cfea899e63a885dfaa9edCharles Davis
542cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hinesvoid MCStreamer::EmitWinCFISaveXMM(unsigned Register, unsigned Offset) {
543c3b162857a587c9877e903f038471b882b213232Charles Davis  EnsureValidW64UnwindInfo();
544edeecbff0e231c04b7222a79a26017a48668f0e2Charles Davis  if (Offset & 0x0F)
545edeecbff0e231c04b7222a79a26017a48668f0e2Charles Davis    report_fatal_error("Misaligned saved vector register offset!");
546c3b162857a587c9877e903f038471b882b213232Charles Davis  MCWin64EHUnwindInfo *CurFrame = CurrentW64UnwindInfo;
547c4cbf9b6aa95cf861a5a80bfccf615ff5c53e4efCharles Davis  MCSymbol *Label = getContext().CreateTempSymbol();
548c3b162857a587c9877e903f038471b882b213232Charles Davis  MCWin64EHInstruction Inst(
549c2d3022aa6104a21f4368c522ccbf9a4d282b7c6Charles Davis    Offset > 512*1024-16 ? Win64EH::UOP_SaveXMM128Big : Win64EH::UOP_SaveXMM128,
550c4cbf9b6aa95cf861a5a80bfccf615ff5c53e4efCharles Davis                            Label, Register, Offset);
551c4cbf9b6aa95cf861a5a80bfccf615ff5c53e4efCharles Davis  EmitLabel(Label);
552c3b162857a587c9877e903f038471b882b213232Charles Davis  CurFrame->Instructions.push_back(Inst);
553ff96a12db635daf4f88cfea899e63a885dfaa9edCharles Davis}
554ff96a12db635daf4f88cfea899e63a885dfaa9edCharles Davis
555cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hinesvoid MCStreamer::EmitWinCFIPushFrame(bool Code) {
556c3b162857a587c9877e903f038471b882b213232Charles Davis  EnsureValidW64UnwindInfo();
557c3b162857a587c9877e903f038471b882b213232Charles Davis  MCWin64EHUnwindInfo *CurFrame = CurrentW64UnwindInfo;
558c2d3022aa6104a21f4368c522ccbf9a4d282b7c6Charles Davis  if (CurFrame->Instructions.size() > 0)
559c2d3022aa6104a21f4368c522ccbf9a4d282b7c6Charles Davis    report_fatal_error("If present, PushMachFrame must be the first UOP");
560c4cbf9b6aa95cf861a5a80bfccf615ff5c53e4efCharles Davis  MCSymbol *Label = getContext().CreateTempSymbol();
561c4cbf9b6aa95cf861a5a80bfccf615ff5c53e4efCharles Davis  MCWin64EHInstruction Inst(Win64EH::UOP_PushMachFrame, Label, Code);
562c4cbf9b6aa95cf861a5a80bfccf615ff5c53e4efCharles Davis  EmitLabel(Label);
563c3b162857a587c9877e903f038471b882b213232Charles Davis  CurFrame->Instructions.push_back(Inst);
564ff96a12db635daf4f88cfea899e63a885dfaa9edCharles Davis}
565ff96a12db635daf4f88cfea899e63a885dfaa9edCharles Davis
566cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hinesvoid MCStreamer::EmitWinCFIEndProlog() {
56761558aaf4f924fd44fd2f275fcb7ab7199ede304Charles Davis  EnsureValidW64UnwindInfo();
56861558aaf4f924fd44fd2f275fcb7ab7199ede304Charles Davis  MCWin64EHUnwindInfo *CurFrame = CurrentW64UnwindInfo;
56961558aaf4f924fd44fd2f275fcb7ab7199ede304Charles Davis  CurFrame->PrologEnd = getContext().CreateTempSymbol();
57061558aaf4f924fd44fd2f275fcb7ab7199ede304Charles Davis  EmitLabel(CurFrame->PrologEnd);
571cacdc4fc41f035c149d5f1b92acd587d475ffd58Charles Davis}
572cacdc4fc41f035c149d5f1b92acd587d475ffd58Charles Davis
57336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hinesvoid MCStreamer::EmitCOFFSectionIndex(MCSymbol const *Symbol) {
57436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines}
57536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines
5768f7d12ccfd8feb258bdf4e582592bc00beacc7c6Rafael Espindolavoid MCStreamer::EmitCOFFSecRel32(MCSymbol const *Symbol) {
5778f7d12ccfd8feb258bdf4e582592bc00beacc7c6Rafael Espindola}
5788f7d12ccfd8feb258bdf4e582592bc00beacc7c6Rafael Espindola
579ab3b3651add0915a5a051b177029ad117a877f52Matt Fleming/// EmitRawText - If this file is backed by an assembly streamer, this dumps
58091bead790518fcf5cb26019fb1ebf2372e8a5b3fChris Lattner/// the specified string in the output .s file.  This capability is
58191bead790518fcf5cb26019fb1ebf2372e8a5b3fChris Lattner/// indicated by the hasRawTextSupport() predicate.
5825759c3a02902026a27a0d1bc24a5bad85f52bd71David Blaikievoid MCStreamer::EmitRawTextImpl(StringRef String) {
58391bead790518fcf5cb26019fb1ebf2372e8a5b3fChris Lattner  errs() << "EmitRawText called on an MCStreamer that doesn't support it, "
58491bead790518fcf5cb26019fb1ebf2372e8a5b3fChris Lattner  " something must not be fully mc'ized\n";
58591bead790518fcf5cb26019fb1ebf2372e8a5b3fChris Lattner  abort();
58691bead790518fcf5cb26019fb1ebf2372e8a5b3fChris Lattner}
58758bc4dd4a91443ddd3120b0a2f1801ad4d6aae1cChris Lattner
58858bc4dd4a91443ddd3120b0a2f1801ad4d6aae1cChris Lattnervoid MCStreamer::EmitRawText(const Twine &T) {
58958bc4dd4a91443ddd3120b0a2f1801ad4d6aae1cChris Lattner  SmallString<128> Str;
5905759c3a02902026a27a0d1bc24a5bad85f52bd71David Blaikie  EmitRawTextImpl(T.toStringRef(Str));
59158bc4dd4a91443ddd3120b0a2f1801ad4d6aae1cChris Lattner}
592c25dad8750083829d9a8935ce40d0734e5488f8eRafael Espindola
59338ea9eecd7c810e11f96c8306b241f9db88fc62fCharles Davisvoid MCStreamer::EmitW64Tables() {
59438ea9eecd7c810e11f96c8306b241f9db88fc62fCharles Davis  if (!getNumW64UnwindInfos())
59538ea9eecd7c810e11f96c8306b241f9db88fc62fCharles Davis    return;
59638ea9eecd7c810e11f96c8306b241f9db88fc62fCharles Davis
59738ea9eecd7c810e11f96c8306b241f9db88fc62fCharles Davis  MCWin64EHUnwindEmitter::Emit(*this);
59838ea9eecd7c810e11f96c8306b241f9db88fc62fCharles Davis}
59999b4237c1647156f0e1d3d7e03efdab23ed79778Rafael Espindola
60099b4237c1647156f0e1d3d7e03efdab23ed79778Rafael Espindolavoid MCStreamer::Finish() {
60199b4237c1647156f0e1d3d7e03efdab23ed79778Rafael Espindola  if (!FrameInfos.empty() && !FrameInfos.back().End)
60299b4237c1647156f0e1d3d7e03efdab23ed79778Rafael Espindola    report_fatal_error("Unfinished frame!");
60399b4237c1647156f0e1d3d7e03efdab23ed79778Rafael Espindola
60436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  MCTargetStreamer *TS = getTargetStreamer();
60536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  if (TS)
60636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines    TS->finish();
60736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines
60899b4237c1647156f0e1d3d7e03efdab23ed79778Rafael Espindola  FinishImpl();
60999b4237c1647156f0e1d3d7e03efdab23ed79778Rafael Espindola}
61077afbdce53aa740777486b0cc4e9df151ae65468Jack Carter
61136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hinesvoid MCStreamer::EmitAssignment(MCSymbol *Symbol, const MCExpr *Value) {
612cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines  visitUsedExpr(*Value);
61336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  Symbol->setVariableValue(Value);
61436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines
61536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  MCTargetStreamer *TS = getTargetStreamer();
61636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  if (TS)
61736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines    TS->emitAssignment(Symbol, Value);
61836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines}
619cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines
620cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hinesvoid MCStreamer::visitUsedSymbol(const MCSymbol &Sym) {
621cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines}
622cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines
623cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hinesvoid MCStreamer::visitUsedExpr(const MCExpr &Expr) {
624cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines  switch (Expr.getKind()) {
625cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines  case MCExpr::Target:
626cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines    cast<MCTargetExpr>(Expr).visitUsedExpr(*this);
627cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines    break;
628cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines
629cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines  case MCExpr::Constant:
630cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines    break;
631cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines
632cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines  case MCExpr::Binary: {
633cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines    const MCBinaryExpr &BE = cast<MCBinaryExpr>(Expr);
634cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines    visitUsedExpr(*BE.getLHS());
635cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines    visitUsedExpr(*BE.getRHS());
636cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines    break;
637cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines  }
638cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines
639cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines  case MCExpr::SymbolRef:
640cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines    visitUsedSymbol(cast<MCSymbolRefExpr>(Expr).getSymbol());
641cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines    break;
642cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines
643cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines  case MCExpr::Unary:
644cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines    visitUsedExpr(*cast<MCUnaryExpr>(Expr).getSubExpr());
645cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines    break;
646cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines  }
647cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines}
648cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines
649cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hinesvoid MCStreamer::EmitInstruction(const MCInst &Inst,
650cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines                                 const MCSubtargetInfo &STI) {
651cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines  // Scan for values.
652cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines  for (unsigned i = Inst.getNumOperands(); i--;)
653cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines    if (Inst.getOperand(i).isExpr())
654cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines      visitUsedExpr(*Inst.getOperand(i).getExpr());
655cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines}
656cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines
657cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hinesvoid MCStreamer::EmitAssemblerFlag(MCAssemblerFlag Flag) {}
658cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hinesvoid MCStreamer::EmitThumbFunc(MCSymbol *Func) {}
659cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hinesvoid MCStreamer::EmitSymbolDesc(MCSymbol *Symbol, unsigned DescValue) {}
660cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hinesvoid MCStreamer::BeginCOFFSymbolDef(const MCSymbol *Symbol) {}
661cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hinesvoid MCStreamer::EndCOFFSymbolDef() {}
662cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hinesvoid MCStreamer::EmitFileDirective(StringRef Filename) {}
663cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hinesvoid MCStreamer::EmitCOFFSymbolStorageClass(int StorageClass) {}
664cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hinesvoid MCStreamer::EmitCOFFSymbolType(int Type) {}
665cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hinesvoid MCStreamer::EmitELFSize(MCSymbol *Symbol, const MCExpr *Value) {}
666cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hinesvoid MCStreamer::EmitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size,
667cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines                                       unsigned ByteAlignment) {}
668cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hinesvoid MCStreamer::EmitTBSSSymbol(const MCSection *Section, MCSymbol *Symbol,
669cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines                                uint64_t Size, unsigned ByteAlignment) {}
670cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hinesvoid MCStreamer::ChangeSection(const MCSection *, const MCExpr *) {}
671cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hinesvoid MCStreamer::EmitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol) {}
672cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hinesvoid MCStreamer::EmitBytes(StringRef Data) {}
673cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hinesvoid MCStreamer::EmitValueImpl(const MCExpr *Value, unsigned Size,
674cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines                               const SMLoc &Loc) {
675cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines  visitUsedExpr(*Value);
676cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines}
677cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hinesvoid MCStreamer::EmitULEB128Value(const MCExpr *Value) {}
678cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hinesvoid MCStreamer::EmitSLEB128Value(const MCExpr *Value) {}
679cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hinesvoid MCStreamer::EmitValueToAlignment(unsigned ByteAlignment, int64_t Value,
680cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines                                      unsigned ValueSize,
681cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines                                      unsigned MaxBytesToEmit) {}
682cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hinesvoid MCStreamer::EmitCodeAlignment(unsigned ByteAlignment,
683cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines                                   unsigned MaxBytesToEmit) {}
684cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hinesbool MCStreamer::EmitValueToOffset(const MCExpr *Offset, unsigned char Value) {
685cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines  return false;
686cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines}
687cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hinesvoid MCStreamer::EmitBundleAlignMode(unsigned AlignPow2) {}
688cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hinesvoid MCStreamer::EmitBundleLock(bool AlignToEnd) {}
689cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hinesvoid MCStreamer::FinishImpl() {}
690cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hinesvoid MCStreamer::EmitBundleUnlock() {}
691