blob: 265f0daef0fd58af6d4a3149dc7a91f26e27242b [file] [log] [blame]
Chris Lattnereb72dca2010-07-11 22:05:00 +00001//===-- llvm/MC/WinCOFFStreamer.cpp -----------------------------*- C++ -*-===//
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// This file contains an implementation of a Win32 COFF object file streamer.
11//
12//===----------------------------------------------------------------------===//
13
14#define DEBUG_TYPE "WinCOFFStreamer"
15
16#include "llvm/MC/MCObjectStreamer.h"
17#include "llvm/MC/MCContext.h"
18#include "llvm/MC/MCSection.h"
19#include "llvm/MC/MCSymbol.h"
20#include "llvm/MC/MCExpr.h"
Michael J. Spencer8067adc2010-07-19 06:13:10 +000021#include "llvm/MC/MCValue.h"
22#include "llvm/MC/MCAssembler.h"
23#include "llvm/MC/MCAsmLayout.h"
Chris Lattnereb72dca2010-07-11 22:05:00 +000024#include "llvm/MC/MCCodeEmitter.h"
25#include "llvm/MC/MCSectionCOFF.h"
Charles Davis3185f5c2011-05-22 03:01:05 +000026#include "llvm/MC/MCWin64EH.h"
Evan Cheng78c10ee2011-07-25 23:24:55 +000027#include "llvm/MC/MCAsmBackend.h"
Michael J. Spencer8067adc2010-07-19 06:13:10 +000028#include "llvm/ADT/StringMap.h"
29
Chris Lattnereb72dca2010-07-11 22:05:00 +000030#include "llvm/Support/COFF.h"
31#include "llvm/Support/Debug.h"
32#include "llvm/Support/ErrorHandling.h"
Evan Cheng3e74d6f2011-08-24 18:08:43 +000033#include "llvm/Support/TargetRegistry.h"
Chris Lattnereb72dca2010-07-11 22:05:00 +000034#include "llvm/Support/raw_ostream.h"
Rafael Espindola8f7d12c2011-12-17 01:14:52 +000035
Chris Lattnereb72dca2010-07-11 22:05:00 +000036using namespace llvm;
37
Chris Lattnereb72dca2010-07-11 22:05:00 +000038namespace {
39class WinCOFFStreamer : public MCObjectStreamer {
40public:
Michael J. Spencer8067adc2010-07-19 06:13:10 +000041 MCSymbol const *CurSymbol;
42
Chris Lattnereb72dca2010-07-11 22:05:00 +000043 WinCOFFStreamer(MCContext &Context,
Evan Cheng78c10ee2011-07-25 23:24:55 +000044 MCAsmBackend &MAB,
Chris Lattnereb72dca2010-07-11 22:05:00 +000045 MCCodeEmitter &CE,
46 raw_ostream &OS);
47
Michael J. Spencer8067adc2010-07-19 06:13:10 +000048 void AddCommonSymbol(MCSymbol *Symbol, uint64_t Size,
49 unsigned ByteAlignment, bool External);
50
Chris Lattnereb72dca2010-07-11 22:05:00 +000051 // MCStreamer interface
52
Rafael Espindolad80781b2010-09-15 21:48:40 +000053 virtual void InitSections();
Rafael Espindolaba210242010-11-28 16:22:59 +000054 virtual void EmitLabel(MCSymbol *Symbol);
Chris Lattnereb72dca2010-07-11 22:05:00 +000055 virtual void EmitAssemblerFlag(MCAssemblerFlag Flag);
Jim Grosbachce792992010-11-05 22:08:08 +000056 virtual void EmitThumbFunc(MCSymbol *Func);
Chris Lattnereb72dca2010-07-11 22:05:00 +000057 virtual void EmitAssignment(MCSymbol *Symbol, const MCExpr *Value);
58 virtual void EmitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute);
59 virtual void EmitSymbolDesc(MCSymbol *Symbol, unsigned DescValue);
60 virtual void BeginCOFFSymbolDef(MCSymbol const *Symbol);
61 virtual void EmitCOFFSymbolStorageClass(int StorageClass);
62 virtual void EmitCOFFSymbolType(int Type);
63 virtual void EndCOFFSymbolDef();
Rafael Espindola8f7d12c2011-12-17 01:14:52 +000064 virtual void EmitCOFFSecRel32(MCSymbol const *Symbol);
Chris Lattnereb72dca2010-07-11 22:05:00 +000065 virtual void EmitELFSize(MCSymbol *Symbol, const MCExpr *Value);
66 virtual void EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
Michael J. Spencer8067adc2010-07-19 06:13:10 +000067 unsigned ByteAlignment);
Benjamin Kramer36a16012011-09-01 23:04:27 +000068 virtual void EmitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size,
69 unsigned ByteAlignment);
Chris Lattnereb72dca2010-07-11 22:05:00 +000070 virtual void EmitZerofill(const MCSection *Section, MCSymbol *Symbol,
Michael J. Spencer8067adc2010-07-19 06:13:10 +000071 unsigned Size,unsigned ByteAlignment);
Chris Lattnereb72dca2010-07-11 22:05:00 +000072 virtual void EmitTBSSSymbol(const MCSection *Section, MCSymbol *Symbol,
Michael J. Spencer8067adc2010-07-19 06:13:10 +000073 uint64_t Size, unsigned ByteAlignment);
Chris Lattnereb72dca2010-07-11 22:05:00 +000074 virtual void EmitBytes(StringRef Data, unsigned AddrSpace);
Chris Lattnereb72dca2010-07-11 22:05:00 +000075 virtual void EmitValueToAlignment(unsigned ByteAlignment, int64_t Value,
Michael J. Spencer8067adc2010-07-19 06:13:10 +000076 unsigned ValueSize, unsigned MaxBytesToEmit);
Chris Lattnereb72dca2010-07-11 22:05:00 +000077 virtual void EmitCodeAlignment(unsigned ByteAlignment,
78 unsigned MaxBytesToEmit);
Chris Lattnereb72dca2010-07-11 22:05:00 +000079 virtual void EmitFileDirective(StringRef Filename);
Chris Lattnereb72dca2010-07-11 22:05:00 +000080 virtual void EmitInstruction(const MCInst &Instruction);
Charles Davis3185f5c2011-05-22 03:01:05 +000081 virtual void EmitWin64EHHandlerData();
Rafael Espindola99b42372012-01-07 03:13:18 +000082 virtual void FinishImpl();
Michael J. Spencer192d1362010-10-09 15:44:27 +000083
84private:
Rafael Espindolaf89671d2010-11-01 16:27:31 +000085 virtual void EmitInstToFragment(const MCInst &Inst) {
86 llvm_unreachable("Not used by WinCOFF.");
87 }
88 virtual void EmitInstToData(const MCInst &Inst) {
89 llvm_unreachable("Not used by WinCOFF.");
90 }
91
Michael J. Spencer192d1362010-10-09 15:44:27 +000092 void SetSection(StringRef Section,
93 unsigned Characteristics,
94 SectionKind Kind) {
95 SwitchSection(getContext().getCOFFSection(Section, Characteristics, Kind));
96 }
97
98 void SetSectionText() {
99 SetSection(".text",
100 COFF::IMAGE_SCN_CNT_CODE
101 | COFF::IMAGE_SCN_MEM_EXECUTE
102 | COFF::IMAGE_SCN_MEM_READ,
103 SectionKind::getText());
104 EmitCodeAlignment(4, 0);
105 }
106
107 void SetSectionData() {
108 SetSection(".data",
109 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA
110 | COFF::IMAGE_SCN_MEM_READ
111 | COFF::IMAGE_SCN_MEM_WRITE,
112 SectionKind::getDataRel());
113 EmitCodeAlignment(4, 0);
114 }
115
116 void SetSectionBSS() {
117 SetSection(".bss",
118 COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA
119 | COFF::IMAGE_SCN_MEM_READ
120 | COFF::IMAGE_SCN_MEM_WRITE,
121 SectionKind::getBSS());
122 EmitCodeAlignment(4, 0);
123 }
124
Chris Lattnereb72dca2010-07-11 22:05:00 +0000125};
126} // end anonymous namespace.
127
128WinCOFFStreamer::WinCOFFStreamer(MCContext &Context,
Evan Cheng78c10ee2011-07-25 23:24:55 +0000129 MCAsmBackend &MAB,
Chris Lattnereb72dca2010-07-11 22:05:00 +0000130 MCCodeEmitter &CE,
131 raw_ostream &OS)
Evan Cheng78c10ee2011-07-25 23:24:55 +0000132 : MCObjectStreamer(Context, MAB, OS, &CE)
Michael J. Spencer8067adc2010-07-19 06:13:10 +0000133 , CurSymbol(NULL) {
134}
135
136void WinCOFFStreamer::AddCommonSymbol(MCSymbol *Symbol, uint64_t Size,
137 unsigned ByteAlignment, bool External) {
138 assert(!Symbol->isInSection() && "Symbol must not already have a section!");
139
140 std::string SectionName(".bss$linkonce");
141 SectionName.append(Symbol->getName().begin(), Symbol->getName().end());
142
143 MCSymbolData &SymbolData = getAssembler().getOrCreateSymbolData(*Symbol);
144
145 unsigned Characteristics =
146 COFF::IMAGE_SCN_LNK_COMDAT |
147 COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA |
148 COFF::IMAGE_SCN_MEM_READ |
149 COFF::IMAGE_SCN_MEM_WRITE;
150
151 int Selection = COFF::IMAGE_COMDAT_SELECT_LARGEST;
152
153 const MCSection *Section = MCStreamer::getContext().getCOFFSection(
154 SectionName, Characteristics, Selection, SectionKind::getBSS());
155
156 MCSectionData &SectionData = getAssembler().getOrCreateSectionData(*Section);
157
158 if (SectionData.getAlignment() < ByteAlignment)
159 SectionData.setAlignment(ByteAlignment);
160
161 SymbolData.setExternal(External);
162
163 Symbol->setSection(*Section);
164
165 if (ByteAlignment != 1)
166 new MCAlignFragment(ByteAlignment, 0, 0, ByteAlignment, &SectionData);
167
168 SymbolData.setFragment(new MCFillFragment(0, 0, Size, &SectionData));
Chris Lattnereb72dca2010-07-11 22:05:00 +0000169}
170
171// MCStreamer interface
172
Rafael Espindolad80781b2010-09-15 21:48:40 +0000173void WinCOFFStreamer::InitSections() {
Michael J. Spencer192d1362010-10-09 15:44:27 +0000174 SetSectionText();
175 SetSectionData();
176 SetSectionBSS();
177 SetSectionText();
Rafael Espindolad80781b2010-09-15 21:48:40 +0000178}
179
Rafael Espindolaba210242010-11-28 16:22:59 +0000180void WinCOFFStreamer::EmitLabel(MCSymbol *Symbol) {
Rafael Espindolaba210242010-11-28 16:22:59 +0000181 assert(Symbol->isUndefined() && "Cannot define a symbol twice!");
Rafael Espindolaea4afa92010-11-28 17:18:55 +0000182 MCObjectStreamer::EmitLabel(Symbol);
Rafael Espindolaba210242010-11-28 16:22:59 +0000183}
184
Chris Lattnereb72dca2010-07-11 22:05:00 +0000185void WinCOFFStreamer::EmitAssemblerFlag(MCAssemblerFlag Flag) {
Michael J. Spencer8067adc2010-07-19 06:13:10 +0000186 llvm_unreachable("not implemented");
Chris Lattnereb72dca2010-07-11 22:05:00 +0000187}
188
Jim Grosbachce792992010-11-05 22:08:08 +0000189void WinCOFFStreamer::EmitThumbFunc(MCSymbol *Func) {
190 llvm_unreachable("not implemented");
191}
192
Chris Lattnereb72dca2010-07-11 22:05:00 +0000193void WinCOFFStreamer::EmitAssignment(MCSymbol *Symbol, const MCExpr *Value) {
Michael J. Spencerd47f4a92010-10-09 11:00:37 +0000194 assert((Symbol->isInSection()
195 ? Symbol->getSection().getVariant() == MCSection::SV_COFF
196 : true) && "Got non COFF section in the COFF backend!");
Michael J. Spencerb5814a32010-10-07 06:29:33 +0000197 // FIXME: This is all very ugly and depressing. What needs to happen here
198 // depends on quite a few things that are all part of relaxation, which we
199 // don't really even do.
200
201 if (Value->getKind() != MCExpr::SymbolRef) {
NAKAMURA Takumi86c36472010-10-07 07:21:04 +0000202 // TODO: This is exactly the same as MachOStreamer. Consider merging into
203 // MCObjectStreamer.
204 getAssembler().getOrCreateSymbolData(*Symbol);
205 AddValueSymbols(Value);
Michael J. Spencerb5814a32010-10-07 06:29:33 +0000206 Symbol->setVariableValue(Value);
207 } else {
208 // FIXME: This is a horrible way to do this :(. This should really be
209 // handled after we are done with the MC* objects and immediately before
210 // writing out the object file when we know exactly what the symbol should
211 // look like in the coff symbol table. I'm not doing that now because the
212 // COFF object writer doesn't have a clearly defined separation between MC
213 // data structures, the object writers data structures, and the raw, POD,
214 // data structures that get written to disk.
215
216 // Copy over the aliased data.
217 MCSymbolData &SD = getAssembler().getOrCreateSymbolData(*Symbol);
218 const MCSymbolData &RealSD = getAssembler().getOrCreateSymbolData(
219 dyn_cast<const MCSymbolRefExpr>(Value)->getSymbol());
220
221 // FIXME: This is particularly nasty because it breaks as soon as any data
222 // members of MCSymbolData change.
223 SD.CommonAlign = RealSD.CommonAlign;
224 SD.CommonSize = RealSD.CommonSize;
225 SD.Flags = RealSD.Flags;
226 SD.Fragment = RealSD.Fragment;
227 SD.Index = RealSD.Index;
228 SD.IsExternal = RealSD.IsExternal;
229 SD.IsPrivateExtern = RealSD.IsPrivateExtern;
230 SD.Offset = RealSD.Offset;
231 SD.SymbolSize = RealSD.SymbolSize;
232 }
Chris Lattnereb72dca2010-07-11 22:05:00 +0000233}
234
235void WinCOFFStreamer::EmitSymbolAttribute(MCSymbol *Symbol,
236 MCSymbolAttr Attribute) {
Michael J. Spencerd47f4a92010-10-09 11:00:37 +0000237 assert(Symbol && "Symbol must be non-null!");
238 assert((Symbol->isInSection()
239 ? Symbol->getSection().getVariant() == MCSection::SV_COFF
240 : true) && "Got non COFF section in the COFF backend!");
Michael J. Spencer8067adc2010-07-19 06:13:10 +0000241 switch (Attribute) {
242 case MCSA_WeakReference:
Michael J. Spencer4cee2892010-10-16 08:25:57 +0000243 case MCSA_Weak: {
244 MCSymbolData &SD = getAssembler().getOrCreateSymbolData(*Symbol);
245 SD.modifyFlags(COFF::SF_WeakExternal, COFF::SF_WeakExternal);
246 SD.setExternal(true);
247 }
Michael J. Spencer8067adc2010-07-19 06:13:10 +0000248 break;
249
250 case MCSA_Global:
251 getAssembler().getOrCreateSymbolData(*Symbol).setExternal(true);
252 break;
253
254 default:
255 llvm_unreachable("unsupported attribute");
256 break;
257 }
Chris Lattnereb72dca2010-07-11 22:05:00 +0000258}
259
260void WinCOFFStreamer::EmitSymbolDesc(MCSymbol *Symbol, unsigned DescValue) {
Michael J. Spencer8067adc2010-07-19 06:13:10 +0000261 llvm_unreachable("not implemented");
Chris Lattnereb72dca2010-07-11 22:05:00 +0000262}
263
264void WinCOFFStreamer::BeginCOFFSymbolDef(MCSymbol const *Symbol) {
Michael J. Spencerd47f4a92010-10-09 11:00:37 +0000265 assert((Symbol->isInSection()
266 ? Symbol->getSection().getVariant() == MCSection::SV_COFF
267 : true) && "Got non COFF section in the COFF backend!");
Michael J. Spencer8067adc2010-07-19 06:13:10 +0000268 assert(CurSymbol == NULL && "EndCOFFSymbolDef must be called between calls "
269 "to BeginCOFFSymbolDef!");
270 CurSymbol = Symbol;
Chris Lattnereb72dca2010-07-11 22:05:00 +0000271}
272
273void WinCOFFStreamer::EmitCOFFSymbolStorageClass(int StorageClass) {
Michael J. Spencer8067adc2010-07-19 06:13:10 +0000274 assert(CurSymbol != NULL && "BeginCOFFSymbolDef must be called first!");
275 assert((StorageClass & ~0xFF) == 0 && "StorageClass must only have data in "
276 "the first byte!");
277
278 getAssembler().getOrCreateSymbolData(*CurSymbol).modifyFlags(
279 StorageClass << COFF::SF_ClassShift,
280 COFF::SF_ClassMask);
Chris Lattnereb72dca2010-07-11 22:05:00 +0000281}
282
283void WinCOFFStreamer::EmitCOFFSymbolType(int Type) {
Michael J. Spencer8067adc2010-07-19 06:13:10 +0000284 assert(CurSymbol != NULL && "BeginCOFFSymbolDef must be called first!");
285 assert((Type & ~0xFFFF) == 0 && "Type must only have data in the first 2 "
286 "bytes");
287
288 getAssembler().getOrCreateSymbolData(*CurSymbol).modifyFlags(
289 Type << COFF::SF_TypeShift,
290 COFF::SF_TypeMask);
Chris Lattnereb72dca2010-07-11 22:05:00 +0000291}
292
293void WinCOFFStreamer::EndCOFFSymbolDef() {
Michael J. Spencer8067adc2010-07-19 06:13:10 +0000294 assert(CurSymbol != NULL && "BeginCOFFSymbolDef must be called first!");
295 CurSymbol = NULL;
Chris Lattnereb72dca2010-07-11 22:05:00 +0000296}
297
Rafael Espindola8f7d12c2011-12-17 01:14:52 +0000298void WinCOFFStreamer::EmitCOFFSecRel32(MCSymbol const *Symbol)
299{
300 MCDataFragment *DF = getOrCreateDataFragment();
301
302 DF->addFixup(MCFixup::Create(DF->getContents().size(),
303 MCSymbolRefExpr::Create (Symbol, getContext ()),
Rafael Espindolace618af2011-12-24 14:47:52 +0000304 FK_SecRel_4));
Rafael Espindola8f7d12c2011-12-17 01:14:52 +0000305 DF->getContents().resize(DF->getContents().size() + 4, 0);
306}
307
Chris Lattnereb72dca2010-07-11 22:05:00 +0000308void WinCOFFStreamer::EmitELFSize(MCSymbol *Symbol, const MCExpr *Value) {
Michael J. Spencer8067adc2010-07-19 06:13:10 +0000309 llvm_unreachable("not implemented");
Chris Lattnereb72dca2010-07-11 22:05:00 +0000310}
311
312void WinCOFFStreamer::EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
Michael J. Spencer8067adc2010-07-19 06:13:10 +0000313 unsigned ByteAlignment) {
Michael J. Spencerd47f4a92010-10-09 11:00:37 +0000314 assert((Symbol->isInSection()
315 ? Symbol->getSection().getVariant() == MCSection::SV_COFF
316 : true) && "Got non COFF section in the COFF backend!");
Michael J. Spencer8067adc2010-07-19 06:13:10 +0000317 AddCommonSymbol(Symbol, Size, ByteAlignment, true);
Chris Lattnereb72dca2010-07-11 22:05:00 +0000318}
319
Benjamin Kramer36a16012011-09-01 23:04:27 +0000320void WinCOFFStreamer::EmitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size,
321 unsigned ByteAlignment) {
Michael J. Spencerd47f4a92010-10-09 11:00:37 +0000322 assert((Symbol->isInSection()
323 ? Symbol->getSection().getVariant() == MCSection::SV_COFF
324 : true) && "Got non COFF section in the COFF backend!");
Benjamin Kramer36a16012011-09-01 23:04:27 +0000325 AddCommonSymbol(Symbol, Size, ByteAlignment, false);
Chris Lattnereb72dca2010-07-11 22:05:00 +0000326}
327
328void WinCOFFStreamer::EmitZerofill(const MCSection *Section, MCSymbol *Symbol,
Michael J. Spencer8067adc2010-07-19 06:13:10 +0000329 unsigned Size,unsigned ByteAlignment) {
330 llvm_unreachable("not implemented");
Chris Lattnereb72dca2010-07-11 22:05:00 +0000331}
332
333void WinCOFFStreamer::EmitTBSSSymbol(const MCSection *Section, MCSymbol *Symbol,
334 uint64_t Size, unsigned ByteAlignment) {
Michael J. Spencer8067adc2010-07-19 06:13:10 +0000335 llvm_unreachable("not implemented");
Chris Lattnereb72dca2010-07-11 22:05:00 +0000336}
337
338void WinCOFFStreamer::EmitBytes(StringRef Data, unsigned AddrSpace) {
Michael J. Spencer8067adc2010-07-19 06:13:10 +0000339 // TODO: This is copied exactly from the MachOStreamer. Consider merging into
340 // MCObjectStreamer?
341 getOrCreateDataFragment()->getContents().append(Data.begin(), Data.end());
Chris Lattnereb72dca2010-07-11 22:05:00 +0000342}
343
Chris Lattnereb72dca2010-07-11 22:05:00 +0000344void WinCOFFStreamer::EmitValueToAlignment(unsigned ByteAlignment,
Michael J. Spencer8067adc2010-07-19 06:13:10 +0000345 int64_t Value,
346 unsigned ValueSize,
347 unsigned MaxBytesToEmit) {
348 // TODO: This is copied exactly from the MachOStreamer. Consider merging into
349 // MCObjectStreamer?
350 if (MaxBytesToEmit == 0)
351 MaxBytesToEmit = ByteAlignment;
352 new MCAlignFragment(ByteAlignment, Value, ValueSize, MaxBytesToEmit,
353 getCurrentSectionData());
354
355 // Update the maximum alignment on the current section if necessary.
356 if (ByteAlignment > getCurrentSectionData()->getAlignment())
357 getCurrentSectionData()->setAlignment(ByteAlignment);
Chris Lattnereb72dca2010-07-11 22:05:00 +0000358}
359
360void WinCOFFStreamer::EmitCodeAlignment(unsigned ByteAlignment,
Michael J. Spencer8067adc2010-07-19 06:13:10 +0000361 unsigned MaxBytesToEmit) {
362 // TODO: This is copied exactly from the MachOStreamer. Consider merging into
363 // MCObjectStreamer?
364 if (MaxBytesToEmit == 0)
365 MaxBytesToEmit = ByteAlignment;
366 MCAlignFragment *F = new MCAlignFragment(ByteAlignment, 0, 1, MaxBytesToEmit,
367 getCurrentSectionData());
368 F->setEmitNops(true);
369
370 // Update the maximum alignment on the current section if necessary.
371 if (ByteAlignment > getCurrentSectionData()->getAlignment())
372 getCurrentSectionData()->setAlignment(ByteAlignment);
Chris Lattnereb72dca2010-07-11 22:05:00 +0000373}
374
Chris Lattnereb72dca2010-07-11 22:05:00 +0000375void WinCOFFStreamer::EmitFileDirective(StringRef Filename) {
376 // Ignore for now, linkers don't care, and proper debug
377 // info will be a much large effort.
378}
379
Chris Lattnereb72dca2010-07-11 22:05:00 +0000380void WinCOFFStreamer::EmitInstruction(const MCInst &Instruction) {
Michael J. Spencer8067adc2010-07-19 06:13:10 +0000381 for (unsigned i = 0, e = Instruction.getNumOperands(); i != e; ++i)
382 if (Instruction.getOperand(i).isExpr())
383 AddValueSymbols(Instruction.getOperand(i).getExpr());
384
385 getCurrentSectionData()->setHasInstructions(true);
386
387 MCInstFragment *Fragment =
388 new MCInstFragment(Instruction, getCurrentSectionData());
389
390 raw_svector_ostream VecOS(Fragment->getCode());
391
392 getAssembler().getEmitter().EncodeInstruction(Instruction, VecOS,
393 Fragment->getFixups());
Chris Lattnereb72dca2010-07-11 22:05:00 +0000394}
395
Charles Davis3185f5c2011-05-22 03:01:05 +0000396void WinCOFFStreamer::EmitWin64EHHandlerData() {
397 MCStreamer::EmitWin64EHHandlerData();
398
399 // We have to emit the unwind info now, because this directive
400 // actually switches to the .xdata section!
401 MCWin64EHUnwindEmitter::EmitUnwindInfo(*this, getCurrentW64UnwindInfo());
402}
403
Rafael Espindola99b42372012-01-07 03:13:18 +0000404void WinCOFFStreamer::FinishImpl() {
Charles Davis38ea9ee2011-05-22 04:15:07 +0000405 EmitW64Tables();
Rafael Espindola99b42372012-01-07 03:13:18 +0000406 MCObjectStreamer::FinishImpl();
Chris Lattnereb72dca2010-07-11 22:05:00 +0000407}
408
409namespace llvm
410{
411 MCStreamer *createWinCOFFStreamer(MCContext &Context,
Evan Cheng78c10ee2011-07-25 23:24:55 +0000412 MCAsmBackend &MAB,
Chris Lattnereb72dca2010-07-11 22:05:00 +0000413 MCCodeEmitter &CE,
Michael J. Spencere2195d82010-07-31 06:22:29 +0000414 raw_ostream &OS,
415 bool RelaxAll) {
Evan Cheng78c10ee2011-07-25 23:24:55 +0000416 WinCOFFStreamer *S = new WinCOFFStreamer(Context, MAB, CE, OS);
Michael J. Spencere2195d82010-07-31 06:22:29 +0000417 S->getAssembler().setRelaxAll(RelaxAll);
418 return S;
Chris Lattnereb72dca2010-07-11 22:05:00 +0000419 }
420}