diff options
author | Chris Lattner <sabre@nondot.org> | 2010-04-08 20:30:37 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2010-04-08 20:30:37 +0000 |
commit | f0559e4b242e85d4b9d1dd08758814c599bdce13 (patch) | |
tree | 34a32e10829a20b60ac0167daabec94e2bb351d5 /lib/MC/MCContext.cpp | |
parent | a57fabe815ccf016eead526eb3ef475f116ab155 (diff) |
move macho section uniquing from MCParser and TLOF to MCContext where
the compiler and asmparser now unique to the same sections. This fixes
rdar://7835021.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@100807 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/MC/MCContext.cpp')
-rw-r--r-- | lib/MC/MCContext.cpp | 48 |
1 files changed, 46 insertions, 2 deletions
diff --git a/lib/MC/MCContext.cpp b/lib/MC/MCContext.cpp index e02cbc7462..6a6841a48d 100644 --- a/lib/MC/MCContext.cpp +++ b/lib/MC/MCContext.cpp @@ -9,20 +9,31 @@ #include "llvm/MC/MCContext.h" #include "llvm/MC/MCAsmInfo.h" -#include "llvm/MC/MCSection.h" +#include "llvm/MC/MCSectionMachO.h" #include "llvm/MC/MCSymbol.h" #include "llvm/ADT/SmallString.h" #include "llvm/ADT/Twine.h" using namespace llvm; +typedef StringMap<const MCSectionMachO*> MachOUniqueMapTy; + + MCContext::MCContext(const MCAsmInfo &mai) : MAI(mai), NextUniqueID(0) { + MachOUniquingMap = 0; } MCContext::~MCContext() { - // NOTE: The sections are all allocated out of a bump pointer allocator, + // NOTE: The symbols are all allocated out of a bump pointer allocator, // we don't need to free them here. + + // If we have the MachO uniquing map, free it. + delete (MachOUniqueMapTy*)MachOUniquingMap; } +//===----------------------------------------------------------------------===// +// Symbol Manipulation +//===----------------------------------------------------------------------===// + MCSymbol *MCContext::GetOrCreateSymbol(StringRef Name) { assert(!Name.empty() && "Normal symbols cannot be unnamed!"); @@ -55,3 +66,36 @@ MCSymbol *MCContext::CreateTempSymbol() { MCSymbol *MCContext::LookupSymbol(StringRef Name) const { return Symbols.lookup(Name); } + +//===----------------------------------------------------------------------===// +// Section Management +//===----------------------------------------------------------------------===// + +const MCSectionMachO *MCContext:: +getMachOSection(StringRef Segment, StringRef Section, + unsigned TypeAndAttributes, + unsigned Reserved2, SectionKind Kind) { + + // We unique sections by their segment/section pair. The returned section + // may not have the same flags as the requested section, if so this should be + // diagnosed by the client as an error. + + // Create the map if it doesn't already exist. + if (MachOUniquingMap == 0) + MachOUniquingMap = new MachOUniqueMapTy(); + MachOUniqueMapTy &Map = *(MachOUniqueMapTy*)MachOUniquingMap; + + // Form the name to look up. + SmallString<64> Name; + Name += Segment; + Name.push_back(','); + Name += Section; + + // Do the lookup, if we have a hit, return it. + const MCSectionMachO *&Entry = Map[Name.str()]; + if (Entry) return Entry; + + // Otherwise, return a new section. + return Entry = MCSectionMachO::Create(Segment, Section, TypeAndAttributes, + Reserved2, Kind, *this); +} |