aboutsummaryrefslogtreecommitdiffstats
path: root/lib/Target/PIC16/PIC16TargetAsmInfo.cpp
diff options
context:
space:
mode:
authorSanjiv Gupta <sanjiv.gupta@microchip.com>2009-05-12 17:07:27 +0000
committerSanjiv Gupta <sanjiv.gupta@microchip.com>2009-05-12 17:07:27 +0000
commitdbe79114b9c4188fc1a11b88f428859699978f4f (patch)
tree0fdddf849b7114fd888e8451d09d2cc7f60b7064 /lib/Target/PIC16/PIC16TargetAsmInfo.cpp
parentb47afd5164d0a5b888e4f44e1e35936cd7afb10e (diff)
downloadexternal_llvm-dbe79114b9c4188fc1a11b88f428859699978f4f.zip
external_llvm-dbe79114b9c4188fc1a11b88f428859699978f4f.tar.gz
external_llvm-dbe79114b9c4188fc1a11b88f428859699978f4f.tar.bz2
Iterate over globals once and sectionize them into appropriate sections.
Later in asmprinter, go over thsese sections and print them. Do not print empty sections. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@71560 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Target/PIC16/PIC16TargetAsmInfo.cpp')
-rw-r--r--lib/Target/PIC16/PIC16TargetAsmInfo.cpp53
1 files changed, 49 insertions, 4 deletions
diff --git a/lib/Target/PIC16/PIC16TargetAsmInfo.cpp b/lib/Target/PIC16/PIC16TargetAsmInfo.cpp
index 3837f9e..295188f 100644
--- a/lib/Target/PIC16/PIC16TargetAsmInfo.cpp
+++ b/lib/Target/PIC16/PIC16TargetAsmInfo.cpp
@@ -44,6 +44,7 @@ PIC16TargetAsmInfo(const PIC16TargetMachine &TM)
// Need because otherwise a .text symbol is emitted by DwarfWriter
// in BeginModule, and gpasm cribbs for that .text symbol.
TextSection = getUnnamedSection("", SectionFlags::Code);
+ ROSection = new PIC16Section(getReadOnlySection());
}
const char *PIC16TargetAsmInfo::getRomDirective(unsigned size) const
@@ -154,6 +155,40 @@ PIC16TargetAsmInfo::getIDATASectionForGlobal(const GlobalVariable *GV) const {
return FoundIDATA->S_;
}
+// Get the section for an automatic variable of a function.
+// For PIC16 they are globals only with mangled names.
+const Section *
+PIC16TargetAsmInfo::getSectionForAuto(const GlobalVariable *GV) const {
+
+ const std::string name = PAN::getSectionNameForSym(GV->getName());
+
+ // Go through all Auto Sections and assign this variable
+ // to the appropriate section.
+ PIC16Section *FoundAutoSec = NULL;
+ for (unsigned i = 0; i < AutosSections.size(); i++) {
+ if ( AutosSections[i]->S_->getName() == name) {
+ FoundAutoSec = AutosSections[i];
+ break;
+ }
+ }
+
+ // No Auto section was found. Crate a new one.
+ if (! FoundAutoSec) {
+ const Section *NewSection = getNamedSection (name.c_str());
+
+ FoundAutoSec = new PIC16Section(NewSection);
+
+ // Add this newly created autos section to the list of AutosSections.
+ AutosSections.push_back(FoundAutoSec);
+ }
+
+ // Insert the auto into this section.
+ FoundAutoSec->Items.push_back(GV);
+
+ return FoundAutoSec->S_;
+}
+
+
// Override default implementation to put the true globals into
// multiple data sections if required.
const Section*
@@ -168,8 +203,7 @@ PIC16TargetAsmInfo::SelectSectionForGlobal(const GlobalValue *GV1) const {
// name for it and return.
const std::string name = GV->getName();
if (PAN::isLocalName(name)) {
- const std::string Sec_Name = PAN::getSectionNameForSym(name);
- return getNamedSection(Sec_Name.c_str());
+ return getSectionForAuto(GV);
}
// See if this is an uninitialized global.
@@ -177,11 +211,16 @@ PIC16TargetAsmInfo::SelectSectionForGlobal(const GlobalValue *GV1) const {
if (C->isNullValue())
return getBSSSectionForGlobal(GV);
- // This is initialized data. We only deal with initialized data in RAM.
+ // If this is initialized data in RAM. Put it in the correct IDATA section.
if (GV->getType()->getAddressSpace() == PIC16ISD::RAM_SPACE)
return getIDATASectionForGlobal(GV);
-
+ // This is initialized data in rom, put it in the readonly section.
+ if (GV->getType()->getAddressSpace() == PIC16ISD::ROM_SPACE) {
+ ROSection->Items.push_back(GV);
+ return ROSection->S_;
+ }
+
// Else let the default implementation take care of it.
return TargetAsmInfo::SelectSectionForGlobal(GV);
}
@@ -195,4 +234,10 @@ PIC16TargetAsmInfo::~PIC16TargetAsmInfo() {
for (unsigned i = 0; i < IDATASections.size(); i++) {
delete IDATASections[i];
}
+
+ for (unsigned i = 0; i < AutosSections.size(); i++) {
+ delete AutosSections[i];
+ }
+
+ delete ROSection;
}