create sections with MCSection::Create instead of Context->getOrCreateSection.
This is needed to allow polymorphic sections.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@77680 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/MC/MCContext.cpp b/lib/MC/MCContext.cpp
index 6c74dcd..5f3f125 100644
--- a/lib/MC/MCContext.cpp
+++ b/lib/MC/MCContext.cpp
@@ -14,22 +14,29 @@
#include "llvm/MC/MCValue.h"
using namespace llvm;
-MCContext::MCContext()
-{
+MCContext::MCContext() {
}
MCContext::~MCContext() {
}
-MCSection *MCContext::GetSection(const StringRef &Name) {
- MCSection *&Entry = Sections[Name];
-
- if (!Entry)
- Entry = new (*this) MCSection(Name);
-
- return Entry;
+MCSection *MCContext::GetSection(const StringRef &Name) const {
+ StringMap<MCSection*>::const_iterator I = Sections.find(Name);
+ return I != Sections.end() ? I->second : 0;
}
+
+MCSection::MCSection(const StringRef &_Name, MCContext &Ctx) : Name(_Name) {
+ MCSection *&Entry = Ctx.Sections[Name];
+ assert(Entry == 0 && "Multiple sections with the same name created");
+ Entry = this;
+}
+
+MCSection *MCSection::Create(const StringRef &Name, MCContext &Ctx) {
+ return new (Ctx) MCSection(Name, Ctx);
+}
+
+
MCSymbol *MCContext::CreateSymbol(const StringRef &Name) {
assert(Name[0] != '\0' && "Normal symbols cannot be unnamed!");