MCAssembler.h revision f08fde41f34d739c157b1d75dadbb864e7957cab
1//===- MCAssembler.h - Object File Generation -------------------*- 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#ifndef LLVM_MC_MCASSEMBLER_H 11#define LLVM_MC_MCASSEMBLER_H 12 13#include "llvm/ADT/DenseMap.h" 14#include "llvm/ADT/SmallString.h" 15#include "llvm/ADT/ilist.h" 16#include "llvm/ADT/ilist_node.h" 17#include "llvm/Support/Casting.h" 18#include "llvm/MC/MCFixup.h" 19#include "llvm/System/DataTypes.h" 20#include <vector> // FIXME: Shouldn't be needed. 21 22namespace llvm { 23class raw_ostream; 24class MCAsmLayout; 25class MCAssembler; 26class MCContext; 27class MCExpr; 28class MCFragment; 29class MCSection; 30class MCSectionData; 31class MCSymbol; 32class MCValue; 33class TargetAsmBackend; 34 35/// MCAsmFixup - Represent a fixed size region of bytes inside some fragment 36/// which needs to be rewritten. This region will either be rewritten by the 37/// assembler or cause a relocation entry to be generated. 38struct MCAsmFixup { 39 /// Offset - The offset inside the fragment which needs to be rewritten. 40 uint64_t Offset; 41 42 /// Value - The expression to eventually write into the fragment. 43 const MCExpr *Value; 44 45 /// Kind - The fixup kind. 46 MCFixupKind Kind; 47 48 /// FixedValue - The value to replace the fix up by. 49 // 50 // FIXME: This should not be here. 51 uint64_t FixedValue; 52 53public: 54 MCAsmFixup(uint64_t _Offset, const MCExpr &_Value, MCFixupKind _Kind) 55 : Offset(_Offset), Value(&_Value), Kind(_Kind), FixedValue(0) {} 56}; 57 58class MCFragment : public ilist_node<MCFragment> { 59 MCFragment(const MCFragment&); // DO NOT IMPLEMENT 60 void operator=(const MCFragment&); // DO NOT IMPLEMENT 61 62public: 63 enum FragmentType { 64 FT_Data, 65 FT_Align, 66 FT_Fill, 67 FT_Org, 68 FT_ZeroFill 69 }; 70 71private: 72 FragmentType Kind; 73 74 /// Parent - The data for the section this fragment is in. 75 MCSectionData *Parent; 76 77 /// @name Assembler Backend Data 78 /// @{ 79 // 80 // FIXME: This could all be kept private to the assembler implementation. 81 82 /// Offset - The offset of this fragment in its section. This is ~0 until 83 /// initialized. 84 uint64_t Offset; 85 86 /// FileSize - The file size of this section. This is ~0 until initialized. 87 uint64_t FileSize; 88 89 /// @} 90 91protected: 92 MCFragment(FragmentType _Kind, MCSectionData *_Parent = 0); 93 94public: 95 // Only for sentinel. 96 MCFragment(); 97 virtual ~MCFragment(); 98 99 FragmentType getKind() const { return Kind; } 100 101 MCSectionData *getParent() const { return Parent; } 102 void setParent(MCSectionData *Value) { Parent = Value; } 103 104 // FIXME: This should be abstract, fix sentinel. 105 virtual uint64_t getMaxFileSize() const { 106 assert(0 && "Invalid getMaxFileSize call!"); 107 return 0; 108 } 109 110 /// @name Assembler Backend Support 111 /// @{ 112 // 113 // FIXME: This could all be kept private to the assembler implementation. 114 115 uint64_t getAddress() const; 116 117 uint64_t getFileSize() const { 118 assert(FileSize != ~UINT64_C(0) && "File size not set!"); 119 return FileSize; 120 } 121 void setFileSize(uint64_t Value) { 122 assert(Value <= getMaxFileSize() && "Invalid file size!"); 123 FileSize = Value; 124 } 125 126 uint64_t getOffset() const { 127 assert(Offset != ~UINT64_C(0) && "File offset not set!"); 128 return Offset; 129 } 130 void setOffset(uint64_t Value) { Offset = Value; } 131 132 /// @} 133 134 static bool classof(const MCFragment *O) { return true; } 135 136 virtual void dump(); 137}; 138 139class MCDataFragment : public MCFragment { 140 SmallString<32> Contents; 141 142 /// Fixups - The list of fixups in this fragment. 143 std::vector<MCAsmFixup> Fixups; 144 145public: 146 typedef std::vector<MCAsmFixup>::const_iterator const_fixup_iterator; 147 typedef std::vector<MCAsmFixup>::iterator fixup_iterator; 148 149public: 150 MCDataFragment(MCSectionData *SD = 0) : MCFragment(FT_Data, SD) {} 151 152 /// @name Accessors 153 /// @{ 154 155 uint64_t getMaxFileSize() const { 156 return Contents.size(); 157 } 158 159 SmallString<32> &getContents() { return Contents; } 160 const SmallString<32> &getContents() const { return Contents; } 161 162 /// @} 163 164 /// @name Fixup Access 165 /// @{ 166 167 void addFixup(MCAsmFixup Fixup) { 168 // Enforce invariant that fixups are in offset order. 169 assert(Fixups.empty() || Fixup.Offset > Fixups.back().Offset && 170 "Fixups must be added in order!"); 171 Fixups.push_back(Fixup); 172 } 173 174 std::vector<MCAsmFixup> &getFixups() { return Fixups; } 175 const std::vector<MCAsmFixup> &getFixups() const { return Fixups; } 176 177 fixup_iterator fixup_begin() { return Fixups.begin(); } 178 const_fixup_iterator fixup_begin() const { return Fixups.begin(); } 179 180 fixup_iterator fixup_end() {return Fixups.end();} 181 const_fixup_iterator fixup_end() const {return Fixups.end();} 182 183 size_t fixup_size() const { return Fixups.size(); } 184 185 /// @} 186 187 static bool classof(const MCFragment *F) { 188 return F->getKind() == MCFragment::FT_Data; 189 } 190 static bool classof(const MCDataFragment *) { return true; } 191 192 virtual void dump(); 193}; 194 195class MCAlignFragment : public MCFragment { 196 /// Alignment - The alignment to ensure, in bytes. 197 unsigned Alignment; 198 199 /// Value - Value to use for filling padding bytes. 200 int64_t Value; 201 202 /// ValueSize - The size of the integer (in bytes) of \arg Value. 203 unsigned ValueSize; 204 205 /// MaxBytesToEmit - The maximum number of bytes to emit; if the alignment 206 /// cannot be satisfied in this width then this fragment is ignored. 207 unsigned MaxBytesToEmit; 208 209 /// EmitNops - true when aligning code and optimal nops to be used for 210 /// filling. 211 bool EmitNops; 212 213public: 214 MCAlignFragment(unsigned _Alignment, int64_t _Value, unsigned _ValueSize, 215 unsigned _MaxBytesToEmit, bool _EmitNops, 216 MCSectionData *SD = 0) 217 : MCFragment(FT_Align, SD), Alignment(_Alignment), 218 Value(_Value),ValueSize(_ValueSize), 219 MaxBytesToEmit(_MaxBytesToEmit), EmitNops(_EmitNops) {} 220 221 /// @name Accessors 222 /// @{ 223 224 uint64_t getMaxFileSize() const { 225 return std::max(Alignment - 1, MaxBytesToEmit); 226 } 227 228 unsigned getAlignment() const { return Alignment; } 229 230 int64_t getValue() const { return Value; } 231 232 unsigned getValueSize() const { return ValueSize; } 233 234 unsigned getMaxBytesToEmit() const { return MaxBytesToEmit; } 235 236 unsigned getEmitNops() const { return EmitNops; } 237 238 /// @} 239 240 static bool classof(const MCFragment *F) { 241 return F->getKind() == MCFragment::FT_Align; 242 } 243 static bool classof(const MCAlignFragment *) { return true; } 244 245 virtual void dump(); 246}; 247 248class MCFillFragment : public MCFragment { 249 /// Value - Value to use for filling bytes. 250 int64_t Value; 251 252 /// ValueSize - The size (in bytes) of \arg Value to use when filling. 253 unsigned ValueSize; 254 255 /// Count - The number of copies of \arg Value to insert. 256 uint64_t Count; 257 258public: 259 MCFillFragment(int64_t _Value, unsigned _ValueSize, uint64_t _Count, 260 MCSectionData *SD = 0) 261 : MCFragment(FT_Fill, SD), 262 Value(_Value), ValueSize(_ValueSize), Count(_Count) {} 263 264 /// @name Accessors 265 /// @{ 266 267 uint64_t getMaxFileSize() const { 268 return ValueSize * Count; 269 } 270 271 int64_t getValue() const { return Value; } 272 273 unsigned getValueSize() const { return ValueSize; } 274 275 uint64_t getCount() const { return Count; } 276 277 /// @} 278 279 static bool classof(const MCFragment *F) { 280 return F->getKind() == MCFragment::FT_Fill; 281 } 282 static bool classof(const MCFillFragment *) { return true; } 283 284 virtual void dump(); 285}; 286 287class MCOrgFragment : public MCFragment { 288 /// Offset - The offset this fragment should start at. 289 const MCExpr *Offset; 290 291 /// Value - Value to use for filling bytes. 292 int8_t Value; 293 294public: 295 MCOrgFragment(const MCExpr &_Offset, int8_t _Value, MCSectionData *SD = 0) 296 : MCFragment(FT_Org, SD), 297 Offset(&_Offset), Value(_Value) {} 298 299 /// @name Accessors 300 /// @{ 301 302 uint64_t getMaxFileSize() const { 303 // FIXME: This doesn't make much sense. 304 return ~UINT64_C(0); 305 } 306 307 const MCExpr &getOffset() const { return *Offset; } 308 309 uint8_t getValue() const { return Value; } 310 311 /// @} 312 313 static bool classof(const MCFragment *F) { 314 return F->getKind() == MCFragment::FT_Org; 315 } 316 static bool classof(const MCOrgFragment *) { return true; } 317 318 virtual void dump(); 319}; 320 321/// MCZeroFillFragment - Represent data which has a fixed size and alignment, 322/// but requires no physical space in the object file. 323class MCZeroFillFragment : public MCFragment { 324 /// Size - The size of this fragment. 325 uint64_t Size; 326 327 /// Alignment - The alignment for this fragment. 328 unsigned Alignment; 329 330public: 331 MCZeroFillFragment(uint64_t _Size, unsigned _Alignment, MCSectionData *SD = 0) 332 : MCFragment(FT_ZeroFill, SD), 333 Size(_Size), Alignment(_Alignment) {} 334 335 /// @name Accessors 336 /// @{ 337 338 uint64_t getMaxFileSize() const { 339 // FIXME: This also doesn't make much sense, this method is misnamed. 340 return ~UINT64_C(0); 341 } 342 343 uint64_t getSize() const { return Size; } 344 345 unsigned getAlignment() const { return Alignment; } 346 347 /// @} 348 349 static bool classof(const MCFragment *F) { 350 return F->getKind() == MCFragment::FT_ZeroFill; 351 } 352 static bool classof(const MCZeroFillFragment *) { return true; } 353 354 virtual void dump(); 355}; 356 357// FIXME: Should this be a separate class, or just merged into MCSection? Since 358// we anticipate the fast path being through an MCAssembler, the only reason to 359// keep it out is for API abstraction. 360class MCSectionData : public ilist_node<MCSectionData> { 361 MCSectionData(const MCSectionData&); // DO NOT IMPLEMENT 362 void operator=(const MCSectionData&); // DO NOT IMPLEMENT 363 364public: 365 typedef iplist<MCFragment> FragmentListType; 366 367 typedef FragmentListType::const_iterator const_iterator; 368 typedef FragmentListType::iterator iterator; 369 370 typedef FragmentListType::const_reverse_iterator const_reverse_iterator; 371 typedef FragmentListType::reverse_iterator reverse_iterator; 372 373private: 374 iplist<MCFragment> Fragments; 375 const MCSection *Section; 376 377 /// Alignment - The maximum alignment seen in this section. 378 unsigned Alignment; 379 380 /// @name Assembler Backend Data 381 /// @{ 382 // 383 // FIXME: This could all be kept private to the assembler implementation. 384 385 /// Address - The computed address of this section. This is ~0 until 386 /// initialized. 387 uint64_t Address; 388 389 /// Size - The content size of this section. This is ~0 until initialized. 390 uint64_t Size; 391 392 /// FileSize - The size of this section in the object file. This is ~0 until 393 /// initialized. 394 uint64_t FileSize; 395 396 /// HasInstructions - Whether this section has had instructions emitted into 397 /// it. 398 unsigned HasInstructions : 1; 399 400 /// @} 401 402public: 403 // Only for use as sentinel. 404 MCSectionData(); 405 MCSectionData(const MCSection &Section, MCAssembler *A = 0); 406 407 const MCSection &getSection() const { return *Section; } 408 409 unsigned getAlignment() const { return Alignment; } 410 void setAlignment(unsigned Value) { Alignment = Value; } 411 412 /// @name Fragment Access 413 /// @{ 414 415 const FragmentListType &getFragmentList() const { return Fragments; } 416 FragmentListType &getFragmentList() { return Fragments; } 417 418 iterator begin() { return Fragments.begin(); } 419 const_iterator begin() const { return Fragments.begin(); } 420 421 iterator end() { return Fragments.end(); } 422 const_iterator end() const { return Fragments.end(); } 423 424 reverse_iterator rbegin() { return Fragments.rbegin(); } 425 const_reverse_iterator rbegin() const { return Fragments.rbegin(); } 426 427 reverse_iterator rend() { return Fragments.rend(); } 428 const_reverse_iterator rend() const { return Fragments.rend(); } 429 430 size_t size() const { return Fragments.size(); } 431 432 bool empty() const { return Fragments.empty(); } 433 434 /// @} 435 /// @name Assembler Backend Support 436 /// @{ 437 // 438 // FIXME: This could all be kept private to the assembler implementation. 439 440 uint64_t getAddress() const { 441 assert(Address != ~UINT64_C(0) && "Address not set!"); 442 return Address; 443 } 444 void setAddress(uint64_t Value) { Address = Value; } 445 446 uint64_t getSize() const { 447 assert(Size != ~UINT64_C(0) && "File size not set!"); 448 return Size; 449 } 450 void setSize(uint64_t Value) { Size = Value; } 451 452 uint64_t getFileSize() const { 453 assert(FileSize != ~UINT64_C(0) && "File size not set!"); 454 return FileSize; 455 } 456 void setFileSize(uint64_t Value) { FileSize = Value; } 457 458 bool hasInstructions() const { return HasInstructions; } 459 void setHasInstructions(bool Value) { HasInstructions = Value; } 460 461 /// @} 462 463 void dump(); 464}; 465 466// FIXME: Same concerns as with SectionData. 467class MCSymbolData : public ilist_node<MCSymbolData> { 468public: 469 const MCSymbol *Symbol; 470 471 /// Fragment - The fragment this symbol's value is relative to, if any. 472 MCFragment *Fragment; 473 474 /// Offset - The offset to apply to the fragment address to form this symbol's 475 /// value. 476 uint64_t Offset; 477 478 /// IsExternal - True if this symbol is visible outside this translation 479 /// unit. 480 unsigned IsExternal : 1; 481 482 /// IsPrivateExtern - True if this symbol is private extern. 483 unsigned IsPrivateExtern : 1; 484 485 /// CommonSize - The size of the symbol, if it is 'common', or 0. 486 // 487 // FIXME: Pack this in with other fields? We could put it in offset, since a 488 // common symbol can never get a definition. 489 uint64_t CommonSize; 490 491 /// CommonAlign - The alignment of the symbol, if it is 'common'. 492 // 493 // FIXME: Pack this in with other fields? 494 unsigned CommonAlign; 495 496 /// Flags - The Flags field is used by object file implementations to store 497 /// additional per symbol information which is not easily classified. 498 uint32_t Flags; 499 500 /// Index - Index field, for use by the object file implementation. 501 uint64_t Index; 502 503public: 504 // Only for use as sentinel. 505 MCSymbolData(); 506 MCSymbolData(const MCSymbol &_Symbol, MCFragment *_Fragment, uint64_t _Offset, 507 MCAssembler *A = 0); 508 509 /// @name Accessors 510 /// @{ 511 512 const MCSymbol &getSymbol() const { return *Symbol; } 513 514 MCFragment *getFragment() const { return Fragment; } 515 void setFragment(MCFragment *Value) { Fragment = Value; } 516 517 uint64_t getOffset() const { return Offset; } 518 void setOffset(uint64_t Value) { Offset = Value; } 519 520 uint64_t getAddress() const { 521 assert(getFragment() && "Invalid getAddress() on undefined symbol!"); 522 return getFragment()->getAddress() + getOffset(); 523 } 524 525 /// @} 526 /// @name Symbol Attributes 527 /// @{ 528 529 bool isExternal() const { return IsExternal; } 530 void setExternal(bool Value) { IsExternal = Value; } 531 532 bool isPrivateExtern() const { return IsPrivateExtern; } 533 void setPrivateExtern(bool Value) { IsPrivateExtern = Value; } 534 535 /// isCommon - Is this a 'common' symbol. 536 bool isCommon() const { return CommonSize != 0; } 537 538 /// setCommon - Mark this symbol as being 'common'. 539 /// 540 /// \param Size - The size of the symbol. 541 /// \param Align - The alignment of the symbol. 542 void setCommon(uint64_t Size, unsigned Align) { 543 CommonSize = Size; 544 CommonAlign = Align; 545 } 546 547 /// getCommonSize - Return the size of a 'common' symbol. 548 uint64_t getCommonSize() const { 549 assert(isCommon() && "Not a 'common' symbol!"); 550 return CommonSize; 551 } 552 553 /// getCommonAlignment - Return the alignment of a 'common' symbol. 554 unsigned getCommonAlignment() const { 555 assert(isCommon() && "Not a 'common' symbol!"); 556 return CommonAlign; 557 } 558 559 /// getFlags - Get the (implementation defined) symbol flags. 560 uint32_t getFlags() const { return Flags; } 561 562 /// setFlags - Set the (implementation defined) symbol flags. 563 void setFlags(uint32_t Value) { Flags = Value; } 564 565 /// getIndex - Get the (implementation defined) index. 566 uint64_t getIndex() const { return Index; } 567 568 /// setIndex - Set the (implementation defined) index. 569 void setIndex(uint64_t Value) { Index = Value; } 570 571 /// @} 572 573 void dump(); 574}; 575 576// FIXME: This really doesn't belong here. See comments below. 577struct IndirectSymbolData { 578 MCSymbol *Symbol; 579 MCSectionData *SectionData; 580}; 581 582class MCAssembler { 583public: 584 typedef iplist<MCSectionData> SectionDataListType; 585 typedef iplist<MCSymbolData> SymbolDataListType; 586 587 typedef SectionDataListType::const_iterator const_iterator; 588 typedef SectionDataListType::iterator iterator; 589 590 typedef SymbolDataListType::const_iterator const_symbol_iterator; 591 typedef SymbolDataListType::iterator symbol_iterator; 592 593 typedef std::vector<IndirectSymbolData>::iterator indirect_symbol_iterator; 594 595private: 596 MCAssembler(const MCAssembler&); // DO NOT IMPLEMENT 597 void operator=(const MCAssembler&); // DO NOT IMPLEMENT 598 599 MCContext &Context; 600 601 TargetAsmBackend &Backend; 602 603 raw_ostream &OS; 604 605 iplist<MCSectionData> Sections; 606 607 iplist<MCSymbolData> Symbols; 608 609 /// The map of sections to their associated assembler backend data. 610 // 611 // FIXME: Avoid this indirection? 612 DenseMap<const MCSection*, MCSectionData*> SectionMap; 613 614 /// The map of symbols to their associated assembler backend data. 615 // 616 // FIXME: Avoid this indirection? 617 DenseMap<const MCSymbol*, MCSymbolData*> SymbolMap; 618 619 std::vector<IndirectSymbolData> IndirectSymbols; 620 621 unsigned SubsectionsViaSymbols : 1; 622 623private: 624 /// Check whether a fixup can be satisfied, or whether it needs to be relaxed 625 /// (increased in size, in order to hold its value correctly). 626 bool FixupNeedsRelaxation(MCAsmFixup &Fixup, MCDataFragment *DF); 627 628 /// LayoutSection - Assign offsets and sizes to the fragments in the section 629 /// \arg SD, and update the section size. The section file offset should 630 /// already have been computed. 631 void LayoutSection(MCSectionData &SD); 632 633 /// LayoutOnce - Perform one layout iteration and return true if any offsets 634 /// were adjusted. 635 bool LayoutOnce(); 636 637 // FIXME: Make protected once we factor out object writer classes. 638public: 639 /// Evaluate a fixup to a relocatable expression and the value which should be 640 /// placed into the fixup. 641 /// 642 /// \param Layout The layout to use for evaluation. 643 /// \param Fixup The fixup to evaluate. 644 /// \param DF The fragment the fixup is inside. 645 /// \param Target [out] On return, the relocatable expression the fixup 646 /// evaluates to. 647 /// \param Value [out] On return, the value of the fixup as currently layed 648 /// out. 649 /// \return Whether the fixup value was fully resolved. This is true if the 650 /// \arg Value result is fixed, otherwise the value may change due to 651 /// relocation. 652 bool EvaluateFixup(const MCAsmLayout &Layout, 653 MCAsmFixup &Fixup, MCDataFragment *DF, 654 MCValue &Target, uint64_t &Value) const; 655 656public: 657 /// Construct a new assembler instance. 658 /// 659 /// \arg OS - The stream to output to. 660 // 661 // FIXME: How are we going to parameterize this? Two obvious options are stay 662 // concrete and require clients to pass in a target like object. The other 663 // option is to make this abstract, and have targets provide concrete 664 // implementations as we do with AsmParser. 665 MCAssembler(MCContext &_Context, TargetAsmBackend &_Backend, raw_ostream &OS); 666 ~MCAssembler(); 667 668 MCContext &getContext() const { return Context; } 669 670 TargetAsmBackend &getBackend() const { return Backend; } 671 672 /// Finish - Do final processing and write the object to the output stream. 673 void Finish(); 674 675 // FIXME: This does not belong here. 676 bool getSubsectionsViaSymbols() const { 677 return SubsectionsViaSymbols; 678 } 679 void setSubsectionsViaSymbols(bool Value) { 680 SubsectionsViaSymbols = Value; 681 } 682 683 /// @name Section List Access 684 /// @{ 685 686 const SectionDataListType &getSectionList() const { return Sections; } 687 SectionDataListType &getSectionList() { return Sections; } 688 689 iterator begin() { return Sections.begin(); } 690 const_iterator begin() const { return Sections.begin(); } 691 692 iterator end() { return Sections.end(); } 693 const_iterator end() const { return Sections.end(); } 694 695 size_t size() const { return Sections.size(); } 696 697 /// @} 698 /// @name Symbol List Access 699 /// @{ 700 701 const SymbolDataListType &getSymbolList() const { return Symbols; } 702 SymbolDataListType &getSymbolList() { return Symbols; } 703 704 symbol_iterator symbol_begin() { return Symbols.begin(); } 705 const_symbol_iterator symbol_begin() const { return Symbols.begin(); } 706 707 symbol_iterator symbol_end() { return Symbols.end(); } 708 const_symbol_iterator symbol_end() const { return Symbols.end(); } 709 710 size_t symbol_size() const { return Symbols.size(); } 711 712 /// @} 713 /// @name Indirect Symbol List Access 714 /// @{ 715 716 // FIXME: This is a total hack, this should not be here. Once things are 717 // factored so that the streamer has direct access to the .o writer, it can 718 // disappear. 719 std::vector<IndirectSymbolData> &getIndirectSymbols() { 720 return IndirectSymbols; 721 } 722 723 indirect_symbol_iterator indirect_symbol_begin() { 724 return IndirectSymbols.begin(); 725 } 726 727 indirect_symbol_iterator indirect_symbol_end() { 728 return IndirectSymbols.end(); 729 } 730 731 size_t indirect_symbol_size() const { return IndirectSymbols.size(); } 732 733 /// @} 734 /// @name Backend Data Access 735 /// @{ 736 737 MCSectionData &getSectionData(const MCSection &Section) const { 738 MCSectionData *Entry = SectionMap.lookup(&Section); 739 assert(Entry && "Missing section data!"); 740 return *Entry; 741 } 742 743 MCSectionData &getOrCreateSectionData(const MCSection &Section, 744 bool *Created = 0) { 745 MCSectionData *&Entry = SectionMap[&Section]; 746 747 if (Created) *Created = !Entry; 748 if (!Entry) 749 Entry = new MCSectionData(Section, this); 750 751 return *Entry; 752 } 753 754 MCSymbolData &getSymbolData(const MCSymbol &Symbol) const { 755 MCSymbolData *Entry = SymbolMap.lookup(&Symbol); 756 assert(Entry && "Missing symbol data!"); 757 return *Entry; 758 } 759 760 MCSymbolData &getOrCreateSymbolData(const MCSymbol &Symbol, 761 bool *Created = 0) { 762 MCSymbolData *&Entry = SymbolMap[&Symbol]; 763 764 if (Created) *Created = !Entry; 765 if (!Entry) 766 Entry = new MCSymbolData(Symbol, 0, 0, this); 767 768 return *Entry; 769 } 770 771 /// @} 772 773 void dump(); 774}; 775 776} // end namespace llvm 777 778#endif 779