diff options
Diffstat (limited to 'lib/Target')
-rw-r--r-- | lib/Target/PIC16/PIC16AsmPrinter.cpp | 10 | ||||
-rw-r--r-- | lib/Target/PIC16/PIC16Section.h | 20 | ||||
-rw-r--r-- | lib/Target/PIC16/PIC16TargetObjectFile.cpp | 77 | ||||
-rw-r--r-- | lib/Target/PIC16/PIC16TargetObjectFile.h | 9 |
4 files changed, 63 insertions, 53 deletions
diff --git a/lib/Target/PIC16/PIC16AsmPrinter.cpp b/lib/Target/PIC16/PIC16AsmPrinter.cpp index dc332ffe6d..7a5fdc853c 100644 --- a/lib/Target/PIC16/PIC16AsmPrinter.cpp +++ b/lib/Target/PIC16/PIC16AsmPrinter.cpp @@ -13,6 +13,7 @@ //===----------------------------------------------------------------------===// #include "PIC16AsmPrinter.h" +#include "PIC16Section.h" #include "PIC16TargetAsmInfo.h" #include "llvm/DerivedTypes.h" #include "llvm/Function.h" @@ -21,7 +22,6 @@ #include "llvm/CodeGen/MachineFrameInfo.h" #include "llvm/CodeGen/DwarfWriter.h" #include "llvm/CodeGen/MachineModuleInfo.h" -#include "llvm/MC/MCSection.h" #include "llvm/Target/TargetRegistry.h" #include "llvm/Target/TargetLoweringObjectFile.h" #include "llvm/Support/ErrorHandling.h" @@ -227,9 +227,11 @@ bool PIC16AsmPrinter::doInitialization(Module &M) { // Set the section names for all globals. for (Module::global_iterator I = M.global_begin(), E = M.global_end(); I != E; ++I) - if (!I->isDeclaration() && !I->hasAvailableExternallyLinkage()) - I->setSection(getObjFileLowering(). - SectionForGlobal(I, Mang,TM)->getName()); + if (!I->isDeclaration() && !I->hasAvailableExternallyLinkage()) { + const MCSection *S = getObjFileLowering().SectionForGlobal(I, Mang, TM); + + I->setSection(((const MCSectionPIC16*)S)->getName()); + } DbgInfo.BeginModule(M); EmitFunctionDecls(M); diff --git a/lib/Target/PIC16/PIC16Section.h b/lib/Target/PIC16/PIC16Section.h index 4c2ae05707..f69cc2c807 100644 --- a/lib/Target/PIC16/PIC16Section.h +++ b/lib/Target/PIC16/PIC16Section.h @@ -15,27 +15,23 @@ #define LLVM_PIC16SECTION_H #include "llvm/MC/MCSection.h" -#include "llvm/MC/MCContext.h" -#include "llvm/Support/raw_ostream.h" namespace llvm { class MCSectionPIC16 : public MCSection { - MCSectionPIC16(const StringRef &Name, bool IsDirective, SectionKind K, - MCContext &Ctx) : MCSection(Name, IsDirective, K, Ctx) {} + std::string Name; + + MCSectionPIC16(const StringRef &name, SectionKind K, + MCContext &Ctx); public: - static MCSectionPIC16 *Create(const StringRef &Name, bool IsDirective, - SectionKind K, MCContext &Ctx) { - return new (Ctx) MCSectionPIC16(Name, IsDirective, K, Ctx); - } + const std::string &getName() const { return Name; } + static MCSectionPIC16 *Create(const StringRef &Name, + SectionKind K, MCContext &Ctx); virtual void PrintSwitchToSection(const TargetAsmInfo &TAI, - raw_ostream &OS) const { - OS << getName() << '\n'; - } - + raw_ostream &OS) const; }; } // end namespace llvm diff --git a/lib/Target/PIC16/PIC16TargetObjectFile.cpp b/lib/Target/PIC16/PIC16TargetObjectFile.cpp index a9668f9c07..ed1caf225e 100644 --- a/lib/Target/PIC16/PIC16TargetObjectFile.cpp +++ b/lib/Target/PIC16/PIC16TargetObjectFile.cpp @@ -15,17 +15,37 @@ #include "llvm/Module.h" #include "llvm/MC/MCSection.h" #include "llvm/MC/MCContext.h" +#include "llvm/Support/raw_ostream.h" using namespace llvm; +MCSectionPIC16::MCSectionPIC16(const StringRef &name, SectionKind K, + MCContext &Ctx) : MCSection(K), Name(name) { + Ctx.SetSection(Name, this); +} + +MCSectionPIC16 *MCSectionPIC16::Create(const StringRef &Name, + SectionKind K, MCContext &Ctx) { + return new (Ctx) MCSectionPIC16(Name, K, Ctx); +} + + +void MCSectionPIC16::PrintSwitchToSection(const TargetAsmInfo &TAI, + raw_ostream &OS) const { + OS << getName() << '\n'; +} + + + + PIC16TargetObjectFile::PIC16TargetObjectFile() : ExternalVarDecls(0), ExternalVarDefs(0) { } -const MCSection *PIC16TargetObjectFile:: -getPIC16Section(const char *Name, bool isDirective, SectionKind Kind) const { +const MCSectionPIC16 *PIC16TargetObjectFile:: +getPIC16Section(const char *Name, SectionKind Kind) const { if (MCSection *S = getContext().GetSection(Name)) - return S; - return MCSectionPIC16::Create(Name, isDirective, Kind, getContext()); + return (MCSectionPIC16*)S; + return MCSectionPIC16::Create(Name, Kind, getContext()); } @@ -33,39 +53,35 @@ void PIC16TargetObjectFile::Initialize(MCContext &Ctx, const TargetMachine &tm){ TargetLoweringObjectFile::Initialize(Ctx, tm); TM = &tm; - BSSSection = getPIC16Section("udata.# UDATA", false, - SectionKind::getBSS()); - ReadOnlySection = getPIC16Section("romdata.# ROMDATA", false, + BSSSection = getPIC16Section("udata.# UDATA", SectionKind::getBSS()); + ReadOnlySection = getPIC16Section("romdata.# ROMDATA", SectionKind::getReadOnly()); - DataSection = getPIC16Section("idata.# IDATA", false, - SectionKind::getDataRel()); + DataSection = getPIC16Section("idata.# IDATA", SectionKind::getDataRel()); // Need because otherwise a .text symbol is emitted by DwarfWriter // in BeginModule, and gpasm cribbs for that .text symbol. - TextSection = getPIC16Section("", true, SectionKind::getText()); + TextSection = getPIC16Section("", SectionKind::getText()); - ROSections.push_back(new PIC16Section(ReadOnlySection)); + ROSections.push_back(new PIC16Section((MCSectionPIC16*)ReadOnlySection)); // FIXME: I don't know what the classification of these sections really is. ExternalVarDecls = new PIC16Section(getPIC16Section("ExternalVarDecls", - false, SectionKind::getMetadata())); ExternalVarDefs = new PIC16Section(getPIC16Section("ExternalVarDefs", - false, SectionKind::getMetadata())); } const MCSection *PIC16TargetObjectFile:: getSectionForFunction(const std::string &FnName) const { std::string T = PAN::getCodeSectionName(FnName); - return getPIC16Section(T.c_str(), false, SectionKind::getText()); + return getPIC16Section(T.c_str(), SectionKind::getText()); } const MCSection *PIC16TargetObjectFile:: getSectionForFunctionFrame(const std::string &FnName) const { std::string T = PAN::getFrameSectionName(FnName); - return getPIC16Section(T.c_str(), false, SectionKind::getDataRel()); + return getPIC16Section(T.c_str(), SectionKind::getDataRel()); } const MCSection * @@ -92,9 +108,8 @@ PIC16TargetObjectFile::getBSSSectionForGlobal(const GlobalVariable *GV) const { // No BSS section spacious enough was found. Crate a new one. if (!FoundBSS) { std::string name = PAN::getUdataSectionName(BSSSections.size()); - const MCSection *NewSection = getPIC16Section(name.c_str(), false, - // FIXME. - SectionKind::getMetadata()); + const MCSectionPIC16 *NewSection + = getPIC16Section(name.c_str(), /*FIXME*/ SectionKind::getMetadata()); FoundBSS = new PIC16Section(NewSection); @@ -134,9 +149,8 @@ PIC16TargetObjectFile::getIDATASectionForGlobal(const GlobalVariable *GV) const{ // No IDATA section spacious enough was found. Crate a new one. if (!FoundIDATA) { std::string name = PAN::getIdataSectionName(IDATASections.size()); - const MCSection *NewSection = getPIC16Section(name.c_str(), false, - // FIXME. - SectionKind::getMetadata()); + const MCSectionPIC16 *NewSection = + getPIC16Section(name.c_str(), /*FIXME*/ SectionKind::getMetadata()); FoundIDATA = new PIC16Section(NewSection); @@ -169,10 +183,8 @@ PIC16TargetObjectFile::getSectionForAuto(const GlobalVariable *GV) const { // No Auto section was found. Crate a new one. if (!FoundAutoSec) { - const MCSection *NewSection = getPIC16Section(name.c_str(), - // FIXME. - false, - SectionKind::getMetadata()); + const MCSectionPIC16 *NewSection = + getPIC16Section(name.c_str(), /*FIXME*/ SectionKind::getMetadata()); FoundAutoSec = new PIC16Section(NewSection); @@ -270,7 +282,7 @@ getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind, return CreateSectionForGlobal(GVar, Mang); } - return getPIC16Section(GV->getSection().c_str(), false, Kind); + return getPIC16Section(GV->getSection().c_str(), Kind); } // Create a new section for global variable. If Addr is given then create @@ -322,8 +334,8 @@ PIC16TargetObjectFile::CreateBSSSectionForGlobal(const GlobalVariable *GV, PIC16Section *NewBSS = FoundBSS; if (NewBSS == NULL) { - const MCSection *NewSection = getPIC16Section(Name.c_str(), false, - SectionKind::getBSS()); + const MCSectionPIC16 *NewSection = + getPIC16Section(Name.c_str(), SectionKind::getBSS()); NewBSS = new PIC16Section(NewSection); BSSSections.push_back(NewBSS); } @@ -374,9 +386,8 @@ PIC16TargetObjectFile::CreateIDATASectionForGlobal(const GlobalVariable *GV, PIC16Section *NewIDATASec = FoundIDATASec; if (NewIDATASec == NULL) { - const MCSection *NewSection = getPIC16Section(Name.c_str(), false, - // FIXME: - SectionKind::getMetadata()); + const MCSectionPIC16 *NewSection = + getPIC16Section(Name.c_str(), /* FIXME */SectionKind::getMetadata()); NewIDATASec = new PIC16Section(NewSection); IDATASections.push_back(NewIDATASec); } @@ -414,8 +425,8 @@ PIC16TargetObjectFile::CreateROSectionForGlobal(const GlobalVariable *GV, PIC16Section *NewRomSec = FoundROSec; if (NewRomSec == NULL) { - const MCSection *NewSection = getPIC16Section(Name.c_str(), false, - SectionKind::getReadOnly()); + const MCSectionPIC16 *NewSection = + getPIC16Section(Name.c_str(), SectionKind::getReadOnly()); NewRomSec = new PIC16Section(NewSection); ROSections.push_back(NewRomSec); } diff --git a/lib/Target/PIC16/PIC16TargetObjectFile.h b/lib/Target/PIC16/PIC16TargetObjectFile.h index f8389a6adc..edd2b1cc15 100644 --- a/lib/Target/PIC16/PIC16TargetObjectFile.h +++ b/lib/Target/PIC16/PIC16TargetObjectFile.h @@ -17,6 +17,7 @@ namespace llvm { class GlobalVariable; class Module; class PIC16TargetMachine; + class MCSectionPIC16; enum { DataBankSize = 80 }; @@ -29,12 +30,12 @@ namespace llvm { /// FIXME: MOVE ALL THIS STUFF TO MCSectionPIC16. /// struct PIC16Section { - const MCSection *S_; // Connection to actual Section. + const MCSectionPIC16 *S_; // Connection to actual Section. unsigned Size; // Total size of the objects contained. bool SectionPrinted; std::vector<const GlobalVariable*> Items; - PIC16Section(const MCSection *s) { + PIC16Section(const MCSectionPIC16 *s) { S_ = s; Size = 0; SectionPrinted = false; @@ -46,8 +47,8 @@ namespace llvm { class PIC16TargetObjectFile : public TargetLoweringObjectFile { const TargetMachine *TM; - const MCSection *getPIC16Section(const char *Name, bool isDirective, - SectionKind K) const; + const MCSectionPIC16 *getPIC16Section(const char *Name, + SectionKind K) const; public: mutable std::vector<PIC16Section*> BSSSections; mutable std::vector<PIC16Section*> IDATASections; |