delete the fixme too! :)
[oota-llvm.git] / lib / Target / PIC16 / PIC16TargetObjectFile.cpp
index b3c435e85c7ae7293ab95a819af70000cb9b9437..a2a4c09d29781a849b2ccded48c3af46d61c0a2a 100644 (file)
 using namespace llvm;
 
 
-MCSectionPIC16 *MCSectionPIC16::Create(const StringRef &Name, 
-                                       SectionKind K, MCContext &Ctx) {
-  return new (Ctx) MCSectionPIC16(Name, K);
+MCSectionPIC16 *MCSectionPIC16::Create(const StringRef &Name, SectionKind K, 
+                                       int Address, int Color, MCContext &Ctx) {
+  return new (Ctx) MCSectionPIC16(Name, K, Address, Color);
 }
 
 
-void MCSectionPIC16::PrintSwitchToSection(const TargetAsmInfo &TAI,
+void MCSectionPIC16::PrintSwitchToSection(const MCAsmInfo &MAI,
                                           raw_ostream &OS) const {
   OS << getName() << '\n';
 }
@@ -38,12 +38,14 @@ PIC16TargetObjectFile::PIC16TargetObjectFile()
 }
 
 const MCSectionPIC16 *PIC16TargetObjectFile::
-getPIC16Section(const char *Name, SectionKind Kind) const {
+getPIC16Section(const char *Name, SectionKind Kind, 
+                int Address, int Color) const {
   MCSectionPIC16 *&Entry = SectionsByName[Name];
   if (Entry)
     return Entry;
 
-  return Entry = MCSectionPIC16::Create(Name, Kind, getContext());
+  return Entry = MCSectionPIC16::Create(Name, Kind, Address, Color, 
+                                        getContext());
 }
 
 
@@ -51,10 +53,10 @@ void PIC16TargetObjectFile::Initialize(MCContext &Ctx, const TargetMachine &tm){
   TargetLoweringObjectFile::Initialize(Ctx, tm);
   TM = &tm;
   
-  BSSSection = getPIC16Section("udata.# UDATA", SectionKind::getBSS());
+  BSSSection = getPIC16Section("udata.# UDATA", MCSectionPIC16::UDATA_Kind());
   ReadOnlySection = getPIC16Section("romdata.# ROMDATA", 
-                                    SectionKind::getReadOnly());
-  DataSection = getPIC16Section("idata.# IDATA", SectionKind::getDataRel());
+                                    MCSectionPIC16::ROMDATA_Kind());
+  DataSection = getPIC16Section("idata.# IDATA", MCSectionPIC16::IDATA_Kind());
   
   // Need because otherwise a .text symbol is emitted by DwarfWriter
   // in BeginModule, and gpasm cribbs for that .text symbol.
@@ -63,6 +65,8 @@ void PIC16TargetObjectFile::Initialize(MCContext &Ctx, const TargetMachine &tm){
   ROSections.push_back(new PIC16Section((MCSectionPIC16*)ReadOnlySection));
   
   // FIXME: I don't know what the classification of these sections really is.
+  // These aren't really objects belonging to any section. Just emit them
+  // in AsmPrinter and remove this code from here. 
   ExternalVarDecls = new PIC16Section(getPIC16Section("ExternalVarDecls",
                                       SectionKind::getMetadata()));
   ExternalVarDefs = new PIC16Section(getPIC16Section("ExternalVarDefs",
@@ -70,8 +74,8 @@ void PIC16TargetObjectFile::Initialize(MCContext &Ctx, const TargetMachine &tm){
 }
 
 const MCSection *PIC16TargetObjectFile::
-getSectionForFunction(const std::string &FnName, bool isInterrupt) const {
-  std::string T = PAN::getCodeSectionName(FnName, isInterrupt);
+getSectionForFunction(const std::string &FnName) const {
+  std::string T = PAN::getCodeSectionName(FnName);
   return getPIC16Section(T.c_str(), SectionKind::getText());
 }
 
@@ -82,35 +86,6 @@ getSectionForFunctionFrame(const std::string &FnName) const {
   return getPIC16Section(T.c_str(), SectionKind::getDataRel());
 }
 
-std::string PIC16TargetObjectFile::getNameForFunctFrame(const Function *F,
-                                                          bool IsAutosSection) {
-  std::string SectionName = F->getName();
-  if (F->hasSection()) {
-    std::string Sectn = F->getSection();
-    std::string StrToFind = "Overlay=";
-    size_t Pos = Sectn.find(StrToFind);
-    if (Pos != std::string::npos) {
-      Pos += StrToFind.length();
-      std::string Color = "";
-      char c = Sectn.at(Pos);
-      // A Color can only consist on upper case letters or underscore.
-      while ((c >= 'A' && c<= 'Z') || c == '_') {
-        Color.append(1,c);
-        Pos++;
-        if (Pos >= Sectn.length())
-          break;
-        c = Sectn.at(Pos);
-      }
-      // Autos Section need to be given a different name from function frame. 
-      if (IsAutosSection)
-        SectionName = PAN::getAutosSectionForColor(Color);
-      else
-        SectionName = Color;
-    }
-  }
-  return SectionName;
-}
-
 const MCSection *
 PIC16TargetObjectFile::getBSSSectionForGlobal(const GlobalVariable *GV) const {
   assert(GV->hasInitializer() && "This global doesn't need space");
@@ -136,7 +111,7 @@ PIC16TargetObjectFile::getBSSSectionForGlobal(const GlobalVariable *GV) const {
   if (!FoundBSS) {
     std::string name = PAN::getUdataSectionName(BSSSections.size());
     const MCSectionPIC16 *NewSection
-      = getPIC16Section(name.c_str(), /*FIXME*/ SectionKind::getMetadata());
+      = getPIC16Section(name.c_str(), MCSectionPIC16::UDATA_Kind());
 
     FoundBSS = new PIC16Section(NewSection);
 
@@ -177,7 +152,7 @@ PIC16TargetObjectFile::getIDATASectionForGlobal(const GlobalVariable *GV) const{
   if (!FoundIDATA) {
     std::string name = PAN::getIdataSectionName(IDATASections.size());
     const MCSectionPIC16 *NewSection =
-      getPIC16Section(name.c_str(), /*FIXME*/ SectionKind::getMetadata());
+      getPIC16Section(name.c_str(), MCSectionPIC16::IDATA_Kind());
 
     FoundIDATA = new PIC16Section(NewSection);
 
@@ -211,7 +186,7 @@ PIC16TargetObjectFile::getSectionForAuto(const GlobalVariable *GV) const {
   // No Auto section was found. Crate a new one.
   if (!FoundAutoSec) {
     const MCSectionPIC16 *NewSection =
-      getPIC16Section(name.c_str(), /*FIXME*/ SectionKind::getMetadata());
+      getPIC16Section(name.c_str(), MCSectionPIC16::UDATA_OVR_Kind());
 
     FoundAutoSec = new PIC16Section(NewSection);
 
@@ -225,48 +200,6 @@ PIC16TargetObjectFile::getSectionForAuto(const GlobalVariable *GV) const {
   return FoundAutoSec->S_;
 }
 
-void PIC16TargetObjectFile::createClonedSectionForAutos(const std::string &SecName) {
-
-  // If the function is cloned then it will have ".IL" in its name
-  // If this function is not cloned then return;
-  if (SecName.find(".IL") == std::string::npos) 
-      return;
-
-  // Come here if the function is cloned.
-  // Get the name of the original section from which it has been cloned.
-  std::string OrigName = SecName;
-  OrigName.replace(SecName.find(".IL"),3,"");
-
-  // Find original section
-  PIC16Section *FoundAutoSec = NULL;
-  for (unsigned i = 0; i < AutosSections.size(); i++) {
-    if (AutosSections[i]->S_->getName() == OrigName) {
-      FoundAutoSec = AutosSections[i];
-      break; 
-    }
-  }
-
-  // No auto section exists for the original function.
-  if (!FoundAutoSec)
-    return;
-
-  // Create new section for the cloned function 
-  const MCSectionPIC16 *NewSection =
-      getPIC16Section(SecName.c_str(), SectionKind::getMetadata());
-  
-  PIC16Section *NewAutoSec = new PIC16Section(NewSection);
-  // Add this newly created autos section to the list of AutosSections.
-  AutosSections.push_back(NewAutoSec);
-
-  // Add the items from the original section to the new section
-  // Donot mangle them here. Because mangling them here will distort 
-  // the original names. 
-  // These names will be mangled them at the time of printing only
-  const std::vector<const GlobalVariable*> &Items = FoundAutoSec->Items;
-  for (unsigned j = 0; j < Items.size(); j++) {
-    NewAutoSec->Items.push_back(Items[j]); 
-  }
-}
 
 // Override default implementation to put the true globals into
 // multiple data sections if required.
@@ -404,7 +337,7 @@ PIC16TargetObjectFile::CreateBSSSectionForGlobal(const GlobalVariable *GV,
   PIC16Section *NewBSS = FoundBSS;
   if (NewBSS == NULL) {
     const MCSectionPIC16 *NewSection =
-      getPIC16Section(Name.c_str(), SectionKind::getBSS());
+      getPIC16Section(Name.c_str(), MCSectionPIC16::UDATA_Kind());
     NewBSS = new PIC16Section(NewSection);
     BSSSections.push_back(NewBSS);
   }
@@ -456,7 +389,7 @@ PIC16TargetObjectFile::CreateIDATASectionForGlobal(const GlobalVariable *GV,
   PIC16Section *NewIDATASec = FoundIDATASec;
   if (NewIDATASec == NULL) {
     const MCSectionPIC16 *NewSection =
-      getPIC16Section(Name.c_str(), /* FIXME */SectionKind::getMetadata());
+      getPIC16Section(Name.c_str(), MCSectionPIC16::IDATA_Kind());
     NewIDATASec = new PIC16Section(NewSection);
     IDATASections.push_back(NewIDATASec);
   }
@@ -495,7 +428,7 @@ PIC16TargetObjectFile::CreateROSectionForGlobal(const GlobalVariable *GV,
   PIC16Section *NewRomSec = FoundROSec;
   if (NewRomSec == NULL) {
     const MCSectionPIC16 *NewSection =
-      getPIC16Section(Name.c_str(), SectionKind::getReadOnly());
+      getPIC16Section(Name.c_str(), MCSectionPIC16::ROMDATA_Kind());
     NewRomSec = new PIC16Section(NewSection);
     ROSections.push_back(NewRomSec);
   }