blob: 3678a589f4ee3bf72c005cd31ade39d22f52b250 [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
36#include "../Target/X86/MCTargetDesc/X86FixupKinds.h"
37
Chris Lattnereb72dca2010-07-11 22:05:00 +000038using namespace llvm;
39
Chris Lattnereb72dca2010-07-11 22:05:00 +000040namespace {
41class WinCOFFStreamer : public MCObjectStreamer {
42public:
Michael J. Spencer8067adc2010-07-19 06:13:10 +000043 MCSymbol const *CurSymbol;
44
Chris Lattnereb72dca2010-07-11 22:05:00 +000045 WinCOFFStreamer(MCContext &Context,
Evan Cheng78c10ee2011-07-25 23:24:55 +000046 MCAsmBackend &MAB,
Chris Lattnereb72dca2010-07-11 22:05:00 +000047 MCCodeEmitter &CE,
48 raw_ostream &OS);
49
Michael J. Spencer8067adc2010-07-19 06:13:10 +000050 void AddCommonSymbol(MCSymbol *Symbol, uint64_t Size,
51 unsigned ByteAlignment, bool External);
52
Chris Lattnereb72dca2010-07-11 22:05:00 +000053 // MCStreamer interface
54
Rafael Espindolad80781b2010-09-15 21:48:40 +000055 virtual void InitSections();
Rafael Espindolaba210242010-11-28 16:22:59 +000056 virtual void EmitLabel(MCSymbol *Symbol);
Chris Lattnereb72dca2010-07-11 22:05:00 +000057 virtual void EmitAssemblerFlag(MCAssemblerFlag Flag);
Jim Grosbachce792992010-11-05 22:08:08 +000058 virtual void EmitThumbFunc(MCSymbol *Func);
Chris Lattnereb72dca2010-07-11 22:05:00 +000059 virtual void EmitAssignment(MCSymbol *Symbol, const MCExpr *Value);
60 virtual void EmitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute);
61 virtual void EmitSymbolDesc(MCSymbol *Symbol, unsigned DescValue);
62 virtual void BeginCOFFSymbolDef(MCSymbol const *Symbol);
63 virtual void EmitCOFFSymbolStorageClass(int StorageClass);
64 virtual void EmitCOFFSymbolType(int Type);
65 virtual void EndCOFFSymbolDef();
Rafael Espindola8f7d12c2011-12-17 01:14:52 +000066 virtual void EmitCOFFSecRel32(MCSymbol const *Symbol);
Chris Lattnereb72dca2010-07-11 22:05:00 +000067 virtual void EmitELFSize(MCSymbol *Symbol, const MCExpr *Value);
68 virtual void EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
Michael J. Spencer8067adc2010-07-19 06:13:10 +000069 unsigned ByteAlignment);
Benjamin Kramer36a16012011-09-01 23:04:27 +000070 virtual void EmitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size,
71 unsigned ByteAlignment);
Chris Lattnereb72dca2010-07-11 22:05:00 +000072 virtual void EmitZerofill(const MCSection *Section, MCSymbol *Symbol,
Michael J. Spencer8067adc2010-07-19 06:13:10 +000073 unsigned Size,unsigned ByteAlignment);
Chris Lattnereb72dca2010-07-11 22:05:00 +000074 virtual void EmitTBSSSymbol(const MCSection *Section, MCSymbol *Symbol,
Michael J. Spencer8067adc2010-07-19 06:13:10 +000075 uint64_t Size, unsigned ByteAlignment);
Chris Lattnereb72dca2010-07-11 22:05:00 +000076 virtual void EmitBytes(StringRef Data, unsigned AddrSpace);
Chris Lattnereb72dca2010-07-11 22:05:00 +000077 virtual void EmitValueToAlignment(unsigned ByteAlignment, int64_t Value,
Michael J. Spencer8067adc2010-07-19 06:13:10 +000078 unsigned ValueSize, unsigned MaxBytesToEmit);
Chris Lattnereb72dca2010-07-11 22:05:00 +000079 virtual void EmitCodeAlignment(unsigned ByteAlignment,
80 unsigned MaxBytesToEmit);
Chris Lattnereb72dca2010-07-11 22:05:00 +000081 virtual void EmitFileDirective(StringRef Filename);
Chris Lattnereb72dca2010-07-11 22:05:00 +000082 virtual void EmitInstruction(const MCInst &Instruction);
Charles Davis3185f5c2011-05-22 03:01:05 +000083 virtual void EmitWin64EHHandlerData();
Chris Lattnereb72dca2010-07-11 22:05:00 +000084 virtual void Finish();
Michael J. Spencer192d1362010-10-09 15:44:27 +000085
86private:
Rafael Espindolaf89671d2010-11-01 16:27:31 +000087 virtual void EmitInstToFragment(const MCInst &Inst) {
88 llvm_unreachable("Not used by WinCOFF.");
89 }
90 virtual void EmitInstToData(const MCInst &Inst) {
91 llvm_unreachable("Not used by WinCOFF.");
92 }
93
Michael J. Spencer192d1362010-10-09 15:44:27 +000094 void SetSection(StringRef Section,
95 unsigned Characteristics,
96 SectionKind Kind) {
97 SwitchSection(getContext().getCOFFSection(Section, Characteristics, Kind));
98 }
99
100 void SetSectionText() {
101 SetSection(".text",
102 COFF::IMAGE_SCN_CNT_CODE
103 | COFF::IMAGE_SCN_MEM_EXECUTE
104 | COFF::IMAGE_SCN_MEM_READ,
105 SectionKind::getText());
106 EmitCodeAlignment(4, 0);
107 }
108
109 void SetSectionData() {
110 SetSection(".data",
111 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA
112 | COFF::IMAGE_SCN_MEM_READ
113 | COFF::IMAGE_SCN_MEM_WRITE,
114 SectionKind::getDataRel());
115 EmitCodeAlignment(4, 0);
116 }
117
118 void SetSectionBSS() {
119 SetSection(".bss",
120 COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA
121 | COFF::IMAGE_SCN_MEM_READ
122 | COFF::IMAGE_SCN_MEM_WRITE,
123 SectionKind::getBSS());
124 EmitCodeAlignment(4, 0);
125 }
126
Chris Lattnereb72dca2010-07-11 22:05:00 +0000127};
128} // end anonymous namespace.
129
130WinCOFFStreamer::WinCOFFStreamer(MCContext &Context,
Evan Cheng78c10ee2011-07-25 23:24:55 +0000131 MCAsmBackend &MAB,
Chris Lattnereb72dca2010-07-11 22:05:00 +0000132 MCCodeEmitter &CE,
133 raw_ostream &OS)
Evan Cheng78c10ee2011-07-25 23:24:55 +0000134 : MCObjectStreamer(Context, MAB, OS, &CE)
Michael J. Spencer8067adc2010-07-19 06:13:10 +0000135 , CurSymbol(NULL) {
136}
137
138void WinCOFFStreamer::AddCommonSymbol(MCSymbol *Symbol, uint64_t Size,
139 unsigned ByteAlignment, bool External) {
140 assert(!Symbol->isInSection() && "Symbol must not already have a section!");
141
142 std::string SectionName(".bss$linkonce");
143 SectionName.append(Symbol->getName().begin(), Symbol->getName().end());
144
145 MCSymbolData &SymbolData = getAssembler().getOrCreateSymbolData(*Symbol);
146
147 unsigned Characteristics =
148 COFF::IMAGE_SCN_LNK_COMDAT |
149 COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA |
150 COFF::IMAGE_SCN_MEM_READ |
151 COFF::IMAGE_SCN_MEM_WRITE;
152
153 int Selection = COFF::IMAGE_COMDAT_SELECT_LARGEST;
154
155 const MCSection *Section = MCStreamer::getContext().getCOFFSection(
156 SectionName, Characteristics, Selection, SectionKind::getBSS());
157
158 MCSectionData &SectionData = getAssembler().getOrCreateSectionData(*Section);
159
160 if (SectionData.getAlignment() < ByteAlignment)
161 SectionData.setAlignment(ByteAlignment);
162
163 SymbolData.setExternal(External);
164
165 Symbol->setSection(*Section);
166
167 if (ByteAlignment != 1)
168 new MCAlignFragment(ByteAlignment, 0, 0, ByteAlignment, &SectionData);
169
170 SymbolData.setFragment(new MCFillFragment(0, 0, Size, &SectionData));
Chris Lattnereb72dca2010-07-11 22:05:00 +0000171}
172
173// MCStreamer interface
174
Rafael Espindolad80781b2010-09-15 21:48:40 +0000175void WinCOFFStreamer::InitSections() {
Michael J. Spencer192d1362010-10-09 15:44:27 +0000176 SetSectionText();
177 SetSectionData();
178 SetSectionBSS();
179 SetSectionText();
Rafael Espindolad80781b2010-09-15 21:48:40 +0000180}
181
Rafael Espindolaba210242010-11-28 16:22:59 +0000182void WinCOFFStreamer::EmitLabel(MCSymbol *Symbol) {
Rafael Espindolaba210242010-11-28 16:22:59 +0000183 assert(Symbol->isUndefined() && "Cannot define a symbol twice!");
Rafael Espindolaea4afa92010-11-28 17:18:55 +0000184 MCObjectStreamer::EmitLabel(Symbol);
Rafael Espindolaba210242010-11-28 16:22:59 +0000185}
186
Chris Lattnereb72dca2010-07-11 22:05:00 +0000187void WinCOFFStreamer::EmitAssemblerFlag(MCAssemblerFlag Flag) {
Michael J. Spencer8067adc2010-07-19 06:13:10 +0000188 llvm_unreachable("not implemented");
Chris Lattnereb72dca2010-07-11 22:05:00 +0000189}
190
Jim Grosbachce792992010-11-05 22:08:08 +0000191void WinCOFFStreamer::EmitThumbFunc(MCSymbol *Func) {
192 llvm_unreachable("not implemented");
193}
194
Chris Lattnereb72dca2010-07-11 22:05:00 +0000195void WinCOFFStreamer::EmitAssignment(MCSymbol *Symbol, const MCExpr *Value) {
Michael J. Spencerd47f4a92010-10-09 11:00:37 +0000196 assert((Symbol->isInSection()
197 ? Symbol->getSection().getVariant() == MCSection::SV_COFF
198 : true) && "Got non COFF section in the COFF backend!");
Michael J. Spencerb5814a32010-10-07 06:29:33 +0000199 // FIXME: This is all very ugly and depressing. What needs to happen here
200 // depends on quite a few things that are all part of relaxation, which we
201 // don't really even do.
202
203 if (Value->getKind() != MCExpr::SymbolRef) {
NAKAMURA Takumi86c36472010-10-07 07:21:04 +0000204 // TODO: This is exactly the same as MachOStreamer. Consider merging into
205 // MCObjectStreamer.
206 getAssembler().getOrCreateSymbolData(*Symbol);
207 AddValueSymbols(Value);
Michael J. Spencerb5814a32010-10-07 06:29:33 +0000208 Symbol->setVariableValue(Value);
209 } else {
210 // FIXME: This is a horrible way to do this :(. This should really be
211 // handled after we are done with the MC* objects and immediately before
212 // writing out the object file when we know exactly what the symbol should
213 // look like in the coff symbol table. I'm not doing that now because the
214 // COFF object writer doesn't have a clearly defined separation between MC
215 // data structures, the object writers data structures, and the raw, POD,
216 // data structures that get written to disk.
217
218 // Copy over the aliased data.
219 MCSymbolData &SD = getAssembler().getOrCreateSymbolData(*Symbol);
220 const MCSymbolData &RealSD = getAssembler().getOrCreateSymbolData(
221 dyn_cast<const MCSymbolRefExpr>(Value)->getSymbol());
222
223 // FIXME: This is particularly nasty because it breaks as soon as any data
224 // members of MCSymbolData change.
225 SD.CommonAlign = RealSD.CommonAlign;
226 SD.CommonSize = RealSD.CommonSize;
227 SD.Flags = RealSD.Flags;
228 SD.Fragment = RealSD.Fragment;
229 SD.Index = RealSD.Index;
230 SD.IsExternal = RealSD.IsExternal;
231 SD.IsPrivateExtern = RealSD.IsPrivateExtern;
232 SD.Offset = RealSD.Offset;
233 SD.SymbolSize = RealSD.SymbolSize;
234 }
Chris Lattnereb72dca2010-07-11 22:05:00 +0000235}
236
237void WinCOFFStreamer::EmitSymbolAttribute(MCSymbol *Symbol,
238 MCSymbolAttr Attribute) {
Michael J. Spencerd47f4a92010-10-09 11:00:37 +0000239 assert(Symbol && "Symbol must be non-null!");
240 assert((Symbol->isInSection()
241 ? Symbol->getSection().getVariant() == MCSection::SV_COFF
242 : true) && "Got non COFF section in the COFF backend!");
Michael J. Spencer8067adc2010-07-19 06:13:10 +0000243 switch (Attribute) {
244 case MCSA_WeakReference:
Michael J. Spencer4cee2892010-10-16 08:25:57 +0000245 case MCSA_Weak: {
246 MCSymbolData &SD = getAssembler().getOrCreateSymbolData(*Symbol);
247 SD.modifyFlags(COFF::SF_WeakExternal, COFF::SF_WeakExternal);
248 SD.setExternal(true);
249 }
Michael J. Spencer8067adc2010-07-19 06:13:10 +0000250 break;
251
252 case MCSA_Global:
253 getAssembler().getOrCreateSymbolData(*Symbol).setExternal(true);
254 break;
255
256 default:
257 llvm_unreachable("unsupported attribute");
258 break;
259 }
Chris Lattnereb72dca2010-07-11 22:05:00 +0000260}
261
262void WinCOFFStreamer::EmitSymbolDesc(MCSymbol *Symbol, unsigned DescValue) {
Michael J. Spencer8067adc2010-07-19 06:13:10 +0000263 llvm_unreachable("not implemented");
Chris Lattnereb72dca2010-07-11 22:05:00 +0000264}
265
266void WinCOFFStreamer::BeginCOFFSymbolDef(MCSymbol const *Symbol) {
Michael J. Spencerd47f4a92010-10-09 11:00:37 +0000267 assert((Symbol->isInSection()
268 ? Symbol->getSection().getVariant() == MCSection::SV_COFF
269 : true) && "Got non COFF section in the COFF backend!");
Michael J. Spencer8067adc2010-07-19 06:13:10 +0000270 assert(CurSymbol == NULL && "EndCOFFSymbolDef must be called between calls "
271 "to BeginCOFFSymbolDef!");
272 CurSymbol = Symbol;
Chris Lattnereb72dca2010-07-11 22:05:00 +0000273}
274
275void WinCOFFStreamer::EmitCOFFSymbolStorageClass(int StorageClass) {
Michael J. Spencer8067adc2010-07-19 06:13:10 +0000276 assert(CurSymbol != NULL && "BeginCOFFSymbolDef must be called first!");
277 assert((StorageClass & ~0xFF) == 0 && "StorageClass must only have data in "
278 "the first byte!");
279
280 getAssembler().getOrCreateSymbolData(*CurSymbol).modifyFlags(
281 StorageClass << COFF::SF_ClassShift,
282 COFF::SF_ClassMask);
Chris Lattnereb72dca2010-07-11 22:05:00 +0000283}
284
285void WinCOFFStreamer::EmitCOFFSymbolType(int Type) {
Michael J. Spencer8067adc2010-07-19 06:13:10 +0000286 assert(CurSymbol != NULL && "BeginCOFFSymbolDef must be called first!");
287 assert((Type & ~0xFFFF) == 0 && "Type must only have data in the first 2 "
288 "bytes");
289
290 getAssembler().getOrCreateSymbolData(*CurSymbol).modifyFlags(
291 Type << COFF::SF_TypeShift,
292 COFF::SF_TypeMask);
Chris Lattnereb72dca2010-07-11 22:05:00 +0000293}
294
295void WinCOFFStreamer::EndCOFFSymbolDef() {
Michael J. Spencer8067adc2010-07-19 06:13:10 +0000296 assert(CurSymbol != NULL && "BeginCOFFSymbolDef must be called first!");
297 CurSymbol = NULL;
Chris Lattnereb72dca2010-07-11 22:05:00 +0000298}
299
Rafael Espindola8f7d12c2011-12-17 01:14:52 +0000300void WinCOFFStreamer::EmitCOFFSecRel32(MCSymbol const *Symbol)
301{
302 MCDataFragment *DF = getOrCreateDataFragment();
303
304 DF->addFixup(MCFixup::Create(DF->getContents().size(),
305 MCSymbolRefExpr::Create (Symbol, getContext ()),
306 (MCFixupKind)X86::reloc_coff_secrel32));
307 DF->getContents().resize(DF->getContents().size() + 4, 0);
308}
309
Chris Lattnereb72dca2010-07-11 22:05:00 +0000310void WinCOFFStreamer::EmitELFSize(MCSymbol *Symbol, const MCExpr *Value) {
Michael J. Spencer8067adc2010-07-19 06:13:10 +0000311 llvm_unreachable("not implemented");
Chris Lattnereb72dca2010-07-11 22:05:00 +0000312}
313
314void WinCOFFStreamer::EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
Michael J. Spencer8067adc2010-07-19 06:13:10 +0000315 unsigned ByteAlignment) {
Michael J. Spencerd47f4a92010-10-09 11:00:37 +0000316 assert((Symbol->isInSection()
317 ? Symbol->getSection().getVariant() == MCSection::SV_COFF
318 : true) && "Got non COFF section in the COFF backend!");
Michael J. Spencer8067adc2010-07-19 06:13:10 +0000319 AddCommonSymbol(Symbol, Size, ByteAlignment, true);
Chris Lattnereb72dca2010-07-11 22:05:00 +0000320}
321
Benjamin Kramer36a16012011-09-01 23:04:27 +0000322void WinCOFFStreamer::EmitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size,
323 unsigned ByteAlignment) {
Michael J. Spencerd47f4a92010-10-09 11:00:37 +0000324 assert((Symbol->isInSection()
325 ? Symbol->getSection().getVariant() == MCSection::SV_COFF
326 : true) && "Got non COFF section in the COFF backend!");
Benjamin Kramer36a16012011-09-01 23:04:27 +0000327 AddCommonSymbol(Symbol, Size, ByteAlignment, false);
Chris Lattnereb72dca2010-07-11 22:05:00 +0000328}
329
330void WinCOFFStreamer::EmitZerofill(const MCSection *Section, MCSymbol *Symbol,
Michael J. Spencer8067adc2010-07-19 06:13:10 +0000331 unsigned Size,unsigned ByteAlignment) {
332 llvm_unreachable("not implemented");
Chris Lattnereb72dca2010-07-11 22:05:00 +0000333}
334
335void WinCOFFStreamer::EmitTBSSSymbol(const MCSection *Section, MCSymbol *Symbol,
336 uint64_t Size, unsigned ByteAlignment) {
Michael J. Spencer8067adc2010-07-19 06:13:10 +0000337 llvm_unreachable("not implemented");
Chris Lattnereb72dca2010-07-11 22:05:00 +0000338}
339
340void WinCOFFStreamer::EmitBytes(StringRef Data, unsigned AddrSpace) {
Michael J. Spencer8067adc2010-07-19 06:13:10 +0000341 // TODO: This is copied exactly from the MachOStreamer. Consider merging into
342 // MCObjectStreamer?
343 getOrCreateDataFragment()->getContents().append(Data.begin(), Data.end());
Chris Lattnereb72dca2010-07-11 22:05:00 +0000344}
345
Chris Lattnereb72dca2010-07-11 22:05:00 +0000346void WinCOFFStreamer::EmitValueToAlignment(unsigned ByteAlignment,
Michael J. Spencer8067adc2010-07-19 06:13:10 +0000347 int64_t Value,
348 unsigned ValueSize,
349 unsigned MaxBytesToEmit) {
350 // TODO: This is copied exactly from the MachOStreamer. Consider merging into
351 // MCObjectStreamer?
352 if (MaxBytesToEmit == 0)
353 MaxBytesToEmit = ByteAlignment;
354 new MCAlignFragment(ByteAlignment, Value, ValueSize, MaxBytesToEmit,
355 getCurrentSectionData());
356
357 // Update the maximum alignment on the current section if necessary.
358 if (ByteAlignment > getCurrentSectionData()->getAlignment())
359 getCurrentSectionData()->setAlignment(ByteAlignment);
Chris Lattnereb72dca2010-07-11 22:05:00 +0000360}
361
362void WinCOFFStreamer::EmitCodeAlignment(unsigned ByteAlignment,
Michael J. Spencer8067adc2010-07-19 06:13:10 +0000363 unsigned MaxBytesToEmit) {
364 // TODO: This is copied exactly from the MachOStreamer. Consider merging into
365 // MCObjectStreamer?
366 if (MaxBytesToEmit == 0)
367 MaxBytesToEmit = ByteAlignment;
368 MCAlignFragment *F = new MCAlignFragment(ByteAlignment, 0, 1, MaxBytesToEmit,
369 getCurrentSectionData());
370 F->setEmitNops(true);
371
372 // Update the maximum alignment on the current section if necessary.
373 if (ByteAlignment > getCurrentSectionData()->getAlignment())
374 getCurrentSectionData()->setAlignment(ByteAlignment);
Chris Lattnereb72dca2010-07-11 22:05:00 +0000375}
376
Chris Lattnereb72dca2010-07-11 22:05:00 +0000377void WinCOFFStreamer::EmitFileDirective(StringRef Filename) {
378 // Ignore for now, linkers don't care, and proper debug
379 // info will be a much large effort.
380}
381
Chris Lattnereb72dca2010-07-11 22:05:00 +0000382void WinCOFFStreamer::EmitInstruction(const MCInst &Instruction) {
Michael J. Spencer8067adc2010-07-19 06:13:10 +0000383 for (unsigned i = 0, e = Instruction.getNumOperands(); i != e; ++i)
384 if (Instruction.getOperand(i).isExpr())
385 AddValueSymbols(Instruction.getOperand(i).getExpr());
386
387 getCurrentSectionData()->setHasInstructions(true);
388
389 MCInstFragment *Fragment =
390 new MCInstFragment(Instruction, getCurrentSectionData());
391
392 raw_svector_ostream VecOS(Fragment->getCode());
393
394 getAssembler().getEmitter().EncodeInstruction(Instruction, VecOS,
395 Fragment->getFixups());
Chris Lattnereb72dca2010-07-11 22:05:00 +0000396}
397
Charles Davis3185f5c2011-05-22 03:01:05 +0000398void WinCOFFStreamer::EmitWin64EHHandlerData() {
399 MCStreamer::EmitWin64EHHandlerData();
400
401 // We have to emit the unwind info now, because this directive
402 // actually switches to the .xdata section!
403 MCWin64EHUnwindEmitter::EmitUnwindInfo(*this, getCurrentW64UnwindInfo());
404}
405
Chris Lattnereb72dca2010-07-11 22:05:00 +0000406void WinCOFFStreamer::Finish() {
Charles Davis38ea9ee2011-05-22 04:15:07 +0000407 EmitW64Tables();
Chris Lattnereb72dca2010-07-11 22:05:00 +0000408 MCObjectStreamer::Finish();
409}
410
411namespace llvm
412{
413 MCStreamer *createWinCOFFStreamer(MCContext &Context,
Evan Cheng78c10ee2011-07-25 23:24:55 +0000414 MCAsmBackend &MAB,
Chris Lattnereb72dca2010-07-11 22:05:00 +0000415 MCCodeEmitter &CE,
Michael J. Spencere2195d82010-07-31 06:22:29 +0000416 raw_ostream &OS,
417 bool RelaxAll) {
Evan Cheng78c10ee2011-07-25 23:24:55 +0000418 WinCOFFStreamer *S = new WinCOFFStreamer(Context, MAB, CE, OS);
Michael J. Spencere2195d82010-07-31 06:22:29 +0000419 S->getAssembler().setRelaxAll(RelaxAll);
420 return S;
Chris Lattnereb72dca2010-07-11 22:05:00 +0000421 }
422}