blob: b665cdff83e898a99e18b2d12b66be612eae4ace [file] [log] [blame]
Daniel Dunbarfb4a6b32009-08-21 09:11:24 +00001//===- lib/MC/MCAssembler.cpp - Assembler Backend Implementation ----------===//
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
Daniel Dunbar0adcd352009-08-25 21:10:45 +000010#define DEBUG_TYPE "assembler"
Daniel Dunbarfb4a6b32009-08-21 09:11:24 +000011#include "llvm/MC/MCAssembler.h"
Daniel Dunbar18ff2cc2010-03-11 05:53:33 +000012#include "llvm/MC/MCAsmLayout.h"
Daniel Dunbarb36052f2010-03-19 10:43:23 +000013#include "llvm/MC/MCCodeEmitter.h"
Daniel Dunbar1253a6f2009-10-16 01:58:03 +000014#include "llvm/MC/MCExpr.h"
Daniel Dunbar53b23382010-03-19 09:28:59 +000015#include "llvm/MC/MCObjectWriter.h"
Daniel Dunbar1253a6f2009-10-16 01:58:03 +000016#include "llvm/MC/MCSymbol.h"
17#include "llvm/MC/MCValue.h"
Daniel Dunbar1a9158c2010-03-19 10:43:26 +000018#include "llvm/ADT/OwningPtr.h"
Daniel Dunbar0adcd352009-08-25 21:10:45 +000019#include "llvm/ADT/Statistic.h"
Daniel Dunbarb7c3a4b2010-02-13 09:28:03 +000020#include "llvm/ADT/StringExtras.h"
Daniel Dunbard6f761e2009-08-21 23:07:38 +000021#include "llvm/ADT/Twine.h"
Daniel Dunbar0705fbf2009-08-21 18:29:01 +000022#include "llvm/Support/ErrorHandling.h"
Daniel Dunbarfb4a6b32009-08-21 09:11:24 +000023#include "llvm/Support/raw_ostream.h"
Daniel Dunbarb7c3a4b2010-02-13 09:28:03 +000024#include "llvm/Support/Debug.h"
Daniel Dunbaree0d8922010-03-13 22:10:17 +000025#include "llvm/Target/TargetRegistry.h"
Daniel Dunbardf3c8f22010-03-12 21:00:49 +000026#include "llvm/Target/TargetAsmBackend.h"
Daniel Dunbarf6346762010-02-13 09:29:02 +000027
Chris Lattner23132b12009-08-24 03:52:50 +000028#include <vector>
Daniel Dunbarfb4a6b32009-08-21 09:11:24 +000029using namespace llvm;
30
Daniel Dunbar0adcd352009-08-25 21:10:45 +000031STATISTIC(EmittedFragments, "Number of emitted assembler fragments");
32
Daniel Dunbar8f4d1462009-08-28 07:08:35 +000033// FIXME FIXME FIXME: There are number of places in this file where we convert
34// what is a 64-bit assembler value used for computation into a value in the
35// object file, which may truncate it. We should detect that truncation where
36// invalid and report errors back.
37
Daniel Dunbarfb4a6b32009-08-21 09:11:24 +000038/* *** */
39
Daniel Dunbar0705fbf2009-08-21 18:29:01 +000040MCFragment::MCFragment() : Kind(FragmentType(~0)) {
41}
42
Daniel Dunbar5e835962009-08-26 02:48:04 +000043MCFragment::MCFragment(FragmentType _Kind, MCSectionData *_Parent)
Daniel Dunbar0705fbf2009-08-21 18:29:01 +000044 : Kind(_Kind),
Daniel Dunbar5e835962009-08-26 02:48:04 +000045 Parent(_Parent),
Daniel Dunbar0705fbf2009-08-21 18:29:01 +000046 FileSize(~UINT64_C(0))
Daniel Dunbarfb4a6b32009-08-21 09:11:24 +000047{
Daniel Dunbar5e835962009-08-26 02:48:04 +000048 if (Parent)
49 Parent->getFragmentList().push_back(this);
Daniel Dunbarfb4a6b32009-08-21 09:11:24 +000050}
51
Daniel Dunbar0705fbf2009-08-21 18:29:01 +000052MCFragment::~MCFragment() {
53}
54
Daniel Dunbar5e835962009-08-26 02:48:04 +000055uint64_t MCFragment::getAddress() const {
56 assert(getParent() && "Missing Section!");
57 return getParent()->getAddress() + Offset;
58}
59
Daniel Dunbarfb4a6b32009-08-21 09:11:24 +000060/* *** */
61
Daniel Dunbar81e40002009-08-27 00:38:04 +000062MCSectionData::MCSectionData() : Section(0) {}
Daniel Dunbarfb4a6b32009-08-21 09:11:24 +000063
64MCSectionData::MCSectionData(const MCSection &_Section, MCAssembler *A)
Daniel Dunbar81e40002009-08-27 00:38:04 +000065 : Section(&_Section),
Daniel Dunbarfb4a6b32009-08-21 09:11:24 +000066 Alignment(1),
Daniel Dunbar5e835962009-08-26 02:48:04 +000067 Address(~UINT64_C(0)),
Daniel Dunbar6742e342009-08-26 04:13:32 +000068 Size(~UINT64_C(0)),
Daniel Dunbar3f6a9602009-08-26 13:58:10 +000069 FileSize(~UINT64_C(0)),
Daniel Dunbare1ec6172010-02-02 21:44:01 +000070 HasInstructions(false)
Daniel Dunbarfb4a6b32009-08-21 09:11:24 +000071{
72 if (A)
73 A->getSectionList().push_back(this);
74}
75
Daniel Dunbarfb4a6b32009-08-21 09:11:24 +000076/* *** */
77
Daniel Dunbarefbb5332009-09-01 04:09:03 +000078MCSymbolData::MCSymbolData() : Symbol(0) {}
Daniel Dunbarf3d2ef02009-08-22 10:13:24 +000079
Daniel Dunbarcb579b32009-08-31 08:08:06 +000080MCSymbolData::MCSymbolData(const MCSymbol &_Symbol, MCFragment *_Fragment,
Daniel Dunbarf3d2ef02009-08-22 10:13:24 +000081 uint64_t _Offset, MCAssembler *A)
Daniel Dunbarefbb5332009-09-01 04:09:03 +000082 : Symbol(&_Symbol), Fragment(_Fragment), Offset(_Offset),
Daniel Dunbar8f4d1462009-08-28 07:08:35 +000083 IsExternal(false), IsPrivateExtern(false),
84 CommonSize(0), CommonAlign(0), Flags(0), Index(0)
Daniel Dunbarf3d2ef02009-08-22 10:13:24 +000085{
86 if (A)
87 A->getSymbolList().push_back(this);
88}
89
90/* *** */
91
Daniel Dunbar1f3e4452010-03-11 01:34:27 +000092MCAssembler::MCAssembler(MCContext &_Context, TargetAsmBackend &_Backend,
Daniel Dunbarcf871e52010-03-19 10:43:18 +000093 MCCodeEmitter &_Emitter, raw_ostream &_OS)
94 : Context(_Context), Backend(_Backend), Emitter(_Emitter),
95 OS(_OS), SubsectionsViaSymbols(false)
Daniel Dunbar6009db42009-08-26 21:22:22 +000096{
97}
Daniel Dunbarfb4a6b32009-08-21 09:11:24 +000098
99MCAssembler::~MCAssembler() {
100}
101
Daniel Dunbar939f8d72010-03-19 03:18:12 +0000102static bool isScatteredFixupFullyResolvedSimple(const MCAssembler &Asm,
103 const MCAsmFixup &Fixup,
Daniel Dunbar939f8d72010-03-19 03:18:12 +0000104 const MCValue Target,
105 const MCSection *BaseSection) {
106 // The effective fixup address is
107 // addr(atom(A)) + offset(A)
108 // - addr(atom(B)) - offset(B)
109 // - addr(<base symbol>) + <fixup offset from base symbol>
110 // and the offsets are not relocatable, so the fixup is fully resolved when
111 // addr(atom(A)) - addr(atom(B)) - addr(<base symbol>)) == 0.
112 //
113 // The simple (Darwin, except on x86_64) way of dealing with this was to
114 // assume that any reference to a temporary symbol *must* be a temporary
115 // symbol in the same atom, unless the sections differ. Therefore, any PCrel
116 // relocation to a temporary symbol (in the same section) is fully
117 // resolved. This also works in conjunction with absolutized .set, which
118 // requires the compiler to use .set to absolutize the differences between
119 // symbols which the compiler knows to be assembly time constants, so we don't
120 // need to worry about consider symbol differences fully resolved.
121
122 // Non-relative fixups are only resolved if constant.
123 if (!BaseSection)
124 return Target.isAbsolute();
125
126 // Otherwise, relative fixups are only resolved if not a difference and the
127 // target is a temporary in the same section.
128 if (Target.isAbsolute() || Target.getSymB())
129 return false;
130
131 const MCSymbol *A = &Target.getSymA()->getSymbol();
132 if (!A->isTemporary() || !A->isInSection() ||
133 &A->getSection() != BaseSection)
134 return false;
135
136 return true;
137}
138
Daniel Dunbar034843a2010-03-19 03:18:18 +0000139static bool isScatteredFixupFullyResolved(const MCAssembler &Asm,
140 const MCAsmFixup &Fixup,
Daniel Dunbar034843a2010-03-19 03:18:18 +0000141 const MCValue Target,
142 const MCSymbolData *BaseSymbol) {
143 // The effective fixup address is
144 // addr(atom(A)) + offset(A)
145 // - addr(atom(B)) - offset(B)
146 // - addr(BaseSymbol) + <fixup offset from base symbol>
147 // and the offsets are not relocatable, so the fixup is fully resolved when
148 // addr(atom(A)) - addr(atom(B)) - addr(BaseSymbol) == 0.
149 //
150 // Note that "false" is almost always conservatively correct (it means we emit
151 // a relocation which is unnecessary), except when it would force us to emit a
152 // relocation which the target cannot encode.
153
154 const MCSymbolData *A_Base = 0, *B_Base = 0;
155 if (const MCSymbolRefExpr *A = Target.getSymA()) {
156 // Modified symbol references cannot be resolved.
157 if (A->getKind() != MCSymbolRefExpr::VK_None)
158 return false;
159
160 A_Base = Asm.getAtom(&Asm.getSymbolData(A->getSymbol()));
161 if (!A_Base)
162 return false;
163 }
164
165 if (const MCSymbolRefExpr *B = Target.getSymB()) {
166 // Modified symbol references cannot be resolved.
167 if (B->getKind() != MCSymbolRefExpr::VK_None)
168 return false;
169
170 B_Base = Asm.getAtom(&Asm.getSymbolData(B->getSymbol()));
171 if (!B_Base)
172 return false;
173 }
174
175 // If there is no base, A and B have to be the same atom for this fixup to be
176 // fully resolved.
177 if (!BaseSymbol)
178 return A_Base == B_Base;
179
180 // Otherwise, B must be missing and A must be the base.
181 return !B_Base && BaseSymbol == A_Base;
182}
183
Daniel Dunbar23869852010-03-19 03:18:09 +0000184bool MCAssembler::isSymbolLinkerVisible(const MCSymbolData *SD) const {
185 // Non-temporary labels should always be visible to the linker.
186 if (!SD->getSymbol().isTemporary())
187 return true;
188
189 // Absolute temporary labels are never visible.
190 if (!SD->getFragment())
191 return false;
192
193 // Otherwise, check if the section requires symbols even for temporary labels.
194 return getBackend().doesSectionRequireSymbols(
195 SD->getFragment()->getParent()->getSection());
196}
197
Daniel Dunbar8ad0dcc2010-03-19 03:18:15 +0000198const MCSymbolData *MCAssembler::getAtomForAddress(const MCSectionData *Section,
199 uint64_t Address) const {
200 const MCSymbolData *Best = 0;
201 for (MCAssembler::const_symbol_iterator it = symbol_begin(),
202 ie = symbol_end(); it != ie; ++it) {
203 // Ignore non-linker visible symbols.
204 if (!isSymbolLinkerVisible(it))
205 continue;
206
207 // Ignore symbols not in the same section.
208 if (!it->getFragment() || it->getFragment()->getParent() != Section)
209 continue;
210
211 // Otherwise, find the closest symbol preceding this address (ties are
212 // resolved in favor of the last defined symbol).
213 if (it->getAddress() <= Address &&
214 (!Best || it->getAddress() >= Best->getAddress()))
215 Best = it;
216 }
217
218 return Best;
219}
220
221const MCSymbolData *MCAssembler::getAtom(const MCSymbolData *SD) const {
222 // Linker visible symbols define atoms.
223 if (isSymbolLinkerVisible(SD))
224 return SD;
225
226 // Absolute and undefined symbols have no defining atom.
227 if (!SD->getFragment())
228 return 0;
229
230 // Otherwise, search by address.
231 return getAtomForAddress(SD->getFragment()->getParent(), SD->getAddress());
232}
233
Daniel Dunbar9d39e612010-03-22 21:49:41 +0000234bool MCAssembler::EvaluateFixup(const MCAsmLayout &Layout,
235 const MCAsmFixup &Fixup, const MCFragment *DF,
Daniel Dunbardf3c8f22010-03-12 21:00:49 +0000236 MCValue &Target, uint64_t &Value) const {
237 if (!Fixup.Value->EvaluateAsRelocatable(Target, &Layout))
238 llvm_report_error("expected relocatable expression");
239
240 // FIXME: How do non-scattered symbols work in ELF? I presume the linker
241 // doesn't support small relocations, but then under what criteria does the
242 // assembler allow symbol differences?
243
244 Value = Target.getConstant();
245
Daniel Dunbarb36052f2010-03-19 10:43:23 +0000246 bool IsPCRel =
247 Emitter.getFixupKindInfo(Fixup.Kind).Flags & MCFixupKindInfo::FKF_IsPCRel;
248 bool IsResolved = true;
Daniel Dunbar9a1d2002010-03-18 00:59:10 +0000249 if (const MCSymbolRefExpr *A = Target.getSymA()) {
250 if (A->getSymbol().isDefined())
251 Value += getSymbolData(A->getSymbol()).getAddress();
Daniel Dunbardf3c8f22010-03-12 21:00:49 +0000252 else
253 IsResolved = false;
Daniel Dunbardf3c8f22010-03-12 21:00:49 +0000254 }
Daniel Dunbar9a1d2002010-03-18 00:59:10 +0000255 if (const MCSymbolRefExpr *B = Target.getSymB()) {
256 if (B->getSymbol().isDefined())
257 Value -= getSymbolData(B->getSymbol()).getAddress();
Daniel Dunbardf3c8f22010-03-12 21:00:49 +0000258 else
259 IsResolved = false;
Daniel Dunbar939f8d72010-03-19 03:18:12 +0000260 }
Daniel Dunbardf3c8f22010-03-12 21:00:49 +0000261
Daniel Dunbar939f8d72010-03-19 03:18:12 +0000262 // If we are using scattered symbols, determine whether this value is actually
263 // resolved; scattering may cause atoms to move.
264 if (IsResolved && getBackend().hasScatteredSymbols()) {
265 if (getBackend().hasReliableSymbolDifference()) {
Daniel Dunbar034843a2010-03-19 03:18:18 +0000266 // If this is a PCrel relocation, find the base atom (identified by its
267 // symbol) that the fixup value is relative to.
268 const MCSymbolData *BaseSymbol = 0;
269 if (IsPCRel) {
270 BaseSymbol = getAtomForAddress(
271 DF->getParent(), DF->getAddress() + Fixup.Offset);
272 if (!BaseSymbol)
273 IsResolved = false;
274 }
275
276 if (IsResolved)
Daniel Dunbarc6f59822010-03-22 21:49:38 +0000277 IsResolved = isScatteredFixupFullyResolved(*this, Fixup, Target,
Daniel Dunbar034843a2010-03-19 03:18:18 +0000278 BaseSymbol);
Daniel Dunbar939f8d72010-03-19 03:18:12 +0000279 } else {
280 const MCSection *BaseSection = 0;
281 if (IsPCRel)
282 BaseSection = &DF->getParent()->getSection();
283
Daniel Dunbarc6f59822010-03-22 21:49:38 +0000284 IsResolved = isScatteredFixupFullyResolvedSimple(*this, Fixup, Target,
Daniel Dunbar939f8d72010-03-19 03:18:12 +0000285 BaseSection);
286 }
Daniel Dunbardf3c8f22010-03-12 21:00:49 +0000287 }
288
289 if (IsPCRel)
Daniel Dunbarda3e9f72010-03-13 02:38:00 +0000290 Value -= DF->getAddress() + Fixup.Offset;
Daniel Dunbardf3c8f22010-03-12 21:00:49 +0000291
292 return IsResolved;
293}
294
Daniel Dunbar8d39eb42010-03-22 20:35:35 +0000295void MCAssembler::LayoutSection(MCSectionData &SD,
296 MCAsmLayout &Layout) {
Daniel Dunbar6742e342009-08-26 04:13:32 +0000297 uint64_t Address = SD.getAddress();
Daniel Dunbar0705fbf2009-08-21 18:29:01 +0000298
299 for (MCSectionData::iterator it = SD.begin(), ie = SD.end(); it != ie; ++it) {
300 MCFragment &F = *it;
Daniel Dunbard6f761e2009-08-21 23:07:38 +0000301
Daniel Dunbar6742e342009-08-26 04:13:32 +0000302 F.setOffset(Address - SD.getAddress());
Daniel Dunbard6f761e2009-08-21 23:07:38 +0000303
304 // Evaluate fragment size.
305 switch (F.getKind()) {
306 case MCFragment::FT_Align: {
307 MCAlignFragment &AF = cast<MCAlignFragment>(F);
Daniel Dunbar7eb85192009-10-16 01:58:15 +0000308
Daniel Dunbard5a8e982009-08-28 05:49:21 +0000309 uint64_t Size = OffsetToAlignment(Address, AF.getAlignment());
Daniel Dunbar6742e342009-08-26 04:13:32 +0000310 if (Size > AF.getMaxBytesToEmit())
Daniel Dunbard6f761e2009-08-21 23:07:38 +0000311 AF.setFileSize(0);
312 else
Daniel Dunbar6742e342009-08-26 04:13:32 +0000313 AF.setFileSize(Size);
Daniel Dunbard6f761e2009-08-21 23:07:38 +0000314 break;
315 }
316
317 case MCFragment::FT_Data:
Daniel Dunbar2a6e3f52010-03-22 20:35:43 +0000318 F.setFileSize(cast<MCDataFragment>(F).getContents().size());
Daniel Dunbard6f761e2009-08-21 23:07:38 +0000319 break;
320
Daniel Dunbar2a6e3f52010-03-22 20:35:43 +0000321 case MCFragment::FT_Fill: {
322 MCFillFragment &FF = cast<MCFillFragment>(F);
323 F.setFileSize(FF.getValueSize() * FF.getCount());
324 break;
325 }
326
Daniel Dunbar3f4dcd92010-03-22 23:16:48 +0000327 case MCFragment::FT_Inst:
328 F.setFileSize(cast<MCInstFragment>(F).getInstSize());
329 break;
330
Daniel Dunbard6f761e2009-08-21 23:07:38 +0000331 case MCFragment::FT_Org: {
332 MCOrgFragment &OF = cast<MCOrgFragment>(F);
333
Daniel Dunbar18ff2cc2010-03-11 05:53:33 +0000334 int64_t TargetLocation;
335 if (!OF.getOffset().EvaluateAsAbsolute(TargetLocation, &Layout))
336 llvm_report_error("expected assembly-time absolute expression");
Daniel Dunbard6f761e2009-08-21 23:07:38 +0000337
338 // FIXME: We need a way to communicate this error.
Daniel Dunbar18ff2cc2010-03-11 05:53:33 +0000339 int64_t Offset = TargetLocation - F.getOffset();
340 if (Offset < 0)
341 llvm_report_error("invalid .org offset '" + Twine(TargetLocation) +
342 "' (at offset '" + Twine(F.getOffset()) + "'");
Daniel Dunbar7eb85192009-10-16 01:58:15 +0000343
Daniel Dunbar18ff2cc2010-03-11 05:53:33 +0000344 F.setFileSize(Offset);
Daniel Dunbard6f761e2009-08-21 23:07:38 +0000345 break;
Daniel Dunbar7eb85192009-10-16 01:58:15 +0000346 }
Daniel Dunbard5a8e982009-08-28 05:49:21 +0000347
348 case MCFragment::FT_ZeroFill: {
349 MCZeroFillFragment &ZFF = cast<MCZeroFillFragment>(F);
350
351 // Align the fragment offset; it is safe to adjust the offset freely since
352 // this is only in virtual sections.
Daniel Dunbar37fad5c2010-03-08 21:10:42 +0000353 Address = RoundUpToAlignment(Address, ZFF.getAlignment());
354 F.setOffset(Address - SD.getAddress());
Daniel Dunbard5a8e982009-08-28 05:49:21 +0000355
356 // FIXME: This is misnamed.
357 F.setFileSize(ZFF.getSize());
358 break;
359 }
Daniel Dunbard6f761e2009-08-21 23:07:38 +0000360 }
361
Daniel Dunbar6742e342009-08-26 04:13:32 +0000362 Address += F.getFileSize();
Daniel Dunbar0705fbf2009-08-21 18:29:01 +0000363 }
364
Daniel Dunbar6742e342009-08-26 04:13:32 +0000365 // Set the section sizes.
366 SD.setSize(Address - SD.getAddress());
Daniel Dunbarcc5b84c2010-03-19 09:29:03 +0000367 if (getBackend().isVirtualSection(SD.getSection()))
Daniel Dunbard5a8e982009-08-28 05:49:21 +0000368 SD.setFileSize(0);
369 else
370 SD.setFileSize(Address - SD.getAddress());
Daniel Dunbar0705fbf2009-08-21 18:29:01 +0000371}
372
Daniel Dunbar53b23382010-03-19 09:28:59 +0000373/// WriteFragmentData - Write the \arg F data to the output file.
Daniel Dunbar8f9b80e2010-03-23 02:36:58 +0000374static void WriteFragmentData(const MCAssembler &Asm, const MCFragment &F,
375 MCObjectWriter *OW) {
Daniel Dunbar53b23382010-03-19 09:28:59 +0000376 uint64_t Start = OW->getStream().tell();
Daniel Dunbar0705fbf2009-08-21 18:29:01 +0000377 (void) Start;
Daniel Dunbar7eb85192009-10-16 01:58:15 +0000378
Daniel Dunbar0adcd352009-08-25 21:10:45 +0000379 ++EmittedFragments;
380
Daniel Dunbar0705fbf2009-08-21 18:29:01 +0000381 // FIXME: Embed in fragments instead?
382 switch (F.getKind()) {
Daniel Dunbard6f761e2009-08-21 23:07:38 +0000383 case MCFragment::FT_Align: {
384 MCAlignFragment &AF = cast<MCAlignFragment>(F);
385 uint64_t Count = AF.getFileSize() / AF.getValueSize();
386
387 // FIXME: This error shouldn't actually occur (the front end should emit
388 // multiple .align directives to enforce the semantics it wants), but is
389 // severe enough that we want to report it. How to handle this?
390 if (Count * AF.getValueSize() != AF.getFileSize())
Daniel Dunbar7eb85192009-10-16 01:58:15 +0000391 llvm_report_error("undefined .align directive, value size '" +
392 Twine(AF.getValueSize()) +
Daniel Dunbard6f761e2009-08-21 23:07:38 +0000393 "' is not a divisor of padding size '" +
394 Twine(AF.getFileSize()) + "'");
395
Kevin Enderby6e720482010-02-23 18:26:34 +0000396 // See if we are aligning with nops, and if so do that first to try to fill
397 // the Count bytes. Then if that did not fill any bytes or there are any
398 // bytes left to fill use the the Value and ValueSize to fill the rest.
Daniel Dunbar8f9b80e2010-03-23 02:36:58 +0000399 // If we are aligning with nops, ask that target to emit the right data.
Kevin Enderby6e720482010-02-23 18:26:34 +0000400 if (AF.getEmitNops()) {
Daniel Dunbar8f9b80e2010-03-23 02:36:58 +0000401 if (!Asm.getBackend().WriteNopData(Count, OW))
402 llvm_report_error("unable to write nop sequence of " +
403 Twine(Count) + " bytes");
404 break;
Kevin Enderby6e720482010-02-23 18:26:34 +0000405 }
406
Daniel Dunbar8f9b80e2010-03-23 02:36:58 +0000407 // Otherwise, write out in multiples of the value size.
Daniel Dunbard6f761e2009-08-21 23:07:38 +0000408 for (uint64_t i = 0; i != Count; ++i) {
409 switch (AF.getValueSize()) {
410 default:
411 assert(0 && "Invalid size!");
Daniel Dunbarbdd92812010-03-19 09:28:55 +0000412 case 1: OW->Write8 (uint8_t (AF.getValue())); break;
413 case 2: OW->Write16(uint16_t(AF.getValue())); break;
414 case 4: OW->Write32(uint32_t(AF.getValue())); break;
415 case 8: OW->Write64(uint64_t(AF.getValue())); break;
Daniel Dunbard6f761e2009-08-21 23:07:38 +0000416 }
417 }
418 break;
419 }
Daniel Dunbar0705fbf2009-08-21 18:29:01 +0000420
Daniel Dunbar3a30b822010-02-13 09:28:15 +0000421 case MCFragment::FT_Data: {
Daniel Dunbar3f4dcd92010-03-22 23:16:48 +0000422 MCDataFragment &DF = cast<MCDataFragment>(F);
423 assert(DF.getFileSize() == DF.getContents().size() && "Invalid size!");
424 OW->WriteBytes(DF.getContents().str());
Daniel Dunbar0705fbf2009-08-21 18:29:01 +0000425 break;
Daniel Dunbar3a30b822010-02-13 09:28:15 +0000426 }
Daniel Dunbar0705fbf2009-08-21 18:29:01 +0000427
Daniel Dunbar0705fbf2009-08-21 18:29:01 +0000428 case MCFragment::FT_Fill: {
429 MCFillFragment &FF = cast<MCFillFragment>(F);
Daniel Dunbar0705fbf2009-08-21 18:29:01 +0000430 for (uint64_t i = 0, e = FF.getCount(); i != e; ++i) {
431 switch (FF.getValueSize()) {
432 default:
433 assert(0 && "Invalid size!");
Daniel Dunbarbdd92812010-03-19 09:28:55 +0000434 case 1: OW->Write8 (uint8_t (FF.getValue())); break;
435 case 2: OW->Write16(uint16_t(FF.getValue())); break;
436 case 4: OW->Write32(uint32_t(FF.getValue())); break;
437 case 8: OW->Write64(uint64_t(FF.getValue())); break;
Daniel Dunbar0705fbf2009-08-21 18:29:01 +0000438 }
439 }
440 break;
441 }
Daniel Dunbar7eb85192009-10-16 01:58:15 +0000442
Daniel Dunbar3f4dcd92010-03-22 23:16:48 +0000443 case MCFragment::FT_Inst:
444 llvm_unreachable("unexpected inst fragment after lowering");
445 break;
446
Daniel Dunbard6f761e2009-08-21 23:07:38 +0000447 case MCFragment::FT_Org: {
448 MCOrgFragment &OF = cast<MCOrgFragment>(F);
449
450 for (uint64_t i = 0, e = OF.getFileSize(); i != e; ++i)
Daniel Dunbarbdd92812010-03-19 09:28:55 +0000451 OW->Write8(uint8_t(OF.getValue()));
Daniel Dunbard6f761e2009-08-21 23:07:38 +0000452
453 break;
454 }
Daniel Dunbard5a8e982009-08-28 05:49:21 +0000455
456 case MCFragment::FT_ZeroFill: {
457 assert(0 && "Invalid zero fill fragment in concrete section!");
458 break;
459 }
Daniel Dunbar0705fbf2009-08-21 18:29:01 +0000460 }
461
Daniel Dunbar53b23382010-03-19 09:28:59 +0000462 assert(OW->getStream().tell() - Start == F.getFileSize());
Daniel Dunbar0705fbf2009-08-21 18:29:01 +0000463}
464
Daniel Dunbar53b23382010-03-19 09:28:59 +0000465void MCAssembler::WriteSectionData(const MCSectionData *SD,
466 MCObjectWriter *OW) const {
Daniel Dunbard5a8e982009-08-28 05:49:21 +0000467 // Ignore virtual sections.
Daniel Dunbarcc5b84c2010-03-19 09:29:03 +0000468 if (getBackend().isVirtualSection(SD->getSection())) {
Daniel Dunbar53b23382010-03-19 09:28:59 +0000469 assert(SD->getFileSize() == 0);
Daniel Dunbard5a8e982009-08-28 05:49:21 +0000470 return;
471 }
472
Daniel Dunbar53b23382010-03-19 09:28:59 +0000473 uint64_t Start = OW->getStream().tell();
Daniel Dunbar0705fbf2009-08-21 18:29:01 +0000474 (void) Start;
Daniel Dunbar7eb85192009-10-16 01:58:15 +0000475
Daniel Dunbar53b23382010-03-19 09:28:59 +0000476 for (MCSectionData::const_iterator it = SD->begin(),
477 ie = SD->end(); it != ie; ++it)
Daniel Dunbar8f9b80e2010-03-23 02:36:58 +0000478 WriteFragmentData(*this, *it, OW);
Daniel Dunbar0705fbf2009-08-21 18:29:01 +0000479
Daniel Dunbar6742e342009-08-26 04:13:32 +0000480 // Add section padding.
Daniel Dunbar53b23382010-03-19 09:28:59 +0000481 assert(SD->getFileSize() >= SD->getSize() && "Invalid section sizes!");
482 OW->WriteZeros(SD->getFileSize() - SD->getSize());
Daniel Dunbar6742e342009-08-26 04:13:32 +0000483
Daniel Dunbar53b23382010-03-19 09:28:59 +0000484 assert(OW->getStream().tell() - Start == SD->getFileSize());
Daniel Dunbar0705fbf2009-08-21 18:29:01 +0000485}
486
Daniel Dunbarfb4a6b32009-08-21 09:11:24 +0000487void MCAssembler::Finish() {
Daniel Dunbarb7c3a4b2010-02-13 09:28:03 +0000488 DEBUG_WITH_TYPE("mc-dump", {
489 llvm::errs() << "assembler backend - pre-layout\n--\n";
490 dump(); });
491
Daniel Dunbarf08fde42010-03-12 22:07:14 +0000492 // Layout until everything fits.
Daniel Dunbar8d39eb42010-03-22 20:35:35 +0000493 MCAsmLayout Layout(*this);
494 while (LayoutOnce(Layout))
Daniel Dunbarf08fde42010-03-12 22:07:14 +0000495 continue;
496
497 DEBUG_WITH_TYPE("mc-dump", {
Daniel Dunbar3f4dcd92010-03-22 23:16:48 +0000498 llvm::errs() << "assembler backend - post-relaxation\n--\n";
499 dump(); });
500
501 // Finalize the layout, including fragment lowering.
502 FinishLayout(Layout);
503
504 DEBUG_WITH_TYPE("mc-dump", {
505 llvm::errs() << "assembler backend - final-layout\n--\n";
Daniel Dunbarf08fde42010-03-12 22:07:14 +0000506 dump(); });
507
Daniel Dunbar1a9158c2010-03-19 10:43:26 +0000508 llvm::OwningPtr<MCObjectWriter> Writer(getBackend().createObjectWriter(OS));
509 if (!Writer)
510 llvm_report_error("unable to create object writer!");
Daniel Dunbarbacba992010-03-19 07:09:33 +0000511
512 // Allow the object writer a chance to perform post-layout binding (for
513 // example, to set the index fields in the symbol data).
Daniel Dunbar1a9158c2010-03-19 10:43:26 +0000514 Writer->ExecutePostLayoutBinding(*this);
Daniel Dunbarbacba992010-03-19 07:09:33 +0000515
Daniel Dunbarb1e98942010-03-19 07:09:47 +0000516 // Evaluate and apply the fixups, generating relocation entries as necessary.
Daniel Dunbarb1e98942010-03-19 07:09:47 +0000517 for (MCAssembler::iterator it = begin(), ie = end(); it != ie; ++it) {
518 for (MCSectionData::iterator it2 = it->begin(),
519 ie2 = it->end(); it2 != ie2; ++it2) {
520 MCDataFragment *DF = dyn_cast<MCDataFragment>(it2);
521 if (!DF)
522 continue;
523
524 for (MCDataFragment::fixup_iterator it3 = DF->fixup_begin(),
525 ie3 = DF->fixup_end(); it3 != ie3; ++it3) {
526 MCAsmFixup &Fixup = *it3;
527
528 // Evaluate the fixup.
529 MCValue Target;
530 uint64_t FixedValue;
531 if (!EvaluateFixup(Layout, Fixup, DF, Target, FixedValue)) {
532 // The fixup was unresolved, we need a relocation. Inform the object
533 // writer of the relocation, and give it an opportunity to adjust the
534 // fixup value if need be.
Daniel Dunbarb7514182010-03-22 20:35:50 +0000535 Writer->RecordRelocation(*this, DF, Fixup, Target, FixedValue);
Daniel Dunbarb1e98942010-03-19 07:09:47 +0000536 }
537
Daniel Dunbar87190c42010-03-19 09:28:12 +0000538 getBackend().ApplyFixup(Fixup, *DF, FixedValue);
Daniel Dunbarb1e98942010-03-19 07:09:47 +0000539 }
540 }
541 }
542
Daniel Dunbarbacba992010-03-19 07:09:33 +0000543 // Write the object file.
Daniel Dunbar1a9158c2010-03-19 10:43:26 +0000544 Writer->WriteObject(*this);
Daniel Dunbarf08fde42010-03-12 22:07:14 +0000545 OS.flush();
546}
547
Daniel Dunbar9d39e612010-03-22 21:49:41 +0000548bool MCAssembler::FixupNeedsRelaxation(const MCAsmFixup &Fixup,
549 const MCFragment *DF,
Daniel Dunbar8d39eb42010-03-22 20:35:35 +0000550 const MCAsmLayout &Layout) const {
Daniel Dunbarf08fde42010-03-12 22:07:14 +0000551 // If we cannot resolve the fixup value, it requires relaxation.
552 MCValue Target;
553 uint64_t Value;
554 if (!EvaluateFixup(Layout, Fixup, DF, Target, Value))
555 return true;
556
557 // Otherwise, relax if the value is too big for a (signed) i8.
558 return int64_t(Value) != int64_t(int8_t(Value));
559}
560
Daniel Dunbard8036fb2010-03-23 05:09:03 +0000561bool MCAssembler::FragmentNeedsRelaxation(const MCInstFragment *IF,
562 const MCAsmLayout &Layout) const {
563 // If this inst doesn't ever need relaxation, ignore it. This occurs when we
564 // are intentionally pushing out inst fragments, or because we relaxed a
565 // previous instruction to one that doesn't need relaxation.
566 if (!getBackend().MayNeedRelaxation(IF->getInst(), IF->getFixups()))
567 return false;
568
569 for (MCInstFragment::const_fixup_iterator it = IF->fixup_begin(),
570 ie = IF->fixup_end(); it != ie; ++it)
571 if (FixupNeedsRelaxation(*it, IF, Layout))
572 return true;
573
574 return false;
575}
576
Daniel Dunbar8d39eb42010-03-22 20:35:35 +0000577bool MCAssembler::LayoutOnce(MCAsmLayout &Layout) {
Daniel Dunbard5a8e982009-08-28 05:49:21 +0000578 // Layout the concrete sections and fragments.
Daniel Dunbar5e835962009-08-26 02:48:04 +0000579 uint64_t Address = 0;
Daniel Dunbaredc670f2009-08-28 05:49:04 +0000580 MCSectionData *Prev = 0;
581 for (iterator it = begin(), ie = end(); it != ie; ++it) {
Daniel Dunbar6742e342009-08-26 04:13:32 +0000582 MCSectionData &SD = *it;
583
Daniel Dunbard5a8e982009-08-28 05:49:21 +0000584 // Skip virtual sections.
Daniel Dunbarcc5b84c2010-03-19 09:29:03 +0000585 if (getBackend().isVirtualSection(SD.getSection()))
Daniel Dunbard5a8e982009-08-28 05:49:21 +0000586 continue;
587
Daniel Dunbaredc670f2009-08-28 05:49:04 +0000588 // Align this section if necessary by adding padding bytes to the previous
589 // section.
590 if (uint64_t Pad = OffsetToAlignment(Address, it->getAlignment())) {
591 assert(Prev && "Missing prev section!");
592 Prev->setFileSize(Prev->getFileSize() + Pad);
593 Address += Pad;
594 }
Daniel Dunbar6742e342009-08-26 04:13:32 +0000595
596 // Layout the section fragments and its size.
597 SD.setAddress(Address);
Daniel Dunbar8d39eb42010-03-22 20:35:35 +0000598 LayoutSection(SD, Layout);
Daniel Dunbar6742e342009-08-26 04:13:32 +0000599 Address += SD.getFileSize();
Daniel Dunbaredc670f2009-08-28 05:49:04 +0000600
601 Prev = &SD;
Daniel Dunbar5e835962009-08-26 02:48:04 +0000602 }
Daniel Dunbar0705fbf2009-08-21 18:29:01 +0000603
Daniel Dunbard5a8e982009-08-28 05:49:21 +0000604 // Layout the virtual sections.
605 for (iterator it = begin(), ie = end(); it != ie; ++it) {
606 MCSectionData &SD = *it;
607
Daniel Dunbarcc5b84c2010-03-19 09:29:03 +0000608 if (!getBackend().isVirtualSection(SD.getSection()))
Daniel Dunbard5a8e982009-08-28 05:49:21 +0000609 continue;
610
Daniel Dunbarb2b4acd2010-03-08 22:03:42 +0000611 // Align this section if necessary by adding padding bytes to the previous
612 // section.
Daniel Dunbarf8b8ad72010-03-09 01:12:20 +0000613 if (uint64_t Pad = OffsetToAlignment(Address, it->getAlignment()))
Daniel Dunbarb2b4acd2010-03-08 22:03:42 +0000614 Address += Pad;
Daniel Dunbarb2b4acd2010-03-08 22:03:42 +0000615
Daniel Dunbard5a8e982009-08-28 05:49:21 +0000616 SD.setAddress(Address);
Daniel Dunbar8d39eb42010-03-22 20:35:35 +0000617 LayoutSection(SD, Layout);
Daniel Dunbard5a8e982009-08-28 05:49:21 +0000618 Address += SD.getSize();
619 }
620
Daniel Dunbard8036fb2010-03-23 05:09:03 +0000621 // Scan for fragments that need relaxation.
Daniel Dunbarf08fde42010-03-12 22:07:14 +0000622 for (iterator it = begin(), ie = end(); it != ie; ++it) {
623 MCSectionData &SD = *it;
Daniel Dunbarb7c3a4b2010-02-13 09:28:03 +0000624
Daniel Dunbarf08fde42010-03-12 22:07:14 +0000625 for (MCSectionData::iterator it2 = SD.begin(),
626 ie2 = SD.end(); it2 != ie2; ++it2) {
Daniel Dunbard8036fb2010-03-23 05:09:03 +0000627 // Check if this is an instruction fragment that needs relaxation.
628 MCInstFragment *IF = dyn_cast<MCInstFragment>(it2);
629 if (!IF || !FragmentNeedsRelaxation(IF, Layout))
Daniel Dunbarf08fde42010-03-12 22:07:14 +0000630 continue;
Daniel Dunbar0705fbf2009-08-21 18:29:01 +0000631
Daniel Dunbard8036fb2010-03-23 05:09:03 +0000632 // FIXME-PERF: We could immediately lower out instructions if we can tell
633 // they are fully resolved, to avoid retesting on later passes.
Daniel Dunbarf08fde42010-03-12 22:07:14 +0000634
Daniel Dunbard8036fb2010-03-23 05:09:03 +0000635 // Relax the fragment.
Daniel Dunbarf08fde42010-03-12 22:07:14 +0000636
Daniel Dunbard8036fb2010-03-23 05:09:03 +0000637 MCInst Relaxed;
638 getBackend().RelaxInstruction(IF, Relaxed);
Daniel Dunbarf08fde42010-03-12 22:07:14 +0000639
Daniel Dunbard8036fb2010-03-23 05:09:03 +0000640 // Encode the new instruction.
641 //
642 // FIXME-PERF: If it matters, we could let the target do this. It can
643 // probably do so more efficiently in many cases.
644 SmallVector<MCFixup, 4> Fixups;
645 SmallString<256> Code;
646 raw_svector_ostream VecOS(Code);
647 getEmitter().EncodeInstruction(Relaxed, VecOS, Fixups);
648 VecOS.flush();
Daniel Dunbarf08fde42010-03-12 22:07:14 +0000649
Daniel Dunbard8036fb2010-03-23 05:09:03 +0000650 // Update the instruction fragment.
651 IF->setInst(Relaxed);
652 IF->getCode() = Code;
653 IF->getFixups().clear();
654 for (unsigned i = 0, e = Fixups.size(); i != e; ++i) {
655 MCFixup &F = Fixups[i];
656 IF->getFixups().push_back(MCAsmFixup(F.getOffset(), *F.getValue(),
657 F.getKind()));
Daniel Dunbarf08fde42010-03-12 22:07:14 +0000658 }
Daniel Dunbard8036fb2010-03-23 05:09:03 +0000659
660 // Restart layout.
661 //
662 // FIXME-PERF: This is O(N^2), but will be eliminated once we have a
663 // smart MCAsmLayout object.
664 return true;
Daniel Dunbarf08fde42010-03-12 22:07:14 +0000665 }
666 }
667
668 return false;
Daniel Dunbarfb4a6b32009-08-21 09:11:24 +0000669}
Daniel Dunbarb7c3a4b2010-02-13 09:28:03 +0000670
Daniel Dunbar3f4dcd92010-03-22 23:16:48 +0000671void MCAssembler::FinishLayout(MCAsmLayout &Layout) {
672 // Lower out any instruction fragments, to simplify the fixup application and
673 // output.
674 //
675 // FIXME-PERF: We don't have to do this, but the assumption is that it is
676 // cheap (we will mostly end up eliminating fragments and appending on to data
677 // fragments), so the extra complexity downstream isn't worth it. Evaluate
678 // this assumption.
679 for (iterator it = begin(), ie = end(); it != ie; ++it) {
680 MCSectionData &SD = *it;
681
682 for (MCSectionData::iterator it2 = SD.begin(),
683 ie2 = SD.end(); it2 != ie2; ++it2) {
684 MCInstFragment *IF = dyn_cast<MCInstFragment>(it2);
685 if (!IF)
686 continue;
687
688 // Create a new data fragment for the instruction.
689 //
Daniel Dunbar337055e2010-03-23 03:13:05 +0000690 // FIXME-PERF: Reuse previous data fragment if possible.
Daniel Dunbar3f4dcd92010-03-22 23:16:48 +0000691 MCDataFragment *DF = new MCDataFragment();
692 SD.getFragmentList().insert(it2, DF);
693
694 // Update the data fragments layout data.
Daniel Dunbar9799de92010-03-23 01:39:05 +0000695 DF->setParent(IF->getParent());
Daniel Dunbar3f4dcd92010-03-22 23:16:48 +0000696 DF->setOffset(IF->getOffset());
697 DF->setFileSize(IF->getInstSize());
698
Daniel Dunbar9799de92010-03-23 01:39:05 +0000699 // Copy in the data and the fixups.
700 DF->getContents().append(IF->getCode().begin(), IF->getCode().end());
701 for (unsigned i = 0, e = IF->getFixups().size(); i != e; ++i)
702 DF->getFixups().push_back(IF->getFixups()[i]);
Daniel Dunbar3f4dcd92010-03-22 23:16:48 +0000703
704 // Delete the instruction fragment and update the iterator.
705 SD.getFragmentList().erase(IF);
706 it2 = DF;
707 }
708 }
709}
710
Daniel Dunbarb7c3a4b2010-02-13 09:28:03 +0000711// Debugging methods
712
713namespace llvm {
714
715raw_ostream &operator<<(raw_ostream &OS, const MCAsmFixup &AF) {
Daniel Dunbar2be2fd02010-02-13 09:28:54 +0000716 OS << "<MCAsmFixup" << " Offset:" << AF.Offset << " Value:" << *AF.Value
717 << " Kind:" << AF.Kind << ">";
Daniel Dunbarb7c3a4b2010-02-13 09:28:03 +0000718 return OS;
719}
720
721}
722
723void MCFragment::dump() {
724 raw_ostream &OS = llvm::errs();
725
726 OS << "<MCFragment " << (void*) this << " Offset:" << Offset
727 << " FileSize:" << FileSize;
728
Daniel Dunbarb7c3a4b2010-02-13 09:28:03 +0000729 OS << ">";
730}
731
732void MCAlignFragment::dump() {
733 raw_ostream &OS = llvm::errs();
734
735 OS << "<MCAlignFragment ";
736 this->MCFragment::dump();
737 OS << "\n ";
738 OS << " Alignment:" << getAlignment()
739 << " Value:" << getValue() << " ValueSize:" << getValueSize()
740 << " MaxBytesToEmit:" << getMaxBytesToEmit() << ">";
741}
742
743void MCDataFragment::dump() {
744 raw_ostream &OS = llvm::errs();
745
746 OS << "<MCDataFragment ";
747 this->MCFragment::dump();
748 OS << "\n ";
749 OS << " Contents:[";
750 for (unsigned i = 0, e = getContents().size(); i != e; ++i) {
751 if (i) OS << ",";
752 OS << hexdigit((Contents[i] >> 4) & 0xF) << hexdigit(Contents[i] & 0xF);
753 }
Daniel Dunbar2be2fd02010-02-13 09:28:54 +0000754 OS << "] (" << getContents().size() << " bytes)";
Daniel Dunbar0bcf0742010-02-13 09:28:43 +0000755
756 if (!getFixups().empty()) {
757 OS << ",\n ";
758 OS << " Fixups:[";
759 for (fixup_iterator it = fixup_begin(), ie = fixup_end(); it != ie; ++it) {
Daniel Dunbar45aefff2010-03-09 01:12:23 +0000760 if (it != fixup_begin()) OS << ",\n ";
Daniel Dunbar0bcf0742010-02-13 09:28:43 +0000761 OS << *it;
762 }
763 OS << "]";
764 }
765
766 OS << ">";
Daniel Dunbarb7c3a4b2010-02-13 09:28:03 +0000767}
768
769void MCFillFragment::dump() {
770 raw_ostream &OS = llvm::errs();
771
772 OS << "<MCFillFragment ";
773 this->MCFragment::dump();
774 OS << "\n ";
775 OS << " Value:" << getValue() << " ValueSize:" << getValueSize()
776 << " Count:" << getCount() << ">";
777}
778
Daniel Dunbar3f4dcd92010-03-22 23:16:48 +0000779void MCInstFragment::dump() {
780 raw_ostream &OS = llvm::errs();
781
782 OS << "<MCInstFragment ";
783 this->MCFragment::dump();
784 OS << "\n ";
785 OS << " Inst:";
786 getInst().dump_pretty(OS);
787 OS << ">";
788}
789
Daniel Dunbarb7c3a4b2010-02-13 09:28:03 +0000790void MCOrgFragment::dump() {
791 raw_ostream &OS = llvm::errs();
792
793 OS << "<MCOrgFragment ";
794 this->MCFragment::dump();
795 OS << "\n ";
796 OS << " Offset:" << getOffset() << " Value:" << getValue() << ">";
797}
798
799void MCZeroFillFragment::dump() {
800 raw_ostream &OS = llvm::errs();
801
802 OS << "<MCZeroFillFragment ";
803 this->MCFragment::dump();
804 OS << "\n ";
805 OS << " Size:" << getSize() << " Alignment:" << getAlignment() << ">";
806}
807
808void MCSectionData::dump() {
809 raw_ostream &OS = llvm::errs();
810
811 OS << "<MCSectionData";
812 OS << " Alignment:" << getAlignment() << " Address:" << Address
813 << " Size:" << Size << " FileSize:" << FileSize
Daniel Dunbar45aefff2010-03-09 01:12:23 +0000814 << " Fragments:[\n ";
Daniel Dunbarb7c3a4b2010-02-13 09:28:03 +0000815 for (iterator it = begin(), ie = end(); it != ie; ++it) {
816 if (it != begin()) OS << ",\n ";
817 it->dump();
818 }
819 OS << "]>";
820}
821
822void MCSymbolData::dump() {
823 raw_ostream &OS = llvm::errs();
824
825 OS << "<MCSymbolData Symbol:" << getSymbol()
826 << " Fragment:" << getFragment() << " Offset:" << getOffset()
827 << " Flags:" << getFlags() << " Index:" << getIndex();
828 if (isCommon())
829 OS << " (common, size:" << getCommonSize()
830 << " align: " << getCommonAlignment() << ")";
831 if (isExternal())
832 OS << " (external)";
833 if (isPrivateExtern())
834 OS << " (private extern)";
835 OS << ">";
836}
837
838void MCAssembler::dump() {
839 raw_ostream &OS = llvm::errs();
840
841 OS << "<MCAssembler\n";
Daniel Dunbar45aefff2010-03-09 01:12:23 +0000842 OS << " Sections:[\n ";
Daniel Dunbarb7c3a4b2010-02-13 09:28:03 +0000843 for (iterator it = begin(), ie = end(); it != ie; ++it) {
844 if (it != begin()) OS << ",\n ";
845 it->dump();
846 }
847 OS << "],\n";
848 OS << " Symbols:[";
849
850 for (symbol_iterator it = symbol_begin(), ie = symbol_end(); it != ie; ++it) {
Daniel Dunbar45aefff2010-03-09 01:12:23 +0000851 if (it != symbol_begin()) OS << ",\n ";
Daniel Dunbarb7c3a4b2010-02-13 09:28:03 +0000852 it->dump();
853 }
854 OS << "]>\n";
855}