blob: 40a21ad5dd23575f000b056c465f7de2d0140b87 [file] [log] [blame]
Daniel Dunbarfb4a6b32009-08-21 09:11:24 +00001//===- lib/MC/MCMachOStreamer.cpp - Mach-O Object Output ------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#include "llvm/MC/MCStreamer.h"
11
Daniel Dunbarfb4a6b32009-08-21 09:11:24 +000012#include "llvm/MC/MCAssembler.h"
13#include "llvm/MC/MCContext.h"
Daniel Dunbar4fac7492009-08-27 08:17:51 +000014#include "llvm/MC/MCCodeEmitter.h"
Daniel Dunbar8c2eebe2009-08-31 08:08:38 +000015#include "llvm/MC/MCExpr.h"
Daniel Dunbar4fac7492009-08-27 08:17:51 +000016#include "llvm/MC/MCInst.h"
Daniel Dunbarfb4a6b32009-08-21 09:11:24 +000017#include "llvm/MC/MCSection.h"
18#include "llvm/MC/MCSymbol.h"
Daniel Dunbar821e3332009-08-31 08:09:28 +000019#include "llvm/MC/MCValue.h"
Daniel Dunbarfb4a6b32009-08-21 09:11:24 +000020#include "llvm/Support/ErrorHandling.h"
Daniel Dunbar4fac7492009-08-27 08:17:51 +000021#include "llvm/Support/raw_ostream.h"
Daniel Dunbarfb4a6b32009-08-21 09:11:24 +000022using namespace llvm;
23
24namespace {
25
26class MCMachOStreamer : public MCStreamer {
Daniel Dunbar6aff2fb2009-08-24 08:40:12 +000027 /// SymbolFlags - We store the value for the 'desc' symbol field in the lowest
28 /// 16 bits of the implementation defined flags.
29 enum SymbolFlags { // See <mach-o/nlist.h>.
30 SF_DescFlagsMask = 0xFFFF,
31
32 // Reference type flags.
33 SF_ReferenceTypeMask = 0x0007,
34 SF_ReferenceTypeUndefinedNonLazy = 0x0000,
35 SF_ReferenceTypeUndefinedLazy = 0x0001,
36 SF_ReferenceTypeDefined = 0x0002,
37 SF_ReferenceTypePrivateDefined = 0x0003,
38 SF_ReferenceTypePrivateUndefinedNonLazy = 0x0004,
39 SF_ReferenceTypePrivateUndefinedLazy = 0x0005,
40
41 // Other 'desc' flags.
42 SF_NoDeadStrip = 0x0020,
43 SF_WeakReference = 0x0040,
44 SF_WeakDefinition = 0x0080
45 };
46
47private:
Daniel Dunbarfb4a6b32009-08-21 09:11:24 +000048 MCAssembler Assembler;
Daniel Dunbar4fac7492009-08-27 08:17:51 +000049 MCCodeEmitter *Emitter;
Daniel Dunbarfb4a6b32009-08-21 09:11:24 +000050 MCSectionData *CurSectionData;
Daniel Dunbarfb4a6b32009-08-21 09:11:24 +000051 DenseMap<const MCSection*, MCSectionData*> SectionMap;
Daniel Dunbarf3d2ef02009-08-22 10:13:24 +000052 DenseMap<const MCSymbol*, MCSymbolData*> SymbolMap;
53
54private:
55 MCFragment *getCurrentFragment() const {
56 assert(CurSectionData && "No current section!");
57
58 if (!CurSectionData->empty())
59 return &CurSectionData->getFragmentList().back();
60
61 return 0;
62 }
63
Daniel Dunbar0f5fa692009-08-28 05:48:54 +000064 MCSectionData &getSectionData(const MCSection &Section) {
65 MCSectionData *&Entry = SectionMap[&Section];
66
67 if (!Entry)
68 Entry = new MCSectionData(Section, &Assembler);
69
70 return *Entry;
71 }
72
Daniel Dunbarcb579b32009-08-31 08:08:06 +000073 MCSymbolData &getSymbolData(const MCSymbol &Symbol) {
Daniel Dunbarf3d2ef02009-08-22 10:13:24 +000074 MCSymbolData *&Entry = SymbolMap[&Symbol];
75
76 if (!Entry)
77 Entry = new MCSymbolData(Symbol, 0, 0, &Assembler);
78
79 return *Entry;
80 }
Daniel Dunbarfb4a6b32009-08-21 09:11:24 +000081
82public:
Daniel Dunbar4fac7492009-08-27 08:17:51 +000083 MCMachOStreamer(MCContext &Context, raw_ostream &_OS, MCCodeEmitter *_Emitter)
Daniel Dunbara03a3682009-08-31 08:07:55 +000084 : MCStreamer(Context), Assembler(Context, _OS), Emitter(_Emitter),
Daniel Dunbar4fac7492009-08-27 08:17:51 +000085 CurSectionData(0) {}
Daniel Dunbarfb4a6b32009-08-21 09:11:24 +000086 ~MCMachOStreamer() {}
87
Daniel Dunbar8c2eebe2009-08-31 08:08:38 +000088 const MCExpr *AddValueSymbols(const MCExpr *Value) {
89 switch (Value->getKind()) {
Chris Lattner5d917a82010-02-08 19:41:07 +000090 case MCExpr::Target: assert(0 && "Can't handle target exprs yet!");
Daniel Dunbar8c2eebe2009-08-31 08:08:38 +000091 case MCExpr::Constant:
92 break;
93
94 case MCExpr::Binary: {
95 const MCBinaryExpr *BE = cast<MCBinaryExpr>(Value);
96 AddValueSymbols(BE->getLHS());
97 AddValueSymbols(BE->getRHS());
98 break;
99 }
100
101 case MCExpr::SymbolRef:
102 getSymbolData(cast<MCSymbolRefExpr>(Value)->getSymbol());
103 break;
104
105 case MCExpr::Unary:
106 AddValueSymbols(cast<MCUnaryExpr>(Value)->getSubExpr());
107 break;
108 }
109
110 return Value;
111 }
112
Daniel Dunbarfb4a6b32009-08-21 09:11:24 +0000113 /// @name MCStreamer Interface
114 /// @{
115
116 virtual void SwitchSection(const MCSection *Section);
Daniel Dunbarfb4a6b32009-08-21 09:11:24 +0000117 virtual void EmitLabel(MCSymbol *Symbol);
Chris Lattnera5ad93a2010-01-23 06:39:22 +0000118 virtual void EmitAssemblerFlag(MCAssemblerFlag Flag);
Daniel Dunbar821e3332009-08-31 08:09:28 +0000119 virtual void EmitAssignment(MCSymbol *Symbol, const MCExpr *Value);
Chris Lattnera5ad93a2010-01-23 06:39:22 +0000120 virtual void EmitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute);
Daniel Dunbarfb4a6b32009-08-21 09:11:24 +0000121 virtual void EmitSymbolDesc(MCSymbol *Symbol, unsigned DescValue);
Chris Lattner9eb158d2010-01-23 07:47:02 +0000122 virtual void EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
Daniel Dunbar7092c7e2009-08-30 06:17:16 +0000123 unsigned ByteAlignment);
Chris Lattner99328ad2010-01-25 07:52:13 +0000124 virtual void EmitELFSize(MCSymbol *Symbol, const MCExpr *Value) {
125 assert(0 && "macho doesn't support this directive");
126 }
Chris Lattner9eb158d2010-01-23 07:47:02 +0000127 virtual void EmitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size) {
128 assert(0 && "macho doesn't support this directive");
129 }
Daniel Dunbar8751b942009-08-28 05:48:22 +0000130 virtual void EmitZerofill(const MCSection *Section, MCSymbol *Symbol = 0,
Daniel Dunbar7092c7e2009-08-30 06:17:16 +0000131 unsigned Size = 0, unsigned ByteAlignment = 0);
Chris Lattneraaec2052010-01-19 19:46:13 +0000132 virtual void EmitBytes(StringRef Data, unsigned AddrSpace);
Chris Lattneraaec2052010-01-19 19:46:13 +0000133 virtual void EmitValue(const MCExpr *Value, unsigned Size,unsigned AddrSpace);
Chris Lattner718fb592010-01-25 21:28:50 +0000134 virtual void EmitGPRel32Value(const MCExpr *Value) {
135 assert(0 && "macho doesn't support this directive");
136 }
Daniel Dunbarfb4a6b32009-08-21 09:11:24 +0000137 virtual void EmitValueToAlignment(unsigned ByteAlignment, int64_t Value = 0,
138 unsigned ValueSize = 1,
139 unsigned MaxBytesToEmit = 0);
Daniel Dunbar821e3332009-08-31 08:09:28 +0000140 virtual void EmitValueToOffset(const MCExpr *Offset,
Daniel Dunbarfb4a6b32009-08-21 09:11:24 +0000141 unsigned char Value = 0);
Chris Lattnera6594fc2010-01-25 18:58:59 +0000142
143 virtual void EmitFileDirective(StringRef Filename) {
144 errs() << "FIXME: MCMachoStreamer:EmitFileDirective not implemented\n";
145 }
146 virtual void EmitDwarfFileDirective(unsigned FileNo, StringRef Filename) {
147 errs() << "FIXME: MCMachoStreamer:EmitDwarfFileDirective not implemented\n";
148 }
149
Daniel Dunbarfb4a6b32009-08-21 09:11:24 +0000150 virtual void EmitInstruction(const MCInst &Inst);
Daniel Dunbarfb4a6b32009-08-21 09:11:24 +0000151 virtual void Finish();
152
153 /// @}
154};
155
156} // end anonymous namespace.
157
158void MCMachOStreamer::SwitchSection(const MCSection *Section) {
159 assert(Section && "Cannot switch to a null section!");
Chris Lattnercda7f782009-08-22 19:35:08 +0000160
161 // If already in this section, then this is a noop.
162 if (Section == CurSection) return;
Daniel Dunbar0f5fa692009-08-28 05:48:54 +0000163
Chris Lattnercda7f782009-08-22 19:35:08 +0000164 CurSection = Section;
Daniel Dunbar0f5fa692009-08-28 05:48:54 +0000165 CurSectionData = &getSectionData(*Section);
Daniel Dunbarfb4a6b32009-08-21 09:11:24 +0000166}
167
168void MCMachOStreamer::EmitLabel(MCSymbol *Symbol) {
Daniel Dunbar8906ff12009-08-22 07:22:36 +0000169 assert(Symbol->isUndefined() && "Cannot define a symbol twice!");
Daniel Dunbarfb4a6b32009-08-21 09:11:24 +0000170
Daniel Dunbar5e835962009-08-26 02:48:04 +0000171 // FIXME: We should also use offsets into Fill fragments.
Daniel Dunbarf3d2ef02009-08-22 10:13:24 +0000172 MCDataFragment *F = dyn_cast_or_null<MCDataFragment>(getCurrentFragment());
173 if (!F)
174 F = new MCDataFragment(CurSectionData);
Daniel Dunbarfb4a6b32009-08-21 09:11:24 +0000175
Daniel Dunbarf3d2ef02009-08-22 10:13:24 +0000176 MCSymbolData &SD = getSymbolData(*Symbol);
177 assert(!SD.getFragment() && "Unexpected fragment on symbol data!");
178 SD.setFragment(F);
179 SD.setOffset(F->getContents().size());
Daniel Dunbar6aff2fb2009-08-24 08:40:12 +0000180
181 // This causes the reference type and weak reference flags to be cleared.
182 SD.setFlags(SD.getFlags() & ~(SF_WeakReference | SF_ReferenceTypeMask));
Daniel Dunbarf3d2ef02009-08-22 10:13:24 +0000183
Daniel Dunbar8906ff12009-08-22 07:22:36 +0000184 Symbol->setSection(*CurSection);
Daniel Dunbarfb4a6b32009-08-21 09:11:24 +0000185}
186
Chris Lattnera5ad93a2010-01-23 06:39:22 +0000187void MCMachOStreamer::EmitAssemblerFlag(MCAssemblerFlag Flag) {
Daniel Dunbar6009db42009-08-26 21:22:22 +0000188 switch (Flag) {
Chris Lattnera5ad93a2010-01-23 06:39:22 +0000189 case MCAF_SubsectionsViaSymbols:
Daniel Dunbar6009db42009-08-26 21:22:22 +0000190 Assembler.setSubsectionsViaSymbols(true);
Daniel Dunbar8c3eaf42009-08-28 07:08:47 +0000191 return;
Daniel Dunbar6009db42009-08-26 21:22:22 +0000192 }
Daniel Dunbar8c3eaf42009-08-28 07:08:47 +0000193
194 assert(0 && "invalid assembler flag!");
Daniel Dunbarfb4a6b32009-08-21 09:11:24 +0000195}
196
Daniel Dunbar821e3332009-08-31 08:09:28 +0000197void MCMachOStreamer::EmitAssignment(MCSymbol *Symbol, const MCExpr *Value) {
Daniel Dunbar8906ff12009-08-22 07:22:36 +0000198 // Only absolute symbols can be redefined.
199 assert((Symbol->isUndefined() || Symbol->isAbsolute()) &&
200 "Cannot define a symbol twice!");
Daniel Dunbarfb4a6b32009-08-21 09:11:24 +0000201
Daniel Dunbara4d86672009-10-16 01:58:23 +0000202 // FIXME: Lift context changes into super class.
203 // FIXME: Set associated section.
204 Symbol->setValue(Value);
Daniel Dunbarfb4a6b32009-08-21 09:11:24 +0000205}
206
207void MCMachOStreamer::EmitSymbolAttribute(MCSymbol *Symbol,
Chris Lattnera5ad93a2010-01-23 06:39:22 +0000208 MCSymbolAttr Attribute) {
Daniel Dunbar0c7761b2009-08-24 11:56:58 +0000209 // Indirect symbols are handled differently, to match how 'as' handles
210 // them. This makes writing matching .o files easier.
Chris Lattnera5ad93a2010-01-23 06:39:22 +0000211 if (Attribute == MCSA_IndirectSymbol) {
Daniel Dunbarad7c3d52009-08-26 00:18:21 +0000212 // Note that we intentionally cannot use the symbol data here; this is
213 // important for matching the string table that 'as' generates.
Daniel Dunbar0c7761b2009-08-24 11:56:58 +0000214 IndirectSymbolData ISD;
215 ISD.Symbol = Symbol;
216 ISD.SectionData = CurSectionData;
217 Assembler.getIndirectSymbols().push_back(ISD);
218 return;
219 }
220
Daniel Dunbar6aff2fb2009-08-24 08:40:12 +0000221 // Adding a symbol attribute always introduces the symbol, note that an
222 // important side effect of calling getSymbolData here is to register the
223 // symbol with the assembler.
224 MCSymbolData &SD = getSymbolData(*Symbol);
225
226 // The implementation of symbol attributes is designed to match 'as', but it
227 // leaves much to desired. It doesn't really make sense to arbitrarily add and
228 // remove flags, but 'as' allows this (in particular, see .desc).
229 //
230 // In the future it might be worth trying to make these operations more well
231 // defined.
Daniel Dunbar3edd9bb2009-08-22 11:41:10 +0000232 switch (Attribute) {
Chris Lattnera5ad93a2010-01-23 06:39:22 +0000233 case MCSA_Invalid:
Chris Lattnered0ab152010-01-25 18:30:45 +0000234 case MCSA_ELF_TypeFunction:
235 case MCSA_ELF_TypeIndFunction:
236 case MCSA_ELF_TypeObject:
237 case MCSA_ELF_TypeTLS:
238 case MCSA_ELF_TypeCommon:
239 case MCSA_ELF_TypeNoType:
Chris Lattnera5ad93a2010-01-23 06:39:22 +0000240 case MCSA_IndirectSymbol:
241 case MCSA_Hidden:
242 case MCSA_Internal:
243 case MCSA_Protected:
244 case MCSA_Weak:
245 case MCSA_Local:
Daniel Dunbar6aff2fb2009-08-24 08:40:12 +0000246 assert(0 && "Invalid symbol attribute for Mach-O!");
247 break;
Daniel Dunbar3edd9bb2009-08-22 11:41:10 +0000248
Chris Lattnera5ad93a2010-01-23 06:39:22 +0000249 case MCSA_Global:
Daniel Dunbar8f4d1462009-08-28 07:08:35 +0000250 SD.setExternal(true);
Daniel Dunbar3edd9bb2009-08-22 11:41:10 +0000251 break;
Daniel Dunbar6aff2fb2009-08-24 08:40:12 +0000252
Chris Lattnera5ad93a2010-01-23 06:39:22 +0000253 case MCSA_LazyReference:
Daniel Dunbar6aff2fb2009-08-24 08:40:12 +0000254 // FIXME: This requires -dynamic.
255 SD.setFlags(SD.getFlags() | SF_NoDeadStrip);
256 if (Symbol->isUndefined())
257 SD.setFlags(SD.getFlags() | SF_ReferenceTypeUndefinedLazy);
258 break;
259
Daniel Dunbar6aff2fb2009-08-24 08:40:12 +0000260 // Since .reference sets the no dead strip bit, it is equivalent to
261 // .no_dead_strip in practice.
Chris Lattnera5ad93a2010-01-23 06:39:22 +0000262 case MCSA_Reference:
263 case MCSA_NoDeadStrip:
Daniel Dunbar6aff2fb2009-08-24 08:40:12 +0000264 SD.setFlags(SD.getFlags() | SF_NoDeadStrip);
265 break;
266
Chris Lattnera5ad93a2010-01-23 06:39:22 +0000267 case MCSA_PrivateExtern:
Daniel Dunbar6aff2fb2009-08-24 08:40:12 +0000268 SD.setExternal(true);
269 SD.setPrivateExtern(true);
270 break;
271
Chris Lattnera5ad93a2010-01-23 06:39:22 +0000272 case MCSA_WeakReference:
Daniel Dunbar6aff2fb2009-08-24 08:40:12 +0000273 // FIXME: This requires -dynamic.
274 if (Symbol->isUndefined())
275 SD.setFlags(SD.getFlags() | SF_WeakReference);
276 break;
277
Chris Lattnera5ad93a2010-01-23 06:39:22 +0000278 case MCSA_WeakDefinition:
Daniel Dunbar6aff2fb2009-08-24 08:40:12 +0000279 // FIXME: 'as' enforces that this is defined and global. The manual claims
280 // it has to be in a coalesced section, but this isn't enforced.
281 SD.setFlags(SD.getFlags() | SF_WeakDefinition);
282 break;
Daniel Dunbar3edd9bb2009-08-22 11:41:10 +0000283 }
Daniel Dunbarfb4a6b32009-08-21 09:11:24 +0000284}
285
286void MCMachOStreamer::EmitSymbolDesc(MCSymbol *Symbol, unsigned DescValue) {
Daniel Dunbar6aff2fb2009-08-24 08:40:12 +0000287 // Encode the 'desc' value into the lowest implementation defined bits.
288 assert(DescValue == (DescValue & SF_DescFlagsMask) &&
289 "Invalid .desc value!");
290 getSymbolData(*Symbol).setFlags(DescValue & SF_DescFlagsMask);
Daniel Dunbarfb4a6b32009-08-21 09:11:24 +0000291}
292
Chris Lattner9eb158d2010-01-23 07:47:02 +0000293void MCMachOStreamer::EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
Daniel Dunbar7092c7e2009-08-30 06:17:16 +0000294 unsigned ByteAlignment) {
Daniel Dunbar8f4d1462009-08-28 07:08:35 +0000295 // FIXME: Darwin 'as' does appear to allow redef of a .comm by itself.
296 assert(Symbol->isUndefined() && "Cannot define a symbol twice!");
297
298 MCSymbolData &SD = getSymbolData(*Symbol);
299 SD.setExternal(true);
Daniel Dunbar7092c7e2009-08-30 06:17:16 +0000300 SD.setCommon(Size, ByteAlignment);
Daniel Dunbarfb4a6b32009-08-21 09:11:24 +0000301}
302
Daniel Dunbar8751b942009-08-28 05:48:22 +0000303void MCMachOStreamer::EmitZerofill(const MCSection *Section, MCSymbol *Symbol,
Daniel Dunbar7092c7e2009-08-30 06:17:16 +0000304 unsigned Size, unsigned ByteAlignment) {
Daniel Dunbard5a8e982009-08-28 05:49:21 +0000305 MCSectionData &SectData = getSectionData(*Section);
306
307 // The symbol may not be present, which only creates the section.
308 if (!Symbol)
309 return;
310
311 // FIXME: Assert that this section has the zerofill type.
312
313 assert(Symbol->isUndefined() && "Cannot define a symbol twice!");
314
315 MCSymbolData &SD = getSymbolData(*Symbol);
316
Daniel Dunbar7092c7e2009-08-30 06:17:16 +0000317 MCFragment *F = new MCZeroFillFragment(Size, ByteAlignment, &SectData);
Daniel Dunbard5a8e982009-08-28 05:49:21 +0000318 SD.setFragment(F);
319
320 Symbol->setSection(*Section);
321
322 // Update the maximum alignment on the zero fill section if necessary.
323 if (ByteAlignment > SectData.getAlignment())
324 SectData.setAlignment(ByteAlignment);
Daniel Dunbarfb4a6b32009-08-21 09:11:24 +0000325}
326
Chris Lattneraaec2052010-01-19 19:46:13 +0000327void MCMachOStreamer::EmitBytes(StringRef Data, unsigned AddrSpace) {
Daniel Dunbarf3d2ef02009-08-22 10:13:24 +0000328 MCDataFragment *DF = dyn_cast_or_null<MCDataFragment>(getCurrentFragment());
329 if (!DF)
330 DF = new MCDataFragment(CurSectionData);
Daniel Dunbar0705fbf2009-08-21 18:29:01 +0000331 DF->getContents().append(Data.begin(), Data.end());
Daniel Dunbarfb4a6b32009-08-21 09:11:24 +0000332}
333
Chris Lattneraaec2052010-01-19 19:46:13 +0000334void MCMachOStreamer::EmitValue(const MCExpr *Value, unsigned Size,
335 unsigned AddrSpace) {
Daniel Dunbar1253a6f2009-10-16 01:58:03 +0000336 new MCFillFragment(*AddValueSymbols(Value), Size, 1, CurSectionData);
Daniel Dunbarfb4a6b32009-08-21 09:11:24 +0000337}
338
339void MCMachOStreamer::EmitValueToAlignment(unsigned ByteAlignment,
340 int64_t Value, unsigned ValueSize,
341 unsigned MaxBytesToEmit) {
Daniel Dunbard6f761e2009-08-21 23:07:38 +0000342 if (MaxBytesToEmit == 0)
343 MaxBytesToEmit = ByteAlignment;
Daniel Dunbar0705fbf2009-08-21 18:29:01 +0000344 new MCAlignFragment(ByteAlignment, Value, ValueSize, MaxBytesToEmit,
345 CurSectionData);
346
Daniel Dunbarf3d2ef02009-08-22 10:13:24 +0000347 // Update the maximum alignment on the current section if necessary.
Daniel Dunbar0705fbf2009-08-21 18:29:01 +0000348 if (ByteAlignment > CurSectionData->getAlignment())
349 CurSectionData->setAlignment(ByteAlignment);
Daniel Dunbarfb4a6b32009-08-21 09:11:24 +0000350}
351
Daniel Dunbar821e3332009-08-31 08:09:28 +0000352void MCMachOStreamer::EmitValueToOffset(const MCExpr *Offset,
Daniel Dunbarfb4a6b32009-08-21 09:11:24 +0000353 unsigned char Value) {
Daniel Dunbar1253a6f2009-10-16 01:58:03 +0000354 new MCOrgFragment(*Offset, Value, CurSectionData);
Daniel Dunbarfb4a6b32009-08-21 09:11:24 +0000355}
356
357void MCMachOStreamer::EmitInstruction(const MCInst &Inst) {
Daniel Dunbar4fac7492009-08-27 08:17:51 +0000358 // Scan for values.
359 for (unsigned i = 0; i != Inst.getNumOperands(); ++i)
Daniel Dunbar8c2eebe2009-08-31 08:08:38 +0000360 if (Inst.getOperand(i).isExpr())
361 AddValueSymbols(Inst.getOperand(i).getExpr());
Daniel Dunbar4fac7492009-08-27 08:17:51 +0000362
363 if (!Emitter)
364 llvm_unreachable("no code emitter available!");
365
Daniel Dunbare1ec6172010-02-02 21:44:01 +0000366 CurSectionData->setHasInstructions(true);
367
Daniel Dunbar4fac7492009-08-27 08:17:51 +0000368 // FIXME: Relocations!
369 SmallString<256> Code;
370 raw_svector_ostream VecOS(Code);
371 Emitter->EncodeInstruction(Inst, VecOS);
Chris Lattneraaec2052010-01-19 19:46:13 +0000372 EmitBytes(VecOS.str(), 0);
Daniel Dunbarfb4a6b32009-08-21 09:11:24 +0000373}
374
375void MCMachOStreamer::Finish() {
376 Assembler.Finish();
377}
378
Daniel Dunbar4fac7492009-08-27 08:17:51 +0000379MCStreamer *llvm::createMachOStreamer(MCContext &Context, raw_ostream &OS,
380 MCCodeEmitter *CE) {
381 return new MCMachOStreamer(Context, OS, CE);
Daniel Dunbarfb4a6b32009-08-21 09:11:24 +0000382}