[llvm-commits] [llvm] r77680 - in /llvm/trunk: include/llvm/MC/MCContext.h include/llvm/MC/MCSection.h lib/MC/MCContext.cpp

Chris Lattner sabre at nondot.org
Fri Jul 31 09:43:50 PDT 2009


Author: lattner
Date: Fri Jul 31 11:43:49 2009
New Revision: 77680

URL: http://llvm.org/viewvc/llvm-project?rev=77680&view=rev
Log:
create sections with MCSection::Create instead of Context->getOrCreateSection.
This is needed to allow polymorphic sections.

Modified:
    llvm/trunk/include/llvm/MC/MCContext.h
    llvm/trunk/include/llvm/MC/MCSection.h
    llvm/trunk/lib/MC/MCContext.cpp

Modified: llvm/trunk/include/llvm/MC/MCContext.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCContext.h?rev=77680&r1=77679&r2=77680&view=diff

==============================================================================
--- llvm/trunk/include/llvm/MC/MCContext.h (original)
+++ llvm/trunk/include/llvm/MC/MCContext.h Fri Jul 31 11:43:49 2009
@@ -42,12 +42,14 @@
     /// objects.
     BumpPtrAllocator Allocator;
 
+    friend class MCSection;
   public:
     MCContext();
     ~MCContext();
 
-    /// GetSection - Get or create a new section with the given @param Name.
-    MCSection *GetSection(const StringRef &Name);
+    /// GetSection - Look up a section with the given @param Name, returning
+    /// null if it doesn't exist.
+    MCSection *GetSection(const StringRef &Name) const;
     
     /// CreateSymbol - Create a new symbol with the specified @param Name.
     ///

Modified: llvm/trunk/include/llvm/MC/MCSection.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCSection.h?rev=77680&r1=77679&r2=77680&view=diff

==============================================================================
--- llvm/trunk/include/llvm/MC/MCSection.h (original)
+++ llvm/trunk/include/llvm/MC/MCSection.h Fri Jul 31 11:43:49 2009
@@ -25,13 +25,13 @@
   class MCSection {
     std::string Name;
   private:
-    friend class MCContext;
-    MCSection(const StringRef &_Name) : Name(_Name) {}
-    
     MCSection(const MCSection&);      // DO NOT IMPLEMENT
     void operator=(const MCSection&); // DO NOT IMPLEMENT
+    MCSection(const StringRef &_Name, MCContext &Ctx);
   public:
 
+    static MCSection *Create(const StringRef &_Name, MCContext &Ctx);
+    
     const std::string &getName() const { return Name; }
   };
 

Modified: llvm/trunk/lib/MC/MCContext.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCContext.cpp?rev=77680&r1=77679&r2=77680&view=diff

==============================================================================
--- llvm/trunk/lib/MC/MCContext.cpp (original)
+++ llvm/trunk/lib/MC/MCContext.cpp Fri Jul 31 11:43:49 2009
@@ -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);
+MCSection *MCContext::GetSection(const StringRef &Name) const {
+  StringMap<MCSection*>::const_iterator I = Sections.find(Name);
+  return I != Sections.end() ? I->second : 0;
+}
+
 
-  return Entry;
+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!");
 





More information about the llvm-commits mailing list