Further refactoring of PIC16 Obj file code.

llvm-svn: 80670
This commit is contained in:
Sanjiv Gupta 2009-09-01 10:47:31 +00:00
parent a43ad3ddbd
commit a19e971f0c
3 changed files with 26 additions and 19 deletions

View File

@ -29,10 +29,9 @@ namespace llvm {
/// Negative value here means user hasn't specified any. /// Negative value here means user hasn't specified any.
int Address; int Address;
/// FIXME: Keep overlay information here. uncomment the decl below.
/// Overlay information - Sections with same color can be overlaid on /// Overlay information - Sections with same color can be overlaid on
/// one another. /// one another.
/// std::string Color; int Color;
/// Conatined data objects. /// Conatined data objects.
std::vector<const GlobalVariable *>Items; std::vector<const GlobalVariable *>Items;
@ -40,8 +39,8 @@ namespace llvm {
/// Total size of all data objects contained here. /// Total size of all data objects contained here.
unsigned Size; unsigned Size;
MCSectionPIC16(const StringRef &name, SectionKind K, int addr) MCSectionPIC16(const StringRef &name, SectionKind K, int addr, int color)
: MCSection(K), Name(name), Address(addr) { : MCSection(K), Name(name), Address(addr), Color(color) {
} }
public: public:
@ -51,6 +50,9 @@ namespace llvm {
/// Return the Address of the section. /// Return the Address of the section.
int getAddress() const { return Address; } int getAddress() const { return Address; }
/// Return the Color of the section.
int getColor() const { return Color; }
/// PIC16 Terminology for section kinds is as below. /// PIC16 Terminology for section kinds is as below.
/// UDATA - BSS /// UDATA - BSS
/// IDATA - initialized data (equiv to Metadata) /// IDATA - initialized data (equiv to Metadata)
@ -73,7 +75,7 @@ namespace llvm {
/// This would be the only way to create a section. /// This would be the only way to create a section.
static MCSectionPIC16 *Create(const StringRef &Name, SectionKind K, static MCSectionPIC16 *Create(const StringRef &Name, SectionKind K,
int Address, MCContext &Ctx); int Address, int Color, MCContext &Ctx);
/// Override this as PIC16 has its own way of printing switching /// Override this as PIC16 has its own way of printing switching
/// to a section. /// to a section.

View File

@ -20,8 +20,8 @@ using namespace llvm;
MCSectionPIC16 *MCSectionPIC16::Create(const StringRef &Name, SectionKind K, MCSectionPIC16 *MCSectionPIC16::Create(const StringRef &Name, SectionKind K,
int Address, MCContext &Ctx) { int Address, int Color, MCContext &Ctx) {
return new (Ctx) MCSectionPIC16(Name, K, Address); return new (Ctx) MCSectionPIC16(Name, K, Address, Color);
} }
@ -38,12 +38,14 @@ PIC16TargetObjectFile::PIC16TargetObjectFile()
} }
const MCSectionPIC16 *PIC16TargetObjectFile:: const MCSectionPIC16 *PIC16TargetObjectFile::
getPIC16Section(const char *Name, SectionKind Kind, int Address) const { getPIC16Section(const char *Name, SectionKind Kind,
int Address, int Color) const {
MCSectionPIC16 *&Entry = SectionsByName[Name]; MCSectionPIC16 *&Entry = SectionsByName[Name];
if (Entry) if (Entry)
return Entry; return Entry;
return Entry = MCSectionPIC16::Create(Name, Kind, Address, 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); TargetLoweringObjectFile::Initialize(Ctx, tm);
TM = &tm; TM = &tm;
BSSSection = getPIC16Section("udata.# UDATA", SectionKind::getBSS()); BSSSection = getPIC16Section("udata.# UDATA", MCSectionPIC16::UDATA_Kind());
ReadOnlySection = getPIC16Section("romdata.# ROMDATA", ReadOnlySection = getPIC16Section("romdata.# ROMDATA",
SectionKind::getReadOnly()); MCSectionPIC16::ROMDATA_Kind());
DataSection = getPIC16Section("idata.# IDATA", SectionKind::getDataRel()); DataSection = getPIC16Section("idata.# IDATA", MCSectionPIC16::IDATA_Kind());
// Need because otherwise a .text symbol is emitted by DwarfWriter // Need because otherwise a .text symbol is emitted by DwarfWriter
// in BeginModule, and gpasm cribbs for that .text symbol. // 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)); ROSections.push_back(new PIC16Section((MCSectionPIC16*)ReadOnlySection));
// FIXME: I don't know what the classification of these sections really is. // 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", ExternalVarDecls = new PIC16Section(getPIC16Section("ExternalVarDecls",
SectionKind::getMetadata())); SectionKind::getMetadata()));
ExternalVarDefs = new PIC16Section(getPIC16Section("ExternalVarDefs", ExternalVarDefs = new PIC16Section(getPIC16Section("ExternalVarDefs",
@ -107,7 +111,7 @@ PIC16TargetObjectFile::getBSSSectionForGlobal(const GlobalVariable *GV) const {
if (!FoundBSS) { if (!FoundBSS) {
std::string name = PAN::getUdataSectionName(BSSSections.size()); std::string name = PAN::getUdataSectionName(BSSSections.size());
const MCSectionPIC16 *NewSection const MCSectionPIC16 *NewSection
= getPIC16Section(name.c_str(), /*FIXME*/ SectionKind::getMetadata()); = getPIC16Section(name.c_str(), MCSectionPIC16::UDATA_Kind());
FoundBSS = new PIC16Section(NewSection); FoundBSS = new PIC16Section(NewSection);
@ -148,7 +152,7 @@ PIC16TargetObjectFile::getIDATASectionForGlobal(const GlobalVariable *GV) const{
if (!FoundIDATA) { if (!FoundIDATA) {
std::string name = PAN::getIdataSectionName(IDATASections.size()); std::string name = PAN::getIdataSectionName(IDATASections.size());
const MCSectionPIC16 *NewSection = const MCSectionPIC16 *NewSection =
getPIC16Section(name.c_str(), /*FIXME*/ SectionKind::getMetadata()); getPIC16Section(name.c_str(), MCSectionPIC16::IDATA_Kind());
FoundIDATA = new PIC16Section(NewSection); FoundIDATA = new PIC16Section(NewSection);
@ -182,7 +186,7 @@ PIC16TargetObjectFile::getSectionForAuto(const GlobalVariable *GV) const {
// No Auto section was found. Crate a new one. // No Auto section was found. Crate a new one.
if (!FoundAutoSec) { if (!FoundAutoSec) {
const MCSectionPIC16 *NewSection = const MCSectionPIC16 *NewSection =
getPIC16Section(name.c_str(), /*FIXME*/ SectionKind::getMetadata()); getPIC16Section(name.c_str(), MCSectionPIC16::UDATA_OVR_Kind());
FoundAutoSec = new PIC16Section(NewSection); FoundAutoSec = new PIC16Section(NewSection);
@ -333,7 +337,7 @@ PIC16TargetObjectFile::CreateBSSSectionForGlobal(const GlobalVariable *GV,
PIC16Section *NewBSS = FoundBSS; PIC16Section *NewBSS = FoundBSS;
if (NewBSS == NULL) { if (NewBSS == NULL) {
const MCSectionPIC16 *NewSection = const MCSectionPIC16 *NewSection =
getPIC16Section(Name.c_str(), SectionKind::getBSS()); getPIC16Section(Name.c_str(), MCSectionPIC16::UDATA_Kind());
NewBSS = new PIC16Section(NewSection); NewBSS = new PIC16Section(NewSection);
BSSSections.push_back(NewBSS); BSSSections.push_back(NewBSS);
} }
@ -385,7 +389,7 @@ PIC16TargetObjectFile::CreateIDATASectionForGlobal(const GlobalVariable *GV,
PIC16Section *NewIDATASec = FoundIDATASec; PIC16Section *NewIDATASec = FoundIDATASec;
if (NewIDATASec == NULL) { if (NewIDATASec == NULL) {
const MCSectionPIC16 *NewSection = const MCSectionPIC16 *NewSection =
getPIC16Section(Name.c_str(), /* FIXME */SectionKind::getMetadata()); getPIC16Section(Name.c_str(), MCSectionPIC16::IDATA_Kind());
NewIDATASec = new PIC16Section(NewSection); NewIDATASec = new PIC16Section(NewSection);
IDATASections.push_back(NewIDATASec); IDATASections.push_back(NewIDATASec);
} }
@ -424,7 +428,7 @@ PIC16TargetObjectFile::CreateROSectionForGlobal(const GlobalVariable *GV,
PIC16Section *NewRomSec = FoundROSec; PIC16Section *NewRomSec = FoundROSec;
if (NewRomSec == NULL) { if (NewRomSec == NULL) {
const MCSectionPIC16 *NewSection = const MCSectionPIC16 *NewSection =
getPIC16Section(Name.c_str(), SectionKind::getReadOnly()); getPIC16Section(Name.c_str(), MCSectionPIC16::ROMDATA_Kind());
NewRomSec = new PIC16Section(NewSection); NewRomSec = new PIC16Section(NewSection);
ROSections.push_back(NewRomSec); ROSections.push_back(NewRomSec);
} }

View File

@ -54,7 +54,8 @@ namespace llvm {
const MCSectionPIC16 *getPIC16Section(const char *Name, const MCSectionPIC16 *getPIC16Section(const char *Name,
SectionKind K, SectionKind K,
int Address = -1) const; int Address = -1,
int Color = -1) const;
public: public:
mutable std::vector<PIC16Section*> BSSSections; mutable std::vector<PIC16Section*> BSSSections;
mutable std::vector<PIC16Section*> IDATASections; mutable std::vector<PIC16Section*> IDATASections;