diff options
Diffstat (limited to 'lib/MC/MCContext.cpp')
-rw-r--r-- | lib/MC/MCContext.cpp | 62 |
1 files changed, 43 insertions, 19 deletions
diff --git a/lib/MC/MCContext.cpp b/lib/MC/MCContext.cpp index 6e4d82b..3b45d16 100644 --- a/lib/MC/MCContext.cpp +++ b/lib/MC/MCContext.cpp @@ -25,12 +25,16 @@ #include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/Signals.h" #include "llvm/Support/SourceMgr.h" + +#include <map> + using namespace llvm; -typedef StringMap<const MCSectionMachO*> MachOUniqueMapTy; -typedef StringMap<const MCSectionELF*> ELFUniqueMapTy; -typedef StringMap<const MCSectionCOFF*> COFFUniqueMapTy; +typedef std::pair<std::string, std::string> SectionGroupPair; +typedef StringMap<const MCSectionMachO*> MachOUniqueMapTy; +typedef std::map<SectionGroupPair, const MCSectionELF *> ELFUniqueMapTy; +typedef std::map<SectionGroupPair, const MCSectionCOFF *> COFFUniqueMapTy; MCContext::MCContext(const MCAsmInfo *mai, const MCRegisterInfo *mri, const MCObjectFileInfo *mofi, const SourceMgr *mgr, @@ -249,8 +253,9 @@ getELFSection(StringRef Section, unsigned Type, unsigned Flags, ELFUniqueMapTy &Map = *(ELFUniqueMapTy*)ELFUniquingMap; // Do the lookup, if we have a hit, return it. - StringMapEntry<const MCSectionELF*> &Entry = Map.GetOrCreateValue(Section); - if (Entry.getValue()) return Entry.getValue(); + std::pair<ELFUniqueMapTy::iterator, bool> Entry = Map.insert( + std::make_pair(SectionGroupPair(Section, Group), (MCSectionELF *)0)); + if (!Entry.second) return Entry.first->second; // Possibly refine the entry size first. if (!EntrySize) { @@ -261,9 +266,9 @@ getELFSection(StringRef Section, unsigned Type, unsigned Flags, if (!Group.empty()) GroupSym = GetOrCreateSymbol(Group); - MCSectionELF *Result = new (*this) MCSectionELF(Entry.getKey(), Type, Flags, - Kind, EntrySize, GroupSym); - Entry.setValue(Result); + MCSectionELF *Result = new (*this) MCSectionELF( + Entry.first->first.first, Type, Flags, Kind, EntrySize, GroupSym); + Entry.first->second = Result; return Result; } @@ -274,32 +279,51 @@ const MCSectionELF *MCContext::CreateELFGroupSection() { return Result; } -const MCSectionCOFF *MCContext::getCOFFSection(StringRef Section, - unsigned Characteristics, - SectionKind Kind, int Selection, - const MCSectionCOFF *Assoc) { +const MCSectionCOFF * +MCContext::getCOFFSection(StringRef Section, unsigned Characteristics, + SectionKind Kind, StringRef COMDATSymName, + int Selection, const MCSectionCOFF *Assoc) { if (COFFUniquingMap == 0) COFFUniquingMap = new COFFUniqueMapTy(); COFFUniqueMapTy &Map = *(COFFUniqueMapTy*)COFFUniquingMap; // Do the lookup, if we have a hit, return it. - StringMapEntry<const MCSectionCOFF*> &Entry = Map.GetOrCreateValue(Section); - if (Entry.getValue()) return Entry.getValue(); - MCSectionCOFF *Result = new (*this) MCSectionCOFF(Entry.getKey(), - Characteristics, - Selection, Assoc, Kind); + SectionGroupPair P(Section, COMDATSymName); + std::pair<COFFUniqueMapTy::iterator, bool> Entry = + Map.insert(std::make_pair(P, (MCSectionCOFF *)0)); + COFFUniqueMapTy::iterator Iter = Entry.first; + if (!Entry.second) + return Iter->second; - Entry.setValue(Result); + const MCSymbol *COMDATSymbol = NULL; + if (!COMDATSymName.empty()) + COMDATSymbol = GetOrCreateSymbol(COMDATSymName); + + MCSectionCOFF *Result = + new (*this) MCSectionCOFF(Iter->first.first, Characteristics, + COMDATSymbol, Selection, Assoc, Kind); + + Iter->second = Result; return Result; } +const MCSectionCOFF * +MCContext::getCOFFSection(StringRef Section, unsigned Characteristics, + SectionKind Kind) { + return getCOFFSection(Section, Characteristics, Kind, "", 0); +} + const MCSectionCOFF *MCContext::getCOFFSection(StringRef Section) { if (COFFUniquingMap == 0) COFFUniquingMap = new COFFUniqueMapTy(); COFFUniqueMapTy &Map = *(COFFUniqueMapTy*)COFFUniquingMap; - return Map.lookup(Section); + SectionGroupPair P(Section, ""); + COFFUniqueMapTy::iterator Iter = Map.find(P); + if (Iter == Map.end()) + return 0; + return Iter->second; } //===----------------------------------------------------------------------===// |