blob: 376751be515e5a12b0d21665de0a6f8a5525c307 [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"
Michael J. Spencer8067adc2010-07-19 06:13:10 +000026#include "llvm/Target/TargetRegistry.h"
Chris Lattnereb72dca2010-07-11 22:05:00 +000027#include "llvm/Target/TargetAsmBackend.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"
33#include "llvm/Support/raw_ostream.h"
34using namespace llvm;
35
Chris Lattnereb72dca2010-07-11 22:05:00 +000036namespace {
37class WinCOFFStreamer : public MCObjectStreamer {
38public:
Michael J. Spencer8067adc2010-07-19 06:13:10 +000039 MCSymbol const *CurSymbol;
40
Chris Lattnereb72dca2010-07-11 22:05:00 +000041 WinCOFFStreamer(MCContext &Context,
42 TargetAsmBackend &TAB,
43 MCCodeEmitter &CE,
44 raw_ostream &OS);
45
Michael J. Spencer8067adc2010-07-19 06:13:10 +000046 void AddCommonSymbol(MCSymbol *Symbol, uint64_t Size,
47 unsigned ByteAlignment, bool External);
48
Chris Lattnereb72dca2010-07-11 22:05:00 +000049 // MCStreamer interface
50
Rafael Espindolad80781b2010-09-15 21:48:40 +000051 virtual void InitSections();
Chris Lattnereb72dca2010-07-11 22:05:00 +000052 virtual void EmitLabel(MCSymbol *Symbol);
53 virtual void EmitAssemblerFlag(MCAssemblerFlag Flag);
Jim Grosbachce792992010-11-05 22:08:08 +000054 virtual void EmitThumbFunc(MCSymbol *Func);
Chris Lattnereb72dca2010-07-11 22:05:00 +000055 virtual void EmitAssignment(MCSymbol *Symbol, const MCExpr *Value);
56 virtual void EmitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute);
57 virtual void EmitSymbolDesc(MCSymbol *Symbol, unsigned DescValue);
58 virtual void BeginCOFFSymbolDef(MCSymbol const *Symbol);
59 virtual void EmitCOFFSymbolStorageClass(int StorageClass);
60 virtual void EmitCOFFSymbolType(int Type);
61 virtual void EndCOFFSymbolDef();
62 virtual void EmitELFSize(MCSymbol *Symbol, const MCExpr *Value);
63 virtual void EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
Michael J. Spencer8067adc2010-07-19 06:13:10 +000064 unsigned ByteAlignment);
Chris Lattnereb72dca2010-07-11 22:05:00 +000065 virtual void EmitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size);
66 virtual void EmitZerofill(const MCSection *Section, MCSymbol *Symbol,
Michael J. Spencer8067adc2010-07-19 06:13:10 +000067 unsigned Size,unsigned ByteAlignment);
Chris Lattnereb72dca2010-07-11 22:05:00 +000068 virtual void EmitTBSSSymbol(const MCSection *Section, MCSymbol *Symbol,
Michael J. Spencer8067adc2010-07-19 06:13:10 +000069 uint64_t Size, unsigned ByteAlignment);
Chris Lattnereb72dca2010-07-11 22:05:00 +000070 virtual void EmitBytes(StringRef Data, unsigned AddrSpace);
Michael J. Spencer8067adc2010-07-19 06:13:10 +000071 virtual void EmitValue(const MCExpr *Value, unsigned Size,
Chris Lattnereb72dca2010-07-11 22:05:00 +000072 unsigned AddrSpace);
73 virtual void EmitGPRel32Value(const MCExpr *Value);
74 virtual void EmitValueToAlignment(unsigned ByteAlignment, int64_t Value,
Michael J. Spencer8067adc2010-07-19 06:13:10 +000075 unsigned ValueSize, unsigned MaxBytesToEmit);
Chris Lattnereb72dca2010-07-11 22:05:00 +000076 virtual void EmitCodeAlignment(unsigned ByteAlignment,
77 unsigned MaxBytesToEmit);
78 virtual void EmitValueToOffset(const MCExpr *Offset, unsigned char Value);
79 virtual void EmitFileDirective(StringRef Filename);
Chris Lattnereb72dca2010-07-11 22:05:00 +000080 virtual void EmitInstruction(const MCInst &Instruction);
81 virtual void Finish();
Michael J. Spencer192d1362010-10-09 15:44:27 +000082
83private:
Rafael Espindolaf89671d2010-11-01 16:27:31 +000084 virtual void EmitInstToFragment(const MCInst &Inst) {
85 llvm_unreachable("Not used by WinCOFF.");
86 }
87 virtual void EmitInstToData(const MCInst &Inst) {
88 llvm_unreachable("Not used by WinCOFF.");
89 }
90
Michael J. Spencer192d1362010-10-09 15:44:27 +000091 void SetSection(StringRef Section,
92 unsigned Characteristics,
93 SectionKind Kind) {
94 SwitchSection(getContext().getCOFFSection(Section, Characteristics, Kind));
95 }
96
97 void SetSectionText() {
98 SetSection(".text",
99 COFF::IMAGE_SCN_CNT_CODE
100 | COFF::IMAGE_SCN_MEM_EXECUTE
101 | COFF::IMAGE_SCN_MEM_READ,
102 SectionKind::getText());
103 EmitCodeAlignment(4, 0);
104 }
105
106 void SetSectionData() {
107 SetSection(".data",
108 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA
109 | COFF::IMAGE_SCN_MEM_READ
110 | COFF::IMAGE_SCN_MEM_WRITE,
111 SectionKind::getDataRel());
112 EmitCodeAlignment(4, 0);
113 }
114
115 void SetSectionBSS() {
116 SetSection(".bss",
117 COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA
118 | COFF::IMAGE_SCN_MEM_READ
119 | COFF::IMAGE_SCN_MEM_WRITE,
120 SectionKind::getBSS());
121 EmitCodeAlignment(4, 0);
122 }
123
Chris Lattnereb72dca2010-07-11 22:05:00 +0000124};
125} // end anonymous namespace.
126
127WinCOFFStreamer::WinCOFFStreamer(MCContext &Context,
128 TargetAsmBackend &TAB,
129 MCCodeEmitter &CE,
130 raw_ostream &OS)
Rafael Espindola59ff3c92010-09-22 22:27:05 +0000131 : MCObjectStreamer(Context, TAB, OS, &CE, true)
Michael J. Spencer8067adc2010-07-19 06:13:10 +0000132 , CurSymbol(NULL) {
133}
134
135void WinCOFFStreamer::AddCommonSymbol(MCSymbol *Symbol, uint64_t Size,
136 unsigned ByteAlignment, bool External) {
137 assert(!Symbol->isInSection() && "Symbol must not already have a section!");
138
139 std::string SectionName(".bss$linkonce");
140 SectionName.append(Symbol->getName().begin(), Symbol->getName().end());
141
142 MCSymbolData &SymbolData = getAssembler().getOrCreateSymbolData(*Symbol);
143
144 unsigned Characteristics =
145 COFF::IMAGE_SCN_LNK_COMDAT |
146 COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA |
147 COFF::IMAGE_SCN_MEM_READ |
148 COFF::IMAGE_SCN_MEM_WRITE;
149
150 int Selection = COFF::IMAGE_COMDAT_SELECT_LARGEST;
151
152 const MCSection *Section = MCStreamer::getContext().getCOFFSection(
153 SectionName, Characteristics, Selection, SectionKind::getBSS());
154
155 MCSectionData &SectionData = getAssembler().getOrCreateSectionData(*Section);
156
157 if (SectionData.getAlignment() < ByteAlignment)
158 SectionData.setAlignment(ByteAlignment);
159
160 SymbolData.setExternal(External);
161
162 Symbol->setSection(*Section);
163
164 if (ByteAlignment != 1)
165 new MCAlignFragment(ByteAlignment, 0, 0, ByteAlignment, &SectionData);
166
167 SymbolData.setFragment(new MCFillFragment(0, 0, Size, &SectionData));
Chris Lattnereb72dca2010-07-11 22:05:00 +0000168}
169
170// MCStreamer interface
171
Rafael Espindolad80781b2010-09-15 21:48:40 +0000172void WinCOFFStreamer::InitSections() {
Michael J. Spencer192d1362010-10-09 15:44:27 +0000173 SetSectionText();
174 SetSectionData();
175 SetSectionBSS();
176 SetSectionText();
Rafael Espindolad80781b2010-09-15 21:48:40 +0000177}
178
Chris Lattnereb72dca2010-07-11 22:05:00 +0000179void WinCOFFStreamer::EmitLabel(MCSymbol *Symbol) {
Michael J. Spencer8067adc2010-07-19 06:13:10 +0000180 // TODO: This is copied almost exactly from the MachOStreamer. Consider
181 // merging into MCObjectStreamer?
182 assert(Symbol->isUndefined() && "Cannot define a symbol twice!");
183 assert(!Symbol->isVariable() && "Cannot emit a variable symbol!");
184 assert(CurSection && "Cannot emit before setting section!");
185
186 Symbol->setSection(*CurSection);
187
188 MCSymbolData &SD = getAssembler().getOrCreateSymbolData(*Symbol);
189
190 // FIXME: This is wasteful, we don't necessarily need to create a data
191 // fragment. Instead, we should mark the symbol as pointing into the data
192 // fragment if it exists, otherwise we should just queue the label and set its
193 // fragment pointer when we emit the next fragment.
Michael J. Spencerbf252be2010-08-25 19:27:27 +0000194 MCDataFragment *DF = getOrCreateDataFragment();
195
Michael J. Spencer8067adc2010-07-19 06:13:10 +0000196 assert(!SD.getFragment() && "Unexpected fragment on symbol data!");
Michael J. Spencerbf252be2010-08-25 19:27:27 +0000197 SD.setFragment(DF);
198 SD.setOffset(DF->getContents().size());
Chris Lattnereb72dca2010-07-11 22:05:00 +0000199}
200
201void WinCOFFStreamer::EmitAssemblerFlag(MCAssemblerFlag Flag) {
Michael J. Spencer8067adc2010-07-19 06:13:10 +0000202 llvm_unreachable("not implemented");
Chris Lattnereb72dca2010-07-11 22:05:00 +0000203}
204
Jim Grosbachce792992010-11-05 22:08:08 +0000205void WinCOFFStreamer::EmitThumbFunc(MCSymbol *Func) {
206 llvm_unreachable("not implemented");
207}
208
Chris Lattnereb72dca2010-07-11 22:05:00 +0000209void WinCOFFStreamer::EmitAssignment(MCSymbol *Symbol, const MCExpr *Value) {
Michael J. Spencerd47f4a92010-10-09 11:00:37 +0000210 assert((Symbol->isInSection()
211 ? Symbol->getSection().getVariant() == MCSection::SV_COFF
212 : true) && "Got non COFF section in the COFF backend!");
Michael J. Spencerb5814a32010-10-07 06:29:33 +0000213 // FIXME: This is all very ugly and depressing. What needs to happen here
214 // depends on quite a few things that are all part of relaxation, which we
215 // don't really even do.
216
217 if (Value->getKind() != MCExpr::SymbolRef) {
NAKAMURA Takumi86c36472010-10-07 07:21:04 +0000218 // TODO: This is exactly the same as MachOStreamer. Consider merging into
219 // MCObjectStreamer.
220 getAssembler().getOrCreateSymbolData(*Symbol);
221 AddValueSymbols(Value);
Michael J. Spencerb5814a32010-10-07 06:29:33 +0000222 Symbol->setVariableValue(Value);
223 } else {
224 // FIXME: This is a horrible way to do this :(. This should really be
225 // handled after we are done with the MC* objects and immediately before
226 // writing out the object file when we know exactly what the symbol should
227 // look like in the coff symbol table. I'm not doing that now because the
228 // COFF object writer doesn't have a clearly defined separation between MC
229 // data structures, the object writers data structures, and the raw, POD,
230 // data structures that get written to disk.
231
232 // Copy over the aliased data.
233 MCSymbolData &SD = getAssembler().getOrCreateSymbolData(*Symbol);
234 const MCSymbolData &RealSD = getAssembler().getOrCreateSymbolData(
235 dyn_cast<const MCSymbolRefExpr>(Value)->getSymbol());
236
237 // FIXME: This is particularly nasty because it breaks as soon as any data
238 // members of MCSymbolData change.
239 SD.CommonAlign = RealSD.CommonAlign;
240 SD.CommonSize = RealSD.CommonSize;
241 SD.Flags = RealSD.Flags;
242 SD.Fragment = RealSD.Fragment;
243 SD.Index = RealSD.Index;
244 SD.IsExternal = RealSD.IsExternal;
245 SD.IsPrivateExtern = RealSD.IsPrivateExtern;
246 SD.Offset = RealSD.Offset;
247 SD.SymbolSize = RealSD.SymbolSize;
248 }
Chris Lattnereb72dca2010-07-11 22:05:00 +0000249}
250
251void WinCOFFStreamer::EmitSymbolAttribute(MCSymbol *Symbol,
252 MCSymbolAttr Attribute) {
Michael J. Spencerd47f4a92010-10-09 11:00:37 +0000253 assert(Symbol && "Symbol must be non-null!");
254 assert((Symbol->isInSection()
255 ? Symbol->getSection().getVariant() == MCSection::SV_COFF
256 : true) && "Got non COFF section in the COFF backend!");
Michael J. Spencer8067adc2010-07-19 06:13:10 +0000257 switch (Attribute) {
258 case MCSA_WeakReference:
Michael J. Spencer4cee2892010-10-16 08:25:57 +0000259 case MCSA_Weak: {
260 MCSymbolData &SD = getAssembler().getOrCreateSymbolData(*Symbol);
261 SD.modifyFlags(COFF::SF_WeakExternal, COFF::SF_WeakExternal);
262 SD.setExternal(true);
263 }
Michael J. Spencer8067adc2010-07-19 06:13:10 +0000264 break;
265
266 case MCSA_Global:
267 getAssembler().getOrCreateSymbolData(*Symbol).setExternal(true);
268 break;
269
270 default:
271 llvm_unreachable("unsupported attribute");
272 break;
273 }
Chris Lattnereb72dca2010-07-11 22:05:00 +0000274}
275
276void WinCOFFStreamer::EmitSymbolDesc(MCSymbol *Symbol, unsigned DescValue) {
Michael J. Spencer8067adc2010-07-19 06:13:10 +0000277 llvm_unreachable("not implemented");
Chris Lattnereb72dca2010-07-11 22:05:00 +0000278}
279
280void WinCOFFStreamer::BeginCOFFSymbolDef(MCSymbol const *Symbol) {
Michael J. Spencerd47f4a92010-10-09 11:00:37 +0000281 assert((Symbol->isInSection()
282 ? Symbol->getSection().getVariant() == MCSection::SV_COFF
283 : true) && "Got non COFF section in the COFF backend!");
Michael J. Spencer8067adc2010-07-19 06:13:10 +0000284 assert(CurSymbol == NULL && "EndCOFFSymbolDef must be called between calls "
285 "to BeginCOFFSymbolDef!");
286 CurSymbol = Symbol;
Chris Lattnereb72dca2010-07-11 22:05:00 +0000287}
288
289void WinCOFFStreamer::EmitCOFFSymbolStorageClass(int StorageClass) {
Michael J. Spencer8067adc2010-07-19 06:13:10 +0000290 assert(CurSymbol != NULL && "BeginCOFFSymbolDef must be called first!");
291 assert((StorageClass & ~0xFF) == 0 && "StorageClass must only have data in "
292 "the first byte!");
293
294 getAssembler().getOrCreateSymbolData(*CurSymbol).modifyFlags(
295 StorageClass << COFF::SF_ClassShift,
296 COFF::SF_ClassMask);
Chris Lattnereb72dca2010-07-11 22:05:00 +0000297}
298
299void WinCOFFStreamer::EmitCOFFSymbolType(int Type) {
Michael J. Spencer8067adc2010-07-19 06:13:10 +0000300 assert(CurSymbol != NULL && "BeginCOFFSymbolDef must be called first!");
301 assert((Type & ~0xFFFF) == 0 && "Type must only have data in the first 2 "
302 "bytes");
303
304 getAssembler().getOrCreateSymbolData(*CurSymbol).modifyFlags(
305 Type << COFF::SF_TypeShift,
306 COFF::SF_TypeMask);
Chris Lattnereb72dca2010-07-11 22:05:00 +0000307}
308
309void WinCOFFStreamer::EndCOFFSymbolDef() {
Michael J. Spencer8067adc2010-07-19 06:13:10 +0000310 assert(CurSymbol != NULL && "BeginCOFFSymbolDef must be called first!");
311 CurSymbol = NULL;
Chris Lattnereb72dca2010-07-11 22:05:00 +0000312}
313
314void WinCOFFStreamer::EmitELFSize(MCSymbol *Symbol, const MCExpr *Value) {
Michael J. Spencer8067adc2010-07-19 06:13:10 +0000315 llvm_unreachable("not implemented");
Chris Lattnereb72dca2010-07-11 22:05:00 +0000316}
317
318void WinCOFFStreamer::EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
Michael J. Spencer8067adc2010-07-19 06:13:10 +0000319 unsigned ByteAlignment) {
Michael J. Spencerd47f4a92010-10-09 11:00:37 +0000320 assert((Symbol->isInSection()
321 ? Symbol->getSection().getVariant() == MCSection::SV_COFF
322 : true) && "Got non COFF section in the COFF backend!");
Michael J. Spencer8067adc2010-07-19 06:13:10 +0000323 AddCommonSymbol(Symbol, Size, ByteAlignment, true);
Chris Lattnereb72dca2010-07-11 22:05:00 +0000324}
325
326void WinCOFFStreamer::EmitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size) {
Michael J. Spencerd47f4a92010-10-09 11:00:37 +0000327 assert((Symbol->isInSection()
328 ? Symbol->getSection().getVariant() == MCSection::SV_COFF
329 : true) && "Got non COFF section in the COFF backend!");
Michael J. Spencer8067adc2010-07-19 06:13:10 +0000330 AddCommonSymbol(Symbol, Size, 1, false);
Chris Lattnereb72dca2010-07-11 22:05:00 +0000331}
332
333void WinCOFFStreamer::EmitZerofill(const MCSection *Section, MCSymbol *Symbol,
Michael J. Spencer8067adc2010-07-19 06:13:10 +0000334 unsigned Size,unsigned ByteAlignment) {
335 llvm_unreachable("not implemented");
Chris Lattnereb72dca2010-07-11 22:05:00 +0000336}
337
338void WinCOFFStreamer::EmitTBSSSymbol(const MCSection *Section, MCSymbol *Symbol,
339 uint64_t Size, unsigned ByteAlignment) {
Michael J. Spencer8067adc2010-07-19 06:13:10 +0000340 llvm_unreachable("not implemented");
Chris Lattnereb72dca2010-07-11 22:05:00 +0000341}
342
343void WinCOFFStreamer::EmitBytes(StringRef Data, unsigned AddrSpace) {
Michael J. Spencer8067adc2010-07-19 06:13:10 +0000344 // TODO: This is copied exactly from the MachOStreamer. Consider merging into
345 // MCObjectStreamer?
346 getOrCreateDataFragment()->getContents().append(Data.begin(), Data.end());
Chris Lattnereb72dca2010-07-11 22:05:00 +0000347}
348
349void WinCOFFStreamer::EmitValue(const MCExpr *Value, unsigned Size,
Michael J. Spencer8067adc2010-07-19 06:13:10 +0000350 unsigned AddrSpace) {
351 assert(AddrSpace == 0 && "Address space must be 0!");
352
353 // TODO: This is copied exactly from the MachOStreamer. Consider merging into
354 // MCObjectStreamer?
355 MCDataFragment *DF = getOrCreateDataFragment();
356
357 // Avoid fixups when possible.
358 int64_t AbsValue;
359 if (AddValueSymbols(Value)->EvaluateAsAbsolute(AbsValue)) {
360 // FIXME: Endianness assumption.
361 for (unsigned i = 0; i != Size; ++i)
362 DF->getContents().push_back(uint8_t(AbsValue >> (i * 8)));
363 } else {
364 DF->addFixup(MCFixup::Create(DF->getContents().size(),
365 AddValueSymbols(Value),
366 MCFixup::getKindForSize(Size)));
367 DF->getContents().resize(DF->getContents().size() + Size, 0);
368 }
Chris Lattnereb72dca2010-07-11 22:05:00 +0000369}
370
371void WinCOFFStreamer::EmitGPRel32Value(const MCExpr *Value) {
Michael J. Spencer8067adc2010-07-19 06:13:10 +0000372 llvm_unreachable("not implemented");
Chris Lattnereb72dca2010-07-11 22:05:00 +0000373}
374
375void WinCOFFStreamer::EmitValueToAlignment(unsigned ByteAlignment,
Michael J. Spencer8067adc2010-07-19 06:13:10 +0000376 int64_t Value,
377 unsigned ValueSize,
378 unsigned MaxBytesToEmit) {
379 // TODO: This is copied exactly from the MachOStreamer. Consider merging into
380 // MCObjectStreamer?
381 if (MaxBytesToEmit == 0)
382 MaxBytesToEmit = ByteAlignment;
383 new MCAlignFragment(ByteAlignment, Value, ValueSize, MaxBytesToEmit,
384 getCurrentSectionData());
385
386 // Update the maximum alignment on the current section if necessary.
387 if (ByteAlignment > getCurrentSectionData()->getAlignment())
388 getCurrentSectionData()->setAlignment(ByteAlignment);
Chris Lattnereb72dca2010-07-11 22:05:00 +0000389}
390
391void WinCOFFStreamer::EmitCodeAlignment(unsigned ByteAlignment,
Michael J. Spencer8067adc2010-07-19 06:13:10 +0000392 unsigned MaxBytesToEmit) {
393 // TODO: This is copied exactly from the MachOStreamer. Consider merging into
394 // MCObjectStreamer?
395 if (MaxBytesToEmit == 0)
396 MaxBytesToEmit = ByteAlignment;
397 MCAlignFragment *F = new MCAlignFragment(ByteAlignment, 0, 1, MaxBytesToEmit,
398 getCurrentSectionData());
399 F->setEmitNops(true);
400
401 // Update the maximum alignment on the current section if necessary.
402 if (ByteAlignment > getCurrentSectionData()->getAlignment())
403 getCurrentSectionData()->setAlignment(ByteAlignment);
Chris Lattnereb72dca2010-07-11 22:05:00 +0000404}
405
406void WinCOFFStreamer::EmitValueToOffset(const MCExpr *Offset,
Michael J. Spencer8067adc2010-07-19 06:13:10 +0000407 unsigned char Value) {
408 llvm_unreachable("not implemented");
Chris Lattnereb72dca2010-07-11 22:05:00 +0000409}
410
411void WinCOFFStreamer::EmitFileDirective(StringRef Filename) {
412 // Ignore for now, linkers don't care, and proper debug
413 // info will be a much large effort.
414}
415
Chris Lattnereb72dca2010-07-11 22:05:00 +0000416void WinCOFFStreamer::EmitInstruction(const MCInst &Instruction) {
Michael J. Spencer8067adc2010-07-19 06:13:10 +0000417 for (unsigned i = 0, e = Instruction.getNumOperands(); i != e; ++i)
418 if (Instruction.getOperand(i).isExpr())
419 AddValueSymbols(Instruction.getOperand(i).getExpr());
420
421 getCurrentSectionData()->setHasInstructions(true);
422
423 MCInstFragment *Fragment =
424 new MCInstFragment(Instruction, getCurrentSectionData());
425
426 raw_svector_ostream VecOS(Fragment->getCode());
427
428 getAssembler().getEmitter().EncodeInstruction(Instruction, VecOS,
429 Fragment->getFixups());
Chris Lattnereb72dca2010-07-11 22:05:00 +0000430}
431
432void WinCOFFStreamer::Finish() {
433 MCObjectStreamer::Finish();
434}
435
436namespace llvm
437{
438 MCStreamer *createWinCOFFStreamer(MCContext &Context,
439 TargetAsmBackend &TAB,
440 MCCodeEmitter &CE,
Michael J. Spencere2195d82010-07-31 06:22:29 +0000441 raw_ostream &OS,
442 bool RelaxAll) {
443 WinCOFFStreamer *S = new WinCOFFStreamer(Context, TAB, CE, OS);
444 S->getAssembler().setRelaxAll(RelaxAll);
445 return S;
Chris Lattnereb72dca2010-07-11 22:05:00 +0000446 }
447}