Daniel Dunbar | fb4a6b3 | 2009-08-21 09:11:24 +0000 | [diff] [blame] | 1 | //===- 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 Dunbar | fb4a6b3 | 2009-08-21 09:11:24 +0000 | [diff] [blame] | 12 | #include "llvm/MC/MCAssembler.h" |
| 13 | #include "llvm/MC/MCContext.h" |
Daniel Dunbar | 4fac749 | 2009-08-27 08:17:51 +0000 | [diff] [blame] | 14 | #include "llvm/MC/MCCodeEmitter.h" |
| 15 | #include "llvm/MC/MCInst.h" |
Daniel Dunbar | fb4a6b3 | 2009-08-21 09:11:24 +0000 | [diff] [blame] | 16 | #include "llvm/MC/MCSection.h" |
| 17 | #include "llvm/MC/MCSymbol.h" |
Daniel Dunbar | fb4a6b3 | 2009-08-21 09:11:24 +0000 | [diff] [blame] | 18 | #include "llvm/Support/ErrorHandling.h" |
Daniel Dunbar | 4fac749 | 2009-08-27 08:17:51 +0000 | [diff] [blame] | 19 | #include "llvm/Support/raw_ostream.h" |
Daniel Dunbar | fb4a6b3 | 2009-08-21 09:11:24 +0000 | [diff] [blame] | 20 | using namespace llvm; |
| 21 | |
| 22 | namespace { |
| 23 | |
| 24 | class MCMachOStreamer : public MCStreamer { |
Daniel Dunbar | 6aff2fb | 2009-08-24 08:40:12 +0000 | [diff] [blame] | 25 | /// SymbolFlags - We store the value for the 'desc' symbol field in the lowest |
| 26 | /// 16 bits of the implementation defined flags. |
| 27 | enum SymbolFlags { // See <mach-o/nlist.h>. |
| 28 | SF_DescFlagsMask = 0xFFFF, |
| 29 | |
| 30 | // Reference type flags. |
| 31 | SF_ReferenceTypeMask = 0x0007, |
| 32 | SF_ReferenceTypeUndefinedNonLazy = 0x0000, |
| 33 | SF_ReferenceTypeUndefinedLazy = 0x0001, |
| 34 | SF_ReferenceTypeDefined = 0x0002, |
| 35 | SF_ReferenceTypePrivateDefined = 0x0003, |
| 36 | SF_ReferenceTypePrivateUndefinedNonLazy = 0x0004, |
| 37 | SF_ReferenceTypePrivateUndefinedLazy = 0x0005, |
| 38 | |
| 39 | // Other 'desc' flags. |
| 40 | SF_NoDeadStrip = 0x0020, |
| 41 | SF_WeakReference = 0x0040, |
| 42 | SF_WeakDefinition = 0x0080 |
| 43 | }; |
| 44 | |
| 45 | private: |
Daniel Dunbar | fb4a6b3 | 2009-08-21 09:11:24 +0000 | [diff] [blame] | 46 | MCAssembler Assembler; |
| 47 | |
Daniel Dunbar | 4fac749 | 2009-08-27 08:17:51 +0000 | [diff] [blame] | 48 | MCCodeEmitter *Emitter; |
| 49 | |
Daniel Dunbar | fb4a6b3 | 2009-08-21 09:11:24 +0000 | [diff] [blame] | 50 | MCSectionData *CurSectionData; |
| 51 | |
| 52 | DenseMap<const MCSection*, MCSectionData*> SectionMap; |
Daniel Dunbar | f3d2ef0 | 2009-08-22 10:13:24 +0000 | [diff] [blame] | 53 | |
| 54 | DenseMap<const MCSymbol*, MCSymbolData*> SymbolMap; |
| 55 | |
| 56 | private: |
| 57 | MCFragment *getCurrentFragment() const { |
| 58 | assert(CurSectionData && "No current section!"); |
| 59 | |
| 60 | if (!CurSectionData->empty()) |
| 61 | return &CurSectionData->getFragmentList().back(); |
| 62 | |
| 63 | return 0; |
| 64 | } |
| 65 | |
Daniel Dunbar | 0f5fa69 | 2009-08-28 05:48:54 +0000 | [diff] [blame] | 66 | MCSectionData &getSectionData(const MCSection &Section) { |
| 67 | MCSectionData *&Entry = SectionMap[&Section]; |
| 68 | |
| 69 | if (!Entry) |
| 70 | Entry = new MCSectionData(Section, &Assembler); |
| 71 | |
| 72 | return *Entry; |
| 73 | } |
| 74 | |
Daniel Dunbar | f3d2ef0 | 2009-08-22 10:13:24 +0000 | [diff] [blame] | 75 | MCSymbolData &getSymbolData(MCSymbol &Symbol) { |
| 76 | MCSymbolData *&Entry = SymbolMap[&Symbol]; |
| 77 | |
| 78 | if (!Entry) |
| 79 | Entry = new MCSymbolData(Symbol, 0, 0, &Assembler); |
| 80 | |
| 81 | return *Entry; |
| 82 | } |
Daniel Dunbar | fb4a6b3 | 2009-08-21 09:11:24 +0000 | [diff] [blame] | 83 | |
| 84 | public: |
Daniel Dunbar | 4fac749 | 2009-08-27 08:17:51 +0000 | [diff] [blame] | 85 | MCMachOStreamer(MCContext &Context, raw_ostream &_OS, MCCodeEmitter *_Emitter) |
| 86 | : MCStreamer(Context), Assembler(_OS), Emitter(_Emitter), |
| 87 | CurSectionData(0) {} |
Daniel Dunbar | fb4a6b3 | 2009-08-21 09:11:24 +0000 | [diff] [blame] | 88 | ~MCMachOStreamer() {} |
| 89 | |
Daniel Dunbar | a421de1 | 2009-08-26 13:57:37 +0000 | [diff] [blame] | 90 | const MCValue &AddValueSymbols(const MCValue &Value) { |
| 91 | if (Value.getSymA()) |
| 92 | getSymbolData(*const_cast<MCSymbol*>(Value.getSymA())); |
| 93 | if (Value.getSymB()) |
| 94 | getSymbolData(*const_cast<MCSymbol*>(Value.getSymB())); |
| 95 | return Value; |
| 96 | } |
| 97 | |
Daniel Dunbar | fb4a6b3 | 2009-08-21 09:11:24 +0000 | [diff] [blame] | 98 | /// @name MCStreamer Interface |
| 99 | /// @{ |
| 100 | |
| 101 | virtual void SwitchSection(const MCSection *Section); |
| 102 | |
| 103 | virtual void EmitLabel(MCSymbol *Symbol); |
| 104 | |
| 105 | virtual void EmitAssemblerFlag(AssemblerFlag Flag); |
| 106 | |
| 107 | virtual void EmitAssignment(MCSymbol *Symbol, const MCValue &Value, |
| 108 | bool MakeAbsolute = false); |
| 109 | |
| 110 | virtual void EmitSymbolAttribute(MCSymbol *Symbol, SymbolAttr Attribute); |
| 111 | |
| 112 | virtual void EmitSymbolDesc(MCSymbol *Symbol, unsigned DescValue); |
| 113 | |
| 114 | virtual void EmitLocalSymbol(MCSymbol *Symbol, const MCValue &Value); |
| 115 | |
| 116 | virtual void EmitCommonSymbol(MCSymbol *Symbol, unsigned Size, |
Daniel Dunbar | e6cdbf2 | 2009-08-28 05:48:46 +0000 | [diff] [blame] | 117 | unsigned Pow2Alignment); |
Daniel Dunbar | fb4a6b3 | 2009-08-21 09:11:24 +0000 | [diff] [blame] | 118 | |
Daniel Dunbar | 8751b94 | 2009-08-28 05:48:22 +0000 | [diff] [blame] | 119 | virtual void EmitZerofill(const MCSection *Section, MCSymbol *Symbol = 0, |
Daniel Dunbar | fb4a6b3 | 2009-08-21 09:11:24 +0000 | [diff] [blame] | 120 | unsigned Size = 0, unsigned Pow2Alignment = 0); |
| 121 | |
| 122 | virtual void EmitBytes(const StringRef &Data); |
| 123 | |
| 124 | virtual void EmitValue(const MCValue &Value, unsigned Size); |
| 125 | |
| 126 | virtual void EmitValueToAlignment(unsigned ByteAlignment, int64_t Value = 0, |
| 127 | unsigned ValueSize = 1, |
| 128 | unsigned MaxBytesToEmit = 0); |
| 129 | |
| 130 | virtual void EmitValueToOffset(const MCValue &Offset, |
| 131 | unsigned char Value = 0); |
| 132 | |
| 133 | virtual void EmitInstruction(const MCInst &Inst); |
| 134 | |
| 135 | virtual void Finish(); |
| 136 | |
| 137 | /// @} |
| 138 | }; |
| 139 | |
| 140 | } // end anonymous namespace. |
| 141 | |
| 142 | void MCMachOStreamer::SwitchSection(const MCSection *Section) { |
| 143 | assert(Section && "Cannot switch to a null section!"); |
Chris Lattner | cda7f78 | 2009-08-22 19:35:08 +0000 | [diff] [blame] | 144 | |
| 145 | // If already in this section, then this is a noop. |
| 146 | if (Section == CurSection) return; |
Daniel Dunbar | 0f5fa69 | 2009-08-28 05:48:54 +0000 | [diff] [blame] | 147 | |
Chris Lattner | cda7f78 | 2009-08-22 19:35:08 +0000 | [diff] [blame] | 148 | CurSection = Section; |
Daniel Dunbar | 0f5fa69 | 2009-08-28 05:48:54 +0000 | [diff] [blame] | 149 | CurSectionData = &getSectionData(*Section); |
Daniel Dunbar | fb4a6b3 | 2009-08-21 09:11:24 +0000 | [diff] [blame] | 150 | } |
| 151 | |
| 152 | void MCMachOStreamer::EmitLabel(MCSymbol *Symbol) { |
Daniel Dunbar | 8906ff1 | 2009-08-22 07:22:36 +0000 | [diff] [blame] | 153 | assert(Symbol->isUndefined() && "Cannot define a symbol twice!"); |
Daniel Dunbar | fb4a6b3 | 2009-08-21 09:11:24 +0000 | [diff] [blame] | 154 | |
Daniel Dunbar | 5e83596 | 2009-08-26 02:48:04 +0000 | [diff] [blame] | 155 | // FIXME: We should also use offsets into Fill fragments. |
Daniel Dunbar | f3d2ef0 | 2009-08-22 10:13:24 +0000 | [diff] [blame] | 156 | MCDataFragment *F = dyn_cast_or_null<MCDataFragment>(getCurrentFragment()); |
| 157 | if (!F) |
| 158 | F = new MCDataFragment(CurSectionData); |
Daniel Dunbar | fb4a6b3 | 2009-08-21 09:11:24 +0000 | [diff] [blame] | 159 | |
Daniel Dunbar | f3d2ef0 | 2009-08-22 10:13:24 +0000 | [diff] [blame] | 160 | MCSymbolData &SD = getSymbolData(*Symbol); |
| 161 | assert(!SD.getFragment() && "Unexpected fragment on symbol data!"); |
| 162 | SD.setFragment(F); |
| 163 | SD.setOffset(F->getContents().size()); |
Daniel Dunbar | 6aff2fb | 2009-08-24 08:40:12 +0000 | [diff] [blame] | 164 | |
| 165 | // This causes the reference type and weak reference flags to be cleared. |
| 166 | SD.setFlags(SD.getFlags() & ~(SF_WeakReference | SF_ReferenceTypeMask)); |
Daniel Dunbar | f3d2ef0 | 2009-08-22 10:13:24 +0000 | [diff] [blame] | 167 | |
Daniel Dunbar | 8906ff1 | 2009-08-22 07:22:36 +0000 | [diff] [blame] | 168 | Symbol->setSection(*CurSection); |
Daniel Dunbar | fb4a6b3 | 2009-08-21 09:11:24 +0000 | [diff] [blame] | 169 | } |
| 170 | |
| 171 | void MCMachOStreamer::EmitAssemblerFlag(AssemblerFlag Flag) { |
Daniel Dunbar | 6009db4 | 2009-08-26 21:22:22 +0000 | [diff] [blame] | 172 | switch (Flag) { |
| 173 | default: |
| 174 | llvm_unreachable("FIXME: Not yet implemented!"); |
| 175 | |
| 176 | case SubsectionsViaSymbols: |
| 177 | Assembler.setSubsectionsViaSymbols(true); |
| 178 | break; |
| 179 | } |
Daniel Dunbar | fb4a6b3 | 2009-08-21 09:11:24 +0000 | [diff] [blame] | 180 | } |
| 181 | |
| 182 | void MCMachOStreamer::EmitAssignment(MCSymbol *Symbol, |
| 183 | const MCValue &Value, |
| 184 | bool MakeAbsolute) { |
Daniel Dunbar | 8906ff1 | 2009-08-22 07:22:36 +0000 | [diff] [blame] | 185 | // Only absolute symbols can be redefined. |
| 186 | assert((Symbol->isUndefined() || Symbol->isAbsolute()) && |
| 187 | "Cannot define a symbol twice!"); |
Daniel Dunbar | fb4a6b3 | 2009-08-21 09:11:24 +0000 | [diff] [blame] | 188 | |
| 189 | llvm_unreachable("FIXME: Not yet implemented!"); |
| 190 | } |
| 191 | |
| 192 | void MCMachOStreamer::EmitSymbolAttribute(MCSymbol *Symbol, |
| 193 | SymbolAttr Attribute) { |
Daniel Dunbar | 0c7761b | 2009-08-24 11:56:58 +0000 | [diff] [blame] | 194 | // Indirect symbols are handled differently, to match how 'as' handles |
| 195 | // them. This makes writing matching .o files easier. |
| 196 | if (Attribute == MCStreamer::IndirectSymbol) { |
Daniel Dunbar | ad7c3d5 | 2009-08-26 00:18:21 +0000 | [diff] [blame] | 197 | // Note that we intentionally cannot use the symbol data here; this is |
| 198 | // important for matching the string table that 'as' generates. |
Daniel Dunbar | 0c7761b | 2009-08-24 11:56:58 +0000 | [diff] [blame] | 199 | IndirectSymbolData ISD; |
| 200 | ISD.Symbol = Symbol; |
| 201 | ISD.SectionData = CurSectionData; |
| 202 | Assembler.getIndirectSymbols().push_back(ISD); |
| 203 | return; |
| 204 | } |
| 205 | |
Daniel Dunbar | 6aff2fb | 2009-08-24 08:40:12 +0000 | [diff] [blame] | 206 | // Adding a symbol attribute always introduces the symbol, note that an |
| 207 | // important side effect of calling getSymbolData here is to register the |
| 208 | // symbol with the assembler. |
| 209 | MCSymbolData &SD = getSymbolData(*Symbol); |
| 210 | |
| 211 | // The implementation of symbol attributes is designed to match 'as', but it |
| 212 | // leaves much to desired. It doesn't really make sense to arbitrarily add and |
| 213 | // remove flags, but 'as' allows this (in particular, see .desc). |
| 214 | // |
| 215 | // In the future it might be worth trying to make these operations more well |
| 216 | // defined. |
Daniel Dunbar | 3edd9bb | 2009-08-22 11:41:10 +0000 | [diff] [blame] | 217 | switch (Attribute) { |
Daniel Dunbar | 0c7761b | 2009-08-24 11:56:58 +0000 | [diff] [blame] | 218 | case MCStreamer::IndirectSymbol: |
Daniel Dunbar | 6aff2fb | 2009-08-24 08:40:12 +0000 | [diff] [blame] | 219 | case MCStreamer::Hidden: |
| 220 | case MCStreamer::Internal: |
| 221 | case MCStreamer::Protected: |
| 222 | case MCStreamer::Weak: |
| 223 | assert(0 && "Invalid symbol attribute for Mach-O!"); |
| 224 | break; |
Daniel Dunbar | 3edd9bb | 2009-08-22 11:41:10 +0000 | [diff] [blame] | 225 | |
| 226 | case MCStreamer::Global: |
| 227 | getSymbolData(*Symbol).setExternal(true); |
| 228 | break; |
Daniel Dunbar | 6aff2fb | 2009-08-24 08:40:12 +0000 | [diff] [blame] | 229 | |
| 230 | case MCStreamer::LazyReference: |
| 231 | // FIXME: This requires -dynamic. |
| 232 | SD.setFlags(SD.getFlags() | SF_NoDeadStrip); |
| 233 | if (Symbol->isUndefined()) |
| 234 | SD.setFlags(SD.getFlags() | SF_ReferenceTypeUndefinedLazy); |
| 235 | break; |
| 236 | |
Daniel Dunbar | 6aff2fb | 2009-08-24 08:40:12 +0000 | [diff] [blame] | 237 | // Since .reference sets the no dead strip bit, it is equivalent to |
| 238 | // .no_dead_strip in practice. |
| 239 | case MCStreamer::Reference: |
| 240 | case MCStreamer::NoDeadStrip: |
| 241 | SD.setFlags(SD.getFlags() | SF_NoDeadStrip); |
| 242 | break; |
| 243 | |
| 244 | case MCStreamer::PrivateExtern: |
| 245 | SD.setExternal(true); |
| 246 | SD.setPrivateExtern(true); |
| 247 | break; |
| 248 | |
| 249 | case MCStreamer::WeakReference: |
| 250 | // FIXME: This requires -dynamic. |
| 251 | if (Symbol->isUndefined()) |
| 252 | SD.setFlags(SD.getFlags() | SF_WeakReference); |
| 253 | break; |
| 254 | |
| 255 | case MCStreamer::WeakDefinition: |
| 256 | // FIXME: 'as' enforces that this is defined and global. The manual claims |
| 257 | // it has to be in a coalesced section, but this isn't enforced. |
| 258 | SD.setFlags(SD.getFlags() | SF_WeakDefinition); |
| 259 | break; |
Daniel Dunbar | 3edd9bb | 2009-08-22 11:41:10 +0000 | [diff] [blame] | 260 | } |
Daniel Dunbar | fb4a6b3 | 2009-08-21 09:11:24 +0000 | [diff] [blame] | 261 | } |
| 262 | |
| 263 | void MCMachOStreamer::EmitSymbolDesc(MCSymbol *Symbol, unsigned DescValue) { |
Daniel Dunbar | 6aff2fb | 2009-08-24 08:40:12 +0000 | [diff] [blame] | 264 | // Encode the 'desc' value into the lowest implementation defined bits. |
| 265 | assert(DescValue == (DescValue & SF_DescFlagsMask) && |
| 266 | "Invalid .desc value!"); |
| 267 | getSymbolData(*Symbol).setFlags(DescValue & SF_DescFlagsMask); |
Daniel Dunbar | fb4a6b3 | 2009-08-21 09:11:24 +0000 | [diff] [blame] | 268 | } |
| 269 | |
| 270 | void MCMachOStreamer::EmitLocalSymbol(MCSymbol *Symbol, const MCValue &Value) { |
| 271 | llvm_unreachable("FIXME: Not yet implemented!"); |
| 272 | } |
| 273 | |
| 274 | void MCMachOStreamer::EmitCommonSymbol(MCSymbol *Symbol, unsigned Size, |
Daniel Dunbar | e6cdbf2 | 2009-08-28 05:48:46 +0000 | [diff] [blame] | 275 | unsigned Pow2Alignment) { |
Daniel Dunbar | fb4a6b3 | 2009-08-21 09:11:24 +0000 | [diff] [blame] | 276 | llvm_unreachable("FIXME: Not yet implemented!"); |
| 277 | } |
| 278 | |
Daniel Dunbar | 8751b94 | 2009-08-28 05:48:22 +0000 | [diff] [blame] | 279 | void MCMachOStreamer::EmitZerofill(const MCSection *Section, MCSymbol *Symbol, |
Daniel Dunbar | fb4a6b3 | 2009-08-21 09:11:24 +0000 | [diff] [blame] | 280 | unsigned Size, unsigned Pow2Alignment) { |
Daniel Dunbar | d5a8e98 | 2009-08-28 05:49:21 +0000 | [diff] [blame^] | 281 | unsigned ByteAlignment = 1 << Pow2Alignment; |
| 282 | MCSectionData &SectData = getSectionData(*Section); |
| 283 | |
| 284 | // The symbol may not be present, which only creates the section. |
| 285 | if (!Symbol) |
| 286 | return; |
| 287 | |
| 288 | // FIXME: Assert that this section has the zerofill type. |
| 289 | |
| 290 | assert(Symbol->isUndefined() && "Cannot define a symbol twice!"); |
| 291 | |
| 292 | MCSymbolData &SD = getSymbolData(*Symbol); |
| 293 | |
| 294 | MCFragment *F = new MCZeroFillFragment(Size, 1 << Pow2Alignment, &SectData); |
| 295 | SD.setFragment(F); |
| 296 | |
| 297 | Symbol->setSection(*Section); |
| 298 | |
| 299 | // Update the maximum alignment on the zero fill section if necessary. |
| 300 | if (ByteAlignment > SectData.getAlignment()) |
| 301 | SectData.setAlignment(ByteAlignment); |
Daniel Dunbar | fb4a6b3 | 2009-08-21 09:11:24 +0000 | [diff] [blame] | 302 | } |
| 303 | |
| 304 | void MCMachOStreamer::EmitBytes(const StringRef &Data) { |
Daniel Dunbar | f3d2ef0 | 2009-08-22 10:13:24 +0000 | [diff] [blame] | 305 | MCDataFragment *DF = dyn_cast_or_null<MCDataFragment>(getCurrentFragment()); |
| 306 | if (!DF) |
| 307 | DF = new MCDataFragment(CurSectionData); |
Daniel Dunbar | 0705fbf | 2009-08-21 18:29:01 +0000 | [diff] [blame] | 308 | DF->getContents().append(Data.begin(), Data.end()); |
Daniel Dunbar | fb4a6b3 | 2009-08-21 09:11:24 +0000 | [diff] [blame] | 309 | } |
| 310 | |
| 311 | void MCMachOStreamer::EmitValue(const MCValue &Value, unsigned Size) { |
Daniel Dunbar | a421de1 | 2009-08-26 13:57:37 +0000 | [diff] [blame] | 312 | new MCFillFragment(AddValueSymbols(Value), Size, 1, CurSectionData); |
Daniel Dunbar | fb4a6b3 | 2009-08-21 09:11:24 +0000 | [diff] [blame] | 313 | } |
| 314 | |
| 315 | void MCMachOStreamer::EmitValueToAlignment(unsigned ByteAlignment, |
| 316 | int64_t Value, unsigned ValueSize, |
| 317 | unsigned MaxBytesToEmit) { |
Daniel Dunbar | d6f761e | 2009-08-21 23:07:38 +0000 | [diff] [blame] | 318 | if (MaxBytesToEmit == 0) |
| 319 | MaxBytesToEmit = ByteAlignment; |
Daniel Dunbar | 0705fbf | 2009-08-21 18:29:01 +0000 | [diff] [blame] | 320 | new MCAlignFragment(ByteAlignment, Value, ValueSize, MaxBytesToEmit, |
| 321 | CurSectionData); |
| 322 | |
Daniel Dunbar | f3d2ef0 | 2009-08-22 10:13:24 +0000 | [diff] [blame] | 323 | // Update the maximum alignment on the current section if necessary. |
Daniel Dunbar | 0705fbf | 2009-08-21 18:29:01 +0000 | [diff] [blame] | 324 | if (ByteAlignment > CurSectionData->getAlignment()) |
| 325 | CurSectionData->setAlignment(ByteAlignment); |
Daniel Dunbar | fb4a6b3 | 2009-08-21 09:11:24 +0000 | [diff] [blame] | 326 | } |
| 327 | |
| 328 | void MCMachOStreamer::EmitValueToOffset(const MCValue &Offset, |
| 329 | unsigned char Value) { |
Daniel Dunbar | a421de1 | 2009-08-26 13:57:37 +0000 | [diff] [blame] | 330 | new MCOrgFragment(AddValueSymbols(Offset), Value, CurSectionData); |
Daniel Dunbar | fb4a6b3 | 2009-08-21 09:11:24 +0000 | [diff] [blame] | 331 | } |
| 332 | |
| 333 | void MCMachOStreamer::EmitInstruction(const MCInst &Inst) { |
Daniel Dunbar | 4fac749 | 2009-08-27 08:17:51 +0000 | [diff] [blame] | 334 | // Scan for values. |
| 335 | for (unsigned i = 0; i != Inst.getNumOperands(); ++i) |
| 336 | if (Inst.getOperand(i).isMCValue()) |
| 337 | AddValueSymbols(Inst.getOperand(i).getMCValue()); |
| 338 | |
| 339 | if (!Emitter) |
| 340 | llvm_unreachable("no code emitter available!"); |
| 341 | |
| 342 | // FIXME: Relocations! |
| 343 | SmallString<256> Code; |
| 344 | raw_svector_ostream VecOS(Code); |
| 345 | Emitter->EncodeInstruction(Inst, VecOS); |
| 346 | EmitBytes(VecOS.str()); |
Daniel Dunbar | fb4a6b3 | 2009-08-21 09:11:24 +0000 | [diff] [blame] | 347 | } |
| 348 | |
| 349 | void MCMachOStreamer::Finish() { |
| 350 | Assembler.Finish(); |
| 351 | } |
| 352 | |
Daniel Dunbar | 4fac749 | 2009-08-27 08:17:51 +0000 | [diff] [blame] | 353 | MCStreamer *llvm::createMachOStreamer(MCContext &Context, raw_ostream &OS, |
| 354 | MCCodeEmitter *CE) { |
| 355 | return new MCMachOStreamer(Context, OS, CE); |
Daniel Dunbar | fb4a6b3 | 2009-08-21 09:11:24 +0000 | [diff] [blame] | 356 | } |