const Section *
PIC16TargetAsmInfo::getBSSSectionForGlobal(const GlobalVariable *GV) const {
- assert (GV->hasInitializer() && "This global doesn't need space");
+ assert(GV->hasInitializer() && "This global doesn't need space");
Constant *C = GV->getInitializer();
- assert (C->isNullValue() && "Unitialized globals has non-zero initializer");
+ assert(C->isNullValue() && "Unitialized globals has non-zero initializer");
// Find how much space this global needs.
const TargetData *TD = TM.getTargetData();
}
// No BSS section spacious enough was found. Crate a new one.
- if (! FoundBSS) {
+ if (!FoundBSS) {
std::string name = PAN::getUdataSectionName(BSSSections.size());
- const Section *NewSection = getNamedSection (name.c_str());
+ const Section *NewSection = getNamedSection(name.c_str());
FoundBSS = new PIC16Section(NewSection);
// Insert the GV into this BSS.
FoundBSS->Items.push_back(GV);
FoundBSS->Size += ValSize;
-
- // We can't do this here because GV is const .
- // const std::string SName = FoundBSS->S_->getName();
- // GV->setSection(SName);
-
return FoundBSS->S_;
}
const Section *
PIC16TargetAsmInfo::getIDATASectionForGlobal(const GlobalVariable *GV) const {
- assert (GV->hasInitializer() && "This global doesn't need space");
+ assert(GV->hasInitializer() && "This global doesn't need space");
Constant *C = GV->getInitializer();
- assert (!C->isNullValue() && "initialized globals has zero initializer");
- assert (GV->getType()->getAddressSpace() == PIC16ISD::RAM_SPACE &&
- "can split initialized RAM data only");
+ assert(!C->isNullValue() && "initialized globals has zero initializer");
+ assert(GV->getType()->getAddressSpace() == PIC16ISD::RAM_SPACE &&
+ "can split initialized RAM data only");
// Find how much space this global needs.
const TargetData *TD = TM.getTargetData();
// to the first available section having enough space.
PIC16Section *FoundIDATA = NULL;
for (unsigned i = 0; i < IDATASections.size(); i++) {
- if ( DataBankSize - IDATASections[i]->Size >= ValSize) {
+ if (DataBankSize - IDATASections[i]->Size >= ValSize) {
FoundIDATA = IDATASections[i];
break;
}
}
// No IDATA section spacious enough was found. Crate a new one.
- if (! FoundIDATA) {
+ if (!FoundIDATA) {
std::string name = PAN::getIdataSectionName(IDATASections.size());
- const Section *NewSection = getNamedSection (name.c_str());
+ const Section *NewSection = getNamedSection(name.c_str());
FoundIDATA = new PIC16Section(NewSection);
// Insert the GV into this IDATA.
FoundIDATA->Items.push_back(GV);
FoundIDATA->Size += ValSize;
-
- // We can't do this here because GV is const .
- // GV->setSection(FoundIDATA->S->getName());
-
return FoundIDATA->S_;
}
// to the appropriate section.
PIC16Section *FoundAutoSec = NULL;
for (unsigned i = 0; i < AutosSections.size(); i++) {
- if ( AutosSections[i]->S_->getName() == name) {
+ 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());
+ if (!FoundAutoSec) {
+ const Section *NewSection = getNamedSection(name.c_str());
FoundAutoSec = new PIC16Section(NewSection);
// We select the section based on the initializer here, so it really
// has to be a GlobalVariable.
const GlobalVariable *GV = dyn_cast<GlobalVariable>(GV1);
-
if (!GV)
return TargetAsmInfo::SelectSectionForGlobal(GV1);
return ExternalVarDecls->S_;
}
- assert (GV->hasInitializer() && "A def without initializer?");
+ assert(GV->hasInitializer() && "A def without initializer?");
// First, if this is an automatic variable for a function, get the section
// name for it and return.
const Section *
PIC16TargetAsmInfo::CreateBSSSectionForGlobal(const GlobalVariable *GV,
std::string Addr) const {
- assert (GV->hasInitializer() && "This global doesn't need space");
- assert (GV->getInitializer()->isNullValue() &&
- "Unitialized global has non-zero initializer");
+ assert(GV->hasInitializer() && "This global doesn't need space");
+ assert(GV->getInitializer()->isNullValue() &&
+ "Unitialized global has non-zero initializer");
std::string Name;
// If address is given then create a section at that address else create a
// section by section name specified in GV.
break;
}
}
- }
- else {
+ } else {
std::string Prefix = GV->getName() + "." + Addr + ".";
Name = PAN::getUdataSectionName(BSSSections.size(), Prefix) + " " + Addr;
}
PIC16Section *NewBSS = FoundBSS;
if (NewBSS == NULL) {
- const Section *NewSection = getNamedSection (Name.c_str());
+ const Section *NewSection = getNamedSection(Name.c_str());
NewBSS = new PIC16Section(NewSection);
BSSSections.push_back(NewBSS);
}
const Section *
PIC16TargetAsmInfo::CreateIDATASectionForGlobal(const GlobalVariable *GV,
std::string Addr) const {
- assert (GV->hasInitializer() && "This global doesn't need space");
- assert (!GV->getInitializer()->isNullValue() &&
- "initialized global has zero initializer");
- assert (GV->getType()->getAddressSpace() == PIC16ISD::RAM_SPACE &&
- "can be used for initialized RAM data only");
+ assert(GV->hasInitializer() && "This global doesn't need space");
+ assert(!GV->getInitializer()->isNullValue() &&
+ "initialized global has zero initializer");
+ assert(GV->getType()->getAddressSpace() == PIC16ISD::RAM_SPACE &&
+ "can be used for initialized RAM data only");
std::string Name;
// If address is given then create a section at that address else create a
break;
}
}
- }
- else {
+ } else {
std::string Prefix = GV->getName() + "." + Addr + ".";
Name = PAN::getIdataSectionName(IDATASections.size(), Prefix) + " " + Addr;
}
PIC16Section *NewIDATASec = FoundIDATASec;
if (NewIDATASec == NULL) {
- const Section *NewSection = getNamedSection (Name.c_str());
+ const Section *NewSection = getNamedSection(Name.c_str());
NewIDATASec = new PIC16Section(NewSection);
IDATASections.push_back(NewIDATASec);
}
const Section *
PIC16TargetAsmInfo::CreateROSectionForGlobal(const GlobalVariable *GV,
std::string Addr) const {
- assert (GV->getType()->getAddressSpace() == PIC16ISD::ROM_SPACE &&
- "can be used for ROM data only");
+ assert(GV->getType()->getAddressSpace() == PIC16ISD::ROM_SPACE &&
+ "can be used for ROM data only");
std::string Name;
// If address is given then create a section at that address else create a
break;
}
}
- }
- else {
+ } else {
std::string Prefix = GV->getName() + "." + Addr + ".";
Name = PAN::getRomdataSectionName(ROSections.size(), Prefix) + " " + Addr;
}
PIC16Section *NewRomSec = FoundROSec;
if (NewRomSec == NULL) {
- const Section *NewSection = getNamedSection (Name.c_str());
+ const Section *NewSection = getNamedSection(Name.c_str());
NewRomSec = new PIC16Section(NewSection);
ROSections.push_back(NewRomSec);
}
#include "llvm/Target/TargetAsmInfo.h"
#include <vector>
#include "llvm/Module.h"
-#define DataBankSize 80
+
namespace llvm {
+ enum { DataBankSize = 80 };
+
// Forward declaration.
class PIC16TargetMachine;
class GlobalVariable;
- // PIC16 Splits the global data into mulitple udata and idata sections.
- // Each udata and idata section needs to contain a list of globals that
- // they contain, in order to avoid scanning over all the global values
- // again and printing only those that match the current section.
- // Keeping values inside the sections make printing a section much easier.
+ /// PIC16 Splits the global data into mulitple udata and idata sections.
+ /// Each udata and idata section needs to contain a list of globals that
+ /// they contain, in order to avoid scanning over all the global values
+ /// again and printing only those that match the current section.
+ /// Keeping values inside the sections make printing a section much easier.
struct PIC16Section {
- const Section *S_; // Connection to actual Section.
- unsigned Size; // Total size of the objects contained.
- bool SectionPrinted;
- std::vector<const GlobalVariable*> Items;
-
- PIC16Section (const Section *s) { S_ = s; Size = 0;
- SectionPrinted = false;}
- bool isPrinted() { return SectionPrinted ; }
- void setPrintedStatus(bool status) { SectionPrinted = status ;}
+ const Section *S_; // Connection to actual Section.
+ unsigned Size; // Total size of the objects contained.
+ bool SectionPrinted;
+ std::vector<const GlobalVariable*> Items;
+
+ PIC16Section(const Section *s) {
+ S_ = s;
+ Size = 0;
+ SectionPrinted = false;
+ }
+ bool isPrinted() const { return SectionPrinted; }
+ void setPrintedStatus(bool status) { SectionPrinted = status; }
};
struct PIC16TargetAsmInfo : public TargetAsmInfo {
mutable PIC16Section *ExternalVarDefs;
virtual ~PIC16TargetAsmInfo();
- private:
+ private:
const char *RomData8bitsDirective;
const char *RomData16bitsDirective;
const char *RomData32bitsDirective;
virtual const Section *SelectSectionForGlobal(const GlobalValue *GV) const;
const Section * CreateSectionForGlobal(const GlobalValue *GV,
std::string Addr = "") const;
- public:
+ public:
void SetSectionForGVs(Module &M);
- std::vector<PIC16Section *> getBSSSections() const {
+ const std::vector<PIC16Section*> &getBSSSections() const {
return BSSSections;
}
- std::vector<PIC16Section *> getIDATASections() const {
+ const std::vector<PIC16Section*> &getIDATASections() const {
return IDATASections;
}
- std::vector<PIC16Section *> getAutosSections() const {
+ const std::vector<PIC16Section*> &getAutosSections() const {
return AutosSections;
}
- std::vector<PIC16Section *> getROSections() const {
+ const std::vector<PIC16Section*> &getROSections() const {
return ROSections;
}
- virtual const Section* SectionForGlobal(const GlobalValue *GV) const;
+ virtual const Section *SectionForGlobal(const GlobalValue *GV) const;
};
} // namespace llvm