make SectionForGlobal non-virtual, add a hook for pic16 to do its "address=" hack.
[oota-llvm.git] / lib / Target / PIC16 / PIC16TargetAsmInfo.cpp
index 9adf63a0a97ca3a4bc978e0d0666e86d69bbba70..fedb0b82ca3a290e186d77d8dc9e9f5cf3a14182 100644 (file)
@@ -203,15 +203,13 @@ PIC16TargetAsmInfo::SelectSectionForGlobal(const GlobalValue *GV1) const {
 
   // First, if this is an automatic variable for a function, get the section
   // name for it and return.
-  const std::string name = GV->getName();
-  if (PAN::isLocalName(name)) {
+  std::string name = GV->getName();
+  if (PAN::isLocalName(name))
     return getSectionForAuto(GV);
-  }
 
   // Record Exteranl Var Defs.
-  if (GV->hasExternalLinkage() || GV->hasCommonLinkage()) {
+  if (GV->hasExternalLinkage() || GV->hasCommonLinkage())
     ExternalVarDefs->Items.push_back(GV);
-  }
 
   // See if this is an uninitialized global.
   const Constant *C = GV->getInitializer();
@@ -243,36 +241,34 @@ PIC16TargetAsmInfo::~PIC16TargetAsmInfo() {
   delete ExternalVarDefs;
 }
 
-// Override the default implementation. Create PIC16sections for variables 
-// which have a section name or address.
-const Section* 
-PIC16TargetAsmInfo::SectionForGlobal(const GlobalValue *GV) const {
+
+/// getSpecialCasedSectionGlobals - Allow the target to completely override
+/// section assignment of a global.
+const Section *
+PIC16TargetAsmInfo::getSpecialCasedSectionGlobals(const GlobalValue *GV,
+                                                  SectionKind::Kind Kind) const{
   // If GV has a sectin name or section address create that section now.
   if (GV->hasSection()) {
-    std::string SectName = GV->getSection();
-    // If address for a variable is specified, get the address and create
-    // section.
-    std::string AddrStr = "Address=";
-    if (SectName.compare(0, AddrStr.length(), AddrStr) == 0) {
-      std::string SectAddr = SectName.substr(AddrStr.length());
-      return CreateSectionForGlobal(GV, SectAddr);
+    if (const GlobalVariable *GVar = cast<GlobalVariable>(GV)) {
+      std::string SectName = GVar->getSection();
+      // If address for a variable is specified, get the address and create
+      // section.
+      std::string AddrStr = "Address=";
+      if (SectName.compare(0, AddrStr.length(), AddrStr) == 0) {
+        std::string SectAddr = SectName.substr(AddrStr.length());
+        return CreateSectionForGlobal(GVar, SectAddr);
+      }
     }
   }
-  
-  // Use section depending on the 'type' of variable
-  return SelectSectionForGlobal(GV);
+
+  return 0;
 }
 
 // Create a new section for global variable. If Addr is given then create
 // section at that address else create by name.
 const Section *
-PIC16TargetAsmInfo::CreateSectionForGlobal(const GlobalValue *GV1,
-                                           std::string Addr) const {
-  const GlobalVariable *GV = dyn_cast<GlobalVariable>(GV1);
-
-  if (!GV)
-    return TargetAsmInfo::SectionForGlobal(GV1);
-
+PIC16TargetAsmInfo::CreateSectionForGlobal(const GlobalVariable *GV,
+                                           const std::string &Addr) const {
   // See if this is an uninitialized global.
   const Constant *C = GV->getInitializer();
   if (C->isNullValue())
@@ -310,7 +306,7 @@ PIC16TargetAsmInfo::CreateBSSSectionForGlobal(const GlobalVariable *GV,
       }
     }
   } else {
-    std::string Prefix = GV->getName() + "." + Addr + ".";
+    std::string Prefix = GV->getNameStr() + "." + Addr + ".";
     Name = PAN::getUdataSectionName(BSSSections.size(), Prefix) + " " + Addr;
   }
   
@@ -361,7 +357,7 @@ PIC16TargetAsmInfo::CreateIDATASectionForGlobal(const GlobalVariable *GV,
       }
     }
   } else {
-    std::string Prefix = GV->getName() + "." + Addr + ".";
+    std::string Prefix = GV->getNameStr() + "." + Addr + ".";
     Name = PAN::getIdataSectionName(IDATASections.size(), Prefix) + " " + Addr;
   }
 
@@ -399,7 +395,7 @@ PIC16TargetAsmInfo::CreateROSectionForGlobal(const GlobalVariable *GV,
       }
     }
   } else {
-    std::string Prefix = GV->getName() + "." + Addr + ".";
+    std::string Prefix = GV->getNameStr() + "." + Addr + ".";
     Name = PAN::getRomdataSectionName(ROSections.size(), Prefix) + " " + Addr;
   }